blob: d21b1581a665c9ec0bdcc900d911193fd62224fb [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 Berg3d7af872018-10-02 10:00:08 +0200204static int validate_ie_attr(const struct nlattr *attr,
205 struct netlink_ext_ack *extack)
206{
Johannes Berg9f308612019-02-07 23:39:19 +0100207 const u8 *data = nla_data(attr);
208 unsigned int len = nla_len(attr);
Jouni Malinen7388afe2019-02-11 16:29:04 +0200209 const struct element *elem;
Johannes Berg3d7af872018-10-02 10:00:08 +0200210
Johannes Berg9f308612019-02-07 23:39:19 +0100211 for_each_element(elem, data, len) {
212 /* nothing */
Johannes Berg3d7af872018-10-02 10:00:08 +0200213 }
214
Johannes Berg9f308612019-02-07 23:39:19 +0100215 if (for_each_element_completed(elem, data, len))
216 return 0;
217
Johannes Berg3d7af872018-10-02 10:00:08 +0200218 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
219 return -EINVAL;
220}
221
Johannes Berg55682962007-09-20 13:09:35 -0400222/* policy for the attributes */
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700223static const struct nla_policy
224nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
225 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
226 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
227 .len = U8_MAX },
228 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
229 .len = U8_MAX },
230};
231
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200232static const struct nla_policy
233nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
234 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
235 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
236 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
237 NLA_POLICY_MAX(NLA_U8, 15),
238 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
239 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
240 NLA_POLICY_MAX(NLA_U8, 15),
241 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
Aviya Erenfeldea187092019-02-06 13:17:08 +0200242 NLA_POLICY_MAX(NLA_U8, 31),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200243 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
244 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
245 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
246};
247
248static const struct nla_policy
249nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
250 [NL80211_PMSR_TYPE_FTM] =
Johannes Berg23323282019-01-25 10:08:28 +0100251 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200252};
253
254static const struct nla_policy
255nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
256 [NL80211_PMSR_REQ_ATTR_DATA] =
Johannes Berg23323282019-01-25 10:08:28 +0100257 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200258 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
259};
260
261static const struct nla_policy
262nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
263 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
264 /*
265 * we could specify this again to be the top-level policy,
266 * but that would open us up to recursion problems ...
267 */
268 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED },
269 [NL80211_PMSR_PEER_ATTR_REQ] =
Johannes Berg23323282019-01-25 10:08:28 +0100270 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200271 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
272};
273
274static const struct nla_policy
275nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
276 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
277 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
278 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
279 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
280 [NL80211_PMSR_ATTR_PEERS] =
Johannes Berg23323282019-01-25 10:08:28 +0100281 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200282};
283
John Crispin796e90f2019-07-30 18:37:00 +0200284static const struct nla_policy
285he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
286 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
287 NLA_POLICY_RANGE(NLA_U8, 1, 20),
288 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
289 NLA_POLICY_RANGE(NLA_U8, 1, 20),
290};
291
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200292const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg6d4dd4e2019-07-31 10:58:20 +0200293 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
Johannes Berg55682962007-09-20 13:09:35 -0400294 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
295 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700296 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200297 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100298
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200299 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530300 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300301 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
302 NL80211_EDMG_CHANNELS_MIN,
303 NL80211_EDMG_CHANNELS_MAX),
304 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
305 NL80211_EDMG_BW_CONFIG_MIN,
306 NL80211_EDMG_BW_CONFIG_MAX),
307
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100308 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
309 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
310 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
311
Johannes Bergab0d76f2018-10-02 10:00:07 +0200312 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
313 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200314 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100316 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200317 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400318
Johannes Bergab0d76f2018-10-02 10:00:07 +0200319 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400320 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
321 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100322
Johannes Berg1a28ed22019-05-28 14:18:07 +0200323 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
324 [NL80211_ATTR_PREV_BSSID] = {
325 .type = NLA_EXACT_LEN_WARN,
326 .len = ETH_ALEN
327 },
Johannes Berg41ade002007-12-19 02:03:29 +0100328
Johannes Bergb9454e82009-07-08 13:29:08 +0200329 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100330 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
331 .len = WLAN_MAX_KEY_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200332 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
Johannes Berg41ade002007-12-19 02:03:29 +0100333 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
334 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200335 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200336 [NL80211_ATTR_KEY_TYPE] =
337 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100338
339 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
340 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
341 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg3d7af872018-10-02 10:00:08 +0200343 [NL80211_ATTR_BEACON_TAIL] =
344 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
345 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200346 [NL80211_ATTR_STA_AID] =
347 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100348 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
349 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
350 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
351 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200352 [NL80211_ATTR_STA_PLINK_ACTION] =
353 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530354 [NL80211_ATTR_STA_TX_POWER_SETTING] =
355 NLA_POLICY_RANGE(NLA_U8,
356 NL80211_TX_POWER_AUTOMATIC,
357 NL80211_TX_POWER_FIXED),
358 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100359 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200360 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100361 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800362 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100363 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300364
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700365 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
366 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
367
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300368 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
369 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
370 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200371 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
372 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100373 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300374
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800375 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700376 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700377
Johannes Berg1a28ed22019-05-28 14:18:07 +0200378 [NL80211_ATTR_HT_CAPABILITY] = {
379 .type = NLA_EXACT_LEN_WARN,
380 .len = NL80211_HT_CAPABILITY_LEN
381 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200382
383 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200384 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
385 validate_ie_attr,
386 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100387 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
388 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200389
390 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
391 .len = IEEE80211_MAX_SSID_LEN },
392 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
393 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200394 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300395 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200396 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
397 NL80211_MFP_NO,
398 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300399 [NL80211_ATTR_STA_FLAGS2] = {
400 .len = sizeof(struct nl80211_sta_flag_update),
401 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300402 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300403 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
404 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500405 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200406 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
407 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
408 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200409 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100410 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200411 [NL80211_ATTR_PMKID] = {
412 .type = NLA_EXACT_LEN_WARN,
413 .len = WLAN_PMKID_LEN
414 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100415 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
416 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200417 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200418 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
419 .len = IEEE80211_MAX_DATA_LEN },
420 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200421 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
422 NL80211_PS_DISABLED,
423 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200424 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300425 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200426 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300427 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
428 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200429 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900430 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
431 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100432 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100433 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200435 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200436 [NL80211_ATTR_STA_PLINK_STATE] =
437 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
438 [NL80211_ATTR_MESH_PEER_AID] =
439 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300440 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200441 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200442 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200443 [NL80211_ATTR_HIDDEN_SSID] =
444 NLA_POLICY_RANGE(NLA_U32,
445 NL80211_HIDDEN_SSID_NOT_IN_USE,
446 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200447 [NL80211_ATTR_IE_PROBE_RESP] =
448 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
449 IEEE80211_MAX_DATA_LEN),
450 [NL80211_ATTR_IE_ASSOC_RESP] =
451 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
452 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530453 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300454 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530455 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300456 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
457 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
458 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
459 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
460 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300461 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100462 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200463 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
464 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700465 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800466 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
467 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
468 .len = NL80211_HT_CAPABILITY_LEN
469 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100470 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530471 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530472 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200473 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700474 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300475 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200476 [NL80211_ATTR_VHT_CAPABILITY] = {
477 .type = NLA_EXACT_LEN_WARN,
478 .len = NL80211_VHT_CAPABILITY_LEN
479 },
Sam Lefflered4737712012-10-11 21:03:31 -0700480 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200481 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
482 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
483 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
484 NLA_POLICY_RANGE(NLA_U32,
485 NL80211_MESH_POWER_UNKNOWN + 1,
486 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530487 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
488 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200489 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
490 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100491 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100492 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
493 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
494 .len = NL80211_VHT_CAPABILITY_LEN,
495 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200496 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
497 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
498 .len = IEEE80211_MAX_DATA_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200499 [NL80211_ATTR_PEER_AID] =
500 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200501 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
502 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
503 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300504 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
505 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530506 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
507 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200508 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100509 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100510 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
511 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
512 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800513 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
514 .len = IEEE80211_QOS_MAP_LEN_MAX },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200515 [NL80211_ATTR_MAC_HINT] = {
516 .type = NLA_EXACT_LEN_WARN,
517 .len = ETH_ALEN
518 },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200519 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530520 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200521 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300522 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300523 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200524 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
525 [NL80211_ATTR_USER_PRIO] =
526 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300527 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300528 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200529 [NL80211_ATTR_MAC_MASK] = {
530 .type = NLA_EXACT_LEN_WARN,
531 .len = ETH_ALEN
532 },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200533 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200534 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200535 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500536 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200537 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100538 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200539 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
540 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300541 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
542 .len = VHT_MUMIMO_GROUPS_DATA_LEN
543 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200544 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = {
545 .type = NLA_EXACT_LEN_WARN,
546 .len = ETH_ALEN
547 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200548 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200549 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300550 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300551 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
552 .len = FILS_MAX_KEK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200553 [NL80211_ATTR_FILS_NONCES] = {
554 .type = NLA_EXACT_LEN_WARN,
555 .len = 2 * FILS_NONCE_LEN
556 },
Michael Braunce0ce132016-10-10 19:12:22 +0200557 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200558 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200559 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
560 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
561 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
562 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200563 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300564 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
565 .len = FILS_ERP_MAX_USERNAME_LEN },
566 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
567 .len = FILS_ERP_MAX_REALM_LEN },
568 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
569 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
570 .len = FILS_ERP_MAX_RRK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200571 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300572 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100573 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200574 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200575
576 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
577 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
578 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300579 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
580 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700581
582 [NL80211_ATTR_FTM_RESPONDER] = {
583 .type = NLA_NESTED,
584 .validation_data = nl80211_ftm_responder_policy,
585 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200586 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
587 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100588 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800589 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000590 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
591 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200592 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
John Crispin796e90f2019-07-30 18:37:00 +0200593 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
Johannes Berg55682962007-09-20 13:09:35 -0400594};
595
Johannes Berge31b8212010-10-05 19:39:30 +0200596/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000597static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200598 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200599 [NL80211_KEY_IDX] = { .type = NLA_U8 },
600 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200601 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200602 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
603 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200604 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100605 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100606 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100607};
608
609/* policy for the key default flags */
610static const struct nla_policy
611nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
612 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
613 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200614};
615
Johannes Bergf83ace32016-10-17 08:04:07 +0200616#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200617/* policy for WoWLAN attributes */
618static const struct nla_policy
619nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
620 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
621 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
622 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
623 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200624 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
625 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
626 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
627 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100628 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300629 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100630};
631
632static const struct nla_policy
633nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
634 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
635 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200636 [NL80211_WOWLAN_TCP_DST_MAC] = {
637 .type = NLA_EXACT_LEN_WARN,
638 .len = ETH_ALEN
639 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100640 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
641 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200642 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100643 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
644 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
645 },
646 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
647 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
648 },
649 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200650 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
651 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200652};
Johannes Bergf83ace32016-10-17 08:04:07 +0200653#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200654
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700655/* policy for coalesce rule attributes */
656static const struct nla_policy
657nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
658 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200659 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
660 NLA_POLICY_RANGE(NLA_U32,
661 NL80211_COALESCE_CONDITION_MATCH,
662 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700663 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
664};
665
Johannes Berge5497d72011-07-05 16:35:40 +0200666/* policy for GTK rekey offload attributes */
667static const struct nla_policy
668nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Johannes Berg180aa422019-05-28 14:19:07 +0200669 [NL80211_REKEY_DATA_KEK] = {
670 .type = NLA_EXACT_LEN_WARN,
671 .len = NL80211_KEK_LEN,
672 },
673 [NL80211_REKEY_DATA_KCK] = {
674 .type = NLA_EXACT_LEN_WARN,
675 .len = NL80211_KCK_LEN,
676 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200677 [NL80211_REKEY_DATA_REPLAY_CTR] = {
678 .type = NLA_EXACT_LEN_WARN,
679 .len = NL80211_REPLAY_CTR_LEN
680 },
Johannes Berge5497d72011-07-05 16:35:40 +0200681};
682
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300683static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530684nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
685 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
686 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
Arend van Spriele548a1c2019-08-02 13:31:02 +0200687 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530688 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
689};
690
691static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300692nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200693 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300694 .len = IEEE80211_MAX_SSID_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200695 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
696 .type = NLA_EXACT_LEN_WARN,
697 .len = ETH_ALEN
698 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700699 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530700 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
701 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300702};
703
Avraham Stern3b06d272015-10-12 09:51:34 +0300704static const struct nla_policy
705nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
706 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
707 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
708};
709
Arend van Spriel38de03d2016-03-02 20:37:18 +0100710static const struct nla_policy
711nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
712 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
713 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
714 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
715 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
716 },
717};
718
Ayala Bekera442b762016-09-20 17:31:15 +0300719/* policy for NAN function attributes */
720static const struct nla_policy
721nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
722 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300723 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300724 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
725 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
726 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
727 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
728 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
729 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200730 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
731 .type = NLA_EXACT_LEN_WARN,
732 .len = ETH_ALEN
733 },
Ayala Bekera442b762016-09-20 17:31:15 +0300734 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
735 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
736 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
737 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
738 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
739 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
740 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
741 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
742 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
743};
744
745/* policy for Service Response Filter attributes */
746static const struct nla_policy
747nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
748 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
749 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
750 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
751 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
752 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
753};
754
Peng Xuad670232017-10-03 23:21:51 +0300755/* policy for packet pattern attributes */
756static const struct nla_policy
757nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
758 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
759 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
760 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
761};
762
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200763int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
764 struct cfg80211_registered_device **rdev,
765 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100766{
Johannes Berg67748892010-10-04 21:14:06 +0200767 int err;
768
Johannes Berg97990a02013-04-19 01:02:55 +0200769 if (!cb->args[0]) {
Johannes Berg50508d92019-07-29 16:31:09 +0200770 struct nlattr **attrbuf;
771
772 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
773 GFP_KERNEL);
774 if (!attrbuf)
775 return -ENOMEM;
776
Johannes Berg8cb08172019-04-26 14:07:28 +0200777 err = nlmsg_parse_deprecated(cb->nlh,
778 GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg50508d92019-07-29 16:31:09 +0200779 attrbuf, nl80211_fam.maxattr,
Johannes Berg8cb08172019-04-26 14:07:28 +0200780 nl80211_policy, NULL);
Johannes Berg50508d92019-07-29 16:31:09 +0200781 if (err) {
782 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100783 return err;
Johannes Berg50508d92019-07-29 16:31:09 +0200784 }
Johannes Berg97990a02013-04-19 01:02:55 +0200785
Johannes Berg50508d92019-07-29 16:31:09 +0200786 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
787 attrbuf);
788 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100789 if (IS_ERR(*wdev))
790 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800791 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200792 /* 0 is the first index - add 1 to parse only once */
793 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200794 cb->args[1] = (*wdev)->identifier;
795 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200796 /* subtract the 1 again here */
797 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200798 struct wireless_dev *tmp;
799
Johannes Bergea90e0d2017-03-15 14:26:04 +0100800 if (!wiphy)
801 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800802 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200803 *wdev = NULL;
804
Johannes Berg53873f12016-05-03 16:52:04 +0300805 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200806 if (tmp->identifier == cb->args[1]) {
807 *wdev = tmp;
808 break;
809 }
810 }
Johannes Berg97990a02013-04-19 01:02:55 +0200811
Johannes Bergea90e0d2017-03-15 14:26:04 +0100812 if (!*wdev)
813 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200814 }
815
Johannes Berg67748892010-10-04 21:14:06 +0200816 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200817}
818
Johannes Berg55682962007-09-20 13:09:35 -0400819/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200820void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
821 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400822{
823 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000824 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400825}
826
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300827static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
828 const struct ieee80211_reg_rule *rule)
829{
830 int j;
831 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200832 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300833
834 if (!nl_wmm_rules)
835 goto nla_put_failure;
836
837 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200838 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300839
840 if (!nl_wmm_rule)
841 goto nla_put_failure;
842
843 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200844 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300845 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200846 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300847 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200848 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300849 nla_put_u16(msg, NL80211_WMMR_TXOP,
850 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300851 goto nla_put_failure;
852
853 nla_nest_end(msg, nl_wmm_rule);
854 }
855 nla_nest_end(msg, nl_wmm_rules);
856
857 return 0;
858
859nla_put_failure:
860 return -ENOBUFS;
861}
862
863static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100864 struct ieee80211_channel *chan,
865 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400866{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200867 /* Some channels must be completely excluded from the
868 * list to protect old user-space tools from breaking
869 */
870 if (!large && chan->flags &
871 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
872 return 0;
873
David S. Miller9360ffd2012-03-29 04:41:26 -0400874 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
875 chan->center_freq))
876 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400877
David S. Miller9360ffd2012-03-29 04:41:26 -0400878 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
879 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
880 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200881 if (chan->flags & IEEE80211_CHAN_NO_IR) {
882 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
883 goto nla_put_failure;
884 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
885 goto nla_put_failure;
886 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100887 if (chan->flags & IEEE80211_CHAN_RADAR) {
888 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
889 goto nla_put_failure;
890 if (large) {
891 u32 time;
892
893 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
894
895 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
896 chan->dfs_state))
897 goto nla_put_failure;
898 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
899 time))
900 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100901 if (nla_put_u32(msg,
902 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
903 chan->dfs_cac_ms))
904 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100905 }
906 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400907
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100908 if (large) {
909 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
910 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
911 goto nla_put_failure;
912 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
913 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
914 goto nla_put_failure;
915 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
916 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
917 goto nla_put_failure;
918 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
919 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
920 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200921 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
922 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
923 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300924 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
925 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200926 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200927 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
928 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
929 goto nla_put_failure;
930 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
931 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
932 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100933 }
934
David S. Miller9360ffd2012-03-29 04:41:26 -0400935 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
936 DBM_TO_MBM(chan->max_power)))
937 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400938
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300939 if (large) {
940 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300941 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300942
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200943 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300944 if (nl80211_msg_put_wmm_rules(msg, rule))
945 goto nla_put_failure;
946 }
947 }
948
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400949 return 0;
950
951 nla_put_failure:
952 return -ENOBUFS;
953}
954
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200955static bool nl80211_put_txq_stats(struct sk_buff *msg,
956 struct cfg80211_txq_stats *txqstats,
957 int attrtype)
958{
959 struct nlattr *txqattr;
960
961#define PUT_TXQVAL_U32(attr, memb) do { \
962 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
963 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
964 return false; \
965 } while (0)
966
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200967 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200968 if (!txqattr)
969 return false;
970
971 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
972 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
973 PUT_TXQVAL_U32(FLOWS, flows);
974 PUT_TXQVAL_U32(DROPS, drops);
975 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
976 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
977 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
978 PUT_TXQVAL_U32(COLLISIONS, collisions);
979 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
980 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
981 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
982 nla_nest_end(msg, txqattr);
983
984#undef PUT_TXQVAL_U32
985 return true;
986}
987
Johannes Berg55682962007-09-20 13:09:35 -0400988/* netlink command implementations */
989
Johannes Bergb9454e82009-07-08 13:29:08 +0200990struct key_parse {
991 struct key_params p;
992 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200993 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200994 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100995 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200996};
997
Johannes Berg768075e2017-11-13 15:35:06 +0100998static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
999 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +02001000{
1001 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +02001002 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1003 nl80211_key_policy,
1004 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +02001005 if (err)
1006 return err;
1007
1008 k->def = !!tb[NL80211_KEY_DEFAULT];
1009 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1010
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001011 if (k->def) {
1012 k->def_uni = true;
1013 k->def_multi = true;
1014 }
1015 if (k->defmgmt)
1016 k->def_multi = true;
1017
Johannes Bergb9454e82009-07-08 13:29:08 +02001018 if (tb[NL80211_KEY_IDX])
1019 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1020
1021 if (tb[NL80211_KEY_DATA]) {
1022 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1023 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1024 }
1025
1026 if (tb[NL80211_KEY_SEQ]) {
1027 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1028 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1029 }
1030
1031 if (tb[NL80211_KEY_CIPHER])
1032 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1033
Johannes Bergab0d76f2018-10-02 10:00:07 +02001034 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001035 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001036
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001037 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1038 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001039
Johannes Berg8cb08172019-04-26 14:07:28 +02001040 err = nla_parse_nested_deprecated(kdt,
1041 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1042 tb[NL80211_KEY_DEFAULT_TYPES],
1043 nl80211_key_default_policy,
1044 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001045 if (err)
1046 return err;
1047
1048 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1049 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1050 }
1051
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001052 if (tb[NL80211_KEY_MODE])
1053 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1054
Johannes Bergb9454e82009-07-08 13:29:08 +02001055 return 0;
1056}
1057
1058static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1059{
1060 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1061 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1062 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1063 }
1064
1065 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1066 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1067 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1068 }
1069
1070 if (info->attrs[NL80211_ATTR_KEY_IDX])
1071 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1072
1073 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1074 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1075
1076 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1077 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1078
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001079 if (k->def) {
1080 k->def_uni = true;
1081 k->def_multi = true;
1082 }
1083 if (k->defmgmt)
1084 k->def_multi = true;
1085
Johannes Bergab0d76f2018-10-02 10:00:07 +02001086 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001087 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001088
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001089 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1090 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001091 int err = nla_parse_nested_deprecated(kdt,
1092 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1093 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1094 nl80211_key_default_policy,
1095 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001096 if (err)
1097 return err;
1098
1099 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1100 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1101 }
1102
Johannes Bergb9454e82009-07-08 13:29:08 +02001103 return 0;
1104}
1105
1106static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1107{
1108 int err;
1109
1110 memset(k, 0, sizeof(*k));
1111 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001112 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001113
1114 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001115 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001116 else
1117 err = nl80211_parse_key_old(info, k);
1118
1119 if (err)
1120 return err;
1121
Johannes Berg768075e2017-11-13 15:35:06 +01001122 if (k->def && k->defmgmt) {
1123 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001124 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001125 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001126
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001127 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001128 if (k->def_uni || !k->def_multi) {
1129 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001130 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001131 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001132 }
1133
Johannes Bergb9454e82009-07-08 13:29:08 +02001134 if (k->idx != -1) {
1135 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001136 if (k->idx < 4 || k->idx > 5) {
1137 GENL_SET_ERR_MSG(info,
1138 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001139 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001140 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001141 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001142 if (k->idx < 0 || k->idx > 3) {
1143 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001144 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001145 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001146 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001147 if (k->idx < 0 || k->idx > 5) {
1148 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001149 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001150 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001151 }
1152 }
1153
1154 return 0;
1155}
1156
Johannes Bergfffd0932009-07-08 14:22:54 +02001157static struct cfg80211_cached_keys *
1158nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001159 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001160{
Johannes Berg768075e2017-11-13 15:35:06 +01001161 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001162 struct key_parse parse;
1163 struct nlattr *key;
1164 struct cfg80211_cached_keys *result;
1165 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001166 bool have_key = false;
1167
1168 nla_for_each_nested(key, keys, rem) {
1169 have_key = true;
1170 break;
1171 }
1172
1173 if (!have_key)
1174 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001175
1176 result = kzalloc(sizeof(*result), GFP_KERNEL);
1177 if (!result)
1178 return ERR_PTR(-ENOMEM);
1179
1180 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001181
1182 nla_for_each_nested(key, keys, rem) {
1183 memset(&parse, 0, sizeof(parse));
1184 parse.idx = -1;
1185
Johannes Berg768075e2017-11-13 15:35:06 +01001186 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001187 if (err)
1188 goto error;
1189 err = -EINVAL;
1190 if (!parse.p.key)
1191 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001192 if (parse.idx < 0 || parse.idx > 3) {
1193 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001194 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001195 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001196 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001197 if (def) {
1198 GENL_SET_ERR_MSG(info,
1199 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001200 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001201 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001202 def = 1;
1203 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001204 if (!parse.def_uni || !parse.def_multi)
1205 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001206 } else if (parse.defmgmt)
1207 goto error;
1208 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001209 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001210 if (err)
1211 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001212 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1213 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001214 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001215 err = -EINVAL;
1216 goto error;
1217 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001218 result->params[parse.idx].cipher = parse.p.cipher;
1219 result->params[parse.idx].key_len = parse.p.key_len;
1220 result->params[parse.idx].key = result->data[parse.idx];
1221 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301222
Johannes Berg386b1f22016-09-13 16:10:02 +02001223 /* must be WEP key if we got here */
1224 if (no_ht)
1225 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001226 }
1227
Johannes Bergf1c1f172016-09-13 17:08:23 +02001228 if (result->def < 0) {
1229 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001230 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001231 goto error;
1232 }
1233
Johannes Bergfffd0932009-07-08 14:22:54 +02001234 return result;
1235 error:
1236 kfree(result);
1237 return ERR_PTR(err);
1238}
1239
1240static int nl80211_key_allowed(struct wireless_dev *wdev)
1241{
1242 ASSERT_WDEV_LOCK(wdev);
1243
Johannes Bergfffd0932009-07-08 14:22:54 +02001244 switch (wdev->iftype) {
1245 case NL80211_IFTYPE_AP:
1246 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001247 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001248 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001249 break;
1250 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001251 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001252 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001253 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001254 return -ENOLINK;
1255 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001256 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001257 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001258 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001259 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001260 case NL80211_IFTYPE_P2P_DEVICE:
1261 case NL80211_IFTYPE_WDS:
1262 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001263 return -EINVAL;
1264 }
1265
1266 return 0;
1267}
1268
Jouni Malinen664834d2014-01-15 00:01:44 +02001269static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1270 struct nlattr *tb)
1271{
1272 struct ieee80211_channel *chan;
1273
1274 if (tb == NULL)
1275 return NULL;
1276 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1277 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1278 return NULL;
1279 return chan;
1280}
1281
Johannes Berg7527a782011-05-13 10:58:57 +02001282static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1283{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001284 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001285 int i;
1286
1287 if (!nl_modes)
1288 goto nla_put_failure;
1289
1290 i = 0;
1291 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001292 if ((ifmodes & 1) && nla_put_flag(msg, i))
1293 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001294 ifmodes >>= 1;
1295 i++;
1296 }
1297
1298 nla_nest_end(msg, nl_modes);
1299 return 0;
1300
1301nla_put_failure:
1302 return -ENOBUFS;
1303}
1304
1305static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001306 struct sk_buff *msg,
1307 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001308{
1309 struct nlattr *nl_combis;
1310 int i, j;
1311
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001312 nl_combis = nla_nest_start_noflag(msg,
1313 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001314 if (!nl_combis)
1315 goto nla_put_failure;
1316
1317 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1318 const struct ieee80211_iface_combination *c;
1319 struct nlattr *nl_combi, *nl_limits;
1320
1321 c = &wiphy->iface_combinations[i];
1322
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001323 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001324 if (!nl_combi)
1325 goto nla_put_failure;
1326
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001327 nl_limits = nla_nest_start_noflag(msg,
1328 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001329 if (!nl_limits)
1330 goto nla_put_failure;
1331
1332 for (j = 0; j < c->n_limits; j++) {
1333 struct nlattr *nl_limit;
1334
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001335 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001336 if (!nl_limit)
1337 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001338 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1339 c->limits[j].max))
1340 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001341 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1342 c->limits[j].types))
1343 goto nla_put_failure;
1344 nla_nest_end(msg, nl_limit);
1345 }
1346
1347 nla_nest_end(msg, nl_limits);
1348
David S. Miller9360ffd2012-03-29 04:41:26 -04001349 if (c->beacon_int_infra_match &&
1350 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1351 goto nla_put_failure;
1352 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1353 c->num_different_channels) ||
1354 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1355 c->max_interfaces))
1356 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001357 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001358 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1359 c->radar_detect_widths) ||
1360 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1361 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001362 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301363 if (c->beacon_int_min_gcd &&
1364 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1365 c->beacon_int_min_gcd))
1366 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001367
1368 nla_nest_end(msg, nl_combi);
1369 }
1370
1371 nla_nest_end(msg, nl_combis);
1372
1373 return 0;
1374nla_put_failure:
1375 return -ENOBUFS;
1376}
1377
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001379static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1380 struct sk_buff *msg)
1381{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001382 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001383 struct nlattr *nl_tcp;
1384
1385 if (!tcp)
1386 return 0;
1387
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001388 nl_tcp = nla_nest_start_noflag(msg,
1389 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001390 if (!nl_tcp)
1391 return -ENOBUFS;
1392
1393 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1394 tcp->data_payload_max))
1395 return -ENOBUFS;
1396
1397 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1398 tcp->data_payload_max))
1399 return -ENOBUFS;
1400
1401 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1402 return -ENOBUFS;
1403
1404 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1405 sizeof(*tcp->tok), tcp->tok))
1406 return -ENOBUFS;
1407
1408 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1409 tcp->data_interval_max))
1410 return -ENOBUFS;
1411
1412 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1413 tcp->wake_payload_max))
1414 return -ENOBUFS;
1415
1416 nla_nest_end(msg, nl_tcp);
1417 return 0;
1418}
1419
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001421 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001422 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423{
1424 struct nlattr *nl_wowlan;
1425
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001426 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 return 0;
1428
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001429 nl_wowlan = nla_nest_start_noflag(msg,
1430 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 if (!nl_wowlan)
1432 return -ENOBUFS;
1433
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001434 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001436 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001438 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001440 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001442 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001444 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001446 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001448 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1450 return -ENOBUFS;
1451
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001453 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001454 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1455 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1456 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1457 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 };
1459
1460 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1461 sizeof(pat), &pat))
1462 return -ENOBUFS;
1463 }
1464
Luciano Coelho75453cc2015-01-09 14:06:37 +02001465 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1466 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1467 rdev->wiphy.wowlan->max_nd_match_sets))
1468 return -ENOBUFS;
1469
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001471 return -ENOBUFS;
1472
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_nest_end(msg, nl_wowlan);
1474
1475 return 0;
1476}
1477#endif
1478
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001479static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001480 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001481{
1482 struct nl80211_coalesce_rule_support rule;
1483
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001484 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001485 return 0;
1486
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001487 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1488 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1489 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1490 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1491 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1492 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001493
1494 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1495 return -ENOBUFS;
1496
1497 return 0;
1498}
1499
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001500static int
1501nl80211_send_iftype_data(struct sk_buff *msg,
1502 const struct ieee80211_sband_iftype_data *iftdata)
1503{
1504 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1505
1506 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1507 iftdata->types_mask))
1508 return -ENOBUFS;
1509
1510 if (he_cap->has_he) {
1511 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1512 sizeof(he_cap->he_cap_elem.mac_cap_info),
1513 he_cap->he_cap_elem.mac_cap_info) ||
1514 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1515 sizeof(he_cap->he_cap_elem.phy_cap_info),
1516 he_cap->he_cap_elem.phy_cap_info) ||
1517 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1518 sizeof(he_cap->he_mcs_nss_supp),
1519 &he_cap->he_mcs_nss_supp) ||
1520 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1521 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1522 return -ENOBUFS;
1523 }
1524
1525 return 0;
1526}
1527
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1529 struct ieee80211_supported_band *sband)
1530{
1531 struct nlattr *nl_rates, *nl_rate;
1532 struct ieee80211_rate *rate;
1533 int i;
1534
1535 /* add HT info */
1536 if (sband->ht_cap.ht_supported &&
1537 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1538 sizeof(sband->ht_cap.mcs),
1539 &sband->ht_cap.mcs) ||
1540 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1541 sband->ht_cap.cap) ||
1542 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1543 sband->ht_cap.ampdu_factor) ||
1544 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1545 sband->ht_cap.ampdu_density)))
1546 return -ENOBUFS;
1547
1548 /* add VHT info */
1549 if (sband->vht_cap.vht_supported &&
1550 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1551 sizeof(sband->vht_cap.vht_mcs),
1552 &sband->vht_cap.vht_mcs) ||
1553 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1554 sband->vht_cap.cap)))
1555 return -ENOBUFS;
1556
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001557 if (sband->n_iftype_data) {
1558 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001559 nla_nest_start_noflag(msg,
1560 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001561 int err;
1562
1563 if (!nl_iftype_data)
1564 return -ENOBUFS;
1565
1566 for (i = 0; i < sband->n_iftype_data; i++) {
1567 struct nlattr *iftdata;
1568
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001569 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001570 if (!iftdata)
1571 return -ENOBUFS;
1572
1573 err = nl80211_send_iftype_data(msg,
1574 &sband->iftype_data[i]);
1575 if (err)
1576 return err;
1577
1578 nla_nest_end(msg, iftdata);
1579 }
1580
1581 nla_nest_end(msg, nl_iftype_data);
1582 }
1583
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03001584 /* add EDMG info */
1585 if (sband->edmg_cap.channels &&
1586 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1587 sband->edmg_cap.channels) ||
1588 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1589 sband->edmg_cap.bw_config)))
1590
1591 return -ENOBUFS;
1592
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001594 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 if (!nl_rates)
1596 return -ENOBUFS;
1597
1598 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001599 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 if (!nl_rate)
1601 return -ENOBUFS;
1602
1603 rate = &sband->bitrates[i];
1604 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1605 rate->bitrate))
1606 return -ENOBUFS;
1607 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1608 nla_put_flag(msg,
1609 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1610 return -ENOBUFS;
1611
1612 nla_nest_end(msg, nl_rate);
1613 }
1614
1615 nla_nest_end(msg, nl_rates);
1616
1617 return 0;
1618}
1619
1620static int
1621nl80211_send_mgmt_stypes(struct sk_buff *msg,
1622 const struct ieee80211_txrx_stypes *mgmt_stypes)
1623{
1624 u16 stypes;
1625 struct nlattr *nl_ftypes, *nl_ifs;
1626 enum nl80211_iftype ift;
1627 int i;
1628
1629 if (!mgmt_stypes)
1630 return 0;
1631
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001632 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001633 if (!nl_ifs)
1634 return -ENOBUFS;
1635
1636 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001637 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 if (!nl_ftypes)
1639 return -ENOBUFS;
1640 i = 0;
1641 stypes = mgmt_stypes[ift].tx;
1642 while (stypes) {
1643 if ((stypes & 1) &&
1644 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1645 (i << 4) | IEEE80211_FTYPE_MGMT))
1646 return -ENOBUFS;
1647 stypes >>= 1;
1648 i++;
1649 }
1650 nla_nest_end(msg, nl_ftypes);
1651 }
1652
1653 nla_nest_end(msg, nl_ifs);
1654
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001655 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001656 if (!nl_ifs)
1657 return -ENOBUFS;
1658
1659 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001660 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 if (!nl_ftypes)
1662 return -ENOBUFS;
1663 i = 0;
1664 stypes = mgmt_stypes[ift].rx;
1665 while (stypes) {
1666 if ((stypes & 1) &&
1667 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1668 (i << 4) | IEEE80211_FTYPE_MGMT))
1669 return -ENOBUFS;
1670 stypes >>= 1;
1671 i++;
1672 }
1673 nla_nest_end(msg, nl_ftypes);
1674 }
1675 nla_nest_end(msg, nl_ifs);
1676
1677 return 0;
1678}
1679
Johannes Berg17948992016-10-26 11:42:04 +02001680#define CMD(op, n) \
1681 do { \
1682 if (rdev->ops->op) { \
1683 i++; \
1684 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1685 goto nla_put_failure; \
1686 } \
1687 } while (0)
1688
1689static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1690 struct sk_buff *msg)
1691{
1692 int i = 0;
1693
1694 /*
1695 * do *NOT* add anything into this function, new things need to be
1696 * advertised only to new versions of userspace that can deal with
1697 * the split (and they can't possibly care about new features...
1698 */
1699 CMD(add_virtual_intf, NEW_INTERFACE);
1700 CMD(change_virtual_intf, SET_INTERFACE);
1701 CMD(add_key, NEW_KEY);
1702 CMD(start_ap, START_AP);
1703 CMD(add_station, NEW_STATION);
1704 CMD(add_mpath, NEW_MPATH);
1705 CMD(update_mesh_config, SET_MESH_CONFIG);
1706 CMD(change_bss, SET_BSS);
1707 CMD(auth, AUTHENTICATE);
1708 CMD(assoc, ASSOCIATE);
1709 CMD(deauth, DEAUTHENTICATE);
1710 CMD(disassoc, DISASSOCIATE);
1711 CMD(join_ibss, JOIN_IBSS);
1712 CMD(join_mesh, JOIN_MESH);
1713 CMD(set_pmksa, SET_PMKSA);
1714 CMD(del_pmksa, DEL_PMKSA);
1715 CMD(flush_pmksa, FLUSH_PMKSA);
1716 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1717 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1718 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1719 CMD(mgmt_tx, FRAME);
1720 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1721 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1722 i++;
1723 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1724 goto nla_put_failure;
1725 }
1726 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1727 rdev->ops->join_mesh) {
1728 i++;
1729 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1730 goto nla_put_failure;
1731 }
1732 CMD(set_wds_peer, SET_WDS_PEER);
1733 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1734 CMD(tdls_mgmt, TDLS_MGMT);
1735 CMD(tdls_oper, TDLS_OPER);
1736 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001737 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001738 CMD(sched_scan_start, START_SCHED_SCAN);
1739 CMD(probe_client, PROBE_CLIENT);
1740 CMD(set_noack_map, SET_NOACK_MAP);
1741 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1742 i++;
1743 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1744 goto nla_put_failure;
1745 }
1746 CMD(start_p2p_device, START_P2P_DEVICE);
1747 CMD(set_mcast_rate, SET_MCAST_RATE);
1748#ifdef CONFIG_NL80211_TESTMODE
1749 CMD(testmode_cmd, TESTMODE);
1750#endif
1751
1752 if (rdev->ops->connect || rdev->ops->auth) {
1753 i++;
1754 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1755 goto nla_put_failure;
1756 }
1757
1758 if (rdev->ops->disconnect || rdev->ops->deauth) {
1759 i++;
1760 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1761 goto nla_put_failure;
1762 }
1763
1764 return i;
1765 nla_put_failure:
1766 return -ENOBUFS;
1767}
1768
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001769static int
1770nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1771 struct sk_buff *msg)
1772{
1773 struct nlattr *ftm;
1774
1775 if (!cap->ftm.supported)
1776 return 0;
1777
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001778 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001779 if (!ftm)
1780 return -ENOBUFS;
1781
1782 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1783 return -ENOBUFS;
1784 if (cap->ftm.non_asap &&
1785 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1786 return -ENOBUFS;
1787 if (cap->ftm.request_lci &&
1788 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1789 return -ENOBUFS;
1790 if (cap->ftm.request_civicloc &&
1791 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1792 return -ENOBUFS;
1793 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1794 cap->ftm.preambles))
1795 return -ENOBUFS;
1796 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1797 cap->ftm.bandwidths))
1798 return -ENOBUFS;
1799 if (cap->ftm.max_bursts_exponent >= 0 &&
1800 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1801 cap->ftm.max_bursts_exponent))
1802 return -ENOBUFS;
1803 if (cap->ftm.max_ftms_per_burst &&
1804 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1805 cap->ftm.max_ftms_per_burst))
1806 return -ENOBUFS;
1807
1808 nla_nest_end(msg, ftm);
1809 return 0;
1810}
1811
1812static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1813 struct sk_buff *msg)
1814{
1815 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1816 struct nlattr *pmsr, *caps;
1817
1818 if (!cap)
1819 return 0;
1820
1821 /*
1822 * we don't need to clean up anything here since the caller
1823 * will genlmsg_cancel() if we fail
1824 */
1825
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001826 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001827 if (!pmsr)
1828 return -ENOBUFS;
1829
1830 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1831 return -ENOBUFS;
1832
1833 if (cap->report_ap_tsf &&
1834 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1835 return -ENOBUFS;
1836
1837 if (cap->randomize_mac_addr &&
1838 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1839 return -ENOBUFS;
1840
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001841 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001842 if (!caps)
1843 return -ENOBUFS;
1844
1845 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1846 return -ENOBUFS;
1847
1848 nla_nest_end(msg, caps);
1849 nla_nest_end(msg, pmsr);
1850
1851 return 0;
1852}
1853
Johannes Berg86e8cf92013-06-19 10:57:22 +02001854struct nl80211_dump_wiphy_state {
1855 s64 filter_wiphy;
1856 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301857 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 bool split;
1859};
1860
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001861static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001862 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001863 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001864 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001865{
1866 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001867 struct nlattr *nl_bands, *nl_band;
1868 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001869 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001870 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001871 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001872 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001873 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001874 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001875 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001876
Johannes Berg3bb20552014-05-26 13:52:25 +02001877 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001878 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001879 return -ENOBUFS;
1880
Johannes Berg86e8cf92013-06-19 10:57:22 +02001881 if (WARN_ON(!state))
1882 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001883
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001884 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001885 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001886 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001887 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001888 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001889 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001890
Johannes Berg3bb20552014-05-26 13:52:25 +02001891 if (cmd != NL80211_CMD_NEW_WIPHY)
1892 goto finish;
1893
Johannes Berg86e8cf92013-06-19 10:57:22 +02001894 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001895 case 0:
1896 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001897 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001898 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001899 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001900 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001901 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001903 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001904 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001905 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001906 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001907 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001908 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001909 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001910 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001911 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001912 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001913 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001914 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001915 rdev->wiphy.max_match_sets) ||
1916 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1917 rdev->wiphy.max_sched_scan_plans) ||
1918 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1919 rdev->wiphy.max_sched_scan_plan_interval) ||
1920 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1921 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001922 goto nla_put_failure;
1923
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001924 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001925 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1926 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001927 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001928 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1929 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001930 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001931 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1932 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001933 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001934 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1935 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001936 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001937 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1938 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001939 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001940 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001941 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001942 state->split_start++;
1943 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001944 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001945 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001946 case 1:
1947 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001948 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1949 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001950 goto nla_put_failure;
1951
Johannes Berg3713b4e2013-02-14 16:19:38 +01001952 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001953 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001954 goto nla_put_failure;
1955
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001956 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001957 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1958 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001959
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001961 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001962 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001963 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001964 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001965
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001966 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001967 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001968 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001969 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001970
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001971 if ((rdev->wiphy.available_antennas_tx ||
1972 rdev->wiphy.available_antennas_rx) &&
1973 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001974 u32 tx_ant = 0, rx_ant = 0;
1975 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001976
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001977 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001978 if (!res) {
1979 if (nla_put_u32(msg,
1980 NL80211_ATTR_WIPHY_ANTENNA_TX,
1981 tx_ant) ||
1982 nla_put_u32(msg,
1983 NL80211_ATTR_WIPHY_ANTENNA_RX,
1984 rx_ant))
1985 goto nla_put_failure;
1986 }
Johannes Bergee688b002008-01-24 19:38:39 +01001987 }
1988
Johannes Berg86e8cf92013-06-19 10:57:22 +02001989 state->split_start++;
1990 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001991 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001992 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001993 case 2:
1994 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001995 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001996 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001997 state->split_start++;
1998 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001999 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002000 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002001 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002002 nl_bands = nla_nest_start_noflag(msg,
2003 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002004 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01002005 goto nla_put_failure;
2006
Johannes Berg86e8cf92013-06-19 10:57:22 +02002007 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002008 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002009 struct ieee80211_supported_band *sband;
2010
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002011 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01002012
2013 if (!sband)
2014 continue;
2015
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002016 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002017 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01002018 goto nla_put_failure;
2019
Johannes Berg86e8cf92013-06-19 10:57:22 +02002020 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002021 case 0:
2022 if (nl80211_send_band_rateinfo(msg, sband))
2023 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002024 state->chan_start++;
2025 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002026 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002027 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002028 default:
2029 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002030 nl_freqs = nla_nest_start_noflag(msg,
2031 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002032 if (!nl_freqs)
2033 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002034
Johannes Berg86e8cf92013-06-19 10:57:22 +02002035 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002036 i < sband->n_channels;
2037 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002038 nl_freq = nla_nest_start_noflag(msg,
2039 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002040 if (!nl_freq)
2041 goto nla_put_failure;
2042
2043 chan = &sband->channels[i];
2044
Johannes Berg86e8cf92013-06-19 10:57:22 +02002045 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002046 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002047 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002048 goto nla_put_failure;
2049
2050 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002051 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002052 break;
2053 }
2054 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002055 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002056 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002057 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002058 nla_nest_end(msg, nl_freqs);
2059 }
2060
2061 nla_nest_end(msg, nl_band);
2062
Johannes Berg86e8cf92013-06-19 10:57:22 +02002063 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002064 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002065 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002066 band--;
2067 break;
2068 }
Johannes Bergee688b002008-01-24 19:38:39 +01002069 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002070 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002071
Johannes Berg57fbcce2016-04-12 15:56:15 +02002072 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002073 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002074 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002075 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002076
Johannes Berg3713b4e2013-02-14 16:19:38 +01002077 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002078 if (state->band_start == 0 && state->chan_start == 0)
2079 state->split_start++;
2080 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002081 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002082 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002083 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002084 nl_cmds = nla_nest_start_noflag(msg,
2085 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002086 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002087 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002088
Johannes Berg17948992016-10-26 11:42:04 +02002089 i = nl80211_add_commands_unsplit(rdev, msg);
2090 if (i < 0)
2091 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002092 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002093 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2094 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002095 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002096 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002097 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002098 if (rdev->wiphy.features &
2099 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002100 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002101 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002102 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Matthew Wang70109982019-08-22 10:48:06 -07002103 CMD(update_ft_ies, UPDATE_FT_IES);
Arend van Spriel5de17982013-04-18 15:49:00 +02002104 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002105#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002106
Johannes Berg3713b4e2013-02-14 16:19:38 +01002107 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002108 state->split_start++;
2109 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002110 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002111 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002112 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002113 if (rdev->ops->remain_on_channel &&
2114 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002115 nla_put_u32(msg,
2116 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002117 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002118 goto nla_put_failure;
2119
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002120 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002121 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2122 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002123
Johannes Berg3713b4e2013-02-14 16:19:38 +01002124 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2125 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002126 state->split_start++;
2127 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002128 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002129 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002130 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002131#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002132 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002133 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002134 state->split_start++;
2135 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002136 break;
2137#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002138 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002139#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002140 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002141 case 7:
2142 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002143 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002144 goto nla_put_failure;
2145
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002146 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002147 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002148 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002149
Johannes Berg86e8cf92013-06-19 10:57:22 +02002150 state->split_start++;
2151 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002152 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002153 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002154 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002155 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002156 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002157 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002158 goto nla_put_failure;
2159
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002160 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002161 /*
2162 * We can only add the per-channel limit information if the
2163 * dump is split, otherwise it makes it too big. Therefore
2164 * only advertise it in that case.
2165 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002166 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002167 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2168 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002169 goto nla_put_failure;
2170
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002171 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002172 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002173 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2174 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002175 goto nla_put_failure;
2176
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002177 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2178 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002179 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002180 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002181 goto nla_put_failure;
2182
2183 /*
2184 * Any information below this point is only available to
2185 * applications that can deal with it being split. This
2186 * helps ensure that newly added capabilities don't break
2187 * older tools by overrunning their buffers.
2188 *
2189 * We still increment split_start so that in the split
2190 * case we'll continue with more data in the next round,
2191 * but break unconditionally so unsplit data stops here.
2192 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002193 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002194 break;
2195 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002196 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002197 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002198 rdev->wiphy.extended_capabilities_len,
2199 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002200 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002201 rdev->wiphy.extended_capabilities_len,
2202 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002203 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002204
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002205 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002206 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002207 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2208 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002209 goto nla_put_failure;
2210
Denis Kenziorae6fa4d2019-07-22 06:33:12 -05002211 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2212 rdev->wiphy.perm_addr))
2213 goto nla_put_failure;
2214
2215 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2216 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2217 rdev->wiphy.addr_mask))
2218 goto nla_put_failure;
2219
2220 if (rdev->wiphy.n_addresses > 1) {
2221 void *attr;
2222
2223 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2224 if (!attr)
2225 goto nla_put_failure;
2226
2227 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2228 if (nla_put(msg, i + 1, ETH_ALEN,
2229 rdev->wiphy.addresses[i].addr))
2230 goto nla_put_failure;
2231
2232 nla_nest_end(msg, attr);
2233 }
2234
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002235 state->split_start++;
2236 break;
2237 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002238 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002239 goto nla_put_failure;
2240
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002241 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002242 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2243 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2244 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002245
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002246 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002247 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002248 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002249 goto nla_put_failure;
2250
Johannes Bergad7e7182013-11-13 13:37:47 +01002251 state->split_start++;
2252 break;
2253 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002254 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002255 const struct nl80211_vendor_cmd_info *info;
2256 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002257
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002258 nested = nla_nest_start_noflag(msg,
2259 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002260 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002261 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002262
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002263 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2264 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002265 if (nla_put(msg, i + 1, sizeof(*info), info))
2266 goto nla_put_failure;
2267 }
2268 nla_nest_end(msg, nested);
2269 }
2270
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002271 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002272 const struct nl80211_vendor_cmd_info *info;
2273 struct nlattr *nested;
2274
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002275 nested = nla_nest_start_noflag(msg,
2276 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002277 if (!nested)
2278 goto nla_put_failure;
2279
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002280 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2281 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002282 if (nla_put(msg, i + 1, sizeof(*info), info))
2283 goto nla_put_failure;
2284 }
2285 nla_nest_end(msg, nested);
2286 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002287 state->split_start++;
2288 break;
2289 case 12:
2290 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2291 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2292 rdev->wiphy.max_num_csa_counters))
2293 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002294
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002295 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2296 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2297 goto nla_put_failure;
2298
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002299 if (rdev->wiphy.max_sched_scan_reqs &&
2300 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2301 rdev->wiphy.max_sched_scan_reqs))
2302 goto nla_put_failure;
2303
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002304 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2305 sizeof(rdev->wiphy.ext_features),
2306 rdev->wiphy.ext_features))
2307 goto nla_put_failure;
2308
Arend van Spriel38de03d2016-03-02 20:37:18 +01002309 if (rdev->wiphy.bss_select_support) {
2310 struct nlattr *nested;
2311 u32 bss_select_support = rdev->wiphy.bss_select_support;
2312
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002313 nested = nla_nest_start_noflag(msg,
2314 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002315 if (!nested)
2316 goto nla_put_failure;
2317
2318 i = 0;
2319 while (bss_select_support) {
2320 if ((bss_select_support & 1) &&
2321 nla_put_flag(msg, i))
2322 goto nla_put_failure;
2323 i++;
2324 bss_select_support >>= 1;
2325 }
2326 nla_nest_end(msg, nested);
2327 }
2328
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302329 state->split_start++;
2330 break;
2331 case 13:
2332 if (rdev->wiphy.num_iftype_ext_capab &&
2333 rdev->wiphy.iftype_ext_capab) {
2334 struct nlattr *nested_ext_capab, *nested;
2335
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002336 nested = nla_nest_start_noflag(msg,
2337 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302338 if (!nested)
2339 goto nla_put_failure;
2340
2341 for (i = state->capa_start;
2342 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2343 const struct wiphy_iftype_ext_capab *capab;
2344
2345 capab = &rdev->wiphy.iftype_ext_capab[i];
2346
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002347 nested_ext_capab = nla_nest_start_noflag(msg,
2348 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302349 if (!nested_ext_capab ||
2350 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2351 capab->iftype) ||
2352 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2353 capab->extended_capabilities_len,
2354 capab->extended_capabilities) ||
2355 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2356 capab->extended_capabilities_len,
2357 capab->extended_capabilities_mask))
2358 goto nla_put_failure;
2359
2360 nla_nest_end(msg, nested_ext_capab);
2361 if (state->split)
2362 break;
2363 }
2364 nla_nest_end(msg, nested);
2365 if (i < rdev->wiphy.num_iftype_ext_capab) {
2366 state->capa_start = i + 1;
2367 break;
2368 }
2369 }
2370
Luca Coelho85859892017-02-08 15:00:34 +02002371 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2372 rdev->wiphy.nan_supported_bands))
2373 goto nla_put_failure;
2374
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002375 if (wiphy_ext_feature_isset(&rdev->wiphy,
2376 NL80211_EXT_FEATURE_TXQS)) {
2377 struct cfg80211_txq_stats txqstats = {};
2378 int res;
2379
2380 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2381 if (!res &&
2382 !nl80211_put_txq_stats(msg, &txqstats,
2383 NL80211_ATTR_TXQ_STATS))
2384 goto nla_put_failure;
2385
2386 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2387 rdev->wiphy.txq_limit))
2388 goto nla_put_failure;
2389 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2390 rdev->wiphy.txq_memory_limit))
2391 goto nla_put_failure;
2392 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2393 rdev->wiphy.txq_quantum))
2394 goto nla_put_failure;
2395 }
2396
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002397 state->split_start++;
2398 break;
2399 case 14:
2400 if (nl80211_send_pmsr_capa(rdev, msg))
2401 goto nla_put_failure;
2402
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302403 state->split_start++;
2404 break;
2405 case 15:
2406 if (rdev->wiphy.akm_suites &&
2407 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2408 sizeof(u32) * rdev->wiphy.n_akm_suites,
2409 rdev->wiphy.akm_suites))
2410 goto nla_put_failure;
2411
Johannes Berg3713b4e2013-02-14 16:19:38 +01002412 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002413 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002414 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002415 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002416 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002417 genlmsg_end(msg, hdr);
2418 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002419
2420 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002421 genlmsg_cancel(msg, hdr);
2422 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002423}
2424
Johannes Berg86e8cf92013-06-19 10:57:22 +02002425static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2426 struct netlink_callback *cb,
2427 struct nl80211_dump_wiphy_state *state)
2428{
Johannes Berg50508d92019-07-29 16:31:09 +02002429 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2430 int ret;
2431
2432 if (!tb)
2433 return -ENOMEM;
2434
2435 ret = nlmsg_parse_deprecated(cb->nlh,
2436 GENL_HDRLEN + nl80211_fam.hdrsize,
2437 tb, nl80211_fam.maxattr,
2438 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002439 /* ignore parse errors for backward compatibility */
Johannes Berg50508d92019-07-29 16:31:09 +02002440 if (ret) {
2441 ret = 0;
2442 goto out;
2443 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002444
2445 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2446 if (tb[NL80211_ATTR_WIPHY])
2447 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2448 if (tb[NL80211_ATTR_WDEV])
2449 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2450 if (tb[NL80211_ATTR_IFINDEX]) {
2451 struct net_device *netdev;
2452 struct cfg80211_registered_device *rdev;
2453 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2454
Ying Xue7f2b8562014-01-15 10:23:45 +08002455 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg50508d92019-07-29 16:31:09 +02002456 if (!netdev) {
2457 ret = -ENODEV;
2458 goto out;
2459 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002460 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002461 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002462 netdev->ieee80211_ptr->wiphy);
2463 state->filter_wiphy = rdev->wiphy_idx;
2464 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002465 }
2466
Johannes Berg50508d92019-07-29 16:31:09 +02002467 ret = 0;
2468out:
2469 kfree(tb);
2470 return ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002471}
2472
Johannes Berg55682962007-09-20 13:09:35 -04002473static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2474{
Johannes Berg645e77d2013-03-01 14:03:49 +01002475 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002476 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002477 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002478
Johannes Berg5fe231e2013-05-08 21:45:15 +02002479 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002480 if (!state) {
2481 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002482 if (!state) {
2483 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002484 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002485 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002486 state->filter_wiphy = -1;
2487 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2488 if (ret) {
2489 kfree(state);
2490 rtnl_unlock();
2491 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002492 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002493 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002494 }
2495
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002496 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2497 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002498 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002499 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002500 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002501 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002502 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002503 continue;
2504 /* attempt to fit multiple wiphy data chunks into the skb */
2505 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002506 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2507 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002508 NETLINK_CB(cb->skb).portid,
2509 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002510 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002511 if (ret < 0) {
2512 /*
2513 * If sending the wiphy data didn't fit (ENOBUFS
2514 * or EMSGSIZE returned), this SKB is still
2515 * empty (so it's not too big because another
2516 * wiphy dataset is already in the skb) and
2517 * we've not tried to adjust the dump allocation
2518 * yet ... then adjust the alloc size to be
2519 * bigger, and return 1 but with the empty skb.
2520 * This results in an empty message being RX'ed
2521 * in userspace, but that is ignored.
2522 *
2523 * We can then retry with the larger buffer.
2524 */
2525 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002526 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002527 cb->min_dump_alloc < 4096) {
2528 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002529 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002530 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002531 return 1;
2532 }
2533 idx--;
2534 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002535 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002536 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002537 break;
Johannes Berg55682962007-09-20 13:09:35 -04002538 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002539 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002540
Johannes Berg86e8cf92013-06-19 10:57:22 +02002541 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002542
2543 return skb->len;
2544}
2545
Johannes Berg86e8cf92013-06-19 10:57:22 +02002546static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2547{
2548 kfree((void *)cb->args[0]);
2549 return 0;
2550}
2551
Johannes Berg55682962007-09-20 13:09:35 -04002552static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2553{
2554 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002556 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002557
Johannes Berg645e77d2013-03-01 14:03:49 +01002558 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002559 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002560 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002561
Johannes Berg3bb20552014-05-26 13:52:25 +02002562 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2563 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002564 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002565 nlmsg_free(msg);
2566 return -ENOBUFS;
2567 }
Johannes Berg55682962007-09-20 13:09:35 -04002568
Johannes Berg134e6372009-07-10 09:51:34 +00002569 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002570}
2571
Jouni Malinen31888482008-10-30 16:59:24 +02002572static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2573 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2574 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2575 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2576 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2577 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2578};
2579
2580static int parse_txq_params(struct nlattr *tb[],
2581 struct ieee80211_txq_params *txq_params)
2582{
Dan Williams259d8c12018-01-29 17:03:15 -08002583 u8 ac;
2584
Johannes Berga3304b02012-03-28 11:04:24 +02002585 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002586 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2587 !tb[NL80211_TXQ_ATTR_AIFS])
2588 return -EINVAL;
2589
Dan Williams259d8c12018-01-29 17:03:15 -08002590 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002591 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2592 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2593 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2594 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2595
Dan Williams259d8c12018-01-29 17:03:15 -08002596 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002597 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002598 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002599 return 0;
2600}
2601
Johannes Bergf444de02010-05-05 15:25:02 +02002602static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2603{
2604 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002605 * You can only set the channel explicitly for WDS interfaces,
2606 * all others have their channel managed via their respective
2607 * "establish a connection" command (connect, join, ...)
2608 *
2609 * For AP/GO and mesh mode, the channel can be set with the
2610 * channel userspace API, but is only stored and passed to the
2611 * low-level driver when the AP starts or the mesh is joined.
2612 * This is for backward compatibility, userspace can also give
2613 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002614 *
2615 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002616 * whatever else is going on, so they have their own special
2617 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002618 */
2619 return !wdev ||
2620 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002621 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002622 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2623 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002624}
2625
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002626int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2627 struct genl_info *info,
2628 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002629{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002630 struct netlink_ext_ack *extack = info->extack;
2631 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302632 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002633
Johannes Berg49f9cf02018-10-01 11:55:09 +02002634 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002635 return -EINVAL;
2636
Johannes Berg49f9cf02018-10-01 11:55:09 +02002637 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002638
2639 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002640 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2641 chandef->center_freq1 = control_freq;
2642 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002643
2644 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002645 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2646 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2647 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002648 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002649 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002650
Johannes Berg49f9cf02018-10-01 11:55:09 +02002651 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002652 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002653
Johannes Berg49f9cf02018-10-01 11:55:09 +02002654 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002655
2656 switch (chantype) {
2657 case NL80211_CHAN_NO_HT:
2658 case NL80211_CHAN_HT20:
2659 case NL80211_CHAN_HT40PLUS:
2660 case NL80211_CHAN_HT40MINUS:
2661 cfg80211_chandef_create(chandef, chandef->chan,
2662 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002663 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002664 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2665 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2666 NL_SET_ERR_MSG_ATTR(extack,
2667 attrs[NL80211_ATTR_CENTER_FREQ1],
2668 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002669 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002670 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002671 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002672 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2673 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2674 NL_SET_ERR_MSG_ATTR(extack,
2675 attrs[NL80211_ATTR_CENTER_FREQ2],
2676 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002677 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002678 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002679 break;
2680 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002681 NL_SET_ERR_MSG_ATTR(extack,
2682 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2683 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002684 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002685 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002686 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002687 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002688 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2689 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002690 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002691 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2692 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002693 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002694 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002695 }
2696
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03002697 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2698 chandef->edmg.channels =
2699 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2700
2701 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2702 chandef->edmg.bw_config =
2703 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2704 } else {
2705 chandef->edmg.bw_config = 0;
2706 chandef->edmg.channels = 0;
2707 }
2708
Johannes Berg49f9cf02018-10-01 11:55:09 +02002709 if (!cfg80211_chandef_valid(chandef)) {
2710 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002711 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002712 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002713
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002714 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002715 IEEE80211_CHAN_DISABLED)) {
2716 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002717 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002718 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002719
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002720 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2721 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002722 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2723 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002724 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002725 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002726
Johannes Berg683b6d32012-11-08 21:25:48 +01002727 return 0;
2728}
2729
Johannes Bergf444de02010-05-05 15:25:02 +02002730static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002731 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002732 struct genl_info *info)
2733{
Johannes Berg683b6d32012-11-08 21:25:48 +01002734 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002735 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002736 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002737 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002738
Jouni Malinene16821b2014-04-28 11:22:08 +03002739 if (dev)
2740 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002741 if (!nl80211_can_set_dev_channel(wdev))
2742 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002743 if (wdev)
2744 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002745
Johannes Berg683b6d32012-11-08 21:25:48 +01002746 result = nl80211_parse_chandef(rdev, info, &chandef);
2747 if (result)
2748 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002749
Johannes Berge8c9bd52012-06-06 08:18:22 +02002750 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002751 case NL80211_IFTYPE_AP:
2752 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002753 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2754 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002755 result = -EINVAL;
2756 break;
2757 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002758 if (wdev->beacon_interval) {
2759 if (!dev || !rdev->ops->set_ap_chanwidth ||
2760 !(rdev->wiphy.features &
2761 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2762 result = -EBUSY;
2763 break;
2764 }
2765
2766 /* Only allow dynamic channel width changes */
2767 if (chandef.chan != wdev->preset_chandef.chan) {
2768 result = -EBUSY;
2769 break;
2770 }
2771 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2772 if (result)
2773 break;
2774 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002775 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002776 result = 0;
2777 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002778 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002779 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002780 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002781 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002782 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002783 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002784 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002785 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002786 }
Johannes Bergf444de02010-05-05 15:25:02 +02002787
2788 return result;
2789}
2790
2791static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2792{
Johannes Berg4c476992010-10-04 21:36:35 +02002793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2794 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002795
Jouni Malinene16821b2014-04-28 11:22:08 +03002796 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002797}
2798
Bill Jordane8347eb2010-10-01 13:54:28 -04002799static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2800{
Johannes Berg43b19952010-10-07 13:10:30 +02002801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2802 struct net_device *dev = info->user_ptr[1];
2803 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002804 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002805
2806 if (!info->attrs[NL80211_ATTR_MAC])
2807 return -EINVAL;
2808
Johannes Berg43b19952010-10-07 13:10:30 +02002809 if (netif_running(dev))
2810 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002811
Johannes Berg43b19952010-10-07 13:10:30 +02002812 if (!rdev->ops->set_wds_peer)
2813 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002814
Johannes Berg43b19952010-10-07 13:10:30 +02002815 if (wdev->iftype != NL80211_IFTYPE_WDS)
2816 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002817
2818 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002819 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002820}
2821
Johannes Berg55682962007-09-20 13:09:35 -04002822static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2823{
2824 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002825 struct net_device *netdev = NULL;
2826 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002827 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002828 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002829 u32 changed;
2830 u8 retry_short = 0, retry_long = 0;
2831 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002832 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002833 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002834
Johannes Berg5fe231e2013-05-08 21:45:15 +02002835 ASSERT_RTNL();
2836
Johannes Bergf444de02010-05-05 15:25:02 +02002837 /*
2838 * Try to find the wiphy and netdev. Normally this
2839 * function shouldn't need the netdev, but this is
2840 * done for backward compatibility -- previously
2841 * setting the channel was done per wiphy, but now
2842 * it is per netdev. Previous userland like hostapd
2843 * also passed a netdev to set_wiphy, so that it is
2844 * possible to let that go to the right netdev!
2845 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002846
Johannes Bergf444de02010-05-05 15:25:02 +02002847 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2848 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2849
Ying Xue7f2b8562014-01-15 10:23:45 +08002850 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002851 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002852 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002853 else
Johannes Bergf444de02010-05-05 15:25:02 +02002854 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002855 }
2856
Johannes Bergf444de02010-05-05 15:25:02 +02002857 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002858 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2859 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002860 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002861 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002862 wdev = NULL;
2863 netdev = NULL;
2864 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002865 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002866 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002867
2868 /*
2869 * end workaround code, by now the rdev is available
2870 * and locked, and wdev may or may not be NULL.
2871 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002872
2873 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002874 result = cfg80211_dev_rename(
2875 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002876
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002877 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002878 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002879
Jouni Malinen31888482008-10-30 16:59:24 +02002880 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2881 struct ieee80211_txq_params txq_params;
2882 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2883
Ying Xue7f2b8562014-01-15 10:23:45 +08002884 if (!rdev->ops->set_txq_params)
2885 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002886
Ying Xue7f2b8562014-01-15 10:23:45 +08002887 if (!netdev)
2888 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002889
Johannes Berg133a3ff2011-11-03 14:50:13 +01002890 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002891 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2892 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002893
Ying Xue7f2b8562014-01-15 10:23:45 +08002894 if (!netif_running(netdev))
2895 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002896
Jouni Malinen31888482008-10-30 16:59:24 +02002897 nla_for_each_nested(nl_txq_params,
2898 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2899 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02002900 result = nla_parse_nested_deprecated(tb,
2901 NL80211_TXQ_ATTR_MAX,
2902 nl_txq_params,
2903 txq_params_policy,
2904 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002905 if (result)
2906 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002907 result = parse_txq_params(tb, &txq_params);
2908 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002909 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002910
Hila Gonene35e4d22012-06-27 17:19:42 +03002911 result = rdev_set_txq_params(rdev, netdev,
2912 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002913 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002914 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002915 }
2916 }
2917
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002918 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002919 result = __nl80211_set_channel(
2920 rdev,
2921 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2922 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002923 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002924 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002925 }
2926
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002927 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002928 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002929 enum nl80211_tx_power_setting type;
2930 int idx, mbm = 0;
2931
Johannes Bergc8442112012-10-24 10:17:18 +02002932 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2933 txp_wdev = NULL;
2934
Ying Xue7f2b8562014-01-15 10:23:45 +08002935 if (!rdev->ops->set_tx_power)
2936 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002937
2938 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2939 type = nla_get_u32(info->attrs[idx]);
2940
2941 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002942 (type != NL80211_TX_POWER_AUTOMATIC))
2943 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002944
2945 if (type != NL80211_TX_POWER_AUTOMATIC) {
2946 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2947 mbm = nla_get_u32(info->attrs[idx]);
2948 }
2949
Johannes Bergc8442112012-10-24 10:17:18 +02002950 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002951 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002952 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002953 }
2954
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002955 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2956 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2957 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002958
Bruno Randolf7f531e02010-12-16 11:30:22 +09002959 if ((!rdev->wiphy.available_antennas_tx &&
2960 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002961 !rdev->ops->set_antenna)
2962 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002963
2964 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2965 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2966
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002967 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002968 * available antenna masks, except for the "all" mask */
2969 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002970 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2971 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002972
Bruno Randolf7f531e02010-12-16 11:30:22 +09002973 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2974 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002975
Hila Gonene35e4d22012-06-27 17:19:42 +03002976 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002977 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002978 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002979 }
2980
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002981 changed = 0;
2982
2983 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2984 retry_short = nla_get_u8(
2985 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002986
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002987 changed |= WIPHY_PARAM_RETRY_SHORT;
2988 }
2989
2990 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2991 retry_long = nla_get_u8(
2992 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002993
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002994 changed |= WIPHY_PARAM_RETRY_LONG;
2995 }
2996
2997 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2998 frag_threshold = nla_get_u32(
2999 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003000 if (frag_threshold < 256)
3001 return -EINVAL;
3002
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003003 if (frag_threshold != (u32) -1) {
3004 /*
3005 * Fragments (apart from the last one) are required to
3006 * have even length. Make the fragmentation code
3007 * simpler by stripping LSB should someone try to use
3008 * odd threshold value.
3009 */
3010 frag_threshold &= ~0x1;
3011 }
3012 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3013 }
3014
3015 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3016 rts_threshold = nla_get_u32(
3017 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3018 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3019 }
3020
Lukáš Turek81077e82009-12-21 22:50:47 +01003021 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003022 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3023 return -EINVAL;
3024
Lukáš Turek81077e82009-12-21 22:50:47 +01003025 coverage_class = nla_get_u8(
3026 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3027 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3028 }
3029
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003030 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3031 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3032 return -EOPNOTSUPP;
3033
3034 changed |= WIPHY_PARAM_DYN_ACK;
3035 }
3036
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003037 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3038 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3039 NL80211_EXT_FEATURE_TXQS))
3040 return -EOPNOTSUPP;
3041 txq_limit = nla_get_u32(
3042 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3043 changed |= WIPHY_PARAM_TXQ_LIMIT;
3044 }
3045
3046 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3047 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3048 NL80211_EXT_FEATURE_TXQS))
3049 return -EOPNOTSUPP;
3050 txq_memory_limit = nla_get_u32(
3051 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3052 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3053 }
3054
3055 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3056 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3057 NL80211_EXT_FEATURE_TXQS))
3058 return -EOPNOTSUPP;
3059 txq_quantum = nla_get_u32(
3060 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3061 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3062 }
3063
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003064 if (changed) {
3065 u8 old_retry_short, old_retry_long;
3066 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003067 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003068 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003069
Ying Xue7f2b8562014-01-15 10:23:45 +08003070 if (!rdev->ops->set_wiphy_params)
3071 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003072
3073 old_retry_short = rdev->wiphy.retry_short;
3074 old_retry_long = rdev->wiphy.retry_long;
3075 old_frag_threshold = rdev->wiphy.frag_threshold;
3076 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003077 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003078 old_txq_limit = rdev->wiphy.txq_limit;
3079 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3080 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003081
3082 if (changed & WIPHY_PARAM_RETRY_SHORT)
3083 rdev->wiphy.retry_short = retry_short;
3084 if (changed & WIPHY_PARAM_RETRY_LONG)
3085 rdev->wiphy.retry_long = retry_long;
3086 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3087 rdev->wiphy.frag_threshold = frag_threshold;
3088 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3089 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003090 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3091 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003092 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3093 rdev->wiphy.txq_limit = txq_limit;
3094 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3095 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3096 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3097 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003098
Hila Gonene35e4d22012-06-27 17:19:42 +03003099 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003100 if (result) {
3101 rdev->wiphy.retry_short = old_retry_short;
3102 rdev->wiphy.retry_long = old_retry_long;
3103 rdev->wiphy.frag_threshold = old_frag_threshold;
3104 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003105 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003106 rdev->wiphy.txq_limit = old_txq_limit;
3107 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3108 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003109 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003110 }
3111 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003112 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003113}
3114
Johannes Berg683b6d32012-11-08 21:25:48 +01003115static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003116 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003117{
Johannes Berg601555c2014-11-27 17:26:56 +01003118 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3119 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003120
Johannes Berg683b6d32012-11-08 21:25:48 +01003121 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3122 chandef->chan->center_freq))
3123 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003124 switch (chandef->width) {
3125 case NL80211_CHAN_WIDTH_20_NOHT:
3126 case NL80211_CHAN_WIDTH_20:
3127 case NL80211_CHAN_WIDTH_40:
3128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3129 cfg80211_get_chandef_type(chandef)))
3130 return -ENOBUFS;
3131 break;
3132 default:
3133 break;
3134 }
3135 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3136 return -ENOBUFS;
3137 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3138 return -ENOBUFS;
3139 if (chandef->center_freq2 &&
3140 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003141 return -ENOBUFS;
3142 return 0;
3143}
3144
Eric W. Biederman15e47302012-09-07 20:12:54 +00003145static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003146 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003147 struct wireless_dev *wdev,
3148 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003149{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003150 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003151 void *hdr;
3152
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003153 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3154 cmd != NL80211_CMD_DEL_INTERFACE &&
3155 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003156
3157 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003158 if (!hdr)
3159 return -1;
3160
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003161 if (dev &&
3162 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003163 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003164 goto nla_put_failure;
3165
3166 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3167 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003168 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3169 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003170 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003171 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3172 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003173 (cfg80211_rdev_list_generation << 2)) ||
3174 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003175 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003176
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003177 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003178 int ret;
3179 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003180
Johannes Berg683b6d32012-11-08 21:25:48 +01003181 ret = rdev_get_channel(rdev, wdev, &chandef);
3182 if (ret == 0) {
3183 if (nl80211_send_chandef(msg, &chandef))
3184 goto nla_put_failure;
3185 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003186 }
3187
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003188 if (rdev->ops->get_tx_power) {
3189 int dbm, ret;
3190
3191 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3192 if (ret == 0 &&
3193 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3194 DBM_TO_MBM(dbm)))
3195 goto nla_put_failure;
3196 }
3197
Johannes Berg44905262017-10-17 21:56:01 +02003198 wdev_lock(wdev);
3199 switch (wdev->iftype) {
3200 case NL80211_IFTYPE_AP:
3201 if (wdev->ssid_len &&
3202 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003203 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003204 break;
3205 case NL80211_IFTYPE_STATION:
3206 case NL80211_IFTYPE_P2P_CLIENT:
3207 case NL80211_IFTYPE_ADHOC: {
3208 const u8 *ssid_ie;
3209 if (!wdev->current_bss)
3210 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003211 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003212 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3213 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003214 if (ssid_ie &&
3215 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3216 goto nla_put_failure_rcu_locked;
3217 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003218 break;
3219 }
3220 default:
3221 /* nothing */
3222 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003223 }
Johannes Berg44905262017-10-17 21:56:01 +02003224 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003225
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003226 if (rdev->ops->get_txq_stats) {
3227 struct cfg80211_txq_stats txqstats = {};
3228 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3229
3230 if (ret == 0 &&
3231 !nl80211_put_txq_stats(msg, &txqstats,
3232 NL80211_ATTR_TXQ_STATS))
3233 goto nla_put_failure;
3234 }
3235
Johannes Berg053c0952015-01-16 22:09:00 +01003236 genlmsg_end(msg, hdr);
3237 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003238
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003239 nla_put_failure_rcu_locked:
3240 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003241 nla_put_failure_locked:
3242 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003243 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003244 genlmsg_cancel(msg, hdr);
3245 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003246}
3247
3248static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3249{
3250 int wp_idx = 0;
3251 int if_idx = 0;
3252 int wp_start = cb->args[0];
3253 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003254 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003255 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003256 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003257 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003258
Johannes Berg5fe231e2013-05-08 21:45:15 +02003259 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003260 if (!cb->args[2]) {
3261 struct nl80211_dump_wiphy_state state = {
3262 .filter_wiphy = -1,
3263 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003264
3265 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3266 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003267 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003268
3269 filter_wiphy = state.filter_wiphy;
3270
3271 /*
3272 * if filtering, set cb->args[2] to +1 since 0 is the default
3273 * value needed to determine that parsing is necessary.
3274 */
3275 if (filter_wiphy >= 0)
3276 cb->args[2] = filter_wiphy + 1;
3277 else
3278 cb->args[2] = -1;
3279 } else if (cb->args[2] > 0) {
3280 filter_wiphy = cb->args[2] - 1;
3281 }
3282
Johannes Bergf5ea9122009-08-07 16:17:38 +02003283 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3284 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003285 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003286 if (wp_idx < wp_start) {
3287 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003288 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003289 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003290
3291 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3292 continue;
3293
Johannes Berg55682962007-09-20 13:09:35 -04003294 if_idx = 0;
3295
Johannes Berg53873f12016-05-03 16:52:04 +03003296 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003297 if (if_idx < if_start) {
3298 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003299 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003300 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003301 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003302 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003303 rdev, wdev,
3304 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003305 goto out;
3306 }
3307 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003308 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003309
3310 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003311 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003312 out:
Johannes Berg55682962007-09-20 13:09:35 -04003313 cb->args[0] = wp_idx;
3314 cb->args[1] = if_idx;
3315
Johannes Bergea90e0d2017-03-15 14:26:04 +01003316 ret = skb->len;
3317 out_unlock:
3318 rtnl_unlock();
3319
3320 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003321}
3322
3323static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3324{
3325 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003327 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003328
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003330 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003331 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003332
Eric W. Biederman15e47302012-09-07 20:12:54 +00003333 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003334 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003335 nlmsg_free(msg);
3336 return -ENOBUFS;
3337 }
Johannes Berg55682962007-09-20 13:09:35 -04003338
Johannes Berg134e6372009-07-10 09:51:34 +00003339 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003340}
3341
Michael Wu66f7ac52008-01-31 19:48:22 +01003342static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3343 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3344 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3345 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3346 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3347 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003348 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003349};
3350
3351static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3352{
3353 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3354 int flag;
3355
3356 *mntrflags = 0;
3357
3358 if (!nla)
3359 return -EINVAL;
3360
Johannes Berg8cb08172019-04-26 14:07:28 +02003361 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003362 return -EINVAL;
3363
3364 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3365 if (flags[flag])
3366 *mntrflags |= (1<<flag);
3367
Johannes Berg818a9862017-04-12 11:23:28 +02003368 *mntrflags |= MONITOR_FLAG_CHANGED;
3369
Michael Wu66f7ac52008-01-31 19:48:22 +01003370 return 0;
3371}
3372
Johannes Berg1db77592017-04-12 11:36:31 +02003373static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3374 enum nl80211_iftype type,
3375 struct genl_info *info,
3376 struct vif_params *params)
3377{
3378 bool change = false;
3379 int err;
3380
3381 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3382 if (type != NL80211_IFTYPE_MONITOR)
3383 return -EINVAL;
3384
3385 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3386 &params->flags);
3387 if (err)
3388 return err;
3389
3390 change = true;
3391 }
3392
3393 if (params->flags & MONITOR_FLAG_ACTIVE &&
3394 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3395 return -EOPNOTSUPP;
3396
3397 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3398 const u8 *mumimo_groups;
3399 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3400
3401 if (type != NL80211_IFTYPE_MONITOR)
3402 return -EINVAL;
3403
3404 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3405 return -EOPNOTSUPP;
3406
3407 mumimo_groups =
3408 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3409
3410 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003411 if ((mumimo_groups[0] & BIT(0)) ||
3412 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003413 return -EINVAL;
3414
3415 params->vht_mumimo_groups = mumimo_groups;
3416 change = true;
3417 }
3418
3419 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3420 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3421
3422 if (type != NL80211_IFTYPE_MONITOR)
3423 return -EINVAL;
3424
3425 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3426 return -EOPNOTSUPP;
3427
3428 params->vht_mumimo_follow_addr =
3429 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3430 change = true;
3431 }
3432
3433 return change ? 1 : 0;
3434}
3435
Johannes Berg9bc383d2009-11-19 11:55:19 +01003436static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003437 struct net_device *netdev, u8 use_4addr,
3438 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003439{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003440 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003441 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003442 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003443 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003444 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003445
3446 switch (iftype) {
3447 case NL80211_IFTYPE_AP_VLAN:
3448 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3449 return 0;
3450 break;
3451 case NL80211_IFTYPE_STATION:
3452 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3453 return 0;
3454 break;
3455 default:
3456 break;
3457 }
3458
3459 return -EOPNOTSUPP;
3460}
3461
Johannes Berg55682962007-09-20 13:09:35 -04003462static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3463{
Johannes Berg4c476992010-10-04 21:36:35 +02003464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003465 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003466 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003467 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003468 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003469 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003470
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003471 memset(&params, 0, sizeof(params));
3472
Johannes Berg04a773a2009-04-19 21:24:32 +02003473 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003474
Johannes Berg723b0382008-09-16 20:22:09 +02003475 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003476 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003477 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003478 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003479 }
3480
Johannes Berg92ffe052008-09-16 20:39:36 +02003481 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003482 struct wireless_dev *wdev = dev->ieee80211_ptr;
3483
Johannes Berg4c476992010-10-04 21:36:35 +02003484 if (ntype != NL80211_IFTYPE_MESH_POINT)
3485 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003486 if (netif_running(dev))
3487 return -EBUSY;
3488
3489 wdev_lock(wdev);
3490 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3491 IEEE80211_MAX_MESH_ID_LEN);
3492 wdev->mesh_id_up_len =
3493 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3494 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3495 wdev->mesh_id_up_len);
3496 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003497 }
3498
Felix Fietkau8b787642009-11-10 18:53:10 +01003499 if (info->attrs[NL80211_ATTR_4ADDR]) {
3500 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3501 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003502 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003504 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003505 } else {
3506 params.use_4addr = -1;
3507 }
3508
Johannes Berg1db77592017-04-12 11:36:31 +02003509 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3510 if (err < 0)
3511 return err;
3512 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003513 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003514
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003515 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003516 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003517 else
3518 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003519
Johannes Berg9bc383d2009-11-19 11:55:19 +01003520 if (!err && params.use_4addr != -1)
3521 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3522
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003523 if (change && !err) {
3524 struct wireless_dev *wdev = dev->ieee80211_ptr;
3525
3526 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3527 }
3528
Johannes Berg55682962007-09-20 13:09:35 -04003529 return err;
3530}
3531
3532static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3533{
Johannes Berg4c476992010-10-04 21:36:35 +02003534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003535 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003536 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003537 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003538 int err;
3539 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3540
Johannes Berg78f22b62014-03-24 17:57:27 +01003541 /* to avoid failing a new interface creation due to pending removal */
3542 cfg80211_destroy_ifaces(rdev);
3543
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003544 memset(&params, 0, sizeof(params));
3545
Johannes Berg55682962007-09-20 13:09:35 -04003546 if (!info->attrs[NL80211_ATTR_IFNAME])
3547 return -EINVAL;
3548
Johannes Bergab0d76f2018-10-02 10:00:07 +02003549 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003550 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003551
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303552 if (!rdev->ops->add_virtual_intf)
Johannes Berg4c476992010-10-04 21:36:35 +02003553 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003554
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003555 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003556 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3557 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003558 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3559 ETH_ALEN);
3560 if (!is_valid_ether_addr(params.macaddr))
3561 return -EADDRNOTAVAIL;
3562 }
3563
Johannes Berg9bc383d2009-11-19 11:55:19 +01003564 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003565 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003566 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003567 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003568 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003569 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003570
Manikanta Pubbisettye6f40512019-07-22 12:44:50 +05303571 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303572 return -EOPNOTSUPP;
3573
Johannes Berg1db77592017-04-12 11:36:31 +02003574 err = nl80211_parse_mon_options(rdev, type, info, &params);
3575 if (err < 0)
3576 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003577
Johannes Berga18c7192015-02-24 10:56:42 +01003578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3579 if (!msg)
3580 return -ENOMEM;
3581
Hila Gonene35e4d22012-06-27 17:19:42 +03003582 wdev = rdev_add_virtual_intf(rdev,
3583 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003584 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003585 if (WARN_ON(!wdev)) {
3586 nlmsg_free(msg);
3587 return -EPROTO;
3588 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003589 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003590 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003591 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003592
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003593 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003594 wdev->owner_nlportid = info->snd_portid;
3595
Johannes Berg98104fde2012-06-16 00:19:54 +02003596 switch (type) {
3597 case NL80211_IFTYPE_MESH_POINT:
3598 if (!info->attrs[NL80211_ATTR_MESH_ID])
3599 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003600 wdev_lock(wdev);
3601 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3602 IEEE80211_MAX_MESH_ID_LEN);
3603 wdev->mesh_id_up_len =
3604 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3605 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3606 wdev->mesh_id_up_len);
3607 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003608 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003609 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003610 case NL80211_IFTYPE_P2P_DEVICE:
3611 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003612 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003613 * through the netdev notifier and must be added here
3614 */
Johannes Berge4d42162018-09-13 14:12:03 +02003615 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003616 break;
3617 default:
3618 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003619 }
3620
Eric W. Biederman15e47302012-09-07 20:12:54 +00003621 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003622 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003623 nlmsg_free(msg);
3624 return -ENOBUFS;
3625 }
3626
3627 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003628}
3629
3630static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3631{
Johannes Berg4c476992010-10-04 21:36:35 +02003632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003633 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003634
Johannes Berg4c476992010-10-04 21:36:35 +02003635 if (!rdev->ops->del_virtual_intf)
3636 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003637
Johannes Berg84efbb82012-06-16 00:00:26 +02003638 /*
3639 * If we remove a wireless device without a netdev then clear
3640 * user_ptr[1] so that nl80211_post_doit won't dereference it
3641 * to check if it needs to do dev_put(). Otherwise it crashes
3642 * since the wdev has been freed, unlike with a netdev where
3643 * we need the dev_put() for the netdev to really be freed.
3644 */
3645 if (!wdev->netdev)
3646 info->user_ptr[1] = NULL;
3647
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003648 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003649}
3650
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003651static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3652{
3653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3654 struct net_device *dev = info->user_ptr[1];
3655 u16 noack_map;
3656
3657 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3658 return -EINVAL;
3659
3660 if (!rdev->ops->set_noack_map)
3661 return -EOPNOTSUPP;
3662
3663 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3664
Hila Gonene35e4d22012-06-27 17:19:42 +03003665 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003666}
3667
Johannes Berg41ade002007-12-19 02:03:29 +01003668struct get_key_cookie {
3669 struct sk_buff *msg;
3670 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003671 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003672};
3673
3674static void get_key_callback(void *c, struct key_params *params)
3675{
Johannes Bergb9454e82009-07-08 13:29:08 +02003676 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003677 struct get_key_cookie *cookie = c;
3678
David S. Miller9360ffd2012-03-29 04:41:26 -04003679 if ((params->key &&
3680 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3681 params->key_len, params->key)) ||
3682 (params->seq &&
3683 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3684 params->seq_len, params->seq)) ||
3685 (params->cipher &&
3686 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3687 params->cipher)))
3688 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003689
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003690 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003691 if (!key)
3692 goto nla_put_failure;
3693
David S. Miller9360ffd2012-03-29 04:41:26 -04003694 if ((params->key &&
3695 nla_put(cookie->msg, NL80211_KEY_DATA,
3696 params->key_len, params->key)) ||
3697 (params->seq &&
3698 nla_put(cookie->msg, NL80211_KEY_SEQ,
3699 params->seq_len, params->seq)) ||
3700 (params->cipher &&
3701 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3702 params->cipher)))
3703 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003704
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003705 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003706 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003707
3708 nla_nest_end(cookie->msg, key);
3709
Johannes Berg41ade002007-12-19 02:03:29 +01003710 return;
3711 nla_put_failure:
3712 cookie->error = 1;
3713}
3714
3715static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3716{
Johannes Berg4c476992010-10-04 21:36:35 +02003717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003718 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003719 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003720 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003721 const u8 *mac_addr = NULL;
3722 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003723 struct get_key_cookie cookie = {
3724 .error = 0,
3725 };
3726 void *hdr;
3727 struct sk_buff *msg;
3728
3729 if (info->attrs[NL80211_ATTR_KEY_IDX])
3730 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3731
Johannes Berg41ade002007-12-19 02:03:29 +01003732 if (info->attrs[NL80211_ATTR_MAC])
3733 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3734
Johannes Berge31b8212010-10-05 19:39:30 +02003735 pairwise = !!mac_addr;
3736 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3737 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003738
Johannes Berge31b8212010-10-05 19:39:30 +02003739 if (kt != NL80211_KEYTYPE_GROUP &&
3740 kt != NL80211_KEYTYPE_PAIRWISE)
3741 return -EINVAL;
3742 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3743 }
3744
Johannes Berg4c476992010-10-04 21:36:35 +02003745 if (!rdev->ops->get_key)
3746 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003747
Johannes Berg0fa7b392015-01-23 11:10:12 +01003748 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3749 return -ENOENT;
3750
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003752 if (!msg)
3753 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003754
Eric W. Biederman15e47302012-09-07 20:12:54 +00003755 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003756 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003757 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003758 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003759
3760 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003761 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003762
David S. Miller9360ffd2012-03-29 04:41:26 -04003763 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3764 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3765 goto nla_put_failure;
3766 if (mac_addr &&
3767 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3768 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003769
Hila Gonene35e4d22012-06-27 17:19:42 +03003770 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3771 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003772
3773 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003774 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003775
3776 if (cookie.error)
3777 goto nla_put_failure;
3778
3779 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003780 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003781
3782 nla_put_failure:
3783 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003784 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003785 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003786 return err;
3787}
3788
3789static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3790{
Johannes Berg4c476992010-10-04 21:36:35 +02003791 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003792 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003793 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003794 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003795
Johannes Bergb9454e82009-07-08 13:29:08 +02003796 err = nl80211_parse_key(info, &key);
3797 if (err)
3798 return err;
3799
3800 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003801 return -EINVAL;
3802
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003803 /* Only support setting default key and
3804 * Extended Key ID action NL80211_KEY_SET_TX.
3805 */
3806 if (!key.def && !key.defmgmt &&
3807 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01003808 return -EINVAL;
3809
Johannes Bergfffd0932009-07-08 14:22:54 +02003810 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003811
3812 if (key.def) {
3813 if (!rdev->ops->set_default_key) {
3814 err = -EOPNOTSUPP;
3815 goto out;
3816 }
3817
3818 err = nl80211_key_allowed(dev->ieee80211_ptr);
3819 if (err)
3820 goto out;
3821
Hila Gonene35e4d22012-06-27 17:19:42 +03003822 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003823 key.def_uni, key.def_multi);
3824
3825 if (err)
3826 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003827
Johannes Berg3d23e342009-09-29 23:27:28 +02003828#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003829 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003830#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003831 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003832 if (key.def_uni || !key.def_multi) {
3833 err = -EINVAL;
3834 goto out;
3835 }
3836
3837 if (!rdev->ops->set_default_mgmt_key) {
3838 err = -EOPNOTSUPP;
3839 goto out;
3840 }
3841
3842 err = nl80211_key_allowed(dev->ieee80211_ptr);
3843 if (err)
3844 goto out;
3845
Hila Gonene35e4d22012-06-27 17:19:42 +03003846 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003847 if (err)
3848 goto out;
3849
3850#ifdef CONFIG_CFG80211_WEXT
3851 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3852#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003853 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3854 wiphy_ext_feature_isset(&rdev->wiphy,
3855 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3856 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003857
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003858 if (info->attrs[NL80211_ATTR_MAC])
3859 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3860
3861 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3862 err = -EINVAL;
3863 goto out;
3864 }
3865
3866 err = rdev_add_key(rdev, dev, key.idx,
3867 NL80211_KEYTYPE_PAIRWISE,
3868 mac_addr, &key.p);
3869 } else {
3870 err = -EINVAL;
3871 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003872 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003873 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003874
Johannes Berg41ade002007-12-19 02:03:29 +01003875 return err;
3876}
3877
3878static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3879{
Johannes Berg4c476992010-10-04 21:36:35 +02003880 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003881 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003882 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003883 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003884 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003885
Johannes Bergb9454e82009-07-08 13:29:08 +02003886 err = nl80211_parse_key(info, &key);
3887 if (err)
3888 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003889
Johannes Bergb9454e82009-07-08 13:29:08 +02003890 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003891 return -EINVAL;
3892
Johannes Berg41ade002007-12-19 02:03:29 +01003893 if (info->attrs[NL80211_ATTR_MAC])
3894 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3895
Johannes Berge31b8212010-10-05 19:39:30 +02003896 if (key.type == -1) {
3897 if (mac_addr)
3898 key.type = NL80211_KEYTYPE_PAIRWISE;
3899 else
3900 key.type = NL80211_KEYTYPE_GROUP;
3901 }
3902
3903 /* for now */
3904 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3905 key.type != NL80211_KEYTYPE_GROUP)
3906 return -EINVAL;
3907
Johannes Berg4c476992010-10-04 21:36:35 +02003908 if (!rdev->ops->add_key)
3909 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003910
Johannes Berge31b8212010-10-05 19:39:30 +02003911 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3912 key.type == NL80211_KEYTYPE_PAIRWISE,
3913 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003914 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003915
3916 wdev_lock(dev->ieee80211_ptr);
3917 err = nl80211_key_allowed(dev->ieee80211_ptr);
3918 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003919 err = rdev_add_key(rdev, dev, key.idx,
3920 key.type == NL80211_KEYTYPE_PAIRWISE,
3921 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003922 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003923
Johannes Berg41ade002007-12-19 02:03:29 +01003924 return err;
3925}
3926
3927static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3928{
Johannes Berg4c476992010-10-04 21:36:35 +02003929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003930 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003931 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003932 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003933 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003934
Johannes Bergb9454e82009-07-08 13:29:08 +02003935 err = nl80211_parse_key(info, &key);
3936 if (err)
3937 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003938
3939 if (info->attrs[NL80211_ATTR_MAC])
3940 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3941
Johannes Berge31b8212010-10-05 19:39:30 +02003942 if (key.type == -1) {
3943 if (mac_addr)
3944 key.type = NL80211_KEYTYPE_PAIRWISE;
3945 else
3946 key.type = NL80211_KEYTYPE_GROUP;
3947 }
3948
3949 /* for now */
3950 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3951 key.type != NL80211_KEYTYPE_GROUP)
3952 return -EINVAL;
3953
Johannes Berg4c476992010-10-04 21:36:35 +02003954 if (!rdev->ops->del_key)
3955 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003956
Johannes Bergfffd0932009-07-08 14:22:54 +02003957 wdev_lock(dev->ieee80211_ptr);
3958 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003959
Johannes Berg0fa7b392015-01-23 11:10:12 +01003960 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003961 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3962 err = -ENOENT;
3963
Johannes Bergfffd0932009-07-08 14:22:54 +02003964 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003965 err = rdev_del_key(rdev, dev, key.idx,
3966 key.type == NL80211_KEYTYPE_PAIRWISE,
3967 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003968
Johannes Berg3d23e342009-09-29 23:27:28 +02003969#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003970 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003971 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003972 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003973 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003974 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3975 }
3976#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003977 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003978
Johannes Berg41ade002007-12-19 02:03:29 +01003979 return err;
3980}
3981
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303982/* This function returns an error or the number of nested attributes */
3983static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3984{
3985 struct nlattr *attr;
3986 int n_entries = 0, tmp;
3987
3988 nla_for_each_nested(attr, nl_attr, tmp) {
3989 if (nla_len(attr) != ETH_ALEN)
3990 return -EINVAL;
3991
3992 n_entries++;
3993 }
3994
3995 return n_entries;
3996}
3997
3998/*
3999 * This function parses ACL information and allocates memory for ACL data.
4000 * On successful return, the calling function is responsible to free the
4001 * ACL buffer returned by this function.
4002 */
4003static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4004 struct genl_info *info)
4005{
4006 enum nl80211_acl_policy acl_policy;
4007 struct nlattr *attr;
4008 struct cfg80211_acl_data *acl;
4009 int i = 0, n_entries, tmp;
4010
4011 if (!wiphy->max_acl_mac_addrs)
4012 return ERR_PTR(-EOPNOTSUPP);
4013
4014 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4015 return ERR_PTR(-EINVAL);
4016
4017 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4018 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4019 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4020 return ERR_PTR(-EINVAL);
4021
4022 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4023 return ERR_PTR(-EINVAL);
4024
4025 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4026 if (n_entries < 0)
4027 return ERR_PTR(n_entries);
4028
4029 if (n_entries > wiphy->max_acl_mac_addrs)
4030 return ERR_PTR(-ENOTSUPP);
4031
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05004032 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304033 if (!acl)
4034 return ERR_PTR(-ENOMEM);
4035
4036 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4037 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4038 i++;
4039 }
4040
4041 acl->n_acl_entries = n_entries;
4042 acl->acl_policy = acl_policy;
4043
4044 return acl;
4045}
4046
4047static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4048{
4049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4050 struct net_device *dev = info->user_ptr[1];
4051 struct cfg80211_acl_data *acl;
4052 int err;
4053
4054 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4055 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4056 return -EOPNOTSUPP;
4057
4058 if (!dev->ieee80211_ptr->beacon_interval)
4059 return -EINVAL;
4060
4061 acl = parse_acl_data(&rdev->wiphy, info);
4062 if (IS_ERR(acl))
4063 return PTR_ERR(acl);
4064
4065 err = rdev_set_mac_acl(rdev, dev, acl);
4066
4067 kfree(acl);
4068
4069 return err;
4070}
4071
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304072static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4073 u8 *rates, u8 rates_len)
4074{
4075 u8 i;
4076 u32 mask = 0;
4077
4078 for (i = 0; i < rates_len; i++) {
4079 int rate = (rates[i] & 0x7f) * 5;
4080 int ridx;
4081
4082 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4083 struct ieee80211_rate *srate =
4084 &sband->bitrates[ridx];
4085 if (rate == srate->bitrate) {
4086 mask |= 1 << ridx;
4087 break;
4088 }
4089 }
4090 if (ridx == sband->n_bitrates)
4091 return 0; /* rate not found */
4092 }
4093
4094 return mask;
4095}
4096
4097static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4098 u8 *rates, u8 rates_len,
4099 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4100{
4101 u8 i;
4102
4103 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4104
4105 for (i = 0; i < rates_len; i++) {
4106 int ridx, rbit;
4107
4108 ridx = rates[i] / 8;
4109 rbit = BIT(rates[i] % 8);
4110
4111 /* check validity */
4112 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4113 return false;
4114
4115 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004116 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304117 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4118 mcs[ridx] |= rbit;
4119 else
4120 return false;
4121 }
4122
4123 return true;
4124}
4125
4126static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4127{
4128 u16 mcs_mask = 0;
4129
4130 switch (vht_mcs_map) {
4131 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4132 break;
4133 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4134 mcs_mask = 0x00FF;
4135 break;
4136 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4137 mcs_mask = 0x01FF;
4138 break;
4139 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4140 mcs_mask = 0x03FF;
4141 break;
4142 default:
4143 break;
4144 }
4145
4146 return mcs_mask;
4147}
4148
4149static void vht_build_mcs_mask(u16 vht_mcs_map,
4150 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4151{
4152 u8 nss;
4153
4154 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4155 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4156 vht_mcs_map >>= 2;
4157 }
4158}
4159
4160static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4161 struct nl80211_txrate_vht *txrate,
4162 u16 mcs[NL80211_VHT_NSS_MAX])
4163{
4164 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4165 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4166 u8 i;
4167
4168 if (!sband->vht_cap.vht_supported)
4169 return false;
4170
4171 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4172
4173 /* Build vht_mcs_mask from VHT capabilities */
4174 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4175
4176 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4177 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4178 mcs[i] = txrate->mcs[i];
4179 else
4180 return false;
4181 }
4182
4183 return true;
4184}
4185
4186static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4187 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4188 .len = NL80211_MAX_SUPP_RATES },
4189 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4190 .len = NL80211_MAX_SUPP_HT_RATES },
Johannes Berg180aa422019-05-28 14:19:07 +02004191 [NL80211_TXRATE_VHT] = {
4192 .type = NLA_EXACT_LEN_WARN,
4193 .len = sizeof(struct nl80211_txrate_vht),
4194 },
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304195 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4196};
4197
4198static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4199 struct cfg80211_bitrate_mask *mask)
4200{
4201 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4203 int rem, i;
4204 struct nlattr *tx_rates;
4205 struct ieee80211_supported_band *sband;
4206 u16 vht_tx_mcs_map;
4207
4208 memset(mask, 0, sizeof(*mask));
4209 /* Default to all rates enabled */
4210 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4211 sband = rdev->wiphy.bands[i];
4212
4213 if (!sband)
4214 continue;
4215
4216 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4217 memcpy(mask->control[i].ht_mcs,
4218 sband->ht_cap.mcs.rx_mask,
4219 sizeof(mask->control[i].ht_mcs));
4220
4221 if (!sband->vht_cap.vht_supported)
4222 continue;
4223
4224 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4225 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4226 }
4227
4228 /* if no rates are given set it back to the defaults */
4229 if (!info->attrs[NL80211_ATTR_TX_RATES])
4230 goto out;
4231
4232 /* The nested attribute uses enum nl80211_band as the index. This maps
4233 * directly to the enum nl80211_band values used in cfg80211.
4234 */
4235 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4236 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4237 enum nl80211_band band = nla_type(tx_rates);
4238 int err;
4239
4240 if (band < 0 || band >= NUM_NL80211_BANDS)
4241 return -EINVAL;
4242 sband = rdev->wiphy.bands[band];
4243 if (sband == NULL)
4244 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004245 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4246 tx_rates,
4247 nl80211_txattr_policy,
4248 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304249 if (err)
4250 return err;
4251 if (tb[NL80211_TXRATE_LEGACY]) {
4252 mask->control[band].legacy = rateset_to_mask(
4253 sband,
4254 nla_data(tb[NL80211_TXRATE_LEGACY]),
4255 nla_len(tb[NL80211_TXRATE_LEGACY]));
4256 if ((mask->control[band].legacy == 0) &&
4257 nla_len(tb[NL80211_TXRATE_LEGACY]))
4258 return -EINVAL;
4259 }
4260 if (tb[NL80211_TXRATE_HT]) {
4261 if (!ht_rateset_to_mask(
4262 sband,
4263 nla_data(tb[NL80211_TXRATE_HT]),
4264 nla_len(tb[NL80211_TXRATE_HT]),
4265 mask->control[band].ht_mcs))
4266 return -EINVAL;
4267 }
4268 if (tb[NL80211_TXRATE_VHT]) {
4269 if (!vht_set_mcs_mask(
4270 sband,
4271 nla_data(tb[NL80211_TXRATE_VHT]),
4272 mask->control[band].vht_mcs))
4273 return -EINVAL;
4274 }
4275 if (tb[NL80211_TXRATE_GI]) {
4276 mask->control[band].gi =
4277 nla_get_u8(tb[NL80211_TXRATE_GI]);
4278 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4279 return -EINVAL;
4280 }
4281
4282 if (mask->control[band].legacy == 0) {
4283 /* don't allow empty legacy rates if HT or VHT
4284 * are not even supported.
4285 */
4286 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4287 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4288 return -EINVAL;
4289
4290 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4291 if (mask->control[band].ht_mcs[i])
4292 goto out;
4293
4294 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4295 if (mask->control[band].vht_mcs[i])
4296 goto out;
4297
4298 /* legacy and mcs rates may not be both empty */
4299 return -EINVAL;
4300 }
4301 }
4302
4303out:
4304 return 0;
4305}
4306
Johannes Berg8564e382016-09-19 09:44:44 +02004307static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4308 enum nl80211_band band,
4309 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304310{
Johannes Berg8564e382016-09-19 09:44:44 +02004311 u32 count_ht, count_vht, i;
4312 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304313
4314 /* Allow only one rate */
4315 if (hweight32(rate) > 1)
4316 return -EINVAL;
4317
4318 count_ht = 0;
4319 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004320 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304321 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004322 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304323 count_ht++;
4324 if (count_ht > 1)
4325 return -EINVAL;
4326 }
4327 if (count_ht && rate)
4328 return -EINVAL;
4329 }
4330
4331 count_vht = 0;
4332 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004333 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304334 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004335 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304336 count_vht++;
4337 if (count_vht > 1)
4338 return -EINVAL;
4339 }
4340 if (count_vht && rate)
4341 return -EINVAL;
4342 }
4343
4344 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4345 return -EINVAL;
4346
Johannes Berg8564e382016-09-19 09:44:44 +02004347 if (rate &&
4348 !wiphy_ext_feature_isset(&rdev->wiphy,
4349 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4350 return -EINVAL;
4351 if (count_ht &&
4352 !wiphy_ext_feature_isset(&rdev->wiphy,
4353 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4354 return -EINVAL;
4355 if (count_vht &&
4356 !wiphy_ext_feature_isset(&rdev->wiphy,
4357 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4358 return -EINVAL;
4359
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304360 return 0;
4361}
4362
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004363static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4364 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004365 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004366{
Johannes Berg88600202012-02-13 15:17:18 +01004367 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004368 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004369
Johannes Berg88600202012-02-13 15:17:18 +01004370 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004371
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004372 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4373 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4374 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004375 if (!bcn->head_len)
4376 return -EINVAL;
4377 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004378 }
4379
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004380 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4381 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4382 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004383 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004384 }
4385
Johannes Berg4c476992010-10-04 21:36:35 +02004386 if (!haveinfo)
4387 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004388
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004389 if (attrs[NL80211_ATTR_IE]) {
4390 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4391 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004392 }
4393
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004394 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004395 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004396 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004397 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004398 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004399 }
4400
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004401 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004402 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004403 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004404 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004405 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004406 }
4407
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004408 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4409 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4410 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004411 }
4412
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004413 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4414 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4415
Johannes Berg8cb08172019-04-26 14:07:28 +02004416 err = nla_parse_nested_deprecated(tb,
4417 NL80211_FTM_RESP_ATTR_MAX,
4418 attrs[NL80211_ATTR_FTM_RESPONDER],
4419 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004420 if (err)
4421 return err;
4422
4423 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4424 wiphy_ext_feature_isset(&rdev->wiphy,
4425 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4426 bcn->ftm_responder = 1;
4427 else
4428 return -EOPNOTSUPP;
4429
4430 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4431 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4432 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4433 }
4434
4435 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4436 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4437 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4438 }
4439 } else {
4440 bcn->ftm_responder = -1;
4441 }
4442
Johannes Berg88600202012-02-13 15:17:18 +01004443 return 0;
4444}
4445
John Crispin796e90f2019-07-30 18:37:00 +02004446static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4447 struct ieee80211_he_obss_pd *he_obss_pd)
4448{
4449 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4450 int err;
4451
4452 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4453 he_obss_pd_policy, NULL);
4454 if (err)
4455 return err;
4456
4457 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4458 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4459 return -EINVAL;
4460
4461 he_obss_pd->min_offset =
4462 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4463 he_obss_pd->max_offset =
4464 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4465
4466 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4467 return -EINVAL;
4468
4469 he_obss_pd->enable = true;
4470
4471 return 0;
4472}
4473
Johannes Berg66cd7942017-02-07 22:40:44 +02004474static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4475 const u8 *rates)
4476{
4477 int i;
4478
4479 if (!rates)
4480 return;
4481
4482 for (i = 0; i < rates[1]; i++) {
4483 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4484 params->ht_required = true;
4485 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4486 params->vht_required = true;
4487 }
4488}
4489
4490/*
4491 * Since the nl80211 API didn't include, from the beginning, attributes about
4492 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4493 * benefit of drivers that rebuild IEs in the firmware.
4494 */
4495static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4496{
4497 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004498 size_t ies_len = bcn->tail_len;
4499 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004500 const u8 *rates;
4501 const u8 *cap;
4502
4503 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4504 nl80211_check_ap_rate_selectors(params, rates);
4505
4506 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4507 nl80211_check_ap_rate_selectors(params, rates);
4508
4509 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4510 if (cap && cap[1] >= sizeof(*params->ht_cap))
4511 params->ht_cap = (void *)(cap + 2);
4512 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4513 if (cap && cap[1] >= sizeof(*params->vht_cap))
4514 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004515 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4516 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4517 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004518}
4519
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004520static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4521 struct cfg80211_ap_settings *params)
4522{
4523 struct wireless_dev *wdev;
4524 bool ret = false;
4525
Johannes Berg53873f12016-05-03 16:52:04 +03004526 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004527 if (wdev->iftype != NL80211_IFTYPE_AP &&
4528 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4529 continue;
4530
Johannes Berg683b6d32012-11-08 21:25:48 +01004531 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004532 continue;
4533
Johannes Berg683b6d32012-11-08 21:25:48 +01004534 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004535 ret = true;
4536 break;
4537 }
4538
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004539 return ret;
4540}
4541
Jouni Malinene39e5b52012-09-30 19:29:39 +03004542static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4543 enum nl80211_auth_type auth_type,
4544 enum nl80211_commands cmd)
4545{
4546 if (auth_type > NL80211_AUTHTYPE_MAX)
4547 return false;
4548
4549 switch (cmd) {
4550 case NL80211_CMD_AUTHENTICATE:
4551 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4552 auth_type == NL80211_AUTHTYPE_SAE)
4553 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004554 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4555 NL80211_EXT_FEATURE_FILS_STA) &&
4556 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4557 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4558 auth_type == NL80211_AUTHTYPE_FILS_PK))
4559 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004560 return true;
4561 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004562 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00004563 !wiphy_ext_feature_isset(&rdev->wiphy,
4564 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02004565 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004566 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004567
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004568 /* FILS with SK PFS or PK not supported yet */
4569 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4570 auth_type == NL80211_AUTHTYPE_FILS_PK)
4571 return false;
4572 if (!wiphy_ext_feature_isset(
4573 &rdev->wiphy,
4574 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4575 auth_type == NL80211_AUTHTYPE_FILS_SK)
4576 return false;
4577 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004578 case NL80211_CMD_START_AP:
4579 /* SAE not supported yet */
4580 if (auth_type == NL80211_AUTHTYPE_SAE)
4581 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004582 /* FILS not supported yet */
4583 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4584 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4585 auth_type == NL80211_AUTHTYPE_FILS_PK)
4586 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004587 return true;
4588 default:
4589 return false;
4590 }
4591}
4592
Johannes Berg88600202012-02-13 15:17:18 +01004593static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4594{
4595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4596 struct net_device *dev = info->user_ptr[1];
4597 struct wireless_dev *wdev = dev->ieee80211_ptr;
4598 struct cfg80211_ap_settings params;
4599 int err;
4600
4601 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4602 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4603 return -EOPNOTSUPP;
4604
4605 if (!rdev->ops->start_ap)
4606 return -EOPNOTSUPP;
4607
4608 if (wdev->beacon_interval)
4609 return -EALREADY;
4610
4611 memset(&params, 0, sizeof(params));
4612
4613 /* these are required for START_AP */
4614 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4615 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4616 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4617 return -EINVAL;
4618
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004619 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004620 if (err)
4621 return err;
4622
4623 params.beacon_interval =
4624 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4625 params.dtim_period =
4626 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4627
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304628 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4629 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004630 if (err)
4631 return err;
4632
4633 /*
4634 * In theory, some of these attributes should be required here
4635 * but since they were not used when the command was originally
4636 * added, keep them optional for old user space programs to let
4637 * them continue to work with drivers that do not need the
4638 * additional information -- drivers must check!
4639 */
4640 if (info->attrs[NL80211_ATTR_SSID]) {
4641 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4642 params.ssid_len =
4643 nla_len(info->attrs[NL80211_ATTR_SSID]);
4644 if (params.ssid_len == 0 ||
4645 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4646 return -EINVAL;
4647 }
4648
Johannes Bergab0d76f2018-10-02 10:00:07 +02004649 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004650 params.hidden_ssid = nla_get_u32(
4651 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004652
4653 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4654
4655 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4656 params.auth_type = nla_get_u32(
4657 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004658 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4659 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004660 return -EINVAL;
4661 } else
4662 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4663
4664 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4665 NL80211_MAX_NR_CIPHER_SUITES);
4666 if (err)
4667 return err;
4668
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304669 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4670 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4671 return -EOPNOTSUPP;
4672 params.inactivity_timeout = nla_get_u16(
4673 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4674 }
4675
Johannes Berg53cabad2012-11-14 15:17:28 +01004676 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4677 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4678 return -EINVAL;
4679 params.p2p_ctwindow =
4680 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004681 if (params.p2p_ctwindow != 0 &&
4682 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4683 return -EINVAL;
4684 }
4685
4686 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4687 u8 tmp;
4688
4689 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4690 return -EINVAL;
4691 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004692 params.p2p_opp_ps = tmp;
4693 if (params.p2p_opp_ps != 0 &&
4694 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4695 return -EINVAL;
4696 }
4697
Johannes Bergaa430da2012-05-16 23:50:18 +02004698 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004699 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4700 if (err)
4701 return err;
4702 } else if (wdev->preset_chandef.chan) {
4703 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004704 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004705 return -EINVAL;
4706
Arik Nemtsov923b3522015-07-08 15:41:44 +03004707 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4708 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004709 return -EINVAL;
4710
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304711 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4712 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4713 if (err)
4714 return err;
4715
Johannes Berg8564e382016-09-19 09:44:44 +02004716 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4717 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304718 if (err)
4719 return err;
4720 }
4721
Eliad Peller18998c32014-09-10 14:07:34 +03004722 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4723 params.smps_mode =
4724 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4725 switch (params.smps_mode) {
4726 case NL80211_SMPS_OFF:
4727 break;
4728 case NL80211_SMPS_STATIC:
4729 if (!(rdev->wiphy.features &
4730 NL80211_FEATURE_STATIC_SMPS))
4731 return -EINVAL;
4732 break;
4733 case NL80211_SMPS_DYNAMIC:
4734 if (!(rdev->wiphy.features &
4735 NL80211_FEATURE_DYNAMIC_SMPS))
4736 return -EINVAL;
4737 break;
4738 default:
4739 return -EINVAL;
4740 }
4741 } else {
4742 params.smps_mode = NL80211_SMPS_OFF;
4743 }
4744
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304745 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4746 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4747 return -EOPNOTSUPP;
4748
Ola Olsson4baf6be2015-10-29 07:04:58 +01004749 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4750 params.acl = parse_acl_data(&rdev->wiphy, info);
4751 if (IS_ERR(params.acl))
4752 return PTR_ERR(params.acl);
4753 }
4754
John Crispina0de1ca32019-05-28 13:49:48 +02004755 params.twt_responder =
4756 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
4757
John Crispin796e90f2019-07-30 18:37:00 +02004758 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
4759 err = nl80211_parse_he_obss_pd(
4760 info->attrs[NL80211_ATTR_HE_OBSS_PD],
4761 &params.he_obss_pd);
4762 if (err)
4763 return err;
4764 }
4765
Johannes Berg66cd7942017-02-07 22:40:44 +02004766 nl80211_calculate_ap_params(&params);
4767
Srinivas Dasarife494372019-01-23 18:06:56 +05304768 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4769 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4770
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004771 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004772 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004773 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004774 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004775 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004776 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004777 wdev->ssid_len = params.ssid_len;
4778 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004779
4780 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4781 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004782 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004783 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304784
4785 kfree(params.acl);
4786
Johannes Berg56d18932011-05-09 18:41:15 +02004787 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004788}
4789
Johannes Berg88600202012-02-13 15:17:18 +01004790static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4791{
4792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4793 struct net_device *dev = info->user_ptr[1];
4794 struct wireless_dev *wdev = dev->ieee80211_ptr;
4795 struct cfg80211_beacon_data params;
4796 int err;
4797
4798 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4799 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4800 return -EOPNOTSUPP;
4801
4802 if (!rdev->ops->change_beacon)
4803 return -EOPNOTSUPP;
4804
4805 if (!wdev->beacon_interval)
4806 return -EINVAL;
4807
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004808 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004809 if (err)
4810 return err;
4811
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004812 wdev_lock(wdev);
4813 err = rdev_change_beacon(rdev, dev, &params);
4814 wdev_unlock(wdev);
4815
4816 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004817}
4818
4819static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004820{
Johannes Berg4c476992010-10-04 21:36:35 +02004821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4822 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004823
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004824 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004825}
4826
Johannes Berg5727ef12007-12-19 02:03:34 +01004827static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4828 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4829 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4830 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004831 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004832 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004833 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004834};
4835
Johannes Bergeccb8e82009-05-11 21:57:56 +03004836static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004837 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004838 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004839{
4840 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004841 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004842 int flag;
4843
Johannes Bergeccb8e82009-05-11 21:57:56 +03004844 /*
4845 * Try parsing the new attribute first so userspace
4846 * can specify both for older kernels.
4847 */
4848 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4849 if (nla) {
4850 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004851
Johannes Bergeccb8e82009-05-11 21:57:56 +03004852 sta_flags = nla_data(nla);
4853 params->sta_flags_mask = sta_flags->mask;
4854 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004855 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004856 if ((params->sta_flags_mask |
4857 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4858 return -EINVAL;
4859 return 0;
4860 }
4861
4862 /* if present, parse the old attribute */
4863
4864 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004865 if (!nla)
4866 return 0;
4867
Johannes Berg8cb08172019-04-26 14:07:28 +02004868 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004869 return -EINVAL;
4870
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004871 /*
4872 * Only allow certain flags for interface types so that
4873 * other attributes are silently ignored. Remember that
4874 * this is backward compatibility code with old userspace
4875 * and shouldn't be hit in other cases anyway.
4876 */
4877 switch (iftype) {
4878 case NL80211_IFTYPE_AP:
4879 case NL80211_IFTYPE_AP_VLAN:
4880 case NL80211_IFTYPE_P2P_GO:
4881 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4882 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4883 BIT(NL80211_STA_FLAG_WME) |
4884 BIT(NL80211_STA_FLAG_MFP);
4885 break;
4886 case NL80211_IFTYPE_P2P_CLIENT:
4887 case NL80211_IFTYPE_STATION:
4888 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4889 BIT(NL80211_STA_FLAG_TDLS_PEER);
4890 break;
4891 case NL80211_IFTYPE_MESH_POINT:
4892 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4893 BIT(NL80211_STA_FLAG_MFP) |
4894 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004895 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004896 default:
4897 return -EINVAL;
4898 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004899
Johannes Berg3383b5a2012-05-10 20:14:43 +02004900 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4901 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004902 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004903
Johannes Berg3383b5a2012-05-10 20:14:43 +02004904 /* no longer support new API additions in old API */
4905 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4906 return -EINVAL;
4907 }
4908 }
4909
Johannes Berg5727ef12007-12-19 02:03:34 +01004910 return 0;
4911}
4912
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004913bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004914{
4915 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004916 u32 bitrate;
4917 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004918 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004919
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004920 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004921 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004922 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004923
4924 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4925 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004926 /* report 16-bit bitrate only if we can */
4927 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004928 if (bitrate > 0 &&
4929 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4930 return false;
4931 if (bitrate_compat > 0 &&
4932 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4933 return false;
4934
Johannes Bergb51f3be2015-01-15 16:14:02 +01004935 switch (info->bw) {
4936 case RATE_INFO_BW_5:
4937 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4938 break;
4939 case RATE_INFO_BW_10:
4940 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4941 break;
4942 default:
4943 WARN_ON(1);
4944 /* fall through */
4945 case RATE_INFO_BW_20:
4946 rate_flg = 0;
4947 break;
4948 case RATE_INFO_BW_40:
4949 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4950 break;
4951 case RATE_INFO_BW_80:
4952 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4953 break;
4954 case RATE_INFO_BW_160:
4955 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4956 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004957 case RATE_INFO_BW_HE_RU:
4958 rate_flg = 0;
4959 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004960 }
4961
4962 if (rate_flg && nla_put_flag(msg, rate_flg))
4963 return false;
4964
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004965 if (info->flags & RATE_INFO_FLAGS_MCS) {
4966 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4967 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004968 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4969 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4970 return false;
4971 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4972 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4973 return false;
4974 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4975 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004976 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4977 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4978 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004979 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4980 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4981 return false;
4982 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4983 return false;
4984 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4985 return false;
4986 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4987 return false;
4988 if (info->bw == RATE_INFO_BW_HE_RU &&
4989 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4990 info->he_ru_alloc))
4991 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004992 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004993
4994 nla_nest_end(msg, rate);
4995 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004996}
4997
Felix Fietkau119363c2013-04-22 16:29:30 +02004998static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4999 int id)
5000{
5001 void *attr;
5002 int i = 0;
5003
5004 if (!mask)
5005 return true;
5006
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005007 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02005008 if (!attr)
5009 return false;
5010
5011 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5012 if (!(mask & BIT(i)))
5013 continue;
5014
5015 if (nla_put_u8(msg, i, signal[i]))
5016 return false;
5017 }
5018
5019 nla_nest_end(msg, attr);
5020
5021 return true;
5022}
5023
Johannes Bergcf5ead82014-11-14 17:14:00 +01005024static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5025 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04005026 struct cfg80211_registered_device *rdev,
5027 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01005028 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005029{
5030 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07005031 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005032
Johannes Bergcf5ead82014-11-14 17:14:00 +01005033 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Andy Strohmanf77bf482019-05-24 23:27:29 -07005034 if (!hdr) {
5035 cfg80211_sinfo_release_content(sinfo);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005036 return -1;
Andy Strohmanf77bf482019-05-24 23:27:29 -07005037 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005038
David S. Miller9360ffd2012-03-29 04:41:26 -04005039 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5040 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5041 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5042 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005043
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005044 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005045 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005046 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005047
5048#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02005049 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03005050 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01005051 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5052 sinfo->memb)) \
5053 goto nla_put_failure; \
5054 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02005055#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03005056 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005057 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5058 sinfo->memb, NL80211_STA_INFO_PAD)) \
5059 goto nla_put_failure; \
5060 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01005061
5062 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5063 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
Ben Greear6c7a0032019-08-09 11:00:00 -07005064 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
Johannes Berg319090b2014-11-17 14:08:11 +01005065
Omer Efrat397c6572018-06-17 13:06:14 +03005066 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5067 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005068 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005069 (u32)sinfo->rx_bytes))
5070 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005071
Omer Efrat397c6572018-06-17 13:06:14 +03005072 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5073 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005074 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5075 (u32)sinfo->tx_bytes))
5076 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005077
Johannes Bergd686b922016-04-26 09:54:11 +02005078 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5079 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01005080 PUT_SINFO(LLID, llid, u16);
5081 PUT_SINFO(PLID, plid, u16);
5082 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02005083 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005084 PUT_SINFO_U64(TX_DURATION, tx_duration);
5085
5086 if (wiphy_ext_feature_isset(&rdev->wiphy,
5087 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5088 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01005089
John W. Linville66266b32012-03-15 13:25:41 -04005090 switch (rdev->wiphy.signal_type) {
5091 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01005092 PUT_SINFO(SIGNAL, signal, u8);
5093 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04005094 break;
5095 default:
5096 break;
5097 }
Omer Efrat397c6572018-06-17 13:06:14 +03005098 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005099 if (!nl80211_put_signal(msg, sinfo->chains,
5100 sinfo->chain_signal,
5101 NL80211_STA_INFO_CHAIN_SIGNAL))
5102 goto nla_put_failure;
5103 }
Omer Efrat397c6572018-06-17 13:06:14 +03005104 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005105 if (!nl80211_put_signal(msg, sinfo->chains,
5106 sinfo->chain_signal_avg,
5107 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5108 goto nla_put_failure;
5109 }
Omer Efrat397c6572018-06-17 13:06:14 +03005110 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005111 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5112 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01005113 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005114 }
Omer Efrat397c6572018-06-17 13:06:14 +03005115 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005116 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5117 NL80211_STA_INFO_RX_BITRATE))
5118 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01005119 }
Johannes Berg319090b2014-11-17 14:08:11 +01005120
5121 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5122 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5123 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5124 PUT_SINFO(TX_FAILED, tx_failed, u32);
5125 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08005126 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01005127 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5128 PUT_SINFO(LOCAL_PM, local_pm, u32);
5129 PUT_SINFO(PEER_PM, peer_pm, u32);
5130 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04005131 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01005132
Omer Efrat397c6572018-06-17 13:06:14 +03005133 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005134 bss_param = nla_nest_start_noflag(msg,
5135 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005136 if (!bss_param)
5137 goto nla_put_failure;
5138
David S. Miller9360ffd2012-03-29 04:41:26 -04005139 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5140 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5141 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5142 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5143 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5144 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5145 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5146 sinfo->bss_param.dtim_period) ||
5147 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5148 sinfo->bss_param.beacon_interval))
5149 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005150
5151 nla_nest_end(msg, bss_param);
5152 }
Omer Efrat397c6572018-06-17 13:06:14 +03005153 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005154 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5155 sizeof(struct nl80211_sta_flag_update),
5156 &sinfo->sta_flags))
5157 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005158
Johannes Bergd686b922016-04-26 09:54:11 +02005159 PUT_SINFO_U64(T_OFFSET, t_offset);
5160 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5161 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005162 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005163 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5164 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305165 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305166 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5167 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5168 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5169 }
Johannes Berg319090b2014-11-17 14:08:11 +01005170
5171#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005172#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005173
Arend van Spriel8689c052018-05-10 13:50:12 +02005174 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005175 struct nlattr *tidsattr;
5176 int tid;
5177
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005178 tidsattr = nla_nest_start_noflag(msg,
5179 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005180 if (!tidsattr)
5181 goto nla_put_failure;
5182
5183 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5184 struct cfg80211_tid_stats *tidstats;
5185 struct nlattr *tidattr;
5186
5187 tidstats = &sinfo->pertid[tid];
5188
5189 if (!tidstats->filled)
5190 continue;
5191
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005192 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005193 if (!tidattr)
5194 goto nla_put_failure;
5195
Johannes Bergd686b922016-04-26 09:54:11 +02005196#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005197 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005198 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5199 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005200 goto nla_put_failure; \
5201 } while (0)
5202
Johannes Bergd686b922016-04-26 09:54:11 +02005203 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5204 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5205 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5206 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005207
Johannes Bergd686b922016-04-26 09:54:11 +02005208#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005209 if ((tidstats->filled &
5210 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5211 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5212 NL80211_TID_STATS_TXQ_STATS))
5213 goto nla_put_failure;
5214
Johannes Berg6de39802014-12-19 12:34:00 +01005215 nla_nest_end(msg, tidattr);
5216 }
5217
5218 nla_nest_end(msg, tidsattr);
5219 }
5220
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005221 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005222
Johannes Berg319090b2014-11-17 14:08:11 +01005223 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005224 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5225 sinfo->assoc_req_ies))
5226 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005227
Johannes Berg7ea3e112018-05-18 11:40:44 +02005228 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005229 genlmsg_end(msg, hdr);
5230 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005231
5232 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005233 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005234 genlmsg_cancel(msg, hdr);
5235 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005236}
5237
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005238static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005239 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005240{
Johannes Berg73887fd2018-05-18 09:57:55 +02005241 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005242 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005243 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005244 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005245 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005246 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005247
Johannes Bergea90e0d2017-03-15 14:26:04 +01005248 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005249 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005250 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005251 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005252
Johannes Berg97990a02013-04-19 01:02:55 +02005253 if (!wdev->netdev) {
5254 err = -EINVAL;
5255 goto out_err;
5256 }
5257
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005258 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005259 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005260 goto out_err;
5261 }
5262
Johannes Bergbba95fe2008-07-29 13:22:51 +02005263 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005264 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005265 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005266 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005267 if (err == -ENOENT)
5268 break;
5269 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005270 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005271
Johannes Bergcf5ead82014-11-14 17:14:00 +01005272 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005273 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005274 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005275 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005276 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005277 goto out;
5278
5279 sta_idx++;
5280 }
5281
Johannes Bergbba95fe2008-07-29 13:22:51 +02005282 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005283 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005284 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005285 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005286 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005287
5288 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005289}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005290
Johannes Berg5727ef12007-12-19 02:03:34 +01005291static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5292{
Johannes Berg4c476992010-10-04 21:36:35 +02005293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5294 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005295 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005296 struct sk_buff *msg;
5297 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005298 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005299
Johannes Berg73887fd2018-05-18 09:57:55 +02005300 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005301
Johannes Berg73887fd2018-05-18 09:57:55 +02005302 if (!info->attrs[NL80211_ATTR_MAC])
5303 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005304
5305 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5306
Johannes Berg73887fd2018-05-18 09:57:55 +02005307 if (!rdev->ops->get_station)
5308 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005309
Johannes Berg73887fd2018-05-18 09:57:55 +02005310 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005311 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005312 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005313
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005315 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005316 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005317 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005318 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005319
Johannes Bergcf5ead82014-11-14 17:14:00 +01005320 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5321 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005322 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005323 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005324 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005325 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005326
Johannes Berg73887fd2018-05-18 09:57:55 +02005327 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005328}
5329
Johannes Berg77ee7c82013-02-15 00:48:33 +01005330int cfg80211_check_station_change(struct wiphy *wiphy,
5331 struct station_parameters *params,
5332 enum cfg80211_station_type statype)
5333{
Ayala Bekere4208422015-10-23 11:20:06 +03005334 if (params->listen_interval != -1 &&
5335 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005336 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005337
Ayala Beker17b94242016-03-17 15:41:38 +02005338 if (params->support_p2p_ps != -1 &&
5339 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5340 return -EINVAL;
5341
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005342 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005343 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5344 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005345 return -EINVAL;
5346
5347 /* When you run into this, adjust the code below for the new flag */
5348 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5349
5350 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005351 case CFG80211_STA_MESH_PEER_KERNEL:
5352 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005353 /*
5354 * No ignoring the TDLS flag here -- the userspace mesh
5355 * code doesn't have the bug of including TDLS in the
5356 * mask everywhere.
5357 */
5358 if (params->sta_flags_mask &
5359 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5360 BIT(NL80211_STA_FLAG_MFP) |
5361 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5362 return -EINVAL;
5363 break;
5364 case CFG80211_STA_TDLS_PEER_SETUP:
5365 case CFG80211_STA_TDLS_PEER_ACTIVE:
5366 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5367 return -EINVAL;
5368 /* ignore since it can't change */
5369 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5370 break;
5371 default:
5372 /* disallow mesh-specific things */
5373 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5374 return -EINVAL;
5375 if (params->local_pm)
5376 return -EINVAL;
5377 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5378 return -EINVAL;
5379 }
5380
5381 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5382 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5383 /* TDLS can't be set, ... */
5384 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5385 return -EINVAL;
5386 /*
5387 * ... but don't bother the driver with it. This works around
5388 * a hostapd/wpa_supplicant issue -- it always includes the
5389 * TLDS_PEER flag in the mask even for AP mode.
5390 */
5391 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5392 }
5393
Ayala Beker47edb112015-09-21 15:49:53 +03005394 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5395 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005396 /* reject other things that can't change */
5397 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5398 return -EINVAL;
5399 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5400 return -EINVAL;
5401 if (params->supported_rates)
5402 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005403 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5404 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005405 return -EINVAL;
5406 }
5407
Ayala Beker47edb112015-09-21 15:49:53 +03005408 if (statype != CFG80211_STA_AP_CLIENT &&
5409 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005410 if (params->vlan)
5411 return -EINVAL;
5412 }
5413
5414 switch (statype) {
5415 case CFG80211_STA_AP_MLME_CLIENT:
5416 /* Use this only for authorizing/unauthorizing a station */
5417 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5418 return -EOPNOTSUPP;
5419 break;
5420 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005421 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005422 /* accept only the listed bits */
5423 if (params->sta_flags_mask &
5424 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5425 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5426 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5427 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5428 BIT(NL80211_STA_FLAG_WME) |
5429 BIT(NL80211_STA_FLAG_MFP)))
5430 return -EINVAL;
5431
5432 /* but authenticated/associated only if driver handles it */
5433 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5434 params->sta_flags_mask &
5435 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5436 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5437 return -EINVAL;
5438 break;
5439 case CFG80211_STA_IBSS:
5440 case CFG80211_STA_AP_STA:
5441 /* reject any changes other than AUTHORIZED */
5442 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5443 return -EINVAL;
5444 break;
5445 case CFG80211_STA_TDLS_PEER_SETUP:
5446 /* reject any changes other than AUTHORIZED or WME */
5447 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5448 BIT(NL80211_STA_FLAG_WME)))
5449 return -EINVAL;
5450 /* force (at least) rates when authorizing */
5451 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5452 !params->supported_rates)
5453 return -EINVAL;
5454 break;
5455 case CFG80211_STA_TDLS_PEER_ACTIVE:
5456 /* reject any changes */
5457 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005458 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005459 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5460 return -EINVAL;
5461 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005462 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005463 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5464 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005465 return -EINVAL;
5466 break;
5467 }
5468
Beni Lev06f7c882016-07-19 19:28:56 +03005469 /*
5470 * Older kernel versions ignored this attribute entirely, so don't
5471 * reject attempts to update it but mark it as unused instead so the
5472 * driver won't look at the data.
5473 */
5474 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5475 statype != CFG80211_STA_TDLS_PEER_SETUP)
5476 params->opmode_notif_used = false;
5477
Johannes Berg77ee7c82013-02-15 00:48:33 +01005478 return 0;
5479}
5480EXPORT_SYMBOL(cfg80211_check_station_change);
5481
Johannes Berg5727ef12007-12-19 02:03:34 +01005482/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005483 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005484 */
Johannes Berg80b99892011-11-18 16:23:01 +01005485static struct net_device *get_vlan(struct genl_info *info,
5486 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005487{
Johannes Berg463d0182009-07-14 00:33:35 +02005488 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005489 struct net_device *v;
5490 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005491
Johannes Berg80b99892011-11-18 16:23:01 +01005492 if (!vlanattr)
5493 return NULL;
5494
5495 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5496 if (!v)
5497 return ERR_PTR(-ENODEV);
5498
5499 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5500 ret = -EINVAL;
5501 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005502 }
Johannes Berg80b99892011-11-18 16:23:01 +01005503
Johannes Berg77ee7c82013-02-15 00:48:33 +01005504 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5505 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5506 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5507 ret = -EINVAL;
5508 goto error;
5509 }
5510
Johannes Berg80b99892011-11-18 16:23:01 +01005511 if (!netif_running(v)) {
5512 ret = -ENETDOWN;
5513 goto error;
5514 }
5515
5516 return v;
5517 error:
5518 dev_put(v);
5519 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005520}
5521
Johannes Berg94e860f2014-01-20 23:58:15 +01005522static const struct nla_policy
5523nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005524 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5525 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5526};
5527
Johannes Bergff2766912013-02-15 00:09:01 +01005528static int nl80211_parse_sta_wme(struct genl_info *info,
5529 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005530{
Jouni Malinendf881292013-02-14 21:10:54 +02005531 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5532 struct nlattr *nla;
5533 int err;
5534
Jouni Malinendf881292013-02-14 21:10:54 +02005535 /* parse WME attributes if present */
5536 if (!info->attrs[NL80211_ATTR_STA_WME])
5537 return 0;
5538
5539 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02005540 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5541 nl80211_sta_wme_policy,
5542 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005543 if (err)
5544 return err;
5545
5546 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5547 params->uapsd_queues = nla_get_u8(
5548 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5549 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5550 return -EINVAL;
5551
5552 if (tb[NL80211_STA_WME_MAX_SP])
5553 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5554
5555 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5556 return -EINVAL;
5557
5558 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5559
5560 return 0;
5561}
5562
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305563static int nl80211_parse_sta_channel_info(struct genl_info *info,
5564 struct station_parameters *params)
5565{
5566 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5567 params->supported_channels =
5568 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5569 params->supported_channels_len =
5570 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5571 /*
5572 * Need to include at least one (first channel, number of
5573 * channels) tuple for each subband, and must have proper
5574 * tuples for the rest of the data as well.
5575 */
5576 if (params->supported_channels_len < 2)
5577 return -EINVAL;
5578 if (params->supported_channels_len % 2)
5579 return -EINVAL;
5580 }
5581
5582 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5583 params->supported_oper_classes =
5584 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5585 params->supported_oper_classes_len =
5586 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5587 /*
5588 * The value of the Length field of the Supported Operating
5589 * Classes element is between 2 and 253.
5590 */
5591 if (params->supported_oper_classes_len < 2 ||
5592 params->supported_oper_classes_len > 253)
5593 return -EINVAL;
5594 }
5595 return 0;
5596}
5597
Johannes Bergff2766912013-02-15 00:09:01 +01005598static int nl80211_set_station_tdls(struct genl_info *info,
5599 struct station_parameters *params)
5600{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305601 int err;
Johannes Bergff2766912013-02-15 00:09:01 +01005602 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f562013-05-16 20:11:08 +03005603 if (info->attrs[NL80211_ATTR_PEER_AID])
5604 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff2766912013-02-15 00:09:01 +01005605 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5606 params->ht_capa =
5607 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5608 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5609 params->vht_capa =
5610 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005611 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5612 params->he_capa =
5613 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5614 params->he_capa_len =
5615 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5616
5617 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5618 return -EINVAL;
5619 }
Johannes Bergff2766912013-02-15 00:09:01 +01005620
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305621 err = nl80211_parse_sta_channel_info(info, params);
5622 if (err)
5623 return err;
5624
Johannes Bergff2766912013-02-15 00:09:01 +01005625 return nl80211_parse_sta_wme(info, params);
5626}
5627
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305628static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5629 struct station_parameters *params)
5630{
5631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5632 int idx;
5633
5634 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5635 if (!rdev->ops->set_tx_power ||
5636 !wiphy_ext_feature_isset(&rdev->wiphy,
5637 NL80211_EXT_FEATURE_STA_TX_PWR))
5638 return -EOPNOTSUPP;
5639
5640 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5641 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5642
5643 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5644 idx = NL80211_ATTR_STA_TX_POWER;
5645
5646 if (info->attrs[idx])
5647 params->txpwr.power =
5648 nla_get_s16(info->attrs[idx]);
5649 else
5650 return -EINVAL;
5651 }
5652 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5653 }
5654
5655 return 0;
5656}
5657
Johannes Berg5727ef12007-12-19 02:03:34 +01005658static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5659{
Johannes Berg4c476992010-10-04 21:36:35 +02005660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005661 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005662 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005663 u8 *mac_addr;
5664 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005665
5666 memset(&params, 0, sizeof(params));
5667
Johannes Berg77ee7c82013-02-15 00:48:33 +01005668 if (!rdev->ops->change_station)
5669 return -EOPNOTSUPP;
5670
Ayala Bekere4208422015-10-23 11:20:06 +03005671 /*
5672 * AID and listen_interval properties can be set only for unassociated
5673 * station. Include these parameters here and will check them in
5674 * cfg80211_check_station_change().
5675 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005676 if (info->attrs[NL80211_ATTR_STA_AID])
5677 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005678
5679 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5680 params.listen_interval =
5681 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5682 else
5683 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005684
Johannes Bergab0d76f2018-10-02 10:00:07 +02005685 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5686 params.support_p2p_ps =
5687 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5688 else
Ayala Beker17b94242016-03-17 15:41:38 +02005689 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005690
Johannes Berg5727ef12007-12-19 02:03:34 +01005691 if (!info->attrs[NL80211_ATTR_MAC])
5692 return -EINVAL;
5693
5694 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5695
5696 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5697 params.supported_rates =
5698 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5699 params.supported_rates_len =
5700 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5701 }
5702
Jouni Malinen9d62a982013-02-14 21:10:13 +02005703 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5704 params.capability =
5705 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5706 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5707 }
5708
5709 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5710 params.ext_capab =
5711 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5712 params.ext_capab_len =
5713 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5714 }
5715
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005716 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005717 return -EINVAL;
5718
Johannes Bergab0d76f2018-10-02 10:00:07 +02005719 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005720 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005721 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005722
Johannes Bergf8bacc22013-02-14 23:27:01 +01005723 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005724 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005725 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005726 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005727 params.peer_aid = nla_get_u16(
5728 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005729 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5730 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005731
Johannes Bergab0d76f2018-10-02 10:00:07 +02005732 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5733 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005734 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5735
Beni Lev06f7c882016-07-19 19:28:56 +03005736 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5737 params.opmode_notif_used = true;
5738 params.opmode_notif =
5739 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5740 }
5741
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005742 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5743 params.airtime_weight =
5744 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5745
5746 if (params.airtime_weight &&
5747 !wiphy_ext_feature_isset(&rdev->wiphy,
5748 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5749 return -EOPNOTSUPP;
5750
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305751 err = nl80211_parse_sta_txpower_setting(info, &params);
5752 if (err)
5753 return err;
5754
Johannes Berg77ee7c82013-02-15 00:48:33 +01005755 /* Include parameters for TDLS peer (will check later) */
5756 err = nl80211_set_station_tdls(info, &params);
5757 if (err)
5758 return err;
5759
5760 params.vlan = get_vlan(info, rdev);
5761 if (IS_ERR(params.vlan))
5762 return PTR_ERR(params.vlan);
5763
Johannes Berga97f4422009-06-18 17:23:43 +02005764 switch (dev->ieee80211_ptr->iftype) {
5765 case NL80211_IFTYPE_AP:
5766 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005767 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005768 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005769 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005770 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005771 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005772 break;
5773 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005774 err = -EOPNOTSUPP;
5775 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005776 }
5777
Johannes Berg77ee7c82013-02-15 00:48:33 +01005778 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005779 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005780
Johannes Berg77ee7c82013-02-15 00:48:33 +01005781 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005782 if (params.vlan)
5783 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005784
Johannes Berg5727ef12007-12-19 02:03:34 +01005785 return err;
5786}
5787
5788static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5789{
Johannes Berg4c476992010-10-04 21:36:35 +02005790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005791 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005792 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005793 struct station_parameters params;
5794 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005795 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5796 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005797
5798 memset(&params, 0, sizeof(params));
5799
Johannes Berg984c3112013-02-14 23:43:25 +01005800 if (!rdev->ops->add_station)
5801 return -EOPNOTSUPP;
5802
Johannes Berg5727ef12007-12-19 02:03:34 +01005803 if (!info->attrs[NL80211_ATTR_MAC])
5804 return -EINVAL;
5805
Johannes Berg5727ef12007-12-19 02:03:34 +01005806 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5807 return -EINVAL;
5808
5809 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5810 return -EINVAL;
5811
Jouni Malinen5e4b6f562013-05-16 20:11:08 +03005812 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5813 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005814 return -EINVAL;
5815
Johannes Berg5727ef12007-12-19 02:03:34 +01005816 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5817 params.supported_rates =
5818 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5819 params.supported_rates_len =
5820 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5821 params.listen_interval =
5822 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005823
Ayala Beker17b94242016-03-17 15:41:38 +02005824 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005825 params.support_p2p_ps =
5826 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005827 } else {
5828 /*
5829 * if not specified, assume it's supported for P2P GO interface,
5830 * and is NOT supported for AP interface
5831 */
5832 params.support_p2p_ps =
5833 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5834 }
5835
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005836 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f562013-05-16 20:11:08 +03005837 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005838 else
5839 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005840
Jouni Malinen9d62a982013-02-14 21:10:13 +02005841 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5842 params.capability =
5843 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5844 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5845 }
5846
5847 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5848 params.ext_capab =
5849 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5850 params.ext_capab_len =
5851 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5852 }
5853
Jouni Malinen36aedc92008-08-25 11:58:58 +03005854 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5855 params.ht_capa =
5856 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005857
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005858 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5859 params.vht_capa =
5860 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5861
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005862 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5863 params.he_capa =
5864 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5865 params.he_capa_len =
5866 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5867
5868 /* max len is validated in nla policy */
5869 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5870 return -EINVAL;
5871 }
5872
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005873 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5874 params.opmode_notif_used = true;
5875 params.opmode_notif =
5876 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5877 }
5878
Johannes Bergab0d76f2018-10-02 10:00:07 +02005879 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005880 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005881 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005882
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005883 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5884 params.airtime_weight =
5885 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5886
5887 if (params.airtime_weight &&
5888 !wiphy_ext_feature_isset(&rdev->wiphy,
5889 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5890 return -EOPNOTSUPP;
5891
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305892 err = nl80211_parse_sta_txpower_setting(info, &params);
5893 if (err)
5894 return err;
5895
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305896 err = nl80211_parse_sta_channel_info(info, &params);
5897 if (err)
5898 return err;
5899
Johannes Bergff2766912013-02-15 00:09:01 +01005900 err = nl80211_parse_sta_wme(info, &params);
5901 if (err)
5902 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005903
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005904 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005905 return -EINVAL;
5906
Johannes Berg496fcc22015-03-12 08:53:27 +02005907 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5908 * as userspace might just pass through the capabilities from the IEs
5909 * directly, rather than enforcing this restriction and returning an
5910 * error in this case.
5911 */
5912 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5913 params.ht_capa = NULL;
5914 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005915
5916 /* HE requires WME */
5917 if (params.he_capa_len)
5918 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005919 }
5920
Johannes Berg77ee7c82013-02-15 00:48:33 +01005921 /* When you run into this, adjust the code below for the new flag */
5922 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5923
Johannes Bergbdd90d52011-12-14 12:20:27 +01005924 switch (dev->ieee80211_ptr->iftype) {
5925 case NL80211_IFTYPE_AP:
5926 case NL80211_IFTYPE_AP_VLAN:
5927 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005928 /* ignore WME attributes if iface/sta is not capable */
5929 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5930 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5931 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005932
Johannes Bergbdd90d52011-12-14 12:20:27 +01005933 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005934 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5935 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005936 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005937 /* but don't bother the driver with it */
5938 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005939
Johannes Bergd582cff2012-10-26 17:53:44 +02005940 /* allow authenticated/associated only if driver handles it */
5941 if (!(rdev->wiphy.features &
5942 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005943 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005944 return -EINVAL;
5945
Johannes Bergbda95eb2015-11-26 16:26:13 +01005946 /* Older userspace, or userspace wanting to be compatible with
5947 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5948 * and assoc flags in the mask, but assumes the station will be
5949 * added as associated anyway since this was the required driver
5950 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5951 * introduced.
5952 * In order to not bother drivers with this quirk in the API
5953 * set the flags in both the mask and set for new stations in
5954 * this case.
5955 */
5956 if (!(params.sta_flags_mask & auth_assoc)) {
5957 params.sta_flags_mask |= auth_assoc;
5958 params.sta_flags_set |= auth_assoc;
5959 }
5960
Johannes Bergbdd90d52011-12-14 12:20:27 +01005961 /* must be last in here for error handling */
5962 params.vlan = get_vlan(info, rdev);
5963 if (IS_ERR(params.vlan))
5964 return PTR_ERR(params.vlan);
5965 break;
5966 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005967 /* ignore uAPSD data */
5968 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5969
Johannes Bergd582cff2012-10-26 17:53:44 +02005970 /* associated is disallowed */
5971 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5972 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005973 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005974 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5975 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005976 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005977 break;
5978 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005979 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005980 /* ignore uAPSD data */
5981 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5982
Johannes Berg77ee7c82013-02-15 00:48:33 +01005983 /* these are disallowed */
5984 if (params.sta_flags_mask &
5985 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5986 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005987 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005988 /* Only TDLS peers can be added */
5989 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5990 return -EINVAL;
5991 /* Can only add if TDLS ... */
5992 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5993 return -EOPNOTSUPP;
5994 /* ... with external setup is supported */
5995 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5996 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005997 /*
5998 * Older wpa_supplicant versions always mark the TDLS peer
5999 * as authorized, but it shouldn't yet be.
6000 */
6001 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01006002 break;
6003 default:
6004 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006005 }
6006
Johannes Bergbdd90d52011-12-14 12:20:27 +01006007 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01006008
Hila Gonene35e4d22012-06-27 17:19:42 +03006009 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006010
Johannes Berg5727ef12007-12-19 02:03:34 +01006011 if (params.vlan)
6012 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01006013 return err;
6014}
6015
6016static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6017{
Johannes Berg4c476992010-10-04 21:36:35 +02006018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6019 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03006020 struct station_del_parameters params;
6021
6022 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01006023
6024 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03006025 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006026
Johannes Berge80cf852009-05-11 14:43:13 +02006027 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02006028 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02006029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02006030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6031 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02006032
Johannes Berg4c476992010-10-04 21:36:35 +02006033 if (!rdev->ops->del_station)
6034 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01006035
Jouni Malinen98856862014-10-20 13:20:45 +03006036 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6037 params.subtype =
6038 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6039 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6040 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6041 return -EINVAL;
6042 } else {
6043 /* Default to Deauthentication frame */
6044 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6045 }
6046
6047 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6048 params.reason_code =
6049 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6050 if (params.reason_code == 0)
6051 return -EINVAL; /* 0 is reserved */
6052 } else {
6053 /* Default to reason code 2 */
6054 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6055 }
6056
Jouni Malinen89c771e2014-10-10 20:52:40 +03006057 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006058}
6059
Eric W. Biederman15e47302012-09-07 20:12:54 +00006060static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006061 int flags, struct net_device *dev,
6062 u8 *dst, u8 *next_hop,
6063 struct mpath_info *pinfo)
6064{
6065 void *hdr;
6066 struct nlattr *pinfoattr;
6067
Henning Rogge1ef4c852014-11-04 16:14:58 +01006068 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006069 if (!hdr)
6070 return -1;
6071
David S. Miller9360ffd2012-03-29 04:41:26 -04006072 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6073 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6074 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6075 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6076 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02006077
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006078 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006079 if (!pinfoattr)
6080 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006081 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6082 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6083 pinfo->frame_qlen))
6084 goto nla_put_failure;
6085 if (((pinfo->filled & MPATH_INFO_SN) &&
6086 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6087 ((pinfo->filled & MPATH_INFO_METRIC) &&
6088 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6089 pinfo->metric)) ||
6090 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6091 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6092 pinfo->exptime)) ||
6093 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6094 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6095 pinfo->flags)) ||
6096 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6097 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6098 pinfo->discovery_timeout)) ||
6099 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6100 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08006101 pinfo->discovery_retries)) ||
6102 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6103 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08006104 pinfo->hop_count)) ||
6105 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6106 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6107 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006108 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006109
6110 nla_nest_end(msg, pinfoattr);
6111
Johannes Berg053c0952015-01-16 22:09:00 +01006112 genlmsg_end(msg, hdr);
6113 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006114
6115 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07006116 genlmsg_cancel(msg, hdr);
6117 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006118}
6119
6120static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006121 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006122{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006123 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006124 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006125 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006126 u8 dst[ETH_ALEN];
6127 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02006128 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006129 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006130
Johannes Bergea90e0d2017-03-15 14:26:04 +01006131 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006132 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006133 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006134 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006135
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006136 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006137 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006138 goto out_err;
6139 }
6140
Johannes Berg97990a02013-04-19 01:02:55 +02006141 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006142 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006143 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006144 }
6145
Johannes Bergbba95fe2008-07-29 13:22:51 +02006146 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006147 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006148 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006149 if (err == -ENOENT)
6150 break;
6151 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006152 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006153
Eric W. Biederman15e47302012-09-07 20:12:54 +00006154 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006155 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006156 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006157 &pinfo) < 0)
6158 goto out;
6159
6160 path_idx++;
6161 }
6162
Johannes Bergbba95fe2008-07-29 13:22:51 +02006163 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006164 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006165 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006166 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006167 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006168 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006169}
6170
6171static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6172{
Johannes Berg4c476992010-10-04 21:36:35 +02006173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006174 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006175 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006176 struct mpath_info pinfo;
6177 struct sk_buff *msg;
6178 u8 *dst = NULL;
6179 u8 next_hop[ETH_ALEN];
6180
6181 memset(&pinfo, 0, sizeof(pinfo));
6182
6183 if (!info->attrs[NL80211_ATTR_MAC])
6184 return -EINVAL;
6185
6186 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6187
Johannes Berg4c476992010-10-04 21:36:35 +02006188 if (!rdev->ops->get_mpath)
6189 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006190
Johannes Berg4c476992010-10-04 21:36:35 +02006191 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6192 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006193
Hila Gonene35e4d22012-06-27 17:19:42 +03006194 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006195 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006196 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006197
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006199 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006200 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006201
Eric W. Biederman15e47302012-09-07 20:12:54 +00006202 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006203 dev, dst, next_hop, &pinfo) < 0) {
6204 nlmsg_free(msg);
6205 return -ENOBUFS;
6206 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006207
Johannes Berg4c476992010-10-04 21:36:35 +02006208 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006209}
6210
6211static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6212{
Johannes Berg4c476992010-10-04 21:36:35 +02006213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6214 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006215 u8 *dst = NULL;
6216 u8 *next_hop = NULL;
6217
6218 if (!info->attrs[NL80211_ATTR_MAC])
6219 return -EINVAL;
6220
6221 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6222 return -EINVAL;
6223
6224 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6225 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6226
Johannes Berg4c476992010-10-04 21:36:35 +02006227 if (!rdev->ops->change_mpath)
6228 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006229
Johannes Berg4c476992010-10-04 21:36:35 +02006230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6231 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006232
Hila Gonene35e4d22012-06-27 17:19:42 +03006233 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006234}
Johannes Berg4c476992010-10-04 21:36:35 +02006235
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006236static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6237{
Johannes Berg4c476992010-10-04 21:36:35 +02006238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6239 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006240 u8 *dst = NULL;
6241 u8 *next_hop = NULL;
6242
6243 if (!info->attrs[NL80211_ATTR_MAC])
6244 return -EINVAL;
6245
6246 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6247 return -EINVAL;
6248
6249 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6250 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6251
Johannes Berg4c476992010-10-04 21:36:35 +02006252 if (!rdev->ops->add_mpath)
6253 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006254
Johannes Berg4c476992010-10-04 21:36:35 +02006255 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6256 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006257
Hila Gonene35e4d22012-06-27 17:19:42 +03006258 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006259}
6260
6261static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6262{
Johannes Berg4c476992010-10-04 21:36:35 +02006263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6264 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006265 u8 *dst = NULL;
6266
6267 if (info->attrs[NL80211_ATTR_MAC])
6268 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6269
Johannes Berg4c476992010-10-04 21:36:35 +02006270 if (!rdev->ops->del_mpath)
6271 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006272
Hila Gonene35e4d22012-06-27 17:19:42 +03006273 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006274}
6275
Henning Rogge66be7d22014-09-12 08:58:49 +02006276static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6277{
6278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6279 int err;
6280 struct net_device *dev = info->user_ptr[1];
6281 struct mpath_info pinfo;
6282 struct sk_buff *msg;
6283 u8 *dst = NULL;
6284 u8 mpp[ETH_ALEN];
6285
6286 memset(&pinfo, 0, sizeof(pinfo));
6287
6288 if (!info->attrs[NL80211_ATTR_MAC])
6289 return -EINVAL;
6290
6291 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6292
6293 if (!rdev->ops->get_mpp)
6294 return -EOPNOTSUPP;
6295
6296 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6297 return -EOPNOTSUPP;
6298
6299 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6300 if (err)
6301 return err;
6302
6303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6304 if (!msg)
6305 return -ENOMEM;
6306
6307 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6308 dev, dst, mpp, &pinfo) < 0) {
6309 nlmsg_free(msg);
6310 return -ENOBUFS;
6311 }
6312
6313 return genlmsg_reply(msg, info);
6314}
6315
6316static int nl80211_dump_mpp(struct sk_buff *skb,
6317 struct netlink_callback *cb)
6318{
6319 struct mpath_info pinfo;
6320 struct cfg80211_registered_device *rdev;
6321 struct wireless_dev *wdev;
6322 u8 dst[ETH_ALEN];
6323 u8 mpp[ETH_ALEN];
6324 int path_idx = cb->args[2];
6325 int err;
6326
Johannes Bergea90e0d2017-03-15 14:26:04 +01006327 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006328 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006329 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006330 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006331
6332 if (!rdev->ops->dump_mpp) {
6333 err = -EOPNOTSUPP;
6334 goto out_err;
6335 }
6336
6337 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6338 err = -EOPNOTSUPP;
6339 goto out_err;
6340 }
6341
6342 while (1) {
6343 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6344 mpp, &pinfo);
6345 if (err == -ENOENT)
6346 break;
6347 if (err)
6348 goto out_err;
6349
6350 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6351 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6352 wdev->netdev, dst, mpp,
6353 &pinfo) < 0)
6354 goto out;
6355
6356 path_idx++;
6357 }
6358
6359 out:
6360 cb->args[2] = path_idx;
6361 err = skb->len;
6362 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006363 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006364 return err;
6365}
6366
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006367static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6368{
Johannes Berg4c476992010-10-04 21:36:35 +02006369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6370 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006371 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006372 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006373 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006374
6375 memset(&params, 0, sizeof(params));
6376 /* default to not changing parameters */
6377 params.use_cts_prot = -1;
6378 params.use_short_preamble = -1;
6379 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006380 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006381 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006382 params.p2p_ctwindow = -1;
6383 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006384
6385 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6386 params.use_cts_prot =
6387 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6388 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6389 params.use_short_preamble =
6390 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6391 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6392 params.use_short_slot_time =
6393 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006394 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6395 params.basic_rates =
6396 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6397 params.basic_rates_len =
6398 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6399 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006400 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6401 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006402 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6403 params.ht_opmode =
6404 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006405
Johannes Berg53cabad2012-11-14 15:17:28 +01006406 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6407 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6408 return -EINVAL;
6409 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006410 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006411 if (params.p2p_ctwindow != 0 &&
6412 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6413 return -EINVAL;
6414 }
6415
6416 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6417 u8 tmp;
6418
6419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6420 return -EINVAL;
6421 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006422 params.p2p_opp_ps = tmp;
6423 if (params.p2p_opp_ps &&
6424 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6425 return -EINVAL;
6426 }
6427
Johannes Berg4c476992010-10-04 21:36:35 +02006428 if (!rdev->ops->change_bss)
6429 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006430
Johannes Berg074ac8d2010-09-16 14:58:22 +02006431 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006432 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6433 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006434
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006435 wdev_lock(wdev);
6436 err = rdev_change_bss(rdev, dev, &params);
6437 wdev_unlock(wdev);
6438
6439 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006440}
6441
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006442static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6443{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006444 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006445 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006446 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006447 u32 owner_nlportid;
6448
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006449 /*
6450 * You should only get this when cfg80211 hasn't yet initialized
6451 * completely when built-in to the kernel right between the time
6452 * window between nl80211_init() and regulatory_init(), if that is
6453 * even possible.
6454 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006455 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006456 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006457
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006458 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6459 user_reg_hint_type =
6460 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6461 else
6462 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6463
6464 switch (user_reg_hint_type) {
6465 case NL80211_USER_REG_HINT_USER:
6466 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006467 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6468 return -EINVAL;
6469
6470 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6471 return regulatory_hint_user(data, user_reg_hint_type);
6472 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006473 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6474 owner_nlportid = info->snd_portid;
6475 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6476 } else {
6477 owner_nlportid = 0;
6478 is_indoor = true;
6479 }
6480
6481 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006482 default:
6483 return -EINVAL;
6484 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006485}
6486
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006487static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6488{
6489 return reg_reload_regdb();
6490}
6491
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006492static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006493 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006494{
Johannes Berg4c476992010-10-04 21:36:35 +02006495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006496 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006497 struct wireless_dev *wdev = dev->ieee80211_ptr;
6498 struct mesh_config cur_params;
6499 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006500 void *hdr;
6501 struct nlattr *pinfoattr;
6502 struct sk_buff *msg;
6503
Johannes Berg29cbe682010-12-03 09:20:44 +01006504 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6505 return -EOPNOTSUPP;
6506
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006507 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006508 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006509
Johannes Berg29cbe682010-12-03 09:20:44 +01006510 wdev_lock(wdev);
6511 /* If not connected, get default parameters */
6512 if (!wdev->mesh_id_len)
6513 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6514 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006515 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006516 wdev_unlock(wdev);
6517
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006518 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006519 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006520
6521 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006523 if (!msg)
6524 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006525 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006526 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006527 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006528 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006529 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006530 if (!pinfoattr)
6531 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006532 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6533 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6534 cur_params.dot11MeshRetryTimeout) ||
6535 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6536 cur_params.dot11MeshConfirmTimeout) ||
6537 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6538 cur_params.dot11MeshHoldingTimeout) ||
6539 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6540 cur_params.dot11MeshMaxPeerLinks) ||
6541 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6542 cur_params.dot11MeshMaxRetries) ||
6543 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6544 cur_params.dot11MeshTTL) ||
6545 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6546 cur_params.element_ttl) ||
6547 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6548 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006549 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6550 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006551 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6552 cur_params.dot11MeshHWMPmaxPREQretries) ||
6553 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6554 cur_params.path_refresh_time) ||
6555 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6556 cur_params.min_discovery_timeout) ||
6557 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6558 cur_params.dot11MeshHWMPactivePathTimeout) ||
6559 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6560 cur_params.dot11MeshHWMPpreqMinInterval) ||
6561 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6562 cur_params.dot11MeshHWMPperrMinInterval) ||
6563 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6564 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6565 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6566 cur_params.dot11MeshHWMPRootMode) ||
6567 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6568 cur_params.dot11MeshHWMPRannInterval) ||
6569 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6570 cur_params.dot11MeshGateAnnouncementProtocol) ||
6571 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6572 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006573 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006574 cur_params.rssi_threshold) ||
6575 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006576 cur_params.ht_opmode) ||
6577 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6578 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6579 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006580 cur_params.dot11MeshHWMProotInterval) ||
6581 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006582 cur_params.dot11MeshHWMPconfirmationInterval) ||
6583 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6584 cur_params.power_mode) ||
6585 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006586 cur_params.dot11MeshAwakeWindowDuration) ||
6587 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006588 cur_params.plink_timeout) ||
6589 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6590 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006591 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006592 nla_nest_end(msg, pinfoattr);
6593 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006594 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006595
Johannes Berg3b858752009-03-12 09:55:09 +01006596 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006597 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006598 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006599 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006600}
6601
Johannes Bergab0d76f2018-10-02 10:00:07 +02006602static const struct nla_policy
6603nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6604 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6605 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6606 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6607 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6608 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6609 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6610 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6611 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6612 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6613 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6614 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6615 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6616 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6617 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006618 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6619 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006620 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006621 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006622 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6623 NLA_POLICY_MIN(NLA_U16, 1),
6624 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6625 NLA_POLICY_MIN(NLA_U16, 1),
6626 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6627 NLA_POLICY_MIN(NLA_U16, 1),
6628 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6629 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6630 NLA_POLICY_MIN(NLA_U16, 1),
6631 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6632 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6633 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6634 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006635 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006636 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006637 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6638 NLA_POLICY_MIN(NLA_U16, 1),
6639 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6640 NLA_POLICY_MIN(NLA_U16, 1),
6641 [NL80211_MESHCONF_POWER_MODE] =
6642 NLA_POLICY_RANGE(NLA_U32,
6643 NL80211_MESH_POWER_ACTIVE,
6644 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006645 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006646 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006647 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006648};
6649
Javier Cardonac80d5452010-12-16 17:37:49 -08006650static const struct nla_policy
6651 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006652 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006653 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6654 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006655 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006656 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006657 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006658 [NL80211_MESH_SETUP_IE] =
6659 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6660 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006661 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006662};
6663
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006664static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006665 struct mesh_config *cfg,
6666 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006667{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006668 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006669 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006670 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006671
Johannes Bergab0d76f2018-10-02 10:00:07 +02006672#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6673do { \
6674 if (tb[attr]) { \
6675 cfg->param = fn(tb[attr]); \
6676 mask |= BIT((attr) - 1); \
6677 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006678} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006679
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006680 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006681 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006682 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 -07006683 return -EINVAL;
6684
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006685 /* This makes sure that there aren't more than 32 mesh config
6686 * parameters (otherwise our bitfield scheme would not work.) */
6687 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6688
6689 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6691 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6693 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6694 nla_get_u16);
6695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6696 NL80211_MESHCONF_HOLDING_TIMEOUT,
6697 nla_get_u16);
6698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6699 NL80211_MESHCONF_MAX_PEER_LINKS,
6700 nla_get_u16);
6701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6702 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6704 NL80211_MESHCONF_TTL, nla_get_u8);
6705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6706 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6708 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6709 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006711 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006712 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006713 nla_get_u32);
6714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6715 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6716 nla_get_u8);
6717 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6718 NL80211_MESHCONF_PATH_REFRESH_TIME,
6719 nla_get_u32);
6720 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6721 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6722 return -EINVAL;
6723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6724 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6725 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006727 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006728 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006729 nla_get_u32);
6730 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6731 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6732 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6733 return -EINVAL;
6734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006735 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006736 nla_get_u16);
6737 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006738 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006739 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006741 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006742 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006743 nla_get_u16);
6744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6745 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6747 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6748 nla_get_u16);
6749 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006750 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006751 nla_get_u8);
6752 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6753 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6755 NL80211_MESHCONF_RSSI_THRESHOLD,
6756 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6758 NL80211_MESHCONF_CONNECTED_TO_GATE,
6759 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006760 /*
6761 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006762 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006763 */
6764 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6765 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6766
6767 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6768 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6769 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6770 return -EINVAL;
6771
Bob Copeland188f60a2018-06-24 21:10:49 -04006772 /* NON_HT_STA bit is reserved, but some programs set it */
6773 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006774
Masashi Honma97572352016-08-03 10:07:44 +09006775 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006776 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006777 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006778 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006779 dot11MeshHWMPactivePathToRootTimeout, mask,
6780 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6781 nla_get_u32);
6782 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6783 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6784 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6785 return -EINVAL;
6786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6787 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6788 nla_get_u16);
6789 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6790 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006791 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006792 nla_get_u16);
6793 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6794 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6796 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6797 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6798 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006799 if (mask_out)
6800 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006801
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006802 return 0;
6803
6804#undef FILL_IN_MESH_PARAM_IF_SET
6805}
6806
Javier Cardonac80d5452010-12-16 17:37:49 -08006807static int nl80211_parse_mesh_setup(struct genl_info *info,
6808 struct mesh_setup *setup)
6809{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006811 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6812
6813 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6814 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006815 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 -08006816 return -EINVAL;
6817
Javier Cardonad299a1f2012-03-31 11:31:33 -07006818 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6819 setup->sync_method =
6820 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6821 IEEE80211_SYNC_METHOD_VENDOR :
6822 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6823
Javier Cardonac80d5452010-12-16 17:37:49 -08006824 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6825 setup->path_sel_proto =
6826 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6827 IEEE80211_PATH_PROTOCOL_VENDOR :
6828 IEEE80211_PATH_PROTOCOL_HWMP;
6829
6830 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6831 setup->path_metric =
6832 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6833 IEEE80211_PATH_METRIC_VENDOR :
6834 IEEE80211_PATH_METRIC_AIRTIME;
6835
Javier Cardona581a8b02011-04-07 15:08:27 -07006836 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006837 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006838 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006839 setup->ie = nla_data(ieattr);
6840 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006841 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006842 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6843 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6844 return -EINVAL;
6845 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006846 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6847 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006848 if (setup->is_secure)
6849 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006850
Colleen Twitty6e16d902013-05-08 11:45:59 -07006851 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6852 if (!setup->user_mpm)
6853 return -EINVAL;
6854 setup->auth_id =
6855 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6856 }
6857
Javier Cardonac80d5452010-12-16 17:37:49 -08006858 return 0;
6859}
6860
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006861static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006862 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006863{
6864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6865 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006866 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006867 struct mesh_config cfg;
6868 u32 mask;
6869 int err;
6870
Johannes Berg29cbe682010-12-03 09:20:44 +01006871 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6872 return -EOPNOTSUPP;
6873
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006874 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006875 return -EOPNOTSUPP;
6876
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006877 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006878 if (err)
6879 return err;
6880
Johannes Berg29cbe682010-12-03 09:20:44 +01006881 wdev_lock(wdev);
6882 if (!wdev->mesh_id_len)
6883 err = -ENOLINK;
6884
6885 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006886 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006887
6888 wdev_unlock(wdev);
6889
6890 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006891}
6892
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006893static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6894 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006895{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006896 struct nlattr *nl_reg_rules;
6897 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006898
Johannes Berg458f4f92012-12-06 15:47:38 +01006899 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6900 (regdom->dfs_region &&
6901 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006902 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006903
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006904 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006905 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006906 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006907
Johannes Berg458f4f92012-12-06 15:47:38 +01006908 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006909 struct nlattr *nl_reg_rule;
6910 const struct ieee80211_reg_rule *reg_rule;
6911 const struct ieee80211_freq_range *freq_range;
6912 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006913 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006914
Johannes Berg458f4f92012-12-06 15:47:38 +01006915 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006916 freq_range = &reg_rule->freq_range;
6917 power_rule = &reg_rule->power_rule;
6918
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006919 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006920 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006921 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006922
Janusz Dziedzic97524822014-01-30 09:52:20 +01006923 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6924 if (!max_bandwidth_khz)
6925 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6926 reg_rule);
6927
David S. Miller9360ffd2012-03-29 04:41:26 -04006928 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6929 reg_rule->flags) ||
6930 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6931 freq_range->start_freq_khz) ||
6932 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6933 freq_range->end_freq_khz) ||
6934 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006935 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006936 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6937 power_rule->max_antenna_gain) ||
6938 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006939 power_rule->max_eirp) ||
6940 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6941 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006942 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006943
6944 nla_nest_end(msg, nl_reg_rule);
6945 }
6946
6947 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006948 return 0;
6949
6950nla_put_failure:
6951 return -EMSGSIZE;
6952}
6953
6954static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6955{
6956 const struct ieee80211_regdomain *regdom = NULL;
6957 struct cfg80211_registered_device *rdev;
6958 struct wiphy *wiphy = NULL;
6959 struct sk_buff *msg;
6960 void *hdr;
6961
6962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6963 if (!msg)
6964 return -ENOBUFS;
6965
6966 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6967 NL80211_CMD_GET_REG);
6968 if (!hdr)
6969 goto put_failure;
6970
6971 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006972 bool self_managed;
6973
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006974 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6975 if (IS_ERR(rdev)) {
6976 nlmsg_free(msg);
6977 return PTR_ERR(rdev);
6978 }
6979
6980 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006981 self_managed = wiphy->regulatory_flags &
6982 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006983 regdom = get_wiphy_regdom(wiphy);
6984
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006985 /* a self-managed-reg device must have a private regdom */
6986 if (WARN_ON(!regdom && self_managed)) {
6987 nlmsg_free(msg);
6988 return -EINVAL;
6989 }
6990
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006991 if (regdom &&
6992 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6993 goto nla_put_failure;
6994 }
6995
6996 if (!wiphy && reg_last_request_cell_base() &&
6997 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6998 NL80211_USER_REG_HINT_CELL_BASE))
6999 goto nla_put_failure;
7000
7001 rcu_read_lock();
7002
7003 if (!regdom)
7004 regdom = rcu_dereference(cfg80211_regdomain);
7005
7006 if (nl80211_put_regdom(regdom, msg))
7007 goto nla_put_failure_rcu;
7008
7009 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007010
7011 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007012 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007013
Johannes Berg458f4f92012-12-06 15:47:38 +01007014nla_put_failure_rcu:
7015 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007016nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007017put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04007018 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007019 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007020}
7021
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007022static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7023 u32 seq, int flags, struct wiphy *wiphy,
7024 const struct ieee80211_regdomain *regdom)
7025{
7026 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7027 NL80211_CMD_GET_REG);
7028
7029 if (!hdr)
7030 return -1;
7031
Michal Kubecek0a833c22017-11-15 13:09:32 +01007032 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007033
7034 if (nl80211_put_regdom(regdom, msg))
7035 goto nla_put_failure;
7036
7037 if (!wiphy && reg_last_request_cell_base() &&
7038 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7039 NL80211_USER_REG_HINT_CELL_BASE))
7040 goto nla_put_failure;
7041
7042 if (wiphy &&
7043 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7044 goto nla_put_failure;
7045
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007046 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7047 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7048 goto nla_put_failure;
7049
Johannes Berg053c0952015-01-16 22:09:00 +01007050 genlmsg_end(msg, hdr);
7051 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007052
7053nla_put_failure:
7054 genlmsg_cancel(msg, hdr);
7055 return -EMSGSIZE;
7056}
7057
7058static int nl80211_get_reg_dump(struct sk_buff *skb,
7059 struct netlink_callback *cb)
7060{
7061 const struct ieee80211_regdomain *regdom = NULL;
7062 struct cfg80211_registered_device *rdev;
7063 int err, reg_idx, start = cb->args[2];
7064
7065 rtnl_lock();
7066
7067 if (cfg80211_regdomain && start == 0) {
7068 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7069 NLM_F_MULTI, NULL,
7070 rtnl_dereference(cfg80211_regdomain));
7071 if (err < 0)
7072 goto out_err;
7073 }
7074
7075 /* the global regdom is idx 0 */
7076 reg_idx = 1;
7077 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7078 regdom = get_wiphy_regdom(&rdev->wiphy);
7079 if (!regdom)
7080 continue;
7081
7082 if (++reg_idx <= start)
7083 continue;
7084
7085 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7086 NLM_F_MULTI, &rdev->wiphy, regdom);
7087 if (err < 0) {
7088 reg_idx--;
7089 break;
7090 }
7091 }
7092
7093 cb->args[2] = reg_idx;
7094 err = skb->len;
7095out_err:
7096 rtnl_unlock();
7097 return err;
7098}
7099
Johannes Bergb6863032015-10-15 09:25:18 +02007100#ifdef CONFIG_CFG80211_CRDA_SUPPORT
7101static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7102 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7103 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7104 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7105 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7106 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7107 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7108 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7109};
7110
7111static int parse_reg_rule(struct nlattr *tb[],
7112 struct ieee80211_reg_rule *reg_rule)
7113{
7114 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
7115 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
7116
7117 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7118 return -EINVAL;
7119 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7120 return -EINVAL;
7121 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7122 return -EINVAL;
7123 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7124 return -EINVAL;
7125 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7126 return -EINVAL;
7127
7128 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7129
7130 freq_range->start_freq_khz =
7131 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7132 freq_range->end_freq_khz =
7133 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7134 freq_range->max_bandwidth_khz =
7135 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7136
7137 power_rule->max_eirp =
7138 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7139
7140 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7141 power_rule->max_antenna_gain =
7142 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7143
7144 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7145 reg_rule->dfs_cac_ms =
7146 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7147
7148 return 0;
7149}
7150
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007151static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7152{
7153 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7154 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007155 char *alpha2;
7156 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007157 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007158 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007159 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007160
7161 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7162 return -EINVAL;
7163
7164 if (!info->attrs[NL80211_ATTR_REG_RULES])
7165 return -EINVAL;
7166
7167 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7168
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007169 if (info->attrs[NL80211_ATTR_DFS_REGION])
7170 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7171
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007172 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007173 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007174 num_rules++;
7175 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007176 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007177 }
7178
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007179 if (!reg_is_valid_request(alpha2))
7180 return -EINVAL;
7181
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007182 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007183 if (!rd)
7184 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007185
7186 rd->n_reg_rules = num_rules;
7187 rd->alpha2[0] = alpha2[0];
7188 rd->alpha2[1] = alpha2[1];
7189
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007190 /*
7191 * Disable DFS master mode if the DFS region was
7192 * not supported or known on this kernel.
7193 */
7194 if (reg_supported_dfs_region(dfs_region))
7195 rd->dfs_region = dfs_region;
7196
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007197 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007198 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007199 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7200 nl_reg_rule, reg_rule_policy,
7201 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007202 if (r)
7203 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007204 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7205 if (r)
7206 goto bad_reg;
7207
7208 rule_idx++;
7209
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007210 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7211 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007212 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007213 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007214 }
7215
Johannes Berg06627992016-06-09 10:40:09 +02007216 /* set_regdom takes ownership of rd */
7217 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007218 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007219 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007220 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007221}
Johannes Bergb6863032015-10-15 09:25:18 +02007222#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007223
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007224static int validate_scan_freqs(struct nlattr *freqs)
7225{
7226 struct nlattr *attr1, *attr2;
7227 int n_channels = 0, tmp1, tmp2;
7228
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007229 nla_for_each_nested(attr1, freqs, tmp1)
7230 if (nla_len(attr1) != sizeof(u32))
7231 return 0;
7232
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007233 nla_for_each_nested(attr1, freqs, tmp1) {
7234 n_channels++;
7235 /*
7236 * Some hardware has a limited channel list for
7237 * scanning, and it is pretty much nonsensical
7238 * to scan for a channel twice, so disallow that
7239 * and don't require drivers to check that the
7240 * channel list they get isn't longer than what
7241 * they can scan, as long as they can scan all
7242 * the channels they registered at once.
7243 */
7244 nla_for_each_nested(attr2, freqs, tmp2)
7245 if (attr1 != attr2 &&
7246 nla_get_u32(attr1) == nla_get_u32(attr2))
7247 return 0;
7248 }
7249
7250 return n_channels;
7251}
7252
Johannes Berg57fbcce2016-04-12 15:56:15 +02007253static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007254{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007255 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007256}
7257
7258static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7259 struct cfg80211_bss_selection *bss_select)
7260{
7261 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7262 struct nlattr *nest;
7263 int err;
7264 bool found = false;
7265 int i;
7266
7267 /* only process one nested attribute */
7268 nest = nla_data(nla);
7269 if (!nla_ok(nest, nla_len(nest)))
7270 return -EINVAL;
7271
Johannes Berg8cb08172019-04-26 14:07:28 +02007272 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7273 nest, nl80211_bss_select_policy,
7274 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007275 if (err)
7276 return err;
7277
7278 /* only one attribute may be given */
7279 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7280 if (attr[i]) {
7281 if (found)
7282 return -EINVAL;
7283 found = true;
7284 }
7285 }
7286
7287 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7288
7289 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7290 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7291
7292 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7293 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7294 bss_select->param.band_pref =
7295 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7296 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7297 return -EINVAL;
7298 }
7299
7300 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7301 struct nl80211_bss_select_rssi_adjust *adj_param;
7302
7303 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7304 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7305 bss_select->param.adjust.band = adj_param->band;
7306 bss_select->param.adjust.delta = adj_param->delta;
7307 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7308 return -EINVAL;
7309 }
7310
7311 /* user-space did not provide behaviour attribute */
7312 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7313 return -EINVAL;
7314
7315 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7316 return -EINVAL;
7317
7318 return 0;
7319}
7320
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007321int nl80211_parse_random_mac(struct nlattr **attrs,
7322 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007323{
7324 int i;
7325
7326 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007327 eth_zero_addr(mac_addr);
7328 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007329 mac_addr[0] = 0x2;
7330 mac_addr_mask[0] = 0x3;
7331
7332 return 0;
7333 }
7334
7335 /* need both or none */
7336 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7337 return -EINVAL;
7338
7339 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7340 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7341
7342 /* don't allow or configure an mcast address */
7343 if (!is_multicast_ether_addr(mac_addr_mask) ||
7344 is_multicast_ether_addr(mac_addr))
7345 return -EINVAL;
7346
7347 /*
7348 * allow users to pass a MAC address that has bits set outside
7349 * of the mask, but don't bother drivers with having to deal
7350 * with such bits
7351 */
7352 for (i = 0; i < ETH_ALEN; i++)
7353 mac_addr[i] &= mac_addr_mask[i];
7354
7355 return 0;
7356}
7357
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307358static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7359{
7360 ASSERT_WDEV_LOCK(wdev);
7361
7362 if (!cfg80211_beaconing_iface_active(wdev))
7363 return true;
7364
7365 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7366 return true;
7367
7368 return regulatory_pre_cac_allowed(wdev->wiphy);
7369}
7370
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007371static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7372 enum nl80211_ext_feature_index feat)
7373{
7374 if (!(flags & flag))
7375 return true;
7376 if (wiphy_ext_feature_isset(wiphy, feat))
7377 return true;
7378 return false;
7379}
7380
Roee Zamir2d23d072017-08-06 11:38:22 +03007381static int
7382nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7383 void *request, struct nlattr **attrs,
7384 bool is_sched_scan)
7385{
7386 u8 *mac_addr, *mac_addr_mask;
7387 u32 *flags;
7388 enum nl80211_feature_flags randomness_flag;
7389
7390 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7391 return 0;
7392
7393 if (is_sched_scan) {
7394 struct cfg80211_sched_scan_request *req = request;
7395
7396 randomness_flag = wdev ?
7397 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7398 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7399 flags = &req->flags;
7400 mac_addr = req->mac_addr;
7401 mac_addr_mask = req->mac_addr_mask;
7402 } else {
7403 struct cfg80211_scan_request *req = request;
7404
7405 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7406 flags = &req->flags;
7407 mac_addr = req->mac_addr;
7408 mac_addr_mask = req->mac_addr_mask;
7409 }
7410
7411 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7412
Sunil Dutt5037a002018-01-25 17:13:37 +02007413 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7414 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007415 !nl80211_check_scan_feat(wiphy, *flags,
7416 NL80211_SCAN_FLAG_LOW_SPAN,
7417 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7418 !nl80211_check_scan_feat(wiphy, *flags,
7419 NL80211_SCAN_FLAG_LOW_POWER,
7420 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7421 !nl80211_check_scan_feat(wiphy, *flags,
7422 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7423 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7424 !nl80211_check_scan_feat(wiphy, *flags,
7425 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7426 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7427 !nl80211_check_scan_feat(wiphy, *flags,
7428 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7429 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7430 !nl80211_check_scan_feat(wiphy, *flags,
7431 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7432 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7433 !nl80211_check_scan_feat(wiphy, *flags,
7434 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007435 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7436 !nl80211_check_scan_feat(wiphy, *flags,
7437 NL80211_SCAN_FLAG_RANDOM_SN,
7438 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7439 !nl80211_check_scan_feat(wiphy, *flags,
7440 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7441 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007442 return -EOPNOTSUPP;
7443
7444 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7445 int err;
7446
7447 if (!(wiphy->features & randomness_flag) ||
7448 (wdev && wdev->current_bss))
7449 return -EOPNOTSUPP;
7450
7451 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7452 if (err)
7453 return err;
7454 }
7455
Roee Zamir2d23d072017-08-06 11:38:22 +03007456 return 0;
7457}
7458
Johannes Berg2a519312009-02-10 21:25:55 +01007459static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7460{
Johannes Berg4c476992010-10-04 21:36:35 +02007461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007462 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007463 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007464 struct nlattr *attr;
7465 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007466 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007467 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007468
Johannes Berg79c97e92009-07-07 03:56:12 +02007469 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007470
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007471 if (wdev->iftype == NL80211_IFTYPE_NAN)
7472 return -EOPNOTSUPP;
7473
Johannes Berg4c476992010-10-04 21:36:35 +02007474 if (!rdev->ops->scan)
7475 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007476
Johannes Bergf9d15d12014-01-22 11:14:19 +02007477 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007478 err = -EBUSY;
7479 goto unlock;
7480 }
Johannes Berg2a519312009-02-10 21:25:55 +01007481
7482 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007483 n_channels = validate_scan_freqs(
7484 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007485 if (!n_channels) {
7486 err = -EINVAL;
7487 goto unlock;
7488 }
Johannes Berg2a519312009-02-10 21:25:55 +01007489 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007490 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007491 }
7492
7493 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7494 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7495 n_ssids++;
7496
Johannes Bergf9f47522013-03-19 15:04:07 +01007497 if (n_ssids > wiphy->max_scan_ssids) {
7498 err = -EINVAL;
7499 goto unlock;
7500 }
Johannes Berg2a519312009-02-10 21:25:55 +01007501
Jouni Malinen70692ad2009-02-16 19:39:13 +02007502 if (info->attrs[NL80211_ATTR_IE])
7503 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7504 else
7505 ie_len = 0;
7506
Johannes Bergf9f47522013-03-19 15:04:07 +01007507 if (ie_len > wiphy->max_scan_ie_len) {
7508 err = -EINVAL;
7509 goto unlock;
7510 }
Johannes Berg18a83652009-03-31 12:12:05 +02007511
Johannes Berg2a519312009-02-10 21:25:55 +01007512 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007513 + sizeof(*request->ssids) * n_ssids
7514 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007515 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007516 if (!request) {
7517 err = -ENOMEM;
7518 goto unlock;
7519 }
Johannes Berg2a519312009-02-10 21:25:55 +01007520
Johannes Berg2a519312009-02-10 21:25:55 +01007521 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007522 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007523 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007524 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007525 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007526 request->ie = (void *)(request->ssids + n_ssids);
7527 else
7528 request->ie = (void *)(request->channels + n_channels);
7529 }
Johannes Berg2a519312009-02-10 21:25:55 +01007530
Johannes Berg584991d2009-11-02 13:32:03 +01007531 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007532 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7533 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007534 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007535 struct ieee80211_channel *chan;
7536
7537 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7538
7539 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007540 err = -EINVAL;
7541 goto out_free;
7542 }
Johannes Berg584991d2009-11-02 13:32:03 +01007543
7544 /* ignore disabled channels */
7545 if (chan->flags & IEEE80211_CHAN_DISABLED)
7546 continue;
7547
7548 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007549 i++;
7550 }
7551 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007552 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007553
Johannes Berg2a519312009-02-10 21:25:55 +01007554 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007555 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007556 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007557
Johannes Berg2a519312009-02-10 21:25:55 +01007558 if (!wiphy->bands[band])
7559 continue;
7560 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007561 struct ieee80211_channel *chan;
7562
7563 chan = &wiphy->bands[band]->channels[j];
7564
7565 if (chan->flags & IEEE80211_CHAN_DISABLED)
7566 continue;
7567
7568 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007569 i++;
7570 }
7571 }
7572 }
7573
Johannes Berg584991d2009-11-02 13:32:03 +01007574 if (!i) {
7575 err = -EINVAL;
7576 goto out_free;
7577 }
7578
7579 request->n_channels = i;
7580
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307581 wdev_lock(wdev);
7582 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7583 struct ieee80211_channel *chan;
7584
7585 if (request->n_channels != 1) {
7586 wdev_unlock(wdev);
7587 err = -EBUSY;
7588 goto out_free;
7589 }
7590
7591 chan = request->channels[0];
7592 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7593 wdev_unlock(wdev);
7594 err = -EBUSY;
7595 goto out_free;
7596 }
7597 }
7598 wdev_unlock(wdev);
7599
Johannes Berg2a519312009-02-10 21:25:55 +01007600 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007601 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007602 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007603 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007604 err = -EINVAL;
7605 goto out_free;
7606 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007607 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007608 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007609 i++;
7610 }
7611 }
7612
Jouni Malinen70692ad2009-02-16 19:39:13 +02007613 if (info->attrs[NL80211_ATTR_IE]) {
7614 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007615 memcpy((void *)request->ie,
7616 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007617 request->ie_len);
7618 }
7619
Johannes Berg57fbcce2016-04-12 15:56:15 +02007620 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007621 if (wiphy->bands[i])
7622 request->rates[i] =
7623 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007624
7625 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7626 nla_for_each_nested(attr,
7627 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7628 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007629 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007630
Johannes Berg57fbcce2016-04-12 15:56:15 +02007631 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007632 err = -EINVAL;
7633 goto out_free;
7634 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007635
7636 if (!wiphy->bands[band])
7637 continue;
7638
Johannes Berg34850ab2011-07-18 18:08:35 +02007639 err = ieee80211_get_ratemask(wiphy->bands[band],
7640 nla_data(attr),
7641 nla_len(attr),
7642 &request->rates[band]);
7643 if (err)
7644 goto out_free;
7645 }
7646 }
7647
Avraham Stern1d762502016-07-05 17:10:13 +03007648 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7649 if (!wiphy_ext_feature_isset(wiphy,
7650 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7651 err = -EOPNOTSUPP;
7652 goto out_free;
7653 }
7654
7655 request->duration =
7656 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7657 request->duration_mandatory =
7658 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7659 }
7660
Roee Zamir2d23d072017-08-06 11:38:22 +03007661 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7662 false);
7663 if (err)
7664 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007665
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307666 request->no_cck =
7667 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7668
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007669 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7670 * BSSID to scan for. This was problematic because that same attribute
7671 * was already used for another purpose (local random MAC address). The
7672 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7673 * compatibility with older userspace components, also use the
7674 * NL80211_ATTR_MAC value here if it can be determined to be used for
7675 * the specific BSSID use case instead of the random MAC address
7676 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7677 */
7678 if (info->attrs[NL80211_ATTR_BSSID])
7679 memcpy(request->bssid,
7680 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7681 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7682 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007683 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7684 ETH_ALEN);
7685 else
7686 eth_broadcast_addr(request->bssid);
7687
Johannes Bergfd014282012-06-18 19:17:03 +02007688 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007689 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007690 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007691
Johannes Berg79c97e92009-07-07 03:56:12 +02007692 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007693 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007694
Johannes Berg463d0182009-07-14 00:33:35 +02007695 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007696 nl80211_send_scan_start(rdev, wdev);
7697 if (wdev->netdev)
7698 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007699 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007700 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007701 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007702 kfree(request);
7703 }
Johannes Berg3b858752009-03-12 09:55:09 +01007704
Johannes Bergf9f47522013-03-19 15:04:07 +01007705 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007706 return err;
7707}
7708
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307709static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7710{
7711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7712 struct wireless_dev *wdev = info->user_ptr[1];
7713
7714 if (!rdev->ops->abort_scan)
7715 return -EOPNOTSUPP;
7716
7717 if (rdev->scan_msg)
7718 return 0;
7719
7720 if (!rdev->scan_req)
7721 return -ENOENT;
7722
7723 rdev_abort_scan(rdev, wdev);
7724 return 0;
7725}
7726
Avraham Stern3b06d272015-10-12 09:51:34 +03007727static int
7728nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7729 struct cfg80211_sched_scan_request *request,
7730 struct nlattr **attrs)
7731{
7732 int tmp, err, i = 0;
7733 struct nlattr *attr;
7734
7735 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7736 u32 interval;
7737
7738 /*
7739 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007740 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007741 * case one scan plan will be set with the specified scan
7742 * interval and infinite number of iterations.
7743 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007744 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7745 if (!interval)
7746 return -EINVAL;
7747
7748 request->scan_plans[0].interval =
7749 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7750 if (!request->scan_plans[0].interval)
7751 return -EINVAL;
7752
7753 if (request->scan_plans[0].interval >
7754 wiphy->max_sched_scan_plan_interval)
7755 request->scan_plans[0].interval =
7756 wiphy->max_sched_scan_plan_interval;
7757
7758 return 0;
7759 }
7760
7761 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7762 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7763
7764 if (WARN_ON(i >= n_plans))
7765 return -EINVAL;
7766
Johannes Berg8cb08172019-04-26 14:07:28 +02007767 err = nla_parse_nested_deprecated(plan,
7768 NL80211_SCHED_SCAN_PLAN_MAX,
7769 attr, nl80211_plan_policy,
7770 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007771 if (err)
7772 return err;
7773
7774 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7775 return -EINVAL;
7776
7777 request->scan_plans[i].interval =
7778 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7779 if (!request->scan_plans[i].interval ||
7780 request->scan_plans[i].interval >
7781 wiphy->max_sched_scan_plan_interval)
7782 return -EINVAL;
7783
7784 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7785 request->scan_plans[i].iterations =
7786 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7787 if (!request->scan_plans[i].iterations ||
7788 (request->scan_plans[i].iterations >
7789 wiphy->max_sched_scan_plan_iterations))
7790 return -EINVAL;
7791 } else if (i < n_plans - 1) {
7792 /*
7793 * All scan plans but the last one must specify
7794 * a finite number of iterations
7795 */
7796 return -EINVAL;
7797 }
7798
7799 i++;
7800 }
7801
7802 /*
7803 * The last scan plan must not specify the number of
7804 * iterations, it is supposed to run infinitely
7805 */
7806 if (request->scan_plans[n_plans - 1].iterations)
7807 return -EINVAL;
7808
7809 return 0;
7810}
7811
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307812static int
7813nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7814 struct cfg80211_match_set *match_sets,
7815 struct nlattr *tb_band_rssi,
7816 s32 rssi_thold)
7817{
7818 struct nlattr *attr;
7819 int i, tmp, ret = 0;
7820
7821 if (!wiphy_ext_feature_isset(wiphy,
7822 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7823 if (tb_band_rssi)
7824 ret = -EOPNOTSUPP;
7825 else
7826 for (i = 0; i < NUM_NL80211_BANDS; i++)
7827 match_sets->per_band_rssi_thold[i] =
7828 NL80211_SCAN_RSSI_THOLD_OFF;
7829 return ret;
7830 }
7831
7832 for (i = 0; i < NUM_NL80211_BANDS; i++)
7833 match_sets->per_band_rssi_thold[i] = rssi_thold;
7834
7835 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7836 enum nl80211_band band = nla_type(attr);
7837
7838 if (band < 0 || band >= NUM_NL80211_BANDS)
7839 return -EINVAL;
7840
7841 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7842 }
7843
7844 return 0;
7845}
7846
Luciano Coelho256da022014-11-10 16:13:46 +02007847static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007848nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007849 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007850{
7851 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007852 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007853 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007854 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007855 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007856 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007857 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007858
Luciano Coelho256da022014-11-10 16:13:46 +02007859 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007860 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007861 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007862 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007863 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007864 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007865 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007866 }
7867
Luciano Coelho256da022014-11-10 16:13:46 +02007868 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7869 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007870 tmp)
7871 n_ssids++;
7872
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007873 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007874 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007875
Johannes Bergea73cbc2014-01-24 10:53:53 +01007876 /*
7877 * First, count the number of 'real' matchsets. Due to an issue with
7878 * the old implementation, matchsets containing only the RSSI attribute
7879 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7880 * RSSI for all matchsets, rather than their own matchset for reporting
7881 * all APs with a strong RSSI. This is needed to be compatible with
7882 * older userspace that treated a matchset with only the RSSI as the
7883 * global RSSI for all other matchsets - if there are other matchsets.
7884 */
Luciano Coelho256da022014-11-10 16:13:46 +02007885 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007886 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007887 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007888 tmp) {
7889 struct nlattr *rssi;
7890
Johannes Berg8cb08172019-04-26 14:07:28 +02007891 err = nla_parse_nested_deprecated(tb,
7892 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7893 attr,
7894 nl80211_match_policy,
7895 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007896 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007897 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007898
7899 /* SSID and BSSID are mutually exclusive */
7900 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7901 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7902 return ERR_PTR(-EINVAL);
7903
Johannes Bergea73cbc2014-01-24 10:53:53 +01007904 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007905 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7906 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007907 n_match_sets++;
7908 continue;
7909 }
7910 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7911 if (rssi)
7912 default_match_rssi = nla_get_s32(rssi);
7913 }
7914 }
7915
7916 /* However, if there's no other matchset, add the RSSI one */
7917 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7918 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007919
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007920 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007921 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007922
Luciano Coelho256da022014-11-10 16:13:46 +02007923 if (attrs[NL80211_ATTR_IE])
7924 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007925 else
7926 ie_len = 0;
7927
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007928 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007929 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007930
Avraham Stern3b06d272015-10-12 09:51:34 +03007931 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7932 /*
7933 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7934 * each scan plan already specifies its own interval
7935 */
7936 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7937 return ERR_PTR(-EINVAL);
7938
7939 nla_for_each_nested(attr,
7940 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7941 n_plans++;
7942 } else {
7943 /*
7944 * The scan interval attribute is kept for backward
7945 * compatibility. If no scan plans are specified and sched scan
7946 * interval is specified, one scan plan will be set with this
7947 * scan interval and infinite number of iterations.
7948 */
7949 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7950 return ERR_PTR(-EINVAL);
7951
7952 n_plans = 1;
7953 }
7954
7955 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7956 return ERR_PTR(-EINVAL);
7957
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007958 if (!wiphy_ext_feature_isset(
7959 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7960 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7961 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7962 return ERR_PTR(-EINVAL);
7963
Luciano Coelho807f8a82011-05-11 17:09:35 +03007964 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007965 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007966 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007967 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007968 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007969 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007970 if (!request)
7971 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007972
7973 if (n_ssids)
7974 request->ssids = (void *)&request->channels[n_channels];
7975 request->n_ssids = n_ssids;
7976 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007977 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007978 request->ie = (void *)(request->ssids + n_ssids);
7979 else
7980 request->ie = (void *)(request->channels + n_channels);
7981 }
7982
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007983 if (n_match_sets) {
7984 if (request->ie)
7985 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007986 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007987 request->match_sets =
7988 (void *)(request->ssids + n_ssids);
7989 else
7990 request->match_sets =
7991 (void *)(request->channels + n_channels);
7992 }
7993 request->n_match_sets = n_match_sets;
7994
Avraham Stern3b06d272015-10-12 09:51:34 +03007995 if (n_match_sets)
7996 request->scan_plans = (void *)(request->match_sets +
7997 n_match_sets);
7998 else if (request->ie)
7999 request->scan_plans = (void *)(request->ie + ie_len);
8000 else if (n_ssids)
8001 request->scan_plans = (void *)(request->ssids + n_ssids);
8002 else
8003 request->scan_plans = (void *)(request->channels + n_channels);
8004
8005 request->n_scan_plans = n_plans;
8006
Luciano Coelho807f8a82011-05-11 17:09:35 +03008007 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008008 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008009 /* user specified, bail out if channel not found */
8010 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008011 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008012 tmp) {
8013 struct ieee80211_channel *chan;
8014
8015 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8016
8017 if (!chan) {
8018 err = -EINVAL;
8019 goto out_free;
8020 }
8021
8022 /* ignore disabled channels */
8023 if (chan->flags & IEEE80211_CHAN_DISABLED)
8024 continue;
8025
8026 request->channels[i] = chan;
8027 i++;
8028 }
8029 } else {
8030 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008031 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008032 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008033
Luciano Coelho807f8a82011-05-11 17:09:35 +03008034 if (!wiphy->bands[band])
8035 continue;
8036 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8037 struct ieee80211_channel *chan;
8038
8039 chan = &wiphy->bands[band]->channels[j];
8040
8041 if (chan->flags & IEEE80211_CHAN_DISABLED)
8042 continue;
8043
8044 request->channels[i] = chan;
8045 i++;
8046 }
8047 }
8048 }
8049
8050 if (!i) {
8051 err = -EINVAL;
8052 goto out_free;
8053 }
8054
8055 request->n_channels = i;
8056
8057 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008058 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02008059 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008060 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008061 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008062 err = -EINVAL;
8063 goto out_free;
8064 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008065 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008066 memcpy(request->ssids[i].ssid, nla_data(attr),
8067 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03008068 i++;
8069 }
8070 }
8071
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008072 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008073 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008074 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008075 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008076 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01008077 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008078
Johannes Berg8cb08172019-04-26 14:07:28 +02008079 err = nla_parse_nested_deprecated(tb,
8080 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8081 attr,
8082 nl80211_match_policy,
8083 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01008084 if (err)
8085 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02008086 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01008087 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02008088
8089 if (!ssid && !bssid) {
8090 i++;
8091 continue;
8092 }
8093
8094 if (WARN_ON(i >= n_match_sets)) {
8095 /* this indicates a programming error,
8096 * the loop above should have verified
8097 * things properly
8098 */
8099 err = -EINVAL;
8100 goto out_free;
8101 }
8102
8103 if (ssid) {
8104 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008105 err = -EINVAL;
8106 goto out_free;
8107 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008108 memcpy(request->match_sets[i].ssid.ssid,
8109 nla_data(ssid), nla_len(ssid));
8110 request->match_sets[i].ssid.ssid_len =
8111 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008112 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008113 if (bssid) {
8114 if (nla_len(bssid) != ETH_ALEN) {
8115 err = -EINVAL;
8116 goto out_free;
8117 }
8118 memcpy(request->match_sets[i].bssid,
8119 nla_data(bssid), ETH_ALEN);
8120 }
8121
8122 /* special attribute - old implementation w/a */
8123 request->match_sets[i].rssi_thold = default_match_rssi;
8124 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8125 if (rssi)
8126 request->match_sets[i].rssi_thold =
8127 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308128
8129 /* Parse per band RSSI attribute */
8130 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8131 &request->match_sets[i],
8132 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8133 request->match_sets[i].rssi_thold);
8134 if (err)
8135 goto out_free;
8136
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008137 i++;
8138 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008139
8140 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008141 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008142 request->match_sets[0].rssi_thold = default_match_rssi;
8143
8144 request->min_rssi_thold = INT_MAX;
8145 for (i = 0; i < n_match_sets; i++)
8146 request->min_rssi_thold =
8147 min(request->match_sets[i].rssi_thold,
8148 request->min_rssi_thold);
8149 } else {
8150 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008151 }
8152
Johannes Berg9900e482014-02-04 21:01:25 +01008153 if (ie_len) {
8154 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008155 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008156 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008157 request->ie_len);
8158 }
8159
Roee Zamir2d23d072017-08-06 11:38:22 +03008160 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8161 if (err)
8162 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008163
Luciano Coelho9c748932015-01-16 16:04:09 +02008164 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8165 request->delay =
8166 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8167
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008168 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8169 request->relative_rssi = nla_get_s8(
8170 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8171 request->relative_rssi_set = true;
8172 }
8173
8174 if (request->relative_rssi_set &&
8175 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8176 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8177
8178 rssi_adjust = nla_data(
8179 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8180 request->rssi_adjust.band = rssi_adjust->band;
8181 request->rssi_adjust.delta = rssi_adjust->delta;
8182 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8183 err = -EINVAL;
8184 goto out_free;
8185 }
8186 }
8187
Avraham Stern3b06d272015-10-12 09:51:34 +03008188 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8189 if (err)
8190 goto out_free;
8191
Sam Leffler15d60302012-10-11 21:03:34 -07008192 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008193
Luciano Coelho256da022014-11-10 16:13:46 +02008194 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008195
8196out_free:
8197 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008198 return ERR_PTR(err);
8199}
8200
8201static int nl80211_start_sched_scan(struct sk_buff *skb,
8202 struct genl_info *info)
8203{
8204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8205 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008206 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008207 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008208 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008209 int err;
8210
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008211 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008212 return -EOPNOTSUPP;
8213
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008214 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8215 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8216 if (err)
8217 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008218
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008219 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008220 info->attrs,
8221 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008222
8223 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008224 if (err)
8225 goto out_err;
8226
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008227 /* leave request id zero for legacy request
8228 * or if driver does not support multi-scheduled scan
8229 */
8230 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
8231 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02008232 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008233 }
8234
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008235 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008236 if (err)
8237 goto out_free;
8238
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008239 sched_scan_req->dev = dev;
8240 sched_scan_req->wiphy = &rdev->wiphy;
8241
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008242 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8243 sched_scan_req->owner_nlportid = info->snd_portid;
8244
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008245 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008246
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008247 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008248 return 0;
8249
8250out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008251 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008252out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008253 return err;
8254}
8255
8256static int nl80211_stop_sched_scan(struct sk_buff *skb,
8257 struct genl_info *info)
8258{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008259 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008261 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008262
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008263 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008264 return -EOPNOTSUPP;
8265
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008266 if (info->attrs[NL80211_ATTR_COOKIE]) {
8267 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8268 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8269 }
8270
8271 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8272 struct cfg80211_sched_scan_request,
8273 list);
8274 if (!req || req->reqid ||
8275 (req->owner_nlportid &&
8276 req->owner_nlportid != info->snd_portid))
8277 return -ENOENT;
8278
8279 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008280}
8281
Simon Wunderlich04f39042013-02-08 18:16:19 +01008282static int nl80211_start_radar_detection(struct sk_buff *skb,
8283 struct genl_info *info)
8284{
8285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8286 struct net_device *dev = info->user_ptr[1];
8287 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008288 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008289 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008290 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008291 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008292 int err;
8293
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008294 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008295 if (dfs_region == NL80211_DFS_UNSET)
8296 return -EINVAL;
8297
Simon Wunderlich04f39042013-02-08 18:16:19 +01008298 err = nl80211_parse_chandef(rdev, info, &chandef);
8299 if (err)
8300 return err;
8301
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008302 if (netif_carrier_ok(dev))
8303 return -EBUSY;
8304
Simon Wunderlich04f39042013-02-08 18:16:19 +01008305 if (wdev->cac_started)
8306 return -EBUSY;
8307
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008308 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008309 if (err < 0)
8310 return err;
8311
8312 if (err == 0)
8313 return -EINVAL;
8314
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008315 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008316 return -EINVAL;
8317
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008318 /* CAC start is offloaded to HW and can't be started manually */
8319 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8320 return -EOPNOTSUPP;
8321
Simon Wunderlich04f39042013-02-08 18:16:19 +01008322 if (!rdev->ops->start_radar_detection)
8323 return -EOPNOTSUPP;
8324
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008325 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8326 if (WARN_ON(!cac_time_ms))
8327 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8328
Ilan Peera1056b1b2015-10-22 22:27:46 +03008329 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008330 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008331 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008332 wdev->cac_started = true;
8333 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008334 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008335 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008336 return err;
8337}
8338
Sriram R30c63112018-12-04 17:46:52 +05308339static int nl80211_notify_radar_detection(struct sk_buff *skb,
8340 struct genl_info *info)
8341{
8342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8343 struct net_device *dev = info->user_ptr[1];
8344 struct wireless_dev *wdev = dev->ieee80211_ptr;
8345 struct wiphy *wiphy = wdev->wiphy;
8346 struct cfg80211_chan_def chandef;
8347 enum nl80211_dfs_regions dfs_region;
8348 int err;
8349
8350 dfs_region = reg_get_dfs_region(wiphy);
8351 if (dfs_region == NL80211_DFS_UNSET) {
8352 GENL_SET_ERR_MSG(info,
8353 "DFS Region is not set. Unexpected Radar indication");
8354 return -EINVAL;
8355 }
8356
8357 err = nl80211_parse_chandef(rdev, info, &chandef);
8358 if (err) {
8359 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8360 return err;
8361 }
8362
8363 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8364 if (err < 0) {
8365 GENL_SET_ERR_MSG(info, "chandef is invalid");
8366 return err;
8367 }
8368
8369 if (err == 0) {
8370 GENL_SET_ERR_MSG(info,
8371 "Unexpected Radar indication for chandef/iftype");
8372 return -EINVAL;
8373 }
8374
8375 /* Do not process this notification if radar is already detected
8376 * by kernel on this channel, and return success.
8377 */
8378 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8379 return 0;
8380
8381 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8382
8383 cfg80211_sched_dfs_chan_update(rdev);
8384
Luca Coelhoa680fe42019-04-17 09:34:40 +03008385 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308386
8387 /* Propagate this notification to other radios as well */
8388 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8389
8390 return 0;
8391}
8392
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008393static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8394{
8395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8396 struct net_device *dev = info->user_ptr[1];
8397 struct wireless_dev *wdev = dev->ieee80211_ptr;
8398 struct cfg80211_csa_settings params;
8399 /* csa_attrs is defined static to avoid waste of stack size - this
8400 * function is called under RTNL lock, so this should not be a problem.
8401 */
8402 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008403 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008404 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008405 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008406 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008407 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008408
8409 if (!rdev->ops->channel_switch ||
8410 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8411 return -EOPNOTSUPP;
8412
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008413 switch (dev->ieee80211_ptr->iftype) {
8414 case NL80211_IFTYPE_AP:
8415 case NL80211_IFTYPE_P2P_GO:
8416 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008417 /* For all modes except AP the handle_dfs flag needs to be
8418 * supplied to tell the kernel that userspace will handle radar
8419 * events when they happen. Otherwise a switch to a channel
8420 * requiring DFS will be rejected.
8421 */
8422 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008423
8424 /* useless if AP is not running */
8425 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008426 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008427 break;
8428 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008429 if (!wdev->ssid_len)
8430 return -ENOTCONN;
8431 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008432 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008433 if (!wdev->mesh_id_len)
8434 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008435 break;
8436 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008437 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008438 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008439
8440 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008441 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008442
8443 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8444 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8445 return -EINVAL;
8446
8447 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008448 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008449 return -EINVAL;
8450
Luciano Coelho252e07c2014-10-08 09:48:34 +03008451 /* Even though the attribute is u32, the specification says
8452 * u8, so let's make sure we don't overflow.
8453 */
8454 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8455 if (cs_count > 255)
8456 return -EINVAL;
8457
8458 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008459
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008460 if (!need_new_beacon)
8461 goto skip_beacons;
8462
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008463 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008464 if (err)
8465 return err;
8466
Johannes Berg8cb08172019-04-26 14:07:28 +02008467 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8468 info->attrs[NL80211_ATTR_CSA_IES],
8469 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008470 if (err)
8471 return err;
8472
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008473 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008474 if (err)
8475 return err;
8476
8477 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8478 return -EINVAL;
8479
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008480 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8481 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008482 return -EINVAL;
8483
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008484 params.n_counter_offsets_beacon = len / sizeof(u16);
8485 if (rdev->wiphy.max_num_csa_counters &&
8486 (params.n_counter_offsets_beacon >
8487 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008488 return -EINVAL;
8489
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008490 params.counter_offsets_beacon =
8491 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8492
8493 /* sanity checks - counters should fit and be the same */
8494 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8495 u16 offset = params.counter_offsets_beacon[i];
8496
8497 if (offset >= params.beacon_csa.tail_len)
8498 return -EINVAL;
8499
8500 if (params.beacon_csa.tail[offset] != params.count)
8501 return -EINVAL;
8502 }
8503
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008504 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008505 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8506 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008507 return -EINVAL;
8508
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008509 params.n_counter_offsets_presp = len / sizeof(u16);
8510 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008511 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008512 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008513 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008514
8515 params.counter_offsets_presp =
8516 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8517
8518 /* sanity checks - counters should fit and be the same */
8519 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8520 u16 offset = params.counter_offsets_presp[i];
8521
8522 if (offset >= params.beacon_csa.probe_resp_len)
8523 return -EINVAL;
8524
8525 if (params.beacon_csa.probe_resp[offset] !=
8526 params.count)
8527 return -EINVAL;
8528 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008529 }
8530
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008531skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008532 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8533 if (err)
8534 return err;
8535
Arik Nemtsov923b3522015-07-08 15:41:44 +03008536 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8537 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008538 return -EINVAL;
8539
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008540 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8541 &params.chandef,
8542 wdev->iftype);
8543 if (err < 0)
8544 return err;
8545
Benjamin Berg8d9de162017-05-16 11:23:12 +02008546 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008547 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008548 if (need_handle_dfs_flag &&
8549 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8550 return -EINVAL;
8551 }
8552 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008553
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008554 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8555 params.block_tx = true;
8556
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008557 wdev_lock(wdev);
8558 err = rdev_channel_switch(rdev, dev, &params);
8559 wdev_unlock(wdev);
8560
8561 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008562}
8563
Johannes Berg9720bb32011-06-21 09:45:33 +02008564static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8565 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008566 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008567 struct wireless_dev *wdev,
8568 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008569{
Johannes Berg48ab9052009-07-10 18:42:31 +02008570 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008571 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008572 void *hdr;
8573 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008574
8575 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008576
Eric W. Biederman15e47302012-09-07 20:12:54 +00008577 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008578 NL80211_CMD_NEW_SCAN_RESULTS);
8579 if (!hdr)
8580 return -1;
8581
Michal Kubecek0a833c22017-11-15 13:09:32 +01008582 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008583
Johannes Berg97990a02013-04-19 01:02:55 +02008584 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8585 goto nla_put_failure;
8586 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008587 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8588 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008589 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8590 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008591 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008592
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008593 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01008594 if (!bss)
8595 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008596 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008597 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008598 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008599
8600 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008601 /* indicate whether we have probe response data or not */
8602 if (rcu_access_pointer(res->proberesp_ies) &&
8603 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8604 goto fail_unlock_rcu;
8605
8606 /* this pointer prefers to be pointed to probe response data
8607 * but is always valid
8608 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008609 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008610 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008611 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8612 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008613 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008614 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8615 ies->len, ies->data))
8616 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008617 }
Johannes Berg0e227082014-08-12 20:34:30 +02008618
8619 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008620 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008621 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008622 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8623 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008624 goto fail_unlock_rcu;
8625 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8626 ies->len, ies->data))
8627 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008628 }
8629 rcu_read_unlock();
8630
David S. Miller9360ffd2012-03-29 04:41:26 -04008631 if (res->beacon_interval &&
8632 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8633 goto nla_put_failure;
8634 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8635 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008636 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008637 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8638 jiffies_to_msecs(jiffies - intbss->ts)))
8639 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008640
Avraham Stern1d762502016-07-05 17:10:13 +03008641 if (intbss->parent_tsf &&
8642 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8643 intbss->parent_tsf, NL80211_BSS_PAD) ||
8644 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8645 intbss->parent_bssid)))
8646 goto nla_put_failure;
8647
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008648 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008649 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8650 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008651 goto nla_put_failure;
8652
Sunil Dutt983dafa2017-12-13 19:51:36 +02008653 if (!nl80211_put_signal(msg, intbss->pub.chains,
8654 intbss->pub.chain_signal,
8655 NL80211_BSS_CHAIN_SIGNAL))
8656 goto nla_put_failure;
8657
Johannes Berg77965c972009-02-18 18:45:06 +01008658 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008659 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008660 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8661 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008662 break;
8663 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008664 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8665 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008666 break;
8667 default:
8668 break;
8669 }
8670
Johannes Berg48ab9052009-07-10 18:42:31 +02008671 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008672 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008673 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008674 if (intbss == wdev->current_bss &&
8675 nla_put_u32(msg, NL80211_BSS_STATUS,
8676 NL80211_BSS_STATUS_ASSOCIATED))
8677 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008678 break;
8679 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008680 if (intbss == wdev->current_bss &&
8681 nla_put_u32(msg, NL80211_BSS_STATUS,
8682 NL80211_BSS_STATUS_IBSS_JOINED))
8683 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008684 break;
8685 default:
8686 break;
8687 }
8688
Johannes Berg2a519312009-02-10 21:25:55 +01008689 nla_nest_end(msg, bss);
8690
Johannes Berg053c0952015-01-16 22:09:00 +01008691 genlmsg_end(msg, hdr);
8692 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008693
Johannes Berg8cef2c92013-02-05 16:54:31 +01008694 fail_unlock_rcu:
8695 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008696 nla_put_failure:
8697 genlmsg_cancel(msg, hdr);
8698 return -EMSGSIZE;
8699}
8700
Johannes Berg97990a02013-04-19 01:02:55 +02008701static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008702{
Johannes Berg48ab9052009-07-10 18:42:31 +02008703 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008704 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008705 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008706 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008707 int err;
8708
Johannes Bergea90e0d2017-03-15 14:26:04 +01008709 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008710 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008711 if (err) {
8712 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008713 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008714 }
Johannes Berg2a519312009-02-10 21:25:55 +01008715
Johannes Berg48ab9052009-07-10 18:42:31 +02008716 wdev_lock(wdev);
8717 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008718
8719 /*
8720 * dump_scan will be called multiple times to break up the scan results
8721 * into multiple messages. It is unlikely that any more bss-es will be
8722 * expired after the first call, so only call only call this on the
8723 * first dump_scan invocation.
8724 */
8725 if (start == 0)
8726 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008727
Johannes Berg9720bb32011-06-21 09:45:33 +02008728 cb->seq = rdev->bss_generation;
8729
Johannes Berg48ab9052009-07-10 18:42:31 +02008730 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008731 if (++idx <= start)
8732 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008733 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008734 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008735 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008736 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008737 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008738 }
8739 }
8740
Johannes Berg48ab9052009-07-10 18:42:31 +02008741 spin_unlock_bh(&rdev->bss_lock);
8742 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008743
Johannes Berg97990a02013-04-19 01:02:55 +02008744 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008745 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008746
Johannes Berg67748892010-10-04 21:14:06 +02008747 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008748}
8749
Eric W. Biederman15e47302012-09-07 20:12:54 +00008750static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008751 int flags, struct net_device *dev,
8752 bool allow_radio_stats,
8753 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008754{
8755 void *hdr;
8756 struct nlattr *infoattr;
8757
Johannes Berg11f78ac2014-11-14 16:43:50 +01008758 /* skip radio stats if userspace didn't request them */
8759 if (!survey->channel && !allow_radio_stats)
8760 return 0;
8761
Eric W. Biederman15e47302012-09-07 20:12:54 +00008762 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008763 NL80211_CMD_NEW_SURVEY_RESULTS);
8764 if (!hdr)
8765 return -ENOMEM;
8766
David S. Miller9360ffd2012-03-29 04:41:26 -04008767 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8768 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008769
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008770 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01008771 if (!infoattr)
8772 goto nla_put_failure;
8773
Johannes Berg11f78ac2014-11-14 16:43:50 +01008774 if (survey->channel &&
8775 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008776 survey->channel->center_freq))
8777 goto nla_put_failure;
8778
8779 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8780 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8781 goto nla_put_failure;
8782 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8783 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8784 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008785 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008786 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8787 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008788 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008789 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008790 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8791 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008792 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008793 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008794 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8795 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008796 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008797 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008798 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8799 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008800 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008801 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008802 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8803 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008804 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008805 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008806 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8807 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008808 goto nla_put_failure;
Felix Fietkauc8cd6e72019-08-28 12:20:42 +02008809 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
8810 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
8811 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
8812 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008813
8814 nla_nest_end(msg, infoattr);
8815
Johannes Berg053c0952015-01-16 22:09:00 +01008816 genlmsg_end(msg, hdr);
8817 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008818
8819 nla_put_failure:
8820 genlmsg_cancel(msg, hdr);
8821 return -EMSGSIZE;
8822}
8823
Johannes Berg11f78ac2014-11-14 16:43:50 +01008824static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008825{
Johannes Berg50508d92019-07-29 16:31:09 +02008826 struct nlattr **attrbuf;
Holger Schurig61fa7132009-11-11 12:25:40 +01008827 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008828 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008829 struct wireless_dev *wdev;
8830 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008831 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008832 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008833
Johannes Berg50508d92019-07-29 16:31:09 +02008834 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
8835 if (!attrbuf)
8836 return -ENOMEM;
8837
Johannes Bergea90e0d2017-03-15 14:26:04 +01008838 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008839 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008840 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008841 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008842
Johannes Berg11f78ac2014-11-14 16:43:50 +01008843 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008844 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008845
Johannes Berg97990a02013-04-19 01:02:55 +02008846 if (!wdev->netdev) {
8847 res = -EINVAL;
8848 goto out_err;
8849 }
8850
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008851 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008852 res = -EOPNOTSUPP;
8853 goto out_err;
8854 }
8855
8856 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008857 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008858 if (res == -ENOENT)
8859 break;
8860 if (res)
8861 goto out_err;
8862
Johannes Berg11f78ac2014-11-14 16:43:50 +01008863 /* don't send disabled channels, but do send non-channel data */
8864 if (survey.channel &&
8865 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008866 survey_idx++;
8867 continue;
8868 }
8869
Holger Schurig61fa7132009-11-11 12:25:40 +01008870 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008871 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008872 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008873 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008874 goto out;
8875 survey_idx++;
8876 }
8877
8878 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008879 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008880 res = skb->len;
8881 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02008882 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008883 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008884 return res;
8885}
8886
Samuel Ortizb23aa672009-07-01 21:26:54 +02008887static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8888{
8889 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00008890 NL80211_WPA_VERSION_2 |
8891 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02008892}
8893
Jouni Malinen636a5d32009-03-19 13:39:22 +02008894static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8895{
Johannes Berg4c476992010-10-04 21:36:35 +02008896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8897 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008898 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008899 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8900 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008901 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008902 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008903 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008904
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008905 if (!info->attrs[NL80211_ATTR_MAC])
8906 return -EINVAL;
8907
Jouni Malinen17780922009-03-27 20:52:47 +02008908 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8909 return -EINVAL;
8910
Johannes Berg19957bb2009-07-02 17:20:43 +02008911 if (!info->attrs[NL80211_ATTR_SSID])
8912 return -EINVAL;
8913
8914 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8915 return -EINVAL;
8916
Johannes Bergfffd0932009-07-08 14:22:54 +02008917 err = nl80211_parse_key(info, &key);
8918 if (err)
8919 return err;
8920
8921 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008922 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8923 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008924 if (!key.p.key || !key.p.key_len)
8925 return -EINVAL;
8926 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8927 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8928 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8929 key.p.key_len != WLAN_KEY_LEN_WEP104))
8930 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008931 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008932 return -EINVAL;
8933 } else {
8934 key.p.key_len = 0;
8935 key.p.key = NULL;
8936 }
8937
Johannes Bergafea0b72010-08-10 09:46:42 +02008938 if (key.idx >= 0) {
8939 int i;
8940 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008941
Johannes Bergafea0b72010-08-10 09:46:42 +02008942 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8943 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8944 ok = true;
8945 break;
8946 }
8947 }
Johannes Berg4c476992010-10-04 21:36:35 +02008948 if (!ok)
8949 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008950 }
8951
Johannes Berg4c476992010-10-04 21:36:35 +02008952 if (!rdev->ops->auth)
8953 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008954
Johannes Berg074ac8d2010-09-16 14:58:22 +02008955 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008956 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8957 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008958
Johannes Berg19957bb2009-07-02 17:20:43 +02008959 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008960 chan = nl80211_get_valid_chan(&rdev->wiphy,
8961 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8962 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008963 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008964
Johannes Berg19957bb2009-07-02 17:20:43 +02008965 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8966 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8967
8968 if (info->attrs[NL80211_ATTR_IE]) {
8969 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8970 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8971 }
8972
8973 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008974 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008975 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008976
Jouni Malinen63181062016-10-27 00:42:02 +03008977 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8978 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8979 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8980 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008981 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008982 return -EINVAL;
8983
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008984 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008985 if (auth_type != NL80211_AUTHTYPE_SAE &&
8986 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8987 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8988 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008989 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008990 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8991 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008992 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008993 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008994 return -EINVAL;
8995 }
8996
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008997 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8998
Johannes Berg95de8172012-01-20 13:55:25 +01008999 /*
9000 * Since we no longer track auth state, ignore
9001 * requests to only change local state.
9002 */
9003 if (local_state_change)
9004 return 0;
9005
Johannes Berg91bf9b22013-05-15 17:44:01 +02009006 wdev_lock(dev->ieee80211_ptr);
9007 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9008 ssid, ssid_len, ie, ie_len,
9009 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009010 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009011 wdev_unlock(dev->ieee80211_ptr);
9012 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009013}
9014
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009015static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9016 struct genl_info *info)
9017{
9018 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9019 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9020 return -EINVAL;
9021 }
9022
9023 if (!rdev->ops->tx_control_port ||
9024 !wiphy_ext_feature_isset(&rdev->wiphy,
9025 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9026 return -EOPNOTSUPP;
9027
9028 return 0;
9029}
9030
Johannes Bergc0692b82010-08-27 14:26:53 +03009031static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9032 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009033 struct cfg80211_crypto_settings *settings,
9034 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009035{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02009036 memset(settings, 0, sizeof(*settings));
9037
Samuel Ortizb23aa672009-07-01 21:26:54 +02009038 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9039
Johannes Bergc0692b82010-08-27 14:26:53 +03009040 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9041 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009042
Johannes Bergc0692b82010-08-27 14:26:53 +03009043 proto = nla_get_u16(
9044 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9045 settings->control_port_ethertype = cpu_to_be16(proto);
9046 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9047 proto != ETH_P_PAE)
9048 return -EINVAL;
9049 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9050 settings->control_port_no_encrypt = true;
9051 } else
9052 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9053
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009054 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9055 int r = validate_pae_over_nl80211(rdev, info);
9056
9057 if (r < 0)
9058 return r;
9059
9060 settings->control_port_over_nl80211 = true;
9061 }
9062
Samuel Ortizb23aa672009-07-01 21:26:54 +02009063 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9064 void *data;
9065 int len, i;
9066
9067 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9068 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9069 settings->n_ciphers_pairwise = len / sizeof(u32);
9070
9071 if (len % sizeof(u32))
9072 return -EINVAL;
9073
Johannes Berg3dc27d22009-07-02 21:36:37 +02009074 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009075 return -EINVAL;
9076
9077 memcpy(settings->ciphers_pairwise, data, len);
9078
9079 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009080 if (!cfg80211_supported_cipher_suite(
9081 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009082 settings->ciphers_pairwise[i]))
9083 return -EINVAL;
9084 }
9085
9086 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9087 settings->cipher_group =
9088 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009089 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9090 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009091 return -EINVAL;
9092 }
9093
9094 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9095 settings->wpa_versions =
9096 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9097 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9098 return -EINVAL;
9099 }
9100
9101 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9102 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03009103 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009104
9105 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9106 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9107 settings->n_akm_suites = len / sizeof(u32);
9108
9109 if (len % sizeof(u32))
9110 return -EINVAL;
9111
Jouni Malinen1b9ca022011-09-21 16:13:07 +03009112 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9113 return -EINVAL;
9114
Samuel Ortizb23aa672009-07-01 21:26:54 +02009115 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009116 }
9117
Eliad Peller91b5ab62017-06-09 13:08:42 +01009118 if (info->attrs[NL80211_ATTR_PMK]) {
9119 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9120 return -EINVAL;
9121 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9122 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
9123 return -EINVAL;
9124 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9125 }
9126
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009127 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9128 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9129 NL80211_EXT_FEATURE_SAE_OFFLOAD))
9130 return -EINVAL;
9131 settings->sae_pwd =
9132 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9133 settings->sae_pwd_len =
9134 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9135 }
9136
Samuel Ortizb23aa672009-07-01 21:26:54 +02009137 return 0;
9138}
9139
Jouni Malinen636a5d32009-03-19 13:39:22 +02009140static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9141{
Johannes Berg4c476992010-10-04 21:36:35 +02009142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9143 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009144 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009145 struct cfg80211_assoc_request req = {};
9146 const u8 *bssid, *ssid;
9147 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009148
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009149 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9150 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9151 return -EPERM;
9152
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009153 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009154 !info->attrs[NL80211_ATTR_SSID] ||
9155 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009156 return -EINVAL;
9157
Johannes Berg4c476992010-10-04 21:36:35 +02009158 if (!rdev->ops->assoc)
9159 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009160
Johannes Berg074ac8d2010-09-16 14:58:22 +02009161 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009162 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9163 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009164
Johannes Berg19957bb2009-07-02 17:20:43 +02009165 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009166
Jouni Malinen664834d2014-01-15 00:01:44 +02009167 chan = nl80211_get_valid_chan(&rdev->wiphy,
9168 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9169 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009170 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009171
Johannes Berg19957bb2009-07-02 17:20:43 +02009172 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9173 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009174
9175 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009176 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9177 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009178 }
9179
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009180 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009181 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009182 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009183 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009184 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009185 else if (mfp != NL80211_MFP_NO)
9186 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009187 }
9188
Johannes Berg3e5d7642009-07-07 14:37:26 +02009189 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009190 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009191
Ben Greear7e7c8922011-11-18 11:31:59 -08009192 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009193 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009194
9195 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009196 memcpy(&req.ht_capa_mask,
9197 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9198 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009199
9200 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009201 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009202 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009203 memcpy(&req.ht_capa,
9204 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9205 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009206 }
9207
Johannes Bergee2aca32013-02-21 17:36:01 +01009208 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009209 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009210
9211 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009212 memcpy(&req.vht_capa_mask,
9213 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9214 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009215
9216 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009217 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009218 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009219 memcpy(&req.vht_capa,
9220 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9221 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009222 }
9223
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009224 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009225 if (!((rdev->wiphy.features &
9226 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9227 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9228 !wiphy_ext_feature_isset(&rdev->wiphy,
9229 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009230 return -EINVAL;
9231 req.flags |= ASSOC_REQ_USE_RRM;
9232 }
9233
Jouni Malinen348bd452016-10-27 00:42:03 +03009234 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9235 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9236 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9237 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9238 return -EINVAL;
9239 req.fils_nonces =
9240 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9241 }
9242
Johannes Bergf62fab72013-02-21 20:09:09 +01009243 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009244 if (!err) {
9245 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009246
Johannes Bergf62fab72013-02-21 20:09:09 +01009247 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9248 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009249
9250 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9251 dev->ieee80211_ptr->conn_owner_nlportid =
9252 info->snd_portid;
9253 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9254 bssid, ETH_ALEN);
9255 }
9256
Johannes Berg91bf9b22013-05-15 17:44:01 +02009257 wdev_unlock(dev->ieee80211_ptr);
9258 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009259
Jouni Malinen636a5d32009-03-19 13:39:22 +02009260 return err;
9261}
9262
9263static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9264{
Johannes Berg4c476992010-10-04 21:36:35 +02009265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9266 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009267 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009268 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009269 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009270 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009271
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009272 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9273 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9274 return -EPERM;
9275
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009276 if (!info->attrs[NL80211_ATTR_MAC])
9277 return -EINVAL;
9278
9279 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9280 return -EINVAL;
9281
Johannes Berg4c476992010-10-04 21:36:35 +02009282 if (!rdev->ops->deauth)
9283 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009284
Johannes Berg074ac8d2010-09-16 14:58:22 +02009285 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009286 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9287 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009288
Johannes Berg19957bb2009-07-02 17:20:43 +02009289 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009290
Johannes Berg19957bb2009-07-02 17:20:43 +02009291 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9292 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009293 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009294 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009295 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009296
9297 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009298 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9299 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009300 }
9301
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009302 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9303
Johannes Berg91bf9b22013-05-15 17:44:01 +02009304 wdev_lock(dev->ieee80211_ptr);
9305 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9306 local_state_change);
9307 wdev_unlock(dev->ieee80211_ptr);
9308 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009309}
9310
9311static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9312{
Johannes Berg4c476992010-10-04 21:36:35 +02009313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9314 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009315 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009316 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009317 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009318 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009319
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009320 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9321 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9322 return -EPERM;
9323
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009324 if (!info->attrs[NL80211_ATTR_MAC])
9325 return -EINVAL;
9326
9327 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9328 return -EINVAL;
9329
Johannes Berg4c476992010-10-04 21:36:35 +02009330 if (!rdev->ops->disassoc)
9331 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009332
Johannes Berg074ac8d2010-09-16 14:58:22 +02009333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009334 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9335 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009336
Johannes Berg19957bb2009-07-02 17:20:43 +02009337 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009338
Johannes Berg19957bb2009-07-02 17:20:43 +02009339 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9340 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009341 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009342 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009343 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009344
9345 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009346 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9347 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009348 }
9349
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009350 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9351
Johannes Berg91bf9b22013-05-15 17:44:01 +02009352 wdev_lock(dev->ieee80211_ptr);
9353 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9354 local_state_change);
9355 wdev_unlock(dev->ieee80211_ptr);
9356 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009357}
9358
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009359static bool
9360nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009361 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009362 int rateval)
9363{
9364 struct wiphy *wiphy = &rdev->wiphy;
9365 bool found = false;
9366 int band, i;
9367
Johannes Berg57fbcce2016-04-12 15:56:15 +02009368 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009369 struct ieee80211_supported_band *sband;
9370
9371 sband = wiphy->bands[band];
9372 if (!sband)
9373 continue;
9374
9375 for (i = 0; i < sband->n_bitrates; i++) {
9376 if (sband->bitrates[i].bitrate == rateval) {
9377 mcast_rate[band] = i + 1;
9378 found = true;
9379 break;
9380 }
9381 }
9382 }
9383
9384 return found;
9385}
9386
Johannes Berg04a773a2009-04-19 21:24:32 +02009387static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9388{
Johannes Berg4c476992010-10-04 21:36:35 +02009389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9390 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009391 struct cfg80211_ibss_params ibss;
9392 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009393 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009394 int err;
9395
Johannes Berg8e30bc52009-04-22 17:45:38 +02009396 memset(&ibss, 0, sizeof(ibss));
9397
Johannes Berg683b6d32012-11-08 21:25:48 +01009398 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009399 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9400 return -EINVAL;
9401
Johannes Berg8e30bc52009-04-22 17:45:38 +02009402 ibss.beacon_interval = 100;
9403
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309404 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009405 ibss.beacon_interval =
9406 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309407
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309408 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9409 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309410 if (err)
9411 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009412
Johannes Berg4c476992010-10-04 21:36:35 +02009413 if (!rdev->ops->join_ibss)
9414 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009415
Johannes Berg4c476992010-10-04 21:36:35 +02009416 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9417 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009418
Johannes Berg79c97e92009-07-07 03:56:12 +02009419 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009420
Johannes Berg39193492011-09-16 13:45:25 +02009421 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009422 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009423
9424 if (!is_valid_ether_addr(ibss.bssid))
9425 return -EINVAL;
9426 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009427 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9428 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9429
9430 if (info->attrs[NL80211_ATTR_IE]) {
9431 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9432 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9433 }
9434
Johannes Berg683b6d32012-11-08 21:25:48 +01009435 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9436 if (err)
9437 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009438
Ilan Peer174e0cd2014-02-23 09:13:01 +02009439 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9440 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009441 return -EINVAL;
9442
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009443 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009444 case NL80211_CHAN_WIDTH_5:
9445 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009446 case NL80211_CHAN_WIDTH_20_NOHT:
9447 break;
9448 case NL80211_CHAN_WIDTH_20:
9449 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009450 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9451 return -EINVAL;
9452 break;
9453 case NL80211_CHAN_WIDTH_80:
9454 case NL80211_CHAN_WIDTH_80P80:
9455 case NL80211_CHAN_WIDTH_160:
9456 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9457 return -EINVAL;
9458 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9459 NL80211_EXT_FEATURE_VHT_IBSS))
9460 return -EINVAL;
9461 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009462 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009463 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009464 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009465
Johannes Berg04a773a2009-04-19 21:24:32 +02009466 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009467 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009468
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009469 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9470 u8 *rates =
9471 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9472 int n_rates =
9473 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9474 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009475 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009476
Johannes Berg34850ab2011-07-18 18:08:35 +02009477 err = ieee80211_get_ratemask(sband, rates, n_rates,
9478 &ibss.basic_rates);
9479 if (err)
9480 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009481 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009482
Simon Wunderlich803768f2013-06-28 10:39:58 +02009483 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9484 memcpy(&ibss.ht_capa_mask,
9485 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9486 sizeof(ibss.ht_capa_mask));
9487
9488 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9489 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9490 return -EINVAL;
9491 memcpy(&ibss.ht_capa,
9492 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9493 sizeof(ibss.ht_capa));
9494 }
9495
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009496 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9497 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9498 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9499 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009500
Johannes Berg4c476992010-10-04 21:36:35 +02009501 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309502 bool no_ht = false;
9503
Johannes Berg768075e2017-11-13 15:35:06 +01009504 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009505 if (IS_ERR(connkeys))
9506 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309507
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009508 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9509 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009510 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309511 return -EINVAL;
9512 }
Johannes Berg4c476992010-10-04 21:36:35 +02009513 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009514
Antonio Quartulli267335d2012-01-31 20:25:47 +01009515 ibss.control_port =
9516 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9517
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009518 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9519 int r = validate_pae_over_nl80211(rdev, info);
9520
Johannes Bergd350a0f2018-12-15 11:03:22 +02009521 if (r < 0) {
9522 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009523 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009524 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009525
9526 ibss.control_port_over_nl80211 = true;
9527 }
9528
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009529 ibss.userspace_handles_dfs =
9530 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9531
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009532 wdev_lock(dev->ieee80211_ptr);
9533 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009534 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009535 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009536 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9537 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9538 wdev_unlock(dev->ieee80211_ptr);
9539
Johannes Berg04a773a2009-04-19 21:24:32 +02009540 return err;
9541}
9542
9543static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9544{
Johannes Berg4c476992010-10-04 21:36:35 +02009545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9546 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009547
Johannes Berg4c476992010-10-04 21:36:35 +02009548 if (!rdev->ops->leave_ibss)
9549 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009550
Johannes Berg4c476992010-10-04 21:36:35 +02009551 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9552 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009553
Johannes Berg4c476992010-10-04 21:36:35 +02009554 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009555}
9556
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009557static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9558{
9559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9560 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009561 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009562 u32 nla_rate;
9563 int err;
9564
9565 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009566 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9567 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009568 return -EOPNOTSUPP;
9569
9570 if (!rdev->ops->set_mcast_rate)
9571 return -EOPNOTSUPP;
9572
9573 memset(mcast_rate, 0, sizeof(mcast_rate));
9574
9575 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9576 return -EINVAL;
9577
9578 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9579 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9580 return -EINVAL;
9581
Ilan Peera1056b1b2015-10-22 22:27:46 +03009582 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009583
9584 return err;
9585}
9586
Johannes Bergad7e7182013-11-13 13:37:47 +01009587static struct sk_buff *
9588__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009589 struct wireless_dev *wdev, int approxlen,
9590 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009591 enum nl80211_attrs attr,
9592 const struct nl80211_vendor_cmd_info *info,
9593 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009594{
9595 struct sk_buff *skb;
9596 void *hdr;
9597 struct nlattr *data;
9598
9599 skb = nlmsg_new(approxlen + 100, gfp);
9600 if (!skb)
9601 return NULL;
9602
9603 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9604 if (!hdr) {
9605 kfree_skb(skb);
9606 return NULL;
9607 }
9608
9609 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9610 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009611
9612 if (info) {
9613 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9614 info->vendor_id))
9615 goto nla_put_failure;
9616 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9617 info->subcmd))
9618 goto nla_put_failure;
9619 }
9620
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009621 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009622 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9623 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009624 goto nla_put_failure;
9625 if (wdev->netdev &&
9626 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9627 wdev->netdev->ifindex))
9628 goto nla_put_failure;
9629 }
9630
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009631 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009632 if (!data)
9633 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009634
9635 ((void **)skb->cb)[0] = rdev;
9636 ((void **)skb->cb)[1] = hdr;
9637 ((void **)skb->cb)[2] = data;
9638
9639 return skb;
9640
9641 nla_put_failure:
9642 kfree_skb(skb);
9643 return NULL;
9644}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009645
Johannes Berge03ad6e2014-01-01 17:22:30 +01009646struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009647 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009648 enum nl80211_commands cmd,
9649 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009650 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009651 int vendor_event_idx,
9652 int approxlen, gfp_t gfp)
9653{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009655 const struct nl80211_vendor_cmd_info *info;
9656
9657 switch (cmd) {
9658 case NL80211_CMD_TESTMODE:
9659 if (WARN_ON(vendor_event_idx != -1))
9660 return NULL;
9661 info = NULL;
9662 break;
9663 case NL80211_CMD_VENDOR:
9664 if (WARN_ON(vendor_event_idx < 0 ||
9665 vendor_event_idx >= wiphy->n_vendor_events))
9666 return NULL;
9667 info = &wiphy->vendor_events[vendor_event_idx];
9668 break;
9669 default:
9670 WARN_ON(1);
9671 return NULL;
9672 }
9673
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009674 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009675 cmd, attr, info, gfp);
9676}
9677EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9678
9679void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9680{
9681 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9682 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009683 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009684 struct nlattr *data = ((void **)skb->cb)[2];
9685 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9686
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009687 /* clear CB data for netlink core to own from now on */
9688 memset(skb->cb, 0, sizeof(skb->cb));
9689
Johannes Berge03ad6e2014-01-01 17:22:30 +01009690 nla_nest_end(skb, data);
9691 genlmsg_end(skb, hdr);
9692
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009693 if (nlhdr->nlmsg_pid) {
9694 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9695 nlhdr->nlmsg_pid);
9696 } else {
9697 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9698 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +01009699
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009700 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9701 skb, 0, mcgrp, gfp);
9702 }
Johannes Berge03ad6e2014-01-01 17:22:30 +01009703}
9704EXPORT_SYMBOL(__cfg80211_send_event_skb);
9705
Johannes Bergaff89a92009-07-01 21:26:51 +02009706#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009707static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9708{
Johannes Berg4c476992010-10-04 21:36:35 +02009709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009710 struct wireless_dev *wdev =
9711 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009712 int err;
9713
David Spinadelfc73f112013-07-31 18:04:15 +03009714 if (!rdev->ops->testmode_cmd)
9715 return -EOPNOTSUPP;
9716
9717 if (IS_ERR(wdev)) {
9718 err = PTR_ERR(wdev);
9719 if (err != -EINVAL)
9720 return err;
9721 wdev = NULL;
9722 } else if (wdev->wiphy != &rdev->wiphy) {
9723 return -EINVAL;
9724 }
9725
Johannes Bergaff89a92009-07-01 21:26:51 +02009726 if (!info->attrs[NL80211_ATTR_TESTDATA])
9727 return -EINVAL;
9728
Johannes Bergad7e7182013-11-13 13:37:47 +01009729 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009730 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009731 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9732 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009733 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009734
Johannes Bergaff89a92009-07-01 21:26:51 +02009735 return err;
9736}
9737
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009738static int nl80211_testmode_dump(struct sk_buff *skb,
9739 struct netlink_callback *cb)
9740{
Johannes Berg00918d32011-12-13 17:22:05 +01009741 struct cfg80211_registered_device *rdev;
Johannes Berg50508d92019-07-29 16:31:09 +02009742 struct nlattr **attrbuf = NULL;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009743 int err;
9744 long phy_idx;
9745 void *data = NULL;
9746 int data_len = 0;
9747
Johannes Berg5fe231e2013-05-08 21:45:15 +02009748 rtnl_lock();
9749
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009750 if (cb->args[0]) {
9751 /*
9752 * 0 is a valid index, but not valid for args[0],
9753 * so we need to offset by 1.
9754 */
9755 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009756
9757 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9758 if (!rdev) {
9759 err = -ENOENT;
9760 goto out_err;
9761 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009762 } else {
Johannes Berg50508d92019-07-29 16:31:09 +02009763 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
9764 GFP_KERNEL);
9765 if (!attrbuf) {
9766 err = -ENOMEM;
9767 goto out_err;
9768 }
Johannes Bergc90c39d2016-10-24 14:40:01 +02009769
Johannes Berg8cb08172019-04-26 14:07:28 +02009770 err = nlmsg_parse_deprecated(cb->nlh,
9771 GENL_HDRLEN + nl80211_fam.hdrsize,
9772 attrbuf, nl80211_fam.maxattr,
9773 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009774 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009775 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009776
Johannes Bergc90c39d2016-10-24 14:40:01 +02009777 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009778 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009779 err = PTR_ERR(rdev);
9780 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009781 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009782 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009783
Johannes Bergc90c39d2016-10-24 14:40:01 +02009784 if (attrbuf[NL80211_ATTR_TESTDATA])
9785 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009786 }
9787
9788 if (cb->args[1]) {
9789 data = nla_data((void *)cb->args[1]);
9790 data_len = nla_len((void *)cb->args[1]);
9791 }
9792
Johannes Berg00918d32011-12-13 17:22:05 +01009793 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009794 err = -EOPNOTSUPP;
9795 goto out_err;
9796 }
9797
9798 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009799 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009800 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9801 NL80211_CMD_TESTMODE);
9802 struct nlattr *tmdata;
9803
Dan Carpentercb35fba2013-08-14 14:50:01 +03009804 if (!hdr)
9805 break;
9806
David S. Miller9360ffd2012-03-29 04:41:26 -04009807 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009808 genlmsg_cancel(skb, hdr);
9809 break;
9810 }
9811
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009812 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009813 if (!tmdata) {
9814 genlmsg_cancel(skb, hdr);
9815 break;
9816 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009817 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009818 nla_nest_end(skb, tmdata);
9819
9820 if (err == -ENOBUFS || err == -ENOENT) {
9821 genlmsg_cancel(skb, hdr);
9822 break;
9823 } else if (err) {
9824 genlmsg_cancel(skb, hdr);
9825 goto out_err;
9826 }
9827
9828 genlmsg_end(skb, hdr);
9829 }
9830
9831 err = skb->len;
9832 /* see above */
9833 cb->args[0] = phy_idx + 1;
9834 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02009835 kfree(attrbuf);
Johannes Berg5fe231e2013-05-08 21:45:15 +02009836 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009837 return err;
9838}
Johannes Bergaff89a92009-07-01 21:26:51 +02009839#endif
9840
Samuel Ortizb23aa672009-07-01 21:26:54 +02009841static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9842{
Johannes Berg4c476992010-10-04 21:36:35 +02009843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9844 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009845 struct cfg80211_connect_params connect;
9846 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009847 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009848 int err;
9849
9850 memset(&connect, 0, sizeof(connect));
9851
Samuel Ortizb23aa672009-07-01 21:26:54 +02009852 if (!info->attrs[NL80211_ATTR_SSID] ||
9853 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9854 return -EINVAL;
9855
9856 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9857 connect.auth_type =
9858 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009859 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9860 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009861 return -EINVAL;
9862 } else
9863 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9864
9865 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9866
Avraham Stern3a00df52017-06-09 13:08:43 +01009867 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9868 !wiphy_ext_feature_isset(&rdev->wiphy,
9869 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9870 return -EINVAL;
9871 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9872
Johannes Bergc0692b82010-08-27 14:26:53 +03009873 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009874 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009875 if (err)
9876 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009877
Johannes Berg074ac8d2010-09-16 14:58:22 +02009878 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009879 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9880 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009881
Johannes Berg79c97e92009-07-07 03:56:12 +02009882 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009883
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309884 connect.bg_scan_period = -1;
9885 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9886 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9887 connect.bg_scan_period =
9888 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9889 }
9890
Samuel Ortizb23aa672009-07-01 21:26:54 +02009891 if (info->attrs[NL80211_ATTR_MAC])
9892 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009893 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9894 connect.bssid_hint =
9895 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009896 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9897 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9898
9899 if (info->attrs[NL80211_ATTR_IE]) {
9900 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9901 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9902 }
9903
Jouni Malinencee00a92013-01-15 17:15:57 +02009904 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9905 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009906 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9907 !wiphy_ext_feature_isset(&rdev->wiphy,
9908 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9909 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009910 } else {
9911 connect.mfp = NL80211_MFP_NO;
9912 }
9913
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009914 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9915 connect.prev_bssid =
9916 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9917
Samuel Ortizb23aa672009-07-01 21:26:54 +02009918 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009919 connect.channel = nl80211_get_valid_chan(
9920 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9921 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009922 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009923 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009924 connect.channel_hint = nl80211_get_valid_chan(
9925 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9926 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009927 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009928 }
9929
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03009930 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
9931 connect.edmg.channels =
9932 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
9933
9934 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
9935 connect.edmg.bw_config =
9936 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
9937 }
9938
Johannes Bergfffd0932009-07-08 14:22:54 +02009939 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009940 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009941 if (IS_ERR(connkeys))
9942 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009943 }
9944
Ben Greear7e7c8922011-11-18 11:31:59 -08009945 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9946 connect.flags |= ASSOC_REQ_DISABLE_HT;
9947
9948 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9949 memcpy(&connect.ht_capa_mask,
9950 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9951 sizeof(connect.ht_capa_mask));
9952
9953 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009954 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009955 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009956 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009957 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009958 memcpy(&connect.ht_capa,
9959 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9960 sizeof(connect.ht_capa));
9961 }
9962
Johannes Bergee2aca32013-02-21 17:36:01 +01009963 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9964 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9965
9966 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9967 memcpy(&connect.vht_capa_mask,
9968 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9969 sizeof(connect.vht_capa_mask));
9970
9971 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9972 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009973 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009974 return -EINVAL;
9975 }
9976 memcpy(&connect.vht_capa,
9977 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9978 sizeof(connect.vht_capa));
9979 }
9980
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009981 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009982 if (!((rdev->wiphy.features &
9983 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9984 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9985 !wiphy_ext_feature_isset(&rdev->wiphy,
9986 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009987 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009988 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009989 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009990 connect.flags |= ASSOC_REQ_USE_RRM;
9991 }
9992
Lior David34d50512016-01-28 10:58:25 +02009993 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009994 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009995 kzfree(connkeys);
9996 return -EOPNOTSUPP;
9997 }
9998
Arend van Spriel38de03d2016-03-02 20:37:18 +01009999 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10000 /* bss selection makes no sense if bssid is set */
10001 if (connect.bssid) {
10002 kzfree(connkeys);
10003 return -EINVAL;
10004 }
10005
10006 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10007 wiphy, &connect.bss_select);
10008 if (err) {
10009 kzfree(connkeys);
10010 return err;
10011 }
10012 }
10013
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010014 if (wiphy_ext_feature_isset(&rdev->wiphy,
10015 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10016 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10017 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10018 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10019 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10020 connect.fils_erp_username =
10021 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10022 connect.fils_erp_username_len =
10023 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10024 connect.fils_erp_realm =
10025 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10026 connect.fils_erp_realm_len =
10027 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10028 connect.fils_erp_next_seq_num =
10029 nla_get_u16(
10030 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10031 connect.fils_erp_rrk =
10032 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10033 connect.fils_erp_rrk_len =
10034 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10035 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10036 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10037 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10038 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10039 kzfree(connkeys);
10040 return -EINVAL;
10041 }
10042
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010043 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10044 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +053010045 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010046 GENL_SET_ERR_MSG(info,
10047 "external auth requires connection ownership");
10048 return -EINVAL;
10049 }
10050 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10051 }
10052
Johannes Berg83739b02013-05-15 17:44:01 +020010053 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010054
Jouni Malinen4ce2bd92016-03-29 13:53:28 +030010055 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10056 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +020010057 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +030010058 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010059
10060 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10061 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10062 if (connect.bssid)
10063 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10064 connect.bssid, ETH_ALEN);
10065 else
10066 memset(dev->ieee80211_ptr->disconnect_bssid,
10067 0, ETH_ALEN);
10068 }
10069
10070 wdev_unlock(dev->ieee80211_ptr);
10071
Samuel Ortizb23aa672009-07-01 21:26:54 +020010072 return err;
10073}
10074
vamsi krishna088e8df2016-10-27 16:51:11 +030010075static int nl80211_update_connect_params(struct sk_buff *skb,
10076 struct genl_info *info)
10077{
10078 struct cfg80211_connect_params connect = {};
10079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10080 struct net_device *dev = info->user_ptr[1];
10081 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010082 bool fils_sk_offload;
10083 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +030010084 u32 changed = 0;
10085 int ret;
10086
10087 if (!rdev->ops->update_connect_params)
10088 return -EOPNOTSUPP;
10089
10090 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +030010091 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10092 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10093 changed |= UPDATE_ASSOC_IES;
10094 }
10095
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010096 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10097 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10098
10099 /*
10100 * when driver supports fils-sk offload all attributes must be
10101 * provided. So the else covers "fils-sk-not-all" and
10102 * "no-fils-sk-any".
10103 */
10104 if (fils_sk_offload &&
10105 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10106 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10107 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10108 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10109 connect.fils_erp_username =
10110 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10111 connect.fils_erp_username_len =
10112 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10113 connect.fils_erp_realm =
10114 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10115 connect.fils_erp_realm_len =
10116 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10117 connect.fils_erp_next_seq_num =
10118 nla_get_u16(
10119 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10120 connect.fils_erp_rrk =
10121 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10122 connect.fils_erp_rrk_len =
10123 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10124 changed |= UPDATE_FILS_ERP_INFO;
10125 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10126 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10127 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10128 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10129 return -EINVAL;
10130 }
10131
10132 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10133 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10134 if (!nl80211_valid_auth_type(rdev, auth_type,
10135 NL80211_CMD_CONNECT))
10136 return -EINVAL;
10137
10138 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10139 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10140 return -EINVAL;
10141
10142 connect.auth_type = auth_type;
10143 changed |= UPDATE_AUTH_TYPE;
10144 }
10145
vamsi krishna088e8df2016-10-27 16:51:11 +030010146 wdev_lock(dev->ieee80211_ptr);
10147 if (!wdev->current_bss)
10148 ret = -ENOLINK;
10149 else
10150 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10151 wdev_unlock(dev->ieee80211_ptr);
10152
10153 return ret;
10154}
10155
Samuel Ortizb23aa672009-07-01 21:26:54 +020010156static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10157{
Johannes Berg4c476992010-10-04 21:36:35 +020010158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10159 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010160 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010161 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010162
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010163 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10164 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10165 return -EPERM;
10166
Samuel Ortizb23aa672009-07-01 21:26:54 +020010167 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10168 reason = WLAN_REASON_DEAUTH_LEAVING;
10169 else
10170 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10171
10172 if (reason == 0)
10173 return -EINVAL;
10174
Johannes Berg074ac8d2010-09-16 14:58:22 +020010175 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010176 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10177 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010178
Johannes Berg83739b02013-05-15 17:44:01 +020010179 wdev_lock(dev->ieee80211_ptr);
10180 ret = cfg80211_disconnect(rdev, dev, reason, true);
10181 wdev_unlock(dev->ieee80211_ptr);
10182 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010183}
10184
Johannes Berg463d0182009-07-14 00:33:35 +020010185static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10186{
Johannes Berg4c476992010-10-04 21:36:35 +020010187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010188 struct net *net;
10189 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010190
Vadim Kochan4b681c82015-01-12 16:34:05 +020010191 if (info->attrs[NL80211_ATTR_PID]) {
10192 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10193
10194 net = get_net_ns_by_pid(pid);
10195 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10196 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10197
10198 net = get_net_ns_by_fd(fd);
10199 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010200 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010201 }
Johannes Berg463d0182009-07-14 00:33:35 +020010202
Johannes Berg4c476992010-10-04 21:36:35 +020010203 if (IS_ERR(net))
10204 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010205
10206 err = 0;
10207
10208 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010209 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10210 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010211
Johannes Berg463d0182009-07-14 00:33:35 +020010212 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010213 return err;
10214}
10215
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010216static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10217{
Johannes Berg4c476992010-10-04 21:36:35 +020010218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010219 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10220 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010221 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010222 struct cfg80211_pmksa pmksa;
10223
10224 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10225
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010226 if (!info->attrs[NL80211_ATTR_PMKID])
10227 return -EINVAL;
10228
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010229 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010230
10231 if (info->attrs[NL80211_ATTR_MAC]) {
10232 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10233 } else if (info->attrs[NL80211_ATTR_SSID] &&
10234 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10235 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10236 info->attrs[NL80211_ATTR_PMK])) {
10237 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10238 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10239 pmksa.cache_id =
10240 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10241 } else {
10242 return -EINVAL;
10243 }
10244 if (info->attrs[NL80211_ATTR_PMK]) {
10245 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10246 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10247 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010248
Johannes Berg074ac8d2010-09-16 14:58:22 +020010249 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010250 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10251 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10252 wiphy_ext_feature_isset(&rdev->wiphy,
10253 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010254 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010255
10256 switch (info->genlhdr->cmd) {
10257 case NL80211_CMD_SET_PMKSA:
10258 rdev_ops = rdev->ops->set_pmksa;
10259 break;
10260 case NL80211_CMD_DEL_PMKSA:
10261 rdev_ops = rdev->ops->del_pmksa;
10262 break;
10263 default:
10264 WARN_ON(1);
10265 break;
10266 }
10267
Johannes Berg4c476992010-10-04 21:36:35 +020010268 if (!rdev_ops)
10269 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010270
Johannes Berg4c476992010-10-04 21:36:35 +020010271 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010272}
10273
10274static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10275{
Johannes Berg4c476992010-10-04 21:36:35 +020010276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10277 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010278
Johannes Berg074ac8d2010-09-16 14:58:22 +020010279 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010280 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10281 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010282
Johannes Berg4c476992010-10-04 21:36:35 +020010283 if (!rdev->ops->flush_pmksa)
10284 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010285
Hila Gonene35e4d22012-06-27 17:19:42 +030010286 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010287}
10288
Arik Nemtsov109086c2011-09-28 14:12:50 +030010289static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10290{
10291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10292 struct net_device *dev = info->user_ptr[1];
10293 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010294 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010295 u16 status_code;
10296 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010297 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010298
10299 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10300 !rdev->ops->tdls_mgmt)
10301 return -EOPNOTSUPP;
10302
10303 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10304 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10305 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10306 !info->attrs[NL80211_ATTR_IE] ||
10307 !info->attrs[NL80211_ATTR_MAC])
10308 return -EINVAL;
10309
10310 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10311 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10312 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10313 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010314 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010315 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10316 peer_capability =
10317 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010318
Hila Gonene35e4d22012-06-27 17:19:42 +030010319 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010320 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010321 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010322 nla_data(info->attrs[NL80211_ATTR_IE]),
10323 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010324}
10325
10326static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10327{
10328 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10329 struct net_device *dev = info->user_ptr[1];
10330 enum nl80211_tdls_operation operation;
10331 u8 *peer;
10332
10333 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10334 !rdev->ops->tdls_oper)
10335 return -EOPNOTSUPP;
10336
10337 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10338 !info->attrs[NL80211_ATTR_MAC])
10339 return -EINVAL;
10340
10341 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10342 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10343
Hila Gonene35e4d22012-06-27 17:19:42 +030010344 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010345}
10346
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010347static int nl80211_remain_on_channel(struct sk_buff *skb,
10348 struct genl_info *info)
10349{
Johannes Berg4c476992010-10-04 21:36:35 +020010350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010351 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010352 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010353 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010354 struct sk_buff *msg;
10355 void *hdr;
10356 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010357 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010358 int err;
10359
10360 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10361 !info->attrs[NL80211_ATTR_DURATION])
10362 return -EINVAL;
10363
10364 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10365
Johannes Berg7c4ef712011-11-18 15:33:48 +010010366 if (!rdev->ops->remain_on_channel ||
10367 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010368 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010369
Johannes Bergebf348f2012-06-01 12:50:54 +020010370 /*
10371 * We should be on that channel for at least a minimum amount of
10372 * time (10ms) but no longer than the driver supports.
10373 */
10374 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10375 duration > rdev->wiphy.max_remain_on_channel_duration)
10376 return -EINVAL;
10377
Johannes Berg683b6d32012-11-08 21:25:48 +010010378 err = nl80211_parse_chandef(rdev, info, &chandef);
10379 if (err)
10380 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010381
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010382 wdev_lock(wdev);
10383 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10384 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10385 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10386 &chandef);
10387 if (compat_chandef != &chandef) {
10388 wdev_unlock(wdev);
10389 return -EBUSY;
10390 }
10391 }
10392 wdev_unlock(wdev);
10393
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010395 if (!msg)
10396 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010397
Eric W. Biederman15e47302012-09-07 20:12:54 +000010398 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010399 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010400 if (!hdr) {
10401 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010402 goto free_msg;
10403 }
10404
Johannes Berg683b6d32012-11-08 21:25:48 +010010405 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10406 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010407
10408 if (err)
10409 goto free_msg;
10410
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010411 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10412 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010413 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010414
10415 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010416
10417 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010418
10419 nla_put_failure:
10420 err = -ENOBUFS;
10421 free_msg:
10422 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010423 return err;
10424}
10425
10426static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10427 struct genl_info *info)
10428{
Johannes Berg4c476992010-10-04 21:36:35 +020010429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010430 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010431 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010432
10433 if (!info->attrs[NL80211_ATTR_COOKIE])
10434 return -EINVAL;
10435
Johannes Berg4c476992010-10-04 21:36:35 +020010436 if (!rdev->ops->cancel_remain_on_channel)
10437 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010438
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010439 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10440
Hila Gonene35e4d22012-06-27 17:19:42 +030010441 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010442}
10443
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010444static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10445 struct genl_info *info)
10446{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010447 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010449 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010450 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010451
Johannes Berg4c476992010-10-04 21:36:35 +020010452 if (!rdev->ops->set_bitrate_mask)
10453 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010454
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010455 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10456 if (err)
10457 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010458
Hila Gonene35e4d22012-06-27 17:19:42 +030010459 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010460}
10461
Johannes Berg2e161f782010-08-12 15:38:38 +020010462static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010463{
Johannes Berg4c476992010-10-04 21:36:35 +020010464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010465 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010466 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010467
10468 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10469 return -EINVAL;
10470
Johannes Berg2e161f782010-08-12 15:38:38 +020010471 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10472 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010473
Johannes Berg71bbc992012-06-15 15:30:18 +020010474 switch (wdev->iftype) {
10475 case NL80211_IFTYPE_STATION:
10476 case NL80211_IFTYPE_ADHOC:
10477 case NL80211_IFTYPE_P2P_CLIENT:
10478 case NL80211_IFTYPE_AP:
10479 case NL80211_IFTYPE_AP_VLAN:
10480 case NL80211_IFTYPE_MESH_POINT:
10481 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010482 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010483 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010484 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010485 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010486 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010487 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010488
10489 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010490 if (!rdev->ops->mgmt_tx)
10491 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010492
Eric W. Biederman15e47302012-09-07 20:12:54 +000010493 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010494 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10495 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010496}
10497
Johannes Berg2e161f782010-08-12 15:38:38 +020010498static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010499{
Johannes Berg4c476992010-10-04 21:36:35 +020010500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010501 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010502 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010503 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010504 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010505 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010506 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010507 struct cfg80211_mgmt_tx_params params = {
10508 .dont_wait_for_ack =
10509 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10510 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010511
Johannes Berg683b6d32012-11-08 21:25:48 +010010512 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010513 return -EINVAL;
10514
Johannes Berg4c476992010-10-04 21:36:35 +020010515 if (!rdev->ops->mgmt_tx)
10516 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010517
Johannes Berg71bbc992012-06-15 15:30:18 +020010518 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010519 case NL80211_IFTYPE_P2P_DEVICE:
10520 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10521 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010522 case NL80211_IFTYPE_STATION:
10523 case NL80211_IFTYPE_ADHOC:
10524 case NL80211_IFTYPE_P2P_CLIENT:
10525 case NL80211_IFTYPE_AP:
10526 case NL80211_IFTYPE_AP_VLAN:
10527 case NL80211_IFTYPE_MESH_POINT:
10528 case NL80211_IFTYPE_P2P_GO:
10529 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010530 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010531 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010532 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010533 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010534
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010535 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010536 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010537 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010538 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010539
10540 /*
10541 * We should wait on the channel for at least a minimum amount
10542 * of time (10ms) but no longer than the driver supports.
10543 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010544 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10545 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010546 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010547 }
10548
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010549 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010550
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010551 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010552 return -EINVAL;
10553
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010554 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010555
Antonio Quartulliea141b752013-06-11 14:20:03 +020010556 /* get the channel if any has been specified, otherwise pass NULL to
10557 * the driver. The latter will use the current one
10558 */
10559 chandef.chan = NULL;
10560 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10561 err = nl80211_parse_chandef(rdev, info, &chandef);
10562 if (err)
10563 return err;
10564 }
10565
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010566 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010567 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010568
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010569 wdev_lock(wdev);
10570 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10571 wdev_unlock(wdev);
10572 return -EBUSY;
10573 }
10574 wdev_unlock(wdev);
10575
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010576 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10577 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10578
10579 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10580 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10581 int i;
10582
10583 if (len % sizeof(u16))
10584 return -EINVAL;
10585
10586 params.n_csa_offsets = len / sizeof(u16);
10587 params.csa_offsets =
10588 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10589
10590 /* check that all the offsets fit the frame */
10591 for (i = 0; i < params.n_csa_offsets; i++) {
10592 if (params.csa_offsets[i] >= params.len)
10593 return -EINVAL;
10594 }
10595 }
10596
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010597 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10599 if (!msg)
10600 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010601
Eric W. Biederman15e47302012-09-07 20:12:54 +000010602 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010603 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010604 if (!hdr) {
10605 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010606 goto free_msg;
10607 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010608 }
Johannes Berge247bd902011-11-04 11:18:21 +010010609
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010610 params.chan = chandef.chan;
10611 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010612 if (err)
10613 goto free_msg;
10614
Johannes Berge247bd902011-11-04 11:18:21 +010010615 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010616 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10617 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010618 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010619
Johannes Berge247bd902011-11-04 11:18:21 +010010620 genlmsg_end(msg, hdr);
10621 return genlmsg_reply(msg, info);
10622 }
10623
10624 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010625
10626 nla_put_failure:
10627 err = -ENOBUFS;
10628 free_msg:
10629 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010630 return err;
10631}
10632
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010633static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10634{
10635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010636 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010637 u64 cookie;
10638
10639 if (!info->attrs[NL80211_ATTR_COOKIE])
10640 return -EINVAL;
10641
10642 if (!rdev->ops->mgmt_tx_cancel_wait)
10643 return -EOPNOTSUPP;
10644
Johannes Berg71bbc992012-06-15 15:30:18 +020010645 switch (wdev->iftype) {
10646 case NL80211_IFTYPE_STATION:
10647 case NL80211_IFTYPE_ADHOC:
10648 case NL80211_IFTYPE_P2P_CLIENT:
10649 case NL80211_IFTYPE_AP:
10650 case NL80211_IFTYPE_AP_VLAN:
10651 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010652 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010653 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010654 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010655 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010656 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010657 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010658
10659 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10660
Hila Gonene35e4d22012-06-27 17:19:42 +030010661 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010662}
10663
Kalle Valoffb9eb32010-02-17 17:58:10 +020010664static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10665{
Johannes Berg4c476992010-10-04 21:36:35 +020010666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010667 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010668 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010669 u8 ps_state;
10670 bool state;
10671 int err;
10672
Johannes Berg4c476992010-10-04 21:36:35 +020010673 if (!info->attrs[NL80211_ATTR_PS_STATE])
10674 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010675
10676 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10677
Kalle Valoffb9eb32010-02-17 17:58:10 +020010678 wdev = dev->ieee80211_ptr;
10679
Johannes Berg4c476992010-10-04 21:36:35 +020010680 if (!rdev->ops->set_power_mgmt)
10681 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010682
10683 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10684
10685 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010686 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010687
Hila Gonene35e4d22012-06-27 17:19:42 +030010688 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010689 if (!err)
10690 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010691 return err;
10692}
10693
10694static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10695{
Johannes Berg4c476992010-10-04 21:36:35 +020010696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010697 enum nl80211_ps_state ps_state;
10698 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010699 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010700 struct sk_buff *msg;
10701 void *hdr;
10702 int err;
10703
Kalle Valoffb9eb32010-02-17 17:58:10 +020010704 wdev = dev->ieee80211_ptr;
10705
Johannes Berg4c476992010-10-04 21:36:35 +020010706 if (!rdev->ops->set_power_mgmt)
10707 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010708
10709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010710 if (!msg)
10711 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010712
Eric W. Biederman15e47302012-09-07 20:12:54 +000010713 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010714 NL80211_CMD_GET_POWER_SAVE);
10715 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010716 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010717 goto free_msg;
10718 }
10719
10720 if (wdev->ps)
10721 ps_state = NL80211_PS_ENABLED;
10722 else
10723 ps_state = NL80211_PS_DISABLED;
10724
David S. Miller9360ffd2012-03-29 04:41:26 -040010725 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10726 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010727
10728 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010729 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010730
Johannes Berg4c476992010-10-04 21:36:35 +020010731 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010732 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010733 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010734 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010735 return err;
10736}
10737
Johannes Berg94e860f2014-01-20 23:58:15 +010010738static const struct nla_policy
10739nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010740 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010741 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10742 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010743 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10744 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10745 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010746 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010747};
10748
Thomas Pedersen84f10702012-07-12 16:17:33 -070010749static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010750 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010751{
10752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010753 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010754 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010755
Johannes Bergd9d8b012012-11-26 12:51:52 +010010756 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010757 return -EINVAL;
10758
Thomas Pedersen84f10702012-07-12 16:17:33 -070010759 if (!rdev->ops->set_cqm_txe_config)
10760 return -EOPNOTSUPP;
10761
10762 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10763 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10764 return -EOPNOTSUPP;
10765
Hila Gonene35e4d22012-06-27 17:19:42 +030010766 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010767}
10768
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010769static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10770 struct net_device *dev)
10771{
10772 struct wireless_dev *wdev = dev->ieee80211_ptr;
10773 s32 last, low, high;
10774 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010775 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010776 int err;
10777
10778 /* RSSI reporting disabled? */
10779 if (!wdev->cqm_config)
10780 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10781
10782 /*
10783 * Obtain current RSSI value if possible, if not and no RSSI threshold
10784 * event has been received yet, we should receive an event after a
10785 * connection is established and enough beacons received to calculate
10786 * the average.
10787 */
10788 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10789 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010790 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010791 u8 *mac_addr;
10792
10793 mac_addr = wdev->current_bss->pub.bssid;
10794
Johannes Berg73887fd2018-05-18 09:57:55 +020010795 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10796 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010797 return err;
10798
Omer Efrat397c6572018-06-17 13:06:14 +030010799 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010800 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010801 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010802 }
10803
10804 last = wdev->cqm_config->last_rssi_event_value;
10805 hyst = wdev->cqm_config->rssi_hyst;
10806 n = wdev->cqm_config->n_rssi_thresholds;
10807
Masashi Honma4b2c5a12019-09-08 09:56:53 +090010808 for (i = 0; i < n; i++) {
10809 i = array_index_nospec(i, n);
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010810 if (last < wdev->cqm_config->rssi_thresholds[i])
10811 break;
Masashi Honma4b2c5a12019-09-08 09:56:53 +090010812 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010813
Masashi Honma1222a162018-09-25 11:15:01 +090010814 low_index = i - 1;
10815 if (low_index >= 0) {
10816 low_index = array_index_nospec(low_index, n);
10817 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10818 } else {
10819 low = S32_MIN;
10820 }
10821 if (i < n) {
10822 i = array_index_nospec(i, n);
10823 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10824 } else {
10825 high = S32_MAX;
10826 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010827
10828 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10829}
10830
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010831static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010832 const s32 *thresholds, int n_thresholds,
10833 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010834{
Johannes Berg4c476992010-10-04 21:36:35 +020010835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010836 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010837 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010838 int i, err;
10839 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010840
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010841 /* Check all values negative and sorted */
10842 for (i = 0; i < n_thresholds; i++) {
10843 if (thresholds[i] > 0 || thresholds[i] <= prev)
10844 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010845
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010846 prev = thresholds[i];
10847 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010848
Johannes Berg074ac8d2010-09-16 14:58:22 +020010849 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010850 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10851 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010852
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010853 wdev_lock(wdev);
10854 cfg80211_cqm_config_free(wdev);
10855 wdev_unlock(wdev);
10856
10857 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10858 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10859 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10860
10861 return rdev_set_cqm_rssi_config(rdev, dev,
10862 thresholds[0], hysteresis);
10863 }
10864
10865 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10866 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10867 return -EOPNOTSUPP;
10868
10869 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10870 n_thresholds = 0;
10871
10872 wdev_lock(wdev);
10873 if (n_thresholds) {
10874 struct cfg80211_cqm_config *cqm_config;
10875
10876 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10877 n_thresholds * sizeof(s32), GFP_KERNEL);
10878 if (!cqm_config) {
10879 err = -ENOMEM;
10880 goto unlock;
10881 }
10882
10883 cqm_config->rssi_hyst = hysteresis;
10884 cqm_config->n_rssi_thresholds = n_thresholds;
10885 memcpy(cqm_config->rssi_thresholds, thresholds,
10886 n_thresholds * sizeof(s32));
10887
10888 wdev->cqm_config = cqm_config;
10889 }
10890
10891 err = cfg80211_cqm_rssi_update(rdev, dev);
10892
10893unlock:
10894 wdev_unlock(wdev);
10895
10896 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010897}
10898
10899static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10900{
10901 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10902 struct nlattr *cqm;
10903 int err;
10904
10905 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010906 if (!cqm)
10907 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010908
Johannes Berg8cb08172019-04-26 14:07:28 +020010909 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10910 nl80211_attr_cqm_policy,
10911 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010912 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010913 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010914
10915 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10916 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010917 const s32 *thresholds =
10918 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10919 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010920 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010921
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010922 if (len % 4)
10923 return -EINVAL;
10924
10925 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10926 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010927 }
10928
10929 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10930 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10931 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10932 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10933 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10934 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10935
10936 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10937 }
10938
10939 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010940}
10941
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010942static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10943{
10944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10945 struct net_device *dev = info->user_ptr[1];
10946 struct ocb_setup setup = {};
10947 int err;
10948
10949 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10950 if (err)
10951 return err;
10952
10953 return cfg80211_join_ocb(rdev, dev, &setup);
10954}
10955
10956static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10957{
10958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10959 struct net_device *dev = info->user_ptr[1];
10960
10961 return cfg80211_leave_ocb(rdev, dev);
10962}
10963
Johannes Berg29cbe682010-12-03 09:20:44 +010010964static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10965{
10966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10967 struct net_device *dev = info->user_ptr[1];
10968 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010969 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010970 int err;
10971
10972 /* start with default */
10973 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010974 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010975
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010976 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010977 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010978 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010979 if (err)
10980 return err;
10981 }
10982
10983 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10984 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10985 return -EINVAL;
10986
Javier Cardonac80d5452010-12-16 17:37:49 -080010987 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10988 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10989
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010990 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10991 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10992 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10993 return -EINVAL;
10994
Marco Porsch9bdbf042013-01-07 16:04:51 +010010995 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10996 setup.beacon_interval =
10997 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010998
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010999 err = cfg80211_validate_beacon_int(rdev,
11000 NL80211_IFTYPE_MESH_POINT,
11001 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011002 if (err)
11003 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010011004 }
11005
11006 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11007 setup.dtim_period =
11008 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11009 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11010 return -EINVAL;
11011 }
11012
Javier Cardonac80d5452010-12-16 17:37:49 -080011013 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11014 /* parse additional setup parameters if given */
11015 err = nl80211_parse_mesh_setup(info, &setup);
11016 if (err)
11017 return err;
11018 }
11019
Thomas Pedersend37bb182013-03-04 13:06:13 -080011020 if (setup.user_mpm)
11021 cfg.auto_open_plinks = false;
11022
Johannes Bergcc1d2802012-05-16 23:50:20 +020011023 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010011024 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11025 if (err)
11026 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011027 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050011028 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010011029 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011030 }
11031
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070011032 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11033 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11034 int n_rates =
11035 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11036 struct ieee80211_supported_band *sband;
11037
11038 if (!setup.chandef.chan)
11039 return -EINVAL;
11040
11041 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11042
11043 err = ieee80211_get_ratemask(sband, rates, n_rates,
11044 &setup.basic_rates);
11045 if (err)
11046 return err;
11047 }
11048
Johannes Berg8564e382016-09-19 09:44:44 +020011049 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11050 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
11051 if (err)
11052 return err;
11053
Johannes Berg265698d2017-09-18 22:46:36 +020011054 if (!setup.chandef.chan)
11055 return -EINVAL;
11056
Johannes Berg8564e382016-09-19 09:44:44 +020011057 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11058 &setup.beacon_rate);
11059 if (err)
11060 return err;
11061 }
11062
Benjamin Bergd37d49c2017-05-16 11:23:11 +020011063 setup.userspace_handles_dfs =
11064 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11065
Denis Kenzior1224f582018-03-26 12:52:49 -050011066 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11067 int r = validate_pae_over_nl80211(rdev, info);
11068
11069 if (r < 0)
11070 return r;
11071
11072 setup.control_port_over_nl80211 = true;
11073 }
11074
Denis Kenzior188c1b32018-03-26 12:52:46 -050011075 wdev_lock(dev->ieee80211_ptr);
11076 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11077 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11078 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11079 wdev_unlock(dev->ieee80211_ptr);
11080
11081 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010011082}
11083
11084static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11085{
11086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11087 struct net_device *dev = info->user_ptr[1];
11088
11089 return cfg80211_leave_mesh(rdev, dev);
11090}
11091
Johannes Bergdfb89c52012-06-27 09:23:48 +020011092#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011093static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11094 struct cfg80211_registered_device *rdev)
11095{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011096 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011097 struct nlattr *nl_pats, *nl_pat;
11098 int i, pat_len;
11099
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011100 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011101 return 0;
11102
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011103 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011104 if (!nl_pats)
11105 return -ENOBUFS;
11106
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011107 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011108 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011109 if (!nl_pat)
11110 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011111 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011112 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011113 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011114 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11115 wowlan->patterns[i].pattern) ||
11116 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011117 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011118 return -ENOBUFS;
11119 nla_nest_end(msg, nl_pat);
11120 }
11121 nla_nest_end(msg, nl_pats);
11122
11123 return 0;
11124}
11125
Johannes Berg2a0e0472013-01-23 22:57:40 +010011126static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11127 struct cfg80211_wowlan_tcp *tcp)
11128{
11129 struct nlattr *nl_tcp;
11130
11131 if (!tcp)
11132 return 0;
11133
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011134 nl_tcp = nla_nest_start_noflag(msg,
11135 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011136 if (!nl_tcp)
11137 return -ENOBUFS;
11138
Jiri Benc930345e2015-03-29 16:59:25 +020011139 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11140 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010011141 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11142 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11143 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11144 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11145 tcp->payload_len, tcp->payload) ||
11146 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11147 tcp->data_interval) ||
11148 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11149 tcp->wake_len, tcp->wake_data) ||
11150 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11151 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11152 return -ENOBUFS;
11153
11154 if (tcp->payload_seq.len &&
11155 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11156 sizeof(tcp->payload_seq), &tcp->payload_seq))
11157 return -ENOBUFS;
11158
11159 if (tcp->payload_tok.len &&
11160 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11161 sizeof(tcp->payload_tok) + tcp->tokens_size,
11162 &tcp->payload_tok))
11163 return -ENOBUFS;
11164
Johannes Berge248ad32013-05-16 10:24:28 +020011165 nla_nest_end(msg, nl_tcp);
11166
Johannes Berg2a0e0472013-01-23 22:57:40 +010011167 return 0;
11168}
11169
Luciano Coelho75453cc2015-01-09 14:06:37 +020011170static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11171 struct cfg80211_sched_scan_request *req)
11172{
Avraham Stern3b06d272015-10-12 09:51:34 +030011173 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011174 int i;
11175
11176 if (!req)
11177 return 0;
11178
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011179 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011180 if (!nd)
11181 return -ENOBUFS;
11182
Avraham Stern3b06d272015-10-12 09:51:34 +030011183 if (req->n_scan_plans == 1 &&
11184 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11185 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011186 return -ENOBUFS;
11187
Luciano Coelho21fea562015-03-17 16:36:01 +020011188 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11189 return -ENOBUFS;
11190
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011191 if (req->relative_rssi_set) {
11192 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11193
11194 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11195 req->relative_rssi))
11196 return -ENOBUFS;
11197
11198 rssi_adjust.band = req->rssi_adjust.band;
11199 rssi_adjust.delta = req->rssi_adjust.delta;
11200 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11201 sizeof(rssi_adjust), &rssi_adjust))
11202 return -ENOBUFS;
11203 }
11204
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011205 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011206 if (!freqs)
11207 return -ENOBUFS;
11208
Johannes Berg53b18982016-09-14 09:59:21 +020011209 for (i = 0; i < req->n_channels; i++) {
11210 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11211 return -ENOBUFS;
11212 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011213
11214 nla_nest_end(msg, freqs);
11215
11216 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011217 matches = nla_nest_start_noflag(msg,
11218 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011219 if (!matches)
11220 return -ENOBUFS;
11221
Luciano Coelho75453cc2015-01-09 14:06:37 +020011222 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011223 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011224 if (!match)
11225 return -ENOBUFS;
11226
Johannes Berg53b18982016-09-14 09:59:21 +020011227 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11228 req->match_sets[i].ssid.ssid_len,
11229 req->match_sets[i].ssid.ssid))
11230 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011231 nla_nest_end(msg, match);
11232 }
11233 nla_nest_end(msg, matches);
11234 }
11235
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011236 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011237 if (!scan_plans)
11238 return -ENOBUFS;
11239
11240 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011241 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011242 if (!scan_plan)
11243 return -ENOBUFS;
11244
Colin Ian King67626962018-09-06 10:58:44 +010011245 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011246 req->scan_plans[i].interval) ||
11247 (req->scan_plans[i].iterations &&
11248 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11249 req->scan_plans[i].iterations)))
11250 return -ENOBUFS;
11251 nla_nest_end(msg, scan_plan);
11252 }
11253 nla_nest_end(msg, scan_plans);
11254
Luciano Coelho75453cc2015-01-09 14:06:37 +020011255 nla_nest_end(msg, nd);
11256
11257 return 0;
11258}
11259
Johannes Bergff1b6e62011-05-04 15:37:28 +020011260static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11261{
11262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11263 struct sk_buff *msg;
11264 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011265 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011266
Johannes Berg964dc9e2013-06-03 17:25:34 +020011267 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011268 return -EOPNOTSUPP;
11269
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011270 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011271 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011272 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11273 rdev->wiphy.wowlan_config->tcp->payload_len +
11274 rdev->wiphy.wowlan_config->tcp->wake_len +
11275 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011276 }
11277
11278 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011279 if (!msg)
11280 return -ENOMEM;
11281
Eric W. Biederman15e47302012-09-07 20:12:54 +000011282 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011283 NL80211_CMD_GET_WOWLAN);
11284 if (!hdr)
11285 goto nla_put_failure;
11286
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011287 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011288 struct nlattr *nl_wowlan;
11289
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011290 nl_wowlan = nla_nest_start_noflag(msg,
11291 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011292 if (!nl_wowlan)
11293 goto nla_put_failure;
11294
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011295 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011296 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011297 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011298 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011299 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011301 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011302 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011303 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011304 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011305 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011307 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11309 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011310
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011311 if (nl80211_send_wowlan_patterns(msg, rdev))
11312 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011313
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011314 if (nl80211_send_wowlan_tcp(msg,
11315 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011316 goto nla_put_failure;
11317
Luciano Coelho75453cc2015-01-09 14:06:37 +020011318 if (nl80211_send_wowlan_nd(
11319 msg,
11320 rdev->wiphy.wowlan_config->nd_config))
11321 goto nla_put_failure;
11322
Johannes Bergff1b6e62011-05-04 15:37:28 +020011323 nla_nest_end(msg, nl_wowlan);
11324 }
11325
11326 genlmsg_end(msg, hdr);
11327 return genlmsg_reply(msg, info);
11328
11329nla_put_failure:
11330 nlmsg_free(msg);
11331 return -ENOBUFS;
11332}
11333
Johannes Berg2a0e0472013-01-23 22:57:40 +010011334static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11335 struct nlattr *attr,
11336 struct cfg80211_wowlan *trig)
11337{
11338 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11339 struct cfg80211_wowlan_tcp *cfg;
11340 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11341 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11342 u32 size;
11343 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11344 int err, port;
11345
Johannes Berg964dc9e2013-06-03 17:25:34 +020011346 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011347 return -EINVAL;
11348
Johannes Berg8cb08172019-04-26 14:07:28 +020011349 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11350 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011351 if (err)
11352 return err;
11353
11354 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11355 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11356 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11357 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11358 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11359 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11360 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11361 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11362 return -EINVAL;
11363
11364 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011365 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011366 return -EINVAL;
11367
11368 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011369 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011370 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011371 return -EINVAL;
11372
11373 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011374 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011375 return -EINVAL;
11376
11377 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11378 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11379 return -EINVAL;
11380
11381 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11382 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11383
11384 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11385 tokens_size = tokln - sizeof(*tok);
11386
11387 if (!tok->len || tokens_size % tok->len)
11388 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011389 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011390 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011391 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011392 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011393 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011394 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011395 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011396 return -EINVAL;
11397 if (tok->offset + tok->len > data_size)
11398 return -EINVAL;
11399 }
11400
11401 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11402 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011403 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011404 return -EINVAL;
11405 if (seq->len == 0 || seq->len > 4)
11406 return -EINVAL;
11407 if (seq->len + seq->offset > data_size)
11408 return -EINVAL;
11409 }
11410
11411 size = sizeof(*cfg);
11412 size += data_size;
11413 size += wake_size + wake_mask_size;
11414 size += tokens_size;
11415
11416 cfg = kzalloc(size, GFP_KERNEL);
11417 if (!cfg)
11418 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011419 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11420 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011421 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11422 ETH_ALEN);
11423 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11424 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11425 else
11426 port = 0;
11427#ifdef CONFIG_INET
11428 /* allocate a socket and port for it and use it */
11429 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11430 IPPROTO_TCP, &cfg->sock, 1);
11431 if (err) {
11432 kfree(cfg);
11433 return err;
11434 }
11435 if (inet_csk_get_port(cfg->sock->sk, port)) {
11436 sock_release(cfg->sock);
11437 kfree(cfg);
11438 return -EADDRINUSE;
11439 }
11440 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11441#else
11442 if (!port) {
11443 kfree(cfg);
11444 return -EINVAL;
11445 }
11446 cfg->src_port = port;
11447#endif
11448
11449 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11450 cfg->payload_len = data_size;
11451 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11452 memcpy((void *)cfg->payload,
11453 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11454 data_size);
11455 if (seq)
11456 cfg->payload_seq = *seq;
11457 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11458 cfg->wake_len = wake_size;
11459 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11460 memcpy((void *)cfg->wake_data,
11461 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11462 wake_size);
11463 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11464 data_size + wake_size;
11465 memcpy((void *)cfg->wake_mask,
11466 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11467 wake_mask_size);
11468 if (tok) {
11469 cfg->tokens_size = tokens_size;
11470 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11471 }
11472
11473 trig->tcp = cfg;
11474
11475 return 0;
11476}
11477
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011478static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11479 const struct wiphy_wowlan_support *wowlan,
11480 struct nlattr *attr,
11481 struct cfg80211_wowlan *trig)
11482{
11483 struct nlattr **tb;
11484 int err;
11485
Kees Cook6396bb22018-06-12 14:03:40 -070011486 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011487 if (!tb)
11488 return -ENOMEM;
11489
11490 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11491 err = -EOPNOTSUPP;
11492 goto out;
11493 }
11494
Johannes Berg8cb08172019-04-26 14:07:28 +020011495 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11496 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011497 if (err)
11498 goto out;
11499
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011500 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11501 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011502 err = PTR_ERR_OR_ZERO(trig->nd_config);
11503 if (err)
11504 trig->nd_config = NULL;
11505
11506out:
11507 kfree(tb);
11508 return err;
11509}
11510
Johannes Bergff1b6e62011-05-04 15:37:28 +020011511static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11512{
11513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11514 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011515 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011516 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011517 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011518 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011519 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011520 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011521
Johannes Berg964dc9e2013-06-03 17:25:34 +020011522 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011523 return -EOPNOTSUPP;
11524
Johannes Bergae33bd82012-07-12 16:25:02 +020011525 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11526 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011527 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011528 goto set_wakeup;
11529 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011530
Johannes Berg8cb08172019-04-26 14:07:28 +020011531 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11532 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11533 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011534 if (err)
11535 return err;
11536
11537 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11538 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11539 return -EINVAL;
11540 new_triggers.any = true;
11541 }
11542
11543 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11544 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11545 return -EINVAL;
11546 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011547 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011548 }
11549
11550 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11551 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11552 return -EINVAL;
11553 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011554 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011555 }
11556
Johannes Berg77dbbb12011-07-13 10:48:55 +020011557 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11558 return -EINVAL;
11559
11560 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11561 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11562 return -EINVAL;
11563 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011564 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011565 }
11566
11567 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11568 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11569 return -EINVAL;
11570 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011571 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011572 }
11573
11574 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11575 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11576 return -EINVAL;
11577 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011578 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011579 }
11580
11581 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11582 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11583 return -EINVAL;
11584 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011585 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011586 }
11587
Johannes Bergff1b6e62011-05-04 15:37:28 +020011588 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11589 struct nlattr *pat;
11590 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011591 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011592 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011593
Johannes Berg98fc4382015-03-01 09:10:13 +020011594 regular = true;
11595
Johannes Bergff1b6e62011-05-04 15:37:28 +020011596 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11597 rem)
11598 n_patterns++;
11599 if (n_patterns > wowlan->n_patterns)
11600 return -EINVAL;
11601
11602 new_triggers.patterns = kcalloc(n_patterns,
11603 sizeof(new_triggers.patterns[0]),
11604 GFP_KERNEL);
11605 if (!new_triggers.patterns)
11606 return -ENOMEM;
11607
11608 new_triggers.n_patterns = n_patterns;
11609 i = 0;
11610
11611 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11612 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011613 u8 *mask_pat;
11614
Johannes Berg8cb08172019-04-26 14:07:28 +020011615 err = nla_parse_nested_deprecated(pat_tb,
11616 MAX_NL80211_PKTPAT,
11617 pat,
11618 nl80211_packet_pattern_policy,
11619 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020011620 if (err)
11621 goto error;
11622
Johannes Bergff1b6e62011-05-04 15:37:28 +020011623 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011624 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11625 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011626 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011627 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011628 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011629 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011630 goto error;
11631 if (pat_len > wowlan->pattern_max_len ||
11632 pat_len < wowlan->pattern_min_len)
11633 goto error;
11634
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011635 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011636 pkt_offset = 0;
11637 else
11638 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011639 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011640 if (pkt_offset > wowlan->max_pkt_offset)
11641 goto error;
11642 new_triggers.patterns[i].pkt_offset = pkt_offset;
11643
Johannes Berg922bd802014-05-19 17:59:50 +020011644 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11645 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011646 err = -ENOMEM;
11647 goto error;
11648 }
Johannes Berg922bd802014-05-19 17:59:50 +020011649 new_triggers.patterns[i].mask = mask_pat;
11650 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011651 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011652 mask_pat += mask_len;
11653 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011654 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011655 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011656 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011657 pat_len);
11658 i++;
11659 }
11660 }
11661
Johannes Berg2a0e0472013-01-23 22:57:40 +010011662 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011663 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011664 err = nl80211_parse_wowlan_tcp(
11665 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11666 &new_triggers);
11667 if (err)
11668 goto error;
11669 }
11670
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011671 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011672 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011673 err = nl80211_parse_wowlan_nd(
11674 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11675 &new_triggers);
11676 if (err)
11677 goto error;
11678 }
11679
Johannes Berg98fc4382015-03-01 09:10:13 +020011680 /* The 'any' trigger means the device continues operating more or less
11681 * as in its normal operation mode and wakes up the host on most of the
11682 * normal interrupts (like packet RX, ...)
11683 * It therefore makes little sense to combine with the more constrained
11684 * wakeup trigger modes.
11685 */
11686 if (new_triggers.any && regular) {
11687 err = -EINVAL;
11688 goto error;
11689 }
11690
Johannes Bergae33bd82012-07-12 16:25:02 +020011691 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11692 if (!ntrig) {
11693 err = -ENOMEM;
11694 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011695 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011696 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011697 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011698
Johannes Bergae33bd82012-07-12 16:25:02 +020011699 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011700 if (rdev->ops->set_wakeup &&
11701 prev_enabled != !!rdev->wiphy.wowlan_config)
11702 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011703
Johannes Bergff1b6e62011-05-04 15:37:28 +020011704 return 0;
11705 error:
11706 for (i = 0; i < new_triggers.n_patterns; i++)
11707 kfree(new_triggers.patterns[i].mask);
11708 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011709 if (new_triggers.tcp && new_triggers.tcp->sock)
11710 sock_release(new_triggers.tcp->sock);
11711 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011712 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011713 return err;
11714}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011715#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011716
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011717static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11718 struct cfg80211_registered_device *rdev)
11719{
11720 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11721 int i, j, pat_len;
11722 struct cfg80211_coalesce_rules *rule;
11723
11724 if (!rdev->coalesce->n_rules)
11725 return 0;
11726
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011727 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011728 if (!nl_rules)
11729 return -ENOBUFS;
11730
11731 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011732 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011733 if (!nl_rule)
11734 return -ENOBUFS;
11735
11736 rule = &rdev->coalesce->rules[i];
11737 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11738 rule->delay))
11739 return -ENOBUFS;
11740
11741 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11742 rule->condition))
11743 return -ENOBUFS;
11744
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011745 nl_pats = nla_nest_start_noflag(msg,
11746 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011747 if (!nl_pats)
11748 return -ENOBUFS;
11749
11750 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011751 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011752 if (!nl_pat)
11753 return -ENOBUFS;
11754 pat_len = rule->patterns[j].pattern_len;
11755 if (nla_put(msg, NL80211_PKTPAT_MASK,
11756 DIV_ROUND_UP(pat_len, 8),
11757 rule->patterns[j].mask) ||
11758 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11759 rule->patterns[j].pattern) ||
11760 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11761 rule->patterns[j].pkt_offset))
11762 return -ENOBUFS;
11763 nla_nest_end(msg, nl_pat);
11764 }
11765 nla_nest_end(msg, nl_pats);
11766 nla_nest_end(msg, nl_rule);
11767 }
11768 nla_nest_end(msg, nl_rules);
11769
11770 return 0;
11771}
11772
11773static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11774{
11775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11776 struct sk_buff *msg;
11777 void *hdr;
11778
11779 if (!rdev->wiphy.coalesce)
11780 return -EOPNOTSUPP;
11781
11782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11783 if (!msg)
11784 return -ENOMEM;
11785
11786 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11787 NL80211_CMD_GET_COALESCE);
11788 if (!hdr)
11789 goto nla_put_failure;
11790
11791 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11792 goto nla_put_failure;
11793
11794 genlmsg_end(msg, hdr);
11795 return genlmsg_reply(msg, info);
11796
11797nla_put_failure:
11798 nlmsg_free(msg);
11799 return -ENOBUFS;
11800}
11801
11802void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11803{
11804 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11805 int i, j;
11806 struct cfg80211_coalesce_rules *rule;
11807
11808 if (!coalesce)
11809 return;
11810
11811 for (i = 0; i < coalesce->n_rules; i++) {
11812 rule = &coalesce->rules[i];
11813 for (j = 0; j < rule->n_patterns; j++)
11814 kfree(rule->patterns[j].mask);
11815 kfree(rule->patterns);
11816 }
11817 kfree(coalesce->rules);
11818 kfree(coalesce);
11819 rdev->coalesce = NULL;
11820}
11821
11822static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11823 struct nlattr *rule,
11824 struct cfg80211_coalesce_rules *new_rule)
11825{
11826 int err, i;
11827 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11828 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11829 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11830 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11831
Johannes Berg8cb08172019-04-26 14:07:28 +020011832 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11833 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011834 if (err)
11835 return err;
11836
11837 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11838 new_rule->delay =
11839 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11840 if (new_rule->delay > coalesce->max_delay)
11841 return -EINVAL;
11842
11843 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11844 new_rule->condition =
11845 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011846
11847 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11848 return -EINVAL;
11849
11850 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11851 rem)
11852 n_patterns++;
11853 if (n_patterns > coalesce->n_patterns)
11854 return -EINVAL;
11855
11856 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11857 GFP_KERNEL);
11858 if (!new_rule->patterns)
11859 return -ENOMEM;
11860
11861 new_rule->n_patterns = n_patterns;
11862 i = 0;
11863
11864 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11865 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011866 u8 *mask_pat;
11867
Johannes Berg8cb08172019-04-26 14:07:28 +020011868 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11869 pat,
11870 nl80211_packet_pattern_policy,
11871 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020011872 if (err)
11873 return err;
11874
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011875 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11876 !pat_tb[NL80211_PKTPAT_PATTERN])
11877 return -EINVAL;
11878 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11879 mask_len = DIV_ROUND_UP(pat_len, 8);
11880 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11881 return -EINVAL;
11882 if (pat_len > coalesce->pattern_max_len ||
11883 pat_len < coalesce->pattern_min_len)
11884 return -EINVAL;
11885
11886 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11887 pkt_offset = 0;
11888 else
11889 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11890 if (pkt_offset > coalesce->max_pkt_offset)
11891 return -EINVAL;
11892 new_rule->patterns[i].pkt_offset = pkt_offset;
11893
Johannes Berg922bd802014-05-19 17:59:50 +020011894 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11895 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011896 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011897
11898 new_rule->patterns[i].mask = mask_pat;
11899 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11900 mask_len);
11901
11902 mask_pat += mask_len;
11903 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011904 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011905 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11906 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011907 i++;
11908 }
11909
11910 return 0;
11911}
11912
11913static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11914{
11915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11916 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11917 struct cfg80211_coalesce new_coalesce = {};
11918 struct cfg80211_coalesce *n_coalesce;
11919 int err, rem_rule, n_rules = 0, i, j;
11920 struct nlattr *rule;
11921 struct cfg80211_coalesce_rules *tmp_rule;
11922
11923 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11924 return -EOPNOTSUPP;
11925
11926 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11927 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011928 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011929 return 0;
11930 }
11931
11932 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11933 rem_rule)
11934 n_rules++;
11935 if (n_rules > coalesce->n_rules)
11936 return -EINVAL;
11937
11938 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11939 GFP_KERNEL);
11940 if (!new_coalesce.rules)
11941 return -ENOMEM;
11942
11943 new_coalesce.n_rules = n_rules;
11944 i = 0;
11945
11946 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11947 rem_rule) {
11948 err = nl80211_parse_coalesce_rule(rdev, rule,
11949 &new_coalesce.rules[i]);
11950 if (err)
11951 goto error;
11952
11953 i++;
11954 }
11955
Ilan Peera1056b1b2015-10-22 22:27:46 +030011956 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011957 if (err)
11958 goto error;
11959
11960 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11961 if (!n_coalesce) {
11962 err = -ENOMEM;
11963 goto error;
11964 }
11965 cfg80211_rdev_free_coalesce(rdev);
11966 rdev->coalesce = n_coalesce;
11967
11968 return 0;
11969error:
11970 for (i = 0; i < new_coalesce.n_rules; i++) {
11971 tmp_rule = &new_coalesce.rules[i];
11972 for (j = 0; j < tmp_rule->n_patterns; j++)
11973 kfree(tmp_rule->patterns[j].mask);
11974 kfree(tmp_rule->patterns);
11975 }
11976 kfree(new_coalesce.rules);
11977
11978 return err;
11979}
11980
Johannes Berge5497d72011-07-05 16:35:40 +020011981static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11982{
11983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11984 struct net_device *dev = info->user_ptr[1];
11985 struct wireless_dev *wdev = dev->ieee80211_ptr;
11986 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11987 struct cfg80211_gtk_rekey_data rekey_data;
11988 int err;
11989
11990 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11991 return -EINVAL;
11992
Johannes Berg8cb08172019-04-26 14:07:28 +020011993 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
11994 info->attrs[NL80211_ATTR_REKEY_DATA],
11995 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011996 if (err)
11997 return err;
11998
Vladis Dronove785fa02017-09-13 00:21:21 +020011999 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12000 !tb[NL80211_REKEY_DATA_KCK])
12001 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020012002 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
12003 return -ERANGE;
12004 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
12005 return -ERANGE;
12006 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
12007 return -ERANGE;
12008
Johannes Berg78f686c2014-09-10 22:28:06 +030012009 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12010 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12011 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020012012
12013 wdev_lock(wdev);
12014 if (!wdev->current_bss) {
12015 err = -ENOTCONN;
12016 goto out;
12017 }
12018
12019 if (!rdev->ops->set_rekey_data) {
12020 err = -EOPNOTSUPP;
12021 goto out;
12022 }
12023
Hila Gonene35e4d22012-06-27 17:19:42 +030012024 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020012025 out:
12026 wdev_unlock(wdev);
12027 return err;
12028}
12029
Johannes Berg28946da2011-11-04 11:18:12 +010012030static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12031 struct genl_info *info)
12032{
12033 struct net_device *dev = info->user_ptr[1];
12034 struct wireless_dev *wdev = dev->ieee80211_ptr;
12035
12036 if (wdev->iftype != NL80211_IFTYPE_AP &&
12037 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12038 return -EINVAL;
12039
Eric W. Biederman15e47302012-09-07 20:12:54 +000012040 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012041 return -EBUSY;
12042
Eric W. Biederman15e47302012-09-07 20:12:54 +000012043 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010012044 return 0;
12045}
12046
Johannes Berg7f6cf312011-11-04 11:18:15 +010012047static int nl80211_probe_client(struct sk_buff *skb,
12048 struct genl_info *info)
12049{
12050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12051 struct net_device *dev = info->user_ptr[1];
12052 struct wireless_dev *wdev = dev->ieee80211_ptr;
12053 struct sk_buff *msg;
12054 void *hdr;
12055 const u8 *addr;
12056 u64 cookie;
12057 int err;
12058
12059 if (wdev->iftype != NL80211_IFTYPE_AP &&
12060 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12061 return -EOPNOTSUPP;
12062
12063 if (!info->attrs[NL80211_ATTR_MAC])
12064 return -EINVAL;
12065
12066 if (!rdev->ops->probe_client)
12067 return -EOPNOTSUPP;
12068
12069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12070 if (!msg)
12071 return -ENOMEM;
12072
Eric W. Biederman15e47302012-09-07 20:12:54 +000012073 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010012074 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030012075 if (!hdr) {
12076 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012077 goto free_msg;
12078 }
12079
12080 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12081
Hila Gonene35e4d22012-06-27 17:19:42 +030012082 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012083 if (err)
12084 goto free_msg;
12085
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012086 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12087 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012088 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012089
12090 genlmsg_end(msg, hdr);
12091
12092 return genlmsg_reply(msg, info);
12093
12094 nla_put_failure:
12095 err = -ENOBUFS;
12096 free_msg:
12097 nlmsg_free(msg);
12098 return err;
12099}
12100
Johannes Berg5e760232011-11-04 11:18:17 +010012101static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12102{
12103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070012104 struct cfg80211_beacon_registration *reg, *nreg;
12105 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012106
12107 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12108 return -EOPNOTSUPP;
12109
Ben Greear37c73b52012-10-26 14:49:25 -070012110 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12111 if (!nreg)
12112 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010012113
Ben Greear37c73b52012-10-26 14:49:25 -070012114 /* First, check if already registered. */
12115 spin_lock_bh(&rdev->beacon_registrations_lock);
12116 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12117 if (reg->nlportid == info->snd_portid) {
12118 rv = -EALREADY;
12119 goto out_err;
12120 }
12121 }
12122 /* Add it to the list */
12123 nreg->nlportid = info->snd_portid;
12124 list_add(&nreg->list, &rdev->beacon_registrations);
12125
12126 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012127
12128 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070012129out_err:
12130 spin_unlock_bh(&rdev->beacon_registrations_lock);
12131 kfree(nreg);
12132 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012133}
12134
Johannes Berg98104fde2012-06-16 00:19:54 +020012135static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12136{
12137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12138 struct wireless_dev *wdev = info->user_ptr[1];
12139 int err;
12140
12141 if (!rdev->ops->start_p2p_device)
12142 return -EOPNOTSUPP;
12143
12144 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12145 return -EOPNOTSUPP;
12146
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012147 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020012148 return 0;
12149
Luciano Coelhob6a55012014-02-27 11:07:21 +020012150 if (rfkill_blocked(rdev->rfkill))
12151 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020012152
Johannes Bergeeb126e2012-10-23 15:16:50 +020012153 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012154 if (err)
12155 return err;
12156
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012157 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020012158 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020012159
12160 return 0;
12161}
12162
12163static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12164{
12165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12166 struct wireless_dev *wdev = info->user_ptr[1];
12167
12168 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12169 return -EOPNOTSUPP;
12170
12171 if (!rdev->ops->stop_p2p_device)
12172 return -EOPNOTSUPP;
12173
Johannes Bergf9f47522013-03-19 15:04:07 +010012174 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012175
12176 return 0;
12177}
12178
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012179static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12180{
12181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12182 struct wireless_dev *wdev = info->user_ptr[1];
12183 struct cfg80211_nan_conf conf = {};
12184 int err;
12185
12186 if (wdev->iftype != NL80211_IFTYPE_NAN)
12187 return -EOPNOTSUPP;
12188
Johannes Bergeeb04a92016-11-21 13:55:48 +010012189 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012190 return -EEXIST;
12191
12192 if (rfkill_blocked(rdev->rfkill))
12193 return -ERFKILL;
12194
12195 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12196 return -EINVAL;
12197
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012198 conf.master_pref =
12199 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012200
Luca Coelho85859892017-02-08 15:00:34 +020012201 if (info->attrs[NL80211_ATTR_BANDS]) {
12202 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12203
12204 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12205 return -EOPNOTSUPP;
12206
12207 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12208 return -EINVAL;
12209
12210 conf.bands = bands;
12211 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012212
12213 err = rdev_start_nan(rdev, wdev, &conf);
12214 if (err)
12215 return err;
12216
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012217 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012218 rdev->opencount++;
12219
12220 return 0;
12221}
12222
12223static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12224{
12225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12226 struct wireless_dev *wdev = info->user_ptr[1];
12227
12228 if (wdev->iftype != NL80211_IFTYPE_NAN)
12229 return -EOPNOTSUPP;
12230
12231 cfg80211_stop_nan(rdev, wdev);
12232
12233 return 0;
12234}
12235
Ayala Bekera442b762016-09-20 17:31:15 +030012236static int validate_nan_filter(struct nlattr *filter_attr)
12237{
12238 struct nlattr *attr;
12239 int len = 0, n_entries = 0, rem;
12240
12241 nla_for_each_nested(attr, filter_attr, rem) {
12242 len += nla_len(attr);
12243 n_entries++;
12244 }
12245
12246 if (len >= U8_MAX)
12247 return -EINVAL;
12248
12249 return n_entries;
12250}
12251
12252static int handle_nan_filter(struct nlattr *attr_filter,
12253 struct cfg80211_nan_func *func,
12254 bool tx)
12255{
12256 struct nlattr *attr;
12257 int n_entries, rem, i;
12258 struct cfg80211_nan_func_filter *filter;
12259
12260 n_entries = validate_nan_filter(attr_filter);
12261 if (n_entries < 0)
12262 return n_entries;
12263
12264 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12265
12266 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12267 if (!filter)
12268 return -ENOMEM;
12269
12270 i = 0;
12271 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012272 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012273 filter[i].len = nla_len(attr);
12274 i++;
12275 }
12276 if (tx) {
12277 func->num_tx_filters = n_entries;
12278 func->tx_filters = filter;
12279 } else {
12280 func->num_rx_filters = n_entries;
12281 func->rx_filters = filter;
12282 }
12283
12284 return 0;
12285}
12286
12287static int nl80211_nan_add_func(struct sk_buff *skb,
12288 struct genl_info *info)
12289{
12290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12291 struct wireless_dev *wdev = info->user_ptr[1];
12292 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12293 struct cfg80211_nan_func *func;
12294 struct sk_buff *msg = NULL;
12295 void *hdr = NULL;
12296 int err = 0;
12297
12298 if (wdev->iftype != NL80211_IFTYPE_NAN)
12299 return -EOPNOTSUPP;
12300
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012301 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012302 return -ENOTCONN;
12303
12304 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12305 return -EINVAL;
12306
Johannes Berg8cb08172019-04-26 14:07:28 +020012307 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12308 info->attrs[NL80211_ATTR_NAN_FUNC],
12309 nl80211_nan_func_policy,
12310 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012311 if (err)
12312 return err;
12313
12314 func = kzalloc(sizeof(*func), GFP_KERNEL);
12315 if (!func)
12316 return -ENOMEM;
12317
Johannes Bergb60ad342018-10-01 11:52:07 +020012318 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012319
12320 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12321 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12322 err = -EINVAL;
12323 goto out;
12324 }
12325
12326
12327 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12328
12329 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12330 err = -EINVAL;
12331 goto out;
12332 }
12333
12334 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12335 sizeof(func->service_id));
12336
12337 func->close_range =
12338 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12339
12340 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12341 func->serv_spec_info_len =
12342 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12343 func->serv_spec_info =
12344 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12345 func->serv_spec_info_len,
12346 GFP_KERNEL);
12347 if (!func->serv_spec_info) {
12348 err = -ENOMEM;
12349 goto out;
12350 }
12351 }
12352
12353 if (tb[NL80211_NAN_FUNC_TTL])
12354 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12355
12356 switch (func->type) {
12357 case NL80211_NAN_FUNC_PUBLISH:
12358 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12359 err = -EINVAL;
12360 goto out;
12361 }
12362
12363 func->publish_type =
12364 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12365 func->publish_bcast =
12366 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12367
12368 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12369 func->publish_bcast) {
12370 err = -EINVAL;
12371 goto out;
12372 }
12373 break;
12374 case NL80211_NAN_FUNC_SUBSCRIBE:
12375 func->subscribe_active =
12376 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12377 break;
12378 case NL80211_NAN_FUNC_FOLLOW_UP:
12379 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012380 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12381 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012382 err = -EINVAL;
12383 goto out;
12384 }
12385
12386 func->followup_id =
12387 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12388 func->followup_reqid =
12389 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12390 memcpy(func->followup_dest.addr,
12391 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12392 sizeof(func->followup_dest.addr));
12393 if (func->ttl) {
12394 err = -EINVAL;
12395 goto out;
12396 }
12397 break;
12398 default:
12399 err = -EINVAL;
12400 goto out;
12401 }
12402
12403 if (tb[NL80211_NAN_FUNC_SRF]) {
12404 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12405
Johannes Berg8cb08172019-04-26 14:07:28 +020012406 err = nla_parse_nested_deprecated(srf_tb,
12407 NL80211_NAN_SRF_ATTR_MAX,
12408 tb[NL80211_NAN_FUNC_SRF],
12409 nl80211_nan_srf_policy,
12410 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012411 if (err)
12412 goto out;
12413
12414 func->srf_include =
12415 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12416
12417 if (srf_tb[NL80211_NAN_SRF_BF]) {
12418 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12419 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12420 err = -EINVAL;
12421 goto out;
12422 }
12423
12424 func->srf_bf_len =
12425 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12426 func->srf_bf =
12427 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12428 func->srf_bf_len, GFP_KERNEL);
12429 if (!func->srf_bf) {
12430 err = -ENOMEM;
12431 goto out;
12432 }
12433
12434 func->srf_bf_idx =
12435 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12436 } else {
12437 struct nlattr *attr, *mac_attr =
12438 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12439 int n_entries, rem, i = 0;
12440
12441 if (!mac_attr) {
12442 err = -EINVAL;
12443 goto out;
12444 }
12445
12446 n_entries = validate_acl_mac_addrs(mac_attr);
12447 if (n_entries <= 0) {
12448 err = -EINVAL;
12449 goto out;
12450 }
12451
12452 func->srf_num_macs = n_entries;
12453 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012454 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012455 GFP_KERNEL);
12456 if (!func->srf_macs) {
12457 err = -ENOMEM;
12458 goto out;
12459 }
12460
12461 nla_for_each_nested(attr, mac_attr, rem)
12462 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12463 sizeof(*func->srf_macs));
12464 }
12465 }
12466
12467 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12468 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12469 func, true);
12470 if (err)
12471 goto out;
12472 }
12473
12474 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12475 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12476 func, false);
12477 if (err)
12478 goto out;
12479 }
12480
12481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12482 if (!msg) {
12483 err = -ENOMEM;
12484 goto out;
12485 }
12486
12487 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12488 NL80211_CMD_ADD_NAN_FUNCTION);
12489 /* This can't really happen - we just allocated 4KB */
12490 if (WARN_ON(!hdr)) {
12491 err = -ENOMEM;
12492 goto out;
12493 }
12494
12495 err = rdev_add_nan_func(rdev, wdev, func);
12496out:
12497 if (err < 0) {
12498 cfg80211_free_nan_func(func);
12499 nlmsg_free(msg);
12500 return err;
12501 }
12502
12503 /* propagate the instance id and cookie to userspace */
12504 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12505 NL80211_ATTR_PAD))
12506 goto nla_put_failure;
12507
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012508 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030012509 if (!func_attr)
12510 goto nla_put_failure;
12511
12512 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12513 func->instance_id))
12514 goto nla_put_failure;
12515
12516 nla_nest_end(msg, func_attr);
12517
12518 genlmsg_end(msg, hdr);
12519 return genlmsg_reply(msg, info);
12520
12521nla_put_failure:
12522 nlmsg_free(msg);
12523 return -ENOBUFS;
12524}
12525
12526static int nl80211_nan_del_func(struct sk_buff *skb,
12527 struct genl_info *info)
12528{
12529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12530 struct wireless_dev *wdev = info->user_ptr[1];
12531 u64 cookie;
12532
12533 if (wdev->iftype != NL80211_IFTYPE_NAN)
12534 return -EOPNOTSUPP;
12535
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012536 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012537 return -ENOTCONN;
12538
12539 if (!info->attrs[NL80211_ATTR_COOKIE])
12540 return -EINVAL;
12541
Ayala Bekera442b762016-09-20 17:31:15 +030012542 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12543
12544 rdev_del_nan_func(rdev, wdev, cookie);
12545
12546 return 0;
12547}
12548
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012549static int nl80211_nan_change_config(struct sk_buff *skb,
12550 struct genl_info *info)
12551{
12552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12553 struct wireless_dev *wdev = info->user_ptr[1];
12554 struct cfg80211_nan_conf conf = {};
12555 u32 changed = 0;
12556
12557 if (wdev->iftype != NL80211_IFTYPE_NAN)
12558 return -EOPNOTSUPP;
12559
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012560 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012561 return -ENOTCONN;
12562
12563 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12564 conf.master_pref =
12565 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12566 if (conf.master_pref <= 1 || conf.master_pref == 255)
12567 return -EINVAL;
12568
12569 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12570 }
12571
Luca Coelho85859892017-02-08 15:00:34 +020012572 if (info->attrs[NL80211_ATTR_BANDS]) {
12573 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12574
12575 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12576 return -EOPNOTSUPP;
12577
12578 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12579 return -EINVAL;
12580
12581 conf.bands = bands;
12582 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012583 }
12584
12585 if (!changed)
12586 return -EINVAL;
12587
12588 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12589}
12590
Ayala Beker50bcd312016-09-20 17:31:17 +030012591void cfg80211_nan_match(struct wireless_dev *wdev,
12592 struct cfg80211_nan_match_params *match, gfp_t gfp)
12593{
12594 struct wiphy *wiphy = wdev->wiphy;
12595 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12596 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12597 struct sk_buff *msg;
12598 void *hdr;
12599
12600 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12601 return;
12602
12603 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12604 if (!msg)
12605 return;
12606
12607 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12608 if (!hdr) {
12609 nlmsg_free(msg);
12610 return;
12611 }
12612
12613 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12614 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12615 wdev->netdev->ifindex)) ||
12616 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12617 NL80211_ATTR_PAD))
12618 goto nla_put_failure;
12619
12620 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12621 NL80211_ATTR_PAD) ||
12622 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12623 goto nla_put_failure;
12624
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012625 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030012626 if (!match_attr)
12627 goto nla_put_failure;
12628
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012629 local_func_attr = nla_nest_start_noflag(msg,
12630 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030012631 if (!local_func_attr)
12632 goto nla_put_failure;
12633
12634 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12635 goto nla_put_failure;
12636
12637 nla_nest_end(msg, local_func_attr);
12638
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012639 peer_func_attr = nla_nest_start_noflag(msg,
12640 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030012641 if (!peer_func_attr)
12642 goto nla_put_failure;
12643
12644 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12645 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12646 goto nla_put_failure;
12647
12648 if (match->info && match->info_len &&
12649 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12650 match->info))
12651 goto nla_put_failure;
12652
12653 nla_nest_end(msg, peer_func_attr);
12654 nla_nest_end(msg, match_attr);
12655 genlmsg_end(msg, hdr);
12656
12657 if (!wdev->owner_nlportid)
12658 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12659 msg, 0, NL80211_MCGRP_NAN, gfp);
12660 else
12661 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12662 wdev->owner_nlportid);
12663
12664 return;
12665
12666nla_put_failure:
12667 nlmsg_free(msg);
12668}
12669EXPORT_SYMBOL(cfg80211_nan_match);
12670
Ayala Beker368e5a72016-09-20 17:31:18 +030012671void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12672 u8 inst_id,
12673 enum nl80211_nan_func_term_reason reason,
12674 u64 cookie, gfp_t gfp)
12675{
12676 struct wiphy *wiphy = wdev->wiphy;
12677 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12678 struct sk_buff *msg;
12679 struct nlattr *func_attr;
12680 void *hdr;
12681
12682 if (WARN_ON(!inst_id))
12683 return;
12684
12685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12686 if (!msg)
12687 return;
12688
12689 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12690 if (!hdr) {
12691 nlmsg_free(msg);
12692 return;
12693 }
12694
12695 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12696 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12697 wdev->netdev->ifindex)) ||
12698 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12699 NL80211_ATTR_PAD))
12700 goto nla_put_failure;
12701
12702 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12703 NL80211_ATTR_PAD))
12704 goto nla_put_failure;
12705
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012706 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030012707 if (!func_attr)
12708 goto nla_put_failure;
12709
12710 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12711 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12712 goto nla_put_failure;
12713
12714 nla_nest_end(msg, func_attr);
12715 genlmsg_end(msg, hdr);
12716
12717 if (!wdev->owner_nlportid)
12718 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12719 msg, 0, NL80211_MCGRP_NAN, gfp);
12720 else
12721 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12722 wdev->owner_nlportid);
12723
12724 return;
12725
12726nla_put_failure:
12727 nlmsg_free(msg);
12728}
12729EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12730
Johannes Berg3713b4e2013-02-14 16:19:38 +010012731static int nl80211_get_protocol_features(struct sk_buff *skb,
12732 struct genl_info *info)
12733{
12734 void *hdr;
12735 struct sk_buff *msg;
12736
12737 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12738 if (!msg)
12739 return -ENOMEM;
12740
12741 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12742 NL80211_CMD_GET_PROTOCOL_FEATURES);
12743 if (!hdr)
12744 goto nla_put_failure;
12745
12746 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12747 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12748 goto nla_put_failure;
12749
12750 genlmsg_end(msg, hdr);
12751 return genlmsg_reply(msg, info);
12752
12753 nla_put_failure:
12754 kfree_skb(msg);
12755 return -ENOBUFS;
12756}
12757
Jouni Malinen355199e2013-02-27 17:14:27 +020012758static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12759{
12760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12761 struct cfg80211_update_ft_ies_params ft_params;
12762 struct net_device *dev = info->user_ptr[1];
12763
12764 if (!rdev->ops->update_ft_ies)
12765 return -EOPNOTSUPP;
12766
12767 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012768 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012769 return -EINVAL;
12770
12771 memset(&ft_params, 0, sizeof(ft_params));
12772 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12773 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12774 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12775
12776 return rdev_update_ft_ies(rdev, dev, &ft_params);
12777}
12778
Arend van Spriel5de17982013-04-18 15:49:00 +020012779static int nl80211_crit_protocol_start(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 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12785 u16 duration;
12786 int ret;
12787
12788 if (!rdev->ops->crit_proto_start)
12789 return -EOPNOTSUPP;
12790
12791 if (WARN_ON(!rdev->ops->crit_proto_stop))
12792 return -EINVAL;
12793
12794 if (rdev->crit_proto_nlportid)
12795 return -EBUSY;
12796
12797 /* determine protocol if provided */
12798 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12799 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12800
12801 if (proto >= NUM_NL80211_CRIT_PROTO)
12802 return -EINVAL;
12803
12804 /* timeout must be provided */
12805 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12806 return -EINVAL;
12807
12808 duration =
12809 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12810
12811 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12812 return -ERANGE;
12813
12814 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12815 if (!ret)
12816 rdev->crit_proto_nlportid = info->snd_portid;
12817
12818 return ret;
12819}
12820
12821static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12822 struct genl_info *info)
12823{
12824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12825 struct wireless_dev *wdev = info->user_ptr[1];
12826
12827 if (!rdev->ops->crit_proto_stop)
12828 return -EOPNOTSUPP;
12829
12830 if (rdev->crit_proto_nlportid) {
12831 rdev->crit_proto_nlportid = 0;
12832 rdev_crit_proto_stop(rdev, wdev);
12833 }
12834 return 0;
12835}
12836
Johannes Berg901bb982019-05-28 10:56:03 +020012837static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
12838 struct nlattr *attr,
12839 struct netlink_ext_ack *extack)
12840{
12841 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
12842 if (attr->nla_type & NLA_F_NESTED) {
12843 NL_SET_ERR_MSG_ATTR(extack, attr,
12844 "unexpected nested data");
12845 return -EINVAL;
12846 }
12847
12848 return 0;
12849 }
12850
12851 if (!(attr->nla_type & NLA_F_NESTED)) {
12852 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
12853 return -EINVAL;
12854 }
12855
12856 return nl80211_validate_nested(attr, vcmd->maxattr, vcmd->policy,
12857 extack);
12858}
12859
Johannes Bergad7e7182013-11-13 13:37:47 +010012860static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12861{
12862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12863 struct wireless_dev *wdev =
12864 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12865 int i, err;
12866 u32 vid, subcmd;
12867
12868 if (!rdev->wiphy.vendor_commands)
12869 return -EOPNOTSUPP;
12870
12871 if (IS_ERR(wdev)) {
12872 err = PTR_ERR(wdev);
12873 if (err != -EINVAL)
12874 return err;
12875 wdev = NULL;
12876 } else if (wdev->wiphy != &rdev->wiphy) {
12877 return -EINVAL;
12878 }
12879
12880 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12881 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12882 return -EINVAL;
12883
12884 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12885 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12886 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12887 const struct wiphy_vendor_command *vcmd;
12888 void *data = NULL;
12889 int len = 0;
12890
12891 vcmd = &rdev->wiphy.vendor_commands[i];
12892
12893 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12894 continue;
12895
12896 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12897 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12898 if (!wdev)
12899 return -EINVAL;
12900 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12901 !wdev->netdev)
12902 return -EINVAL;
12903
12904 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012905 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012906 return -ENETDOWN;
12907 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012908
12909 if (!vcmd->doit)
12910 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012911 } else {
12912 wdev = NULL;
12913 }
12914
12915 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12916 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12917 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020012918
12919 err = nl80211_vendor_check_policy(vcmd,
12920 info->attrs[NL80211_ATTR_VENDOR_DATA],
12921 info->extack);
12922 if (err)
12923 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010012924 }
12925
12926 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020012927 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010012928 rdev->cur_cmd_info = NULL;
12929 return err;
12930 }
12931
12932 return -EOPNOTSUPP;
12933}
12934
Johannes Berg7bdbe402015-08-15 22:39:49 +030012935static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12936 struct netlink_callback *cb,
12937 struct cfg80211_registered_device **rdev,
12938 struct wireless_dev **wdev)
12939{
Johannes Berg50508d92019-07-29 16:31:09 +020012940 struct nlattr **attrbuf;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012941 u32 vid, subcmd;
12942 unsigned int i;
12943 int vcmd_idx = -1;
12944 int err;
12945 void *data = NULL;
12946 unsigned int data_len = 0;
12947
Johannes Berg7bdbe402015-08-15 22:39:49 +030012948 if (cb->args[0]) {
12949 /* subtract the 1 again here */
12950 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12951 struct wireless_dev *tmp;
12952
Johannes Bergea90e0d2017-03-15 14:26:04 +010012953 if (!wiphy)
12954 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012955 *rdev = wiphy_to_rdev(wiphy);
12956 *wdev = NULL;
12957
12958 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012959 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012960 if (tmp->identifier == cb->args[1] - 1) {
12961 *wdev = tmp;
12962 break;
12963 }
12964 }
12965 }
12966
12967 /* keep rtnl locked in successful case */
12968 return 0;
12969 }
12970
Johannes Berg50508d92019-07-29 16:31:09 +020012971 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
12972 if (!attrbuf)
12973 return -ENOMEM;
12974
Johannes Berg8cb08172019-04-26 14:07:28 +020012975 err = nlmsg_parse_deprecated(cb->nlh,
12976 GENL_HDRLEN + nl80211_fam.hdrsize,
12977 attrbuf, nl80211_fam.maxattr,
12978 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012979 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020012980 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012981
Johannes Bergc90c39d2016-10-24 14:40:01 +020012982 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg50508d92019-07-29 16:31:09 +020012983 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
12984 err = -EINVAL;
12985 goto out;
12986 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012987
Johannes Bergc90c39d2016-10-24 14:40:01 +020012988 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012989 if (IS_ERR(*wdev))
12990 *wdev = NULL;
12991
Johannes Bergc90c39d2016-10-24 14:40:01 +020012992 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg50508d92019-07-29 16:31:09 +020012993 if (IS_ERR(*rdev)) {
12994 err = PTR_ERR(*rdev);
12995 goto out;
12996 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012997
Johannes Bergc90c39d2016-10-24 14:40:01 +020012998 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12999 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013000
13001 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13002 const struct wiphy_vendor_command *vcmd;
13003
13004 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13005
13006 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13007 continue;
13008
Johannes Berg50508d92019-07-29 16:31:09 +020013009 if (!vcmd->dumpit) {
13010 err = -EOPNOTSUPP;
13011 goto out;
13012 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013013
13014 vcmd_idx = i;
13015 break;
13016 }
13017
Johannes Berg50508d92019-07-29 16:31:09 +020013018 if (vcmd_idx < 0) {
13019 err = -EOPNOTSUPP;
13020 goto out;
13021 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013022
Johannes Bergc90c39d2016-10-24 14:40:01 +020013023 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13024 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13025 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020013026
13027 err = nl80211_vendor_check_policy(
13028 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13029 attrbuf[NL80211_ATTR_VENDOR_DATA],
13030 cb->extack);
13031 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013032 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013033 }
13034
13035 /* 0 is the first index - add 1 to parse only once */
13036 cb->args[0] = (*rdev)->wiphy_idx + 1;
13037 /* add 1 to know if it was NULL */
13038 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13039 cb->args[2] = vcmd_idx;
13040 cb->args[3] = (unsigned long)data;
13041 cb->args[4] = data_len;
13042
13043 /* keep rtnl locked in successful case */
Johannes Berg50508d92019-07-29 16:31:09 +020013044 err = 0;
13045out:
13046 kfree(attrbuf);
13047 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013048}
13049
13050static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13051 struct netlink_callback *cb)
13052{
13053 struct cfg80211_registered_device *rdev;
13054 struct wireless_dev *wdev;
13055 unsigned int vcmd_idx;
13056 const struct wiphy_vendor_command *vcmd;
13057 void *data;
13058 int data_len;
13059 int err;
13060 struct nlattr *vendor_data;
13061
Johannes Bergea90e0d2017-03-15 14:26:04 +010013062 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030013063 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13064 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010013065 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013066
13067 vcmd_idx = cb->args[2];
13068 data = (void *)cb->args[3];
13069 data_len = cb->args[4];
13070 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13071
13072 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13073 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013074 if (!wdev) {
13075 err = -EINVAL;
13076 goto out;
13077 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013078 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010013079 !wdev->netdev) {
13080 err = -EINVAL;
13081 goto out;
13082 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013083
13084 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013085 if (!wdev_running(wdev)) {
13086 err = -ENETDOWN;
13087 goto out;
13088 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013089 }
13090 }
13091
13092 while (1) {
13093 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13094 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13095 NL80211_CMD_VENDOR);
13096 if (!hdr)
13097 break;
13098
13099 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013100 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13101 wdev_id(wdev),
13102 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013103 genlmsg_cancel(skb, hdr);
13104 break;
13105 }
13106
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013107 vendor_data = nla_nest_start_noflag(skb,
13108 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013109 if (!vendor_data) {
13110 genlmsg_cancel(skb, hdr);
13111 break;
13112 }
13113
13114 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13115 (unsigned long *)&cb->args[5]);
13116 nla_nest_end(skb, vendor_data);
13117
13118 if (err == -ENOBUFS || err == -ENOENT) {
13119 genlmsg_cancel(skb, hdr);
13120 break;
13121 } else if (err) {
13122 genlmsg_cancel(skb, hdr);
13123 goto out;
13124 }
13125
13126 genlmsg_end(skb, hdr);
13127 }
13128
13129 err = skb->len;
13130 out:
13131 rtnl_unlock();
13132 return err;
13133}
13134
Johannes Bergad7e7182013-11-13 13:37:47 +010013135struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13136 enum nl80211_commands cmd,
13137 enum nl80211_attrs attr,
13138 int approxlen)
13139{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013140 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010013141
13142 if (WARN_ON(!rdev->cur_cmd_info))
13143 return NULL;
13144
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020013145 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010013146 rdev->cur_cmd_info->snd_portid,
13147 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010013148 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010013149}
13150EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13151
13152int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13153{
13154 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13155 void *hdr = ((void **)skb->cb)[1];
13156 struct nlattr *data = ((void **)skb->cb)[2];
13157
Johannes Bergbd8c78e2014-07-30 14:55:26 +020013158 /* clear CB data for netlink core to own from now on */
13159 memset(skb->cb, 0, sizeof(skb->cb));
13160
Johannes Bergad7e7182013-11-13 13:37:47 +010013161 if (WARN_ON(!rdev->cur_cmd_info)) {
13162 kfree_skb(skb);
13163 return -EINVAL;
13164 }
13165
13166 nla_nest_end(skb, data);
13167 genlmsg_end(skb, hdr);
13168 return genlmsg_reply(skb, rdev->cur_cmd_info);
13169}
13170EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13171
Johannes Berg55c1fdf2019-02-06 13:17:19 +020013172unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13173{
13174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13175
13176 if (WARN_ON(!rdev->cur_cmd_info))
13177 return 0;
13178
13179 return rdev->cur_cmd_info->snd_portid;
13180}
13181EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13182
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013183static int nl80211_set_qos_map(struct sk_buff *skb,
13184 struct genl_info *info)
13185{
13186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13187 struct cfg80211_qos_map *qos_map = NULL;
13188 struct net_device *dev = info->user_ptr[1];
13189 u8 *pos, len, num_des, des_len, des;
13190 int ret;
13191
13192 if (!rdev->ops->set_qos_map)
13193 return -EOPNOTSUPP;
13194
13195 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13196 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13197 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13198
13199 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13200 len > IEEE80211_QOS_MAP_LEN_MAX)
13201 return -EINVAL;
13202
13203 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13204 if (!qos_map)
13205 return -ENOMEM;
13206
13207 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13208 if (num_des) {
13209 des_len = num_des *
13210 sizeof(struct cfg80211_dscp_exception);
13211 memcpy(qos_map->dscp_exception, pos, des_len);
13212 qos_map->num_des = num_des;
13213 for (des = 0; des < num_des; des++) {
13214 if (qos_map->dscp_exception[des].up > 7) {
13215 kfree(qos_map);
13216 return -EINVAL;
13217 }
13218 }
13219 pos += des_len;
13220 }
13221 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13222 }
13223
13224 wdev_lock(dev->ieee80211_ptr);
13225 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13226 if (!ret)
13227 ret = rdev_set_qos_map(rdev, dev, qos_map);
13228 wdev_unlock(dev->ieee80211_ptr);
13229
13230 kfree(qos_map);
13231 return ret;
13232}
13233
Johannes Berg960d01a2014-09-09 22:55:35 +030013234static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13235{
13236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13237 struct net_device *dev = info->user_ptr[1];
13238 struct wireless_dev *wdev = dev->ieee80211_ptr;
13239 const u8 *peer;
13240 u8 tsid, up;
13241 u16 admitted_time = 0;
13242 int err;
13243
Johannes Berg723e73a2014-10-22 09:25:06 +020013244 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013245 return -EOPNOTSUPP;
13246
13247 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13248 !info->attrs[NL80211_ATTR_USER_PRIO])
13249 return -EINVAL;
13250
13251 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013252 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013253
13254 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013255 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013256 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013257 * need more attributes for that (e.g. BA session requirement);
13258 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013259 */
13260 return -EINVAL;
13261 }
13262
13263 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13264
13265 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13266 admitted_time =
13267 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13268 if (!admitted_time)
13269 return -EINVAL;
13270 }
13271
13272 wdev_lock(wdev);
13273 switch (wdev->iftype) {
13274 case NL80211_IFTYPE_STATION:
13275 case NL80211_IFTYPE_P2P_CLIENT:
13276 if (wdev->current_bss)
13277 break;
13278 err = -ENOTCONN;
13279 goto out;
13280 default:
13281 err = -EOPNOTSUPP;
13282 goto out;
13283 }
13284
13285 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13286
13287 out:
13288 wdev_unlock(wdev);
13289 return err;
13290}
13291
13292static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13293{
13294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13295 struct net_device *dev = info->user_ptr[1];
13296 struct wireless_dev *wdev = dev->ieee80211_ptr;
13297 const u8 *peer;
13298 u8 tsid;
13299 int err;
13300
13301 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13302 return -EINVAL;
13303
13304 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13305 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13306
13307 wdev_lock(wdev);
13308 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13309 wdev_unlock(wdev);
13310
13311 return err;
13312}
13313
Arik Nemtsov1057d352014-11-19 12:54:26 +020013314static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13315 struct genl_info *info)
13316{
13317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13318 struct net_device *dev = info->user_ptr[1];
13319 struct wireless_dev *wdev = dev->ieee80211_ptr;
13320 struct cfg80211_chan_def chandef = {};
13321 const u8 *addr;
13322 u8 oper_class;
13323 int err;
13324
13325 if (!rdev->ops->tdls_channel_switch ||
13326 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13327 return -EOPNOTSUPP;
13328
13329 switch (dev->ieee80211_ptr->iftype) {
13330 case NL80211_IFTYPE_STATION:
13331 case NL80211_IFTYPE_P2P_CLIENT:
13332 break;
13333 default:
13334 return -EOPNOTSUPP;
13335 }
13336
13337 if (!info->attrs[NL80211_ATTR_MAC] ||
13338 !info->attrs[NL80211_ATTR_OPER_CLASS])
13339 return -EINVAL;
13340
13341 err = nl80211_parse_chandef(rdev, info, &chandef);
13342 if (err)
13343 return err;
13344
13345 /*
13346 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13347 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13348 * specification is not defined for them.
13349 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013350 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013351 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13352 chandef.width != NL80211_CHAN_WIDTH_20)
13353 return -EINVAL;
13354
13355 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013356 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13357 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013358 return -EINVAL;
13359
13360 /* don't allow switching to DFS channels */
13361 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13362 return -EINVAL;
13363
13364 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13365 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13366
13367 wdev_lock(wdev);
13368 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13369 wdev_unlock(wdev);
13370
13371 return err;
13372}
13373
13374static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13375 struct genl_info *info)
13376{
13377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13378 struct net_device *dev = info->user_ptr[1];
13379 struct wireless_dev *wdev = dev->ieee80211_ptr;
13380 const u8 *addr;
13381
13382 if (!rdev->ops->tdls_channel_switch ||
13383 !rdev->ops->tdls_cancel_channel_switch ||
13384 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13385 return -EOPNOTSUPP;
13386
13387 switch (dev->ieee80211_ptr->iftype) {
13388 case NL80211_IFTYPE_STATION:
13389 case NL80211_IFTYPE_P2P_CLIENT:
13390 break;
13391 default:
13392 return -EOPNOTSUPP;
13393 }
13394
13395 if (!info->attrs[NL80211_ATTR_MAC])
13396 return -EINVAL;
13397
13398 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13399
13400 wdev_lock(wdev);
13401 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13402 wdev_unlock(wdev);
13403
13404 return 0;
13405}
13406
Michael Braunce0ce132016-10-10 19:12:22 +020013407static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13408 struct genl_info *info)
13409{
13410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13411 struct net_device *dev = info->user_ptr[1];
13412 struct wireless_dev *wdev = dev->ieee80211_ptr;
13413 const struct nlattr *nla;
13414 bool enabled;
13415
Michael Braunce0ce132016-10-10 19:12:22 +020013416 if (!rdev->ops->set_multicast_to_unicast)
13417 return -EOPNOTSUPP;
13418
13419 if (wdev->iftype != NL80211_IFTYPE_AP &&
13420 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13421 return -EOPNOTSUPP;
13422
13423 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13424 enabled = nla_get_flag(nla);
13425
13426 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13427}
13428
Avraham Stern3a00df52017-06-09 13:08:43 +010013429static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13430{
13431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13432 struct net_device *dev = info->user_ptr[1];
13433 struct wireless_dev *wdev = dev->ieee80211_ptr;
13434 struct cfg80211_pmk_conf pmk_conf = {};
13435 int ret;
13436
13437 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13438 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13439 return -EOPNOTSUPP;
13440
13441 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13442 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13443 return -EOPNOTSUPP;
13444
13445 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13446 return -EINVAL;
13447
13448 wdev_lock(wdev);
13449 if (!wdev->current_bss) {
13450 ret = -ENOTCONN;
13451 goto out;
13452 }
13453
13454 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13455 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13456 ret = -EINVAL;
13457 goto out;
13458 }
13459
13460 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13461 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13462 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13463 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13464 ret = -EINVAL;
13465 goto out;
13466 }
13467
13468 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13469 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13470
13471 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13472 ret = -EINVAL;
13473 goto out;
13474 }
13475
13476 pmk_conf.pmk_r0_name =
13477 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13478 }
13479
13480 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13481out:
13482 wdev_unlock(wdev);
13483 return ret;
13484}
13485
13486static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13487{
13488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13489 struct net_device *dev = info->user_ptr[1];
13490 struct wireless_dev *wdev = dev->ieee80211_ptr;
13491 const u8 *aa;
13492 int ret;
13493
13494 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13495 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13496 return -EOPNOTSUPP;
13497
13498 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13499 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13500 return -EOPNOTSUPP;
13501
13502 if (!info->attrs[NL80211_ATTR_MAC])
13503 return -EINVAL;
13504
13505 wdev_lock(wdev);
13506 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13507 ret = rdev_del_pmk(rdev, dev, aa);
13508 wdev_unlock(wdev);
13509
13510 return ret;
13511}
13512
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013513static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13514{
13515 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13516 struct net_device *dev = info->user_ptr[1];
13517 struct cfg80211_external_auth_params params;
13518
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013519 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013520 return -EOPNOTSUPP;
13521
Srinivas Dasarife494372019-01-23 18:06:56 +053013522 if (!info->attrs[NL80211_ATTR_SSID] &&
13523 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13524 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013525 return -EINVAL;
13526
13527 if (!info->attrs[NL80211_ATTR_BSSID])
13528 return -EINVAL;
13529
13530 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13531 return -EINVAL;
13532
13533 memset(&params, 0, sizeof(params));
13534
Srinivas Dasarife494372019-01-23 18:06:56 +053013535 if (info->attrs[NL80211_ATTR_SSID]) {
13536 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13537 if (params.ssid.ssid_len == 0 ||
13538 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13539 return -EINVAL;
13540 memcpy(params.ssid.ssid,
13541 nla_data(info->attrs[NL80211_ATTR_SSID]),
13542 params.ssid.ssid_len);
13543 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013544
13545 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13546 ETH_ALEN);
13547
13548 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13549
Srinivas Dasarife494372019-01-23 18:06:56 +053013550 if (info->attrs[NL80211_ATTR_PMKID])
13551 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13552
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013553 return rdev_external_auth(rdev, dev, &params);
13554}
13555
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013556static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13557{
13558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13559 struct net_device *dev = info->user_ptr[1];
13560 struct wireless_dev *wdev = dev->ieee80211_ptr;
13561 const u8 *buf;
13562 size_t len;
13563 u8 *dest;
13564 u16 proto;
13565 bool noencrypt;
13566 int err;
13567
13568 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13569 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13570 return -EOPNOTSUPP;
13571
13572 if (!rdev->ops->tx_control_port)
13573 return -EOPNOTSUPP;
13574
13575 if (!info->attrs[NL80211_ATTR_FRAME] ||
13576 !info->attrs[NL80211_ATTR_MAC] ||
13577 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13578 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13579 return -EINVAL;
13580 }
13581
13582 wdev_lock(wdev);
13583
13584 switch (wdev->iftype) {
13585 case NL80211_IFTYPE_AP:
13586 case NL80211_IFTYPE_P2P_GO:
13587 case NL80211_IFTYPE_MESH_POINT:
13588 break;
13589 case NL80211_IFTYPE_ADHOC:
13590 case NL80211_IFTYPE_STATION:
13591 case NL80211_IFTYPE_P2P_CLIENT:
13592 if (wdev->current_bss)
13593 break;
13594 err = -ENOTCONN;
13595 goto out;
13596 default:
13597 err = -EOPNOTSUPP;
13598 goto out;
13599 }
13600
13601 wdev_unlock(wdev);
13602
13603 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13604 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13605 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13606 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13607 noencrypt =
13608 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13609
13610 return rdev_tx_control_port(rdev, dev, buf, len,
13611 dest, cpu_to_be16(proto), noencrypt);
13612
13613 out:
13614 wdev_unlock(wdev);
13615 return err;
13616}
13617
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013618static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13619 struct genl_info *info)
13620{
13621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13622 struct net_device *dev = info->user_ptr[1];
13623 struct wireless_dev *wdev = dev->ieee80211_ptr;
13624 struct cfg80211_ftm_responder_stats ftm_stats = {};
13625 struct sk_buff *msg;
13626 void *hdr;
13627 struct nlattr *ftm_stats_attr;
13628 int err;
13629
13630 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13631 return -EOPNOTSUPP;
13632
13633 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13634 if (err)
13635 return err;
13636
13637 if (!ftm_stats.filled)
13638 return -ENODATA;
13639
13640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13641 if (!msg)
13642 return -ENOMEM;
13643
13644 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13645 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13646 if (!hdr)
13647 return -ENOBUFS;
13648
13649 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13650 goto nla_put_failure;
13651
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013652 ftm_stats_attr = nla_nest_start_noflag(msg,
13653 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013654 if (!ftm_stats_attr)
13655 goto nla_put_failure;
13656
13657#define SET_FTM(field, name, type) \
13658 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13659 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13660 ftm_stats.field)) \
13661 goto nla_put_failure; } while (0)
13662#define SET_FTM_U64(field, name) \
13663 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13664 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13665 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13666 goto nla_put_failure; } while (0)
13667
13668 SET_FTM(success_num, SUCCESS_NUM, u32);
13669 SET_FTM(partial_num, PARTIAL_NUM, u32);
13670 SET_FTM(failed_num, FAILED_NUM, u32);
13671 SET_FTM(asap_num, ASAP_NUM, u32);
13672 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13673 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13674 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13675 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13676 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13677#undef SET_FTM
13678
13679 nla_nest_end(msg, ftm_stats_attr);
13680
13681 genlmsg_end(msg, hdr);
13682 return genlmsg_reply(msg, info);
13683
13684nla_put_failure:
13685 nlmsg_free(msg);
13686 return -ENOBUFS;
13687}
13688
Sunil Duttcb74e972019-02-20 16:18:07 +053013689static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13690{
13691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13692 struct cfg80211_update_owe_info owe_info;
13693 struct net_device *dev = info->user_ptr[1];
13694
13695 if (!rdev->ops->update_owe_info)
13696 return -EOPNOTSUPP;
13697
13698 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13699 !info->attrs[NL80211_ATTR_MAC])
13700 return -EINVAL;
13701
13702 memset(&owe_info, 0, sizeof(owe_info));
13703 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13704 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13705
13706 if (info->attrs[NL80211_ATTR_IE]) {
13707 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13708 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13709 }
13710
13711 return rdev_update_owe_info(rdev, dev, &owe_info);
13712}
13713
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013714static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13715{
13716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13717 struct net_device *dev = info->user_ptr[1];
13718 struct wireless_dev *wdev = dev->ieee80211_ptr;
13719 struct station_info sinfo = {};
13720 const u8 *buf;
13721 size_t len;
13722 u8 *dest;
13723 int err;
13724
13725 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13726 return -EOPNOTSUPP;
13727
13728 if (!info->attrs[NL80211_ATTR_MAC] ||
13729 !info->attrs[NL80211_ATTR_FRAME]) {
13730 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13731 return -EINVAL;
13732 }
13733
13734 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13735 return -EOPNOTSUPP;
13736
13737 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13738 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13739 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13740
13741 if (len < sizeof(struct ethhdr))
13742 return -EINVAL;
13743
13744 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13745 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13746 return -EINVAL;
13747
13748 err = rdev_get_station(rdev, dev, dest, &sinfo);
13749 if (err)
13750 return err;
13751
13752 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13753}
13754
Johannes Berg4c476992010-10-04 21:36:35 +020013755#define NL80211_FLAG_NEED_WIPHY 0x01
13756#define NL80211_FLAG_NEED_NETDEV 0x02
13757#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013758#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13759#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13760 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013761#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013762/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013763#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13764 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013765#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013766
Johannes Bergf84f7712013-11-14 17:14:45 +010013767static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013768 struct genl_info *info)
13769{
13770 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013771 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013772 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013773 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13774
13775 if (rtnl)
13776 rtnl_lock();
13777
13778 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013779 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013780 if (IS_ERR(rdev)) {
13781 if (rtnl)
13782 rtnl_unlock();
13783 return PTR_ERR(rdev);
13784 }
13785 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013786 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13787 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013788 ASSERT_RTNL();
13789
Johannes Berg89a54e42012-06-15 14:33:17 +020013790 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13791 info->attrs);
13792 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013793 if (rtnl)
13794 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013795 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013796 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013797
Johannes Berg89a54e42012-06-15 14:33:17 +020013798 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013799 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013800
Johannes Berg1bf614e2012-06-15 15:23:36 +020013801 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13802 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013803 if (rtnl)
13804 rtnl_unlock();
13805 return -EINVAL;
13806 }
13807
13808 info->user_ptr[1] = dev;
13809 } else {
13810 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013811 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013812
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013813 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13814 !wdev_running(wdev)) {
13815 if (rtnl)
13816 rtnl_unlock();
13817 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013818 }
13819
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013820 if (dev)
13821 dev_hold(dev);
13822
Johannes Berg4c476992010-10-04 21:36:35 +020013823 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013824 }
13825
13826 return 0;
13827}
13828
Johannes Bergf84f7712013-11-14 17:14:45 +010013829static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013830 struct genl_info *info)
13831{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013832 if (info->user_ptr[1]) {
13833 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13834 struct wireless_dev *wdev = info->user_ptr[1];
13835
13836 if (wdev->netdev)
13837 dev_put(wdev->netdev);
13838 } else {
13839 dev_put(info->user_ptr[1]);
13840 }
13841 }
Johannes Berg5393b912014-09-10 15:00:16 +030013842
Johannes Berg4c476992010-10-04 21:36:35 +020013843 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13844 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013845
13846 /* If needed, clear the netlink message payload from the SKB
13847 * as it might contain key data that shouldn't stick around on
13848 * the heap after the SKB is freed. The netlink message header
13849 * is still needed for further processing, so leave it intact.
13850 */
13851 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13852 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13853
13854 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13855 }
Johannes Berg4c476992010-10-04 21:36:35 +020013856}
13857
Johannes Berg4534de82013-11-14 17:14:46 +010013858static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013859 {
13860 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013861 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013862 .doit = nl80211_get_wiphy,
13863 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013864 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013865 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013866 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13867 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013868 },
13869 {
13870 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013871 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013872 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013873 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013874 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013875 },
13876 {
13877 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013878 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013879 .doit = nl80211_get_interface,
13880 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040013881 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013882 .internal_flags = NL80211_FLAG_NEED_WDEV |
13883 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013884 },
13885 {
13886 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013887 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013888 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013889 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013890 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13891 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013892 },
13893 {
13894 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013895 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013896 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013897 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013898 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13899 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013900 },
13901 {
13902 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013904 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013905 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013906 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013907 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013908 },
Johannes Berg41ade002007-12-19 02:03:29 +010013909 {
13910 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013911 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013912 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013913 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013914 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013915 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013916 },
13917 {
13918 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013919 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013920 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013921 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013922 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013923 NL80211_FLAG_NEED_RTNL |
13924 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013925 },
13926 {
13927 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013928 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013929 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013930 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013931 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013932 NL80211_FLAG_NEED_RTNL |
13933 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013934 },
13935 {
13936 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013937 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013938 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013939 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013940 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013941 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013942 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013943 {
13944 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020013945 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013946 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013947 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013949 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013950 },
13951 {
Johannes Berg88600202012-02-13 15:17:18 +010013952 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013953 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013954 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013955 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013956 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013957 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013958 },
13959 {
Johannes Berg88600202012-02-13 15:17:18 +010013960 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013961 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013962 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013963 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013964 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013965 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013966 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013967 {
13968 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013969 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013970 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013971 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020013972 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13973 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013974 },
13975 {
13976 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013977 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013978 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013979 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013981 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013982 },
13983 {
13984 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013985 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013986 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013987 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013988 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013989 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013990 },
13991 {
13992 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013993 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013994 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013995 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013996 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013997 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013998 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013999 {
14000 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014001 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014002 .doit = nl80211_get_mpath,
14003 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014004 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014005 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014006 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014007 },
14008 {
Henning Rogge66be7d22014-09-12 08:58:49 +020014009 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014010 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020014011 .doit = nl80211_get_mpp,
14012 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020014013 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020014014 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14015 NL80211_FLAG_NEED_RTNL,
14016 },
14017 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014018 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014019 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014020 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014021 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014023 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014024 },
14025 {
14026 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014027 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014028 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014029 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014030 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014031 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014032 },
14033 {
14034 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014035 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014036 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014037 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014038 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014039 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014040 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014041 {
14042 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014043 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014044 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014045 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014046 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014047 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014048 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014049 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014050 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014051 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014052 .doit = nl80211_get_reg_do,
14053 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014054 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014055 /* can be retrieved by unprivileged users */
14056 },
Johannes Bergb6863032015-10-15 09:25:18 +020014057#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014058 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014059 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014060 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014061 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014062 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014063 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014064 },
Johannes Bergb6863032015-10-15 09:25:18 +020014065#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014066 {
14067 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014068 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014069 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014070 .flags = GENL_ADMIN_PERM,
14071 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014072 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014073 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014074 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014075 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014076 .flags = GENL_ADMIN_PERM,
14077 },
14078 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014079 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014080 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014081 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014082 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014084 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014085 },
14086 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014087 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014088 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014089 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020014090 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014092 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014093 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020014094 {
Johannes Berg2a519312009-02-10 21:25:55 +010014095 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014096 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014097 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014098 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020014099 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014100 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010014101 },
14102 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014103 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014104 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014105 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014106 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014107 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14108 NL80211_FLAG_NEED_RTNL,
14109 },
14110 {
Johannes Berg2a519312009-02-10 21:25:55 +010014111 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014112 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014113 .dumpit = nl80211_dump_scan,
14114 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020014115 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014116 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014117 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014118 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014119 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14121 NL80211_FLAG_NEED_RTNL,
14122 },
14123 {
14124 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014125 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014126 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014127 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14129 NL80211_FLAG_NEED_RTNL,
14130 },
14131 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020014132 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014133 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014134 .doit = nl80211_authenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014135 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014136 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014137 NL80211_FLAG_NEED_RTNL |
14138 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014139 },
14140 {
14141 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014142 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014143 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014144 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014145 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014146 NL80211_FLAG_NEED_RTNL |
14147 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014148 },
14149 {
14150 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014151 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014152 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014153 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014154 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014155 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014156 },
14157 {
14158 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014160 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014163 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014164 },
Johannes Berg04a773a2009-04-19 21:24:32 +020014165 {
14166 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014168 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014169 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014171 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014172 },
14173 {
14174 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014176 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014177 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014179 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014180 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014181#ifdef CONFIG_NL80211_TESTMODE
14182 {
14183 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014185 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014186 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014187 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014188 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14189 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014190 },
14191#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014192 {
14193 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014194 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014195 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014196 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014198 NL80211_FLAG_NEED_RTNL |
14199 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014200 },
14201 {
vamsi krishna088e8df2016-10-27 16:51:11 +030014202 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014203 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030014204 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030014205 .flags = GENL_ADMIN_PERM,
14206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014207 NL80211_FLAG_NEED_RTNL |
14208 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030014209 },
14210 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020014211 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014212 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014213 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014214 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014216 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014217 },
Johannes Berg463d0182009-07-14 00:33:35 +020014218 {
14219 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014220 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020014221 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020014222 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014223 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14224 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020014225 },
Holger Schurig61fa7132009-11-11 12:25:40 +010014226 {
14227 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014228 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010014229 .dumpit = nl80211_dump_survey,
14230 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014231 {
14232 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014233 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014234 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014235 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014237 NL80211_FLAG_NEED_RTNL |
14238 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014239 },
14240 {
14241 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014243 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014246 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014247 },
14248 {
14249 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014250 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014251 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014252 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014253 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014254 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014255 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014256 {
14257 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014258 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014259 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014260 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014261 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014262 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014263 },
14264 {
14265 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014266 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014267 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014268 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014269 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014270 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014271 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014272 {
14273 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014274 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014275 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020014276 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014277 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14278 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014279 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014280 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014281 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014282 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014283 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014284 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014285 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014286 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014287 },
14288 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014289 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014290 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014291 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014292 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014293 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014294 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014295 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014296 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014297 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014298 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014299 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014300 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014301 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014302 NL80211_FLAG_NEED_RTNL,
14303 },
14304 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014305 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014306 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014307 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014308 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014309 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14310 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014311 },
14312 {
14313 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014314 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014315 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014316 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020014317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14318 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014319 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014320 {
14321 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020014322 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014323 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020014324 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14326 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014327 },
Johannes Bergf444de02010-05-05 15:25:02 +020014328 {
14329 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014330 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020014331 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014332 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014333 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14334 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020014335 },
Bill Jordane8347eb2010-10-01 13:54:28 -040014336 {
14337 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014338 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040014339 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020014340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020014341 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14342 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040014343 },
Johannes Berg29cbe682010-12-03 09:20:44 +010014344 {
14345 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014346 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014347 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014348 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14350 NL80211_FLAG_NEED_RTNL,
14351 },
14352 {
14353 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014354 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014355 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014356 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14358 NL80211_FLAG_NEED_RTNL,
14359 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014360 {
14361 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014362 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014363 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014364 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14366 NL80211_FLAG_NEED_RTNL,
14367 },
14368 {
14369 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014370 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014371 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014372 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14374 NL80211_FLAG_NEED_RTNL,
14375 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014376#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020014377 {
14378 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014380 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014381 /* can be retrieved by unprivileged users */
14382 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14383 NL80211_FLAG_NEED_RTNL,
14384 },
14385 {
14386 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014387 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014388 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014389 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014390 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14391 NL80211_FLAG_NEED_RTNL,
14392 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014393#endif
Johannes Berge5497d72011-07-05 16:35:40 +020014394 {
14395 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020014396 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020014397 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020014398 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020014399 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014400 NL80211_FLAG_NEED_RTNL |
14401 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020014402 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030014403 {
14404 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014405 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014406 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014407 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14409 NL80211_FLAG_NEED_RTNL,
14410 },
14411 {
14412 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014414 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020014415 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14417 NL80211_FLAG_NEED_RTNL,
14418 },
Johannes Berg28946da2011-11-04 11:18:12 +010014419 {
14420 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014421 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010014422 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020014423 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010014424 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14425 NL80211_FLAG_NEED_RTNL,
14426 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010014427 {
14428 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014429 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010014430 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020014431 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014432 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010014433 NL80211_FLAG_NEED_RTNL,
14434 },
Johannes Berg5e760232011-11-04 11:18:17 +010014435 {
14436 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014437 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010014438 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020014439 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010014440 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14441 NL80211_FLAG_NEED_RTNL,
14442 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014443 {
14444 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014445 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014446 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014447 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014448 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14449 NL80211_FLAG_NEED_RTNL,
14450 },
Johannes Berg98104fde2012-06-16 00:19:54 +020014451 {
14452 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014453 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014454 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014455 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014456 .internal_flags = NL80211_FLAG_NEED_WDEV |
14457 NL80211_FLAG_NEED_RTNL,
14458 },
14459 {
14460 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014461 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014462 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014463 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014464 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14465 NL80211_FLAG_NEED_RTNL,
14466 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014467 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014468 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014469 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014470 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014471 .flags = GENL_ADMIN_PERM,
14472 .internal_flags = NL80211_FLAG_NEED_WDEV |
14473 NL80211_FLAG_NEED_RTNL,
14474 },
14475 {
14476 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014477 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014478 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014479 .flags = GENL_ADMIN_PERM,
14480 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14481 NL80211_FLAG_NEED_RTNL,
14482 },
14483 {
Ayala Bekera442b762016-09-20 17:31:15 +030014484 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014485 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014486 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014487 .flags = GENL_ADMIN_PERM,
14488 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14489 NL80211_FLAG_NEED_RTNL,
14490 },
14491 {
14492 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014493 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014494 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014495 .flags = GENL_ADMIN_PERM,
14496 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14497 NL80211_FLAG_NEED_RTNL,
14498 },
14499 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014500 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014501 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014502 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014503 .flags = GENL_ADMIN_PERM,
14504 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14505 NL80211_FLAG_NEED_RTNL,
14506 },
14507 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014508 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014509 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014510 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014511 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014512 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14513 NL80211_FLAG_NEED_RTNL,
14514 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014515 {
14516 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014517 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014518 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020014519 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014520 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14521 NL80211_FLAG_NEED_RTNL,
14522 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014523 {
14524 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014525 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014526 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020014527 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14529 NL80211_FLAG_NEED_RTNL,
14530 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014531 {
14532 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014533 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014534 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014535 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014536 {
14537 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014538 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020014539 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020014540 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14542 NL80211_FLAG_NEED_RTNL,
14543 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014544 {
14545 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014546 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014547 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020014548 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014549 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14550 NL80211_FLAG_NEED_RTNL,
14551 },
14552 {
14553 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014554 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014555 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020014556 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014557 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14558 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014559 },
14560 {
14561 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014562 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014563 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014564 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14565 NL80211_FLAG_NEED_RTNL,
14566 },
14567 {
14568 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014569 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014570 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020014571 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014572 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14573 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014574 },
14575 {
14576 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014577 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014578 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014579 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014580 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14581 NL80211_FLAG_NEED_RTNL,
14582 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014583 {
14584 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014585 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010014586 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014587 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014589 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014590 NL80211_FLAG_NEED_RTNL |
14591 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010014592 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014593 {
14594 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014595 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014596 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014597 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14599 NL80211_FLAG_NEED_RTNL,
14600 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014601 {
14602 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014603 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014604 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014605 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14607 NL80211_FLAG_NEED_RTNL,
14608 },
14609 {
14610 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014612 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014613 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14615 NL80211_FLAG_NEED_RTNL,
14616 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014617 {
14618 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014619 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014620 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014621 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14623 NL80211_FLAG_NEED_RTNL,
14624 },
14625 {
14626 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014627 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014628 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014629 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14631 NL80211_FLAG_NEED_RTNL,
14632 },
Michael Braunce0ce132016-10-10 19:12:22 +020014633 {
14634 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020014635 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020014636 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020014637 .flags = GENL_UNS_ADMIN_PERM,
14638 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14639 NL80211_FLAG_NEED_RTNL,
14640 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014641 {
14642 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014643 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014644 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014645 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014646 NL80211_FLAG_NEED_RTNL |
14647 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010014648 },
14649 {
14650 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014651 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014652 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14654 NL80211_FLAG_NEED_RTNL,
14655 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014656 {
14657 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014658 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014659 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014660 .flags = GENL_ADMIN_PERM,
14661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14662 NL80211_FLAG_NEED_RTNL,
14663 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014664 {
14665 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014666 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014667 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014668 .flags = GENL_UNS_ADMIN_PERM,
14669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14670 NL80211_FLAG_NEED_RTNL,
14671 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014672 {
14673 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014674 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014675 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014676 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14677 NL80211_FLAG_NEED_RTNL,
14678 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014679 {
14680 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014681 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014682 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014683 .flags = GENL_UNS_ADMIN_PERM,
14684 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14685 NL80211_FLAG_NEED_RTNL,
14686 },
Sriram R30c63112018-12-04 17:46:52 +053014687 {
14688 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014689 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053014690 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053014691 .flags = GENL_UNS_ADMIN_PERM,
14692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14693 NL80211_FLAG_NEED_RTNL,
14694 },
Sunil Duttcb74e972019-02-20 16:18:07 +053014695 {
14696 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14697 .doit = nl80211_update_owe_info,
14698 .flags = GENL_ADMIN_PERM,
14699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14700 NL80211_FLAG_NEED_RTNL,
14701 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014702 {
14703 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14704 .doit = nl80211_probe_mesh_link,
14705 .flags = GENL_UNS_ADMIN_PERM,
14706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14707 NL80211_FLAG_NEED_RTNL,
14708 },
Johannes Berg55682962007-09-20 13:09:35 -040014709};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014710
Johannes Berg56989f62016-10-24 14:40:05 +020014711static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014712 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14713 .hdrsize = 0, /* no private header */
14714 .version = 1, /* no particular meaning now */
14715 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010014716 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020014717 .netnsok = true,
14718 .pre_doit = nl80211_pre_doit,
14719 .post_doit = nl80211_post_doit,
14720 .module = THIS_MODULE,
14721 .ops = nl80211_ops,
14722 .n_ops = ARRAY_SIZE(nl80211_ops),
14723 .mcgrps = nl80211_mcgrps,
14724 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
Johannes Berg50508d92019-07-29 16:31:09 +020014725 .parallel_ops = true,
Johannes Berg489111e2016-10-24 14:40:03 +020014726};
14727
Johannes Berg55682962007-09-20 13:09:35 -040014728/* notification functions */
14729
Johannes Berg3bb20552014-05-26 13:52:25 +020014730void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14731 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014732{
14733 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014734 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014735
Johannes Berg3bb20552014-05-26 13:52:25 +020014736 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14737 cmd != NL80211_CMD_DEL_WIPHY);
14738
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014740 if (!msg)
14741 return;
14742
Johannes Berg3bb20552014-05-26 13:52:25 +020014743 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014744 nlmsg_free(msg);
14745 return;
14746 }
14747
Johannes Berg68eb5502013-11-19 15:19:38 +010014748 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014749 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014750}
14751
Denis Kenzior896ff062016-08-03 16:58:33 -050014752void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14753 struct wireless_dev *wdev,
14754 enum nl80211_commands cmd)
14755{
14756 struct sk_buff *msg;
14757
Denis Kenzior896ff062016-08-03 16:58:33 -050014758 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14759 if (!msg)
14760 return;
14761
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014762 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014763 nlmsg_free(msg);
14764 return;
14765 }
14766
14767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14768 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14769}
14770
Johannes Berg362a4152009-05-24 16:43:15 +020014771static int nl80211_add_scan_req(struct sk_buff *msg,
14772 struct cfg80211_registered_device *rdev)
14773{
14774 struct cfg80211_scan_request *req = rdev->scan_req;
14775 struct nlattr *nest;
14776 int i;
14777
14778 if (WARN_ON(!req))
14779 return 0;
14780
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014781 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020014782 if (!nest)
14783 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014784 for (i = 0; i < req->n_ssids; i++) {
14785 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14786 goto nla_put_failure;
14787 }
Johannes Berg362a4152009-05-24 16:43:15 +020014788 nla_nest_end(msg, nest);
14789
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014790 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Johannes Berg362a4152009-05-24 16:43:15 +020014791 if (!nest)
14792 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014793 for (i = 0; i < req->n_channels; i++) {
14794 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14795 goto nla_put_failure;
14796 }
Johannes Berg362a4152009-05-24 16:43:15 +020014797 nla_nest_end(msg, nest);
14798
David S. Miller9360ffd2012-03-29 04:41:26 -040014799 if (req->ie &&
14800 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14801 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014802
Johannes Bergae917c92013-10-25 11:05:22 +020014803 if (req->flags &&
14804 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14805 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014806
Avraham Stern1d762502016-07-05 17:10:13 +030014807 if (req->info.scan_start_tsf &&
14808 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14809 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14810 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14811 req->info.tsf_bssid)))
14812 goto nla_put_failure;
14813
Johannes Berg362a4152009-05-24 16:43:15 +020014814 return 0;
14815 nla_put_failure:
14816 return -ENOBUFS;
14817}
14818
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014819static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014820 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014821 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014822 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014823 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014824{
14825 void *hdr;
14826
Eric W. Biederman15e47302012-09-07 20:12:54 +000014827 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014828 if (!hdr)
14829 return -1;
14830
David S. Miller9360ffd2012-03-29 04:41:26 -040014831 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014832 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14833 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014834 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14835 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014836 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014837
Johannes Berg362a4152009-05-24 16:43:15 +020014838 /* ignore errors and send incomplete event anyway */
14839 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014840
Johannes Berg053c0952015-01-16 22:09:00 +010014841 genlmsg_end(msg, hdr);
14842 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014843
14844 nla_put_failure:
14845 genlmsg_cancel(msg, hdr);
14846 return -EMSGSIZE;
14847}
14848
Luciano Coelho807f8a82011-05-11 17:09:35 +030014849static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014850nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014851 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014852{
14853 void *hdr;
14854
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014855 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014856 if (!hdr)
14857 return -1;
14858
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14860 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14862 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14863 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014864 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014865
Johannes Berg053c0952015-01-16 22:09:00 +010014866 genlmsg_end(msg, hdr);
14867 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014868
14869 nla_put_failure:
14870 genlmsg_cancel(msg, hdr);
14871 return -EMSGSIZE;
14872}
14873
Johannes Berga538e2d2009-06-16 19:56:42 +020014874void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014875 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014876{
14877 struct sk_buff *msg;
14878
Thomas Graf58050fc2012-06-28 03:57:45 +000014879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014880 if (!msg)
14881 return;
14882
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014883 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014884 NL80211_CMD_TRIGGER_SCAN) < 0) {
14885 nlmsg_free(msg);
14886 return;
14887 }
14888
Johannes Berg68eb5502013-11-19 15:19:38 +010014889 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014890 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014891}
14892
Johannes Bergf9d15d12014-01-22 11:14:19 +020014893struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14894 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014895{
14896 struct sk_buff *msg;
14897
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014899 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014900 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014901
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014902 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014903 aborted ? NL80211_CMD_SCAN_ABORTED :
14904 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014905 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014906 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014907 }
14908
Johannes Bergf9d15d12014-01-22 11:14:19 +020014909 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014910}
14911
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014912/* send message created by nl80211_build_scan_msg() */
14913void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14914 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014915{
Johannes Berg2a519312009-02-10 21:25:55 +010014916 if (!msg)
14917 return;
14918
Johannes Berg68eb5502013-11-19 15:19:38 +010014919 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014920 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014921}
14922
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014923void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014924{
14925 struct sk_buff *msg;
14926
Thomas Graf58050fc2012-06-28 03:57:45 +000014927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014928 if (!msg)
14929 return;
14930
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014931 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014932 nlmsg_free(msg);
14933 return;
14934 }
14935
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014937 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014938}
14939
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014940static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14941 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014942{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014943 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014944 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14945 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014946
David S. Miller9360ffd2012-03-29 04:41:26 -040014947 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14948 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14949 NL80211_REGDOM_TYPE_WORLD))
14950 goto nla_put_failure;
14951 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14952 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14953 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14954 goto nla_put_failure;
14955 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14956 request->intersect) {
14957 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14958 NL80211_REGDOM_TYPE_INTERSECTION))
14959 goto nla_put_failure;
14960 } else {
14961 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14962 NL80211_REGDOM_TYPE_COUNTRY) ||
14963 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14964 request->alpha2))
14965 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014966 }
14967
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014968 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14969 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14970
14971 if (wiphy &&
14972 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14973 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014974
14975 if (wiphy &&
14976 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14977 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14978 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014979 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014980
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014981 return true;
14982
14983nla_put_failure:
14984 return false;
14985}
14986
14987/*
14988 * This can happen on global regulatory changes or device specific settings
14989 * based on custom regulatory domains.
14990 */
14991void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14992 struct regulatory_request *request)
14993{
14994 struct sk_buff *msg;
14995 void *hdr;
14996
14997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14998 if (!msg)
14999 return;
15000
15001 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
zhong jiang24f6d762019-09-05 12:25:37 +080015002 if (!hdr)
15003 goto nla_put_failure;
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015004
zhong jiang24f6d762019-09-05 12:25:37 +080015005 if (!nl80211_reg_change_event_fill(msg, request))
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015006 goto nla_put_failure;
15007
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015008 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015009
Johannes Bergbc43b282009-07-25 10:54:13 +020015010 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015011 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015012 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020015013 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015014
15015 return;
15016
15017nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015018 nlmsg_free(msg);
15019}
15020
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015021static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15022 struct net_device *netdev,
15023 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015024 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015025 int uapsd_queues, const u8 *req_ies,
15026 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015027{
15028 struct sk_buff *msg;
15029 void *hdr;
15030
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015031 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015032 if (!msg)
15033 return;
15034
15035 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15036 if (!hdr) {
15037 nlmsg_free(msg);
15038 return;
15039 }
15040
David S. Miller9360ffd2012-03-29 04:41:26 -040015041 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15042 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015043 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15044 (req_ies &&
15045 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015046 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015047
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015048 if (uapsd_queues >= 0) {
15049 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015050 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015051 if (!nla_wmm)
15052 goto nla_put_failure;
15053
15054 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15055 uapsd_queues))
15056 goto nla_put_failure;
15057
15058 nla_nest_end(msg, nla_wmm);
15059 }
15060
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015061 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015062
Johannes Berg68eb5502013-11-19 15:19:38 +010015063 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015064 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015065 return;
15066
15067 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015068 nlmsg_free(msg);
15069}
15070
15071void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015072 struct net_device *netdev, const u8 *buf,
15073 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015074{
15075 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015076 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015077}
15078
15079void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15080 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015081 size_t len, gfp_t gfp, int uapsd_queues,
15082 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015083{
Johannes Berge6d6e342009-07-01 21:26:47 +020015084 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015085 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15086 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015087}
15088
Jouni Malinen53b46b82009-03-27 20:53:56 +020015089void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015090 struct net_device *netdev, const u8 *buf,
15091 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015092{
15093 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015094 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015095}
15096
Jouni Malinen53b46b82009-03-27 20:53:56 +020015097void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15098 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020015099 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015100{
15101 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015102 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015103}
15104
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015105void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15106 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020015107{
Johannes Berg947add32013-02-22 22:05:20 +010015108 struct wireless_dev *wdev = dev->ieee80211_ptr;
15109 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015110 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015111 const struct ieee80211_mgmt *mgmt = (void *)buf;
15112 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020015113
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015114 if (WARN_ON(len < 2))
15115 return;
15116
15117 if (ieee80211_is_deauth(mgmt->frame_control))
15118 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15119 else
15120 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15121
15122 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015123 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15124 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015125}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015126EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015127
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040015128static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15129 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020015130 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015131{
15132 struct sk_buff *msg;
15133 void *hdr;
15134
Johannes Berge6d6e342009-07-01 21:26:47 +020015135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015136 if (!msg)
15137 return;
15138
15139 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15140 if (!hdr) {
15141 nlmsg_free(msg);
15142 return;
15143 }
15144
David S. Miller9360ffd2012-03-29 04:41:26 -040015145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15146 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15147 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15148 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15149 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030015150
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015151 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030015152
Johannes Berg68eb5502013-11-19 15:19:38 +010015153 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015154 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015155 return;
15156
15157 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030015158 nlmsg_free(msg);
15159}
15160
15161void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015162 struct net_device *netdev, const u8 *addr,
15163 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015164{
15165 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020015166 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015167}
15168
15169void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015170 struct net_device *netdev, const u8 *addr,
15171 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015172{
Johannes Berge6d6e342009-07-01 21:26:47 +020015173 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15174 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015175}
15176
Samuel Ortizb23aa672009-07-01 21:26:54 +020015177void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015178 struct net_device *netdev,
15179 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015180 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015181{
15182 struct sk_buff *msg;
15183 void *hdr;
15184
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015185 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020015186 cr->fils.kek_len + cr->fils.pmk_len +
15187 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015188 if (!msg)
15189 return;
15190
15191 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15192 if (!hdr) {
15193 nlmsg_free(msg);
15194 return;
15195 }
15196
David S. Miller9360ffd2012-03-29 04:41:26 -040015197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015199 (cr->bssid &&
15200 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030015201 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015202 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15203 cr->status) ||
15204 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015205 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015206 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15207 cr->timeout_reason))) ||
15208 (cr->req_ie &&
15209 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15210 (cr->resp_ie &&
15211 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015212 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020015213 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015214 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020015215 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015216 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020015217 ((cr->fils.kek &&
15218 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15219 cr->fils.kek)) ||
15220 (cr->fils.pmk &&
15221 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15222 (cr->fils.pmkid &&
15223 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040015224 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015225
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015226 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015227
Johannes Berg68eb5502013-11-19 15:19:38 +010015228 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015229 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015230 return;
15231
15232 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015233 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015234}
15235
15236void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015237 struct net_device *netdev,
15238 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015239{
15240 struct sk_buff *msg;
15241 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015242 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015243
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015244 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15245 info->fils.kek_len + info->fils.pmk_len +
15246 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015247 if (!msg)
15248 return;
15249
15250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15251 if (!hdr) {
15252 nlmsg_free(msg);
15253 return;
15254 }
15255
David S. Miller9360ffd2012-03-29 04:41:26 -040015256 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15257 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15258 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015259 (info->req_ie &&
15260 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15261 info->req_ie)) ||
15262 (info->resp_ie &&
15263 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015264 info->resp_ie)) ||
15265 (info->fils.update_erp_next_seq_num &&
15266 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15267 info->fils.erp_next_seq_num)) ||
15268 (info->fils.kek &&
15269 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15270 info->fils.kek)) ||
15271 (info->fils.pmk &&
15272 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15273 (info->fils.pmkid &&
15274 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015275 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015276
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015277 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015278
Johannes Berg68eb5502013-11-19 15:19:38 +010015279 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015280 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015281 return;
15282
15283 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015284 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015285}
15286
Avraham Stern503c1fb2017-09-29 14:21:49 +020015287void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15288 struct net_device *netdev, const u8 *bssid)
15289{
15290 struct sk_buff *msg;
15291 void *hdr;
15292
15293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15294 if (!msg)
15295 return;
15296
15297 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15298 if (!hdr) {
15299 nlmsg_free(msg);
15300 return;
15301 }
15302
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000015303 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15304 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15305 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020015306 goto nla_put_failure;
15307
15308 genlmsg_end(msg, hdr);
15309
15310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15311 NL80211_MCGRP_MLME, GFP_KERNEL);
15312 return;
15313
15314 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020015315 nlmsg_free(msg);
15316}
15317
Samuel Ortizb23aa672009-07-01 21:26:54 +020015318void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15319 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020015320 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015321{
15322 struct sk_buff *msg;
15323 void *hdr;
15324
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015325 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015326 if (!msg)
15327 return;
15328
15329 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15330 if (!hdr) {
15331 nlmsg_free(msg);
15332 return;
15333 }
15334
David S. Miller9360ffd2012-03-29 04:41:26 -040015335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15336 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020015337 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040015338 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15339 (from_ap &&
15340 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15341 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15342 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015343
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015344 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015345
Johannes Berg68eb5502013-11-19 15:19:38 +010015346 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015347 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015348 return;
15349
15350 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015351 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015352}
15353
Johannes Berg04a773a2009-04-19 21:24:32 +020015354void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15355 struct net_device *netdev, const u8 *bssid,
15356 gfp_t gfp)
15357{
15358 struct sk_buff *msg;
15359 void *hdr;
15360
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015361 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015362 if (!msg)
15363 return;
15364
15365 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15366 if (!hdr) {
15367 nlmsg_free(msg);
15368 return;
15369 }
15370
David S. Miller9360ffd2012-03-29 04:41:26 -040015371 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15372 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15373 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15374 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020015375
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015376 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020015377
Johannes Berg68eb5502013-11-19 15:19:38 +010015378 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015379 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015380 return;
15381
15382 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020015383 nlmsg_free(msg);
15384}
15385
Johannes Berg947add32013-02-22 22:05:20 +010015386void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040015387 const u8 *ie, u8 ie_len,
15388 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070015389{
Johannes Berg947add32013-02-22 22:05:20 +010015390 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015391 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015392 struct sk_buff *msg;
15393 void *hdr;
15394
Johannes Berg947add32013-02-22 22:05:20 +010015395 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15396 return;
15397
15398 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15399
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015400 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015401 if (!msg)
15402 return;
15403
15404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15405 if (!hdr) {
15406 nlmsg_free(msg);
15407 return;
15408 }
15409
David S. Miller9360ffd2012-03-29 04:41:26 -040015410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015411 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15412 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015413 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040015414 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15415 (sig_dbm &&
15416 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015417 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070015418
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015419 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015420
Johannes Berg68eb5502013-11-19 15:19:38 +010015421 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015422 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015423 return;
15424
15425 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070015426 nlmsg_free(msg);
15427}
Johannes Berg947add32013-02-22 22:05:20 +010015428EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015429
Jouni Malinena3b8b052009-03-27 21:59:49 +020015430void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15431 struct net_device *netdev, const u8 *addr,
15432 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020015433 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020015434{
15435 struct sk_buff *msg;
15436 void *hdr;
15437
Johannes Berge6d6e342009-07-01 21:26:47 +020015438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015439 if (!msg)
15440 return;
15441
15442 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15443 if (!hdr) {
15444 nlmsg_free(msg);
15445 return;
15446 }
15447
David S. Miller9360ffd2012-03-29 04:41:26 -040015448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15449 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15450 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15451 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15452 (key_id != -1 &&
15453 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15454 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15455 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020015456
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015457 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015458
Johannes Berg68eb5502013-11-19 15:19:38 +010015459 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015460 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015461 return;
15462
15463 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020015464 nlmsg_free(msg);
15465}
15466
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015467void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15468 struct ieee80211_channel *channel_before,
15469 struct ieee80211_channel *channel_after)
15470{
15471 struct sk_buff *msg;
15472 void *hdr;
15473 struct nlattr *nl_freq;
15474
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015476 if (!msg)
15477 return;
15478
15479 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15480 if (!hdr) {
15481 nlmsg_free(msg);
15482 return;
15483 }
15484
15485 /*
15486 * Since we are applying the beacon hint to a wiphy we know its
15487 * wiphy_idx is valid
15488 */
David S. Miller9360ffd2012-03-29 04:41:26 -040015489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15490 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015491
15492 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015493 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015494 if (!nl_freq)
15495 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015496
15497 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015498 goto nla_put_failure;
15499 nla_nest_end(msg, nl_freq);
15500
15501 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015502 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015503 if (!nl_freq)
15504 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015505
15506 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015507 goto nla_put_failure;
15508 nla_nest_end(msg, nl_freq);
15509
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015510 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015511
Johannes Berg463d0182009-07-14 00:33:35 +020015512 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015513 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015514 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020015515 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015516
15517 return;
15518
15519nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015520 nlmsg_free(msg);
15521}
15522
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015523static void nl80211_send_remain_on_chan_event(
15524 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015525 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015526 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015527 unsigned int duration, gfp_t gfp)
15528{
15529 struct sk_buff *msg;
15530 void *hdr;
15531
15532 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15533 if (!msg)
15534 return;
15535
15536 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15537 if (!hdr) {
15538 nlmsg_free(msg);
15539 return;
15540 }
15541
David S. Miller9360ffd2012-03-29 04:41:26 -040015542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015543 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15544 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015545 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15546 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015547 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015548 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15549 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015550 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15551 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015552 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015553
David S. Miller9360ffd2012-03-29 04:41:26 -040015554 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15555 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15556 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015557
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015558 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015559
Johannes Berg68eb5502013-11-19 15:19:38 +010015560 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015561 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015562 return;
15563
15564 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015565 nlmsg_free(msg);
15566}
15567
Johannes Berg947add32013-02-22 22:05:20 +010015568void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15569 struct ieee80211_channel *chan,
15570 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015571{
Johannes Berg947add32013-02-22 22:05:20 +010015572 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015573 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015574
15575 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015576 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015577 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015578 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015579}
Johannes Berg947add32013-02-22 22:05:20 +010015580EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015581
Johannes Berg947add32013-02-22 22:05:20 +010015582void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15583 struct ieee80211_channel *chan,
15584 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015585{
Johannes Berg947add32013-02-22 22:05:20 +010015586 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015587 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015588
15589 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015590 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015591 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015592}
Johannes Berg947add32013-02-22 22:05:20 +010015593EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015594
James Prestwood1c38c7f2019-06-12 12:35:09 -070015595void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
15596 struct ieee80211_channel *chan,
15597 gfp_t gfp)
15598{
15599 struct wiphy *wiphy = wdev->wiphy;
15600 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15601
15602 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
15603 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
15604 rdev, wdev, cookie, chan, 0, gfp);
15605}
15606EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
15607
Johannes Berg947add32013-02-22 22:05:20 +010015608void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15609 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015610{
Johannes Berg947add32013-02-22 22:05:20 +010015611 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015612 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015613 struct sk_buff *msg;
15614
Johannes Berg947add32013-02-22 22:05:20 +010015615 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15616
Thomas Graf58050fc2012-06-28 03:57:45 +000015617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015618 if (!msg)
15619 return;
15620
Johannes Bergcf5ead82014-11-14 17:14:00 +010015621 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015622 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015623 nlmsg_free(msg);
15624 return;
15625 }
15626
Johannes Berg68eb5502013-11-19 15:19:38 +010015627 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015628 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015629}
Johannes Berg947add32013-02-22 22:05:20 +010015630EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015631
Johannes Bergcf5ead82014-11-14 17:14:00 +010015632void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15633 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015634{
Johannes Berg947add32013-02-22 22:05:20 +010015635 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015636 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015637 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015638 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015639
Johannes Berg73887fd2018-05-18 09:57:55 +020015640 if (!sinfo)
15641 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015642
Johannes Berg947add32013-02-22 22:05:20 +010015643 trace_cfg80211_del_sta(dev, mac_addr);
15644
Thomas Graf58050fc2012-06-28 03:57:45 +000015645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015646 if (!msg) {
15647 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015648 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015649 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015650
Johannes Bergcf5ead82014-11-14 17:14:00 +010015651 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015652 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015653 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015654 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015655 }
15656
Johannes Berg68eb5502013-11-19 15:19:38 +010015657 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015658 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015659}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015660EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015661
Johannes Berg947add32013-02-22 22:05:20 +010015662void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15663 enum nl80211_connect_failed_reason reason,
15664 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015665{
Johannes Berg947add32013-02-22 22:05:20 +010015666 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015667 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015668 struct sk_buff *msg;
15669 void *hdr;
15670
15671 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15672 if (!msg)
15673 return;
15674
15675 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15676 if (!hdr) {
15677 nlmsg_free(msg);
15678 return;
15679 }
15680
15681 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15682 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15683 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15684 goto nla_put_failure;
15685
15686 genlmsg_end(msg, hdr);
15687
Johannes Berg68eb5502013-11-19 15:19:38 +010015688 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015689 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015690 return;
15691
15692 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015693 nlmsg_free(msg);
15694}
Johannes Berg947add32013-02-22 22:05:20 +010015695EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015696
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015697static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15698 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015699{
15700 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015701 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015702 struct sk_buff *msg;
15703 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015704 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015705
Eric W. Biederman15e47302012-09-07 20:12:54 +000015706 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015707 return false;
15708
15709 msg = nlmsg_new(100, gfp);
15710 if (!msg)
15711 return true;
15712
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015713 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015714 if (!hdr) {
15715 nlmsg_free(msg);
15716 return true;
15717 }
15718
David S. Miller9360ffd2012-03-29 04:41:26 -040015719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15720 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15721 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15722 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015723
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015724 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015725 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015726 return true;
15727
15728 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015729 nlmsg_free(msg);
15730 return true;
15731}
15732
Johannes Berg947add32013-02-22 22:05:20 +010015733bool cfg80211_rx_spurious_frame(struct net_device *dev,
15734 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015735{
Johannes Berg947add32013-02-22 22:05:20 +010015736 struct wireless_dev *wdev = dev->ieee80211_ptr;
15737 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015738
Johannes Berg947add32013-02-22 22:05:20 +010015739 trace_cfg80211_rx_spurious_frame(dev, addr);
15740
15741 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15742 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15743 trace_cfg80211_return_bool(false);
15744 return false;
15745 }
15746 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15747 addr, gfp);
15748 trace_cfg80211_return_bool(ret);
15749 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015750}
Johannes Berg947add32013-02-22 22:05:20 +010015751EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15752
15753bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15754 const u8 *addr, gfp_t gfp)
15755{
15756 struct wireless_dev *wdev = dev->ieee80211_ptr;
15757 bool ret;
15758
15759 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15760
15761 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15762 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15763 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15764 trace_cfg80211_return_bool(false);
15765 return false;
15766 }
15767 ret = __nl80211_unexpected_frame(dev,
15768 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15769 addr, gfp);
15770 trace_cfg80211_return_bool(ret);
15771 return ret;
15772}
15773EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015774
Johannes Berg2e161f782010-08-12 15:38:38 +020015775int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015776 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015777 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015778 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015779{
Johannes Berg71bbc992012-06-15 15:30:18 +020015780 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015781 struct sk_buff *msg;
15782 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015783
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015784 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015785 if (!msg)
15786 return -ENOMEM;
15787
Johannes Berg2e161f782010-08-12 15:38:38 +020015788 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015789 if (!hdr) {
15790 nlmsg_free(msg);
15791 return -ENOMEM;
15792 }
15793
David S. Miller9360ffd2012-03-29 04:41:26 -040015794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015795 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15796 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015797 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15798 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015799 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15800 (sig_dbm &&
15801 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015802 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15803 (flags &&
15804 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015805 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015806
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015807 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015808
Eric W. Biederman15e47302012-09-07 20:12:54 +000015809 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015810
15811 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015812 nlmsg_free(msg);
15813 return -ENOBUFS;
15814}
15815
Johannes Berg947add32013-02-22 22:05:20 +010015816void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15817 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015818{
Johannes Berg947add32013-02-22 22:05:20 +010015819 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015820 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015821 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015822 struct sk_buff *msg;
15823 void *hdr;
15824
Johannes Berg947add32013-02-22 22:05:20 +010015825 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15826
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015827 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015828 if (!msg)
15829 return;
15830
Johannes Berg2e161f782010-08-12 15:38:38 +020015831 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015832 if (!hdr) {
15833 nlmsg_free(msg);
15834 return;
15835 }
15836
David S. Miller9360ffd2012-03-29 04:41:26 -040015837 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015838 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15839 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015840 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15841 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015842 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015843 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15844 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015845 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15846 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015847
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015848 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015849
Johannes Berg68eb5502013-11-19 15:19:38 +010015850 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015851 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015852 return;
15853
15854 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015855 nlmsg_free(msg);
15856}
Johannes Berg947add32013-02-22 22:05:20 +010015857EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015858
Denis Kenzior6a671a52018-03-26 12:52:41 -050015859static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015860 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015861 bool unencrypted, gfp_t gfp)
15862{
15863 struct wireless_dev *wdev = dev->ieee80211_ptr;
15864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015865 struct ethhdr *ehdr = eth_hdr(skb);
15866 const u8 *addr = ehdr->h_source;
15867 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015868 struct sk_buff *msg;
15869 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015870 struct nlattr *frame;
15871
Denis Kenzior6a671a52018-03-26 12:52:41 -050015872 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15873
15874 if (!nlportid)
15875 return -ENOENT;
15876
Denis Kenziora948f712018-07-03 15:05:48 -050015877 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015878 if (!msg)
15879 return -ENOMEM;
15880
15881 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15882 if (!hdr) {
15883 nlmsg_free(msg);
15884 return -ENOBUFS;
15885 }
15886
15887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15888 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15889 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15890 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015891 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15892 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15893 (unencrypted && nla_put_flag(msg,
15894 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15895 goto nla_put_failure;
15896
Denis Kenziora948f712018-07-03 15:05:48 -050015897 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15898 if (!frame)
15899 goto nla_put_failure;
15900
15901 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015902 genlmsg_end(msg, hdr);
15903
15904 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15905
15906 nla_put_failure:
15907 nlmsg_free(msg);
15908 return -ENOBUFS;
15909}
15910
15911bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015912 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015913{
15914 int ret;
15915
Denis Kenziora948f712018-07-03 15:05:48 -050015916 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15917 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015918 trace_cfg80211_return_bool(ret == 0);
15919 return ret == 0;
15920}
15921EXPORT_SYMBOL(cfg80211_rx_control_port);
15922
Johannes Berg5b97f492014-11-26 12:37:43 +010015923static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15924 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015925{
Johannes Berg947add32013-02-22 22:05:20 +010015926 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015927 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15928 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15929 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015930
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015931 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015932 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015933
Johannes Berg5b97f492014-11-26 12:37:43 +010015934 cb = (void **)msg->cb;
15935
15936 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15937 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015938 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015939 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015940 }
15941
David S. Miller9360ffd2012-03-29 04:41:26 -040015942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015944 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015945
Johannes Berg5b97f492014-11-26 12:37:43 +010015946 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015947 goto nla_put_failure;
15948
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015949 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010015950 if (!cb[1])
15951 goto nla_put_failure;
15952
15953 cb[2] = rdev;
15954
15955 return msg;
15956 nla_put_failure:
15957 nlmsg_free(msg);
15958 return NULL;
15959}
15960
15961static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15962{
15963 void **cb = (void **)msg->cb;
15964 struct cfg80211_registered_device *rdev = cb[2];
15965
15966 nla_nest_end(msg, cb[1]);
15967 genlmsg_end(msg, cb[0]);
15968
15969 memset(msg->cb, 0, sizeof(msg->cb));
15970
15971 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15972 NL80211_MCGRP_MLME, gfp);
15973}
15974
15975void cfg80211_cqm_rssi_notify(struct net_device *dev,
15976 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015977 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015978{
15979 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015980 struct wireless_dev *wdev = dev->ieee80211_ptr;
15981 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015982
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015983 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015984
Johannes Berg98f03342014-11-26 12:42:02 +010015985 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15986 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15987 return;
15988
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015989 if (wdev->cqm_config) {
15990 wdev->cqm_config->last_rssi_event_value = rssi_level;
15991
15992 cfg80211_cqm_rssi_update(rdev, dev);
15993
15994 if (rssi_level == 0)
15995 rssi_level = wdev->cqm_config->last_rssi_event_value;
15996 }
15997
Johannes Berg5b97f492014-11-26 12:37:43 +010015998 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15999 if (!msg)
16000 return;
16001
David S. Miller9360ffd2012-03-29 04:41:26 -040016002 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16003 rssi_event))
16004 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016005
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016006 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16007 rssi_level))
16008 goto nla_put_failure;
16009
Johannes Berg5b97f492014-11-26 12:37:43 +010016010 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016011
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016012 return;
16013
16014 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016015 nlmsg_free(msg);
16016}
Johannes Berg947add32013-02-22 22:05:20 +010016017EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016018
Johannes Berg5b97f492014-11-26 12:37:43 +010016019void cfg80211_cqm_txe_notify(struct net_device *dev,
16020 const u8 *peer, u32 num_packets,
16021 u32 rate, u32 intvl, gfp_t gfp)
16022{
16023 struct sk_buff *msg;
16024
16025 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16026 if (!msg)
16027 return;
16028
16029 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16030 goto nla_put_failure;
16031
16032 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16033 goto nla_put_failure;
16034
16035 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16036 goto nla_put_failure;
16037
16038 cfg80211_send_cqm(msg, gfp);
16039 return;
16040
16041 nla_put_failure:
16042 nlmsg_free(msg);
16043}
16044EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16045
16046void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16047 const u8 *peer, u32 num_packets, gfp_t gfp)
16048{
16049 struct sk_buff *msg;
16050
16051 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16052
16053 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16054 if (!msg)
16055 return;
16056
16057 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16058 goto nla_put_failure;
16059
16060 cfg80211_send_cqm(msg, gfp);
16061 return;
16062
16063 nla_put_failure:
16064 nlmsg_free(msg);
16065}
16066EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16067
Johannes Berg98f03342014-11-26 12:42:02 +010016068void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16069{
16070 struct sk_buff *msg;
16071
16072 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16073 if (!msg)
16074 return;
16075
16076 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16077 goto nla_put_failure;
16078
16079 cfg80211_send_cqm(msg, gfp);
16080 return;
16081
16082 nla_put_failure:
16083 nlmsg_free(msg);
16084}
16085EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16086
Johannes Berg947add32013-02-22 22:05:20 +010016087static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16088 struct net_device *netdev, const u8 *bssid,
16089 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020016090{
16091 struct sk_buff *msg;
16092 struct nlattr *rekey_attr;
16093 void *hdr;
16094
Thomas Graf58050fc2012-06-28 03:57:45 +000016095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016096 if (!msg)
16097 return;
16098
16099 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16100 if (!hdr) {
16101 nlmsg_free(msg);
16102 return;
16103 }
16104
David S. Miller9360ffd2012-03-29 04:41:26 -040016105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16106 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16107 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16108 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016109
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016110 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020016111 if (!rekey_attr)
16112 goto nla_put_failure;
16113
David S. Miller9360ffd2012-03-29 04:41:26 -040016114 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16115 NL80211_REPLAY_CTR_LEN, replay_ctr))
16116 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016117
16118 nla_nest_end(msg, rekey_attr);
16119
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016120 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020016121
Johannes Berg68eb5502013-11-19 15:19:38 +010016122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016123 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016124 return;
16125
16126 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020016127 nlmsg_free(msg);
16128}
16129
Johannes Berg947add32013-02-22 22:05:20 +010016130void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16131 const u8 *replay_ctr, gfp_t gfp)
16132{
16133 struct wireless_dev *wdev = dev->ieee80211_ptr;
16134 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016135 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016136
16137 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16138 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16139}
16140EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16141
16142static void
16143nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16144 struct net_device *netdev, int index,
16145 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016146{
16147 struct sk_buff *msg;
16148 struct nlattr *attr;
16149 void *hdr;
16150
Thomas Graf58050fc2012-06-28 03:57:45 +000016151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016152 if (!msg)
16153 return;
16154
16155 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16156 if (!hdr) {
16157 nlmsg_free(msg);
16158 return;
16159 }
16160
David S. Miller9360ffd2012-03-29 04:41:26 -040016161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16163 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016164
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016165 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016166 if (!attr)
16167 goto nla_put_failure;
16168
David S. Miller9360ffd2012-03-29 04:41:26 -040016169 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16170 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16171 (preauth &&
16172 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16173 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016174
16175 nla_nest_end(msg, attr);
16176
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016177 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016178
Johannes Berg68eb5502013-11-19 15:19:38 +010016179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016180 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016181 return;
16182
16183 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016184 nlmsg_free(msg);
16185}
16186
Johannes Berg947add32013-02-22 22:05:20 +010016187void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16188 const u8 *bssid, bool preauth, gfp_t gfp)
16189{
16190 struct wireless_dev *wdev = dev->ieee80211_ptr;
16191 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016192 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016193
16194 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16195 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16196}
16197EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16198
16199static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16200 struct net_device *netdev,
16201 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020016202 gfp_t gfp,
16203 enum nl80211_commands notif,
16204 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070016205{
16206 struct sk_buff *msg;
16207 void *hdr;
16208
Thomas Graf58050fc2012-06-28 03:57:45 +000016209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016210 if (!msg)
16211 return;
16212
Luciano Coelhof8d75522014-11-07 14:31:35 +020016213 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070016214 if (!hdr) {
16215 nlmsg_free(msg);
16216 return;
16217 }
16218
Johannes Berg683b6d32012-11-08 21:25:48 +010016219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16220 goto nla_put_failure;
16221
16222 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040016223 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070016224
Luciano Coelhof8d75522014-11-07 14:31:35 +020016225 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16226 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16227 goto nla_put_failure;
16228
Thomas Pedersen53145262012-04-06 13:35:47 -070016229 genlmsg_end(msg, hdr);
16230
Johannes Berg68eb5502013-11-19 15:19:38 +010016231 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016232 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016233 return;
16234
16235 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070016236 nlmsg_free(msg);
16237}
16238
Johannes Berg947add32013-02-22 22:05:20 +010016239void cfg80211_ch_switch_notify(struct net_device *dev,
16240 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070016241{
Johannes Berg947add32013-02-22 22:05:20 +010016242 struct wireless_dev *wdev = dev->ieee80211_ptr;
16243 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016244 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016245
Simon Wunderliche487eae2013-11-21 18:19:51 +010016246 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016247
Simon Wunderliche487eae2013-11-21 18:19:51 +010016248 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016249
Michal Kazior9e0e2962014-01-29 14:22:27 +010016250 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016251 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016252
16253 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16254 !WARN_ON(!wdev->current_bss))
Sergey Matyukevich0afd4252019-07-26 16:39:34 +000016255 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016256
Michael Vassernisd34990b2019-07-29 06:01:16 +000016257 cfg80211_sched_dfs_chan_update(rdev);
16258
Luciano Coelhof8d75522014-11-07 14:31:35 +020016259 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16260 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010016261}
16262EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16263
Luciano Coelhof8d75522014-11-07 14:31:35 +020016264void cfg80211_ch_switch_started_notify(struct net_device *dev,
16265 struct cfg80211_chan_def *chandef,
16266 u8 count)
16267{
16268 struct wireless_dev *wdev = dev->ieee80211_ptr;
16269 struct wiphy *wiphy = wdev->wiphy;
16270 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16271
16272 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16273
16274 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16275 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16276}
16277EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16278
Thomas Pedersen84f10702012-07-12 16:17:33 -070016279void
Simon Wunderlich04f39042013-02-08 18:16:19 +010016280nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010016281 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010016282 enum nl80211_radar_event event,
16283 struct net_device *netdev, gfp_t gfp)
16284{
16285 struct sk_buff *msg;
16286 void *hdr;
16287
16288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16289 if (!msg)
16290 return;
16291
16292 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16293 if (!hdr) {
16294 nlmsg_free(msg);
16295 return;
16296 }
16297
16298 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16299 goto nla_put_failure;
16300
16301 /* NOP and radar events don't need a netdev parameter */
16302 if (netdev) {
16303 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16304
16305 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016306 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16307 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010016308 goto nla_put_failure;
16309 }
16310
16311 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16312 goto nla_put_failure;
16313
16314 if (nl80211_send_chandef(msg, chandef))
16315 goto nla_put_failure;
16316
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016317 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016318
Johannes Berg68eb5502013-11-19 15:19:38 +010016319 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016320 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016321 return;
16322
16323 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010016324 nlmsg_free(msg);
16325}
16326
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053016327void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16328 struct sta_opmode_info *sta_opmode,
16329 gfp_t gfp)
16330{
16331 struct sk_buff *msg;
16332 struct wireless_dev *wdev = dev->ieee80211_ptr;
16333 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16334 void *hdr;
16335
16336 if (WARN_ON(!mac))
16337 return;
16338
16339 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16340 if (!msg)
16341 return;
16342
16343 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16344 if (!hdr) {
16345 nlmsg_free(msg);
16346 return;
16347 }
16348
16349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16350 goto nla_put_failure;
16351
16352 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16353 goto nla_put_failure;
16354
16355 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16356 goto nla_put_failure;
16357
16358 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16359 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16360 goto nla_put_failure;
16361
16362 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16363 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16364 goto nla_put_failure;
16365
16366 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16367 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16368 goto nla_put_failure;
16369
16370 genlmsg_end(msg, hdr);
16371
16372 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16373 NL80211_MCGRP_MLME, gfp);
16374
16375 return;
16376
16377nla_put_failure:
16378 nlmsg_free(msg);
16379}
16380EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16381
Johannes Berg7f6cf312011-11-04 11:18:15 +010016382void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd32018-02-13 11:03:06 +053016383 u64 cookie, bool acked, s32 ack_signal,
16384 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010016385{
16386 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016387 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016388 struct sk_buff *msg;
16389 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016390
Beni Lev4ee3e062012-08-27 12:49:39 +030016391 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16392
Thomas Graf58050fc2012-06-28 03:57:45 +000016393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030016394
Johannes Berg7f6cf312011-11-04 11:18:15 +010016395 if (!msg)
16396 return;
16397
16398 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16399 if (!hdr) {
16400 nlmsg_free(msg);
16401 return;
16402 }
16403
David S. Miller9360ffd2012-03-29 04:41:26 -040016404 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16405 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16406 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016407 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16408 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd32018-02-13 11:03:06 +053016409 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16410 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16411 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016412 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016413
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016414 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016415
Johannes Berg68eb5502013-11-19 15:19:38 +010016416 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016417 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016418 return;
16419
16420 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010016421 nlmsg_free(msg);
16422}
16423EXPORT_SYMBOL(cfg80211_probe_status);
16424
Johannes Berg5e760232011-11-04 11:18:17 +010016425void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16426 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070016427 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010016428{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016429 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010016430 struct sk_buff *msg;
16431 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070016432 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010016433
Beni Lev4ee3e062012-08-27 12:49:39 +030016434 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16435
Ben Greear37c73b52012-10-26 14:49:25 -070016436 spin_lock_bh(&rdev->beacon_registrations_lock);
16437 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16438 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16439 if (!msg) {
16440 spin_unlock_bh(&rdev->beacon_registrations_lock);
16441 return;
16442 }
Johannes Berg5e760232011-11-04 11:18:17 +010016443
Ben Greear37c73b52012-10-26 14:49:25 -070016444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16445 if (!hdr)
16446 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010016447
Ben Greear37c73b52012-10-26 14:49:25 -070016448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16449 (freq &&
16450 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16451 (sig_dbm &&
16452 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16453 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16454 goto nla_put_failure;
16455
16456 genlmsg_end(msg, hdr);
16457
16458 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010016459 }
Ben Greear37c73b52012-10-26 14:49:25 -070016460 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016461 return;
16462
16463 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070016464 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016465 nlmsg_free(msg);
16466}
16467EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16468
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016469#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016470static int cfg80211_net_detect_results(struct sk_buff *msg,
16471 struct cfg80211_wowlan_wakeup *wakeup)
16472{
16473 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16474 struct nlattr *nl_results, *nl_match, *nl_freqs;
16475 int i, j;
16476
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016477 nl_results = nla_nest_start_noflag(msg,
16478 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016479 if (!nl_results)
16480 return -EMSGSIZE;
16481
16482 for (i = 0; i < nd->n_matches; i++) {
16483 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16484
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016485 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016486 if (!nl_match)
16487 break;
16488
16489 /* The SSID attribute is optional in nl80211, but for
16490 * simplicity reasons it's always present in the
16491 * cfg80211 structure. If a driver can't pass the
16492 * SSID, that needs to be changed. A zero length SSID
16493 * is still a valid SSID (wildcard), so it cannot be
16494 * used for this purpose.
16495 */
16496 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16497 match->ssid.ssid)) {
16498 nla_nest_cancel(msg, nl_match);
16499 goto out;
16500 }
16501
16502 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016503 nl_freqs = nla_nest_start_noflag(msg,
16504 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016505 if (!nl_freqs) {
16506 nla_nest_cancel(msg, nl_match);
16507 goto out;
16508 }
16509
16510 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020016511 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016512 nla_nest_cancel(msg, nl_freqs);
16513 nla_nest_cancel(msg, nl_match);
16514 goto out;
16515 }
16516 }
16517
16518 nla_nest_end(msg, nl_freqs);
16519 }
16520
16521 nla_nest_end(msg, nl_match);
16522 }
16523
16524out:
16525 nla_nest_end(msg, nl_results);
16526 return 0;
16527}
16528
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016529void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16530 struct cfg80211_wowlan_wakeup *wakeup,
16531 gfp_t gfp)
16532{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016533 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016534 struct sk_buff *msg;
16535 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016536 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016537
16538 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16539
16540 if (wakeup)
16541 size += wakeup->packet_present_len;
16542
16543 msg = nlmsg_new(size, gfp);
16544 if (!msg)
16545 return;
16546
16547 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16548 if (!hdr)
16549 goto free_msg;
16550
16551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016552 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16553 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016554 goto free_msg;
16555
16556 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16557 wdev->netdev->ifindex))
16558 goto free_msg;
16559
16560 if (wakeup) {
16561 struct nlattr *reasons;
16562
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016563 reasons = nla_nest_start_noflag(msg,
16564 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016565 if (!reasons)
16566 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016567
16568 if (wakeup->disconnect &&
16569 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16570 goto free_msg;
16571 if (wakeup->magic_pkt &&
16572 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16573 goto free_msg;
16574 if (wakeup->gtk_rekey_failure &&
16575 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16576 goto free_msg;
16577 if (wakeup->eap_identity_req &&
16578 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16579 goto free_msg;
16580 if (wakeup->four_way_handshake &&
16581 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16582 goto free_msg;
16583 if (wakeup->rfkill_release &&
16584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16585 goto free_msg;
16586
16587 if (wakeup->pattern_idx >= 0 &&
16588 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16589 wakeup->pattern_idx))
16590 goto free_msg;
16591
Johannes Bergae917c92013-10-25 11:05:22 +020016592 if (wakeup->tcp_match &&
16593 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16594 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016595
Johannes Bergae917c92013-10-25 11:05:22 +020016596 if (wakeup->tcp_connlost &&
16597 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16598 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016599
Johannes Bergae917c92013-10-25 11:05:22 +020016600 if (wakeup->tcp_nomoretokens &&
16601 nla_put_flag(msg,
16602 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16603 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016604
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016605 if (wakeup->packet) {
16606 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16607 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16608
16609 if (!wakeup->packet_80211) {
16610 pkt_attr =
16611 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16612 len_attr =
16613 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16614 }
16615
16616 if (wakeup->packet_len &&
16617 nla_put_u32(msg, len_attr, wakeup->packet_len))
16618 goto free_msg;
16619
16620 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16621 wakeup->packet))
16622 goto free_msg;
16623 }
16624
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016625 if (wakeup->net_detect &&
16626 cfg80211_net_detect_results(msg, wakeup))
16627 goto free_msg;
16628
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016629 nla_nest_end(msg, reasons);
16630 }
16631
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016632 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016633
Johannes Berg68eb5502013-11-19 15:19:38 +010016634 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016635 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016636 return;
16637
16638 free_msg:
16639 nlmsg_free(msg);
16640}
16641EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16642#endif
16643
Jouni Malinen3475b092012-11-16 22:49:57 +020016644void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16645 enum nl80211_tdls_operation oper,
16646 u16 reason_code, gfp_t gfp)
16647{
16648 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016649 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016650 struct sk_buff *msg;
16651 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016652
16653 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16654 reason_code);
16655
16656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16657 if (!msg)
16658 return;
16659
16660 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16661 if (!hdr) {
16662 nlmsg_free(msg);
16663 return;
16664 }
16665
16666 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16667 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16668 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16669 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16670 (reason_code > 0 &&
16671 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16672 goto nla_put_failure;
16673
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016674 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016675
Johannes Berg68eb5502013-11-19 15:19:38 +010016676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016677 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016678 return;
16679
16680 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016681 nlmsg_free(msg);
16682}
16683EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16684
Jouni Malinen026331c2010-02-15 12:53:10 +020016685static int nl80211_netlink_notify(struct notifier_block * nb,
16686 unsigned long state,
16687 void *_notify)
16688{
16689 struct netlink_notify *notify = _notify;
16690 struct cfg80211_registered_device *rdev;
16691 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016692 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016693
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016694 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016695 return NOTIFY_DONE;
16696
16697 rcu_read_lock();
16698
Johannes Berg5e760232011-11-04 11:18:17 +010016699 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016700 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016701
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016702 list_for_each_entry_rcu(sched_scan_req,
16703 &rdev->sched_scan_req_list,
16704 list) {
16705 if (sched_scan_req->owner_nlportid == notify->portid) {
16706 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacfd2017-01-05 10:57:14 +010016707 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016708 }
Johannes Berg753aacfd2017-01-05 10:57:14 +010016709 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016710
Johannes Berg53873f12016-05-03 16:52:04 +030016711 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016712 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016713
Johannes Bergab810072017-04-26 07:43:41 +020016714 if (wdev->owner_nlportid == notify->portid) {
16715 wdev->nl_owner_dead = true;
16716 schedule_work(&rdev->destroy_work);
16717 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016718 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016719 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016720
16721 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016722 }
16723
Ben Greear37c73b52012-10-26 14:49:25 -070016724 spin_lock_bh(&rdev->beacon_registrations_lock);
16725 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16726 list) {
16727 if (reg->nlportid == notify->portid) {
16728 list_del(&reg->list);
16729 kfree(reg);
16730 break;
16731 }
16732 }
16733 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016734 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016735
16736 rcu_read_unlock();
16737
Ilan peer05050752015-03-04 00:32:06 -050016738 /*
16739 * It is possible that the user space process that is controlling the
16740 * indoor setting disappeared, so notify the regulatory core.
16741 */
16742 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016743 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016744}
16745
16746static struct notifier_block nl80211_netlink_notifier = {
16747 .notifier_call = nl80211_netlink_notify,
16748};
16749
Jouni Malinen355199e2013-02-27 17:14:27 +020016750void cfg80211_ft_event(struct net_device *netdev,
16751 struct cfg80211_ft_event_params *ft_event)
16752{
16753 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016754 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016755 struct sk_buff *msg;
16756 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016757
16758 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16759
16760 if (!ft_event->target_ap)
16761 return;
16762
Dedy Lansky1039d082018-05-17 16:25:03 +030016763 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16764 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016765 if (!msg)
16766 return;
16767
16768 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016769 if (!hdr)
16770 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016771
Johannes Bergae917c92013-10-25 11:05:22 +020016772 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16773 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16774 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16775 goto out;
16776
16777 if (ft_event->ies &&
16778 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16779 goto out;
16780 if (ft_event->ric_ies &&
16781 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16782 ft_event->ric_ies))
16783 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016784
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016785 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016786
Johannes Berg68eb5502013-11-19 15:19:38 +010016787 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016788 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016789 return;
16790 out:
16791 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016792}
16793EXPORT_SYMBOL(cfg80211_ft_event);
16794
Arend van Spriel5de17982013-04-18 15:49:00 +020016795void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16796{
16797 struct cfg80211_registered_device *rdev;
16798 struct sk_buff *msg;
16799 void *hdr;
16800 u32 nlportid;
16801
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016802 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016803 if (!rdev->crit_proto_nlportid)
16804 return;
16805
16806 nlportid = rdev->crit_proto_nlportid;
16807 rdev->crit_proto_nlportid = 0;
16808
16809 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16810 if (!msg)
16811 return;
16812
16813 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16814 if (!hdr)
16815 goto nla_put_failure;
16816
16817 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016818 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16819 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016820 goto nla_put_failure;
16821
16822 genlmsg_end(msg, hdr);
16823
16824 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16825 return;
16826
16827 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016828 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016829}
16830EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16831
Johannes Berg348baf02014-01-24 14:06:29 +010016832void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16833{
16834 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016835 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016836 struct sk_buff *msg;
16837 void *hdr;
16838
16839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16840 if (!msg)
16841 return;
16842
16843 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16844 if (!hdr)
16845 goto out;
16846
16847 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16848 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016849 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16850 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016851 goto out;
16852
16853 genlmsg_end(msg, hdr);
16854
16855 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16856 NL80211_MCGRP_MLME, GFP_KERNEL);
16857 return;
16858 out:
16859 nlmsg_free(msg);
16860}
16861
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016862int cfg80211_external_auth_request(struct net_device *dev,
16863 struct cfg80211_external_auth_params *params,
16864 gfp_t gfp)
16865{
16866 struct wireless_dev *wdev = dev->ieee80211_ptr;
16867 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16868 struct sk_buff *msg;
16869 void *hdr;
16870
16871 if (!wdev->conn_owner_nlportid)
16872 return -EINVAL;
16873
16874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16875 if (!msg)
16876 return -ENOMEM;
16877
16878 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16879 if (!hdr)
16880 goto nla_put_failure;
16881
16882 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16883 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16884 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16885 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16886 params->action) ||
16887 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16888 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16889 params->ssid.ssid))
16890 goto nla_put_failure;
16891
16892 genlmsg_end(msg, hdr);
16893 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16894 wdev->conn_owner_nlportid);
16895 return 0;
16896
16897 nla_put_failure:
16898 nlmsg_free(msg);
16899 return -ENOBUFS;
16900}
16901EXPORT_SYMBOL(cfg80211_external_auth_request);
16902
Sunil Duttcb74e972019-02-20 16:18:07 +053016903void cfg80211_update_owe_info_event(struct net_device *netdev,
16904 struct cfg80211_update_owe_info *owe_info,
16905 gfp_t gfp)
16906{
16907 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16908 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16909 struct sk_buff *msg;
16910 void *hdr;
16911
16912 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16913
16914 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16915 if (!msg)
16916 return;
16917
16918 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16919 if (!hdr)
16920 goto nla_put_failure;
16921
16922 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16923 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16924 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16925 goto nla_put_failure;
16926
16927 if (!owe_info->ie_len ||
16928 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16929 goto nla_put_failure;
16930
16931 genlmsg_end(msg, hdr);
16932
16933 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16934 NL80211_MCGRP_MLME, gfp);
16935 return;
16936
16937nla_put_failure:
16938 genlmsg_cancel(msg, hdr);
16939 nlmsg_free(msg);
16940}
16941EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16942
Johannes Berg55682962007-09-20 13:09:35 -040016943/* initialisation/exit functions */
16944
Johannes Berg56989f62016-10-24 14:40:05 +020016945int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016946{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016947 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016948
Johannes Berg489111e2016-10-24 14:40:03 +020016949 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016950 if (err)
16951 return err;
16952
Jouni Malinen026331c2010-02-15 12:53:10 +020016953 err = netlink_register_notifier(&nl80211_netlink_notifier);
16954 if (err)
16955 goto err_out;
16956
Johannes Berg55682962007-09-20 13:09:35 -040016957 return 0;
16958 err_out:
16959 genl_unregister_family(&nl80211_fam);
16960 return err;
16961}
16962
16963void nl80211_exit(void)
16964{
Jouni Malinen026331c2010-02-15 12:53:10 +020016965 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016966 genl_unregister_family(&nl80211_fam);
16967}