blob: 3006cfce7158cb380cc605a557d84ee61f014813 [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 Berg55682962007-09-20 13:09:35 -0400293 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
294 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700295 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200296 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100297
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200298 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530299 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100300 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
301 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
302 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
303
Johannes Bergab0d76f2018-10-02 10:00:07 +0200304 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
305 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200306 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
307 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100308 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200309 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400310
Johannes Bergab0d76f2018-10-02 10:00:07 +0200311 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400312 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
313 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100314
Johannes Berg1a28ed22019-05-28 14:18:07 +0200315 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
316 [NL80211_ATTR_PREV_BSSID] = {
317 .type = NLA_EXACT_LEN_WARN,
318 .len = ETH_ALEN
319 },
Johannes Berg41ade002007-12-19 02:03:29 +0100320
Johannes Bergb9454e82009-07-08 13:29:08 +0200321 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100322 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
323 .len = WLAN_MAX_KEY_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200324 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
Johannes Berg41ade002007-12-19 02:03:29 +0100325 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
326 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200327 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200328 [NL80211_ATTR_KEY_TYPE] =
329 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100330
331 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
332 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
333 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg3d7af872018-10-02 10:00:08 +0200335 [NL80211_ATTR_BEACON_TAIL] =
336 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
337 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200338 [NL80211_ATTR_STA_AID] =
339 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100340 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
341 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
343 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200344 [NL80211_ATTR_STA_PLINK_ACTION] =
345 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530346 [NL80211_ATTR_STA_TX_POWER_SETTING] =
347 NLA_POLICY_RANGE(NLA_U8,
348 NL80211_TX_POWER_AUTOMATIC,
349 NL80211_TX_POWER_FIXED),
350 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100351 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200352 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100353 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800354 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100355 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300356
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700357 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
358 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
359
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300360 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
361 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
362 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200363 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
364 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100365 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300366
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800367 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700368 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700369
Johannes Berg1a28ed22019-05-28 14:18:07 +0200370 [NL80211_ATTR_HT_CAPABILITY] = {
371 .type = NLA_EXACT_LEN_WARN,
372 .len = NL80211_HT_CAPABILITY_LEN
373 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200374
375 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200376 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
377 validate_ie_attr,
378 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100379 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
380 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200381
382 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
383 .len = IEEE80211_MAX_SSID_LEN },
384 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
385 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200386 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300387 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200388 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
389 NL80211_MFP_NO,
390 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300391 [NL80211_ATTR_STA_FLAGS2] = {
392 .len = sizeof(struct nl80211_sta_flag_update),
393 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300394 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300395 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
396 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500397 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200398 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
399 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
400 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200401 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100402 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200403 [NL80211_ATTR_PMKID] = {
404 .type = NLA_EXACT_LEN_WARN,
405 .len = WLAN_PMKID_LEN
406 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100407 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
408 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200409 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200410 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
411 .len = IEEE80211_MAX_DATA_LEN },
412 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200413 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
414 NL80211_PS_DISABLED,
415 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200416 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300417 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200418 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300419 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
420 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200421 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900422 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
423 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100424 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100425 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100426 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200427 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200428 [NL80211_ATTR_STA_PLINK_STATE] =
429 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
430 [NL80211_ATTR_MESH_PEER_AID] =
431 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300432 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200433 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200434 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200435 [NL80211_ATTR_HIDDEN_SSID] =
436 NLA_POLICY_RANGE(NLA_U32,
437 NL80211_HIDDEN_SSID_NOT_IN_USE,
438 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200439 [NL80211_ATTR_IE_PROBE_RESP] =
440 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
441 IEEE80211_MAX_DATA_LEN),
442 [NL80211_ATTR_IE_ASSOC_RESP] =
443 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
444 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530445 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300446 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530447 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300448 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
449 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
450 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
451 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
452 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300453 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100454 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200455 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
456 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700457 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800458 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
459 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
460 .len = NL80211_HT_CAPABILITY_LEN
461 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100462 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530463 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530464 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200465 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700466 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300467 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200468 [NL80211_ATTR_VHT_CAPABILITY] = {
469 .type = NLA_EXACT_LEN_WARN,
470 .len = NL80211_VHT_CAPABILITY_LEN
471 },
Sam Lefflered4737712012-10-11 21:03:31 -0700472 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200473 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
474 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
475 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
476 NLA_POLICY_RANGE(NLA_U32,
477 NL80211_MESH_POWER_UNKNOWN + 1,
478 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530479 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
480 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200481 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
482 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100483 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100484 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
485 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
486 .len = NL80211_VHT_CAPABILITY_LEN,
487 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200488 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
489 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
490 .len = IEEE80211_MAX_DATA_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200491 [NL80211_ATTR_PEER_AID] =
492 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200493 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
494 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
495 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300496 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
497 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530498 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
499 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200500 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100501 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100502 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
503 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
504 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800505 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
506 .len = IEEE80211_QOS_MAP_LEN_MAX },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200507 [NL80211_ATTR_MAC_HINT] = {
508 .type = NLA_EXACT_LEN_WARN,
509 .len = ETH_ALEN
510 },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200511 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530512 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200513 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300514 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300515 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200516 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
517 [NL80211_ATTR_USER_PRIO] =
518 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300519 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300520 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200521 [NL80211_ATTR_MAC_MASK] = {
522 .type = NLA_EXACT_LEN_WARN,
523 .len = ETH_ALEN
524 },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200525 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200526 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200527 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500528 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200529 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100530 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200531 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
532 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300533 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
534 .len = VHT_MUMIMO_GROUPS_DATA_LEN
535 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200536 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = {
537 .type = NLA_EXACT_LEN_WARN,
538 .len = ETH_ALEN
539 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200540 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200541 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300542 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300543 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
544 .len = FILS_MAX_KEK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200545 [NL80211_ATTR_FILS_NONCES] = {
546 .type = NLA_EXACT_LEN_WARN,
547 .len = 2 * FILS_NONCE_LEN
548 },
Michael Braunce0ce132016-10-10 19:12:22 +0200549 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200550 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200551 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
552 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
553 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
554 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200555 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300556 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
557 .len = FILS_ERP_MAX_USERNAME_LEN },
558 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
559 .len = FILS_ERP_MAX_REALM_LEN },
560 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
561 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
562 .len = FILS_ERP_MAX_RRK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200563 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300564 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100565 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200566 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200567
568 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
569 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
570 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300571 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
572 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700573
574 [NL80211_ATTR_FTM_RESPONDER] = {
575 .type = NLA_NESTED,
576 .validation_data = nl80211_ftm_responder_policy,
577 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200578 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
579 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100580 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800581 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000582 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
583 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200584 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
John Crispin796e90f2019-07-30 18:37:00 +0200585 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
Johannes Berg55682962007-09-20 13:09:35 -0400586};
587
Johannes Berge31b8212010-10-05 19:39:30 +0200588/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000589static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200590 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200591 [NL80211_KEY_IDX] = { .type = NLA_U8 },
592 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200593 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200594 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
595 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200596 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100597 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100598 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599};
600
601/* policy for the key default flags */
602static const struct nla_policy
603nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
604 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
605 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200606};
607
Johannes Bergf83ace32016-10-17 08:04:07 +0200608#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200609/* policy for WoWLAN attributes */
610static const struct nla_policy
611nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
612 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
613 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
614 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
615 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200616 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
617 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
618 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
619 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100620 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300621 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100622};
623
624static const struct nla_policy
625nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
626 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
627 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200628 [NL80211_WOWLAN_TCP_DST_MAC] = {
629 .type = NLA_EXACT_LEN_WARN,
630 .len = ETH_ALEN
631 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100632 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
633 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200634 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100635 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
636 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
637 },
638 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
639 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
640 },
641 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200642 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
643 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200644};
Johannes Bergf83ace32016-10-17 08:04:07 +0200645#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200646
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700647/* policy for coalesce rule attributes */
648static const struct nla_policy
649nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
650 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200651 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
652 NLA_POLICY_RANGE(NLA_U32,
653 NL80211_COALESCE_CONDITION_MATCH,
654 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700655 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
656};
657
Johannes Berge5497d72011-07-05 16:35:40 +0200658/* policy for GTK rekey offload attributes */
659static const struct nla_policy
660nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Johannes Berg180aa422019-05-28 14:19:07 +0200661 [NL80211_REKEY_DATA_KEK] = {
662 .type = NLA_EXACT_LEN_WARN,
663 .len = NL80211_KEK_LEN,
664 },
665 [NL80211_REKEY_DATA_KCK] = {
666 .type = NLA_EXACT_LEN_WARN,
667 .len = NL80211_KCK_LEN,
668 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200669 [NL80211_REKEY_DATA_REPLAY_CTR] = {
670 .type = NLA_EXACT_LEN_WARN,
671 .len = NL80211_REPLAY_CTR_LEN
672 },
Johannes Berge5497d72011-07-05 16:35:40 +0200673};
674
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300675static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530676nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
677 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
678 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
679 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
680};
681
682static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300683nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200684 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300685 .len = IEEE80211_MAX_SSID_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200686 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
687 .type = NLA_EXACT_LEN_WARN,
688 .len = ETH_ALEN
689 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700690 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530691 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
692 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300693};
694
Avraham Stern3b06d272015-10-12 09:51:34 +0300695static const struct nla_policy
696nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
697 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
698 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
699};
700
Arend van Spriel38de03d2016-03-02 20:37:18 +0100701static const struct nla_policy
702nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
703 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
704 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
705 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
706 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
707 },
708};
709
Ayala Bekera442b762016-09-20 17:31:15 +0300710/* policy for NAN function attributes */
711static const struct nla_policy
712nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
713 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300714 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300715 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
716 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
717 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
718 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
719 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
720 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200721 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
722 .type = NLA_EXACT_LEN_WARN,
723 .len = ETH_ALEN
724 },
Ayala Bekera442b762016-09-20 17:31:15 +0300725 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
726 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
727 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
728 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
729 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
730 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
731 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
732 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
733 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
734};
735
736/* policy for Service Response Filter attributes */
737static const struct nla_policy
738nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
739 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
740 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
741 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
742 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
743 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
744};
745
Peng Xuad670232017-10-03 23:21:51 +0300746/* policy for packet pattern attributes */
747static const struct nla_policy
748nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
749 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
750 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
751 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
752};
753
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200754int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
755 struct cfg80211_registered_device **rdev,
756 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100757{
Johannes Berg67748892010-10-04 21:14:06 +0200758 int err;
759
Johannes Berg97990a02013-04-19 01:02:55 +0200760 if (!cb->args[0]) {
Johannes Berg50508d92019-07-29 16:31:09 +0200761 struct nlattr **attrbuf;
762
763 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
764 GFP_KERNEL);
765 if (!attrbuf)
766 return -ENOMEM;
767
Johannes Berg8cb08172019-04-26 14:07:28 +0200768 err = nlmsg_parse_deprecated(cb->nlh,
769 GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg50508d92019-07-29 16:31:09 +0200770 attrbuf, nl80211_fam.maxattr,
Johannes Berg8cb08172019-04-26 14:07:28 +0200771 nl80211_policy, NULL);
Johannes Berg50508d92019-07-29 16:31:09 +0200772 if (err) {
773 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100774 return err;
Johannes Berg50508d92019-07-29 16:31:09 +0200775 }
Johannes Berg97990a02013-04-19 01:02:55 +0200776
Johannes Berg50508d92019-07-29 16:31:09 +0200777 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
778 attrbuf);
779 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100780 if (IS_ERR(*wdev))
781 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800782 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200783 /* 0 is the first index - add 1 to parse only once */
784 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200785 cb->args[1] = (*wdev)->identifier;
786 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200787 /* subtract the 1 again here */
788 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200789 struct wireless_dev *tmp;
790
Johannes Bergea90e0d2017-03-15 14:26:04 +0100791 if (!wiphy)
792 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800793 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200794 *wdev = NULL;
795
Johannes Berg53873f12016-05-03 16:52:04 +0300796 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200797 if (tmp->identifier == cb->args[1]) {
798 *wdev = tmp;
799 break;
800 }
801 }
Johannes Berg97990a02013-04-19 01:02:55 +0200802
Johannes Bergea90e0d2017-03-15 14:26:04 +0100803 if (!*wdev)
804 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200805 }
806
Johannes Berg67748892010-10-04 21:14:06 +0200807 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200808}
809
Johannes Berg55682962007-09-20 13:09:35 -0400810/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200811void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
812 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400813{
814 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000815 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400816}
817
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300818static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
819 const struct ieee80211_reg_rule *rule)
820{
821 int j;
822 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200823 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300824
825 if (!nl_wmm_rules)
826 goto nla_put_failure;
827
828 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200829 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300830
831 if (!nl_wmm_rule)
832 goto nla_put_failure;
833
834 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200835 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300836 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200837 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300838 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200839 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300840 nla_put_u16(msg, NL80211_WMMR_TXOP,
841 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300842 goto nla_put_failure;
843
844 nla_nest_end(msg, nl_wmm_rule);
845 }
846 nla_nest_end(msg, nl_wmm_rules);
847
848 return 0;
849
850nla_put_failure:
851 return -ENOBUFS;
852}
853
854static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100855 struct ieee80211_channel *chan,
856 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400857{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200858 /* Some channels must be completely excluded from the
859 * list to protect old user-space tools from breaking
860 */
861 if (!large && chan->flags &
862 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
863 return 0;
864
David S. Miller9360ffd2012-03-29 04:41:26 -0400865 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
866 chan->center_freq))
867 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400868
David S. Miller9360ffd2012-03-29 04:41:26 -0400869 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
870 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
871 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200872 if (chan->flags & IEEE80211_CHAN_NO_IR) {
873 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
874 goto nla_put_failure;
875 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
876 goto nla_put_failure;
877 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100878 if (chan->flags & IEEE80211_CHAN_RADAR) {
879 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
880 goto nla_put_failure;
881 if (large) {
882 u32 time;
883
884 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
885
886 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
887 chan->dfs_state))
888 goto nla_put_failure;
889 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
890 time))
891 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100892 if (nla_put_u32(msg,
893 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
894 chan->dfs_cac_ms))
895 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100896 }
897 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400898
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100899 if (large) {
900 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
901 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
902 goto nla_put_failure;
903 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
904 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
905 goto nla_put_failure;
906 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
907 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
908 goto nla_put_failure;
909 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
910 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
911 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200912 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
913 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
914 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300915 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
916 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200917 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200918 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
919 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
920 goto nla_put_failure;
921 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
922 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
923 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100924 }
925
David S. Miller9360ffd2012-03-29 04:41:26 -0400926 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
927 DBM_TO_MBM(chan->max_power)))
928 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400929
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300930 if (large) {
931 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300932 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300933
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200934 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300935 if (nl80211_msg_put_wmm_rules(msg, rule))
936 goto nla_put_failure;
937 }
938 }
939
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400940 return 0;
941
942 nla_put_failure:
943 return -ENOBUFS;
944}
945
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200946static bool nl80211_put_txq_stats(struct sk_buff *msg,
947 struct cfg80211_txq_stats *txqstats,
948 int attrtype)
949{
950 struct nlattr *txqattr;
951
952#define PUT_TXQVAL_U32(attr, memb) do { \
953 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
954 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
955 return false; \
956 } while (0)
957
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200958 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200959 if (!txqattr)
960 return false;
961
962 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
963 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
964 PUT_TXQVAL_U32(FLOWS, flows);
965 PUT_TXQVAL_U32(DROPS, drops);
966 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
967 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
968 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
969 PUT_TXQVAL_U32(COLLISIONS, collisions);
970 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
971 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
972 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
973 nla_nest_end(msg, txqattr);
974
975#undef PUT_TXQVAL_U32
976 return true;
977}
978
Johannes Berg55682962007-09-20 13:09:35 -0400979/* netlink command implementations */
980
Johannes Bergb9454e82009-07-08 13:29:08 +0200981struct key_parse {
982 struct key_params p;
983 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200984 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200985 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100986 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200987};
988
Johannes Berg768075e2017-11-13 15:35:06 +0100989static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
990 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200991{
992 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +0200993 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
994 nl80211_key_policy,
995 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200996 if (err)
997 return err;
998
999 k->def = !!tb[NL80211_KEY_DEFAULT];
1000 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1001
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001002 if (k->def) {
1003 k->def_uni = true;
1004 k->def_multi = true;
1005 }
1006 if (k->defmgmt)
1007 k->def_multi = true;
1008
Johannes Bergb9454e82009-07-08 13:29:08 +02001009 if (tb[NL80211_KEY_IDX])
1010 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1011
1012 if (tb[NL80211_KEY_DATA]) {
1013 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1014 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1015 }
1016
1017 if (tb[NL80211_KEY_SEQ]) {
1018 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1019 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1020 }
1021
1022 if (tb[NL80211_KEY_CIPHER])
1023 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1024
Johannes Bergab0d76f2018-10-02 10:00:07 +02001025 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001026 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001027
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001028 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1029 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001030
Johannes Berg8cb08172019-04-26 14:07:28 +02001031 err = nla_parse_nested_deprecated(kdt,
1032 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1033 tb[NL80211_KEY_DEFAULT_TYPES],
1034 nl80211_key_default_policy,
1035 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001036 if (err)
1037 return err;
1038
1039 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1040 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1041 }
1042
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001043 if (tb[NL80211_KEY_MODE])
1044 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1045
Johannes Bergb9454e82009-07-08 13:29:08 +02001046 return 0;
1047}
1048
1049static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1050{
1051 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1052 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1053 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1054 }
1055
1056 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1057 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1058 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1059 }
1060
1061 if (info->attrs[NL80211_ATTR_KEY_IDX])
1062 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1063
1064 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1065 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1066
1067 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1068 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1069
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001070 if (k->def) {
1071 k->def_uni = true;
1072 k->def_multi = true;
1073 }
1074 if (k->defmgmt)
1075 k->def_multi = true;
1076
Johannes Bergab0d76f2018-10-02 10:00:07 +02001077 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001078 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001079
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001080 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1081 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001082 int err = nla_parse_nested_deprecated(kdt,
1083 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1084 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1085 nl80211_key_default_policy,
1086 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001087 if (err)
1088 return err;
1089
1090 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1091 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1092 }
1093
Johannes Bergb9454e82009-07-08 13:29:08 +02001094 return 0;
1095}
1096
1097static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1098{
1099 int err;
1100
1101 memset(k, 0, sizeof(*k));
1102 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001103 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001104
1105 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001106 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001107 else
1108 err = nl80211_parse_key_old(info, k);
1109
1110 if (err)
1111 return err;
1112
Johannes Berg768075e2017-11-13 15:35:06 +01001113 if (k->def && k->defmgmt) {
1114 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001115 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001116 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001117
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001118 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001119 if (k->def_uni || !k->def_multi) {
1120 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001121 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001122 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001123 }
1124
Johannes Bergb9454e82009-07-08 13:29:08 +02001125 if (k->idx != -1) {
1126 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001127 if (k->idx < 4 || k->idx > 5) {
1128 GENL_SET_ERR_MSG(info,
1129 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001130 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001131 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001132 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001133 if (k->idx < 0 || k->idx > 3) {
1134 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001135 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001136 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001137 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001138 if (k->idx < 0 || k->idx > 5) {
1139 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001140 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001141 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001142 }
1143 }
1144
1145 return 0;
1146}
1147
Johannes Bergfffd0932009-07-08 14:22:54 +02001148static struct cfg80211_cached_keys *
1149nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001150 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001151{
Johannes Berg768075e2017-11-13 15:35:06 +01001152 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001153 struct key_parse parse;
1154 struct nlattr *key;
1155 struct cfg80211_cached_keys *result;
1156 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001157 bool have_key = false;
1158
1159 nla_for_each_nested(key, keys, rem) {
1160 have_key = true;
1161 break;
1162 }
1163
1164 if (!have_key)
1165 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001166
1167 result = kzalloc(sizeof(*result), GFP_KERNEL);
1168 if (!result)
1169 return ERR_PTR(-ENOMEM);
1170
1171 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001172
1173 nla_for_each_nested(key, keys, rem) {
1174 memset(&parse, 0, sizeof(parse));
1175 parse.idx = -1;
1176
Johannes Berg768075e2017-11-13 15:35:06 +01001177 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001178 if (err)
1179 goto error;
1180 err = -EINVAL;
1181 if (!parse.p.key)
1182 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001183 if (parse.idx < 0 || parse.idx > 3) {
1184 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001185 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001186 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001187 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001188 if (def) {
1189 GENL_SET_ERR_MSG(info,
1190 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001191 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001192 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001193 def = 1;
1194 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001195 if (!parse.def_uni || !parse.def_multi)
1196 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001197 } else if (parse.defmgmt)
1198 goto error;
1199 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001200 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001201 if (err)
1202 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001203 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1204 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001205 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001206 err = -EINVAL;
1207 goto error;
1208 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001209 result->params[parse.idx].cipher = parse.p.cipher;
1210 result->params[parse.idx].key_len = parse.p.key_len;
1211 result->params[parse.idx].key = result->data[parse.idx];
1212 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301213
Johannes Berg386b1f22016-09-13 16:10:02 +02001214 /* must be WEP key if we got here */
1215 if (no_ht)
1216 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001217 }
1218
Johannes Bergf1c1f172016-09-13 17:08:23 +02001219 if (result->def < 0) {
1220 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001221 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001222 goto error;
1223 }
1224
Johannes Bergfffd0932009-07-08 14:22:54 +02001225 return result;
1226 error:
1227 kfree(result);
1228 return ERR_PTR(err);
1229}
1230
1231static int nl80211_key_allowed(struct wireless_dev *wdev)
1232{
1233 ASSERT_WDEV_LOCK(wdev);
1234
Johannes Bergfffd0932009-07-08 14:22:54 +02001235 switch (wdev->iftype) {
1236 case NL80211_IFTYPE_AP:
1237 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001238 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001239 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001240 break;
1241 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001242 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001243 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001244 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001245 return -ENOLINK;
1246 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001247 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001248 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001249 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001250 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001251 case NL80211_IFTYPE_P2P_DEVICE:
1252 case NL80211_IFTYPE_WDS:
1253 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001254 return -EINVAL;
1255 }
1256
1257 return 0;
1258}
1259
Jouni Malinen664834d2014-01-15 00:01:44 +02001260static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1261 struct nlattr *tb)
1262{
1263 struct ieee80211_channel *chan;
1264
1265 if (tb == NULL)
1266 return NULL;
1267 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1268 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1269 return NULL;
1270 return chan;
1271}
1272
Johannes Berg7527a782011-05-13 10:58:57 +02001273static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1274{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001275 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001276 int i;
1277
1278 if (!nl_modes)
1279 goto nla_put_failure;
1280
1281 i = 0;
1282 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001283 if ((ifmodes & 1) && nla_put_flag(msg, i))
1284 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001285 ifmodes >>= 1;
1286 i++;
1287 }
1288
1289 nla_nest_end(msg, nl_modes);
1290 return 0;
1291
1292nla_put_failure:
1293 return -ENOBUFS;
1294}
1295
1296static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001297 struct sk_buff *msg,
1298 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001299{
1300 struct nlattr *nl_combis;
1301 int i, j;
1302
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001303 nl_combis = nla_nest_start_noflag(msg,
1304 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001305 if (!nl_combis)
1306 goto nla_put_failure;
1307
1308 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1309 const struct ieee80211_iface_combination *c;
1310 struct nlattr *nl_combi, *nl_limits;
1311
1312 c = &wiphy->iface_combinations[i];
1313
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001314 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001315 if (!nl_combi)
1316 goto nla_put_failure;
1317
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001318 nl_limits = nla_nest_start_noflag(msg,
1319 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001320 if (!nl_limits)
1321 goto nla_put_failure;
1322
1323 for (j = 0; j < c->n_limits; j++) {
1324 struct nlattr *nl_limit;
1325
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001326 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001327 if (!nl_limit)
1328 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001329 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1330 c->limits[j].max))
1331 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001332 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1333 c->limits[j].types))
1334 goto nla_put_failure;
1335 nla_nest_end(msg, nl_limit);
1336 }
1337
1338 nla_nest_end(msg, nl_limits);
1339
David S. Miller9360ffd2012-03-29 04:41:26 -04001340 if (c->beacon_int_infra_match &&
1341 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1342 goto nla_put_failure;
1343 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1344 c->num_different_channels) ||
1345 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1346 c->max_interfaces))
1347 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001348 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001349 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1350 c->radar_detect_widths) ||
1351 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1352 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001353 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301354 if (c->beacon_int_min_gcd &&
1355 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1356 c->beacon_int_min_gcd))
1357 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001358
1359 nla_nest_end(msg, nl_combi);
1360 }
1361
1362 nla_nest_end(msg, nl_combis);
1363
1364 return 0;
1365nla_put_failure:
1366 return -ENOBUFS;
1367}
1368
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001370static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1371 struct sk_buff *msg)
1372{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001373 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001374 struct nlattr *nl_tcp;
1375
1376 if (!tcp)
1377 return 0;
1378
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001379 nl_tcp = nla_nest_start_noflag(msg,
1380 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001381 if (!nl_tcp)
1382 return -ENOBUFS;
1383
1384 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1385 tcp->data_payload_max))
1386 return -ENOBUFS;
1387
1388 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1389 tcp->data_payload_max))
1390 return -ENOBUFS;
1391
1392 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1393 return -ENOBUFS;
1394
1395 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1396 sizeof(*tcp->tok), tcp->tok))
1397 return -ENOBUFS;
1398
1399 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1400 tcp->data_interval_max))
1401 return -ENOBUFS;
1402
1403 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1404 tcp->wake_payload_max))
1405 return -ENOBUFS;
1406
1407 nla_nest_end(msg, nl_tcp);
1408 return 0;
1409}
1410
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001412 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001413 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414{
1415 struct nlattr *nl_wowlan;
1416
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001417 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001418 return 0;
1419
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001420 nl_wowlan = nla_nest_start_noflag(msg,
1421 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 if (!nl_wowlan)
1423 return -ENOBUFS;
1424
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001425 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001427 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001429 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001431 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001433 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001435 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001437 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001439 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1441 return -ENOBUFS;
1442
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001443 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001444 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1446 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1447 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1448 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 };
1450
1451 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1452 sizeof(pat), &pat))
1453 return -ENOBUFS;
1454 }
1455
Luciano Coelho75453cc2015-01-09 14:06:37 +02001456 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1457 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1458 rdev->wiphy.wowlan->max_nd_match_sets))
1459 return -ENOBUFS;
1460
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001462 return -ENOBUFS;
1463
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 nla_nest_end(msg, nl_wowlan);
1465
1466 return 0;
1467}
1468#endif
1469
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001470static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001472{
1473 struct nl80211_coalesce_rule_support rule;
1474
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001475 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001476 return 0;
1477
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1479 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1480 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1481 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1482 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1483 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001484
1485 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1486 return -ENOBUFS;
1487
1488 return 0;
1489}
1490
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001491static int
1492nl80211_send_iftype_data(struct sk_buff *msg,
1493 const struct ieee80211_sband_iftype_data *iftdata)
1494{
1495 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1496
1497 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1498 iftdata->types_mask))
1499 return -ENOBUFS;
1500
1501 if (he_cap->has_he) {
1502 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1503 sizeof(he_cap->he_cap_elem.mac_cap_info),
1504 he_cap->he_cap_elem.mac_cap_info) ||
1505 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1506 sizeof(he_cap->he_cap_elem.phy_cap_info),
1507 he_cap->he_cap_elem.phy_cap_info) ||
1508 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1509 sizeof(he_cap->he_mcs_nss_supp),
1510 &he_cap->he_mcs_nss_supp) ||
1511 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1512 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1513 return -ENOBUFS;
1514 }
1515
1516 return 0;
1517}
1518
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1520 struct ieee80211_supported_band *sband)
1521{
1522 struct nlattr *nl_rates, *nl_rate;
1523 struct ieee80211_rate *rate;
1524 int i;
1525
1526 /* add HT info */
1527 if (sband->ht_cap.ht_supported &&
1528 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1529 sizeof(sband->ht_cap.mcs),
1530 &sband->ht_cap.mcs) ||
1531 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1532 sband->ht_cap.cap) ||
1533 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1534 sband->ht_cap.ampdu_factor) ||
1535 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1536 sband->ht_cap.ampdu_density)))
1537 return -ENOBUFS;
1538
1539 /* add VHT info */
1540 if (sband->vht_cap.vht_supported &&
1541 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1542 sizeof(sband->vht_cap.vht_mcs),
1543 &sband->vht_cap.vht_mcs) ||
1544 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1545 sband->vht_cap.cap)))
1546 return -ENOBUFS;
1547
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001548 if (sband->n_iftype_data) {
1549 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001550 nla_nest_start_noflag(msg,
1551 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001552 int err;
1553
1554 if (!nl_iftype_data)
1555 return -ENOBUFS;
1556
1557 for (i = 0; i < sband->n_iftype_data; i++) {
1558 struct nlattr *iftdata;
1559
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001560 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001561 if (!iftdata)
1562 return -ENOBUFS;
1563
1564 err = nl80211_send_iftype_data(msg,
1565 &sband->iftype_data[i]);
1566 if (err)
1567 return err;
1568
1569 nla_nest_end(msg, iftdata);
1570 }
1571
1572 nla_nest_end(msg, nl_iftype_data);
1573 }
1574
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001576 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 if (!nl_rates)
1578 return -ENOBUFS;
1579
1580 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001581 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 if (!nl_rate)
1583 return -ENOBUFS;
1584
1585 rate = &sband->bitrates[i];
1586 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1587 rate->bitrate))
1588 return -ENOBUFS;
1589 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1590 nla_put_flag(msg,
1591 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1592 return -ENOBUFS;
1593
1594 nla_nest_end(msg, nl_rate);
1595 }
1596
1597 nla_nest_end(msg, nl_rates);
1598
1599 return 0;
1600}
1601
1602static int
1603nl80211_send_mgmt_stypes(struct sk_buff *msg,
1604 const struct ieee80211_txrx_stypes *mgmt_stypes)
1605{
1606 u16 stypes;
1607 struct nlattr *nl_ftypes, *nl_ifs;
1608 enum nl80211_iftype ift;
1609 int i;
1610
1611 if (!mgmt_stypes)
1612 return 0;
1613
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001614 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 if (!nl_ifs)
1616 return -ENOBUFS;
1617
1618 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001619 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 if (!nl_ftypes)
1621 return -ENOBUFS;
1622 i = 0;
1623 stypes = mgmt_stypes[ift].tx;
1624 while (stypes) {
1625 if ((stypes & 1) &&
1626 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1627 (i << 4) | IEEE80211_FTYPE_MGMT))
1628 return -ENOBUFS;
1629 stypes >>= 1;
1630 i++;
1631 }
1632 nla_nest_end(msg, nl_ftypes);
1633 }
1634
1635 nla_nest_end(msg, nl_ifs);
1636
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001637 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 if (!nl_ifs)
1639 return -ENOBUFS;
1640
1641 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001642 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001643 if (!nl_ftypes)
1644 return -ENOBUFS;
1645 i = 0;
1646 stypes = mgmt_stypes[ift].rx;
1647 while (stypes) {
1648 if ((stypes & 1) &&
1649 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1650 (i << 4) | IEEE80211_FTYPE_MGMT))
1651 return -ENOBUFS;
1652 stypes >>= 1;
1653 i++;
1654 }
1655 nla_nest_end(msg, nl_ftypes);
1656 }
1657 nla_nest_end(msg, nl_ifs);
1658
1659 return 0;
1660}
1661
Johannes Berg17948992016-10-26 11:42:04 +02001662#define CMD(op, n) \
1663 do { \
1664 if (rdev->ops->op) { \
1665 i++; \
1666 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1667 goto nla_put_failure; \
1668 } \
1669 } while (0)
1670
1671static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1672 struct sk_buff *msg)
1673{
1674 int i = 0;
1675
1676 /*
1677 * do *NOT* add anything into this function, new things need to be
1678 * advertised only to new versions of userspace that can deal with
1679 * the split (and they can't possibly care about new features...
1680 */
1681 CMD(add_virtual_intf, NEW_INTERFACE);
1682 CMD(change_virtual_intf, SET_INTERFACE);
1683 CMD(add_key, NEW_KEY);
1684 CMD(start_ap, START_AP);
1685 CMD(add_station, NEW_STATION);
1686 CMD(add_mpath, NEW_MPATH);
1687 CMD(update_mesh_config, SET_MESH_CONFIG);
1688 CMD(change_bss, SET_BSS);
1689 CMD(auth, AUTHENTICATE);
1690 CMD(assoc, ASSOCIATE);
1691 CMD(deauth, DEAUTHENTICATE);
1692 CMD(disassoc, DISASSOCIATE);
1693 CMD(join_ibss, JOIN_IBSS);
1694 CMD(join_mesh, JOIN_MESH);
1695 CMD(set_pmksa, SET_PMKSA);
1696 CMD(del_pmksa, DEL_PMKSA);
1697 CMD(flush_pmksa, FLUSH_PMKSA);
1698 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1699 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1700 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1701 CMD(mgmt_tx, FRAME);
1702 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1703 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1704 i++;
1705 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1706 goto nla_put_failure;
1707 }
1708 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1709 rdev->ops->join_mesh) {
1710 i++;
1711 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1712 goto nla_put_failure;
1713 }
1714 CMD(set_wds_peer, SET_WDS_PEER);
1715 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1716 CMD(tdls_mgmt, TDLS_MGMT);
1717 CMD(tdls_oper, TDLS_OPER);
1718 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001719 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001720 CMD(sched_scan_start, START_SCHED_SCAN);
1721 CMD(probe_client, PROBE_CLIENT);
1722 CMD(set_noack_map, SET_NOACK_MAP);
1723 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1724 i++;
1725 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1726 goto nla_put_failure;
1727 }
1728 CMD(start_p2p_device, START_P2P_DEVICE);
1729 CMD(set_mcast_rate, SET_MCAST_RATE);
1730#ifdef CONFIG_NL80211_TESTMODE
1731 CMD(testmode_cmd, TESTMODE);
1732#endif
1733
1734 if (rdev->ops->connect || rdev->ops->auth) {
1735 i++;
1736 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1737 goto nla_put_failure;
1738 }
1739
1740 if (rdev->ops->disconnect || rdev->ops->deauth) {
1741 i++;
1742 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1743 goto nla_put_failure;
1744 }
1745
1746 return i;
1747 nla_put_failure:
1748 return -ENOBUFS;
1749}
1750
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001751static int
1752nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1753 struct sk_buff *msg)
1754{
1755 struct nlattr *ftm;
1756
1757 if (!cap->ftm.supported)
1758 return 0;
1759
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001760 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001761 if (!ftm)
1762 return -ENOBUFS;
1763
1764 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1765 return -ENOBUFS;
1766 if (cap->ftm.non_asap &&
1767 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1768 return -ENOBUFS;
1769 if (cap->ftm.request_lci &&
1770 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1771 return -ENOBUFS;
1772 if (cap->ftm.request_civicloc &&
1773 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1774 return -ENOBUFS;
1775 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1776 cap->ftm.preambles))
1777 return -ENOBUFS;
1778 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1779 cap->ftm.bandwidths))
1780 return -ENOBUFS;
1781 if (cap->ftm.max_bursts_exponent >= 0 &&
1782 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1783 cap->ftm.max_bursts_exponent))
1784 return -ENOBUFS;
1785 if (cap->ftm.max_ftms_per_burst &&
1786 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1787 cap->ftm.max_ftms_per_burst))
1788 return -ENOBUFS;
1789
1790 nla_nest_end(msg, ftm);
1791 return 0;
1792}
1793
1794static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1795 struct sk_buff *msg)
1796{
1797 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1798 struct nlattr *pmsr, *caps;
1799
1800 if (!cap)
1801 return 0;
1802
1803 /*
1804 * we don't need to clean up anything here since the caller
1805 * will genlmsg_cancel() if we fail
1806 */
1807
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001808 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001809 if (!pmsr)
1810 return -ENOBUFS;
1811
1812 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1813 return -ENOBUFS;
1814
1815 if (cap->report_ap_tsf &&
1816 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1817 return -ENOBUFS;
1818
1819 if (cap->randomize_mac_addr &&
1820 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1821 return -ENOBUFS;
1822
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001823 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001824 if (!caps)
1825 return -ENOBUFS;
1826
1827 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1828 return -ENOBUFS;
1829
1830 nla_nest_end(msg, caps);
1831 nla_nest_end(msg, pmsr);
1832
1833 return 0;
1834}
1835
Johannes Berg86e8cf92013-06-19 10:57:22 +02001836struct nl80211_dump_wiphy_state {
1837 s64 filter_wiphy;
1838 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301839 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840 bool split;
1841};
1842
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001843static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001844 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001845 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001846 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001847{
1848 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001849 struct nlattr *nl_bands, *nl_band;
1850 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001851 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001852 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001853 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001854 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001855 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001856 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001857 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001858
Johannes Berg3bb20552014-05-26 13:52:25 +02001859 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001860 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001861 return -ENOBUFS;
1862
Johannes Berg86e8cf92013-06-19 10:57:22 +02001863 if (WARN_ON(!state))
1864 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001865
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001867 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001868 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001869 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001870 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001871 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001872
Johannes Berg3bb20552014-05-26 13:52:25 +02001873 if (cmd != NL80211_CMD_NEW_WIPHY)
1874 goto finish;
1875
Johannes Berg86e8cf92013-06-19 10:57:22 +02001876 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001877 case 0:
1878 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001879 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001880 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001881 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001882 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001883 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001884 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001885 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001886 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001887 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001888 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001889 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001891 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001892 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001893 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001895 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001897 rdev->wiphy.max_match_sets) ||
1898 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1899 rdev->wiphy.max_sched_scan_plans) ||
1900 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1901 rdev->wiphy.max_sched_scan_plan_interval) ||
1902 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1903 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001904 goto nla_put_failure;
1905
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001906 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001907 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1908 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001909 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001910 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1911 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001912 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1914 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001915 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001916 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1917 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001918 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001919 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1920 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001921 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001922 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001923 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001924 state->split_start++;
1925 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001926 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001927 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001928 case 1:
1929 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001930 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1931 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001932 goto nla_put_failure;
1933
Johannes Berg3713b4e2013-02-14 16:19:38 +01001934 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001935 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001936 goto nla_put_failure;
1937
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001938 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001939 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1940 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001941
Johannes Berg3713b4e2013-02-14 16:19:38 +01001942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001943 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001944 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001945 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001946 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001947
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001948 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001949 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001950 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001951 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001952
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001953 if ((rdev->wiphy.available_antennas_tx ||
1954 rdev->wiphy.available_antennas_rx) &&
1955 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001956 u32 tx_ant = 0, rx_ant = 0;
1957 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001958
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001959 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 if (!res) {
1961 if (nla_put_u32(msg,
1962 NL80211_ATTR_WIPHY_ANTENNA_TX,
1963 tx_ant) ||
1964 nla_put_u32(msg,
1965 NL80211_ATTR_WIPHY_ANTENNA_RX,
1966 rx_ant))
1967 goto nla_put_failure;
1968 }
Johannes Bergee688b002008-01-24 19:38:39 +01001969 }
1970
Johannes Berg86e8cf92013-06-19 10:57:22 +02001971 state->split_start++;
1972 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001973 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001974 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001975 case 2:
1976 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001977 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001978 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001979 state->split_start++;
1980 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001981 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001982 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001983 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001984 nl_bands = nla_nest_start_noflag(msg,
1985 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001986 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001987 goto nla_put_failure;
1988
Johannes Berg86e8cf92013-06-19 10:57:22 +02001989 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001990 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001991 struct ieee80211_supported_band *sband;
1992
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001993 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001994
1995 if (!sband)
1996 continue;
1997
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001998 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001999 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01002000 goto nla_put_failure;
2001
Johannes Berg86e8cf92013-06-19 10:57:22 +02002002 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002003 case 0:
2004 if (nl80211_send_band_rateinfo(msg, sband))
2005 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002006 state->chan_start++;
2007 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002008 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002009 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002010 default:
2011 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002012 nl_freqs = nla_nest_start_noflag(msg,
2013 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002014 if (!nl_freqs)
2015 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002016
Johannes Berg86e8cf92013-06-19 10:57:22 +02002017 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002018 i < sband->n_channels;
2019 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002020 nl_freq = nla_nest_start_noflag(msg,
2021 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002022 if (!nl_freq)
2023 goto nla_put_failure;
2024
2025 chan = &sband->channels[i];
2026
Johannes Berg86e8cf92013-06-19 10:57:22 +02002027 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002028 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002029 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002030 goto nla_put_failure;
2031
2032 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002033 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002034 break;
2035 }
2036 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002037 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002038 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002039 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002040 nla_nest_end(msg, nl_freqs);
2041 }
2042
2043 nla_nest_end(msg, nl_band);
2044
Johannes Berg86e8cf92013-06-19 10:57:22 +02002045 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002046 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002047 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002048 band--;
2049 break;
2050 }
Johannes Bergee688b002008-01-24 19:38:39 +01002051 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002052 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002053
Johannes Berg57fbcce2016-04-12 15:56:15 +02002054 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002055 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002056 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002057 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002058
Johannes Berg3713b4e2013-02-14 16:19:38 +01002059 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002060 if (state->band_start == 0 && state->chan_start == 0)
2061 state->split_start++;
2062 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002063 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002064 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002065 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002066 nl_cmds = nla_nest_start_noflag(msg,
2067 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002068 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002069 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002070
Johannes Berg17948992016-10-26 11:42:04 +02002071 i = nl80211_add_commands_unsplit(rdev, msg);
2072 if (i < 0)
2073 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002074 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002075 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2076 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002077 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002078 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002079 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002080 if (rdev->wiphy.features &
2081 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002082 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002083 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002084 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02002085 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002086#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002087
Johannes Berg3713b4e2013-02-14 16:19:38 +01002088 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002089 state->split_start++;
2090 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002091 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002092 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002093 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002094 if (rdev->ops->remain_on_channel &&
2095 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002096 nla_put_u32(msg,
2097 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002098 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002099 goto nla_put_failure;
2100
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002101 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002102 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2103 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002104
Johannes Berg3713b4e2013-02-14 16:19:38 +01002105 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2106 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002107 state->split_start++;
2108 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002109 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002110 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002111 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002112#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002113 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002114 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002115 state->split_start++;
2116 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002117 break;
2118#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002119 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002120#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002121 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002122 case 7:
2123 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002124 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002125 goto nla_put_failure;
2126
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002127 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002128 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002129 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002130
Johannes Berg86e8cf92013-06-19 10:57:22 +02002131 state->split_start++;
2132 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002133 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002134 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002135 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002136 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002137 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002138 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002139 goto nla_put_failure;
2140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002141 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002142 /*
2143 * We can only add the per-channel limit information if the
2144 * dump is split, otherwise it makes it too big. Therefore
2145 * only advertise it in that case.
2146 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002147 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002148 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2149 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002150 goto nla_put_failure;
2151
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002152 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002153 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002154 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2155 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002156 goto nla_put_failure;
2157
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002158 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2159 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002160 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002161 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002162 goto nla_put_failure;
2163
2164 /*
2165 * Any information below this point is only available to
2166 * applications that can deal with it being split. This
2167 * helps ensure that newly added capabilities don't break
2168 * older tools by overrunning their buffers.
2169 *
2170 * We still increment split_start so that in the split
2171 * case we'll continue with more data in the next round,
2172 * but break unconditionally so unsplit data stops here.
2173 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002174 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002175 break;
2176 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002177 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002178 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002179 rdev->wiphy.extended_capabilities_len,
2180 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002181 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002182 rdev->wiphy.extended_capabilities_len,
2183 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002184 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002185
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002186 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002187 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002188 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2189 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002190 goto nla_put_failure;
2191
Denis Kenziorae6fa4d2019-07-22 06:33:12 -05002192 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2193 rdev->wiphy.perm_addr))
2194 goto nla_put_failure;
2195
2196 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2197 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2198 rdev->wiphy.addr_mask))
2199 goto nla_put_failure;
2200
2201 if (rdev->wiphy.n_addresses > 1) {
2202 void *attr;
2203
2204 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2205 if (!attr)
2206 goto nla_put_failure;
2207
2208 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2209 if (nla_put(msg, i + 1, ETH_ALEN,
2210 rdev->wiphy.addresses[i].addr))
2211 goto nla_put_failure;
2212
2213 nla_nest_end(msg, attr);
2214 }
2215
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002216 state->split_start++;
2217 break;
2218 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002219 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002220 goto nla_put_failure;
2221
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002222 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002223 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2224 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2225 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002226
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002227 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002228 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002229 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002230 goto nla_put_failure;
2231
Johannes Bergad7e7182013-11-13 13:37:47 +01002232 state->split_start++;
2233 break;
2234 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002235 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002236 const struct nl80211_vendor_cmd_info *info;
2237 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002238
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002239 nested = nla_nest_start_noflag(msg,
2240 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002241 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002242 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002243
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002244 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2245 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002246 if (nla_put(msg, i + 1, sizeof(*info), info))
2247 goto nla_put_failure;
2248 }
2249 nla_nest_end(msg, nested);
2250 }
2251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002252 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002253 const struct nl80211_vendor_cmd_info *info;
2254 struct nlattr *nested;
2255
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002256 nested = nla_nest_start_noflag(msg,
2257 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002258 if (!nested)
2259 goto nla_put_failure;
2260
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002261 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2262 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002263 if (nla_put(msg, i + 1, sizeof(*info), info))
2264 goto nla_put_failure;
2265 }
2266 nla_nest_end(msg, nested);
2267 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002268 state->split_start++;
2269 break;
2270 case 12:
2271 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2272 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2273 rdev->wiphy.max_num_csa_counters))
2274 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002275
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002276 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2277 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2278 goto nla_put_failure;
2279
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002280 if (rdev->wiphy.max_sched_scan_reqs &&
2281 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2282 rdev->wiphy.max_sched_scan_reqs))
2283 goto nla_put_failure;
2284
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002285 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2286 sizeof(rdev->wiphy.ext_features),
2287 rdev->wiphy.ext_features))
2288 goto nla_put_failure;
2289
Arend van Spriel38de03d2016-03-02 20:37:18 +01002290 if (rdev->wiphy.bss_select_support) {
2291 struct nlattr *nested;
2292 u32 bss_select_support = rdev->wiphy.bss_select_support;
2293
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002294 nested = nla_nest_start_noflag(msg,
2295 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002296 if (!nested)
2297 goto nla_put_failure;
2298
2299 i = 0;
2300 while (bss_select_support) {
2301 if ((bss_select_support & 1) &&
2302 nla_put_flag(msg, i))
2303 goto nla_put_failure;
2304 i++;
2305 bss_select_support >>= 1;
2306 }
2307 nla_nest_end(msg, nested);
2308 }
2309
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302310 state->split_start++;
2311 break;
2312 case 13:
2313 if (rdev->wiphy.num_iftype_ext_capab &&
2314 rdev->wiphy.iftype_ext_capab) {
2315 struct nlattr *nested_ext_capab, *nested;
2316
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002317 nested = nla_nest_start_noflag(msg,
2318 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302319 if (!nested)
2320 goto nla_put_failure;
2321
2322 for (i = state->capa_start;
2323 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2324 const struct wiphy_iftype_ext_capab *capab;
2325
2326 capab = &rdev->wiphy.iftype_ext_capab[i];
2327
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002328 nested_ext_capab = nla_nest_start_noflag(msg,
2329 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302330 if (!nested_ext_capab ||
2331 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2332 capab->iftype) ||
2333 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2334 capab->extended_capabilities_len,
2335 capab->extended_capabilities) ||
2336 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2337 capab->extended_capabilities_len,
2338 capab->extended_capabilities_mask))
2339 goto nla_put_failure;
2340
2341 nla_nest_end(msg, nested_ext_capab);
2342 if (state->split)
2343 break;
2344 }
2345 nla_nest_end(msg, nested);
2346 if (i < rdev->wiphy.num_iftype_ext_capab) {
2347 state->capa_start = i + 1;
2348 break;
2349 }
2350 }
2351
Luca Coelho85859892017-02-08 15:00:34 +02002352 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2353 rdev->wiphy.nan_supported_bands))
2354 goto nla_put_failure;
2355
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002356 if (wiphy_ext_feature_isset(&rdev->wiphy,
2357 NL80211_EXT_FEATURE_TXQS)) {
2358 struct cfg80211_txq_stats txqstats = {};
2359 int res;
2360
2361 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2362 if (!res &&
2363 !nl80211_put_txq_stats(msg, &txqstats,
2364 NL80211_ATTR_TXQ_STATS))
2365 goto nla_put_failure;
2366
2367 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2368 rdev->wiphy.txq_limit))
2369 goto nla_put_failure;
2370 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2371 rdev->wiphy.txq_memory_limit))
2372 goto nla_put_failure;
2373 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2374 rdev->wiphy.txq_quantum))
2375 goto nla_put_failure;
2376 }
2377
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002378 state->split_start++;
2379 break;
2380 case 14:
2381 if (nl80211_send_pmsr_capa(rdev, msg))
2382 goto nla_put_failure;
2383
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302384 state->split_start++;
2385 break;
2386 case 15:
2387 if (rdev->wiphy.akm_suites &&
2388 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2389 sizeof(u32) * rdev->wiphy.n_akm_suites,
2390 rdev->wiphy.akm_suites))
2391 goto nla_put_failure;
2392
Johannes Berg3713b4e2013-02-14 16:19:38 +01002393 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002394 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002395 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002396 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002397 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002398 genlmsg_end(msg, hdr);
2399 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002400
2401 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002402 genlmsg_cancel(msg, hdr);
2403 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002404}
2405
Johannes Berg86e8cf92013-06-19 10:57:22 +02002406static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2407 struct netlink_callback *cb,
2408 struct nl80211_dump_wiphy_state *state)
2409{
Johannes Berg50508d92019-07-29 16:31:09 +02002410 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2411 int ret;
2412
2413 if (!tb)
2414 return -ENOMEM;
2415
2416 ret = nlmsg_parse_deprecated(cb->nlh,
2417 GENL_HDRLEN + nl80211_fam.hdrsize,
2418 tb, nl80211_fam.maxattr,
2419 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002420 /* ignore parse errors for backward compatibility */
Johannes Berg50508d92019-07-29 16:31:09 +02002421 if (ret) {
2422 ret = 0;
2423 goto out;
2424 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002425
2426 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2427 if (tb[NL80211_ATTR_WIPHY])
2428 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2429 if (tb[NL80211_ATTR_WDEV])
2430 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2431 if (tb[NL80211_ATTR_IFINDEX]) {
2432 struct net_device *netdev;
2433 struct cfg80211_registered_device *rdev;
2434 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2435
Ying Xue7f2b8562014-01-15 10:23:45 +08002436 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg50508d92019-07-29 16:31:09 +02002437 if (!netdev) {
2438 ret = -ENODEV;
2439 goto out;
2440 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002441 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002442 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002443 netdev->ieee80211_ptr->wiphy);
2444 state->filter_wiphy = rdev->wiphy_idx;
2445 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002446 }
2447
Johannes Berg50508d92019-07-29 16:31:09 +02002448 ret = 0;
2449out:
2450 kfree(tb);
2451 return ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002452}
2453
Johannes Berg55682962007-09-20 13:09:35 -04002454static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2455{
Johannes Berg645e77d2013-03-01 14:03:49 +01002456 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002457 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002458 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002459
Johannes Berg5fe231e2013-05-08 21:45:15 +02002460 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002461 if (!state) {
2462 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002463 if (!state) {
2464 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002465 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002466 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002467 state->filter_wiphy = -1;
2468 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2469 if (ret) {
2470 kfree(state);
2471 rtnl_unlock();
2472 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002473 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002474 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002475 }
2476
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002477 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2478 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002479 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002480 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002481 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002482 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002483 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002484 continue;
2485 /* attempt to fit multiple wiphy data chunks into the skb */
2486 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002487 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2488 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002489 NETLINK_CB(cb->skb).portid,
2490 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002491 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002492 if (ret < 0) {
2493 /*
2494 * If sending the wiphy data didn't fit (ENOBUFS
2495 * or EMSGSIZE returned), this SKB is still
2496 * empty (so it's not too big because another
2497 * wiphy dataset is already in the skb) and
2498 * we've not tried to adjust the dump allocation
2499 * yet ... then adjust the alloc size to be
2500 * bigger, and return 1 but with the empty skb.
2501 * This results in an empty message being RX'ed
2502 * in userspace, but that is ignored.
2503 *
2504 * We can then retry with the larger buffer.
2505 */
2506 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002507 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002508 cb->min_dump_alloc < 4096) {
2509 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002510 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002511 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002512 return 1;
2513 }
2514 idx--;
2515 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002516 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002517 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002518 break;
Johannes Berg55682962007-09-20 13:09:35 -04002519 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002520 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002521
Johannes Berg86e8cf92013-06-19 10:57:22 +02002522 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002523
2524 return skb->len;
2525}
2526
Johannes Berg86e8cf92013-06-19 10:57:22 +02002527static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2528{
2529 kfree((void *)cb->args[0]);
2530 return 0;
2531}
2532
Johannes Berg55682962007-09-20 13:09:35 -04002533static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2534{
2535 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002537 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002538
Johannes Berg645e77d2013-03-01 14:03:49 +01002539 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002540 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002541 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002542
Johannes Berg3bb20552014-05-26 13:52:25 +02002543 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2544 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002545 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002546 nlmsg_free(msg);
2547 return -ENOBUFS;
2548 }
Johannes Berg55682962007-09-20 13:09:35 -04002549
Johannes Berg134e6372009-07-10 09:51:34 +00002550 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002551}
2552
Jouni Malinen31888482008-10-30 16:59:24 +02002553static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2554 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2555 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2556 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2557 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2558 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2559};
2560
2561static int parse_txq_params(struct nlattr *tb[],
2562 struct ieee80211_txq_params *txq_params)
2563{
Dan Williams259d8c12018-01-29 17:03:15 -08002564 u8 ac;
2565
Johannes Berga3304b02012-03-28 11:04:24 +02002566 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002567 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2568 !tb[NL80211_TXQ_ATTR_AIFS])
2569 return -EINVAL;
2570
Dan Williams259d8c12018-01-29 17:03:15 -08002571 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002572 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2573 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2574 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2575 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2576
Dan Williams259d8c12018-01-29 17:03:15 -08002577 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002578 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002579 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002580 return 0;
2581}
2582
Johannes Bergf444de02010-05-05 15:25:02 +02002583static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2584{
2585 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002586 * You can only set the channel explicitly for WDS interfaces,
2587 * all others have their channel managed via their respective
2588 * "establish a connection" command (connect, join, ...)
2589 *
2590 * For AP/GO and mesh mode, the channel can be set with the
2591 * channel userspace API, but is only stored and passed to the
2592 * low-level driver when the AP starts or the mesh is joined.
2593 * This is for backward compatibility, userspace can also give
2594 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002595 *
2596 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002597 * whatever else is going on, so they have their own special
2598 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002599 */
2600 return !wdev ||
2601 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002602 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002603 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2604 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002605}
2606
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002607int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2608 struct genl_info *info,
2609 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002610{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002611 struct netlink_ext_ack *extack = info->extack;
2612 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302613 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002614
Johannes Berg49f9cf02018-10-01 11:55:09 +02002615 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002616 return -EINVAL;
2617
Johannes Berg49f9cf02018-10-01 11:55:09 +02002618 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002619
2620 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002621 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2622 chandef->center_freq1 = control_freq;
2623 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002624
2625 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002626 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2627 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2628 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002629 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002630 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002631
Johannes Berg49f9cf02018-10-01 11:55:09 +02002632 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002633 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002634
Johannes Berg49f9cf02018-10-01 11:55:09 +02002635 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002636
2637 switch (chantype) {
2638 case NL80211_CHAN_NO_HT:
2639 case NL80211_CHAN_HT20:
2640 case NL80211_CHAN_HT40PLUS:
2641 case NL80211_CHAN_HT40MINUS:
2642 cfg80211_chandef_create(chandef, chandef->chan,
2643 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002644 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002645 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2646 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2647 NL_SET_ERR_MSG_ATTR(extack,
2648 attrs[NL80211_ATTR_CENTER_FREQ1],
2649 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002650 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002651 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002652 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002653 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2654 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2655 NL_SET_ERR_MSG_ATTR(extack,
2656 attrs[NL80211_ATTR_CENTER_FREQ2],
2657 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002658 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002659 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002660 break;
2661 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002662 NL_SET_ERR_MSG_ATTR(extack,
2663 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2664 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002665 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002666 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002667 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002668 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002669 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2670 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002671 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002672 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2673 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002674 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002675 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002676 }
2677
Johannes Berg49f9cf02018-10-01 11:55:09 +02002678 if (!cfg80211_chandef_valid(chandef)) {
2679 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002680 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002681 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002682
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002683 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002684 IEEE80211_CHAN_DISABLED)) {
2685 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002686 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002687 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002688
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002689 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2690 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002691 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2692 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002693 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002694 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002695
Johannes Berg683b6d32012-11-08 21:25:48 +01002696 return 0;
2697}
2698
Johannes Bergf444de02010-05-05 15:25:02 +02002699static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002700 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002701 struct genl_info *info)
2702{
Johannes Berg683b6d32012-11-08 21:25:48 +01002703 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002704 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002705 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002706 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002707
Jouni Malinene16821b2014-04-28 11:22:08 +03002708 if (dev)
2709 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002710 if (!nl80211_can_set_dev_channel(wdev))
2711 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002712 if (wdev)
2713 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002714
Johannes Berg683b6d32012-11-08 21:25:48 +01002715 result = nl80211_parse_chandef(rdev, info, &chandef);
2716 if (result)
2717 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002718
Johannes Berge8c9bd52012-06-06 08:18:22 +02002719 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002720 case NL80211_IFTYPE_AP:
2721 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002722 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2723 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002724 result = -EINVAL;
2725 break;
2726 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002727 if (wdev->beacon_interval) {
2728 if (!dev || !rdev->ops->set_ap_chanwidth ||
2729 !(rdev->wiphy.features &
2730 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2731 result = -EBUSY;
2732 break;
2733 }
2734
2735 /* Only allow dynamic channel width changes */
2736 if (chandef.chan != wdev->preset_chandef.chan) {
2737 result = -EBUSY;
2738 break;
2739 }
2740 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2741 if (result)
2742 break;
2743 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002744 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002745 result = 0;
2746 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002747 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002748 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002749 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002750 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002751 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002752 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002753 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002754 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002755 }
Johannes Bergf444de02010-05-05 15:25:02 +02002756
2757 return result;
2758}
2759
2760static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2761{
Johannes Berg4c476992010-10-04 21:36:35 +02002762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2763 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002764
Jouni Malinene16821b2014-04-28 11:22:08 +03002765 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002766}
2767
Bill Jordane8347eb2010-10-01 13:54:28 -04002768static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2769{
Johannes Berg43b19952010-10-07 13:10:30 +02002770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2771 struct net_device *dev = info->user_ptr[1];
2772 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002773 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002774
2775 if (!info->attrs[NL80211_ATTR_MAC])
2776 return -EINVAL;
2777
Johannes Berg43b19952010-10-07 13:10:30 +02002778 if (netif_running(dev))
2779 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002780
Johannes Berg43b19952010-10-07 13:10:30 +02002781 if (!rdev->ops->set_wds_peer)
2782 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002783
Johannes Berg43b19952010-10-07 13:10:30 +02002784 if (wdev->iftype != NL80211_IFTYPE_WDS)
2785 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002786
2787 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002788 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002789}
2790
Johannes Berg55682962007-09-20 13:09:35 -04002791static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2792{
2793 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002794 struct net_device *netdev = NULL;
2795 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002796 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002797 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002798 u32 changed;
2799 u8 retry_short = 0, retry_long = 0;
2800 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002801 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002802 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002803
Johannes Berg5fe231e2013-05-08 21:45:15 +02002804 ASSERT_RTNL();
2805
Johannes Bergf444de02010-05-05 15:25:02 +02002806 /*
2807 * Try to find the wiphy and netdev. Normally this
2808 * function shouldn't need the netdev, but this is
2809 * done for backward compatibility -- previously
2810 * setting the channel was done per wiphy, but now
2811 * it is per netdev. Previous userland like hostapd
2812 * also passed a netdev to set_wiphy, so that it is
2813 * possible to let that go to the right netdev!
2814 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002815
Johannes Bergf444de02010-05-05 15:25:02 +02002816 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2817 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2818
Ying Xue7f2b8562014-01-15 10:23:45 +08002819 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002820 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002821 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002822 else
Johannes Bergf444de02010-05-05 15:25:02 +02002823 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002824 }
2825
Johannes Bergf444de02010-05-05 15:25:02 +02002826 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002827 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2828 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002829 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002830 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002831 wdev = NULL;
2832 netdev = NULL;
2833 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002834 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002835 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002836
2837 /*
2838 * end workaround code, by now the rdev is available
2839 * and locked, and wdev may or may not be NULL.
2840 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002841
2842 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002843 result = cfg80211_dev_rename(
2844 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002845
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002846 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002847 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002848
Jouni Malinen31888482008-10-30 16:59:24 +02002849 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2850 struct ieee80211_txq_params txq_params;
2851 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2852
Ying Xue7f2b8562014-01-15 10:23:45 +08002853 if (!rdev->ops->set_txq_params)
2854 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002855
Ying Xue7f2b8562014-01-15 10:23:45 +08002856 if (!netdev)
2857 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002858
Johannes Berg133a3ff2011-11-03 14:50:13 +01002859 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002860 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2861 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002862
Ying Xue7f2b8562014-01-15 10:23:45 +08002863 if (!netif_running(netdev))
2864 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002865
Jouni Malinen31888482008-10-30 16:59:24 +02002866 nla_for_each_nested(nl_txq_params,
2867 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2868 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02002869 result = nla_parse_nested_deprecated(tb,
2870 NL80211_TXQ_ATTR_MAX,
2871 nl_txq_params,
2872 txq_params_policy,
2873 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002874 if (result)
2875 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002876 result = parse_txq_params(tb, &txq_params);
2877 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002878 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002879
Hila Gonene35e4d22012-06-27 17:19:42 +03002880 result = rdev_set_txq_params(rdev, netdev,
2881 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002882 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002883 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002884 }
2885 }
2886
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002887 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002888 result = __nl80211_set_channel(
2889 rdev,
2890 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2891 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002892 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002893 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002894 }
2895
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002896 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002897 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002898 enum nl80211_tx_power_setting type;
2899 int idx, mbm = 0;
2900
Johannes Bergc8442112012-10-24 10:17:18 +02002901 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2902 txp_wdev = NULL;
2903
Ying Xue7f2b8562014-01-15 10:23:45 +08002904 if (!rdev->ops->set_tx_power)
2905 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002906
2907 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2908 type = nla_get_u32(info->attrs[idx]);
2909
2910 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002911 (type != NL80211_TX_POWER_AUTOMATIC))
2912 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002913
2914 if (type != NL80211_TX_POWER_AUTOMATIC) {
2915 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2916 mbm = nla_get_u32(info->attrs[idx]);
2917 }
2918
Johannes Bergc8442112012-10-24 10:17:18 +02002919 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002920 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002921 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002922 }
2923
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002924 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2925 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2926 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002927
Bruno Randolf7f531e02010-12-16 11:30:22 +09002928 if ((!rdev->wiphy.available_antennas_tx &&
2929 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002930 !rdev->ops->set_antenna)
2931 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002932
2933 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2934 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2935
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002936 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002937 * available antenna masks, except for the "all" mask */
2938 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002939 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2940 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002941
Bruno Randolf7f531e02010-12-16 11:30:22 +09002942 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2943 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002944
Hila Gonene35e4d22012-06-27 17:19:42 +03002945 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002946 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002947 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002948 }
2949
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002950 changed = 0;
2951
2952 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2953 retry_short = nla_get_u8(
2954 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002955
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002956 changed |= WIPHY_PARAM_RETRY_SHORT;
2957 }
2958
2959 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2960 retry_long = nla_get_u8(
2961 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002962
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002963 changed |= WIPHY_PARAM_RETRY_LONG;
2964 }
2965
2966 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2967 frag_threshold = nla_get_u32(
2968 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002969 if (frag_threshold < 256)
2970 return -EINVAL;
2971
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002972 if (frag_threshold != (u32) -1) {
2973 /*
2974 * Fragments (apart from the last one) are required to
2975 * have even length. Make the fragmentation code
2976 * simpler by stripping LSB should someone try to use
2977 * odd threshold value.
2978 */
2979 frag_threshold &= ~0x1;
2980 }
2981 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2982 }
2983
2984 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2985 rts_threshold = nla_get_u32(
2986 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2987 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2988 }
2989
Lukáš Turek81077e82009-12-21 22:50:47 +01002990 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002991 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2992 return -EINVAL;
2993
Lukáš Turek81077e82009-12-21 22:50:47 +01002994 coverage_class = nla_get_u8(
2995 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2996 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2997 }
2998
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002999 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3000 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3001 return -EOPNOTSUPP;
3002
3003 changed |= WIPHY_PARAM_DYN_ACK;
3004 }
3005
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003006 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3007 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3008 NL80211_EXT_FEATURE_TXQS))
3009 return -EOPNOTSUPP;
3010 txq_limit = nla_get_u32(
3011 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3012 changed |= WIPHY_PARAM_TXQ_LIMIT;
3013 }
3014
3015 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3016 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3017 NL80211_EXT_FEATURE_TXQS))
3018 return -EOPNOTSUPP;
3019 txq_memory_limit = nla_get_u32(
3020 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3021 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3022 }
3023
3024 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3025 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3026 NL80211_EXT_FEATURE_TXQS))
3027 return -EOPNOTSUPP;
3028 txq_quantum = nla_get_u32(
3029 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3030 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3031 }
3032
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003033 if (changed) {
3034 u8 old_retry_short, old_retry_long;
3035 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003036 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003037 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003038
Ying Xue7f2b8562014-01-15 10:23:45 +08003039 if (!rdev->ops->set_wiphy_params)
3040 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003041
3042 old_retry_short = rdev->wiphy.retry_short;
3043 old_retry_long = rdev->wiphy.retry_long;
3044 old_frag_threshold = rdev->wiphy.frag_threshold;
3045 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003046 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003047 old_txq_limit = rdev->wiphy.txq_limit;
3048 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3049 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003050
3051 if (changed & WIPHY_PARAM_RETRY_SHORT)
3052 rdev->wiphy.retry_short = retry_short;
3053 if (changed & WIPHY_PARAM_RETRY_LONG)
3054 rdev->wiphy.retry_long = retry_long;
3055 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3056 rdev->wiphy.frag_threshold = frag_threshold;
3057 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3058 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003059 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3060 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003061 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3062 rdev->wiphy.txq_limit = txq_limit;
3063 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3064 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3065 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3066 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003067
Hila Gonene35e4d22012-06-27 17:19:42 +03003068 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003069 if (result) {
3070 rdev->wiphy.retry_short = old_retry_short;
3071 rdev->wiphy.retry_long = old_retry_long;
3072 rdev->wiphy.frag_threshold = old_frag_threshold;
3073 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003074 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003075 rdev->wiphy.txq_limit = old_txq_limit;
3076 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3077 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003078 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003079 }
3080 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003081 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003082}
3083
Johannes Berg683b6d32012-11-08 21:25:48 +01003084static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003085 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003086{
Johannes Berg601555c2014-11-27 17:26:56 +01003087 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3088 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003089
Johannes Berg683b6d32012-11-08 21:25:48 +01003090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3091 chandef->chan->center_freq))
3092 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003093 switch (chandef->width) {
3094 case NL80211_CHAN_WIDTH_20_NOHT:
3095 case NL80211_CHAN_WIDTH_20:
3096 case NL80211_CHAN_WIDTH_40:
3097 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3098 cfg80211_get_chandef_type(chandef)))
3099 return -ENOBUFS;
3100 break;
3101 default:
3102 break;
3103 }
3104 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3105 return -ENOBUFS;
3106 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3107 return -ENOBUFS;
3108 if (chandef->center_freq2 &&
3109 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003110 return -ENOBUFS;
3111 return 0;
3112}
3113
Eric W. Biederman15e47302012-09-07 20:12:54 +00003114static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003115 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003116 struct wireless_dev *wdev,
3117 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003118{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003119 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003120 void *hdr;
3121
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003122 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3123 cmd != NL80211_CMD_DEL_INTERFACE &&
3124 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003125
3126 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003127 if (!hdr)
3128 return -1;
3129
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003130 if (dev &&
3131 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003132 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003133 goto nla_put_failure;
3134
3135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3136 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003137 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3138 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003139 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003140 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3141 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003142 (cfg80211_rdev_list_generation << 2)) ||
3143 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003144 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003145
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003146 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003147 int ret;
3148 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003149
Johannes Berg683b6d32012-11-08 21:25:48 +01003150 ret = rdev_get_channel(rdev, wdev, &chandef);
3151 if (ret == 0) {
3152 if (nl80211_send_chandef(msg, &chandef))
3153 goto nla_put_failure;
3154 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003155 }
3156
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003157 if (rdev->ops->get_tx_power) {
3158 int dbm, ret;
3159
3160 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3161 if (ret == 0 &&
3162 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3163 DBM_TO_MBM(dbm)))
3164 goto nla_put_failure;
3165 }
3166
Johannes Berg44905262017-10-17 21:56:01 +02003167 wdev_lock(wdev);
3168 switch (wdev->iftype) {
3169 case NL80211_IFTYPE_AP:
3170 if (wdev->ssid_len &&
3171 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003172 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003173 break;
3174 case NL80211_IFTYPE_STATION:
3175 case NL80211_IFTYPE_P2P_CLIENT:
3176 case NL80211_IFTYPE_ADHOC: {
3177 const u8 *ssid_ie;
3178 if (!wdev->current_bss)
3179 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003180 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003181 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3182 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003183 if (ssid_ie &&
3184 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3185 goto nla_put_failure_rcu_locked;
3186 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003187 break;
3188 }
3189 default:
3190 /* nothing */
3191 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003192 }
Johannes Berg44905262017-10-17 21:56:01 +02003193 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003194
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003195 if (rdev->ops->get_txq_stats) {
3196 struct cfg80211_txq_stats txqstats = {};
3197 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3198
3199 if (ret == 0 &&
3200 !nl80211_put_txq_stats(msg, &txqstats,
3201 NL80211_ATTR_TXQ_STATS))
3202 goto nla_put_failure;
3203 }
3204
Johannes Berg053c0952015-01-16 22:09:00 +01003205 genlmsg_end(msg, hdr);
3206 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003207
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003208 nla_put_failure_rcu_locked:
3209 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003210 nla_put_failure_locked:
3211 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003212 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003213 genlmsg_cancel(msg, hdr);
3214 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003215}
3216
3217static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3218{
3219 int wp_idx = 0;
3220 int if_idx = 0;
3221 int wp_start = cb->args[0];
3222 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003223 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003224 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003225 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003226 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003227
Johannes Berg5fe231e2013-05-08 21:45:15 +02003228 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003229 if (!cb->args[2]) {
3230 struct nl80211_dump_wiphy_state state = {
3231 .filter_wiphy = -1,
3232 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003233
3234 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3235 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003236 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003237
3238 filter_wiphy = state.filter_wiphy;
3239
3240 /*
3241 * if filtering, set cb->args[2] to +1 since 0 is the default
3242 * value needed to determine that parsing is necessary.
3243 */
3244 if (filter_wiphy >= 0)
3245 cb->args[2] = filter_wiphy + 1;
3246 else
3247 cb->args[2] = -1;
3248 } else if (cb->args[2] > 0) {
3249 filter_wiphy = cb->args[2] - 1;
3250 }
3251
Johannes Bergf5ea9122009-08-07 16:17:38 +02003252 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3253 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003254 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003255 if (wp_idx < wp_start) {
3256 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003257 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003258 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003259
3260 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3261 continue;
3262
Johannes Berg55682962007-09-20 13:09:35 -04003263 if_idx = 0;
3264
Johannes Berg53873f12016-05-03 16:52:04 +03003265 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003266 if (if_idx < if_start) {
3267 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003268 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003269 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003270 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003271 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003272 rdev, wdev,
3273 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003274 goto out;
3275 }
3276 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003277 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003278
3279 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003280 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003281 out:
Johannes Berg55682962007-09-20 13:09:35 -04003282 cb->args[0] = wp_idx;
3283 cb->args[1] = if_idx;
3284
Johannes Bergea90e0d2017-03-15 14:26:04 +01003285 ret = skb->len;
3286 out_unlock:
3287 rtnl_unlock();
3288
3289 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003290}
3291
3292static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3293{
3294 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003296 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003297
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003299 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003300 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003301
Eric W. Biederman15e47302012-09-07 20:12:54 +00003302 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003303 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003304 nlmsg_free(msg);
3305 return -ENOBUFS;
3306 }
Johannes Berg55682962007-09-20 13:09:35 -04003307
Johannes Berg134e6372009-07-10 09:51:34 +00003308 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003309}
3310
Michael Wu66f7ac52008-01-31 19:48:22 +01003311static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3312 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3313 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3314 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3315 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3316 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003317 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003318};
3319
3320static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3321{
3322 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3323 int flag;
3324
3325 *mntrflags = 0;
3326
3327 if (!nla)
3328 return -EINVAL;
3329
Johannes Berg8cb08172019-04-26 14:07:28 +02003330 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003331 return -EINVAL;
3332
3333 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3334 if (flags[flag])
3335 *mntrflags |= (1<<flag);
3336
Johannes Berg818a9862017-04-12 11:23:28 +02003337 *mntrflags |= MONITOR_FLAG_CHANGED;
3338
Michael Wu66f7ac52008-01-31 19:48:22 +01003339 return 0;
3340}
3341
Johannes Berg1db77592017-04-12 11:36:31 +02003342static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3343 enum nl80211_iftype type,
3344 struct genl_info *info,
3345 struct vif_params *params)
3346{
3347 bool change = false;
3348 int err;
3349
3350 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3351 if (type != NL80211_IFTYPE_MONITOR)
3352 return -EINVAL;
3353
3354 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3355 &params->flags);
3356 if (err)
3357 return err;
3358
3359 change = true;
3360 }
3361
3362 if (params->flags & MONITOR_FLAG_ACTIVE &&
3363 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3364 return -EOPNOTSUPP;
3365
3366 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3367 const u8 *mumimo_groups;
3368 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3369
3370 if (type != NL80211_IFTYPE_MONITOR)
3371 return -EINVAL;
3372
3373 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3374 return -EOPNOTSUPP;
3375
3376 mumimo_groups =
3377 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3378
3379 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003380 if ((mumimo_groups[0] & BIT(0)) ||
3381 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003382 return -EINVAL;
3383
3384 params->vht_mumimo_groups = mumimo_groups;
3385 change = true;
3386 }
3387
3388 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3389 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3390
3391 if (type != NL80211_IFTYPE_MONITOR)
3392 return -EINVAL;
3393
3394 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3395 return -EOPNOTSUPP;
3396
3397 params->vht_mumimo_follow_addr =
3398 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3399 change = true;
3400 }
3401
3402 return change ? 1 : 0;
3403}
3404
Johannes Berg9bc383d2009-11-19 11:55:19 +01003405static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003406 struct net_device *netdev, u8 use_4addr,
3407 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003408{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003409 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003410 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003411 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003412 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003413 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003414
3415 switch (iftype) {
3416 case NL80211_IFTYPE_AP_VLAN:
3417 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3418 return 0;
3419 break;
3420 case NL80211_IFTYPE_STATION:
3421 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3422 return 0;
3423 break;
3424 default:
3425 break;
3426 }
3427
3428 return -EOPNOTSUPP;
3429}
3430
Johannes Berg55682962007-09-20 13:09:35 -04003431static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3432{
Johannes Berg4c476992010-10-04 21:36:35 +02003433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003434 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003435 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003436 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003437 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003438 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003439
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003440 memset(&params, 0, sizeof(params));
3441
Johannes Berg04a773a2009-04-19 21:24:32 +02003442 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003443
Johannes Berg723b0382008-09-16 20:22:09 +02003444 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003445 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003446 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003447 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003448 }
3449
Johannes Berg92ffe052008-09-16 20:39:36 +02003450 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003451 struct wireless_dev *wdev = dev->ieee80211_ptr;
3452
Johannes Berg4c476992010-10-04 21:36:35 +02003453 if (ntype != NL80211_IFTYPE_MESH_POINT)
3454 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003455 if (netif_running(dev))
3456 return -EBUSY;
3457
3458 wdev_lock(wdev);
3459 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3460 IEEE80211_MAX_MESH_ID_LEN);
3461 wdev->mesh_id_up_len =
3462 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3463 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3464 wdev->mesh_id_up_len);
3465 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003466 }
3467
Felix Fietkau8b787642009-11-10 18:53:10 +01003468 if (info->attrs[NL80211_ATTR_4ADDR]) {
3469 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3470 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003471 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003472 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003473 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003474 } else {
3475 params.use_4addr = -1;
3476 }
3477
Johannes Berg1db77592017-04-12 11:36:31 +02003478 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3479 if (err < 0)
3480 return err;
3481 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003482 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003483
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003484 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003485 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003486 else
3487 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003488
Johannes Berg9bc383d2009-11-19 11:55:19 +01003489 if (!err && params.use_4addr != -1)
3490 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3491
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003492 if (change && !err) {
3493 struct wireless_dev *wdev = dev->ieee80211_ptr;
3494
3495 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3496 }
3497
Johannes Berg55682962007-09-20 13:09:35 -04003498 return err;
3499}
3500
3501static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3502{
Johannes Berg4c476992010-10-04 21:36:35 +02003503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003505 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003506 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003507 int err;
3508 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3509
Johannes Berg78f22b62014-03-24 17:57:27 +01003510 /* to avoid failing a new interface creation due to pending removal */
3511 cfg80211_destroy_ifaces(rdev);
3512
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003513 memset(&params, 0, sizeof(params));
3514
Johannes Berg55682962007-09-20 13:09:35 -04003515 if (!info->attrs[NL80211_ATTR_IFNAME])
3516 return -EINVAL;
3517
Johannes Bergab0d76f2018-10-02 10:00:07 +02003518 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003519 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003520
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303521 if (!rdev->ops->add_virtual_intf)
Johannes Berg4c476992010-10-04 21:36:35 +02003522 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003523
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003524 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003525 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3526 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003527 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3528 ETH_ALEN);
3529 if (!is_valid_ether_addr(params.macaddr))
3530 return -EADDRNOTAVAIL;
3531 }
3532
Johannes Berg9bc383d2009-11-19 11:55:19 +01003533 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003534 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003535 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003536 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003537 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003538 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003539
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303540 if (!(rdev->wiphy.interface_modes & (1 << type)) &&
3541 !(type == NL80211_IFTYPE_AP_VLAN && params.use_4addr &&
3542 rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP))
3543 return -EOPNOTSUPP;
3544
Johannes Berg1db77592017-04-12 11:36:31 +02003545 err = nl80211_parse_mon_options(rdev, type, info, &params);
3546 if (err < 0)
3547 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003548
Johannes Berga18c7192015-02-24 10:56:42 +01003549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3550 if (!msg)
3551 return -ENOMEM;
3552
Hila Gonene35e4d22012-06-27 17:19:42 +03003553 wdev = rdev_add_virtual_intf(rdev,
3554 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003555 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003556 if (WARN_ON(!wdev)) {
3557 nlmsg_free(msg);
3558 return -EPROTO;
3559 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003560 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003561 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003562 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003563
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003564 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003565 wdev->owner_nlportid = info->snd_portid;
3566
Johannes Berg98104fde2012-06-16 00:19:54 +02003567 switch (type) {
3568 case NL80211_IFTYPE_MESH_POINT:
3569 if (!info->attrs[NL80211_ATTR_MESH_ID])
3570 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003571 wdev_lock(wdev);
3572 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3573 IEEE80211_MAX_MESH_ID_LEN);
3574 wdev->mesh_id_up_len =
3575 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3576 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3577 wdev->mesh_id_up_len);
3578 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003579 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003580 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003581 case NL80211_IFTYPE_P2P_DEVICE:
3582 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003583 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003584 * through the netdev notifier and must be added here
3585 */
Johannes Berge4d42162018-09-13 14:12:03 +02003586 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003587 break;
3588 default:
3589 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003590 }
3591
Eric W. Biederman15e47302012-09-07 20:12:54 +00003592 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003593 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003594 nlmsg_free(msg);
3595 return -ENOBUFS;
3596 }
3597
3598 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003599}
3600
3601static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3602{
Johannes Berg4c476992010-10-04 21:36:35 +02003603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003604 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003605
Johannes Berg4c476992010-10-04 21:36:35 +02003606 if (!rdev->ops->del_virtual_intf)
3607 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003608
Johannes Berg84efbb82012-06-16 00:00:26 +02003609 /*
3610 * If we remove a wireless device without a netdev then clear
3611 * user_ptr[1] so that nl80211_post_doit won't dereference it
3612 * to check if it needs to do dev_put(). Otherwise it crashes
3613 * since the wdev has been freed, unlike with a netdev where
3614 * we need the dev_put() for the netdev to really be freed.
3615 */
3616 if (!wdev->netdev)
3617 info->user_ptr[1] = NULL;
3618
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003619 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003620}
3621
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003622static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3623{
3624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3625 struct net_device *dev = info->user_ptr[1];
3626 u16 noack_map;
3627
3628 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3629 return -EINVAL;
3630
3631 if (!rdev->ops->set_noack_map)
3632 return -EOPNOTSUPP;
3633
3634 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3635
Hila Gonene35e4d22012-06-27 17:19:42 +03003636 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003637}
3638
Johannes Berg41ade002007-12-19 02:03:29 +01003639struct get_key_cookie {
3640 struct sk_buff *msg;
3641 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003642 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003643};
3644
3645static void get_key_callback(void *c, struct key_params *params)
3646{
Johannes Bergb9454e82009-07-08 13:29:08 +02003647 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003648 struct get_key_cookie *cookie = c;
3649
David S. Miller9360ffd2012-03-29 04:41:26 -04003650 if ((params->key &&
3651 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3652 params->key_len, params->key)) ||
3653 (params->seq &&
3654 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3655 params->seq_len, params->seq)) ||
3656 (params->cipher &&
3657 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3658 params->cipher)))
3659 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003660
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003661 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003662 if (!key)
3663 goto nla_put_failure;
3664
David S. Miller9360ffd2012-03-29 04:41:26 -04003665 if ((params->key &&
3666 nla_put(cookie->msg, NL80211_KEY_DATA,
3667 params->key_len, params->key)) ||
3668 (params->seq &&
3669 nla_put(cookie->msg, NL80211_KEY_SEQ,
3670 params->seq_len, params->seq)) ||
3671 (params->cipher &&
3672 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3673 params->cipher)))
3674 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003675
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003676 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003677 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003678
3679 nla_nest_end(cookie->msg, key);
3680
Johannes Berg41ade002007-12-19 02:03:29 +01003681 return;
3682 nla_put_failure:
3683 cookie->error = 1;
3684}
3685
3686static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3687{
Johannes Berg4c476992010-10-04 21:36:35 +02003688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003689 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003690 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003691 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003692 const u8 *mac_addr = NULL;
3693 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003694 struct get_key_cookie cookie = {
3695 .error = 0,
3696 };
3697 void *hdr;
3698 struct sk_buff *msg;
3699
3700 if (info->attrs[NL80211_ATTR_KEY_IDX])
3701 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3702
Johannes Berg41ade002007-12-19 02:03:29 +01003703 if (info->attrs[NL80211_ATTR_MAC])
3704 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3705
Johannes Berge31b8212010-10-05 19:39:30 +02003706 pairwise = !!mac_addr;
3707 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3708 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003709
Johannes Berge31b8212010-10-05 19:39:30 +02003710 if (kt != NL80211_KEYTYPE_GROUP &&
3711 kt != NL80211_KEYTYPE_PAIRWISE)
3712 return -EINVAL;
3713 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3714 }
3715
Johannes Berg4c476992010-10-04 21:36:35 +02003716 if (!rdev->ops->get_key)
3717 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003718
Johannes Berg0fa7b392015-01-23 11:10:12 +01003719 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3720 return -ENOENT;
3721
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003723 if (!msg)
3724 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003725
Eric W. Biederman15e47302012-09-07 20:12:54 +00003726 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003727 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003728 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003729 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003730
3731 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003732 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003733
David S. Miller9360ffd2012-03-29 04:41:26 -04003734 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3735 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3736 goto nla_put_failure;
3737 if (mac_addr &&
3738 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3739 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003740
Hila Gonene35e4d22012-06-27 17:19:42 +03003741 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3742 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003743
3744 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003745 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003746
3747 if (cookie.error)
3748 goto nla_put_failure;
3749
3750 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003751 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003752
3753 nla_put_failure:
3754 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003755 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003756 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003757 return err;
3758}
3759
3760static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3761{
Johannes Berg4c476992010-10-04 21:36:35 +02003762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003763 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003764 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003765 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003766
Johannes Bergb9454e82009-07-08 13:29:08 +02003767 err = nl80211_parse_key(info, &key);
3768 if (err)
3769 return err;
3770
3771 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003772 return -EINVAL;
3773
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003774 /* Only support setting default key and
3775 * Extended Key ID action NL80211_KEY_SET_TX.
3776 */
3777 if (!key.def && !key.defmgmt &&
3778 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01003779 return -EINVAL;
3780
Johannes Bergfffd0932009-07-08 14:22:54 +02003781 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003782
3783 if (key.def) {
3784 if (!rdev->ops->set_default_key) {
3785 err = -EOPNOTSUPP;
3786 goto out;
3787 }
3788
3789 err = nl80211_key_allowed(dev->ieee80211_ptr);
3790 if (err)
3791 goto out;
3792
Hila Gonene35e4d22012-06-27 17:19:42 +03003793 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003794 key.def_uni, key.def_multi);
3795
3796 if (err)
3797 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003798
Johannes Berg3d23e342009-09-29 23:27:28 +02003799#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003800 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003801#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003802 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003803 if (key.def_uni || !key.def_multi) {
3804 err = -EINVAL;
3805 goto out;
3806 }
3807
3808 if (!rdev->ops->set_default_mgmt_key) {
3809 err = -EOPNOTSUPP;
3810 goto out;
3811 }
3812
3813 err = nl80211_key_allowed(dev->ieee80211_ptr);
3814 if (err)
3815 goto out;
3816
Hila Gonene35e4d22012-06-27 17:19:42 +03003817 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003818 if (err)
3819 goto out;
3820
3821#ifdef CONFIG_CFG80211_WEXT
3822 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3823#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003824 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3825 wiphy_ext_feature_isset(&rdev->wiphy,
3826 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3827 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003828
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003829 if (info->attrs[NL80211_ATTR_MAC])
3830 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3831
3832 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3833 err = -EINVAL;
3834 goto out;
3835 }
3836
3837 err = rdev_add_key(rdev, dev, key.idx,
3838 NL80211_KEYTYPE_PAIRWISE,
3839 mac_addr, &key.p);
3840 } else {
3841 err = -EINVAL;
3842 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003843 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003844 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003845
Johannes Berg41ade002007-12-19 02:03:29 +01003846 return err;
3847}
3848
3849static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3850{
Johannes Berg4c476992010-10-04 21:36:35 +02003851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003852 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003853 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003854 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003855 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003856
Johannes Bergb9454e82009-07-08 13:29:08 +02003857 err = nl80211_parse_key(info, &key);
3858 if (err)
3859 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003860
Johannes Bergb9454e82009-07-08 13:29:08 +02003861 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003862 return -EINVAL;
3863
Johannes Berg41ade002007-12-19 02:03:29 +01003864 if (info->attrs[NL80211_ATTR_MAC])
3865 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3866
Johannes Berge31b8212010-10-05 19:39:30 +02003867 if (key.type == -1) {
3868 if (mac_addr)
3869 key.type = NL80211_KEYTYPE_PAIRWISE;
3870 else
3871 key.type = NL80211_KEYTYPE_GROUP;
3872 }
3873
3874 /* for now */
3875 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3876 key.type != NL80211_KEYTYPE_GROUP)
3877 return -EINVAL;
3878
Johannes Berg4c476992010-10-04 21:36:35 +02003879 if (!rdev->ops->add_key)
3880 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003881
Johannes Berge31b8212010-10-05 19:39:30 +02003882 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3883 key.type == NL80211_KEYTYPE_PAIRWISE,
3884 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003885 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003886
3887 wdev_lock(dev->ieee80211_ptr);
3888 err = nl80211_key_allowed(dev->ieee80211_ptr);
3889 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003890 err = rdev_add_key(rdev, dev, key.idx,
3891 key.type == NL80211_KEYTYPE_PAIRWISE,
3892 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003893 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003894
Johannes Berg41ade002007-12-19 02:03:29 +01003895 return err;
3896}
3897
3898static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3899{
Johannes Berg4c476992010-10-04 21:36:35 +02003900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003901 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003902 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003903 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003904 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003905
Johannes Bergb9454e82009-07-08 13:29:08 +02003906 err = nl80211_parse_key(info, &key);
3907 if (err)
3908 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003909
3910 if (info->attrs[NL80211_ATTR_MAC])
3911 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3912
Johannes Berge31b8212010-10-05 19:39:30 +02003913 if (key.type == -1) {
3914 if (mac_addr)
3915 key.type = NL80211_KEYTYPE_PAIRWISE;
3916 else
3917 key.type = NL80211_KEYTYPE_GROUP;
3918 }
3919
3920 /* for now */
3921 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3922 key.type != NL80211_KEYTYPE_GROUP)
3923 return -EINVAL;
3924
Johannes Berg4c476992010-10-04 21:36:35 +02003925 if (!rdev->ops->del_key)
3926 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003927
Johannes Bergfffd0932009-07-08 14:22:54 +02003928 wdev_lock(dev->ieee80211_ptr);
3929 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003930
Johannes Berg0fa7b392015-01-23 11:10:12 +01003931 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003932 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3933 err = -ENOENT;
3934
Johannes Bergfffd0932009-07-08 14:22:54 +02003935 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003936 err = rdev_del_key(rdev, dev, key.idx,
3937 key.type == NL80211_KEYTYPE_PAIRWISE,
3938 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003939
Johannes Berg3d23e342009-09-29 23:27:28 +02003940#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003941 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003942 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003943 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003944 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003945 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3946 }
3947#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003948 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003949
Johannes Berg41ade002007-12-19 02:03:29 +01003950 return err;
3951}
3952
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303953/* This function returns an error or the number of nested attributes */
3954static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3955{
3956 struct nlattr *attr;
3957 int n_entries = 0, tmp;
3958
3959 nla_for_each_nested(attr, nl_attr, tmp) {
3960 if (nla_len(attr) != ETH_ALEN)
3961 return -EINVAL;
3962
3963 n_entries++;
3964 }
3965
3966 return n_entries;
3967}
3968
3969/*
3970 * This function parses ACL information and allocates memory for ACL data.
3971 * On successful return, the calling function is responsible to free the
3972 * ACL buffer returned by this function.
3973 */
3974static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3975 struct genl_info *info)
3976{
3977 enum nl80211_acl_policy acl_policy;
3978 struct nlattr *attr;
3979 struct cfg80211_acl_data *acl;
3980 int i = 0, n_entries, tmp;
3981
3982 if (!wiphy->max_acl_mac_addrs)
3983 return ERR_PTR(-EOPNOTSUPP);
3984
3985 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3986 return ERR_PTR(-EINVAL);
3987
3988 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3989 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3990 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3991 return ERR_PTR(-EINVAL);
3992
3993 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3994 return ERR_PTR(-EINVAL);
3995
3996 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3997 if (n_entries < 0)
3998 return ERR_PTR(n_entries);
3999
4000 if (n_entries > wiphy->max_acl_mac_addrs)
4001 return ERR_PTR(-ENOTSUPP);
4002
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05004003 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304004 if (!acl)
4005 return ERR_PTR(-ENOMEM);
4006
4007 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4008 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4009 i++;
4010 }
4011
4012 acl->n_acl_entries = n_entries;
4013 acl->acl_policy = acl_policy;
4014
4015 return acl;
4016}
4017
4018static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4019{
4020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4021 struct net_device *dev = info->user_ptr[1];
4022 struct cfg80211_acl_data *acl;
4023 int err;
4024
4025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4027 return -EOPNOTSUPP;
4028
4029 if (!dev->ieee80211_ptr->beacon_interval)
4030 return -EINVAL;
4031
4032 acl = parse_acl_data(&rdev->wiphy, info);
4033 if (IS_ERR(acl))
4034 return PTR_ERR(acl);
4035
4036 err = rdev_set_mac_acl(rdev, dev, acl);
4037
4038 kfree(acl);
4039
4040 return err;
4041}
4042
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304043static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4044 u8 *rates, u8 rates_len)
4045{
4046 u8 i;
4047 u32 mask = 0;
4048
4049 for (i = 0; i < rates_len; i++) {
4050 int rate = (rates[i] & 0x7f) * 5;
4051 int ridx;
4052
4053 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4054 struct ieee80211_rate *srate =
4055 &sband->bitrates[ridx];
4056 if (rate == srate->bitrate) {
4057 mask |= 1 << ridx;
4058 break;
4059 }
4060 }
4061 if (ridx == sband->n_bitrates)
4062 return 0; /* rate not found */
4063 }
4064
4065 return mask;
4066}
4067
4068static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4069 u8 *rates, u8 rates_len,
4070 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4071{
4072 u8 i;
4073
4074 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4075
4076 for (i = 0; i < rates_len; i++) {
4077 int ridx, rbit;
4078
4079 ridx = rates[i] / 8;
4080 rbit = BIT(rates[i] % 8);
4081
4082 /* check validity */
4083 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4084 return false;
4085
4086 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004087 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304088 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4089 mcs[ridx] |= rbit;
4090 else
4091 return false;
4092 }
4093
4094 return true;
4095}
4096
4097static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4098{
4099 u16 mcs_mask = 0;
4100
4101 switch (vht_mcs_map) {
4102 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4103 break;
4104 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4105 mcs_mask = 0x00FF;
4106 break;
4107 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4108 mcs_mask = 0x01FF;
4109 break;
4110 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4111 mcs_mask = 0x03FF;
4112 break;
4113 default:
4114 break;
4115 }
4116
4117 return mcs_mask;
4118}
4119
4120static void vht_build_mcs_mask(u16 vht_mcs_map,
4121 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4122{
4123 u8 nss;
4124
4125 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4126 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4127 vht_mcs_map >>= 2;
4128 }
4129}
4130
4131static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4132 struct nl80211_txrate_vht *txrate,
4133 u16 mcs[NL80211_VHT_NSS_MAX])
4134{
4135 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4136 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4137 u8 i;
4138
4139 if (!sband->vht_cap.vht_supported)
4140 return false;
4141
4142 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4143
4144 /* Build vht_mcs_mask from VHT capabilities */
4145 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4146
4147 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4148 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4149 mcs[i] = txrate->mcs[i];
4150 else
4151 return false;
4152 }
4153
4154 return true;
4155}
4156
4157static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4158 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4159 .len = NL80211_MAX_SUPP_RATES },
4160 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4161 .len = NL80211_MAX_SUPP_HT_RATES },
Johannes Berg180aa422019-05-28 14:19:07 +02004162 [NL80211_TXRATE_VHT] = {
4163 .type = NLA_EXACT_LEN_WARN,
4164 .len = sizeof(struct nl80211_txrate_vht),
4165 },
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304166 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4167};
4168
4169static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4170 struct cfg80211_bitrate_mask *mask)
4171{
4172 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4174 int rem, i;
4175 struct nlattr *tx_rates;
4176 struct ieee80211_supported_band *sband;
4177 u16 vht_tx_mcs_map;
4178
4179 memset(mask, 0, sizeof(*mask));
4180 /* Default to all rates enabled */
4181 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4182 sband = rdev->wiphy.bands[i];
4183
4184 if (!sband)
4185 continue;
4186
4187 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4188 memcpy(mask->control[i].ht_mcs,
4189 sband->ht_cap.mcs.rx_mask,
4190 sizeof(mask->control[i].ht_mcs));
4191
4192 if (!sband->vht_cap.vht_supported)
4193 continue;
4194
4195 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4196 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4197 }
4198
4199 /* if no rates are given set it back to the defaults */
4200 if (!info->attrs[NL80211_ATTR_TX_RATES])
4201 goto out;
4202
4203 /* The nested attribute uses enum nl80211_band as the index. This maps
4204 * directly to the enum nl80211_band values used in cfg80211.
4205 */
4206 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4207 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4208 enum nl80211_band band = nla_type(tx_rates);
4209 int err;
4210
4211 if (band < 0 || band >= NUM_NL80211_BANDS)
4212 return -EINVAL;
4213 sband = rdev->wiphy.bands[band];
4214 if (sband == NULL)
4215 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004216 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4217 tx_rates,
4218 nl80211_txattr_policy,
4219 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304220 if (err)
4221 return err;
4222 if (tb[NL80211_TXRATE_LEGACY]) {
4223 mask->control[band].legacy = rateset_to_mask(
4224 sband,
4225 nla_data(tb[NL80211_TXRATE_LEGACY]),
4226 nla_len(tb[NL80211_TXRATE_LEGACY]));
4227 if ((mask->control[band].legacy == 0) &&
4228 nla_len(tb[NL80211_TXRATE_LEGACY]))
4229 return -EINVAL;
4230 }
4231 if (tb[NL80211_TXRATE_HT]) {
4232 if (!ht_rateset_to_mask(
4233 sband,
4234 nla_data(tb[NL80211_TXRATE_HT]),
4235 nla_len(tb[NL80211_TXRATE_HT]),
4236 mask->control[band].ht_mcs))
4237 return -EINVAL;
4238 }
4239 if (tb[NL80211_TXRATE_VHT]) {
4240 if (!vht_set_mcs_mask(
4241 sband,
4242 nla_data(tb[NL80211_TXRATE_VHT]),
4243 mask->control[band].vht_mcs))
4244 return -EINVAL;
4245 }
4246 if (tb[NL80211_TXRATE_GI]) {
4247 mask->control[band].gi =
4248 nla_get_u8(tb[NL80211_TXRATE_GI]);
4249 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4250 return -EINVAL;
4251 }
4252
4253 if (mask->control[band].legacy == 0) {
4254 /* don't allow empty legacy rates if HT or VHT
4255 * are not even supported.
4256 */
4257 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4258 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4259 return -EINVAL;
4260
4261 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4262 if (mask->control[band].ht_mcs[i])
4263 goto out;
4264
4265 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4266 if (mask->control[band].vht_mcs[i])
4267 goto out;
4268
4269 /* legacy and mcs rates may not be both empty */
4270 return -EINVAL;
4271 }
4272 }
4273
4274out:
4275 return 0;
4276}
4277
Johannes Berg8564e382016-09-19 09:44:44 +02004278static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4279 enum nl80211_band band,
4280 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304281{
Johannes Berg8564e382016-09-19 09:44:44 +02004282 u32 count_ht, count_vht, i;
4283 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304284
4285 /* Allow only one rate */
4286 if (hweight32(rate) > 1)
4287 return -EINVAL;
4288
4289 count_ht = 0;
4290 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004291 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304292 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004293 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304294 count_ht++;
4295 if (count_ht > 1)
4296 return -EINVAL;
4297 }
4298 if (count_ht && rate)
4299 return -EINVAL;
4300 }
4301
4302 count_vht = 0;
4303 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004304 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304305 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004306 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304307 count_vht++;
4308 if (count_vht > 1)
4309 return -EINVAL;
4310 }
4311 if (count_vht && rate)
4312 return -EINVAL;
4313 }
4314
4315 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4316 return -EINVAL;
4317
Johannes Berg8564e382016-09-19 09:44:44 +02004318 if (rate &&
4319 !wiphy_ext_feature_isset(&rdev->wiphy,
4320 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4321 return -EINVAL;
4322 if (count_ht &&
4323 !wiphy_ext_feature_isset(&rdev->wiphy,
4324 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4325 return -EINVAL;
4326 if (count_vht &&
4327 !wiphy_ext_feature_isset(&rdev->wiphy,
4328 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4329 return -EINVAL;
4330
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304331 return 0;
4332}
4333
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004334static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4335 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004336 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004337{
Johannes Berg88600202012-02-13 15:17:18 +01004338 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004339 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004340
Johannes Berg88600202012-02-13 15:17:18 +01004341 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004342
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004343 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4344 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4345 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004346 if (!bcn->head_len)
4347 return -EINVAL;
4348 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004349 }
4350
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004351 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4352 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4353 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004354 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004355 }
4356
Johannes Berg4c476992010-10-04 21:36:35 +02004357 if (!haveinfo)
4358 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004359
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004360 if (attrs[NL80211_ATTR_IE]) {
4361 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4362 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004363 }
4364
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004365 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004366 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004367 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004368 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004369 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004370 }
4371
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004372 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004373 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004374 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004375 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004376 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004377 }
4378
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004379 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4380 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4381 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004382 }
4383
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004384 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4385 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4386
Johannes Berg8cb08172019-04-26 14:07:28 +02004387 err = nla_parse_nested_deprecated(tb,
4388 NL80211_FTM_RESP_ATTR_MAX,
4389 attrs[NL80211_ATTR_FTM_RESPONDER],
4390 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004391 if (err)
4392 return err;
4393
4394 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4395 wiphy_ext_feature_isset(&rdev->wiphy,
4396 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4397 bcn->ftm_responder = 1;
4398 else
4399 return -EOPNOTSUPP;
4400
4401 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4402 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4403 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4404 }
4405
4406 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4407 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4408 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4409 }
4410 } else {
4411 bcn->ftm_responder = -1;
4412 }
4413
Johannes Berg88600202012-02-13 15:17:18 +01004414 return 0;
4415}
4416
John Crispin796e90f2019-07-30 18:37:00 +02004417static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4418 struct ieee80211_he_obss_pd *he_obss_pd)
4419{
4420 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4421 int err;
4422
4423 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4424 he_obss_pd_policy, NULL);
4425 if (err)
4426 return err;
4427
4428 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4429 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4430 return -EINVAL;
4431
4432 he_obss_pd->min_offset =
4433 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4434 he_obss_pd->max_offset =
4435 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4436
4437 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4438 return -EINVAL;
4439
4440 he_obss_pd->enable = true;
4441
4442 return 0;
4443}
4444
Johannes Berg66cd7942017-02-07 22:40:44 +02004445static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4446 const u8 *rates)
4447{
4448 int i;
4449
4450 if (!rates)
4451 return;
4452
4453 for (i = 0; i < rates[1]; i++) {
4454 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4455 params->ht_required = true;
4456 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4457 params->vht_required = true;
4458 }
4459}
4460
4461/*
4462 * Since the nl80211 API didn't include, from the beginning, attributes about
4463 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4464 * benefit of drivers that rebuild IEs in the firmware.
4465 */
4466static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4467{
4468 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004469 size_t ies_len = bcn->tail_len;
4470 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004471 const u8 *rates;
4472 const u8 *cap;
4473
4474 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4475 nl80211_check_ap_rate_selectors(params, rates);
4476
4477 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4478 nl80211_check_ap_rate_selectors(params, rates);
4479
4480 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4481 if (cap && cap[1] >= sizeof(*params->ht_cap))
4482 params->ht_cap = (void *)(cap + 2);
4483 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4484 if (cap && cap[1] >= sizeof(*params->vht_cap))
4485 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004486 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4487 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4488 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004489}
4490
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004491static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4492 struct cfg80211_ap_settings *params)
4493{
4494 struct wireless_dev *wdev;
4495 bool ret = false;
4496
Johannes Berg53873f12016-05-03 16:52:04 +03004497 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004498 if (wdev->iftype != NL80211_IFTYPE_AP &&
4499 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4500 continue;
4501
Johannes Berg683b6d32012-11-08 21:25:48 +01004502 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004503 continue;
4504
Johannes Berg683b6d32012-11-08 21:25:48 +01004505 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004506 ret = true;
4507 break;
4508 }
4509
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004510 return ret;
4511}
4512
Jouni Malinene39e5b52012-09-30 19:29:39 +03004513static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4514 enum nl80211_auth_type auth_type,
4515 enum nl80211_commands cmd)
4516{
4517 if (auth_type > NL80211_AUTHTYPE_MAX)
4518 return false;
4519
4520 switch (cmd) {
4521 case NL80211_CMD_AUTHENTICATE:
4522 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4523 auth_type == NL80211_AUTHTYPE_SAE)
4524 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004525 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4526 NL80211_EXT_FEATURE_FILS_STA) &&
4527 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4528 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4529 auth_type == NL80211_AUTHTYPE_FILS_PK))
4530 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004531 return true;
4532 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004533 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00004534 !wiphy_ext_feature_isset(&rdev->wiphy,
4535 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02004536 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004537 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004538
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004539 /* FILS with SK PFS or PK not supported yet */
4540 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4541 auth_type == NL80211_AUTHTYPE_FILS_PK)
4542 return false;
4543 if (!wiphy_ext_feature_isset(
4544 &rdev->wiphy,
4545 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4546 auth_type == NL80211_AUTHTYPE_FILS_SK)
4547 return false;
4548 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004549 case NL80211_CMD_START_AP:
4550 /* SAE not supported yet */
4551 if (auth_type == NL80211_AUTHTYPE_SAE)
4552 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004553 /* FILS not supported yet */
4554 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4555 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4556 auth_type == NL80211_AUTHTYPE_FILS_PK)
4557 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004558 return true;
4559 default:
4560 return false;
4561 }
4562}
4563
Johannes Berg88600202012-02-13 15:17:18 +01004564static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4565{
4566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4567 struct net_device *dev = info->user_ptr[1];
4568 struct wireless_dev *wdev = dev->ieee80211_ptr;
4569 struct cfg80211_ap_settings params;
4570 int err;
4571
4572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4573 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4574 return -EOPNOTSUPP;
4575
4576 if (!rdev->ops->start_ap)
4577 return -EOPNOTSUPP;
4578
4579 if (wdev->beacon_interval)
4580 return -EALREADY;
4581
4582 memset(&params, 0, sizeof(params));
4583
4584 /* these are required for START_AP */
4585 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4586 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4587 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4588 return -EINVAL;
4589
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004590 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004591 if (err)
4592 return err;
4593
4594 params.beacon_interval =
4595 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4596 params.dtim_period =
4597 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4598
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304599 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4600 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004601 if (err)
4602 return err;
4603
4604 /*
4605 * In theory, some of these attributes should be required here
4606 * but since they were not used when the command was originally
4607 * added, keep them optional for old user space programs to let
4608 * them continue to work with drivers that do not need the
4609 * additional information -- drivers must check!
4610 */
4611 if (info->attrs[NL80211_ATTR_SSID]) {
4612 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4613 params.ssid_len =
4614 nla_len(info->attrs[NL80211_ATTR_SSID]);
4615 if (params.ssid_len == 0 ||
4616 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4617 return -EINVAL;
4618 }
4619
Johannes Bergab0d76f2018-10-02 10:00:07 +02004620 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004621 params.hidden_ssid = nla_get_u32(
4622 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004623
4624 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4625
4626 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4627 params.auth_type = nla_get_u32(
4628 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004629 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4630 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004631 return -EINVAL;
4632 } else
4633 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4634
4635 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4636 NL80211_MAX_NR_CIPHER_SUITES);
4637 if (err)
4638 return err;
4639
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304640 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4641 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4642 return -EOPNOTSUPP;
4643 params.inactivity_timeout = nla_get_u16(
4644 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4645 }
4646
Johannes Berg53cabad2012-11-14 15:17:28 +01004647 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4648 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4649 return -EINVAL;
4650 params.p2p_ctwindow =
4651 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004652 if (params.p2p_ctwindow != 0 &&
4653 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4654 return -EINVAL;
4655 }
4656
4657 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4658 u8 tmp;
4659
4660 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4661 return -EINVAL;
4662 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004663 params.p2p_opp_ps = tmp;
4664 if (params.p2p_opp_ps != 0 &&
4665 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4666 return -EINVAL;
4667 }
4668
Johannes Bergaa430da2012-05-16 23:50:18 +02004669 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004670 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4671 if (err)
4672 return err;
4673 } else if (wdev->preset_chandef.chan) {
4674 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004675 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004676 return -EINVAL;
4677
Arik Nemtsov923b3522015-07-08 15:41:44 +03004678 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4679 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004680 return -EINVAL;
4681
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304682 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4683 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4684 if (err)
4685 return err;
4686
Johannes Berg8564e382016-09-19 09:44:44 +02004687 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4688 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304689 if (err)
4690 return err;
4691 }
4692
Eliad Peller18998c32014-09-10 14:07:34 +03004693 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4694 params.smps_mode =
4695 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4696 switch (params.smps_mode) {
4697 case NL80211_SMPS_OFF:
4698 break;
4699 case NL80211_SMPS_STATIC:
4700 if (!(rdev->wiphy.features &
4701 NL80211_FEATURE_STATIC_SMPS))
4702 return -EINVAL;
4703 break;
4704 case NL80211_SMPS_DYNAMIC:
4705 if (!(rdev->wiphy.features &
4706 NL80211_FEATURE_DYNAMIC_SMPS))
4707 return -EINVAL;
4708 break;
4709 default:
4710 return -EINVAL;
4711 }
4712 } else {
4713 params.smps_mode = NL80211_SMPS_OFF;
4714 }
4715
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304716 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4717 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4718 return -EOPNOTSUPP;
4719
Ola Olsson4baf6be2015-10-29 07:04:58 +01004720 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4721 params.acl = parse_acl_data(&rdev->wiphy, info);
4722 if (IS_ERR(params.acl))
4723 return PTR_ERR(params.acl);
4724 }
4725
John Crispina0de1ca32019-05-28 13:49:48 +02004726 params.twt_responder =
4727 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
4728
John Crispin796e90f2019-07-30 18:37:00 +02004729 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
4730 err = nl80211_parse_he_obss_pd(
4731 info->attrs[NL80211_ATTR_HE_OBSS_PD],
4732 &params.he_obss_pd);
4733 if (err)
4734 return err;
4735 }
4736
Johannes Berg66cd7942017-02-07 22:40:44 +02004737 nl80211_calculate_ap_params(&params);
4738
Srinivas Dasarife494372019-01-23 18:06:56 +05304739 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4740 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4741
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004742 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004743 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004744 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004745 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004746 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004747 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004748 wdev->ssid_len = params.ssid_len;
4749 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004750
4751 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4752 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004753 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004754 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304755
4756 kfree(params.acl);
4757
Johannes Berg56d18932011-05-09 18:41:15 +02004758 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004759}
4760
Johannes Berg88600202012-02-13 15:17:18 +01004761static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4762{
4763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4764 struct net_device *dev = info->user_ptr[1];
4765 struct wireless_dev *wdev = dev->ieee80211_ptr;
4766 struct cfg80211_beacon_data params;
4767 int err;
4768
4769 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4770 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4771 return -EOPNOTSUPP;
4772
4773 if (!rdev->ops->change_beacon)
4774 return -EOPNOTSUPP;
4775
4776 if (!wdev->beacon_interval)
4777 return -EINVAL;
4778
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004779 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004780 if (err)
4781 return err;
4782
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004783 wdev_lock(wdev);
4784 err = rdev_change_beacon(rdev, dev, &params);
4785 wdev_unlock(wdev);
4786
4787 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004788}
4789
4790static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004791{
Johannes Berg4c476992010-10-04 21:36:35 +02004792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4793 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004794
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004795 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004796}
4797
Johannes Berg5727ef12007-12-19 02:03:34 +01004798static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4799 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4800 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4801 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004802 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004803 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004804 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004805};
4806
Johannes Bergeccb8e82009-05-11 21:57:56 +03004807static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004808 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004809 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004810{
4811 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004812 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004813 int flag;
4814
Johannes Bergeccb8e82009-05-11 21:57:56 +03004815 /*
4816 * Try parsing the new attribute first so userspace
4817 * can specify both for older kernels.
4818 */
4819 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4820 if (nla) {
4821 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004822
Johannes Bergeccb8e82009-05-11 21:57:56 +03004823 sta_flags = nla_data(nla);
4824 params->sta_flags_mask = sta_flags->mask;
4825 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004826 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004827 if ((params->sta_flags_mask |
4828 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4829 return -EINVAL;
4830 return 0;
4831 }
4832
4833 /* if present, parse the old attribute */
4834
4835 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004836 if (!nla)
4837 return 0;
4838
Johannes Berg8cb08172019-04-26 14:07:28 +02004839 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004840 return -EINVAL;
4841
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004842 /*
4843 * Only allow certain flags for interface types so that
4844 * other attributes are silently ignored. Remember that
4845 * this is backward compatibility code with old userspace
4846 * and shouldn't be hit in other cases anyway.
4847 */
4848 switch (iftype) {
4849 case NL80211_IFTYPE_AP:
4850 case NL80211_IFTYPE_AP_VLAN:
4851 case NL80211_IFTYPE_P2P_GO:
4852 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4853 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4854 BIT(NL80211_STA_FLAG_WME) |
4855 BIT(NL80211_STA_FLAG_MFP);
4856 break;
4857 case NL80211_IFTYPE_P2P_CLIENT:
4858 case NL80211_IFTYPE_STATION:
4859 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4860 BIT(NL80211_STA_FLAG_TDLS_PEER);
4861 break;
4862 case NL80211_IFTYPE_MESH_POINT:
4863 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4864 BIT(NL80211_STA_FLAG_MFP) |
4865 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004866 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004867 default:
4868 return -EINVAL;
4869 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004870
Johannes Berg3383b5a2012-05-10 20:14:43 +02004871 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4872 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004873 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004874
Johannes Berg3383b5a2012-05-10 20:14:43 +02004875 /* no longer support new API additions in old API */
4876 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4877 return -EINVAL;
4878 }
4879 }
4880
Johannes Berg5727ef12007-12-19 02:03:34 +01004881 return 0;
4882}
4883
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004884bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004885{
4886 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004887 u32 bitrate;
4888 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004889 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004890
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004891 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004892 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004893 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004894
4895 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4896 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004897 /* report 16-bit bitrate only if we can */
4898 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004899 if (bitrate > 0 &&
4900 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4901 return false;
4902 if (bitrate_compat > 0 &&
4903 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4904 return false;
4905
Johannes Bergb51f3be2015-01-15 16:14:02 +01004906 switch (info->bw) {
4907 case RATE_INFO_BW_5:
4908 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4909 break;
4910 case RATE_INFO_BW_10:
4911 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4912 break;
4913 default:
4914 WARN_ON(1);
4915 /* fall through */
4916 case RATE_INFO_BW_20:
4917 rate_flg = 0;
4918 break;
4919 case RATE_INFO_BW_40:
4920 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4921 break;
4922 case RATE_INFO_BW_80:
4923 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4924 break;
4925 case RATE_INFO_BW_160:
4926 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4927 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004928 case RATE_INFO_BW_HE_RU:
4929 rate_flg = 0;
4930 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004931 }
4932
4933 if (rate_flg && nla_put_flag(msg, rate_flg))
4934 return false;
4935
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004936 if (info->flags & RATE_INFO_FLAGS_MCS) {
4937 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4938 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004939 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4940 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4941 return false;
4942 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4943 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4944 return false;
4945 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4946 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004947 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4948 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4949 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004950 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4951 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4952 return false;
4953 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4954 return false;
4955 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4956 return false;
4957 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4958 return false;
4959 if (info->bw == RATE_INFO_BW_HE_RU &&
4960 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4961 info->he_ru_alloc))
4962 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004963 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004964
4965 nla_nest_end(msg, rate);
4966 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004967}
4968
Felix Fietkau119363c2013-04-22 16:29:30 +02004969static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4970 int id)
4971{
4972 void *attr;
4973 int i = 0;
4974
4975 if (!mask)
4976 return true;
4977
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004978 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02004979 if (!attr)
4980 return false;
4981
4982 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4983 if (!(mask & BIT(i)))
4984 continue;
4985
4986 if (nla_put_u8(msg, i, signal[i]))
4987 return false;
4988 }
4989
4990 nla_nest_end(msg, attr);
4991
4992 return true;
4993}
4994
Johannes Bergcf5ead82014-11-14 17:14:00 +01004995static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4996 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004997 struct cfg80211_registered_device *rdev,
4998 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004999 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005000{
5001 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07005002 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005003
Johannes Bergcf5ead82014-11-14 17:14:00 +01005004 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Andy Strohmanf77bf482019-05-24 23:27:29 -07005005 if (!hdr) {
5006 cfg80211_sinfo_release_content(sinfo);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005007 return -1;
Andy Strohmanf77bf482019-05-24 23:27:29 -07005008 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005009
David S. Miller9360ffd2012-03-29 04:41:26 -04005010 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5011 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5012 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5013 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005014
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005015 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005016 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005017 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005018
5019#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02005020 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03005021 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01005022 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5023 sinfo->memb)) \
5024 goto nla_put_failure; \
5025 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02005026#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03005027 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005028 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5029 sinfo->memb, NL80211_STA_INFO_PAD)) \
5030 goto nla_put_failure; \
5031 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01005032
5033 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5034 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
5035
Omer Efrat397c6572018-06-17 13:06:14 +03005036 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5037 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005038 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005039 (u32)sinfo->rx_bytes))
5040 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005041
Omer Efrat397c6572018-06-17 13:06:14 +03005042 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5043 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005044 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5045 (u32)sinfo->tx_bytes))
5046 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005047
Johannes Bergd686b922016-04-26 09:54:11 +02005048 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5049 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01005050 PUT_SINFO(LLID, llid, u16);
5051 PUT_SINFO(PLID, plid, u16);
5052 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02005053 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005054 PUT_SINFO_U64(TX_DURATION, tx_duration);
5055
5056 if (wiphy_ext_feature_isset(&rdev->wiphy,
5057 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5058 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01005059
John W. Linville66266b32012-03-15 13:25:41 -04005060 switch (rdev->wiphy.signal_type) {
5061 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01005062 PUT_SINFO(SIGNAL, signal, u8);
5063 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04005064 break;
5065 default:
5066 break;
5067 }
Omer Efrat397c6572018-06-17 13:06:14 +03005068 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005069 if (!nl80211_put_signal(msg, sinfo->chains,
5070 sinfo->chain_signal,
5071 NL80211_STA_INFO_CHAIN_SIGNAL))
5072 goto nla_put_failure;
5073 }
Omer Efrat397c6572018-06-17 13:06:14 +03005074 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005075 if (!nl80211_put_signal(msg, sinfo->chains,
5076 sinfo->chain_signal_avg,
5077 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5078 goto nla_put_failure;
5079 }
Omer Efrat397c6572018-06-17 13:06:14 +03005080 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005081 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5082 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01005083 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005084 }
Omer Efrat397c6572018-06-17 13:06:14 +03005085 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005086 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5087 NL80211_STA_INFO_RX_BITRATE))
5088 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01005089 }
Johannes Berg319090b2014-11-17 14:08:11 +01005090
5091 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5092 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5093 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5094 PUT_SINFO(TX_FAILED, tx_failed, u32);
5095 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08005096 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01005097 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5098 PUT_SINFO(LOCAL_PM, local_pm, u32);
5099 PUT_SINFO(PEER_PM, peer_pm, u32);
5100 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04005101 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01005102
Omer Efrat397c6572018-06-17 13:06:14 +03005103 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005104 bss_param = nla_nest_start_noflag(msg,
5105 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005106 if (!bss_param)
5107 goto nla_put_failure;
5108
David S. Miller9360ffd2012-03-29 04:41:26 -04005109 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5110 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5111 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5112 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5113 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5114 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5115 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5116 sinfo->bss_param.dtim_period) ||
5117 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5118 sinfo->bss_param.beacon_interval))
5119 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005120
5121 nla_nest_end(msg, bss_param);
5122 }
Omer Efrat397c6572018-06-17 13:06:14 +03005123 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005124 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5125 sizeof(struct nl80211_sta_flag_update),
5126 &sinfo->sta_flags))
5127 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005128
Johannes Bergd686b922016-04-26 09:54:11 +02005129 PUT_SINFO_U64(T_OFFSET, t_offset);
5130 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5131 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005132 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005133 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5134 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305135 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305136 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5137 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5138 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5139 }
Johannes Berg319090b2014-11-17 14:08:11 +01005140
5141#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005142#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005143
Arend van Spriel8689c052018-05-10 13:50:12 +02005144 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005145 struct nlattr *tidsattr;
5146 int tid;
5147
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005148 tidsattr = nla_nest_start_noflag(msg,
5149 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005150 if (!tidsattr)
5151 goto nla_put_failure;
5152
5153 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5154 struct cfg80211_tid_stats *tidstats;
5155 struct nlattr *tidattr;
5156
5157 tidstats = &sinfo->pertid[tid];
5158
5159 if (!tidstats->filled)
5160 continue;
5161
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005162 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005163 if (!tidattr)
5164 goto nla_put_failure;
5165
Johannes Bergd686b922016-04-26 09:54:11 +02005166#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005167 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005168 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5169 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005170 goto nla_put_failure; \
5171 } while (0)
5172
Johannes Bergd686b922016-04-26 09:54:11 +02005173 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5174 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5175 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5176 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005177
Johannes Bergd686b922016-04-26 09:54:11 +02005178#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005179 if ((tidstats->filled &
5180 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5181 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5182 NL80211_TID_STATS_TXQ_STATS))
5183 goto nla_put_failure;
5184
Johannes Berg6de39802014-12-19 12:34:00 +01005185 nla_nest_end(msg, tidattr);
5186 }
5187
5188 nla_nest_end(msg, tidsattr);
5189 }
5190
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005191 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005192
Johannes Berg319090b2014-11-17 14:08:11 +01005193 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005194 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5195 sinfo->assoc_req_ies))
5196 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005197
Johannes Berg7ea3e112018-05-18 11:40:44 +02005198 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005199 genlmsg_end(msg, hdr);
5200 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005201
5202 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005203 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005204 genlmsg_cancel(msg, hdr);
5205 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005206}
5207
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005208static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005209 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005210{
Johannes Berg73887fd2018-05-18 09:57:55 +02005211 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005212 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005213 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005214 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005215 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005216 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005217
Johannes Bergea90e0d2017-03-15 14:26:04 +01005218 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005219 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005220 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005221 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005222
Johannes Berg97990a02013-04-19 01:02:55 +02005223 if (!wdev->netdev) {
5224 err = -EINVAL;
5225 goto out_err;
5226 }
5227
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005228 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005229 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005230 goto out_err;
5231 }
5232
Johannes Bergbba95fe2008-07-29 13:22:51 +02005233 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005234 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005235 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005236 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005237 if (err == -ENOENT)
5238 break;
5239 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005240 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005241
Johannes Bergcf5ead82014-11-14 17:14:00 +01005242 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005243 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005244 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005245 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005246 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005247 goto out;
5248
5249 sta_idx++;
5250 }
5251
Johannes Bergbba95fe2008-07-29 13:22:51 +02005252 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005253 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005254 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005255 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005256 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005257
5258 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005259}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005260
Johannes Berg5727ef12007-12-19 02:03:34 +01005261static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5262{
Johannes Berg4c476992010-10-04 21:36:35 +02005263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5264 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005265 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005266 struct sk_buff *msg;
5267 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005268 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005269
Johannes Berg73887fd2018-05-18 09:57:55 +02005270 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005271
Johannes Berg73887fd2018-05-18 09:57:55 +02005272 if (!info->attrs[NL80211_ATTR_MAC])
5273 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005274
5275 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5276
Johannes Berg73887fd2018-05-18 09:57:55 +02005277 if (!rdev->ops->get_station)
5278 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005279
Johannes Berg73887fd2018-05-18 09:57:55 +02005280 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005281 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005282 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005283
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005285 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005286 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005287 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005288 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005289
Johannes Bergcf5ead82014-11-14 17:14:00 +01005290 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5291 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005292 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005293 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005294 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005295 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005296
Johannes Berg73887fd2018-05-18 09:57:55 +02005297 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005298}
5299
Johannes Berg77ee7c82013-02-15 00:48:33 +01005300int cfg80211_check_station_change(struct wiphy *wiphy,
5301 struct station_parameters *params,
5302 enum cfg80211_station_type statype)
5303{
Ayala Bekere4208422015-10-23 11:20:06 +03005304 if (params->listen_interval != -1 &&
5305 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005306 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005307
Ayala Beker17b94242016-03-17 15:41:38 +02005308 if (params->support_p2p_ps != -1 &&
5309 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5310 return -EINVAL;
5311
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005312 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005313 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5314 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005315 return -EINVAL;
5316
5317 /* When you run into this, adjust the code below for the new flag */
5318 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5319
5320 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005321 case CFG80211_STA_MESH_PEER_KERNEL:
5322 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005323 /*
5324 * No ignoring the TDLS flag here -- the userspace mesh
5325 * code doesn't have the bug of including TDLS in the
5326 * mask everywhere.
5327 */
5328 if (params->sta_flags_mask &
5329 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5330 BIT(NL80211_STA_FLAG_MFP) |
5331 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5332 return -EINVAL;
5333 break;
5334 case CFG80211_STA_TDLS_PEER_SETUP:
5335 case CFG80211_STA_TDLS_PEER_ACTIVE:
5336 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5337 return -EINVAL;
5338 /* ignore since it can't change */
5339 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5340 break;
5341 default:
5342 /* disallow mesh-specific things */
5343 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5344 return -EINVAL;
5345 if (params->local_pm)
5346 return -EINVAL;
5347 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5348 return -EINVAL;
5349 }
5350
5351 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5352 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5353 /* TDLS can't be set, ... */
5354 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5355 return -EINVAL;
5356 /*
5357 * ... but don't bother the driver with it. This works around
5358 * a hostapd/wpa_supplicant issue -- it always includes the
5359 * TLDS_PEER flag in the mask even for AP mode.
5360 */
5361 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5362 }
5363
Ayala Beker47edb112015-09-21 15:49:53 +03005364 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5365 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005366 /* reject other things that can't change */
5367 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5368 return -EINVAL;
5369 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5370 return -EINVAL;
5371 if (params->supported_rates)
5372 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005373 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5374 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005375 return -EINVAL;
5376 }
5377
Ayala Beker47edb112015-09-21 15:49:53 +03005378 if (statype != CFG80211_STA_AP_CLIENT &&
5379 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005380 if (params->vlan)
5381 return -EINVAL;
5382 }
5383
5384 switch (statype) {
5385 case CFG80211_STA_AP_MLME_CLIENT:
5386 /* Use this only for authorizing/unauthorizing a station */
5387 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5388 return -EOPNOTSUPP;
5389 break;
5390 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005391 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005392 /* accept only the listed bits */
5393 if (params->sta_flags_mask &
5394 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5395 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5396 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5397 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5398 BIT(NL80211_STA_FLAG_WME) |
5399 BIT(NL80211_STA_FLAG_MFP)))
5400 return -EINVAL;
5401
5402 /* but authenticated/associated only if driver handles it */
5403 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5404 params->sta_flags_mask &
5405 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5406 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5407 return -EINVAL;
5408 break;
5409 case CFG80211_STA_IBSS:
5410 case CFG80211_STA_AP_STA:
5411 /* reject any changes other than AUTHORIZED */
5412 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5413 return -EINVAL;
5414 break;
5415 case CFG80211_STA_TDLS_PEER_SETUP:
5416 /* reject any changes other than AUTHORIZED or WME */
5417 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5418 BIT(NL80211_STA_FLAG_WME)))
5419 return -EINVAL;
5420 /* force (at least) rates when authorizing */
5421 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5422 !params->supported_rates)
5423 return -EINVAL;
5424 break;
5425 case CFG80211_STA_TDLS_PEER_ACTIVE:
5426 /* reject any changes */
5427 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005428 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005429 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5430 return -EINVAL;
5431 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005432 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005433 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5434 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005435 return -EINVAL;
5436 break;
5437 }
5438
Beni Lev06f7c882016-07-19 19:28:56 +03005439 /*
5440 * Older kernel versions ignored this attribute entirely, so don't
5441 * reject attempts to update it but mark it as unused instead so the
5442 * driver won't look at the data.
5443 */
5444 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5445 statype != CFG80211_STA_TDLS_PEER_SETUP)
5446 params->opmode_notif_used = false;
5447
Johannes Berg77ee7c82013-02-15 00:48:33 +01005448 return 0;
5449}
5450EXPORT_SYMBOL(cfg80211_check_station_change);
5451
Johannes Berg5727ef12007-12-19 02:03:34 +01005452/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005453 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005454 */
Johannes Berg80b99892011-11-18 16:23:01 +01005455static struct net_device *get_vlan(struct genl_info *info,
5456 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005457{
Johannes Berg463d0182009-07-14 00:33:35 +02005458 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005459 struct net_device *v;
5460 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005461
Johannes Berg80b99892011-11-18 16:23:01 +01005462 if (!vlanattr)
5463 return NULL;
5464
5465 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5466 if (!v)
5467 return ERR_PTR(-ENODEV);
5468
5469 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5470 ret = -EINVAL;
5471 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005472 }
Johannes Berg80b99892011-11-18 16:23:01 +01005473
Johannes Berg77ee7c82013-02-15 00:48:33 +01005474 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5475 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5476 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5477 ret = -EINVAL;
5478 goto error;
5479 }
5480
Johannes Berg80b99892011-11-18 16:23:01 +01005481 if (!netif_running(v)) {
5482 ret = -ENETDOWN;
5483 goto error;
5484 }
5485
5486 return v;
5487 error:
5488 dev_put(v);
5489 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005490}
5491
Johannes Berg94e860f2014-01-20 23:58:15 +01005492static const struct nla_policy
5493nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005494 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5495 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5496};
5497
Johannes Bergff276692013-02-15 00:09:01 +01005498static int nl80211_parse_sta_wme(struct genl_info *info,
5499 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005500{
Jouni Malinendf881292013-02-14 21:10:54 +02005501 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5502 struct nlattr *nla;
5503 int err;
5504
Jouni Malinendf881292013-02-14 21:10:54 +02005505 /* parse WME attributes if present */
5506 if (!info->attrs[NL80211_ATTR_STA_WME])
5507 return 0;
5508
5509 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02005510 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5511 nl80211_sta_wme_policy,
5512 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005513 if (err)
5514 return err;
5515
5516 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5517 params->uapsd_queues = nla_get_u8(
5518 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5519 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5520 return -EINVAL;
5521
5522 if (tb[NL80211_STA_WME_MAX_SP])
5523 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5524
5525 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5526 return -EINVAL;
5527
5528 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5529
5530 return 0;
5531}
5532
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305533static int nl80211_parse_sta_channel_info(struct genl_info *info,
5534 struct station_parameters *params)
5535{
5536 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5537 params->supported_channels =
5538 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5539 params->supported_channels_len =
5540 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5541 /*
5542 * Need to include at least one (first channel, number of
5543 * channels) tuple for each subband, and must have proper
5544 * tuples for the rest of the data as well.
5545 */
5546 if (params->supported_channels_len < 2)
5547 return -EINVAL;
5548 if (params->supported_channels_len % 2)
5549 return -EINVAL;
5550 }
5551
5552 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5553 params->supported_oper_classes =
5554 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5555 params->supported_oper_classes_len =
5556 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5557 /*
5558 * The value of the Length field of the Supported Operating
5559 * Classes element is between 2 and 253.
5560 */
5561 if (params->supported_oper_classes_len < 2 ||
5562 params->supported_oper_classes_len > 253)
5563 return -EINVAL;
5564 }
5565 return 0;
5566}
5567
Johannes Bergff276692013-02-15 00:09:01 +01005568static int nl80211_set_station_tdls(struct genl_info *info,
5569 struct station_parameters *params)
5570{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305571 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005572 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005573 if (info->attrs[NL80211_ATTR_PEER_AID])
5574 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005575 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5576 params->ht_capa =
5577 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5578 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5579 params->vht_capa =
5580 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005581 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5582 params->he_capa =
5583 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5584 params->he_capa_len =
5585 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5586
5587 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5588 return -EINVAL;
5589 }
Johannes Bergff276692013-02-15 00:09:01 +01005590
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305591 err = nl80211_parse_sta_channel_info(info, params);
5592 if (err)
5593 return err;
5594
Johannes Bergff276692013-02-15 00:09:01 +01005595 return nl80211_parse_sta_wme(info, params);
5596}
5597
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305598static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5599 struct station_parameters *params)
5600{
5601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5602 int idx;
5603
5604 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5605 if (!rdev->ops->set_tx_power ||
5606 !wiphy_ext_feature_isset(&rdev->wiphy,
5607 NL80211_EXT_FEATURE_STA_TX_PWR))
5608 return -EOPNOTSUPP;
5609
5610 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5611 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5612
5613 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5614 idx = NL80211_ATTR_STA_TX_POWER;
5615
5616 if (info->attrs[idx])
5617 params->txpwr.power =
5618 nla_get_s16(info->attrs[idx]);
5619 else
5620 return -EINVAL;
5621 }
5622 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5623 }
5624
5625 return 0;
5626}
5627
Johannes Berg5727ef12007-12-19 02:03:34 +01005628static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5629{
Johannes Berg4c476992010-10-04 21:36:35 +02005630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005631 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005632 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005633 u8 *mac_addr;
5634 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005635
5636 memset(&params, 0, sizeof(params));
5637
Johannes Berg77ee7c82013-02-15 00:48:33 +01005638 if (!rdev->ops->change_station)
5639 return -EOPNOTSUPP;
5640
Ayala Bekere4208422015-10-23 11:20:06 +03005641 /*
5642 * AID and listen_interval properties can be set only for unassociated
5643 * station. Include these parameters here and will check them in
5644 * cfg80211_check_station_change().
5645 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005646 if (info->attrs[NL80211_ATTR_STA_AID])
5647 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005648
5649 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5650 params.listen_interval =
5651 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5652 else
5653 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005654
Johannes Bergab0d76f2018-10-02 10:00:07 +02005655 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5656 params.support_p2p_ps =
5657 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5658 else
Ayala Beker17b94242016-03-17 15:41:38 +02005659 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005660
Johannes Berg5727ef12007-12-19 02:03:34 +01005661 if (!info->attrs[NL80211_ATTR_MAC])
5662 return -EINVAL;
5663
5664 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5665
5666 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5667 params.supported_rates =
5668 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5669 params.supported_rates_len =
5670 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5671 }
5672
Jouni Malinen9d62a982013-02-14 21:10:13 +02005673 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5674 params.capability =
5675 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5676 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5677 }
5678
5679 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5680 params.ext_capab =
5681 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5682 params.ext_capab_len =
5683 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5684 }
5685
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005686 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005687 return -EINVAL;
5688
Johannes Bergab0d76f2018-10-02 10:00:07 +02005689 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005690 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005691 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005692
Johannes Bergf8bacc22013-02-14 23:27:01 +01005693 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005694 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005695 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005696 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005697 params.peer_aid = nla_get_u16(
5698 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005699 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5700 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005701
Johannes Bergab0d76f2018-10-02 10:00:07 +02005702 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5703 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005704 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5705
Beni Lev06f7c882016-07-19 19:28:56 +03005706 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5707 params.opmode_notif_used = true;
5708 params.opmode_notif =
5709 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5710 }
5711
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005712 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5713 params.airtime_weight =
5714 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5715
5716 if (params.airtime_weight &&
5717 !wiphy_ext_feature_isset(&rdev->wiphy,
5718 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5719 return -EOPNOTSUPP;
5720
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305721 err = nl80211_parse_sta_txpower_setting(info, &params);
5722 if (err)
5723 return err;
5724
Johannes Berg77ee7c82013-02-15 00:48:33 +01005725 /* Include parameters for TDLS peer (will check later) */
5726 err = nl80211_set_station_tdls(info, &params);
5727 if (err)
5728 return err;
5729
5730 params.vlan = get_vlan(info, rdev);
5731 if (IS_ERR(params.vlan))
5732 return PTR_ERR(params.vlan);
5733
Johannes Berga97f4422009-06-18 17:23:43 +02005734 switch (dev->ieee80211_ptr->iftype) {
5735 case NL80211_IFTYPE_AP:
5736 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005737 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005738 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005739 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005740 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005741 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005742 break;
5743 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005744 err = -EOPNOTSUPP;
5745 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005746 }
5747
Johannes Berg77ee7c82013-02-15 00:48:33 +01005748 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005749 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005750
Johannes Berg77ee7c82013-02-15 00:48:33 +01005751 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005752 if (params.vlan)
5753 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005754
Johannes Berg5727ef12007-12-19 02:03:34 +01005755 return err;
5756}
5757
5758static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5759{
Johannes Berg4c476992010-10-04 21:36:35 +02005760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005761 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005762 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005763 struct station_parameters params;
5764 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005765 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5766 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005767
5768 memset(&params, 0, sizeof(params));
5769
Johannes Berg984c3112013-02-14 23:43:25 +01005770 if (!rdev->ops->add_station)
5771 return -EOPNOTSUPP;
5772
Johannes Berg5727ef12007-12-19 02:03:34 +01005773 if (!info->attrs[NL80211_ATTR_MAC])
5774 return -EINVAL;
5775
Johannes Berg5727ef12007-12-19 02:03:34 +01005776 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5777 return -EINVAL;
5778
5779 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5780 return -EINVAL;
5781
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005782 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5783 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005784 return -EINVAL;
5785
Johannes Berg5727ef12007-12-19 02:03:34 +01005786 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5787 params.supported_rates =
5788 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5789 params.supported_rates_len =
5790 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5791 params.listen_interval =
5792 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005793
Ayala Beker17b94242016-03-17 15:41:38 +02005794 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005795 params.support_p2p_ps =
5796 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005797 } else {
5798 /*
5799 * if not specified, assume it's supported for P2P GO interface,
5800 * and is NOT supported for AP interface
5801 */
5802 params.support_p2p_ps =
5803 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5804 }
5805
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005806 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005807 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005808 else
5809 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005810
Jouni Malinen9d62a982013-02-14 21:10:13 +02005811 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5812 params.capability =
5813 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5814 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5815 }
5816
5817 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5818 params.ext_capab =
5819 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5820 params.ext_capab_len =
5821 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5822 }
5823
Jouni Malinen36aedc92008-08-25 11:58:58 +03005824 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5825 params.ht_capa =
5826 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005827
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005828 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5829 params.vht_capa =
5830 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5831
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005832 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5833 params.he_capa =
5834 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5835 params.he_capa_len =
5836 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5837
5838 /* max len is validated in nla policy */
5839 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5840 return -EINVAL;
5841 }
5842
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005843 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5844 params.opmode_notif_used = true;
5845 params.opmode_notif =
5846 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5847 }
5848
Johannes Bergab0d76f2018-10-02 10:00:07 +02005849 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005850 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005851 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005852
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005853 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5854 params.airtime_weight =
5855 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5856
5857 if (params.airtime_weight &&
5858 !wiphy_ext_feature_isset(&rdev->wiphy,
5859 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5860 return -EOPNOTSUPP;
5861
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305862 err = nl80211_parse_sta_txpower_setting(info, &params);
5863 if (err)
5864 return err;
5865
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305866 err = nl80211_parse_sta_channel_info(info, &params);
5867 if (err)
5868 return err;
5869
Johannes Bergff276692013-02-15 00:09:01 +01005870 err = nl80211_parse_sta_wme(info, &params);
5871 if (err)
5872 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005873
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005874 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005875 return -EINVAL;
5876
Johannes Berg496fcc22015-03-12 08:53:27 +02005877 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5878 * as userspace might just pass through the capabilities from the IEs
5879 * directly, rather than enforcing this restriction and returning an
5880 * error in this case.
5881 */
5882 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5883 params.ht_capa = NULL;
5884 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005885
5886 /* HE requires WME */
5887 if (params.he_capa_len)
5888 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005889 }
5890
Johannes Berg77ee7c82013-02-15 00:48:33 +01005891 /* When you run into this, adjust the code below for the new flag */
5892 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5893
Johannes Bergbdd90d52011-12-14 12:20:27 +01005894 switch (dev->ieee80211_ptr->iftype) {
5895 case NL80211_IFTYPE_AP:
5896 case NL80211_IFTYPE_AP_VLAN:
5897 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005898 /* ignore WME attributes if iface/sta is not capable */
5899 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5900 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5901 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005902
Johannes Bergbdd90d52011-12-14 12:20:27 +01005903 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005904 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5905 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005906 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005907 /* but don't bother the driver with it */
5908 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005909
Johannes Bergd582cff2012-10-26 17:53:44 +02005910 /* allow authenticated/associated only if driver handles it */
5911 if (!(rdev->wiphy.features &
5912 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005913 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005914 return -EINVAL;
5915
Johannes Bergbda95eb2015-11-26 16:26:13 +01005916 /* Older userspace, or userspace wanting to be compatible with
5917 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5918 * and assoc flags in the mask, but assumes the station will be
5919 * added as associated anyway since this was the required driver
5920 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5921 * introduced.
5922 * In order to not bother drivers with this quirk in the API
5923 * set the flags in both the mask and set for new stations in
5924 * this case.
5925 */
5926 if (!(params.sta_flags_mask & auth_assoc)) {
5927 params.sta_flags_mask |= auth_assoc;
5928 params.sta_flags_set |= auth_assoc;
5929 }
5930
Johannes Bergbdd90d52011-12-14 12:20:27 +01005931 /* must be last in here for error handling */
5932 params.vlan = get_vlan(info, rdev);
5933 if (IS_ERR(params.vlan))
5934 return PTR_ERR(params.vlan);
5935 break;
5936 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005937 /* ignore uAPSD data */
5938 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5939
Johannes Bergd582cff2012-10-26 17:53:44 +02005940 /* associated is disallowed */
5941 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5942 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005943 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005944 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5945 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005946 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005947 break;
5948 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005949 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005950 /* ignore uAPSD data */
5951 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5952
Johannes Berg77ee7c82013-02-15 00:48:33 +01005953 /* these are disallowed */
5954 if (params.sta_flags_mask &
5955 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5956 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005957 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005958 /* Only TDLS peers can be added */
5959 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5960 return -EINVAL;
5961 /* Can only add if TDLS ... */
5962 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5963 return -EOPNOTSUPP;
5964 /* ... with external setup is supported */
5965 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5966 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005967 /*
5968 * Older wpa_supplicant versions always mark the TDLS peer
5969 * as authorized, but it shouldn't yet be.
5970 */
5971 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005972 break;
5973 default:
5974 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005975 }
5976
Johannes Bergbdd90d52011-12-14 12:20:27 +01005977 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005978
Hila Gonene35e4d22012-06-27 17:19:42 +03005979 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005980
Johannes Berg5727ef12007-12-19 02:03:34 +01005981 if (params.vlan)
5982 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005983 return err;
5984}
5985
5986static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5987{
Johannes Berg4c476992010-10-04 21:36:35 +02005988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5989 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005990 struct station_del_parameters params;
5991
5992 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005993
5994 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005995 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005996
Johannes Berge80cf852009-05-11 14:43:13 +02005997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005999 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02006000 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6001 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02006002
Johannes Berg4c476992010-10-04 21:36:35 +02006003 if (!rdev->ops->del_station)
6004 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01006005
Jouni Malinen98856862014-10-20 13:20:45 +03006006 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6007 params.subtype =
6008 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6009 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6010 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6011 return -EINVAL;
6012 } else {
6013 /* Default to Deauthentication frame */
6014 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6015 }
6016
6017 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6018 params.reason_code =
6019 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6020 if (params.reason_code == 0)
6021 return -EINVAL; /* 0 is reserved */
6022 } else {
6023 /* Default to reason code 2 */
6024 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6025 }
6026
Jouni Malinen89c771e2014-10-10 20:52:40 +03006027 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006028}
6029
Eric W. Biederman15e47302012-09-07 20:12:54 +00006030static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006031 int flags, struct net_device *dev,
6032 u8 *dst, u8 *next_hop,
6033 struct mpath_info *pinfo)
6034{
6035 void *hdr;
6036 struct nlattr *pinfoattr;
6037
Henning Rogge1ef4c852014-11-04 16:14:58 +01006038 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006039 if (!hdr)
6040 return -1;
6041
David S. Miller9360ffd2012-03-29 04:41:26 -04006042 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6043 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6044 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6045 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6046 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02006047
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006048 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006049 if (!pinfoattr)
6050 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006051 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6052 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6053 pinfo->frame_qlen))
6054 goto nla_put_failure;
6055 if (((pinfo->filled & MPATH_INFO_SN) &&
6056 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6057 ((pinfo->filled & MPATH_INFO_METRIC) &&
6058 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6059 pinfo->metric)) ||
6060 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6061 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6062 pinfo->exptime)) ||
6063 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6064 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6065 pinfo->flags)) ||
6066 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6067 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6068 pinfo->discovery_timeout)) ||
6069 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6070 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08006071 pinfo->discovery_retries)) ||
6072 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6073 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08006074 pinfo->hop_count)) ||
6075 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6076 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6077 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006078 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006079
6080 nla_nest_end(msg, pinfoattr);
6081
Johannes Berg053c0952015-01-16 22:09:00 +01006082 genlmsg_end(msg, hdr);
6083 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006084
6085 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07006086 genlmsg_cancel(msg, hdr);
6087 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006088}
6089
6090static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006091 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006092{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006093 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006094 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006095 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006096 u8 dst[ETH_ALEN];
6097 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02006098 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006099 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006100
Johannes Bergea90e0d2017-03-15 14:26:04 +01006101 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006102 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006103 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006104 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006106 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006107 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006108 goto out_err;
6109 }
6110
Johannes Berg97990a02013-04-19 01:02:55 +02006111 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006112 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006113 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006114 }
6115
Johannes Bergbba95fe2008-07-29 13:22:51 +02006116 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006117 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006118 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006119 if (err == -ENOENT)
6120 break;
6121 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006122 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006123
Eric W. Biederman15e47302012-09-07 20:12:54 +00006124 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006125 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006126 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006127 &pinfo) < 0)
6128 goto out;
6129
6130 path_idx++;
6131 }
6132
Johannes Bergbba95fe2008-07-29 13:22:51 +02006133 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006134 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006135 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006136 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006137 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006138 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006139}
6140
6141static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6142{
Johannes Berg4c476992010-10-04 21:36:35 +02006143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006144 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006145 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006146 struct mpath_info pinfo;
6147 struct sk_buff *msg;
6148 u8 *dst = NULL;
6149 u8 next_hop[ETH_ALEN];
6150
6151 memset(&pinfo, 0, sizeof(pinfo));
6152
6153 if (!info->attrs[NL80211_ATTR_MAC])
6154 return -EINVAL;
6155
6156 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6157
Johannes Berg4c476992010-10-04 21:36:35 +02006158 if (!rdev->ops->get_mpath)
6159 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006160
Johannes Berg4c476992010-10-04 21:36:35 +02006161 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6162 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006163
Hila Gonene35e4d22012-06-27 17:19:42 +03006164 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006165 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006166 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006167
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006168 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006169 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006170 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006171
Eric W. Biederman15e47302012-09-07 20:12:54 +00006172 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006173 dev, dst, next_hop, &pinfo) < 0) {
6174 nlmsg_free(msg);
6175 return -ENOBUFS;
6176 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006177
Johannes Berg4c476992010-10-04 21:36:35 +02006178 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006179}
6180
6181static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6182{
Johannes Berg4c476992010-10-04 21:36:35 +02006183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6184 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006185 u8 *dst = NULL;
6186 u8 *next_hop = NULL;
6187
6188 if (!info->attrs[NL80211_ATTR_MAC])
6189 return -EINVAL;
6190
6191 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6192 return -EINVAL;
6193
6194 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6195 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6196
Johannes Berg4c476992010-10-04 21:36:35 +02006197 if (!rdev->ops->change_mpath)
6198 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006199
Johannes Berg4c476992010-10-04 21:36:35 +02006200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6201 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006202
Hila Gonene35e4d22012-06-27 17:19:42 +03006203 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006204}
Johannes Berg4c476992010-10-04 21:36:35 +02006205
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006206static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6207{
Johannes Berg4c476992010-10-04 21:36:35 +02006208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6209 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006210 u8 *dst = NULL;
6211 u8 *next_hop = NULL;
6212
6213 if (!info->attrs[NL80211_ATTR_MAC])
6214 return -EINVAL;
6215
6216 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6217 return -EINVAL;
6218
6219 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6220 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6221
Johannes Berg4c476992010-10-04 21:36:35 +02006222 if (!rdev->ops->add_mpath)
6223 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006224
Johannes Berg4c476992010-10-04 21:36:35 +02006225 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6226 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006227
Hila Gonene35e4d22012-06-27 17:19:42 +03006228 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006229}
6230
6231static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6232{
Johannes Berg4c476992010-10-04 21:36:35 +02006233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6234 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006235 u8 *dst = NULL;
6236
6237 if (info->attrs[NL80211_ATTR_MAC])
6238 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6239
Johannes Berg4c476992010-10-04 21:36:35 +02006240 if (!rdev->ops->del_mpath)
6241 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006242
Hila Gonene35e4d22012-06-27 17:19:42 +03006243 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006244}
6245
Henning Rogge66be7d22014-09-12 08:58:49 +02006246static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6247{
6248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6249 int err;
6250 struct net_device *dev = info->user_ptr[1];
6251 struct mpath_info pinfo;
6252 struct sk_buff *msg;
6253 u8 *dst = NULL;
6254 u8 mpp[ETH_ALEN];
6255
6256 memset(&pinfo, 0, sizeof(pinfo));
6257
6258 if (!info->attrs[NL80211_ATTR_MAC])
6259 return -EINVAL;
6260
6261 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6262
6263 if (!rdev->ops->get_mpp)
6264 return -EOPNOTSUPP;
6265
6266 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6267 return -EOPNOTSUPP;
6268
6269 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6270 if (err)
6271 return err;
6272
6273 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6274 if (!msg)
6275 return -ENOMEM;
6276
6277 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6278 dev, dst, mpp, &pinfo) < 0) {
6279 nlmsg_free(msg);
6280 return -ENOBUFS;
6281 }
6282
6283 return genlmsg_reply(msg, info);
6284}
6285
6286static int nl80211_dump_mpp(struct sk_buff *skb,
6287 struct netlink_callback *cb)
6288{
6289 struct mpath_info pinfo;
6290 struct cfg80211_registered_device *rdev;
6291 struct wireless_dev *wdev;
6292 u8 dst[ETH_ALEN];
6293 u8 mpp[ETH_ALEN];
6294 int path_idx = cb->args[2];
6295 int err;
6296
Johannes Bergea90e0d2017-03-15 14:26:04 +01006297 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006298 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006299 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006300 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006301
6302 if (!rdev->ops->dump_mpp) {
6303 err = -EOPNOTSUPP;
6304 goto out_err;
6305 }
6306
6307 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6308 err = -EOPNOTSUPP;
6309 goto out_err;
6310 }
6311
6312 while (1) {
6313 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6314 mpp, &pinfo);
6315 if (err == -ENOENT)
6316 break;
6317 if (err)
6318 goto out_err;
6319
6320 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6321 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6322 wdev->netdev, dst, mpp,
6323 &pinfo) < 0)
6324 goto out;
6325
6326 path_idx++;
6327 }
6328
6329 out:
6330 cb->args[2] = path_idx;
6331 err = skb->len;
6332 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006333 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006334 return err;
6335}
6336
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006337static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6338{
Johannes Berg4c476992010-10-04 21:36:35 +02006339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6340 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006341 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006342 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006343 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006344
6345 memset(&params, 0, sizeof(params));
6346 /* default to not changing parameters */
6347 params.use_cts_prot = -1;
6348 params.use_short_preamble = -1;
6349 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006350 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006351 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006352 params.p2p_ctwindow = -1;
6353 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006354
6355 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6356 params.use_cts_prot =
6357 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6358 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6359 params.use_short_preamble =
6360 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6361 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6362 params.use_short_slot_time =
6363 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006364 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6365 params.basic_rates =
6366 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6367 params.basic_rates_len =
6368 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6369 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006370 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6371 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006372 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6373 params.ht_opmode =
6374 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006375
Johannes Berg53cabad2012-11-14 15:17:28 +01006376 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6377 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6378 return -EINVAL;
6379 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006380 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006381 if (params.p2p_ctwindow != 0 &&
6382 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6383 return -EINVAL;
6384 }
6385
6386 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6387 u8 tmp;
6388
6389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6390 return -EINVAL;
6391 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006392 params.p2p_opp_ps = tmp;
6393 if (params.p2p_opp_ps &&
6394 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6395 return -EINVAL;
6396 }
6397
Johannes Berg4c476992010-10-04 21:36:35 +02006398 if (!rdev->ops->change_bss)
6399 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006400
Johannes Berg074ac8d2010-09-16 14:58:22 +02006401 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006402 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6403 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006404
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006405 wdev_lock(wdev);
6406 err = rdev_change_bss(rdev, dev, &params);
6407 wdev_unlock(wdev);
6408
6409 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006410}
6411
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006412static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6413{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006414 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006415 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006416 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006417 u32 owner_nlportid;
6418
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006419 /*
6420 * You should only get this when cfg80211 hasn't yet initialized
6421 * completely when built-in to the kernel right between the time
6422 * window between nl80211_init() and regulatory_init(), if that is
6423 * even possible.
6424 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006425 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006426 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006427
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006428 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6429 user_reg_hint_type =
6430 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6431 else
6432 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6433
6434 switch (user_reg_hint_type) {
6435 case NL80211_USER_REG_HINT_USER:
6436 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006437 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6438 return -EINVAL;
6439
6440 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6441 return regulatory_hint_user(data, user_reg_hint_type);
6442 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006443 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6444 owner_nlportid = info->snd_portid;
6445 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6446 } else {
6447 owner_nlportid = 0;
6448 is_indoor = true;
6449 }
6450
6451 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006452 default:
6453 return -EINVAL;
6454 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006455}
6456
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006457static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6458{
6459 return reg_reload_regdb();
6460}
6461
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006462static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006463 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006464{
Johannes Berg4c476992010-10-04 21:36:35 +02006465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006466 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006467 struct wireless_dev *wdev = dev->ieee80211_ptr;
6468 struct mesh_config cur_params;
6469 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006470 void *hdr;
6471 struct nlattr *pinfoattr;
6472 struct sk_buff *msg;
6473
Johannes Berg29cbe682010-12-03 09:20:44 +01006474 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6475 return -EOPNOTSUPP;
6476
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006477 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006478 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006479
Johannes Berg29cbe682010-12-03 09:20:44 +01006480 wdev_lock(wdev);
6481 /* If not connected, get default parameters */
6482 if (!wdev->mesh_id_len)
6483 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6484 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006485 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006486 wdev_unlock(wdev);
6487
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006488 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006489 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006490
6491 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006493 if (!msg)
6494 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006495 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006496 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006497 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006498 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006499 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006500 if (!pinfoattr)
6501 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006502 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6503 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6504 cur_params.dot11MeshRetryTimeout) ||
6505 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6506 cur_params.dot11MeshConfirmTimeout) ||
6507 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6508 cur_params.dot11MeshHoldingTimeout) ||
6509 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6510 cur_params.dot11MeshMaxPeerLinks) ||
6511 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6512 cur_params.dot11MeshMaxRetries) ||
6513 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6514 cur_params.dot11MeshTTL) ||
6515 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6516 cur_params.element_ttl) ||
6517 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6518 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006519 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6520 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006521 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6522 cur_params.dot11MeshHWMPmaxPREQretries) ||
6523 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6524 cur_params.path_refresh_time) ||
6525 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6526 cur_params.min_discovery_timeout) ||
6527 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6528 cur_params.dot11MeshHWMPactivePathTimeout) ||
6529 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6530 cur_params.dot11MeshHWMPpreqMinInterval) ||
6531 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6532 cur_params.dot11MeshHWMPperrMinInterval) ||
6533 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6534 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6535 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6536 cur_params.dot11MeshHWMPRootMode) ||
6537 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6538 cur_params.dot11MeshHWMPRannInterval) ||
6539 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6540 cur_params.dot11MeshGateAnnouncementProtocol) ||
6541 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6542 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006543 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006544 cur_params.rssi_threshold) ||
6545 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006546 cur_params.ht_opmode) ||
6547 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6548 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6549 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006550 cur_params.dot11MeshHWMProotInterval) ||
6551 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006552 cur_params.dot11MeshHWMPconfirmationInterval) ||
6553 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6554 cur_params.power_mode) ||
6555 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006556 cur_params.dot11MeshAwakeWindowDuration) ||
6557 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006558 cur_params.plink_timeout) ||
6559 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6560 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006561 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006562 nla_nest_end(msg, pinfoattr);
6563 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006564 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006565
Johannes Berg3b858752009-03-12 09:55:09 +01006566 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006567 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006568 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006569 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006570}
6571
Johannes Bergab0d76f2018-10-02 10:00:07 +02006572static const struct nla_policy
6573nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6574 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6575 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6576 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6577 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6578 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6579 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6580 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6581 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6582 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6583 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6584 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6585 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6586 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6587 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006588 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6589 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006590 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006591 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006592 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6593 NLA_POLICY_MIN(NLA_U16, 1),
6594 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6595 NLA_POLICY_MIN(NLA_U16, 1),
6596 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6597 NLA_POLICY_MIN(NLA_U16, 1),
6598 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6599 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6600 NLA_POLICY_MIN(NLA_U16, 1),
6601 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6602 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6603 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6604 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006605 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006606 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006607 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6608 NLA_POLICY_MIN(NLA_U16, 1),
6609 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6610 NLA_POLICY_MIN(NLA_U16, 1),
6611 [NL80211_MESHCONF_POWER_MODE] =
6612 NLA_POLICY_RANGE(NLA_U32,
6613 NL80211_MESH_POWER_ACTIVE,
6614 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006615 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006616 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006617 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006618};
6619
Javier Cardonac80d5452010-12-16 17:37:49 -08006620static const struct nla_policy
6621 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006622 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006623 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6624 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006625 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006626 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006627 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006628 [NL80211_MESH_SETUP_IE] =
6629 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6630 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006631 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006632};
6633
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006634static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006635 struct mesh_config *cfg,
6636 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006637{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006638 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006639 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006640 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006641
Johannes Bergab0d76f2018-10-02 10:00:07 +02006642#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6643do { \
6644 if (tb[attr]) { \
6645 cfg->param = fn(tb[attr]); \
6646 mask |= BIT((attr) - 1); \
6647 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006648} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006649
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006650 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006651 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006652 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 -07006653 return -EINVAL;
6654
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006655 /* This makes sure that there aren't more than 32 mesh config
6656 * parameters (otherwise our bitfield scheme would not work.) */
6657 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6658
6659 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006660 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6661 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6662 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6663 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6664 nla_get_u16);
6665 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6666 NL80211_MESHCONF_HOLDING_TIMEOUT,
6667 nla_get_u16);
6668 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6669 NL80211_MESHCONF_MAX_PEER_LINKS,
6670 nla_get_u16);
6671 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6672 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6674 NL80211_MESHCONF_TTL, nla_get_u8);
6675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6676 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6677 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6678 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6679 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006680 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006681 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006682 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006683 nla_get_u32);
6684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6685 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6686 nla_get_u8);
6687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6688 NL80211_MESHCONF_PATH_REFRESH_TIME,
6689 nla_get_u32);
6690 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6691 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6692 return -EINVAL;
6693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6694 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6695 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006697 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006698 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006699 nla_get_u32);
6700 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6701 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6702 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6703 return -EINVAL;
6704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006705 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006706 nla_get_u16);
6707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006708 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006709 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006711 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006712 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006713 nla_get_u16);
6714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6715 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6717 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6718 nla_get_u16);
6719 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006720 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006721 nla_get_u8);
6722 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6723 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6725 NL80211_MESHCONF_RSSI_THRESHOLD,
6726 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6728 NL80211_MESHCONF_CONNECTED_TO_GATE,
6729 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006730 /*
6731 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006732 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006733 */
6734 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6735 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6736
6737 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6738 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6739 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6740 return -EINVAL;
6741
Bob Copeland188f60a2018-06-24 21:10:49 -04006742 /* NON_HT_STA bit is reserved, but some programs set it */
6743 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006744
Masashi Honma97572352016-08-03 10:07:44 +09006745 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006746 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006747 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006749 dot11MeshHWMPactivePathToRootTimeout, mask,
6750 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6751 nla_get_u32);
6752 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6753 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6754 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6755 return -EINVAL;
6756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6757 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6758 nla_get_u16);
6759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6760 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006761 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006762 nla_get_u16);
6763 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6764 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6765 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6766 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6767 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6768 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006769 if (mask_out)
6770 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006771
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006772 return 0;
6773
6774#undef FILL_IN_MESH_PARAM_IF_SET
6775}
6776
Javier Cardonac80d5452010-12-16 17:37:49 -08006777static int nl80211_parse_mesh_setup(struct genl_info *info,
6778 struct mesh_setup *setup)
6779{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006781 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6782
6783 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6784 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006785 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 -08006786 return -EINVAL;
6787
Javier Cardonad299a1f2012-03-31 11:31:33 -07006788 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6789 setup->sync_method =
6790 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6791 IEEE80211_SYNC_METHOD_VENDOR :
6792 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6793
Javier Cardonac80d5452010-12-16 17:37:49 -08006794 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6795 setup->path_sel_proto =
6796 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6797 IEEE80211_PATH_PROTOCOL_VENDOR :
6798 IEEE80211_PATH_PROTOCOL_HWMP;
6799
6800 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6801 setup->path_metric =
6802 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6803 IEEE80211_PATH_METRIC_VENDOR :
6804 IEEE80211_PATH_METRIC_AIRTIME;
6805
Javier Cardona581a8b02011-04-07 15:08:27 -07006806 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006807 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006808 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006809 setup->ie = nla_data(ieattr);
6810 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006811 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006812 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6813 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6814 return -EINVAL;
6815 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006816 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6817 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006818 if (setup->is_secure)
6819 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006820
Colleen Twitty6e16d902013-05-08 11:45:59 -07006821 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6822 if (!setup->user_mpm)
6823 return -EINVAL;
6824 setup->auth_id =
6825 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6826 }
6827
Javier Cardonac80d5452010-12-16 17:37:49 -08006828 return 0;
6829}
6830
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006831static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006832 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006833{
6834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6835 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006836 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006837 struct mesh_config cfg;
6838 u32 mask;
6839 int err;
6840
Johannes Berg29cbe682010-12-03 09:20:44 +01006841 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6842 return -EOPNOTSUPP;
6843
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006844 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006845 return -EOPNOTSUPP;
6846
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006847 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006848 if (err)
6849 return err;
6850
Johannes Berg29cbe682010-12-03 09:20:44 +01006851 wdev_lock(wdev);
6852 if (!wdev->mesh_id_len)
6853 err = -ENOLINK;
6854
6855 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006856 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006857
6858 wdev_unlock(wdev);
6859
6860 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006861}
6862
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006863static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6864 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006865{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006866 struct nlattr *nl_reg_rules;
6867 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006868
Johannes Berg458f4f92012-12-06 15:47:38 +01006869 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6870 (regdom->dfs_region &&
6871 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006872 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006873
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006874 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006875 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006876 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006877
Johannes Berg458f4f92012-12-06 15:47:38 +01006878 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006879 struct nlattr *nl_reg_rule;
6880 const struct ieee80211_reg_rule *reg_rule;
6881 const struct ieee80211_freq_range *freq_range;
6882 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006883 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006884
Johannes Berg458f4f92012-12-06 15:47:38 +01006885 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006886 freq_range = &reg_rule->freq_range;
6887 power_rule = &reg_rule->power_rule;
6888
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006889 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006890 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006891 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006892
Janusz Dziedzic97524822014-01-30 09:52:20 +01006893 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6894 if (!max_bandwidth_khz)
6895 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6896 reg_rule);
6897
David S. Miller9360ffd2012-03-29 04:41:26 -04006898 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6899 reg_rule->flags) ||
6900 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6901 freq_range->start_freq_khz) ||
6902 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6903 freq_range->end_freq_khz) ||
6904 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006905 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006906 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6907 power_rule->max_antenna_gain) ||
6908 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006909 power_rule->max_eirp) ||
6910 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6911 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006912 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006913
6914 nla_nest_end(msg, nl_reg_rule);
6915 }
6916
6917 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006918 return 0;
6919
6920nla_put_failure:
6921 return -EMSGSIZE;
6922}
6923
6924static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6925{
6926 const struct ieee80211_regdomain *regdom = NULL;
6927 struct cfg80211_registered_device *rdev;
6928 struct wiphy *wiphy = NULL;
6929 struct sk_buff *msg;
6930 void *hdr;
6931
6932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6933 if (!msg)
6934 return -ENOBUFS;
6935
6936 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6937 NL80211_CMD_GET_REG);
6938 if (!hdr)
6939 goto put_failure;
6940
6941 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006942 bool self_managed;
6943
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006944 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6945 if (IS_ERR(rdev)) {
6946 nlmsg_free(msg);
6947 return PTR_ERR(rdev);
6948 }
6949
6950 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006951 self_managed = wiphy->regulatory_flags &
6952 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006953 regdom = get_wiphy_regdom(wiphy);
6954
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006955 /* a self-managed-reg device must have a private regdom */
6956 if (WARN_ON(!regdom && self_managed)) {
6957 nlmsg_free(msg);
6958 return -EINVAL;
6959 }
6960
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006961 if (regdom &&
6962 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6963 goto nla_put_failure;
6964 }
6965
6966 if (!wiphy && reg_last_request_cell_base() &&
6967 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6968 NL80211_USER_REG_HINT_CELL_BASE))
6969 goto nla_put_failure;
6970
6971 rcu_read_lock();
6972
6973 if (!regdom)
6974 regdom = rcu_dereference(cfg80211_regdomain);
6975
6976 if (nl80211_put_regdom(regdom, msg))
6977 goto nla_put_failure_rcu;
6978
6979 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006980
6981 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006982 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006983
Johannes Berg458f4f92012-12-06 15:47:38 +01006984nla_put_failure_rcu:
6985 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006986nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006987put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006988 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006989 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006990}
6991
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006992static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6993 u32 seq, int flags, struct wiphy *wiphy,
6994 const struct ieee80211_regdomain *regdom)
6995{
6996 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6997 NL80211_CMD_GET_REG);
6998
6999 if (!hdr)
7000 return -1;
7001
Michal Kubecek0a833c22017-11-15 13:09:32 +01007002 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007003
7004 if (nl80211_put_regdom(regdom, msg))
7005 goto nla_put_failure;
7006
7007 if (!wiphy && reg_last_request_cell_base() &&
7008 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7009 NL80211_USER_REG_HINT_CELL_BASE))
7010 goto nla_put_failure;
7011
7012 if (wiphy &&
7013 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7014 goto nla_put_failure;
7015
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007016 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7017 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7018 goto nla_put_failure;
7019
Johannes Berg053c0952015-01-16 22:09:00 +01007020 genlmsg_end(msg, hdr);
7021 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007022
7023nla_put_failure:
7024 genlmsg_cancel(msg, hdr);
7025 return -EMSGSIZE;
7026}
7027
7028static int nl80211_get_reg_dump(struct sk_buff *skb,
7029 struct netlink_callback *cb)
7030{
7031 const struct ieee80211_regdomain *regdom = NULL;
7032 struct cfg80211_registered_device *rdev;
7033 int err, reg_idx, start = cb->args[2];
7034
7035 rtnl_lock();
7036
7037 if (cfg80211_regdomain && start == 0) {
7038 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7039 NLM_F_MULTI, NULL,
7040 rtnl_dereference(cfg80211_regdomain));
7041 if (err < 0)
7042 goto out_err;
7043 }
7044
7045 /* the global regdom is idx 0 */
7046 reg_idx = 1;
7047 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7048 regdom = get_wiphy_regdom(&rdev->wiphy);
7049 if (!regdom)
7050 continue;
7051
7052 if (++reg_idx <= start)
7053 continue;
7054
7055 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7056 NLM_F_MULTI, &rdev->wiphy, regdom);
7057 if (err < 0) {
7058 reg_idx--;
7059 break;
7060 }
7061 }
7062
7063 cb->args[2] = reg_idx;
7064 err = skb->len;
7065out_err:
7066 rtnl_unlock();
7067 return err;
7068}
7069
Johannes Bergb6863032015-10-15 09:25:18 +02007070#ifdef CONFIG_CFG80211_CRDA_SUPPORT
7071static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7072 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7073 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7074 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7075 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7076 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7077 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7078 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7079};
7080
7081static int parse_reg_rule(struct nlattr *tb[],
7082 struct ieee80211_reg_rule *reg_rule)
7083{
7084 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
7085 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
7086
7087 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7088 return -EINVAL;
7089 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7090 return -EINVAL;
7091 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7092 return -EINVAL;
7093 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7094 return -EINVAL;
7095 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7096 return -EINVAL;
7097
7098 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7099
7100 freq_range->start_freq_khz =
7101 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7102 freq_range->end_freq_khz =
7103 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7104 freq_range->max_bandwidth_khz =
7105 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7106
7107 power_rule->max_eirp =
7108 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7109
7110 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7111 power_rule->max_antenna_gain =
7112 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7113
7114 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7115 reg_rule->dfs_cac_ms =
7116 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7117
7118 return 0;
7119}
7120
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007121static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7122{
7123 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7124 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007125 char *alpha2;
7126 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007127 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007128 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007129 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007130
7131 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7132 return -EINVAL;
7133
7134 if (!info->attrs[NL80211_ATTR_REG_RULES])
7135 return -EINVAL;
7136
7137 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7138
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007139 if (info->attrs[NL80211_ATTR_DFS_REGION])
7140 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7141
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007142 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007143 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007144 num_rules++;
7145 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007146 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007147 }
7148
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007149 if (!reg_is_valid_request(alpha2))
7150 return -EINVAL;
7151
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007152 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007153 if (!rd)
7154 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007155
7156 rd->n_reg_rules = num_rules;
7157 rd->alpha2[0] = alpha2[0];
7158 rd->alpha2[1] = alpha2[1];
7159
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007160 /*
7161 * Disable DFS master mode if the DFS region was
7162 * not supported or known on this kernel.
7163 */
7164 if (reg_supported_dfs_region(dfs_region))
7165 rd->dfs_region = dfs_region;
7166
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007167 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007168 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007169 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7170 nl_reg_rule, reg_rule_policy,
7171 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007172 if (r)
7173 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007174 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7175 if (r)
7176 goto bad_reg;
7177
7178 rule_idx++;
7179
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007180 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7181 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007182 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007183 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007184 }
7185
Johannes Berg06627992016-06-09 10:40:09 +02007186 /* set_regdom takes ownership of rd */
7187 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007188 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007189 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007190 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007191}
Johannes Bergb6863032015-10-15 09:25:18 +02007192#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007193
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007194static int validate_scan_freqs(struct nlattr *freqs)
7195{
7196 struct nlattr *attr1, *attr2;
7197 int n_channels = 0, tmp1, tmp2;
7198
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007199 nla_for_each_nested(attr1, freqs, tmp1)
7200 if (nla_len(attr1) != sizeof(u32))
7201 return 0;
7202
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007203 nla_for_each_nested(attr1, freqs, tmp1) {
7204 n_channels++;
7205 /*
7206 * Some hardware has a limited channel list for
7207 * scanning, and it is pretty much nonsensical
7208 * to scan for a channel twice, so disallow that
7209 * and don't require drivers to check that the
7210 * channel list they get isn't longer than what
7211 * they can scan, as long as they can scan all
7212 * the channels they registered at once.
7213 */
7214 nla_for_each_nested(attr2, freqs, tmp2)
7215 if (attr1 != attr2 &&
7216 nla_get_u32(attr1) == nla_get_u32(attr2))
7217 return 0;
7218 }
7219
7220 return n_channels;
7221}
7222
Johannes Berg57fbcce2016-04-12 15:56:15 +02007223static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007224{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007225 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007226}
7227
7228static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7229 struct cfg80211_bss_selection *bss_select)
7230{
7231 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7232 struct nlattr *nest;
7233 int err;
7234 bool found = false;
7235 int i;
7236
7237 /* only process one nested attribute */
7238 nest = nla_data(nla);
7239 if (!nla_ok(nest, nla_len(nest)))
7240 return -EINVAL;
7241
Johannes Berg8cb08172019-04-26 14:07:28 +02007242 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7243 nest, nl80211_bss_select_policy,
7244 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007245 if (err)
7246 return err;
7247
7248 /* only one attribute may be given */
7249 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7250 if (attr[i]) {
7251 if (found)
7252 return -EINVAL;
7253 found = true;
7254 }
7255 }
7256
7257 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7258
7259 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7260 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7261
7262 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7263 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7264 bss_select->param.band_pref =
7265 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7266 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7267 return -EINVAL;
7268 }
7269
7270 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7271 struct nl80211_bss_select_rssi_adjust *adj_param;
7272
7273 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7274 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7275 bss_select->param.adjust.band = adj_param->band;
7276 bss_select->param.adjust.delta = adj_param->delta;
7277 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7278 return -EINVAL;
7279 }
7280
7281 /* user-space did not provide behaviour attribute */
7282 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7283 return -EINVAL;
7284
7285 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7286 return -EINVAL;
7287
7288 return 0;
7289}
7290
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007291int nl80211_parse_random_mac(struct nlattr **attrs,
7292 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007293{
7294 int i;
7295
7296 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007297 eth_zero_addr(mac_addr);
7298 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007299 mac_addr[0] = 0x2;
7300 mac_addr_mask[0] = 0x3;
7301
7302 return 0;
7303 }
7304
7305 /* need both or none */
7306 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7307 return -EINVAL;
7308
7309 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7310 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7311
7312 /* don't allow or configure an mcast address */
7313 if (!is_multicast_ether_addr(mac_addr_mask) ||
7314 is_multicast_ether_addr(mac_addr))
7315 return -EINVAL;
7316
7317 /*
7318 * allow users to pass a MAC address that has bits set outside
7319 * of the mask, but don't bother drivers with having to deal
7320 * with such bits
7321 */
7322 for (i = 0; i < ETH_ALEN; i++)
7323 mac_addr[i] &= mac_addr_mask[i];
7324
7325 return 0;
7326}
7327
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307328static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7329{
7330 ASSERT_WDEV_LOCK(wdev);
7331
7332 if (!cfg80211_beaconing_iface_active(wdev))
7333 return true;
7334
7335 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7336 return true;
7337
7338 return regulatory_pre_cac_allowed(wdev->wiphy);
7339}
7340
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007341static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7342 enum nl80211_ext_feature_index feat)
7343{
7344 if (!(flags & flag))
7345 return true;
7346 if (wiphy_ext_feature_isset(wiphy, feat))
7347 return true;
7348 return false;
7349}
7350
Roee Zamir2d23d072017-08-06 11:38:22 +03007351static int
7352nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7353 void *request, struct nlattr **attrs,
7354 bool is_sched_scan)
7355{
7356 u8 *mac_addr, *mac_addr_mask;
7357 u32 *flags;
7358 enum nl80211_feature_flags randomness_flag;
7359
7360 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7361 return 0;
7362
7363 if (is_sched_scan) {
7364 struct cfg80211_sched_scan_request *req = request;
7365
7366 randomness_flag = wdev ?
7367 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7368 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7369 flags = &req->flags;
7370 mac_addr = req->mac_addr;
7371 mac_addr_mask = req->mac_addr_mask;
7372 } else {
7373 struct cfg80211_scan_request *req = request;
7374
7375 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7376 flags = &req->flags;
7377 mac_addr = req->mac_addr;
7378 mac_addr_mask = req->mac_addr_mask;
7379 }
7380
7381 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7382
Sunil Dutt5037a002018-01-25 17:13:37 +02007383 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7384 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007385 !nl80211_check_scan_feat(wiphy, *flags,
7386 NL80211_SCAN_FLAG_LOW_SPAN,
7387 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7388 !nl80211_check_scan_feat(wiphy, *flags,
7389 NL80211_SCAN_FLAG_LOW_POWER,
7390 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7391 !nl80211_check_scan_feat(wiphy, *flags,
7392 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7393 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7394 !nl80211_check_scan_feat(wiphy, *flags,
7395 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7396 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7397 !nl80211_check_scan_feat(wiphy, *flags,
7398 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7399 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7400 !nl80211_check_scan_feat(wiphy, *flags,
7401 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7402 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7403 !nl80211_check_scan_feat(wiphy, *flags,
7404 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007405 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7406 !nl80211_check_scan_feat(wiphy, *flags,
7407 NL80211_SCAN_FLAG_RANDOM_SN,
7408 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7409 !nl80211_check_scan_feat(wiphy, *flags,
7410 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7411 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007412 return -EOPNOTSUPP;
7413
7414 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7415 int err;
7416
7417 if (!(wiphy->features & randomness_flag) ||
7418 (wdev && wdev->current_bss))
7419 return -EOPNOTSUPP;
7420
7421 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7422 if (err)
7423 return err;
7424 }
7425
Roee Zamir2d23d072017-08-06 11:38:22 +03007426 return 0;
7427}
7428
Johannes Berg2a519312009-02-10 21:25:55 +01007429static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7430{
Johannes Berg4c476992010-10-04 21:36:35 +02007431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007432 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007433 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007434 struct nlattr *attr;
7435 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007436 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007437 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007438
Johannes Berg79c97e92009-07-07 03:56:12 +02007439 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007440
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007441 if (wdev->iftype == NL80211_IFTYPE_NAN)
7442 return -EOPNOTSUPP;
7443
Johannes Berg4c476992010-10-04 21:36:35 +02007444 if (!rdev->ops->scan)
7445 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007446
Johannes Bergf9d15d12014-01-22 11:14:19 +02007447 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007448 err = -EBUSY;
7449 goto unlock;
7450 }
Johannes Berg2a519312009-02-10 21:25:55 +01007451
7452 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007453 n_channels = validate_scan_freqs(
7454 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007455 if (!n_channels) {
7456 err = -EINVAL;
7457 goto unlock;
7458 }
Johannes Berg2a519312009-02-10 21:25:55 +01007459 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007460 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007461 }
7462
7463 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7464 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7465 n_ssids++;
7466
Johannes Bergf9f47522013-03-19 15:04:07 +01007467 if (n_ssids > wiphy->max_scan_ssids) {
7468 err = -EINVAL;
7469 goto unlock;
7470 }
Johannes Berg2a519312009-02-10 21:25:55 +01007471
Jouni Malinen70692ad2009-02-16 19:39:13 +02007472 if (info->attrs[NL80211_ATTR_IE])
7473 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7474 else
7475 ie_len = 0;
7476
Johannes Bergf9f47522013-03-19 15:04:07 +01007477 if (ie_len > wiphy->max_scan_ie_len) {
7478 err = -EINVAL;
7479 goto unlock;
7480 }
Johannes Berg18a83652009-03-31 12:12:05 +02007481
Johannes Berg2a519312009-02-10 21:25:55 +01007482 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007483 + sizeof(*request->ssids) * n_ssids
7484 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007485 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007486 if (!request) {
7487 err = -ENOMEM;
7488 goto unlock;
7489 }
Johannes Berg2a519312009-02-10 21:25:55 +01007490
Johannes Berg2a519312009-02-10 21:25:55 +01007491 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007492 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007493 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007494 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007495 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007496 request->ie = (void *)(request->ssids + n_ssids);
7497 else
7498 request->ie = (void *)(request->channels + n_channels);
7499 }
Johannes Berg2a519312009-02-10 21:25:55 +01007500
Johannes Berg584991d2009-11-02 13:32:03 +01007501 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007502 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7503 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007504 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007505 struct ieee80211_channel *chan;
7506
7507 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7508
7509 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007510 err = -EINVAL;
7511 goto out_free;
7512 }
Johannes Berg584991d2009-11-02 13:32:03 +01007513
7514 /* ignore disabled channels */
7515 if (chan->flags & IEEE80211_CHAN_DISABLED)
7516 continue;
7517
7518 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007519 i++;
7520 }
7521 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007522 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007523
Johannes Berg2a519312009-02-10 21:25:55 +01007524 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007525 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007526 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007527
Johannes Berg2a519312009-02-10 21:25:55 +01007528 if (!wiphy->bands[band])
7529 continue;
7530 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007531 struct ieee80211_channel *chan;
7532
7533 chan = &wiphy->bands[band]->channels[j];
7534
7535 if (chan->flags & IEEE80211_CHAN_DISABLED)
7536 continue;
7537
7538 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007539 i++;
7540 }
7541 }
7542 }
7543
Johannes Berg584991d2009-11-02 13:32:03 +01007544 if (!i) {
7545 err = -EINVAL;
7546 goto out_free;
7547 }
7548
7549 request->n_channels = i;
7550
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307551 wdev_lock(wdev);
7552 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7553 struct ieee80211_channel *chan;
7554
7555 if (request->n_channels != 1) {
7556 wdev_unlock(wdev);
7557 err = -EBUSY;
7558 goto out_free;
7559 }
7560
7561 chan = request->channels[0];
7562 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7563 wdev_unlock(wdev);
7564 err = -EBUSY;
7565 goto out_free;
7566 }
7567 }
7568 wdev_unlock(wdev);
7569
Johannes Berg2a519312009-02-10 21:25:55 +01007570 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007571 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007572 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007573 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007574 err = -EINVAL;
7575 goto out_free;
7576 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007577 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007578 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007579 i++;
7580 }
7581 }
7582
Jouni Malinen70692ad2009-02-16 19:39:13 +02007583 if (info->attrs[NL80211_ATTR_IE]) {
7584 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007585 memcpy((void *)request->ie,
7586 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007587 request->ie_len);
7588 }
7589
Johannes Berg57fbcce2016-04-12 15:56:15 +02007590 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007591 if (wiphy->bands[i])
7592 request->rates[i] =
7593 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007594
7595 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7596 nla_for_each_nested(attr,
7597 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7598 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007599 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007600
Johannes Berg57fbcce2016-04-12 15:56:15 +02007601 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007602 err = -EINVAL;
7603 goto out_free;
7604 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007605
7606 if (!wiphy->bands[band])
7607 continue;
7608
Johannes Berg34850ab2011-07-18 18:08:35 +02007609 err = ieee80211_get_ratemask(wiphy->bands[band],
7610 nla_data(attr),
7611 nla_len(attr),
7612 &request->rates[band]);
7613 if (err)
7614 goto out_free;
7615 }
7616 }
7617
Avraham Stern1d762502016-07-05 17:10:13 +03007618 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7619 if (!wiphy_ext_feature_isset(wiphy,
7620 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7621 err = -EOPNOTSUPP;
7622 goto out_free;
7623 }
7624
7625 request->duration =
7626 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7627 request->duration_mandatory =
7628 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7629 }
7630
Roee Zamir2d23d072017-08-06 11:38:22 +03007631 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7632 false);
7633 if (err)
7634 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007635
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307636 request->no_cck =
7637 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7638
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007639 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7640 * BSSID to scan for. This was problematic because that same attribute
7641 * was already used for another purpose (local random MAC address). The
7642 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7643 * compatibility with older userspace components, also use the
7644 * NL80211_ATTR_MAC value here if it can be determined to be used for
7645 * the specific BSSID use case instead of the random MAC address
7646 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7647 */
7648 if (info->attrs[NL80211_ATTR_BSSID])
7649 memcpy(request->bssid,
7650 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7651 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7652 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007653 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7654 ETH_ALEN);
7655 else
7656 eth_broadcast_addr(request->bssid);
7657
Johannes Bergfd014282012-06-18 19:17:03 +02007658 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007659 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007660 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007661
Johannes Berg79c97e92009-07-07 03:56:12 +02007662 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007663 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007664
Johannes Berg463d0182009-07-14 00:33:35 +02007665 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007666 nl80211_send_scan_start(rdev, wdev);
7667 if (wdev->netdev)
7668 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007669 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007670 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007671 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007672 kfree(request);
7673 }
Johannes Berg3b858752009-03-12 09:55:09 +01007674
Johannes Bergf9f47522013-03-19 15:04:07 +01007675 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007676 return err;
7677}
7678
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307679static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7680{
7681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7682 struct wireless_dev *wdev = info->user_ptr[1];
7683
7684 if (!rdev->ops->abort_scan)
7685 return -EOPNOTSUPP;
7686
7687 if (rdev->scan_msg)
7688 return 0;
7689
7690 if (!rdev->scan_req)
7691 return -ENOENT;
7692
7693 rdev_abort_scan(rdev, wdev);
7694 return 0;
7695}
7696
Avraham Stern3b06d272015-10-12 09:51:34 +03007697static int
7698nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7699 struct cfg80211_sched_scan_request *request,
7700 struct nlattr **attrs)
7701{
7702 int tmp, err, i = 0;
7703 struct nlattr *attr;
7704
7705 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7706 u32 interval;
7707
7708 /*
7709 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007710 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007711 * case one scan plan will be set with the specified scan
7712 * interval and infinite number of iterations.
7713 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007714 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7715 if (!interval)
7716 return -EINVAL;
7717
7718 request->scan_plans[0].interval =
7719 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7720 if (!request->scan_plans[0].interval)
7721 return -EINVAL;
7722
7723 if (request->scan_plans[0].interval >
7724 wiphy->max_sched_scan_plan_interval)
7725 request->scan_plans[0].interval =
7726 wiphy->max_sched_scan_plan_interval;
7727
7728 return 0;
7729 }
7730
7731 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7732 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7733
7734 if (WARN_ON(i >= n_plans))
7735 return -EINVAL;
7736
Johannes Berg8cb08172019-04-26 14:07:28 +02007737 err = nla_parse_nested_deprecated(plan,
7738 NL80211_SCHED_SCAN_PLAN_MAX,
7739 attr, nl80211_plan_policy,
7740 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007741 if (err)
7742 return err;
7743
7744 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7745 return -EINVAL;
7746
7747 request->scan_plans[i].interval =
7748 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7749 if (!request->scan_plans[i].interval ||
7750 request->scan_plans[i].interval >
7751 wiphy->max_sched_scan_plan_interval)
7752 return -EINVAL;
7753
7754 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7755 request->scan_plans[i].iterations =
7756 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7757 if (!request->scan_plans[i].iterations ||
7758 (request->scan_plans[i].iterations >
7759 wiphy->max_sched_scan_plan_iterations))
7760 return -EINVAL;
7761 } else if (i < n_plans - 1) {
7762 /*
7763 * All scan plans but the last one must specify
7764 * a finite number of iterations
7765 */
7766 return -EINVAL;
7767 }
7768
7769 i++;
7770 }
7771
7772 /*
7773 * The last scan plan must not specify the number of
7774 * iterations, it is supposed to run infinitely
7775 */
7776 if (request->scan_plans[n_plans - 1].iterations)
7777 return -EINVAL;
7778
7779 return 0;
7780}
7781
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307782static int
7783nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7784 struct cfg80211_match_set *match_sets,
7785 struct nlattr *tb_band_rssi,
7786 s32 rssi_thold)
7787{
7788 struct nlattr *attr;
7789 int i, tmp, ret = 0;
7790
7791 if (!wiphy_ext_feature_isset(wiphy,
7792 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7793 if (tb_band_rssi)
7794 ret = -EOPNOTSUPP;
7795 else
7796 for (i = 0; i < NUM_NL80211_BANDS; i++)
7797 match_sets->per_band_rssi_thold[i] =
7798 NL80211_SCAN_RSSI_THOLD_OFF;
7799 return ret;
7800 }
7801
7802 for (i = 0; i < NUM_NL80211_BANDS; i++)
7803 match_sets->per_band_rssi_thold[i] = rssi_thold;
7804
7805 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7806 enum nl80211_band band = nla_type(attr);
7807
7808 if (band < 0 || band >= NUM_NL80211_BANDS)
7809 return -EINVAL;
7810
7811 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7812 }
7813
7814 return 0;
7815}
7816
Luciano Coelho256da022014-11-10 16:13:46 +02007817static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007818nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007819 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007820{
7821 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007822 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007823 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007824 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007825 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007826 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007827 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007828
Luciano Coelho256da022014-11-10 16:13:46 +02007829 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007830 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007831 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007832 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007833 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007834 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007835 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007836 }
7837
Luciano Coelho256da022014-11-10 16:13:46 +02007838 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7839 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007840 tmp)
7841 n_ssids++;
7842
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007843 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007844 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007845
Johannes Bergea73cbc2014-01-24 10:53:53 +01007846 /*
7847 * First, count the number of 'real' matchsets. Due to an issue with
7848 * the old implementation, matchsets containing only the RSSI attribute
7849 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7850 * RSSI for all matchsets, rather than their own matchset for reporting
7851 * all APs with a strong RSSI. This is needed to be compatible with
7852 * older userspace that treated a matchset with only the RSSI as the
7853 * global RSSI for all other matchsets - if there are other matchsets.
7854 */
Luciano Coelho256da022014-11-10 16:13:46 +02007855 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007856 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007857 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007858 tmp) {
7859 struct nlattr *rssi;
7860
Johannes Berg8cb08172019-04-26 14:07:28 +02007861 err = nla_parse_nested_deprecated(tb,
7862 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7863 attr,
7864 nl80211_match_policy,
7865 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007866 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007867 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007868
7869 /* SSID and BSSID are mutually exclusive */
7870 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7871 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7872 return ERR_PTR(-EINVAL);
7873
Johannes Bergea73cbc2014-01-24 10:53:53 +01007874 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007875 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7876 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007877 n_match_sets++;
7878 continue;
7879 }
7880 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7881 if (rssi)
7882 default_match_rssi = nla_get_s32(rssi);
7883 }
7884 }
7885
7886 /* However, if there's no other matchset, add the RSSI one */
7887 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7888 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007889
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007890 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007891 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007892
Luciano Coelho256da022014-11-10 16:13:46 +02007893 if (attrs[NL80211_ATTR_IE])
7894 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007895 else
7896 ie_len = 0;
7897
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007898 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007899 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007900
Avraham Stern3b06d272015-10-12 09:51:34 +03007901 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7902 /*
7903 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7904 * each scan plan already specifies its own interval
7905 */
7906 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7907 return ERR_PTR(-EINVAL);
7908
7909 nla_for_each_nested(attr,
7910 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7911 n_plans++;
7912 } else {
7913 /*
7914 * The scan interval attribute is kept for backward
7915 * compatibility. If no scan plans are specified and sched scan
7916 * interval is specified, one scan plan will be set with this
7917 * scan interval and infinite number of iterations.
7918 */
7919 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7920 return ERR_PTR(-EINVAL);
7921
7922 n_plans = 1;
7923 }
7924
7925 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7926 return ERR_PTR(-EINVAL);
7927
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007928 if (!wiphy_ext_feature_isset(
7929 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7930 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7931 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7932 return ERR_PTR(-EINVAL);
7933
Luciano Coelho807f8a82011-05-11 17:09:35 +03007934 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007935 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007936 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007937 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007938 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007939 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007940 if (!request)
7941 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007942
7943 if (n_ssids)
7944 request->ssids = (void *)&request->channels[n_channels];
7945 request->n_ssids = n_ssids;
7946 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007947 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007948 request->ie = (void *)(request->ssids + n_ssids);
7949 else
7950 request->ie = (void *)(request->channels + n_channels);
7951 }
7952
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007953 if (n_match_sets) {
7954 if (request->ie)
7955 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007956 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007957 request->match_sets =
7958 (void *)(request->ssids + n_ssids);
7959 else
7960 request->match_sets =
7961 (void *)(request->channels + n_channels);
7962 }
7963 request->n_match_sets = n_match_sets;
7964
Avraham Stern3b06d272015-10-12 09:51:34 +03007965 if (n_match_sets)
7966 request->scan_plans = (void *)(request->match_sets +
7967 n_match_sets);
7968 else if (request->ie)
7969 request->scan_plans = (void *)(request->ie + ie_len);
7970 else if (n_ssids)
7971 request->scan_plans = (void *)(request->ssids + n_ssids);
7972 else
7973 request->scan_plans = (void *)(request->channels + n_channels);
7974
7975 request->n_scan_plans = n_plans;
7976
Luciano Coelho807f8a82011-05-11 17:09:35 +03007977 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007978 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007979 /* user specified, bail out if channel not found */
7980 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007981 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007982 tmp) {
7983 struct ieee80211_channel *chan;
7984
7985 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7986
7987 if (!chan) {
7988 err = -EINVAL;
7989 goto out_free;
7990 }
7991
7992 /* ignore disabled channels */
7993 if (chan->flags & IEEE80211_CHAN_DISABLED)
7994 continue;
7995
7996 request->channels[i] = chan;
7997 i++;
7998 }
7999 } else {
8000 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008001 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008002 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008003
Luciano Coelho807f8a82011-05-11 17:09:35 +03008004 if (!wiphy->bands[band])
8005 continue;
8006 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8007 struct ieee80211_channel *chan;
8008
8009 chan = &wiphy->bands[band]->channels[j];
8010
8011 if (chan->flags & IEEE80211_CHAN_DISABLED)
8012 continue;
8013
8014 request->channels[i] = chan;
8015 i++;
8016 }
8017 }
8018 }
8019
8020 if (!i) {
8021 err = -EINVAL;
8022 goto out_free;
8023 }
8024
8025 request->n_channels = i;
8026
8027 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008028 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02008029 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008030 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008031 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008032 err = -EINVAL;
8033 goto out_free;
8034 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008035 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008036 memcpy(request->ssids[i].ssid, nla_data(attr),
8037 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03008038 i++;
8039 }
8040 }
8041
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008042 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008043 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008044 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008045 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008046 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01008047 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008048
Johannes Berg8cb08172019-04-26 14:07:28 +02008049 err = nla_parse_nested_deprecated(tb,
8050 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8051 attr,
8052 nl80211_match_policy,
8053 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01008054 if (err)
8055 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02008056 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01008057 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02008058
8059 if (!ssid && !bssid) {
8060 i++;
8061 continue;
8062 }
8063
8064 if (WARN_ON(i >= n_match_sets)) {
8065 /* this indicates a programming error,
8066 * the loop above should have verified
8067 * things properly
8068 */
8069 err = -EINVAL;
8070 goto out_free;
8071 }
8072
8073 if (ssid) {
8074 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008075 err = -EINVAL;
8076 goto out_free;
8077 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008078 memcpy(request->match_sets[i].ssid.ssid,
8079 nla_data(ssid), nla_len(ssid));
8080 request->match_sets[i].ssid.ssid_len =
8081 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008082 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008083 if (bssid) {
8084 if (nla_len(bssid) != ETH_ALEN) {
8085 err = -EINVAL;
8086 goto out_free;
8087 }
8088 memcpy(request->match_sets[i].bssid,
8089 nla_data(bssid), ETH_ALEN);
8090 }
8091
8092 /* special attribute - old implementation w/a */
8093 request->match_sets[i].rssi_thold = default_match_rssi;
8094 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8095 if (rssi)
8096 request->match_sets[i].rssi_thold =
8097 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308098
8099 /* Parse per band RSSI attribute */
8100 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8101 &request->match_sets[i],
8102 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8103 request->match_sets[i].rssi_thold);
8104 if (err)
8105 goto out_free;
8106
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008107 i++;
8108 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008109
8110 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008111 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008112 request->match_sets[0].rssi_thold = default_match_rssi;
8113
8114 request->min_rssi_thold = INT_MAX;
8115 for (i = 0; i < n_match_sets; i++)
8116 request->min_rssi_thold =
8117 min(request->match_sets[i].rssi_thold,
8118 request->min_rssi_thold);
8119 } else {
8120 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008121 }
8122
Johannes Berg9900e482014-02-04 21:01:25 +01008123 if (ie_len) {
8124 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008125 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008126 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008127 request->ie_len);
8128 }
8129
Roee Zamir2d23d072017-08-06 11:38:22 +03008130 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8131 if (err)
8132 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008133
Luciano Coelho9c748932015-01-16 16:04:09 +02008134 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8135 request->delay =
8136 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8137
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008138 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8139 request->relative_rssi = nla_get_s8(
8140 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8141 request->relative_rssi_set = true;
8142 }
8143
8144 if (request->relative_rssi_set &&
8145 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8146 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8147
8148 rssi_adjust = nla_data(
8149 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8150 request->rssi_adjust.band = rssi_adjust->band;
8151 request->rssi_adjust.delta = rssi_adjust->delta;
8152 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8153 err = -EINVAL;
8154 goto out_free;
8155 }
8156 }
8157
Avraham Stern3b06d272015-10-12 09:51:34 +03008158 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8159 if (err)
8160 goto out_free;
8161
Sam Leffler15d60302012-10-11 21:03:34 -07008162 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008163
Luciano Coelho256da022014-11-10 16:13:46 +02008164 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008165
8166out_free:
8167 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008168 return ERR_PTR(err);
8169}
8170
8171static int nl80211_start_sched_scan(struct sk_buff *skb,
8172 struct genl_info *info)
8173{
8174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8175 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008176 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008177 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008178 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008179 int err;
8180
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008181 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008182 return -EOPNOTSUPP;
8183
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008184 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8185 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8186 if (err)
8187 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008188
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008189 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008190 info->attrs,
8191 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008192
8193 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008194 if (err)
8195 goto out_err;
8196
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008197 /* leave request id zero for legacy request
8198 * or if driver does not support multi-scheduled scan
8199 */
8200 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
8201 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02008202 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008203 }
8204
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008205 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008206 if (err)
8207 goto out_free;
8208
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008209 sched_scan_req->dev = dev;
8210 sched_scan_req->wiphy = &rdev->wiphy;
8211
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008212 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8213 sched_scan_req->owner_nlportid = info->snd_portid;
8214
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008215 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008216
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008217 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008218 return 0;
8219
8220out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008221 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008222out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008223 return err;
8224}
8225
8226static int nl80211_stop_sched_scan(struct sk_buff *skb,
8227 struct genl_info *info)
8228{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008229 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008231 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008232
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008233 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008234 return -EOPNOTSUPP;
8235
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008236 if (info->attrs[NL80211_ATTR_COOKIE]) {
8237 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8238 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8239 }
8240
8241 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8242 struct cfg80211_sched_scan_request,
8243 list);
8244 if (!req || req->reqid ||
8245 (req->owner_nlportid &&
8246 req->owner_nlportid != info->snd_portid))
8247 return -ENOENT;
8248
8249 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008250}
8251
Simon Wunderlich04f39042013-02-08 18:16:19 +01008252static int nl80211_start_radar_detection(struct sk_buff *skb,
8253 struct genl_info *info)
8254{
8255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8256 struct net_device *dev = info->user_ptr[1];
8257 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008258 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008259 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008260 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008261 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008262 int err;
8263
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008264 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008265 if (dfs_region == NL80211_DFS_UNSET)
8266 return -EINVAL;
8267
Simon Wunderlich04f39042013-02-08 18:16:19 +01008268 err = nl80211_parse_chandef(rdev, info, &chandef);
8269 if (err)
8270 return err;
8271
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008272 if (netif_carrier_ok(dev))
8273 return -EBUSY;
8274
Simon Wunderlich04f39042013-02-08 18:16:19 +01008275 if (wdev->cac_started)
8276 return -EBUSY;
8277
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008278 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008279 if (err < 0)
8280 return err;
8281
8282 if (err == 0)
8283 return -EINVAL;
8284
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008285 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008286 return -EINVAL;
8287
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008288 /* CAC start is offloaded to HW and can't be started manually */
8289 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8290 return -EOPNOTSUPP;
8291
Simon Wunderlich04f39042013-02-08 18:16:19 +01008292 if (!rdev->ops->start_radar_detection)
8293 return -EOPNOTSUPP;
8294
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008295 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8296 if (WARN_ON(!cac_time_ms))
8297 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8298
Ilan Peera1056b1b2015-10-22 22:27:46 +03008299 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008300 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008301 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008302 wdev->cac_started = true;
8303 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008304 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008305 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008306 return err;
8307}
8308
Sriram R30c63112018-12-04 17:46:52 +05308309static int nl80211_notify_radar_detection(struct sk_buff *skb,
8310 struct genl_info *info)
8311{
8312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8313 struct net_device *dev = info->user_ptr[1];
8314 struct wireless_dev *wdev = dev->ieee80211_ptr;
8315 struct wiphy *wiphy = wdev->wiphy;
8316 struct cfg80211_chan_def chandef;
8317 enum nl80211_dfs_regions dfs_region;
8318 int err;
8319
8320 dfs_region = reg_get_dfs_region(wiphy);
8321 if (dfs_region == NL80211_DFS_UNSET) {
8322 GENL_SET_ERR_MSG(info,
8323 "DFS Region is not set. Unexpected Radar indication");
8324 return -EINVAL;
8325 }
8326
8327 err = nl80211_parse_chandef(rdev, info, &chandef);
8328 if (err) {
8329 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8330 return err;
8331 }
8332
8333 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8334 if (err < 0) {
8335 GENL_SET_ERR_MSG(info, "chandef is invalid");
8336 return err;
8337 }
8338
8339 if (err == 0) {
8340 GENL_SET_ERR_MSG(info,
8341 "Unexpected Radar indication for chandef/iftype");
8342 return -EINVAL;
8343 }
8344
8345 /* Do not process this notification if radar is already detected
8346 * by kernel on this channel, and return success.
8347 */
8348 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8349 return 0;
8350
8351 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8352
8353 cfg80211_sched_dfs_chan_update(rdev);
8354
Luca Coelhoa680fe42019-04-17 09:34:40 +03008355 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308356
8357 /* Propagate this notification to other radios as well */
8358 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8359
8360 return 0;
8361}
8362
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008363static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8364{
8365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8366 struct net_device *dev = info->user_ptr[1];
8367 struct wireless_dev *wdev = dev->ieee80211_ptr;
8368 struct cfg80211_csa_settings params;
8369 /* csa_attrs is defined static to avoid waste of stack size - this
8370 * function is called under RTNL lock, so this should not be a problem.
8371 */
8372 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008373 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008374 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008375 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008376 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008377 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008378
8379 if (!rdev->ops->channel_switch ||
8380 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8381 return -EOPNOTSUPP;
8382
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008383 switch (dev->ieee80211_ptr->iftype) {
8384 case NL80211_IFTYPE_AP:
8385 case NL80211_IFTYPE_P2P_GO:
8386 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008387 /* For all modes except AP the handle_dfs flag needs to be
8388 * supplied to tell the kernel that userspace will handle radar
8389 * events when they happen. Otherwise a switch to a channel
8390 * requiring DFS will be rejected.
8391 */
8392 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008393
8394 /* useless if AP is not running */
8395 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008396 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008397 break;
8398 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008399 if (!wdev->ssid_len)
8400 return -ENOTCONN;
8401 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008402 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008403 if (!wdev->mesh_id_len)
8404 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008405 break;
8406 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008407 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008408 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008409
8410 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008411 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008412
8413 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8414 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8415 return -EINVAL;
8416
8417 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008418 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008419 return -EINVAL;
8420
Luciano Coelho252e07c2014-10-08 09:48:34 +03008421 /* Even though the attribute is u32, the specification says
8422 * u8, so let's make sure we don't overflow.
8423 */
8424 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8425 if (cs_count > 255)
8426 return -EINVAL;
8427
8428 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008429
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008430 if (!need_new_beacon)
8431 goto skip_beacons;
8432
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008433 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008434 if (err)
8435 return err;
8436
Johannes Berg8cb08172019-04-26 14:07:28 +02008437 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8438 info->attrs[NL80211_ATTR_CSA_IES],
8439 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008440 if (err)
8441 return err;
8442
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008443 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008444 if (err)
8445 return err;
8446
8447 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8448 return -EINVAL;
8449
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008450 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8451 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008452 return -EINVAL;
8453
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008454 params.n_counter_offsets_beacon = len / sizeof(u16);
8455 if (rdev->wiphy.max_num_csa_counters &&
8456 (params.n_counter_offsets_beacon >
8457 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008458 return -EINVAL;
8459
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008460 params.counter_offsets_beacon =
8461 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8462
8463 /* sanity checks - counters should fit and be the same */
8464 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8465 u16 offset = params.counter_offsets_beacon[i];
8466
8467 if (offset >= params.beacon_csa.tail_len)
8468 return -EINVAL;
8469
8470 if (params.beacon_csa.tail[offset] != params.count)
8471 return -EINVAL;
8472 }
8473
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008474 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008475 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8476 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008477 return -EINVAL;
8478
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008479 params.n_counter_offsets_presp = len / sizeof(u16);
8480 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008481 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008482 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008483 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008484
8485 params.counter_offsets_presp =
8486 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8487
8488 /* sanity checks - counters should fit and be the same */
8489 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8490 u16 offset = params.counter_offsets_presp[i];
8491
8492 if (offset >= params.beacon_csa.probe_resp_len)
8493 return -EINVAL;
8494
8495 if (params.beacon_csa.probe_resp[offset] !=
8496 params.count)
8497 return -EINVAL;
8498 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008499 }
8500
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008501skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008502 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8503 if (err)
8504 return err;
8505
Arik Nemtsov923b3522015-07-08 15:41:44 +03008506 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8507 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008508 return -EINVAL;
8509
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008510 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8511 &params.chandef,
8512 wdev->iftype);
8513 if (err < 0)
8514 return err;
8515
Benjamin Berg8d9de162017-05-16 11:23:12 +02008516 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008517 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008518 if (need_handle_dfs_flag &&
8519 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8520 return -EINVAL;
8521 }
8522 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008523
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008524 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8525 params.block_tx = true;
8526
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008527 wdev_lock(wdev);
8528 err = rdev_channel_switch(rdev, dev, &params);
8529 wdev_unlock(wdev);
8530
8531 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008532}
8533
Johannes Berg9720bb32011-06-21 09:45:33 +02008534static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8535 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008536 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008537 struct wireless_dev *wdev,
8538 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008539{
Johannes Berg48ab9052009-07-10 18:42:31 +02008540 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008541 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008542 void *hdr;
8543 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008544
8545 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008546
Eric W. Biederman15e47302012-09-07 20:12:54 +00008547 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008548 NL80211_CMD_NEW_SCAN_RESULTS);
8549 if (!hdr)
8550 return -1;
8551
Michal Kubecek0a833c22017-11-15 13:09:32 +01008552 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008553
Johannes Berg97990a02013-04-19 01:02:55 +02008554 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8555 goto nla_put_failure;
8556 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008557 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8558 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008559 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8560 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008561 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008562
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008563 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01008564 if (!bss)
8565 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008566 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008567 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008568 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008569
8570 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008571 /* indicate whether we have probe response data or not */
8572 if (rcu_access_pointer(res->proberesp_ies) &&
8573 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8574 goto fail_unlock_rcu;
8575
8576 /* this pointer prefers to be pointed to probe response data
8577 * but is always valid
8578 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008579 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008580 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008581 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8582 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008583 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008584 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8585 ies->len, ies->data))
8586 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008587 }
Johannes Berg0e227082014-08-12 20:34:30 +02008588
8589 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008590 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008591 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008592 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8593 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008594 goto fail_unlock_rcu;
8595 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8596 ies->len, ies->data))
8597 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008598 }
8599 rcu_read_unlock();
8600
David S. Miller9360ffd2012-03-29 04:41:26 -04008601 if (res->beacon_interval &&
8602 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8603 goto nla_put_failure;
8604 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8605 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008606 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008607 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8608 jiffies_to_msecs(jiffies - intbss->ts)))
8609 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008610
Avraham Stern1d762502016-07-05 17:10:13 +03008611 if (intbss->parent_tsf &&
8612 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8613 intbss->parent_tsf, NL80211_BSS_PAD) ||
8614 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8615 intbss->parent_bssid)))
8616 goto nla_put_failure;
8617
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008618 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008619 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8620 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008621 goto nla_put_failure;
8622
Sunil Dutt983dafa2017-12-13 19:51:36 +02008623 if (!nl80211_put_signal(msg, intbss->pub.chains,
8624 intbss->pub.chain_signal,
8625 NL80211_BSS_CHAIN_SIGNAL))
8626 goto nla_put_failure;
8627
Johannes Berg77965c972009-02-18 18:45:06 +01008628 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008629 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008630 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8631 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008632 break;
8633 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008634 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8635 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008636 break;
8637 default:
8638 break;
8639 }
8640
Johannes Berg48ab9052009-07-10 18:42:31 +02008641 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008642 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008643 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008644 if (intbss == wdev->current_bss &&
8645 nla_put_u32(msg, NL80211_BSS_STATUS,
8646 NL80211_BSS_STATUS_ASSOCIATED))
8647 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008648 break;
8649 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008650 if (intbss == wdev->current_bss &&
8651 nla_put_u32(msg, NL80211_BSS_STATUS,
8652 NL80211_BSS_STATUS_IBSS_JOINED))
8653 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008654 break;
8655 default:
8656 break;
8657 }
8658
Johannes Berg2a519312009-02-10 21:25:55 +01008659 nla_nest_end(msg, bss);
8660
Johannes Berg053c0952015-01-16 22:09:00 +01008661 genlmsg_end(msg, hdr);
8662 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008663
Johannes Berg8cef2c92013-02-05 16:54:31 +01008664 fail_unlock_rcu:
8665 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008666 nla_put_failure:
8667 genlmsg_cancel(msg, hdr);
8668 return -EMSGSIZE;
8669}
8670
Johannes Berg97990a02013-04-19 01:02:55 +02008671static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008672{
Johannes Berg48ab9052009-07-10 18:42:31 +02008673 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008674 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008675 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008676 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008677 int err;
8678
Johannes Bergea90e0d2017-03-15 14:26:04 +01008679 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008680 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008681 if (err) {
8682 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008683 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008684 }
Johannes Berg2a519312009-02-10 21:25:55 +01008685
Johannes Berg48ab9052009-07-10 18:42:31 +02008686 wdev_lock(wdev);
8687 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008688
8689 /*
8690 * dump_scan will be called multiple times to break up the scan results
8691 * into multiple messages. It is unlikely that any more bss-es will be
8692 * expired after the first call, so only call only call this on the
8693 * first dump_scan invocation.
8694 */
8695 if (start == 0)
8696 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008697
Johannes Berg9720bb32011-06-21 09:45:33 +02008698 cb->seq = rdev->bss_generation;
8699
Johannes Berg48ab9052009-07-10 18:42:31 +02008700 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008701 if (++idx <= start)
8702 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008703 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008704 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008705 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008706 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008707 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008708 }
8709 }
8710
Johannes Berg48ab9052009-07-10 18:42:31 +02008711 spin_unlock_bh(&rdev->bss_lock);
8712 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008713
Johannes Berg97990a02013-04-19 01:02:55 +02008714 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008715 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008716
Johannes Berg67748892010-10-04 21:14:06 +02008717 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008718}
8719
Eric W. Biederman15e47302012-09-07 20:12:54 +00008720static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008721 int flags, struct net_device *dev,
8722 bool allow_radio_stats,
8723 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008724{
8725 void *hdr;
8726 struct nlattr *infoattr;
8727
Johannes Berg11f78ac2014-11-14 16:43:50 +01008728 /* skip radio stats if userspace didn't request them */
8729 if (!survey->channel && !allow_radio_stats)
8730 return 0;
8731
Eric W. Biederman15e47302012-09-07 20:12:54 +00008732 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008733 NL80211_CMD_NEW_SURVEY_RESULTS);
8734 if (!hdr)
8735 return -ENOMEM;
8736
David S. Miller9360ffd2012-03-29 04:41:26 -04008737 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8738 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008739
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008740 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01008741 if (!infoattr)
8742 goto nla_put_failure;
8743
Johannes Berg11f78ac2014-11-14 16:43:50 +01008744 if (survey->channel &&
8745 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008746 survey->channel->center_freq))
8747 goto nla_put_failure;
8748
8749 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8750 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8751 goto nla_put_failure;
8752 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8753 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8754 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008755 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008756 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8757 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008758 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008759 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008760 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8761 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008762 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008763 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008764 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8765 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008766 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008767 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008768 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8769 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008770 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008771 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008772 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8773 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008774 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008775 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008776 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8777 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008778 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008779
8780 nla_nest_end(msg, infoattr);
8781
Johannes Berg053c0952015-01-16 22:09:00 +01008782 genlmsg_end(msg, hdr);
8783 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008784
8785 nla_put_failure:
8786 genlmsg_cancel(msg, hdr);
8787 return -EMSGSIZE;
8788}
8789
Johannes Berg11f78ac2014-11-14 16:43:50 +01008790static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008791{
Johannes Berg50508d92019-07-29 16:31:09 +02008792 struct nlattr **attrbuf;
Holger Schurig61fa7132009-11-11 12:25:40 +01008793 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008794 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008795 struct wireless_dev *wdev;
8796 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008797 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008798 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008799
Johannes Berg50508d92019-07-29 16:31:09 +02008800 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
8801 if (!attrbuf)
8802 return -ENOMEM;
8803
Johannes Bergea90e0d2017-03-15 14:26:04 +01008804 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008805 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008806 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008807 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008808
Johannes Berg11f78ac2014-11-14 16:43:50 +01008809 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008810 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008811
Johannes Berg97990a02013-04-19 01:02:55 +02008812 if (!wdev->netdev) {
8813 res = -EINVAL;
8814 goto out_err;
8815 }
8816
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008817 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008818 res = -EOPNOTSUPP;
8819 goto out_err;
8820 }
8821
8822 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008823 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008824 if (res == -ENOENT)
8825 break;
8826 if (res)
8827 goto out_err;
8828
Johannes Berg11f78ac2014-11-14 16:43:50 +01008829 /* don't send disabled channels, but do send non-channel data */
8830 if (survey.channel &&
8831 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008832 survey_idx++;
8833 continue;
8834 }
8835
Holger Schurig61fa7132009-11-11 12:25:40 +01008836 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008837 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008838 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008839 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008840 goto out;
8841 survey_idx++;
8842 }
8843
8844 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008845 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008846 res = skb->len;
8847 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02008848 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008849 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008850 return res;
8851}
8852
Samuel Ortizb23aa672009-07-01 21:26:54 +02008853static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8854{
8855 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00008856 NL80211_WPA_VERSION_2 |
8857 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02008858}
8859
Jouni Malinen636a5d32009-03-19 13:39:22 +02008860static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8861{
Johannes Berg4c476992010-10-04 21:36:35 +02008862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8863 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008864 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008865 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8866 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008867 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008868 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008869 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008870
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008871 if (!info->attrs[NL80211_ATTR_MAC])
8872 return -EINVAL;
8873
Jouni Malinen17780922009-03-27 20:52:47 +02008874 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8875 return -EINVAL;
8876
Johannes Berg19957bb2009-07-02 17:20:43 +02008877 if (!info->attrs[NL80211_ATTR_SSID])
8878 return -EINVAL;
8879
8880 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8881 return -EINVAL;
8882
Johannes Bergfffd0932009-07-08 14:22:54 +02008883 err = nl80211_parse_key(info, &key);
8884 if (err)
8885 return err;
8886
8887 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008888 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8889 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008890 if (!key.p.key || !key.p.key_len)
8891 return -EINVAL;
8892 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8893 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8894 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8895 key.p.key_len != WLAN_KEY_LEN_WEP104))
8896 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008897 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008898 return -EINVAL;
8899 } else {
8900 key.p.key_len = 0;
8901 key.p.key = NULL;
8902 }
8903
Johannes Bergafea0b72010-08-10 09:46:42 +02008904 if (key.idx >= 0) {
8905 int i;
8906 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008907
Johannes Bergafea0b72010-08-10 09:46:42 +02008908 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8909 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8910 ok = true;
8911 break;
8912 }
8913 }
Johannes Berg4c476992010-10-04 21:36:35 +02008914 if (!ok)
8915 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008916 }
8917
Johannes Berg4c476992010-10-04 21:36:35 +02008918 if (!rdev->ops->auth)
8919 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008920
Johannes Berg074ac8d2010-09-16 14:58:22 +02008921 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8923 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008924
Johannes Berg19957bb2009-07-02 17:20:43 +02008925 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008926 chan = nl80211_get_valid_chan(&rdev->wiphy,
8927 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8928 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008929 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008930
Johannes Berg19957bb2009-07-02 17:20:43 +02008931 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8932 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8933
8934 if (info->attrs[NL80211_ATTR_IE]) {
8935 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8936 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8937 }
8938
8939 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008940 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008941 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008942
Jouni Malinen63181062016-10-27 00:42:02 +03008943 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8944 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8945 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8946 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008947 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008948 return -EINVAL;
8949
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008950 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008951 if (auth_type != NL80211_AUTHTYPE_SAE &&
8952 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8953 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8954 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008955 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008956 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8957 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008958 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008959 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008960 return -EINVAL;
8961 }
8962
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008963 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8964
Johannes Berg95de8172012-01-20 13:55:25 +01008965 /*
8966 * Since we no longer track auth state, ignore
8967 * requests to only change local state.
8968 */
8969 if (local_state_change)
8970 return 0;
8971
Johannes Berg91bf9b22013-05-15 17:44:01 +02008972 wdev_lock(dev->ieee80211_ptr);
8973 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8974 ssid, ssid_len, ie, ie_len,
8975 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008976 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008977 wdev_unlock(dev->ieee80211_ptr);
8978 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008979}
8980
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008981static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8982 struct genl_info *info)
8983{
8984 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8985 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8986 return -EINVAL;
8987 }
8988
8989 if (!rdev->ops->tx_control_port ||
8990 !wiphy_ext_feature_isset(&rdev->wiphy,
8991 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8992 return -EOPNOTSUPP;
8993
8994 return 0;
8995}
8996
Johannes Bergc0692b82010-08-27 14:26:53 +03008997static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8998 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008999 struct cfg80211_crypto_settings *settings,
9000 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009001{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02009002 memset(settings, 0, sizeof(*settings));
9003
Samuel Ortizb23aa672009-07-01 21:26:54 +02009004 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9005
Johannes Bergc0692b82010-08-27 14:26:53 +03009006 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9007 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009008
Johannes Bergc0692b82010-08-27 14:26:53 +03009009 proto = nla_get_u16(
9010 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9011 settings->control_port_ethertype = cpu_to_be16(proto);
9012 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9013 proto != ETH_P_PAE)
9014 return -EINVAL;
9015 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9016 settings->control_port_no_encrypt = true;
9017 } else
9018 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9019
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009020 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9021 int r = validate_pae_over_nl80211(rdev, info);
9022
9023 if (r < 0)
9024 return r;
9025
9026 settings->control_port_over_nl80211 = true;
9027 }
9028
Samuel Ortizb23aa672009-07-01 21:26:54 +02009029 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9030 void *data;
9031 int len, i;
9032
9033 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9034 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9035 settings->n_ciphers_pairwise = len / sizeof(u32);
9036
9037 if (len % sizeof(u32))
9038 return -EINVAL;
9039
Johannes Berg3dc27d22009-07-02 21:36:37 +02009040 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009041 return -EINVAL;
9042
9043 memcpy(settings->ciphers_pairwise, data, len);
9044
9045 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009046 if (!cfg80211_supported_cipher_suite(
9047 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009048 settings->ciphers_pairwise[i]))
9049 return -EINVAL;
9050 }
9051
9052 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9053 settings->cipher_group =
9054 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009055 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9056 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009057 return -EINVAL;
9058 }
9059
9060 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9061 settings->wpa_versions =
9062 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9063 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9064 return -EINVAL;
9065 }
9066
9067 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9068 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03009069 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009070
9071 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9072 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9073 settings->n_akm_suites = len / sizeof(u32);
9074
9075 if (len % sizeof(u32))
9076 return -EINVAL;
9077
Jouni Malinen1b9ca022011-09-21 16:13:07 +03009078 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9079 return -EINVAL;
9080
Samuel Ortizb23aa672009-07-01 21:26:54 +02009081 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009082 }
9083
Eliad Peller91b5ab62017-06-09 13:08:42 +01009084 if (info->attrs[NL80211_ATTR_PMK]) {
9085 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9086 return -EINVAL;
9087 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9088 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
9089 return -EINVAL;
9090 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9091 }
9092
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009093 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9094 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9095 NL80211_EXT_FEATURE_SAE_OFFLOAD))
9096 return -EINVAL;
9097 settings->sae_pwd =
9098 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9099 settings->sae_pwd_len =
9100 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9101 }
9102
Samuel Ortizb23aa672009-07-01 21:26:54 +02009103 return 0;
9104}
9105
Jouni Malinen636a5d32009-03-19 13:39:22 +02009106static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9107{
Johannes Berg4c476992010-10-04 21:36:35 +02009108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9109 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009110 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009111 struct cfg80211_assoc_request req = {};
9112 const u8 *bssid, *ssid;
9113 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009114
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009115 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9116 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9117 return -EPERM;
9118
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009119 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009120 !info->attrs[NL80211_ATTR_SSID] ||
9121 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009122 return -EINVAL;
9123
Johannes Berg4c476992010-10-04 21:36:35 +02009124 if (!rdev->ops->assoc)
9125 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009126
Johannes Berg074ac8d2010-09-16 14:58:22 +02009127 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009128 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9129 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009130
Johannes Berg19957bb2009-07-02 17:20:43 +02009131 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009132
Jouni Malinen664834d2014-01-15 00:01:44 +02009133 chan = nl80211_get_valid_chan(&rdev->wiphy,
9134 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9135 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009136 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009137
Johannes Berg19957bb2009-07-02 17:20:43 +02009138 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9139 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009140
9141 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009142 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9143 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009144 }
9145
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009146 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009147 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009148 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009149 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009150 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009151 else if (mfp != NL80211_MFP_NO)
9152 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009153 }
9154
Johannes Berg3e5d7642009-07-07 14:37:26 +02009155 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009156 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009157
Ben Greear7e7c8922011-11-18 11:31:59 -08009158 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009159 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009160
9161 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009162 memcpy(&req.ht_capa_mask,
9163 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9164 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009165
9166 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009167 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009168 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009169 memcpy(&req.ht_capa,
9170 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9171 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009172 }
9173
Johannes Bergee2aca32013-02-21 17:36:01 +01009174 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009175 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009176
9177 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009178 memcpy(&req.vht_capa_mask,
9179 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9180 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009181
9182 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009183 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009184 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009185 memcpy(&req.vht_capa,
9186 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9187 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009188 }
9189
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009190 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009191 if (!((rdev->wiphy.features &
9192 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9193 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9194 !wiphy_ext_feature_isset(&rdev->wiphy,
9195 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009196 return -EINVAL;
9197 req.flags |= ASSOC_REQ_USE_RRM;
9198 }
9199
Jouni Malinen348bd452016-10-27 00:42:03 +03009200 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9201 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9202 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9203 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9204 return -EINVAL;
9205 req.fils_nonces =
9206 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9207 }
9208
Johannes Bergf62fab72013-02-21 20:09:09 +01009209 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009210 if (!err) {
9211 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009212
Johannes Bergf62fab72013-02-21 20:09:09 +01009213 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9214 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009215
9216 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9217 dev->ieee80211_ptr->conn_owner_nlportid =
9218 info->snd_portid;
9219 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9220 bssid, ETH_ALEN);
9221 }
9222
Johannes Berg91bf9b22013-05-15 17:44:01 +02009223 wdev_unlock(dev->ieee80211_ptr);
9224 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009225
Jouni Malinen636a5d32009-03-19 13:39:22 +02009226 return err;
9227}
9228
9229static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9230{
Johannes Berg4c476992010-10-04 21:36:35 +02009231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9232 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009233 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009234 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009235 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009236 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009237
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009238 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9239 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9240 return -EPERM;
9241
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009242 if (!info->attrs[NL80211_ATTR_MAC])
9243 return -EINVAL;
9244
9245 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9246 return -EINVAL;
9247
Johannes Berg4c476992010-10-04 21:36:35 +02009248 if (!rdev->ops->deauth)
9249 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009250
Johannes Berg074ac8d2010-09-16 14:58:22 +02009251 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009252 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9253 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009254
Johannes Berg19957bb2009-07-02 17:20:43 +02009255 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009256
Johannes Berg19957bb2009-07-02 17:20:43 +02009257 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9258 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009259 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009260 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009261 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009262
9263 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009264 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9265 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009266 }
9267
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009268 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9269
Johannes Berg91bf9b22013-05-15 17:44:01 +02009270 wdev_lock(dev->ieee80211_ptr);
9271 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9272 local_state_change);
9273 wdev_unlock(dev->ieee80211_ptr);
9274 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009275}
9276
9277static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9278{
Johannes Berg4c476992010-10-04 21:36:35 +02009279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9280 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009281 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009282 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009283 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009284 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009285
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009286 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9287 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9288 return -EPERM;
9289
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009290 if (!info->attrs[NL80211_ATTR_MAC])
9291 return -EINVAL;
9292
9293 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9294 return -EINVAL;
9295
Johannes Berg4c476992010-10-04 21:36:35 +02009296 if (!rdev->ops->disassoc)
9297 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009298
Johannes Berg074ac8d2010-09-16 14:58:22 +02009299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009300 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9301 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009302
Johannes Berg19957bb2009-07-02 17:20:43 +02009303 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009304
Johannes Berg19957bb2009-07-02 17:20:43 +02009305 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9306 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009307 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009308 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009309 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009310
9311 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009312 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9313 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009314 }
9315
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009316 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9317
Johannes Berg91bf9b22013-05-15 17:44:01 +02009318 wdev_lock(dev->ieee80211_ptr);
9319 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9320 local_state_change);
9321 wdev_unlock(dev->ieee80211_ptr);
9322 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009323}
9324
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009325static bool
9326nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009327 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009328 int rateval)
9329{
9330 struct wiphy *wiphy = &rdev->wiphy;
9331 bool found = false;
9332 int band, i;
9333
Johannes Berg57fbcce2016-04-12 15:56:15 +02009334 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009335 struct ieee80211_supported_band *sband;
9336
9337 sband = wiphy->bands[band];
9338 if (!sband)
9339 continue;
9340
9341 for (i = 0; i < sband->n_bitrates; i++) {
9342 if (sband->bitrates[i].bitrate == rateval) {
9343 mcast_rate[band] = i + 1;
9344 found = true;
9345 break;
9346 }
9347 }
9348 }
9349
9350 return found;
9351}
9352
Johannes Berg04a773a2009-04-19 21:24:32 +02009353static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9354{
Johannes Berg4c476992010-10-04 21:36:35 +02009355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9356 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009357 struct cfg80211_ibss_params ibss;
9358 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009359 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009360 int err;
9361
Johannes Berg8e30bc52009-04-22 17:45:38 +02009362 memset(&ibss, 0, sizeof(ibss));
9363
Johannes Berg683b6d32012-11-08 21:25:48 +01009364 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009365 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9366 return -EINVAL;
9367
Johannes Berg8e30bc52009-04-22 17:45:38 +02009368 ibss.beacon_interval = 100;
9369
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309370 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009371 ibss.beacon_interval =
9372 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309373
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309374 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9375 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309376 if (err)
9377 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009378
Johannes Berg4c476992010-10-04 21:36:35 +02009379 if (!rdev->ops->join_ibss)
9380 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009381
Johannes Berg4c476992010-10-04 21:36:35 +02009382 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9383 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009384
Johannes Berg79c97e92009-07-07 03:56:12 +02009385 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009386
Johannes Berg39193492011-09-16 13:45:25 +02009387 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009388 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009389
9390 if (!is_valid_ether_addr(ibss.bssid))
9391 return -EINVAL;
9392 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009393 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9394 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9395
9396 if (info->attrs[NL80211_ATTR_IE]) {
9397 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9398 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9399 }
9400
Johannes Berg683b6d32012-11-08 21:25:48 +01009401 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9402 if (err)
9403 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009404
Ilan Peer174e0cd2014-02-23 09:13:01 +02009405 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9406 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009407 return -EINVAL;
9408
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009409 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009410 case NL80211_CHAN_WIDTH_5:
9411 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009412 case NL80211_CHAN_WIDTH_20_NOHT:
9413 break;
9414 case NL80211_CHAN_WIDTH_20:
9415 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009416 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9417 return -EINVAL;
9418 break;
9419 case NL80211_CHAN_WIDTH_80:
9420 case NL80211_CHAN_WIDTH_80P80:
9421 case NL80211_CHAN_WIDTH_160:
9422 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9423 return -EINVAL;
9424 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9425 NL80211_EXT_FEATURE_VHT_IBSS))
9426 return -EINVAL;
9427 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009428 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009429 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009430 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009431
Johannes Berg04a773a2009-04-19 21:24:32 +02009432 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009433 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009434
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009435 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9436 u8 *rates =
9437 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9438 int n_rates =
9439 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9440 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009441 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009442
Johannes Berg34850ab2011-07-18 18:08:35 +02009443 err = ieee80211_get_ratemask(sband, rates, n_rates,
9444 &ibss.basic_rates);
9445 if (err)
9446 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009447 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009448
Simon Wunderlich803768f2013-06-28 10:39:58 +02009449 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9450 memcpy(&ibss.ht_capa_mask,
9451 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9452 sizeof(ibss.ht_capa_mask));
9453
9454 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9455 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9456 return -EINVAL;
9457 memcpy(&ibss.ht_capa,
9458 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9459 sizeof(ibss.ht_capa));
9460 }
9461
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009462 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9463 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9464 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9465 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009466
Johannes Berg4c476992010-10-04 21:36:35 +02009467 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309468 bool no_ht = false;
9469
Johannes Berg768075e2017-11-13 15:35:06 +01009470 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009471 if (IS_ERR(connkeys))
9472 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309473
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009474 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9475 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009476 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309477 return -EINVAL;
9478 }
Johannes Berg4c476992010-10-04 21:36:35 +02009479 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009480
Antonio Quartulli267335d2012-01-31 20:25:47 +01009481 ibss.control_port =
9482 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9483
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009484 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9485 int r = validate_pae_over_nl80211(rdev, info);
9486
Johannes Bergd350a0f2018-12-15 11:03:22 +02009487 if (r < 0) {
9488 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009489 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009490 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009491
9492 ibss.control_port_over_nl80211 = true;
9493 }
9494
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009495 ibss.userspace_handles_dfs =
9496 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9497
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009498 wdev_lock(dev->ieee80211_ptr);
9499 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009500 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009501 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009502 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9503 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9504 wdev_unlock(dev->ieee80211_ptr);
9505
Johannes Berg04a773a2009-04-19 21:24:32 +02009506 return err;
9507}
9508
9509static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9510{
Johannes Berg4c476992010-10-04 21:36:35 +02009511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9512 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009513
Johannes Berg4c476992010-10-04 21:36:35 +02009514 if (!rdev->ops->leave_ibss)
9515 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009516
Johannes Berg4c476992010-10-04 21:36:35 +02009517 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9518 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009519
Johannes Berg4c476992010-10-04 21:36:35 +02009520 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009521}
9522
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009523static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9524{
9525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9526 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009527 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009528 u32 nla_rate;
9529 int err;
9530
9531 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009532 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9533 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009534 return -EOPNOTSUPP;
9535
9536 if (!rdev->ops->set_mcast_rate)
9537 return -EOPNOTSUPP;
9538
9539 memset(mcast_rate, 0, sizeof(mcast_rate));
9540
9541 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9542 return -EINVAL;
9543
9544 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9545 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9546 return -EINVAL;
9547
Ilan Peera1056b1b2015-10-22 22:27:46 +03009548 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009549
9550 return err;
9551}
9552
Johannes Bergad7e7182013-11-13 13:37:47 +01009553static struct sk_buff *
9554__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009555 struct wireless_dev *wdev, int approxlen,
9556 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009557 enum nl80211_attrs attr,
9558 const struct nl80211_vendor_cmd_info *info,
9559 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009560{
9561 struct sk_buff *skb;
9562 void *hdr;
9563 struct nlattr *data;
9564
9565 skb = nlmsg_new(approxlen + 100, gfp);
9566 if (!skb)
9567 return NULL;
9568
9569 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9570 if (!hdr) {
9571 kfree_skb(skb);
9572 return NULL;
9573 }
9574
9575 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9576 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009577
9578 if (info) {
9579 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9580 info->vendor_id))
9581 goto nla_put_failure;
9582 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9583 info->subcmd))
9584 goto nla_put_failure;
9585 }
9586
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009587 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009588 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9589 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009590 goto nla_put_failure;
9591 if (wdev->netdev &&
9592 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9593 wdev->netdev->ifindex))
9594 goto nla_put_failure;
9595 }
9596
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009597 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009598 if (!data)
9599 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009600
9601 ((void **)skb->cb)[0] = rdev;
9602 ((void **)skb->cb)[1] = hdr;
9603 ((void **)skb->cb)[2] = data;
9604
9605 return skb;
9606
9607 nla_put_failure:
9608 kfree_skb(skb);
9609 return NULL;
9610}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009611
Johannes Berge03ad6e2014-01-01 17:22:30 +01009612struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009613 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009614 enum nl80211_commands cmd,
9615 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009616 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009617 int vendor_event_idx,
9618 int approxlen, gfp_t gfp)
9619{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009620 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009621 const struct nl80211_vendor_cmd_info *info;
9622
9623 switch (cmd) {
9624 case NL80211_CMD_TESTMODE:
9625 if (WARN_ON(vendor_event_idx != -1))
9626 return NULL;
9627 info = NULL;
9628 break;
9629 case NL80211_CMD_VENDOR:
9630 if (WARN_ON(vendor_event_idx < 0 ||
9631 vendor_event_idx >= wiphy->n_vendor_events))
9632 return NULL;
9633 info = &wiphy->vendor_events[vendor_event_idx];
9634 break;
9635 default:
9636 WARN_ON(1);
9637 return NULL;
9638 }
9639
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009640 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009641 cmd, attr, info, gfp);
9642}
9643EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9644
9645void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9646{
9647 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9648 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009649 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009650 struct nlattr *data = ((void **)skb->cb)[2];
9651 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9652
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009653 /* clear CB data for netlink core to own from now on */
9654 memset(skb->cb, 0, sizeof(skb->cb));
9655
Johannes Berge03ad6e2014-01-01 17:22:30 +01009656 nla_nest_end(skb, data);
9657 genlmsg_end(skb, hdr);
9658
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009659 if (nlhdr->nlmsg_pid) {
9660 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9661 nlhdr->nlmsg_pid);
9662 } else {
9663 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9664 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +01009665
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009666 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9667 skb, 0, mcgrp, gfp);
9668 }
Johannes Berge03ad6e2014-01-01 17:22:30 +01009669}
9670EXPORT_SYMBOL(__cfg80211_send_event_skb);
9671
Johannes Bergaff89a92009-07-01 21:26:51 +02009672#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009673static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9674{
Johannes Berg4c476992010-10-04 21:36:35 +02009675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009676 struct wireless_dev *wdev =
9677 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009678 int err;
9679
David Spinadelfc73f112013-07-31 18:04:15 +03009680 if (!rdev->ops->testmode_cmd)
9681 return -EOPNOTSUPP;
9682
9683 if (IS_ERR(wdev)) {
9684 err = PTR_ERR(wdev);
9685 if (err != -EINVAL)
9686 return err;
9687 wdev = NULL;
9688 } else if (wdev->wiphy != &rdev->wiphy) {
9689 return -EINVAL;
9690 }
9691
Johannes Bergaff89a92009-07-01 21:26:51 +02009692 if (!info->attrs[NL80211_ATTR_TESTDATA])
9693 return -EINVAL;
9694
Johannes Bergad7e7182013-11-13 13:37:47 +01009695 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009696 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009697 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9698 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009699 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009700
Johannes Bergaff89a92009-07-01 21:26:51 +02009701 return err;
9702}
9703
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009704static int nl80211_testmode_dump(struct sk_buff *skb,
9705 struct netlink_callback *cb)
9706{
Johannes Berg00918d32011-12-13 17:22:05 +01009707 struct cfg80211_registered_device *rdev;
Johannes Berg50508d92019-07-29 16:31:09 +02009708 struct nlattr **attrbuf = NULL;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009709 int err;
9710 long phy_idx;
9711 void *data = NULL;
9712 int data_len = 0;
9713
Johannes Berg5fe231e2013-05-08 21:45:15 +02009714 rtnl_lock();
9715
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009716 if (cb->args[0]) {
9717 /*
9718 * 0 is a valid index, but not valid for args[0],
9719 * so we need to offset by 1.
9720 */
9721 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009722
9723 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9724 if (!rdev) {
9725 err = -ENOENT;
9726 goto out_err;
9727 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009728 } else {
Johannes Berg50508d92019-07-29 16:31:09 +02009729 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
9730 GFP_KERNEL);
9731 if (!attrbuf) {
9732 err = -ENOMEM;
9733 goto out_err;
9734 }
Johannes Bergc90c39d2016-10-24 14:40:01 +02009735
Johannes Berg8cb08172019-04-26 14:07:28 +02009736 err = nlmsg_parse_deprecated(cb->nlh,
9737 GENL_HDRLEN + nl80211_fam.hdrsize,
9738 attrbuf, nl80211_fam.maxattr,
9739 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009740 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009741 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009742
Johannes Bergc90c39d2016-10-24 14:40:01 +02009743 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009744 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009745 err = PTR_ERR(rdev);
9746 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009747 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009748 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009749
Johannes Bergc90c39d2016-10-24 14:40:01 +02009750 if (attrbuf[NL80211_ATTR_TESTDATA])
9751 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009752 }
9753
9754 if (cb->args[1]) {
9755 data = nla_data((void *)cb->args[1]);
9756 data_len = nla_len((void *)cb->args[1]);
9757 }
9758
Johannes Berg00918d32011-12-13 17:22:05 +01009759 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009760 err = -EOPNOTSUPP;
9761 goto out_err;
9762 }
9763
9764 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009765 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009766 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9767 NL80211_CMD_TESTMODE);
9768 struct nlattr *tmdata;
9769
Dan Carpentercb35fba2013-08-14 14:50:01 +03009770 if (!hdr)
9771 break;
9772
David S. Miller9360ffd2012-03-29 04:41:26 -04009773 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009774 genlmsg_cancel(skb, hdr);
9775 break;
9776 }
9777
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009778 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009779 if (!tmdata) {
9780 genlmsg_cancel(skb, hdr);
9781 break;
9782 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009783 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009784 nla_nest_end(skb, tmdata);
9785
9786 if (err == -ENOBUFS || err == -ENOENT) {
9787 genlmsg_cancel(skb, hdr);
9788 break;
9789 } else if (err) {
9790 genlmsg_cancel(skb, hdr);
9791 goto out_err;
9792 }
9793
9794 genlmsg_end(skb, hdr);
9795 }
9796
9797 err = skb->len;
9798 /* see above */
9799 cb->args[0] = phy_idx + 1;
9800 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02009801 kfree(attrbuf);
Johannes Berg5fe231e2013-05-08 21:45:15 +02009802 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009803 return err;
9804}
Johannes Bergaff89a92009-07-01 21:26:51 +02009805#endif
9806
Samuel Ortizb23aa672009-07-01 21:26:54 +02009807static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9808{
Johannes Berg4c476992010-10-04 21:36:35 +02009809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9810 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009811 struct cfg80211_connect_params connect;
9812 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009813 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009814 int err;
9815
9816 memset(&connect, 0, sizeof(connect));
9817
Samuel Ortizb23aa672009-07-01 21:26:54 +02009818 if (!info->attrs[NL80211_ATTR_SSID] ||
9819 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9820 return -EINVAL;
9821
9822 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9823 connect.auth_type =
9824 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009825 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9826 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009827 return -EINVAL;
9828 } else
9829 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9830
9831 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9832
Avraham Stern3a00df52017-06-09 13:08:43 +01009833 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9834 !wiphy_ext_feature_isset(&rdev->wiphy,
9835 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9836 return -EINVAL;
9837 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9838
Johannes Bergc0692b82010-08-27 14:26:53 +03009839 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009840 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009841 if (err)
9842 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009843
Johannes Berg074ac8d2010-09-16 14:58:22 +02009844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009845 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9846 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009847
Johannes Berg79c97e92009-07-07 03:56:12 +02009848 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009849
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309850 connect.bg_scan_period = -1;
9851 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9852 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9853 connect.bg_scan_period =
9854 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9855 }
9856
Samuel Ortizb23aa672009-07-01 21:26:54 +02009857 if (info->attrs[NL80211_ATTR_MAC])
9858 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009859 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9860 connect.bssid_hint =
9861 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009862 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9863 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9864
9865 if (info->attrs[NL80211_ATTR_IE]) {
9866 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9867 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9868 }
9869
Jouni Malinencee00a92013-01-15 17:15:57 +02009870 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9871 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009872 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9873 !wiphy_ext_feature_isset(&rdev->wiphy,
9874 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9875 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009876 } else {
9877 connect.mfp = NL80211_MFP_NO;
9878 }
9879
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009880 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9881 connect.prev_bssid =
9882 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9883
Samuel Ortizb23aa672009-07-01 21:26:54 +02009884 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009885 connect.channel = nl80211_get_valid_chan(
9886 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9887 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009888 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009889 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009890 connect.channel_hint = nl80211_get_valid_chan(
9891 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9892 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009893 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009894 }
9895
Johannes Bergfffd0932009-07-08 14:22:54 +02009896 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009897 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009898 if (IS_ERR(connkeys))
9899 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009900 }
9901
Ben Greear7e7c8922011-11-18 11:31:59 -08009902 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9903 connect.flags |= ASSOC_REQ_DISABLE_HT;
9904
9905 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9906 memcpy(&connect.ht_capa_mask,
9907 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9908 sizeof(connect.ht_capa_mask));
9909
9910 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009911 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009912 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009913 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009914 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009915 memcpy(&connect.ht_capa,
9916 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9917 sizeof(connect.ht_capa));
9918 }
9919
Johannes Bergee2aca32013-02-21 17:36:01 +01009920 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9921 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9922
9923 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9924 memcpy(&connect.vht_capa_mask,
9925 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9926 sizeof(connect.vht_capa_mask));
9927
9928 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9929 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009930 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009931 return -EINVAL;
9932 }
9933 memcpy(&connect.vht_capa,
9934 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9935 sizeof(connect.vht_capa));
9936 }
9937
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009938 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009939 if (!((rdev->wiphy.features &
9940 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9941 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9942 !wiphy_ext_feature_isset(&rdev->wiphy,
9943 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009944 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009945 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009946 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009947 connect.flags |= ASSOC_REQ_USE_RRM;
9948 }
9949
Lior David34d50512016-01-28 10:58:25 +02009950 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009951 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009952 kzfree(connkeys);
9953 return -EOPNOTSUPP;
9954 }
9955
Arend van Spriel38de03d2016-03-02 20:37:18 +01009956 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9957 /* bss selection makes no sense if bssid is set */
9958 if (connect.bssid) {
9959 kzfree(connkeys);
9960 return -EINVAL;
9961 }
9962
9963 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9964 wiphy, &connect.bss_select);
9965 if (err) {
9966 kzfree(connkeys);
9967 return err;
9968 }
9969 }
9970
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009971 if (wiphy_ext_feature_isset(&rdev->wiphy,
9972 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9973 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9974 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9975 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9976 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9977 connect.fils_erp_username =
9978 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9979 connect.fils_erp_username_len =
9980 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9981 connect.fils_erp_realm =
9982 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9983 connect.fils_erp_realm_len =
9984 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9985 connect.fils_erp_next_seq_num =
9986 nla_get_u16(
9987 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9988 connect.fils_erp_rrk =
9989 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9990 connect.fils_erp_rrk_len =
9991 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9992 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9993 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9994 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9995 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9996 kzfree(connkeys);
9997 return -EINVAL;
9998 }
9999
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010000 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10001 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +053010002 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010003 GENL_SET_ERR_MSG(info,
10004 "external auth requires connection ownership");
10005 return -EINVAL;
10006 }
10007 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10008 }
10009
Johannes Berg83739b02013-05-15 17:44:01 +020010010 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010011
Jouni Malinen4ce2bd92016-03-29 13:53:28 +030010012 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10013 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +020010014 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +030010015 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010016
10017 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10018 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10019 if (connect.bssid)
10020 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10021 connect.bssid, ETH_ALEN);
10022 else
10023 memset(dev->ieee80211_ptr->disconnect_bssid,
10024 0, ETH_ALEN);
10025 }
10026
10027 wdev_unlock(dev->ieee80211_ptr);
10028
Samuel Ortizb23aa672009-07-01 21:26:54 +020010029 return err;
10030}
10031
vamsi krishna088e8df2016-10-27 16:51:11 +030010032static int nl80211_update_connect_params(struct sk_buff *skb,
10033 struct genl_info *info)
10034{
10035 struct cfg80211_connect_params connect = {};
10036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10037 struct net_device *dev = info->user_ptr[1];
10038 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010039 bool fils_sk_offload;
10040 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +030010041 u32 changed = 0;
10042 int ret;
10043
10044 if (!rdev->ops->update_connect_params)
10045 return -EOPNOTSUPP;
10046
10047 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +030010048 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10049 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10050 changed |= UPDATE_ASSOC_IES;
10051 }
10052
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010053 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10054 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10055
10056 /*
10057 * when driver supports fils-sk offload all attributes must be
10058 * provided. So the else covers "fils-sk-not-all" and
10059 * "no-fils-sk-any".
10060 */
10061 if (fils_sk_offload &&
10062 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10063 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10064 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10065 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10066 connect.fils_erp_username =
10067 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10068 connect.fils_erp_username_len =
10069 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10070 connect.fils_erp_realm =
10071 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10072 connect.fils_erp_realm_len =
10073 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10074 connect.fils_erp_next_seq_num =
10075 nla_get_u16(
10076 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10077 connect.fils_erp_rrk =
10078 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10079 connect.fils_erp_rrk_len =
10080 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10081 changed |= UPDATE_FILS_ERP_INFO;
10082 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10083 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10084 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10085 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10086 return -EINVAL;
10087 }
10088
10089 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10090 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10091 if (!nl80211_valid_auth_type(rdev, auth_type,
10092 NL80211_CMD_CONNECT))
10093 return -EINVAL;
10094
10095 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10096 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10097 return -EINVAL;
10098
10099 connect.auth_type = auth_type;
10100 changed |= UPDATE_AUTH_TYPE;
10101 }
10102
vamsi krishna088e8df2016-10-27 16:51:11 +030010103 wdev_lock(dev->ieee80211_ptr);
10104 if (!wdev->current_bss)
10105 ret = -ENOLINK;
10106 else
10107 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10108 wdev_unlock(dev->ieee80211_ptr);
10109
10110 return ret;
10111}
10112
Samuel Ortizb23aa672009-07-01 21:26:54 +020010113static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10114{
Johannes Berg4c476992010-10-04 21:36:35 +020010115 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10116 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010117 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010118 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010119
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010120 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10121 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10122 return -EPERM;
10123
Samuel Ortizb23aa672009-07-01 21:26:54 +020010124 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10125 reason = WLAN_REASON_DEAUTH_LEAVING;
10126 else
10127 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10128
10129 if (reason == 0)
10130 return -EINVAL;
10131
Johannes Berg074ac8d2010-09-16 14:58:22 +020010132 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010133 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10134 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010135
Johannes Berg83739b02013-05-15 17:44:01 +020010136 wdev_lock(dev->ieee80211_ptr);
10137 ret = cfg80211_disconnect(rdev, dev, reason, true);
10138 wdev_unlock(dev->ieee80211_ptr);
10139 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010140}
10141
Johannes Berg463d0182009-07-14 00:33:35 +020010142static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10143{
Johannes Berg4c476992010-10-04 21:36:35 +020010144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010145 struct net *net;
10146 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010147
Vadim Kochan4b681c82015-01-12 16:34:05 +020010148 if (info->attrs[NL80211_ATTR_PID]) {
10149 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10150
10151 net = get_net_ns_by_pid(pid);
10152 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10153 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10154
10155 net = get_net_ns_by_fd(fd);
10156 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010157 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010158 }
Johannes Berg463d0182009-07-14 00:33:35 +020010159
Johannes Berg4c476992010-10-04 21:36:35 +020010160 if (IS_ERR(net))
10161 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010162
10163 err = 0;
10164
10165 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010166 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10167 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010168
Johannes Berg463d0182009-07-14 00:33:35 +020010169 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010170 return err;
10171}
10172
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010173static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10174{
Johannes Berg4c476992010-10-04 21:36:35 +020010175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010176 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10177 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010178 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010179 struct cfg80211_pmksa pmksa;
10180
10181 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10182
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010183 if (!info->attrs[NL80211_ATTR_PMKID])
10184 return -EINVAL;
10185
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010186 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010187
10188 if (info->attrs[NL80211_ATTR_MAC]) {
10189 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10190 } else if (info->attrs[NL80211_ATTR_SSID] &&
10191 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10192 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10193 info->attrs[NL80211_ATTR_PMK])) {
10194 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10195 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10196 pmksa.cache_id =
10197 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10198 } else {
10199 return -EINVAL;
10200 }
10201 if (info->attrs[NL80211_ATTR_PMK]) {
10202 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10203 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10204 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010205
Johannes Berg074ac8d2010-09-16 14:58:22 +020010206 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010207 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10208 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10209 wiphy_ext_feature_isset(&rdev->wiphy,
10210 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010211 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010212
10213 switch (info->genlhdr->cmd) {
10214 case NL80211_CMD_SET_PMKSA:
10215 rdev_ops = rdev->ops->set_pmksa;
10216 break;
10217 case NL80211_CMD_DEL_PMKSA:
10218 rdev_ops = rdev->ops->del_pmksa;
10219 break;
10220 default:
10221 WARN_ON(1);
10222 break;
10223 }
10224
Johannes Berg4c476992010-10-04 21:36:35 +020010225 if (!rdev_ops)
10226 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010227
Johannes Berg4c476992010-10-04 21:36:35 +020010228 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010229}
10230
10231static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10232{
Johannes Berg4c476992010-10-04 21:36:35 +020010233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10234 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010235
Johannes Berg074ac8d2010-09-16 14:58:22 +020010236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010237 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10238 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010239
Johannes Berg4c476992010-10-04 21:36:35 +020010240 if (!rdev->ops->flush_pmksa)
10241 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010242
Hila Gonene35e4d22012-06-27 17:19:42 +030010243 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010244}
10245
Arik Nemtsov109086c2011-09-28 14:12:50 +030010246static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10247{
10248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10249 struct net_device *dev = info->user_ptr[1];
10250 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010251 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010252 u16 status_code;
10253 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010254 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010255
10256 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10257 !rdev->ops->tdls_mgmt)
10258 return -EOPNOTSUPP;
10259
10260 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10261 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10262 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10263 !info->attrs[NL80211_ATTR_IE] ||
10264 !info->attrs[NL80211_ATTR_MAC])
10265 return -EINVAL;
10266
10267 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10268 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10269 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10270 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010271 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010272 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10273 peer_capability =
10274 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010275
Hila Gonene35e4d22012-06-27 17:19:42 +030010276 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010277 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010278 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010279 nla_data(info->attrs[NL80211_ATTR_IE]),
10280 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010281}
10282
10283static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10284{
10285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10286 struct net_device *dev = info->user_ptr[1];
10287 enum nl80211_tdls_operation operation;
10288 u8 *peer;
10289
10290 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10291 !rdev->ops->tdls_oper)
10292 return -EOPNOTSUPP;
10293
10294 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10295 !info->attrs[NL80211_ATTR_MAC])
10296 return -EINVAL;
10297
10298 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10299 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10300
Hila Gonene35e4d22012-06-27 17:19:42 +030010301 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010302}
10303
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010304static int nl80211_remain_on_channel(struct sk_buff *skb,
10305 struct genl_info *info)
10306{
Johannes Berg4c476992010-10-04 21:36:35 +020010307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010308 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010309 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010310 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010311 struct sk_buff *msg;
10312 void *hdr;
10313 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010314 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010315 int err;
10316
10317 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10318 !info->attrs[NL80211_ATTR_DURATION])
10319 return -EINVAL;
10320
10321 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10322
Johannes Berg7c4ef712011-11-18 15:33:48 +010010323 if (!rdev->ops->remain_on_channel ||
10324 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010325 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010326
Johannes Bergebf348f2012-06-01 12:50:54 +020010327 /*
10328 * We should be on that channel for at least a minimum amount of
10329 * time (10ms) but no longer than the driver supports.
10330 */
10331 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10332 duration > rdev->wiphy.max_remain_on_channel_duration)
10333 return -EINVAL;
10334
Johannes Berg683b6d32012-11-08 21:25:48 +010010335 err = nl80211_parse_chandef(rdev, info, &chandef);
10336 if (err)
10337 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010338
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010339 wdev_lock(wdev);
10340 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10341 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10342 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10343 &chandef);
10344 if (compat_chandef != &chandef) {
10345 wdev_unlock(wdev);
10346 return -EBUSY;
10347 }
10348 }
10349 wdev_unlock(wdev);
10350
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010351 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010352 if (!msg)
10353 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010354
Eric W. Biederman15e47302012-09-07 20:12:54 +000010355 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010356 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010357 if (!hdr) {
10358 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010359 goto free_msg;
10360 }
10361
Johannes Berg683b6d32012-11-08 21:25:48 +010010362 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10363 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010364
10365 if (err)
10366 goto free_msg;
10367
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010368 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10369 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010370 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010371
10372 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010373
10374 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010375
10376 nla_put_failure:
10377 err = -ENOBUFS;
10378 free_msg:
10379 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010380 return err;
10381}
10382
10383static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10384 struct genl_info *info)
10385{
Johannes Berg4c476992010-10-04 21:36:35 +020010386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010387 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010388 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010389
10390 if (!info->attrs[NL80211_ATTR_COOKIE])
10391 return -EINVAL;
10392
Johannes Berg4c476992010-10-04 21:36:35 +020010393 if (!rdev->ops->cancel_remain_on_channel)
10394 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010395
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010396 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10397
Hila Gonene35e4d22012-06-27 17:19:42 +030010398 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010399}
10400
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010401static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10402 struct genl_info *info)
10403{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010404 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010406 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010407 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010408
Johannes Berg4c476992010-10-04 21:36:35 +020010409 if (!rdev->ops->set_bitrate_mask)
10410 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010411
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010412 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10413 if (err)
10414 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010415
Hila Gonene35e4d22012-06-27 17:19:42 +030010416 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010417}
10418
Johannes Berg2e161f782010-08-12 15:38:38 +020010419static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010420{
Johannes Berg4c476992010-10-04 21:36:35 +020010421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010422 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010423 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010424
10425 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10426 return -EINVAL;
10427
Johannes Berg2e161f782010-08-12 15:38:38 +020010428 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10429 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010430
Johannes Berg71bbc992012-06-15 15:30:18 +020010431 switch (wdev->iftype) {
10432 case NL80211_IFTYPE_STATION:
10433 case NL80211_IFTYPE_ADHOC:
10434 case NL80211_IFTYPE_P2P_CLIENT:
10435 case NL80211_IFTYPE_AP:
10436 case NL80211_IFTYPE_AP_VLAN:
10437 case NL80211_IFTYPE_MESH_POINT:
10438 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010439 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010440 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010441 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010442 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010443 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010444 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010445
10446 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010447 if (!rdev->ops->mgmt_tx)
10448 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010449
Eric W. Biederman15e47302012-09-07 20:12:54 +000010450 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010451 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10452 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010453}
10454
Johannes Berg2e161f782010-08-12 15:38:38 +020010455static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010456{
Johannes Berg4c476992010-10-04 21:36:35 +020010457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010458 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010459 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010460 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010461 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010462 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010463 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010464 struct cfg80211_mgmt_tx_params params = {
10465 .dont_wait_for_ack =
10466 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10467 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010468
Johannes Berg683b6d32012-11-08 21:25:48 +010010469 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010470 return -EINVAL;
10471
Johannes Berg4c476992010-10-04 21:36:35 +020010472 if (!rdev->ops->mgmt_tx)
10473 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010474
Johannes Berg71bbc992012-06-15 15:30:18 +020010475 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010476 case NL80211_IFTYPE_P2P_DEVICE:
10477 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10478 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010479 case NL80211_IFTYPE_STATION:
10480 case NL80211_IFTYPE_ADHOC:
10481 case NL80211_IFTYPE_P2P_CLIENT:
10482 case NL80211_IFTYPE_AP:
10483 case NL80211_IFTYPE_AP_VLAN:
10484 case NL80211_IFTYPE_MESH_POINT:
10485 case NL80211_IFTYPE_P2P_GO:
10486 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010487 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010488 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010489 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010490 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010491
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010492 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010493 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010494 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010495 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010496
10497 /*
10498 * We should wait on the channel for at least a minimum amount
10499 * of time (10ms) but no longer than the driver supports.
10500 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010501 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10502 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010503 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010504 }
10505
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010506 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010507
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010508 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010509 return -EINVAL;
10510
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010511 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010512
Antonio Quartulliea141b752013-06-11 14:20:03 +020010513 /* get the channel if any has been specified, otherwise pass NULL to
10514 * the driver. The latter will use the current one
10515 */
10516 chandef.chan = NULL;
10517 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10518 err = nl80211_parse_chandef(rdev, info, &chandef);
10519 if (err)
10520 return err;
10521 }
10522
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010523 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010524 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010525
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010526 wdev_lock(wdev);
10527 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10528 wdev_unlock(wdev);
10529 return -EBUSY;
10530 }
10531 wdev_unlock(wdev);
10532
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010533 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10534 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10535
10536 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10537 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10538 int i;
10539
10540 if (len % sizeof(u16))
10541 return -EINVAL;
10542
10543 params.n_csa_offsets = len / sizeof(u16);
10544 params.csa_offsets =
10545 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10546
10547 /* check that all the offsets fit the frame */
10548 for (i = 0; i < params.n_csa_offsets; i++) {
10549 if (params.csa_offsets[i] >= params.len)
10550 return -EINVAL;
10551 }
10552 }
10553
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010554 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010555 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10556 if (!msg)
10557 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010558
Eric W. Biederman15e47302012-09-07 20:12:54 +000010559 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010560 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010561 if (!hdr) {
10562 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010563 goto free_msg;
10564 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010565 }
Johannes Berge247bd902011-11-04 11:18:21 +010010566
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010567 params.chan = chandef.chan;
10568 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010569 if (err)
10570 goto free_msg;
10571
Johannes Berge247bd902011-11-04 11:18:21 +010010572 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010573 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10574 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010575 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010576
Johannes Berge247bd902011-11-04 11:18:21 +010010577 genlmsg_end(msg, hdr);
10578 return genlmsg_reply(msg, info);
10579 }
10580
10581 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010582
10583 nla_put_failure:
10584 err = -ENOBUFS;
10585 free_msg:
10586 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010587 return err;
10588}
10589
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010590static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10591{
10592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010593 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010594 u64 cookie;
10595
10596 if (!info->attrs[NL80211_ATTR_COOKIE])
10597 return -EINVAL;
10598
10599 if (!rdev->ops->mgmt_tx_cancel_wait)
10600 return -EOPNOTSUPP;
10601
Johannes Berg71bbc992012-06-15 15:30:18 +020010602 switch (wdev->iftype) {
10603 case NL80211_IFTYPE_STATION:
10604 case NL80211_IFTYPE_ADHOC:
10605 case NL80211_IFTYPE_P2P_CLIENT:
10606 case NL80211_IFTYPE_AP:
10607 case NL80211_IFTYPE_AP_VLAN:
10608 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010609 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010610 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010611 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010612 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010613 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010614 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010615
10616 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10617
Hila Gonene35e4d22012-06-27 17:19:42 +030010618 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010619}
10620
Kalle Valoffb9eb32010-02-17 17:58:10 +020010621static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10622{
Johannes Berg4c476992010-10-04 21:36:35 +020010623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010624 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010625 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010626 u8 ps_state;
10627 bool state;
10628 int err;
10629
Johannes Berg4c476992010-10-04 21:36:35 +020010630 if (!info->attrs[NL80211_ATTR_PS_STATE])
10631 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010632
10633 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10634
Kalle Valoffb9eb32010-02-17 17:58:10 +020010635 wdev = dev->ieee80211_ptr;
10636
Johannes Berg4c476992010-10-04 21:36:35 +020010637 if (!rdev->ops->set_power_mgmt)
10638 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010639
10640 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10641
10642 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010643 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010644
Hila Gonene35e4d22012-06-27 17:19:42 +030010645 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010646 if (!err)
10647 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010648 return err;
10649}
10650
10651static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10652{
Johannes Berg4c476992010-10-04 21:36:35 +020010653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010654 enum nl80211_ps_state ps_state;
10655 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010656 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010657 struct sk_buff *msg;
10658 void *hdr;
10659 int err;
10660
Kalle Valoffb9eb32010-02-17 17:58:10 +020010661 wdev = dev->ieee80211_ptr;
10662
Johannes Berg4c476992010-10-04 21:36:35 +020010663 if (!rdev->ops->set_power_mgmt)
10664 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010665
10666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010667 if (!msg)
10668 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010669
Eric W. Biederman15e47302012-09-07 20:12:54 +000010670 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010671 NL80211_CMD_GET_POWER_SAVE);
10672 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010673 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010674 goto free_msg;
10675 }
10676
10677 if (wdev->ps)
10678 ps_state = NL80211_PS_ENABLED;
10679 else
10680 ps_state = NL80211_PS_DISABLED;
10681
David S. Miller9360ffd2012-03-29 04:41:26 -040010682 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10683 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010684
10685 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010686 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010687
Johannes Berg4c476992010-10-04 21:36:35 +020010688 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010689 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010690 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010691 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010692 return err;
10693}
10694
Johannes Berg94e860f2014-01-20 23:58:15 +010010695static const struct nla_policy
10696nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010697 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010698 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10699 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010700 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10701 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10702 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010703 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010704};
10705
Thomas Pedersen84f10702012-07-12 16:17:33 -070010706static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010707 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010708{
10709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010710 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010711 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010712
Johannes Bergd9d8b012012-11-26 12:51:52 +010010713 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010714 return -EINVAL;
10715
Thomas Pedersen84f10702012-07-12 16:17:33 -070010716 if (!rdev->ops->set_cqm_txe_config)
10717 return -EOPNOTSUPP;
10718
10719 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10720 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10721 return -EOPNOTSUPP;
10722
Hila Gonene35e4d22012-06-27 17:19:42 +030010723 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010724}
10725
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010726static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10727 struct net_device *dev)
10728{
10729 struct wireless_dev *wdev = dev->ieee80211_ptr;
10730 s32 last, low, high;
10731 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010732 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010733 int err;
10734
10735 /* RSSI reporting disabled? */
10736 if (!wdev->cqm_config)
10737 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10738
10739 /*
10740 * Obtain current RSSI value if possible, if not and no RSSI threshold
10741 * event has been received yet, we should receive an event after a
10742 * connection is established and enough beacons received to calculate
10743 * the average.
10744 */
10745 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10746 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010747 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010748 u8 *mac_addr;
10749
10750 mac_addr = wdev->current_bss->pub.bssid;
10751
Johannes Berg73887fd2018-05-18 09:57:55 +020010752 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10753 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010754 return err;
10755
Omer Efrat397c6572018-06-17 13:06:14 +030010756 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010757 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010758 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010759 }
10760
10761 last = wdev->cqm_config->last_rssi_event_value;
10762 hyst = wdev->cqm_config->rssi_hyst;
10763 n = wdev->cqm_config->n_rssi_thresholds;
10764
10765 for (i = 0; i < n; i++)
10766 if (last < wdev->cqm_config->rssi_thresholds[i])
10767 break;
10768
Masashi Honma1222a162018-09-25 11:15:01 +090010769 low_index = i - 1;
10770 if (low_index >= 0) {
10771 low_index = array_index_nospec(low_index, n);
10772 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10773 } else {
10774 low = S32_MIN;
10775 }
10776 if (i < n) {
10777 i = array_index_nospec(i, n);
10778 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10779 } else {
10780 high = S32_MAX;
10781 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010782
10783 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10784}
10785
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010786static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010787 const s32 *thresholds, int n_thresholds,
10788 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010789{
Johannes Berg4c476992010-10-04 21:36:35 +020010790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010791 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010792 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010793 int i, err;
10794 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010795
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010796 /* Check all values negative and sorted */
10797 for (i = 0; i < n_thresholds; i++) {
10798 if (thresholds[i] > 0 || thresholds[i] <= prev)
10799 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010800
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010801 prev = thresholds[i];
10802 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010803
Johannes Berg074ac8d2010-09-16 14:58:22 +020010804 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010805 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10806 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010807
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010808 wdev_lock(wdev);
10809 cfg80211_cqm_config_free(wdev);
10810 wdev_unlock(wdev);
10811
10812 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10813 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10814 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10815
10816 return rdev_set_cqm_rssi_config(rdev, dev,
10817 thresholds[0], hysteresis);
10818 }
10819
10820 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10821 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10822 return -EOPNOTSUPP;
10823
10824 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10825 n_thresholds = 0;
10826
10827 wdev_lock(wdev);
10828 if (n_thresholds) {
10829 struct cfg80211_cqm_config *cqm_config;
10830
10831 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10832 n_thresholds * sizeof(s32), GFP_KERNEL);
10833 if (!cqm_config) {
10834 err = -ENOMEM;
10835 goto unlock;
10836 }
10837
10838 cqm_config->rssi_hyst = hysteresis;
10839 cqm_config->n_rssi_thresholds = n_thresholds;
10840 memcpy(cqm_config->rssi_thresholds, thresholds,
10841 n_thresholds * sizeof(s32));
10842
10843 wdev->cqm_config = cqm_config;
10844 }
10845
10846 err = cfg80211_cqm_rssi_update(rdev, dev);
10847
10848unlock:
10849 wdev_unlock(wdev);
10850
10851 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010852}
10853
10854static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10855{
10856 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10857 struct nlattr *cqm;
10858 int err;
10859
10860 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010861 if (!cqm)
10862 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010863
Johannes Berg8cb08172019-04-26 14:07:28 +020010864 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10865 nl80211_attr_cqm_policy,
10866 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010867 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010868 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010869
10870 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10871 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010872 const s32 *thresholds =
10873 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10874 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010875 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010876
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010877 if (len % 4)
10878 return -EINVAL;
10879
10880 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10881 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010882 }
10883
10884 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10885 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10886 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10887 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10888 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10889 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10890
10891 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10892 }
10893
10894 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010895}
10896
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010897static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10898{
10899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10900 struct net_device *dev = info->user_ptr[1];
10901 struct ocb_setup setup = {};
10902 int err;
10903
10904 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10905 if (err)
10906 return err;
10907
10908 return cfg80211_join_ocb(rdev, dev, &setup);
10909}
10910
10911static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10912{
10913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10914 struct net_device *dev = info->user_ptr[1];
10915
10916 return cfg80211_leave_ocb(rdev, dev);
10917}
10918
Johannes Berg29cbe682010-12-03 09:20:44 +010010919static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10920{
10921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10922 struct net_device *dev = info->user_ptr[1];
10923 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010924 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010925 int err;
10926
10927 /* start with default */
10928 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010929 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010930
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010931 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010932 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010933 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010934 if (err)
10935 return err;
10936 }
10937
10938 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10939 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10940 return -EINVAL;
10941
Javier Cardonac80d5452010-12-16 17:37:49 -080010942 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10943 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10944
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010945 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10946 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10947 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10948 return -EINVAL;
10949
Marco Porsch9bdbf042013-01-07 16:04:51 +010010950 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10951 setup.beacon_interval =
10952 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010953
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010954 err = cfg80211_validate_beacon_int(rdev,
10955 NL80211_IFTYPE_MESH_POINT,
10956 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010957 if (err)
10958 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010959 }
10960
10961 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10962 setup.dtim_period =
10963 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10964 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10965 return -EINVAL;
10966 }
10967
Javier Cardonac80d5452010-12-16 17:37:49 -080010968 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10969 /* parse additional setup parameters if given */
10970 err = nl80211_parse_mesh_setup(info, &setup);
10971 if (err)
10972 return err;
10973 }
10974
Thomas Pedersend37bb182013-03-04 13:06:13 -080010975 if (setup.user_mpm)
10976 cfg.auto_open_plinks = false;
10977
Johannes Bergcc1d2802012-05-16 23:50:20 +020010978 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010979 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10980 if (err)
10981 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010982 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010983 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010984 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010985 }
10986
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010987 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10988 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10989 int n_rates =
10990 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10991 struct ieee80211_supported_band *sband;
10992
10993 if (!setup.chandef.chan)
10994 return -EINVAL;
10995
10996 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10997
10998 err = ieee80211_get_ratemask(sband, rates, n_rates,
10999 &setup.basic_rates);
11000 if (err)
11001 return err;
11002 }
11003
Johannes Berg8564e382016-09-19 09:44:44 +020011004 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11005 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
11006 if (err)
11007 return err;
11008
Johannes Berg265698d2017-09-18 22:46:36 +020011009 if (!setup.chandef.chan)
11010 return -EINVAL;
11011
Johannes Berg8564e382016-09-19 09:44:44 +020011012 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11013 &setup.beacon_rate);
11014 if (err)
11015 return err;
11016 }
11017
Benjamin Bergd37d49c2017-05-16 11:23:11 +020011018 setup.userspace_handles_dfs =
11019 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11020
Denis Kenzior1224f582018-03-26 12:52:49 -050011021 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11022 int r = validate_pae_over_nl80211(rdev, info);
11023
11024 if (r < 0)
11025 return r;
11026
11027 setup.control_port_over_nl80211 = true;
11028 }
11029
Denis Kenzior188c1b32018-03-26 12:52:46 -050011030 wdev_lock(dev->ieee80211_ptr);
11031 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11032 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11033 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11034 wdev_unlock(dev->ieee80211_ptr);
11035
11036 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010011037}
11038
11039static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11040{
11041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11042 struct net_device *dev = info->user_ptr[1];
11043
11044 return cfg80211_leave_mesh(rdev, dev);
11045}
11046
Johannes Bergdfb89c52012-06-27 09:23:48 +020011047#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011048static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11049 struct cfg80211_registered_device *rdev)
11050{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011051 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011052 struct nlattr *nl_pats, *nl_pat;
11053 int i, pat_len;
11054
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011055 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011056 return 0;
11057
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011058 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011059 if (!nl_pats)
11060 return -ENOBUFS;
11061
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011062 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011063 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011064 if (!nl_pat)
11065 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011066 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011067 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011068 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011069 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11070 wowlan->patterns[i].pattern) ||
11071 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011072 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011073 return -ENOBUFS;
11074 nla_nest_end(msg, nl_pat);
11075 }
11076 nla_nest_end(msg, nl_pats);
11077
11078 return 0;
11079}
11080
Johannes Berg2a0e0472013-01-23 22:57:40 +010011081static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11082 struct cfg80211_wowlan_tcp *tcp)
11083{
11084 struct nlattr *nl_tcp;
11085
11086 if (!tcp)
11087 return 0;
11088
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011089 nl_tcp = nla_nest_start_noflag(msg,
11090 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011091 if (!nl_tcp)
11092 return -ENOBUFS;
11093
Jiri Benc930345e2015-03-29 16:59:25 +020011094 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11095 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010011096 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11097 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11098 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11099 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11100 tcp->payload_len, tcp->payload) ||
11101 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11102 tcp->data_interval) ||
11103 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11104 tcp->wake_len, tcp->wake_data) ||
11105 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11106 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11107 return -ENOBUFS;
11108
11109 if (tcp->payload_seq.len &&
11110 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11111 sizeof(tcp->payload_seq), &tcp->payload_seq))
11112 return -ENOBUFS;
11113
11114 if (tcp->payload_tok.len &&
11115 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11116 sizeof(tcp->payload_tok) + tcp->tokens_size,
11117 &tcp->payload_tok))
11118 return -ENOBUFS;
11119
Johannes Berge248ad32013-05-16 10:24:28 +020011120 nla_nest_end(msg, nl_tcp);
11121
Johannes Berg2a0e0472013-01-23 22:57:40 +010011122 return 0;
11123}
11124
Luciano Coelho75453cc2015-01-09 14:06:37 +020011125static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11126 struct cfg80211_sched_scan_request *req)
11127{
Avraham Stern3b06d272015-10-12 09:51:34 +030011128 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011129 int i;
11130
11131 if (!req)
11132 return 0;
11133
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011134 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011135 if (!nd)
11136 return -ENOBUFS;
11137
Avraham Stern3b06d272015-10-12 09:51:34 +030011138 if (req->n_scan_plans == 1 &&
11139 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11140 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011141 return -ENOBUFS;
11142
Luciano Coelho21fea562015-03-17 16:36:01 +020011143 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11144 return -ENOBUFS;
11145
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011146 if (req->relative_rssi_set) {
11147 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11148
11149 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11150 req->relative_rssi))
11151 return -ENOBUFS;
11152
11153 rssi_adjust.band = req->rssi_adjust.band;
11154 rssi_adjust.delta = req->rssi_adjust.delta;
11155 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11156 sizeof(rssi_adjust), &rssi_adjust))
11157 return -ENOBUFS;
11158 }
11159
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011160 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011161 if (!freqs)
11162 return -ENOBUFS;
11163
Johannes Berg53b18982016-09-14 09:59:21 +020011164 for (i = 0; i < req->n_channels; i++) {
11165 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11166 return -ENOBUFS;
11167 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011168
11169 nla_nest_end(msg, freqs);
11170
11171 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011172 matches = nla_nest_start_noflag(msg,
11173 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011174 if (!matches)
11175 return -ENOBUFS;
11176
Luciano Coelho75453cc2015-01-09 14:06:37 +020011177 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011178 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011179 if (!match)
11180 return -ENOBUFS;
11181
Johannes Berg53b18982016-09-14 09:59:21 +020011182 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11183 req->match_sets[i].ssid.ssid_len,
11184 req->match_sets[i].ssid.ssid))
11185 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011186 nla_nest_end(msg, match);
11187 }
11188 nla_nest_end(msg, matches);
11189 }
11190
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011191 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011192 if (!scan_plans)
11193 return -ENOBUFS;
11194
11195 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011196 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011197 if (!scan_plan)
11198 return -ENOBUFS;
11199
Colin Ian King67626962018-09-06 10:58:44 +010011200 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011201 req->scan_plans[i].interval) ||
11202 (req->scan_plans[i].iterations &&
11203 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11204 req->scan_plans[i].iterations)))
11205 return -ENOBUFS;
11206 nla_nest_end(msg, scan_plan);
11207 }
11208 nla_nest_end(msg, scan_plans);
11209
Luciano Coelho75453cc2015-01-09 14:06:37 +020011210 nla_nest_end(msg, nd);
11211
11212 return 0;
11213}
11214
Johannes Bergff1b6e62011-05-04 15:37:28 +020011215static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11216{
11217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11218 struct sk_buff *msg;
11219 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011220 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011221
Johannes Berg964dc9e2013-06-03 17:25:34 +020011222 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011223 return -EOPNOTSUPP;
11224
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011225 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011226 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011227 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11228 rdev->wiphy.wowlan_config->tcp->payload_len +
11229 rdev->wiphy.wowlan_config->tcp->wake_len +
11230 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011231 }
11232
11233 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011234 if (!msg)
11235 return -ENOMEM;
11236
Eric W. Biederman15e47302012-09-07 20:12:54 +000011237 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011238 NL80211_CMD_GET_WOWLAN);
11239 if (!hdr)
11240 goto nla_put_failure;
11241
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011242 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011243 struct nlattr *nl_wowlan;
11244
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011245 nl_wowlan = nla_nest_start_noflag(msg,
11246 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011247 if (!nl_wowlan)
11248 goto nla_put_failure;
11249
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011250 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011251 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011252 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011253 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011254 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011255 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011256 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011257 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011258 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011259 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011260 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011261 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011262 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011263 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11264 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011265
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011266 if (nl80211_send_wowlan_patterns(msg, rdev))
11267 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011268
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011269 if (nl80211_send_wowlan_tcp(msg,
11270 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011271 goto nla_put_failure;
11272
Luciano Coelho75453cc2015-01-09 14:06:37 +020011273 if (nl80211_send_wowlan_nd(
11274 msg,
11275 rdev->wiphy.wowlan_config->nd_config))
11276 goto nla_put_failure;
11277
Johannes Bergff1b6e62011-05-04 15:37:28 +020011278 nla_nest_end(msg, nl_wowlan);
11279 }
11280
11281 genlmsg_end(msg, hdr);
11282 return genlmsg_reply(msg, info);
11283
11284nla_put_failure:
11285 nlmsg_free(msg);
11286 return -ENOBUFS;
11287}
11288
Johannes Berg2a0e0472013-01-23 22:57:40 +010011289static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11290 struct nlattr *attr,
11291 struct cfg80211_wowlan *trig)
11292{
11293 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11294 struct cfg80211_wowlan_tcp *cfg;
11295 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11296 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11297 u32 size;
11298 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11299 int err, port;
11300
Johannes Berg964dc9e2013-06-03 17:25:34 +020011301 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011302 return -EINVAL;
11303
Johannes Berg8cb08172019-04-26 14:07:28 +020011304 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11305 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011306 if (err)
11307 return err;
11308
11309 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11310 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11311 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11312 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11313 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11314 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11315 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11316 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11317 return -EINVAL;
11318
11319 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011320 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011321 return -EINVAL;
11322
11323 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011324 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011325 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011326 return -EINVAL;
11327
11328 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011329 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011330 return -EINVAL;
11331
11332 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11333 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11334 return -EINVAL;
11335
11336 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11337 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11338
11339 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11340 tokens_size = tokln - sizeof(*tok);
11341
11342 if (!tok->len || tokens_size % tok->len)
11343 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011344 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011345 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011346 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011347 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011348 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011349 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011350 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011351 return -EINVAL;
11352 if (tok->offset + tok->len > data_size)
11353 return -EINVAL;
11354 }
11355
11356 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11357 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011358 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011359 return -EINVAL;
11360 if (seq->len == 0 || seq->len > 4)
11361 return -EINVAL;
11362 if (seq->len + seq->offset > data_size)
11363 return -EINVAL;
11364 }
11365
11366 size = sizeof(*cfg);
11367 size += data_size;
11368 size += wake_size + wake_mask_size;
11369 size += tokens_size;
11370
11371 cfg = kzalloc(size, GFP_KERNEL);
11372 if (!cfg)
11373 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011374 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11375 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011376 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11377 ETH_ALEN);
11378 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11379 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11380 else
11381 port = 0;
11382#ifdef CONFIG_INET
11383 /* allocate a socket and port for it and use it */
11384 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11385 IPPROTO_TCP, &cfg->sock, 1);
11386 if (err) {
11387 kfree(cfg);
11388 return err;
11389 }
11390 if (inet_csk_get_port(cfg->sock->sk, port)) {
11391 sock_release(cfg->sock);
11392 kfree(cfg);
11393 return -EADDRINUSE;
11394 }
11395 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11396#else
11397 if (!port) {
11398 kfree(cfg);
11399 return -EINVAL;
11400 }
11401 cfg->src_port = port;
11402#endif
11403
11404 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11405 cfg->payload_len = data_size;
11406 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11407 memcpy((void *)cfg->payload,
11408 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11409 data_size);
11410 if (seq)
11411 cfg->payload_seq = *seq;
11412 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11413 cfg->wake_len = wake_size;
11414 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11415 memcpy((void *)cfg->wake_data,
11416 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11417 wake_size);
11418 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11419 data_size + wake_size;
11420 memcpy((void *)cfg->wake_mask,
11421 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11422 wake_mask_size);
11423 if (tok) {
11424 cfg->tokens_size = tokens_size;
11425 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11426 }
11427
11428 trig->tcp = cfg;
11429
11430 return 0;
11431}
11432
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011433static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11434 const struct wiphy_wowlan_support *wowlan,
11435 struct nlattr *attr,
11436 struct cfg80211_wowlan *trig)
11437{
11438 struct nlattr **tb;
11439 int err;
11440
Kees Cook6396bb22018-06-12 14:03:40 -070011441 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011442 if (!tb)
11443 return -ENOMEM;
11444
11445 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11446 err = -EOPNOTSUPP;
11447 goto out;
11448 }
11449
Johannes Berg8cb08172019-04-26 14:07:28 +020011450 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11451 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011452 if (err)
11453 goto out;
11454
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011455 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11456 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011457 err = PTR_ERR_OR_ZERO(trig->nd_config);
11458 if (err)
11459 trig->nd_config = NULL;
11460
11461out:
11462 kfree(tb);
11463 return err;
11464}
11465
Johannes Bergff1b6e62011-05-04 15:37:28 +020011466static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11467{
11468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11469 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011470 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011471 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011472 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011473 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011474 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011475 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011476
Johannes Berg964dc9e2013-06-03 17:25:34 +020011477 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011478 return -EOPNOTSUPP;
11479
Johannes Bergae33bd82012-07-12 16:25:02 +020011480 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11481 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011482 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011483 goto set_wakeup;
11484 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011485
Johannes Berg8cb08172019-04-26 14:07:28 +020011486 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11487 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11488 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011489 if (err)
11490 return err;
11491
11492 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11493 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11494 return -EINVAL;
11495 new_triggers.any = true;
11496 }
11497
11498 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11499 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11500 return -EINVAL;
11501 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011502 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011503 }
11504
11505 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11506 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11507 return -EINVAL;
11508 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011509 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011510 }
11511
Johannes Berg77dbbb12011-07-13 10:48:55 +020011512 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11513 return -EINVAL;
11514
11515 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11516 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11517 return -EINVAL;
11518 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011519 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011520 }
11521
11522 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11523 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11524 return -EINVAL;
11525 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011526 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011527 }
11528
11529 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11530 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11531 return -EINVAL;
11532 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011533 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011534 }
11535
11536 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11537 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11538 return -EINVAL;
11539 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011540 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011541 }
11542
Johannes Bergff1b6e62011-05-04 15:37:28 +020011543 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11544 struct nlattr *pat;
11545 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011546 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011547 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011548
Johannes Berg98fc4382015-03-01 09:10:13 +020011549 regular = true;
11550
Johannes Bergff1b6e62011-05-04 15:37:28 +020011551 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11552 rem)
11553 n_patterns++;
11554 if (n_patterns > wowlan->n_patterns)
11555 return -EINVAL;
11556
11557 new_triggers.patterns = kcalloc(n_patterns,
11558 sizeof(new_triggers.patterns[0]),
11559 GFP_KERNEL);
11560 if (!new_triggers.patterns)
11561 return -ENOMEM;
11562
11563 new_triggers.n_patterns = n_patterns;
11564 i = 0;
11565
11566 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11567 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011568 u8 *mask_pat;
11569
Johannes Berg8cb08172019-04-26 14:07:28 +020011570 err = nla_parse_nested_deprecated(pat_tb,
11571 MAX_NL80211_PKTPAT,
11572 pat,
11573 nl80211_packet_pattern_policy,
11574 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020011575 if (err)
11576 goto error;
11577
Johannes Bergff1b6e62011-05-04 15:37:28 +020011578 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011579 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11580 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011581 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011582 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011583 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011584 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011585 goto error;
11586 if (pat_len > wowlan->pattern_max_len ||
11587 pat_len < wowlan->pattern_min_len)
11588 goto error;
11589
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011590 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011591 pkt_offset = 0;
11592 else
11593 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011594 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011595 if (pkt_offset > wowlan->max_pkt_offset)
11596 goto error;
11597 new_triggers.patterns[i].pkt_offset = pkt_offset;
11598
Johannes Berg922bd802014-05-19 17:59:50 +020011599 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11600 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011601 err = -ENOMEM;
11602 goto error;
11603 }
Johannes Berg922bd802014-05-19 17:59:50 +020011604 new_triggers.patterns[i].mask = mask_pat;
11605 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011606 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011607 mask_pat += mask_len;
11608 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011609 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011610 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011611 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011612 pat_len);
11613 i++;
11614 }
11615 }
11616
Johannes Berg2a0e0472013-01-23 22:57:40 +010011617 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011618 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011619 err = nl80211_parse_wowlan_tcp(
11620 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11621 &new_triggers);
11622 if (err)
11623 goto error;
11624 }
11625
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011626 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011627 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011628 err = nl80211_parse_wowlan_nd(
11629 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11630 &new_triggers);
11631 if (err)
11632 goto error;
11633 }
11634
Johannes Berg98fc4382015-03-01 09:10:13 +020011635 /* The 'any' trigger means the device continues operating more or less
11636 * as in its normal operation mode and wakes up the host on most of the
11637 * normal interrupts (like packet RX, ...)
11638 * It therefore makes little sense to combine with the more constrained
11639 * wakeup trigger modes.
11640 */
11641 if (new_triggers.any && regular) {
11642 err = -EINVAL;
11643 goto error;
11644 }
11645
Johannes Bergae33bd82012-07-12 16:25:02 +020011646 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11647 if (!ntrig) {
11648 err = -ENOMEM;
11649 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011650 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011651 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011652 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011653
Johannes Bergae33bd82012-07-12 16:25:02 +020011654 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011655 if (rdev->ops->set_wakeup &&
11656 prev_enabled != !!rdev->wiphy.wowlan_config)
11657 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011658
Johannes Bergff1b6e62011-05-04 15:37:28 +020011659 return 0;
11660 error:
11661 for (i = 0; i < new_triggers.n_patterns; i++)
11662 kfree(new_triggers.patterns[i].mask);
11663 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011664 if (new_triggers.tcp && new_triggers.tcp->sock)
11665 sock_release(new_triggers.tcp->sock);
11666 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011667 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011668 return err;
11669}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011670#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011671
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011672static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11673 struct cfg80211_registered_device *rdev)
11674{
11675 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11676 int i, j, pat_len;
11677 struct cfg80211_coalesce_rules *rule;
11678
11679 if (!rdev->coalesce->n_rules)
11680 return 0;
11681
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011682 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011683 if (!nl_rules)
11684 return -ENOBUFS;
11685
11686 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011687 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011688 if (!nl_rule)
11689 return -ENOBUFS;
11690
11691 rule = &rdev->coalesce->rules[i];
11692 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11693 rule->delay))
11694 return -ENOBUFS;
11695
11696 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11697 rule->condition))
11698 return -ENOBUFS;
11699
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011700 nl_pats = nla_nest_start_noflag(msg,
11701 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011702 if (!nl_pats)
11703 return -ENOBUFS;
11704
11705 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011706 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011707 if (!nl_pat)
11708 return -ENOBUFS;
11709 pat_len = rule->patterns[j].pattern_len;
11710 if (nla_put(msg, NL80211_PKTPAT_MASK,
11711 DIV_ROUND_UP(pat_len, 8),
11712 rule->patterns[j].mask) ||
11713 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11714 rule->patterns[j].pattern) ||
11715 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11716 rule->patterns[j].pkt_offset))
11717 return -ENOBUFS;
11718 nla_nest_end(msg, nl_pat);
11719 }
11720 nla_nest_end(msg, nl_pats);
11721 nla_nest_end(msg, nl_rule);
11722 }
11723 nla_nest_end(msg, nl_rules);
11724
11725 return 0;
11726}
11727
11728static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11729{
11730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11731 struct sk_buff *msg;
11732 void *hdr;
11733
11734 if (!rdev->wiphy.coalesce)
11735 return -EOPNOTSUPP;
11736
11737 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11738 if (!msg)
11739 return -ENOMEM;
11740
11741 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11742 NL80211_CMD_GET_COALESCE);
11743 if (!hdr)
11744 goto nla_put_failure;
11745
11746 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11747 goto nla_put_failure;
11748
11749 genlmsg_end(msg, hdr);
11750 return genlmsg_reply(msg, info);
11751
11752nla_put_failure:
11753 nlmsg_free(msg);
11754 return -ENOBUFS;
11755}
11756
11757void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11758{
11759 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11760 int i, j;
11761 struct cfg80211_coalesce_rules *rule;
11762
11763 if (!coalesce)
11764 return;
11765
11766 for (i = 0; i < coalesce->n_rules; i++) {
11767 rule = &coalesce->rules[i];
11768 for (j = 0; j < rule->n_patterns; j++)
11769 kfree(rule->patterns[j].mask);
11770 kfree(rule->patterns);
11771 }
11772 kfree(coalesce->rules);
11773 kfree(coalesce);
11774 rdev->coalesce = NULL;
11775}
11776
11777static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11778 struct nlattr *rule,
11779 struct cfg80211_coalesce_rules *new_rule)
11780{
11781 int err, i;
11782 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11783 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11784 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11785 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11786
Johannes Berg8cb08172019-04-26 14:07:28 +020011787 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11788 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011789 if (err)
11790 return err;
11791
11792 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11793 new_rule->delay =
11794 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11795 if (new_rule->delay > coalesce->max_delay)
11796 return -EINVAL;
11797
11798 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11799 new_rule->condition =
11800 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011801
11802 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11803 return -EINVAL;
11804
11805 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11806 rem)
11807 n_patterns++;
11808 if (n_patterns > coalesce->n_patterns)
11809 return -EINVAL;
11810
11811 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11812 GFP_KERNEL);
11813 if (!new_rule->patterns)
11814 return -ENOMEM;
11815
11816 new_rule->n_patterns = n_patterns;
11817 i = 0;
11818
11819 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11820 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011821 u8 *mask_pat;
11822
Johannes Berg8cb08172019-04-26 14:07:28 +020011823 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11824 pat,
11825 nl80211_packet_pattern_policy,
11826 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020011827 if (err)
11828 return err;
11829
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011830 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11831 !pat_tb[NL80211_PKTPAT_PATTERN])
11832 return -EINVAL;
11833 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11834 mask_len = DIV_ROUND_UP(pat_len, 8);
11835 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11836 return -EINVAL;
11837 if (pat_len > coalesce->pattern_max_len ||
11838 pat_len < coalesce->pattern_min_len)
11839 return -EINVAL;
11840
11841 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11842 pkt_offset = 0;
11843 else
11844 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11845 if (pkt_offset > coalesce->max_pkt_offset)
11846 return -EINVAL;
11847 new_rule->patterns[i].pkt_offset = pkt_offset;
11848
Johannes Berg922bd802014-05-19 17:59:50 +020011849 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11850 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011851 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011852
11853 new_rule->patterns[i].mask = mask_pat;
11854 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11855 mask_len);
11856
11857 mask_pat += mask_len;
11858 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011859 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011860 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11861 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011862 i++;
11863 }
11864
11865 return 0;
11866}
11867
11868static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11869{
11870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11871 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11872 struct cfg80211_coalesce new_coalesce = {};
11873 struct cfg80211_coalesce *n_coalesce;
11874 int err, rem_rule, n_rules = 0, i, j;
11875 struct nlattr *rule;
11876 struct cfg80211_coalesce_rules *tmp_rule;
11877
11878 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11879 return -EOPNOTSUPP;
11880
11881 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11882 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011883 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011884 return 0;
11885 }
11886
11887 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11888 rem_rule)
11889 n_rules++;
11890 if (n_rules > coalesce->n_rules)
11891 return -EINVAL;
11892
11893 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11894 GFP_KERNEL);
11895 if (!new_coalesce.rules)
11896 return -ENOMEM;
11897
11898 new_coalesce.n_rules = n_rules;
11899 i = 0;
11900
11901 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11902 rem_rule) {
11903 err = nl80211_parse_coalesce_rule(rdev, rule,
11904 &new_coalesce.rules[i]);
11905 if (err)
11906 goto error;
11907
11908 i++;
11909 }
11910
Ilan Peera1056b1b2015-10-22 22:27:46 +030011911 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011912 if (err)
11913 goto error;
11914
11915 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11916 if (!n_coalesce) {
11917 err = -ENOMEM;
11918 goto error;
11919 }
11920 cfg80211_rdev_free_coalesce(rdev);
11921 rdev->coalesce = n_coalesce;
11922
11923 return 0;
11924error:
11925 for (i = 0; i < new_coalesce.n_rules; i++) {
11926 tmp_rule = &new_coalesce.rules[i];
11927 for (j = 0; j < tmp_rule->n_patterns; j++)
11928 kfree(tmp_rule->patterns[j].mask);
11929 kfree(tmp_rule->patterns);
11930 }
11931 kfree(new_coalesce.rules);
11932
11933 return err;
11934}
11935
Johannes Berge5497d72011-07-05 16:35:40 +020011936static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11937{
11938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11939 struct net_device *dev = info->user_ptr[1];
11940 struct wireless_dev *wdev = dev->ieee80211_ptr;
11941 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11942 struct cfg80211_gtk_rekey_data rekey_data;
11943 int err;
11944
11945 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11946 return -EINVAL;
11947
Johannes Berg8cb08172019-04-26 14:07:28 +020011948 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
11949 info->attrs[NL80211_ATTR_REKEY_DATA],
11950 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011951 if (err)
11952 return err;
11953
Vladis Dronove785fa02017-09-13 00:21:21 +020011954 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11955 !tb[NL80211_REKEY_DATA_KCK])
11956 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011957 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11958 return -ERANGE;
11959 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11960 return -ERANGE;
11961 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11962 return -ERANGE;
11963
Johannes Berg78f686c2014-09-10 22:28:06 +030011964 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11965 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11966 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011967
11968 wdev_lock(wdev);
11969 if (!wdev->current_bss) {
11970 err = -ENOTCONN;
11971 goto out;
11972 }
11973
11974 if (!rdev->ops->set_rekey_data) {
11975 err = -EOPNOTSUPP;
11976 goto out;
11977 }
11978
Hila Gonene35e4d22012-06-27 17:19:42 +030011979 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011980 out:
11981 wdev_unlock(wdev);
11982 return err;
11983}
11984
Johannes Berg28946da2011-11-04 11:18:12 +010011985static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11986 struct genl_info *info)
11987{
11988 struct net_device *dev = info->user_ptr[1];
11989 struct wireless_dev *wdev = dev->ieee80211_ptr;
11990
11991 if (wdev->iftype != NL80211_IFTYPE_AP &&
11992 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11993 return -EINVAL;
11994
Eric W. Biederman15e47302012-09-07 20:12:54 +000011995 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011996 return -EBUSY;
11997
Eric W. Biederman15e47302012-09-07 20:12:54 +000011998 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011999 return 0;
12000}
12001
Johannes Berg7f6cf312011-11-04 11:18:15 +010012002static int nl80211_probe_client(struct sk_buff *skb,
12003 struct genl_info *info)
12004{
12005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12006 struct net_device *dev = info->user_ptr[1];
12007 struct wireless_dev *wdev = dev->ieee80211_ptr;
12008 struct sk_buff *msg;
12009 void *hdr;
12010 const u8 *addr;
12011 u64 cookie;
12012 int err;
12013
12014 if (wdev->iftype != NL80211_IFTYPE_AP &&
12015 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12016 return -EOPNOTSUPP;
12017
12018 if (!info->attrs[NL80211_ATTR_MAC])
12019 return -EINVAL;
12020
12021 if (!rdev->ops->probe_client)
12022 return -EOPNOTSUPP;
12023
12024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12025 if (!msg)
12026 return -ENOMEM;
12027
Eric W. Biederman15e47302012-09-07 20:12:54 +000012028 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010012029 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030012030 if (!hdr) {
12031 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012032 goto free_msg;
12033 }
12034
12035 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12036
Hila Gonene35e4d22012-06-27 17:19:42 +030012037 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012038 if (err)
12039 goto free_msg;
12040
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012041 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12042 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012043 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012044
12045 genlmsg_end(msg, hdr);
12046
12047 return genlmsg_reply(msg, info);
12048
12049 nla_put_failure:
12050 err = -ENOBUFS;
12051 free_msg:
12052 nlmsg_free(msg);
12053 return err;
12054}
12055
Johannes Berg5e760232011-11-04 11:18:17 +010012056static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12057{
12058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070012059 struct cfg80211_beacon_registration *reg, *nreg;
12060 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012061
12062 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12063 return -EOPNOTSUPP;
12064
Ben Greear37c73b52012-10-26 14:49:25 -070012065 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12066 if (!nreg)
12067 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010012068
Ben Greear37c73b52012-10-26 14:49:25 -070012069 /* First, check if already registered. */
12070 spin_lock_bh(&rdev->beacon_registrations_lock);
12071 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12072 if (reg->nlportid == info->snd_portid) {
12073 rv = -EALREADY;
12074 goto out_err;
12075 }
12076 }
12077 /* Add it to the list */
12078 nreg->nlportid = info->snd_portid;
12079 list_add(&nreg->list, &rdev->beacon_registrations);
12080
12081 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012082
12083 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070012084out_err:
12085 spin_unlock_bh(&rdev->beacon_registrations_lock);
12086 kfree(nreg);
12087 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012088}
12089
Johannes Berg98104fde2012-06-16 00:19:54 +020012090static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12091{
12092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12093 struct wireless_dev *wdev = info->user_ptr[1];
12094 int err;
12095
12096 if (!rdev->ops->start_p2p_device)
12097 return -EOPNOTSUPP;
12098
12099 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12100 return -EOPNOTSUPP;
12101
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012102 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020012103 return 0;
12104
Luciano Coelhob6a55012014-02-27 11:07:21 +020012105 if (rfkill_blocked(rdev->rfkill))
12106 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020012107
Johannes Bergeeb126e2012-10-23 15:16:50 +020012108 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012109 if (err)
12110 return err;
12111
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012112 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020012113 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020012114
12115 return 0;
12116}
12117
12118static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12119{
12120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12121 struct wireless_dev *wdev = info->user_ptr[1];
12122
12123 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12124 return -EOPNOTSUPP;
12125
12126 if (!rdev->ops->stop_p2p_device)
12127 return -EOPNOTSUPP;
12128
Johannes Bergf9f47522013-03-19 15:04:07 +010012129 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012130
12131 return 0;
12132}
12133
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012134static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12135{
12136 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12137 struct wireless_dev *wdev = info->user_ptr[1];
12138 struct cfg80211_nan_conf conf = {};
12139 int err;
12140
12141 if (wdev->iftype != NL80211_IFTYPE_NAN)
12142 return -EOPNOTSUPP;
12143
Johannes Bergeeb04a92016-11-21 13:55:48 +010012144 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012145 return -EEXIST;
12146
12147 if (rfkill_blocked(rdev->rfkill))
12148 return -ERFKILL;
12149
12150 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12151 return -EINVAL;
12152
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012153 conf.master_pref =
12154 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012155
Luca Coelho85859892017-02-08 15:00:34 +020012156 if (info->attrs[NL80211_ATTR_BANDS]) {
12157 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12158
12159 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12160 return -EOPNOTSUPP;
12161
12162 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12163 return -EINVAL;
12164
12165 conf.bands = bands;
12166 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012167
12168 err = rdev_start_nan(rdev, wdev, &conf);
12169 if (err)
12170 return err;
12171
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012172 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012173 rdev->opencount++;
12174
12175 return 0;
12176}
12177
12178static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12179{
12180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12181 struct wireless_dev *wdev = info->user_ptr[1];
12182
12183 if (wdev->iftype != NL80211_IFTYPE_NAN)
12184 return -EOPNOTSUPP;
12185
12186 cfg80211_stop_nan(rdev, wdev);
12187
12188 return 0;
12189}
12190
Ayala Bekera442b762016-09-20 17:31:15 +030012191static int validate_nan_filter(struct nlattr *filter_attr)
12192{
12193 struct nlattr *attr;
12194 int len = 0, n_entries = 0, rem;
12195
12196 nla_for_each_nested(attr, filter_attr, rem) {
12197 len += nla_len(attr);
12198 n_entries++;
12199 }
12200
12201 if (len >= U8_MAX)
12202 return -EINVAL;
12203
12204 return n_entries;
12205}
12206
12207static int handle_nan_filter(struct nlattr *attr_filter,
12208 struct cfg80211_nan_func *func,
12209 bool tx)
12210{
12211 struct nlattr *attr;
12212 int n_entries, rem, i;
12213 struct cfg80211_nan_func_filter *filter;
12214
12215 n_entries = validate_nan_filter(attr_filter);
12216 if (n_entries < 0)
12217 return n_entries;
12218
12219 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12220
12221 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12222 if (!filter)
12223 return -ENOMEM;
12224
12225 i = 0;
12226 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012227 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012228 filter[i].len = nla_len(attr);
12229 i++;
12230 }
12231 if (tx) {
12232 func->num_tx_filters = n_entries;
12233 func->tx_filters = filter;
12234 } else {
12235 func->num_rx_filters = n_entries;
12236 func->rx_filters = filter;
12237 }
12238
12239 return 0;
12240}
12241
12242static int nl80211_nan_add_func(struct sk_buff *skb,
12243 struct genl_info *info)
12244{
12245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12246 struct wireless_dev *wdev = info->user_ptr[1];
12247 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12248 struct cfg80211_nan_func *func;
12249 struct sk_buff *msg = NULL;
12250 void *hdr = NULL;
12251 int err = 0;
12252
12253 if (wdev->iftype != NL80211_IFTYPE_NAN)
12254 return -EOPNOTSUPP;
12255
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012256 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012257 return -ENOTCONN;
12258
12259 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12260 return -EINVAL;
12261
Johannes Berg8cb08172019-04-26 14:07:28 +020012262 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12263 info->attrs[NL80211_ATTR_NAN_FUNC],
12264 nl80211_nan_func_policy,
12265 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012266 if (err)
12267 return err;
12268
12269 func = kzalloc(sizeof(*func), GFP_KERNEL);
12270 if (!func)
12271 return -ENOMEM;
12272
Johannes Bergb60ad342018-10-01 11:52:07 +020012273 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012274
12275 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12276 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12277 err = -EINVAL;
12278 goto out;
12279 }
12280
12281
12282 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12283
12284 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12285 err = -EINVAL;
12286 goto out;
12287 }
12288
12289 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12290 sizeof(func->service_id));
12291
12292 func->close_range =
12293 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12294
12295 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12296 func->serv_spec_info_len =
12297 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12298 func->serv_spec_info =
12299 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12300 func->serv_spec_info_len,
12301 GFP_KERNEL);
12302 if (!func->serv_spec_info) {
12303 err = -ENOMEM;
12304 goto out;
12305 }
12306 }
12307
12308 if (tb[NL80211_NAN_FUNC_TTL])
12309 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12310
12311 switch (func->type) {
12312 case NL80211_NAN_FUNC_PUBLISH:
12313 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12314 err = -EINVAL;
12315 goto out;
12316 }
12317
12318 func->publish_type =
12319 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12320 func->publish_bcast =
12321 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12322
12323 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12324 func->publish_bcast) {
12325 err = -EINVAL;
12326 goto out;
12327 }
12328 break;
12329 case NL80211_NAN_FUNC_SUBSCRIBE:
12330 func->subscribe_active =
12331 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12332 break;
12333 case NL80211_NAN_FUNC_FOLLOW_UP:
12334 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012335 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12336 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012337 err = -EINVAL;
12338 goto out;
12339 }
12340
12341 func->followup_id =
12342 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12343 func->followup_reqid =
12344 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12345 memcpy(func->followup_dest.addr,
12346 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12347 sizeof(func->followup_dest.addr));
12348 if (func->ttl) {
12349 err = -EINVAL;
12350 goto out;
12351 }
12352 break;
12353 default:
12354 err = -EINVAL;
12355 goto out;
12356 }
12357
12358 if (tb[NL80211_NAN_FUNC_SRF]) {
12359 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12360
Johannes Berg8cb08172019-04-26 14:07:28 +020012361 err = nla_parse_nested_deprecated(srf_tb,
12362 NL80211_NAN_SRF_ATTR_MAX,
12363 tb[NL80211_NAN_FUNC_SRF],
12364 nl80211_nan_srf_policy,
12365 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012366 if (err)
12367 goto out;
12368
12369 func->srf_include =
12370 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12371
12372 if (srf_tb[NL80211_NAN_SRF_BF]) {
12373 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12374 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12375 err = -EINVAL;
12376 goto out;
12377 }
12378
12379 func->srf_bf_len =
12380 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12381 func->srf_bf =
12382 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12383 func->srf_bf_len, GFP_KERNEL);
12384 if (!func->srf_bf) {
12385 err = -ENOMEM;
12386 goto out;
12387 }
12388
12389 func->srf_bf_idx =
12390 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12391 } else {
12392 struct nlattr *attr, *mac_attr =
12393 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12394 int n_entries, rem, i = 0;
12395
12396 if (!mac_attr) {
12397 err = -EINVAL;
12398 goto out;
12399 }
12400
12401 n_entries = validate_acl_mac_addrs(mac_attr);
12402 if (n_entries <= 0) {
12403 err = -EINVAL;
12404 goto out;
12405 }
12406
12407 func->srf_num_macs = n_entries;
12408 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012409 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012410 GFP_KERNEL);
12411 if (!func->srf_macs) {
12412 err = -ENOMEM;
12413 goto out;
12414 }
12415
12416 nla_for_each_nested(attr, mac_attr, rem)
12417 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12418 sizeof(*func->srf_macs));
12419 }
12420 }
12421
12422 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12423 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12424 func, true);
12425 if (err)
12426 goto out;
12427 }
12428
12429 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12430 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12431 func, false);
12432 if (err)
12433 goto out;
12434 }
12435
12436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12437 if (!msg) {
12438 err = -ENOMEM;
12439 goto out;
12440 }
12441
12442 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12443 NL80211_CMD_ADD_NAN_FUNCTION);
12444 /* This can't really happen - we just allocated 4KB */
12445 if (WARN_ON(!hdr)) {
12446 err = -ENOMEM;
12447 goto out;
12448 }
12449
12450 err = rdev_add_nan_func(rdev, wdev, func);
12451out:
12452 if (err < 0) {
12453 cfg80211_free_nan_func(func);
12454 nlmsg_free(msg);
12455 return err;
12456 }
12457
12458 /* propagate the instance id and cookie to userspace */
12459 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12460 NL80211_ATTR_PAD))
12461 goto nla_put_failure;
12462
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012463 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030012464 if (!func_attr)
12465 goto nla_put_failure;
12466
12467 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12468 func->instance_id))
12469 goto nla_put_failure;
12470
12471 nla_nest_end(msg, func_attr);
12472
12473 genlmsg_end(msg, hdr);
12474 return genlmsg_reply(msg, info);
12475
12476nla_put_failure:
12477 nlmsg_free(msg);
12478 return -ENOBUFS;
12479}
12480
12481static int nl80211_nan_del_func(struct sk_buff *skb,
12482 struct genl_info *info)
12483{
12484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12485 struct wireless_dev *wdev = info->user_ptr[1];
12486 u64 cookie;
12487
12488 if (wdev->iftype != NL80211_IFTYPE_NAN)
12489 return -EOPNOTSUPP;
12490
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012491 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012492 return -ENOTCONN;
12493
12494 if (!info->attrs[NL80211_ATTR_COOKIE])
12495 return -EINVAL;
12496
Ayala Bekera442b762016-09-20 17:31:15 +030012497 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12498
12499 rdev_del_nan_func(rdev, wdev, cookie);
12500
12501 return 0;
12502}
12503
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012504static int nl80211_nan_change_config(struct sk_buff *skb,
12505 struct genl_info *info)
12506{
12507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12508 struct wireless_dev *wdev = info->user_ptr[1];
12509 struct cfg80211_nan_conf conf = {};
12510 u32 changed = 0;
12511
12512 if (wdev->iftype != NL80211_IFTYPE_NAN)
12513 return -EOPNOTSUPP;
12514
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012515 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012516 return -ENOTCONN;
12517
12518 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12519 conf.master_pref =
12520 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12521 if (conf.master_pref <= 1 || conf.master_pref == 255)
12522 return -EINVAL;
12523
12524 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12525 }
12526
Luca Coelho85859892017-02-08 15:00:34 +020012527 if (info->attrs[NL80211_ATTR_BANDS]) {
12528 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12529
12530 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12531 return -EOPNOTSUPP;
12532
12533 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12534 return -EINVAL;
12535
12536 conf.bands = bands;
12537 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012538 }
12539
12540 if (!changed)
12541 return -EINVAL;
12542
12543 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12544}
12545
Ayala Beker50bcd312016-09-20 17:31:17 +030012546void cfg80211_nan_match(struct wireless_dev *wdev,
12547 struct cfg80211_nan_match_params *match, gfp_t gfp)
12548{
12549 struct wiphy *wiphy = wdev->wiphy;
12550 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12551 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12552 struct sk_buff *msg;
12553 void *hdr;
12554
12555 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12556 return;
12557
12558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12559 if (!msg)
12560 return;
12561
12562 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12563 if (!hdr) {
12564 nlmsg_free(msg);
12565 return;
12566 }
12567
12568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12569 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12570 wdev->netdev->ifindex)) ||
12571 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12572 NL80211_ATTR_PAD))
12573 goto nla_put_failure;
12574
12575 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12576 NL80211_ATTR_PAD) ||
12577 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12578 goto nla_put_failure;
12579
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012580 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030012581 if (!match_attr)
12582 goto nla_put_failure;
12583
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012584 local_func_attr = nla_nest_start_noflag(msg,
12585 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030012586 if (!local_func_attr)
12587 goto nla_put_failure;
12588
12589 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12590 goto nla_put_failure;
12591
12592 nla_nest_end(msg, local_func_attr);
12593
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012594 peer_func_attr = nla_nest_start_noflag(msg,
12595 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030012596 if (!peer_func_attr)
12597 goto nla_put_failure;
12598
12599 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12600 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12601 goto nla_put_failure;
12602
12603 if (match->info && match->info_len &&
12604 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12605 match->info))
12606 goto nla_put_failure;
12607
12608 nla_nest_end(msg, peer_func_attr);
12609 nla_nest_end(msg, match_attr);
12610 genlmsg_end(msg, hdr);
12611
12612 if (!wdev->owner_nlportid)
12613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12614 msg, 0, NL80211_MCGRP_NAN, gfp);
12615 else
12616 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12617 wdev->owner_nlportid);
12618
12619 return;
12620
12621nla_put_failure:
12622 nlmsg_free(msg);
12623}
12624EXPORT_SYMBOL(cfg80211_nan_match);
12625
Ayala Beker368e5a72016-09-20 17:31:18 +030012626void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12627 u8 inst_id,
12628 enum nl80211_nan_func_term_reason reason,
12629 u64 cookie, gfp_t gfp)
12630{
12631 struct wiphy *wiphy = wdev->wiphy;
12632 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12633 struct sk_buff *msg;
12634 struct nlattr *func_attr;
12635 void *hdr;
12636
12637 if (WARN_ON(!inst_id))
12638 return;
12639
12640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12641 if (!msg)
12642 return;
12643
12644 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12645 if (!hdr) {
12646 nlmsg_free(msg);
12647 return;
12648 }
12649
12650 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12651 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12652 wdev->netdev->ifindex)) ||
12653 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12654 NL80211_ATTR_PAD))
12655 goto nla_put_failure;
12656
12657 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12658 NL80211_ATTR_PAD))
12659 goto nla_put_failure;
12660
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012661 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030012662 if (!func_attr)
12663 goto nla_put_failure;
12664
12665 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12666 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12667 goto nla_put_failure;
12668
12669 nla_nest_end(msg, func_attr);
12670 genlmsg_end(msg, hdr);
12671
12672 if (!wdev->owner_nlportid)
12673 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12674 msg, 0, NL80211_MCGRP_NAN, gfp);
12675 else
12676 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12677 wdev->owner_nlportid);
12678
12679 return;
12680
12681nla_put_failure:
12682 nlmsg_free(msg);
12683}
12684EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12685
Johannes Berg3713b4e2013-02-14 16:19:38 +010012686static int nl80211_get_protocol_features(struct sk_buff *skb,
12687 struct genl_info *info)
12688{
12689 void *hdr;
12690 struct sk_buff *msg;
12691
12692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12693 if (!msg)
12694 return -ENOMEM;
12695
12696 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12697 NL80211_CMD_GET_PROTOCOL_FEATURES);
12698 if (!hdr)
12699 goto nla_put_failure;
12700
12701 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12702 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12703 goto nla_put_failure;
12704
12705 genlmsg_end(msg, hdr);
12706 return genlmsg_reply(msg, info);
12707
12708 nla_put_failure:
12709 kfree_skb(msg);
12710 return -ENOBUFS;
12711}
12712
Jouni Malinen355199e2013-02-27 17:14:27 +020012713static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12714{
12715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12716 struct cfg80211_update_ft_ies_params ft_params;
12717 struct net_device *dev = info->user_ptr[1];
12718
12719 if (!rdev->ops->update_ft_ies)
12720 return -EOPNOTSUPP;
12721
12722 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012723 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012724 return -EINVAL;
12725
12726 memset(&ft_params, 0, sizeof(ft_params));
12727 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12728 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12729 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12730
12731 return rdev_update_ft_ies(rdev, dev, &ft_params);
12732}
12733
Arend van Spriel5de17982013-04-18 15:49:00 +020012734static int nl80211_crit_protocol_start(struct sk_buff *skb,
12735 struct genl_info *info)
12736{
12737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12738 struct wireless_dev *wdev = info->user_ptr[1];
12739 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12740 u16 duration;
12741 int ret;
12742
12743 if (!rdev->ops->crit_proto_start)
12744 return -EOPNOTSUPP;
12745
12746 if (WARN_ON(!rdev->ops->crit_proto_stop))
12747 return -EINVAL;
12748
12749 if (rdev->crit_proto_nlportid)
12750 return -EBUSY;
12751
12752 /* determine protocol if provided */
12753 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12754 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12755
12756 if (proto >= NUM_NL80211_CRIT_PROTO)
12757 return -EINVAL;
12758
12759 /* timeout must be provided */
12760 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12761 return -EINVAL;
12762
12763 duration =
12764 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12765
12766 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12767 return -ERANGE;
12768
12769 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12770 if (!ret)
12771 rdev->crit_proto_nlportid = info->snd_portid;
12772
12773 return ret;
12774}
12775
12776static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12777 struct genl_info *info)
12778{
12779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12780 struct wireless_dev *wdev = info->user_ptr[1];
12781
12782 if (!rdev->ops->crit_proto_stop)
12783 return -EOPNOTSUPP;
12784
12785 if (rdev->crit_proto_nlportid) {
12786 rdev->crit_proto_nlportid = 0;
12787 rdev_crit_proto_stop(rdev, wdev);
12788 }
12789 return 0;
12790}
12791
Johannes Berg901bb982019-05-28 10:56:03 +020012792static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
12793 struct nlattr *attr,
12794 struct netlink_ext_ack *extack)
12795{
12796 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
12797 if (attr->nla_type & NLA_F_NESTED) {
12798 NL_SET_ERR_MSG_ATTR(extack, attr,
12799 "unexpected nested data");
12800 return -EINVAL;
12801 }
12802
12803 return 0;
12804 }
12805
12806 if (!(attr->nla_type & NLA_F_NESTED)) {
12807 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
12808 return -EINVAL;
12809 }
12810
12811 return nl80211_validate_nested(attr, vcmd->maxattr, vcmd->policy,
12812 extack);
12813}
12814
Johannes Bergad7e7182013-11-13 13:37:47 +010012815static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12816{
12817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12818 struct wireless_dev *wdev =
12819 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12820 int i, err;
12821 u32 vid, subcmd;
12822
12823 if (!rdev->wiphy.vendor_commands)
12824 return -EOPNOTSUPP;
12825
12826 if (IS_ERR(wdev)) {
12827 err = PTR_ERR(wdev);
12828 if (err != -EINVAL)
12829 return err;
12830 wdev = NULL;
12831 } else if (wdev->wiphy != &rdev->wiphy) {
12832 return -EINVAL;
12833 }
12834
12835 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12836 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12837 return -EINVAL;
12838
12839 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12840 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12841 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12842 const struct wiphy_vendor_command *vcmd;
12843 void *data = NULL;
12844 int len = 0;
12845
12846 vcmd = &rdev->wiphy.vendor_commands[i];
12847
12848 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12849 continue;
12850
12851 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12852 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12853 if (!wdev)
12854 return -EINVAL;
12855 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12856 !wdev->netdev)
12857 return -EINVAL;
12858
12859 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012860 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012861 return -ENETDOWN;
12862 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012863
12864 if (!vcmd->doit)
12865 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012866 } else {
12867 wdev = NULL;
12868 }
12869
12870 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12871 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12872 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020012873
12874 err = nl80211_vendor_check_policy(vcmd,
12875 info->attrs[NL80211_ATTR_VENDOR_DATA],
12876 info->extack);
12877 if (err)
12878 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010012879 }
12880
12881 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020012882 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010012883 rdev->cur_cmd_info = NULL;
12884 return err;
12885 }
12886
12887 return -EOPNOTSUPP;
12888}
12889
Johannes Berg7bdbe402015-08-15 22:39:49 +030012890static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12891 struct netlink_callback *cb,
12892 struct cfg80211_registered_device **rdev,
12893 struct wireless_dev **wdev)
12894{
Johannes Berg50508d92019-07-29 16:31:09 +020012895 struct nlattr **attrbuf;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012896 u32 vid, subcmd;
12897 unsigned int i;
12898 int vcmd_idx = -1;
12899 int err;
12900 void *data = NULL;
12901 unsigned int data_len = 0;
12902
Johannes Berg7bdbe402015-08-15 22:39:49 +030012903 if (cb->args[0]) {
12904 /* subtract the 1 again here */
12905 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12906 struct wireless_dev *tmp;
12907
Johannes Bergea90e0d2017-03-15 14:26:04 +010012908 if (!wiphy)
12909 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012910 *rdev = wiphy_to_rdev(wiphy);
12911 *wdev = NULL;
12912
12913 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012914 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012915 if (tmp->identifier == cb->args[1] - 1) {
12916 *wdev = tmp;
12917 break;
12918 }
12919 }
12920 }
12921
12922 /* keep rtnl locked in successful case */
12923 return 0;
12924 }
12925
Johannes Berg50508d92019-07-29 16:31:09 +020012926 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
12927 if (!attrbuf)
12928 return -ENOMEM;
12929
Johannes Berg8cb08172019-04-26 14:07:28 +020012930 err = nlmsg_parse_deprecated(cb->nlh,
12931 GENL_HDRLEN + nl80211_fam.hdrsize,
12932 attrbuf, nl80211_fam.maxattr,
12933 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012934 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020012935 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012936
Johannes Bergc90c39d2016-10-24 14:40:01 +020012937 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg50508d92019-07-29 16:31:09 +020012938 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
12939 err = -EINVAL;
12940 goto out;
12941 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012942
Johannes Bergc90c39d2016-10-24 14:40:01 +020012943 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012944 if (IS_ERR(*wdev))
12945 *wdev = NULL;
12946
Johannes Bergc90c39d2016-10-24 14:40:01 +020012947 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg50508d92019-07-29 16:31:09 +020012948 if (IS_ERR(*rdev)) {
12949 err = PTR_ERR(*rdev);
12950 goto out;
12951 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012952
Johannes Bergc90c39d2016-10-24 14:40:01 +020012953 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12954 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012955
12956 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12957 const struct wiphy_vendor_command *vcmd;
12958
12959 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12960
12961 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12962 continue;
12963
Johannes Berg50508d92019-07-29 16:31:09 +020012964 if (!vcmd->dumpit) {
12965 err = -EOPNOTSUPP;
12966 goto out;
12967 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012968
12969 vcmd_idx = i;
12970 break;
12971 }
12972
Johannes Berg50508d92019-07-29 16:31:09 +020012973 if (vcmd_idx < 0) {
12974 err = -EOPNOTSUPP;
12975 goto out;
12976 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012977
Johannes Bergc90c39d2016-10-24 14:40:01 +020012978 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12979 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12980 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020012981
12982 err = nl80211_vendor_check_policy(
12983 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
12984 attrbuf[NL80211_ATTR_VENDOR_DATA],
12985 cb->extack);
12986 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020012987 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012988 }
12989
12990 /* 0 is the first index - add 1 to parse only once */
12991 cb->args[0] = (*rdev)->wiphy_idx + 1;
12992 /* add 1 to know if it was NULL */
12993 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12994 cb->args[2] = vcmd_idx;
12995 cb->args[3] = (unsigned long)data;
12996 cb->args[4] = data_len;
12997
12998 /* keep rtnl locked in successful case */
Johannes Berg50508d92019-07-29 16:31:09 +020012999 err = 0;
13000out:
13001 kfree(attrbuf);
13002 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013003}
13004
13005static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13006 struct netlink_callback *cb)
13007{
13008 struct cfg80211_registered_device *rdev;
13009 struct wireless_dev *wdev;
13010 unsigned int vcmd_idx;
13011 const struct wiphy_vendor_command *vcmd;
13012 void *data;
13013 int data_len;
13014 int err;
13015 struct nlattr *vendor_data;
13016
Johannes Bergea90e0d2017-03-15 14:26:04 +010013017 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030013018 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13019 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010013020 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013021
13022 vcmd_idx = cb->args[2];
13023 data = (void *)cb->args[3];
13024 data_len = cb->args[4];
13025 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13026
13027 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13028 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013029 if (!wdev) {
13030 err = -EINVAL;
13031 goto out;
13032 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013033 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010013034 !wdev->netdev) {
13035 err = -EINVAL;
13036 goto out;
13037 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013038
13039 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013040 if (!wdev_running(wdev)) {
13041 err = -ENETDOWN;
13042 goto out;
13043 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013044 }
13045 }
13046
13047 while (1) {
13048 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13049 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13050 NL80211_CMD_VENDOR);
13051 if (!hdr)
13052 break;
13053
13054 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013055 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13056 wdev_id(wdev),
13057 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013058 genlmsg_cancel(skb, hdr);
13059 break;
13060 }
13061
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013062 vendor_data = nla_nest_start_noflag(skb,
13063 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013064 if (!vendor_data) {
13065 genlmsg_cancel(skb, hdr);
13066 break;
13067 }
13068
13069 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13070 (unsigned long *)&cb->args[5]);
13071 nla_nest_end(skb, vendor_data);
13072
13073 if (err == -ENOBUFS || err == -ENOENT) {
13074 genlmsg_cancel(skb, hdr);
13075 break;
13076 } else if (err) {
13077 genlmsg_cancel(skb, hdr);
13078 goto out;
13079 }
13080
13081 genlmsg_end(skb, hdr);
13082 }
13083
13084 err = skb->len;
13085 out:
13086 rtnl_unlock();
13087 return err;
13088}
13089
Johannes Bergad7e7182013-11-13 13:37:47 +010013090struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13091 enum nl80211_commands cmd,
13092 enum nl80211_attrs attr,
13093 int approxlen)
13094{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013095 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010013096
13097 if (WARN_ON(!rdev->cur_cmd_info))
13098 return NULL;
13099
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020013100 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010013101 rdev->cur_cmd_info->snd_portid,
13102 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010013103 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010013104}
13105EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13106
13107int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13108{
13109 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13110 void *hdr = ((void **)skb->cb)[1];
13111 struct nlattr *data = ((void **)skb->cb)[2];
13112
Johannes Bergbd8c78e2014-07-30 14:55:26 +020013113 /* clear CB data for netlink core to own from now on */
13114 memset(skb->cb, 0, sizeof(skb->cb));
13115
Johannes Bergad7e7182013-11-13 13:37:47 +010013116 if (WARN_ON(!rdev->cur_cmd_info)) {
13117 kfree_skb(skb);
13118 return -EINVAL;
13119 }
13120
13121 nla_nest_end(skb, data);
13122 genlmsg_end(skb, hdr);
13123 return genlmsg_reply(skb, rdev->cur_cmd_info);
13124}
13125EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13126
Johannes Berg55c1fdf2019-02-06 13:17:19 +020013127unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13128{
13129 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13130
13131 if (WARN_ON(!rdev->cur_cmd_info))
13132 return 0;
13133
13134 return rdev->cur_cmd_info->snd_portid;
13135}
13136EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13137
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013138static int nl80211_set_qos_map(struct sk_buff *skb,
13139 struct genl_info *info)
13140{
13141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13142 struct cfg80211_qos_map *qos_map = NULL;
13143 struct net_device *dev = info->user_ptr[1];
13144 u8 *pos, len, num_des, des_len, des;
13145 int ret;
13146
13147 if (!rdev->ops->set_qos_map)
13148 return -EOPNOTSUPP;
13149
13150 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13151 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13152 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13153
13154 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13155 len > IEEE80211_QOS_MAP_LEN_MAX)
13156 return -EINVAL;
13157
13158 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13159 if (!qos_map)
13160 return -ENOMEM;
13161
13162 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13163 if (num_des) {
13164 des_len = num_des *
13165 sizeof(struct cfg80211_dscp_exception);
13166 memcpy(qos_map->dscp_exception, pos, des_len);
13167 qos_map->num_des = num_des;
13168 for (des = 0; des < num_des; des++) {
13169 if (qos_map->dscp_exception[des].up > 7) {
13170 kfree(qos_map);
13171 return -EINVAL;
13172 }
13173 }
13174 pos += des_len;
13175 }
13176 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13177 }
13178
13179 wdev_lock(dev->ieee80211_ptr);
13180 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13181 if (!ret)
13182 ret = rdev_set_qos_map(rdev, dev, qos_map);
13183 wdev_unlock(dev->ieee80211_ptr);
13184
13185 kfree(qos_map);
13186 return ret;
13187}
13188
Johannes Berg960d01a2014-09-09 22:55:35 +030013189static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13190{
13191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13192 struct net_device *dev = info->user_ptr[1];
13193 struct wireless_dev *wdev = dev->ieee80211_ptr;
13194 const u8 *peer;
13195 u8 tsid, up;
13196 u16 admitted_time = 0;
13197 int err;
13198
Johannes Berg723e73a2014-10-22 09:25:06 +020013199 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013200 return -EOPNOTSUPP;
13201
13202 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13203 !info->attrs[NL80211_ATTR_USER_PRIO])
13204 return -EINVAL;
13205
13206 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013207 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013208
13209 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013210 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013211 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013212 * need more attributes for that (e.g. BA session requirement);
13213 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013214 */
13215 return -EINVAL;
13216 }
13217
13218 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13219
13220 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13221 admitted_time =
13222 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13223 if (!admitted_time)
13224 return -EINVAL;
13225 }
13226
13227 wdev_lock(wdev);
13228 switch (wdev->iftype) {
13229 case NL80211_IFTYPE_STATION:
13230 case NL80211_IFTYPE_P2P_CLIENT:
13231 if (wdev->current_bss)
13232 break;
13233 err = -ENOTCONN;
13234 goto out;
13235 default:
13236 err = -EOPNOTSUPP;
13237 goto out;
13238 }
13239
13240 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13241
13242 out:
13243 wdev_unlock(wdev);
13244 return err;
13245}
13246
13247static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13248{
13249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13250 struct net_device *dev = info->user_ptr[1];
13251 struct wireless_dev *wdev = dev->ieee80211_ptr;
13252 const u8 *peer;
13253 u8 tsid;
13254 int err;
13255
13256 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13257 return -EINVAL;
13258
13259 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13260 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13261
13262 wdev_lock(wdev);
13263 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13264 wdev_unlock(wdev);
13265
13266 return err;
13267}
13268
Arik Nemtsov1057d352014-11-19 12:54:26 +020013269static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13270 struct genl_info *info)
13271{
13272 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13273 struct net_device *dev = info->user_ptr[1];
13274 struct wireless_dev *wdev = dev->ieee80211_ptr;
13275 struct cfg80211_chan_def chandef = {};
13276 const u8 *addr;
13277 u8 oper_class;
13278 int err;
13279
13280 if (!rdev->ops->tdls_channel_switch ||
13281 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13282 return -EOPNOTSUPP;
13283
13284 switch (dev->ieee80211_ptr->iftype) {
13285 case NL80211_IFTYPE_STATION:
13286 case NL80211_IFTYPE_P2P_CLIENT:
13287 break;
13288 default:
13289 return -EOPNOTSUPP;
13290 }
13291
13292 if (!info->attrs[NL80211_ATTR_MAC] ||
13293 !info->attrs[NL80211_ATTR_OPER_CLASS])
13294 return -EINVAL;
13295
13296 err = nl80211_parse_chandef(rdev, info, &chandef);
13297 if (err)
13298 return err;
13299
13300 /*
13301 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13302 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13303 * specification is not defined for them.
13304 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013305 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013306 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13307 chandef.width != NL80211_CHAN_WIDTH_20)
13308 return -EINVAL;
13309
13310 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013311 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13312 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013313 return -EINVAL;
13314
13315 /* don't allow switching to DFS channels */
13316 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13317 return -EINVAL;
13318
13319 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13320 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13321
13322 wdev_lock(wdev);
13323 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13324 wdev_unlock(wdev);
13325
13326 return err;
13327}
13328
13329static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13330 struct genl_info *info)
13331{
13332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13333 struct net_device *dev = info->user_ptr[1];
13334 struct wireless_dev *wdev = dev->ieee80211_ptr;
13335 const u8 *addr;
13336
13337 if (!rdev->ops->tdls_channel_switch ||
13338 !rdev->ops->tdls_cancel_channel_switch ||
13339 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13340 return -EOPNOTSUPP;
13341
13342 switch (dev->ieee80211_ptr->iftype) {
13343 case NL80211_IFTYPE_STATION:
13344 case NL80211_IFTYPE_P2P_CLIENT:
13345 break;
13346 default:
13347 return -EOPNOTSUPP;
13348 }
13349
13350 if (!info->attrs[NL80211_ATTR_MAC])
13351 return -EINVAL;
13352
13353 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13354
13355 wdev_lock(wdev);
13356 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13357 wdev_unlock(wdev);
13358
13359 return 0;
13360}
13361
Michael Braunce0ce132016-10-10 19:12:22 +020013362static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13363 struct genl_info *info)
13364{
13365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13366 struct net_device *dev = info->user_ptr[1];
13367 struct wireless_dev *wdev = dev->ieee80211_ptr;
13368 const struct nlattr *nla;
13369 bool enabled;
13370
Michael Braunce0ce132016-10-10 19:12:22 +020013371 if (!rdev->ops->set_multicast_to_unicast)
13372 return -EOPNOTSUPP;
13373
13374 if (wdev->iftype != NL80211_IFTYPE_AP &&
13375 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13376 return -EOPNOTSUPP;
13377
13378 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13379 enabled = nla_get_flag(nla);
13380
13381 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13382}
13383
Avraham Stern3a00df52017-06-09 13:08:43 +010013384static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13385{
13386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13387 struct net_device *dev = info->user_ptr[1];
13388 struct wireless_dev *wdev = dev->ieee80211_ptr;
13389 struct cfg80211_pmk_conf pmk_conf = {};
13390 int ret;
13391
13392 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13393 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13394 return -EOPNOTSUPP;
13395
13396 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13397 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13398 return -EOPNOTSUPP;
13399
13400 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13401 return -EINVAL;
13402
13403 wdev_lock(wdev);
13404 if (!wdev->current_bss) {
13405 ret = -ENOTCONN;
13406 goto out;
13407 }
13408
13409 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13410 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13411 ret = -EINVAL;
13412 goto out;
13413 }
13414
13415 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13416 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13417 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13418 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13419 ret = -EINVAL;
13420 goto out;
13421 }
13422
13423 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13424 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13425
13426 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13427 ret = -EINVAL;
13428 goto out;
13429 }
13430
13431 pmk_conf.pmk_r0_name =
13432 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13433 }
13434
13435 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13436out:
13437 wdev_unlock(wdev);
13438 return ret;
13439}
13440
13441static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13442{
13443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13444 struct net_device *dev = info->user_ptr[1];
13445 struct wireless_dev *wdev = dev->ieee80211_ptr;
13446 const u8 *aa;
13447 int ret;
13448
13449 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13450 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13451 return -EOPNOTSUPP;
13452
13453 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13454 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13455 return -EOPNOTSUPP;
13456
13457 if (!info->attrs[NL80211_ATTR_MAC])
13458 return -EINVAL;
13459
13460 wdev_lock(wdev);
13461 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13462 ret = rdev_del_pmk(rdev, dev, aa);
13463 wdev_unlock(wdev);
13464
13465 return ret;
13466}
13467
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013468static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13469{
13470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13471 struct net_device *dev = info->user_ptr[1];
13472 struct cfg80211_external_auth_params params;
13473
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013474 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013475 return -EOPNOTSUPP;
13476
Srinivas Dasarife494372019-01-23 18:06:56 +053013477 if (!info->attrs[NL80211_ATTR_SSID] &&
13478 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13479 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013480 return -EINVAL;
13481
13482 if (!info->attrs[NL80211_ATTR_BSSID])
13483 return -EINVAL;
13484
13485 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13486 return -EINVAL;
13487
13488 memset(&params, 0, sizeof(params));
13489
Srinivas Dasarife494372019-01-23 18:06:56 +053013490 if (info->attrs[NL80211_ATTR_SSID]) {
13491 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13492 if (params.ssid.ssid_len == 0 ||
13493 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13494 return -EINVAL;
13495 memcpy(params.ssid.ssid,
13496 nla_data(info->attrs[NL80211_ATTR_SSID]),
13497 params.ssid.ssid_len);
13498 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013499
13500 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13501 ETH_ALEN);
13502
13503 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13504
Srinivas Dasarife494372019-01-23 18:06:56 +053013505 if (info->attrs[NL80211_ATTR_PMKID])
13506 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13507
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013508 return rdev_external_auth(rdev, dev, &params);
13509}
13510
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013511static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13512{
13513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13514 struct net_device *dev = info->user_ptr[1];
13515 struct wireless_dev *wdev = dev->ieee80211_ptr;
13516 const u8 *buf;
13517 size_t len;
13518 u8 *dest;
13519 u16 proto;
13520 bool noencrypt;
13521 int err;
13522
13523 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13524 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13525 return -EOPNOTSUPP;
13526
13527 if (!rdev->ops->tx_control_port)
13528 return -EOPNOTSUPP;
13529
13530 if (!info->attrs[NL80211_ATTR_FRAME] ||
13531 !info->attrs[NL80211_ATTR_MAC] ||
13532 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13533 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13534 return -EINVAL;
13535 }
13536
13537 wdev_lock(wdev);
13538
13539 switch (wdev->iftype) {
13540 case NL80211_IFTYPE_AP:
13541 case NL80211_IFTYPE_P2P_GO:
13542 case NL80211_IFTYPE_MESH_POINT:
13543 break;
13544 case NL80211_IFTYPE_ADHOC:
13545 case NL80211_IFTYPE_STATION:
13546 case NL80211_IFTYPE_P2P_CLIENT:
13547 if (wdev->current_bss)
13548 break;
13549 err = -ENOTCONN;
13550 goto out;
13551 default:
13552 err = -EOPNOTSUPP;
13553 goto out;
13554 }
13555
13556 wdev_unlock(wdev);
13557
13558 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13559 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13560 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13561 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13562 noencrypt =
13563 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13564
13565 return rdev_tx_control_port(rdev, dev, buf, len,
13566 dest, cpu_to_be16(proto), noencrypt);
13567
13568 out:
13569 wdev_unlock(wdev);
13570 return err;
13571}
13572
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013573static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13574 struct genl_info *info)
13575{
13576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13577 struct net_device *dev = info->user_ptr[1];
13578 struct wireless_dev *wdev = dev->ieee80211_ptr;
13579 struct cfg80211_ftm_responder_stats ftm_stats = {};
13580 struct sk_buff *msg;
13581 void *hdr;
13582 struct nlattr *ftm_stats_attr;
13583 int err;
13584
13585 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13586 return -EOPNOTSUPP;
13587
13588 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13589 if (err)
13590 return err;
13591
13592 if (!ftm_stats.filled)
13593 return -ENODATA;
13594
13595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13596 if (!msg)
13597 return -ENOMEM;
13598
13599 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13600 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13601 if (!hdr)
13602 return -ENOBUFS;
13603
13604 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13605 goto nla_put_failure;
13606
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013607 ftm_stats_attr = nla_nest_start_noflag(msg,
13608 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013609 if (!ftm_stats_attr)
13610 goto nla_put_failure;
13611
13612#define SET_FTM(field, name, type) \
13613 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13614 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13615 ftm_stats.field)) \
13616 goto nla_put_failure; } while (0)
13617#define SET_FTM_U64(field, name) \
13618 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13619 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13620 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13621 goto nla_put_failure; } while (0)
13622
13623 SET_FTM(success_num, SUCCESS_NUM, u32);
13624 SET_FTM(partial_num, PARTIAL_NUM, u32);
13625 SET_FTM(failed_num, FAILED_NUM, u32);
13626 SET_FTM(asap_num, ASAP_NUM, u32);
13627 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13628 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13629 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13630 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13631 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13632#undef SET_FTM
13633
13634 nla_nest_end(msg, ftm_stats_attr);
13635
13636 genlmsg_end(msg, hdr);
13637 return genlmsg_reply(msg, info);
13638
13639nla_put_failure:
13640 nlmsg_free(msg);
13641 return -ENOBUFS;
13642}
13643
Sunil Duttcb74e972019-02-20 16:18:07 +053013644static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13645{
13646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13647 struct cfg80211_update_owe_info owe_info;
13648 struct net_device *dev = info->user_ptr[1];
13649
13650 if (!rdev->ops->update_owe_info)
13651 return -EOPNOTSUPP;
13652
13653 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13654 !info->attrs[NL80211_ATTR_MAC])
13655 return -EINVAL;
13656
13657 memset(&owe_info, 0, sizeof(owe_info));
13658 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13659 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13660
13661 if (info->attrs[NL80211_ATTR_IE]) {
13662 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13663 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13664 }
13665
13666 return rdev_update_owe_info(rdev, dev, &owe_info);
13667}
13668
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013669static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13670{
13671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13672 struct net_device *dev = info->user_ptr[1];
13673 struct wireless_dev *wdev = dev->ieee80211_ptr;
13674 struct station_info sinfo = {};
13675 const u8 *buf;
13676 size_t len;
13677 u8 *dest;
13678 int err;
13679
13680 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13681 return -EOPNOTSUPP;
13682
13683 if (!info->attrs[NL80211_ATTR_MAC] ||
13684 !info->attrs[NL80211_ATTR_FRAME]) {
13685 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13686 return -EINVAL;
13687 }
13688
13689 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13690 return -EOPNOTSUPP;
13691
13692 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13693 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13694 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13695
13696 if (len < sizeof(struct ethhdr))
13697 return -EINVAL;
13698
13699 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13700 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13701 return -EINVAL;
13702
13703 err = rdev_get_station(rdev, dev, dest, &sinfo);
13704 if (err)
13705 return err;
13706
13707 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13708}
13709
Johannes Berg4c476992010-10-04 21:36:35 +020013710#define NL80211_FLAG_NEED_WIPHY 0x01
13711#define NL80211_FLAG_NEED_NETDEV 0x02
13712#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013713#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13714#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13715 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013716#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013717/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013718#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13719 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013720#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013721
Johannes Bergf84f7712013-11-14 17:14:45 +010013722static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013723 struct genl_info *info)
13724{
13725 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013726 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013727 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013728 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13729
13730 if (rtnl)
13731 rtnl_lock();
13732
13733 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013734 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013735 if (IS_ERR(rdev)) {
13736 if (rtnl)
13737 rtnl_unlock();
13738 return PTR_ERR(rdev);
13739 }
13740 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013741 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13742 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013743 ASSERT_RTNL();
13744
Johannes Berg89a54e42012-06-15 14:33:17 +020013745 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13746 info->attrs);
13747 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013748 if (rtnl)
13749 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013750 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013751 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013752
Johannes Berg89a54e42012-06-15 14:33:17 +020013753 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013754 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013755
Johannes Berg1bf614e2012-06-15 15:23:36 +020013756 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13757 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013758 if (rtnl)
13759 rtnl_unlock();
13760 return -EINVAL;
13761 }
13762
13763 info->user_ptr[1] = dev;
13764 } else {
13765 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013766 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013767
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013768 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13769 !wdev_running(wdev)) {
13770 if (rtnl)
13771 rtnl_unlock();
13772 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013773 }
13774
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013775 if (dev)
13776 dev_hold(dev);
13777
Johannes Berg4c476992010-10-04 21:36:35 +020013778 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013779 }
13780
13781 return 0;
13782}
13783
Johannes Bergf84f7712013-11-14 17:14:45 +010013784static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013785 struct genl_info *info)
13786{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013787 if (info->user_ptr[1]) {
13788 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13789 struct wireless_dev *wdev = info->user_ptr[1];
13790
13791 if (wdev->netdev)
13792 dev_put(wdev->netdev);
13793 } else {
13794 dev_put(info->user_ptr[1]);
13795 }
13796 }
Johannes Berg5393b912014-09-10 15:00:16 +030013797
Johannes Berg4c476992010-10-04 21:36:35 +020013798 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13799 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013800
13801 /* If needed, clear the netlink message payload from the SKB
13802 * as it might contain key data that shouldn't stick around on
13803 * the heap after the SKB is freed. The netlink message header
13804 * is still needed for further processing, so leave it intact.
13805 */
13806 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13807 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13808
13809 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13810 }
Johannes Berg4c476992010-10-04 21:36:35 +020013811}
13812
Johannes Berg4534de82013-11-14 17:14:46 +010013813static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013814 {
13815 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013816 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013817 .doit = nl80211_get_wiphy,
13818 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013819 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013820 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013821 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13822 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013823 },
13824 {
13825 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013826 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013827 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013828 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013829 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013830 },
13831 {
13832 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013833 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013834 .doit = nl80211_get_interface,
13835 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040013836 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013837 .internal_flags = NL80211_FLAG_NEED_WDEV |
13838 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013839 },
13840 {
13841 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013842 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013843 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013844 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013845 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13846 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013847 },
13848 {
13849 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013850 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013851 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013852 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013853 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13854 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013855 },
13856 {
13857 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013859 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013860 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013861 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013862 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013863 },
Johannes Berg41ade002007-12-19 02:03:29 +010013864 {
13865 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013867 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013868 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013870 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013871 },
13872 {
13873 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013874 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013875 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013876 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013877 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013878 NL80211_FLAG_NEED_RTNL |
13879 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013880 },
13881 {
13882 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013883 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013884 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013885 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013886 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013887 NL80211_FLAG_NEED_RTNL |
13888 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013889 },
13890 {
13891 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013892 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013893 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013894 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013895 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013896 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013897 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013898 {
13899 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020013900 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013901 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013902 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013903 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013904 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013905 },
13906 {
Johannes Berg88600202012-02-13 15:17:18 +010013907 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013908 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013909 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013910 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013912 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013913 },
13914 {
Johannes Berg88600202012-02-13 15:17:18 +010013915 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013916 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013917 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013918 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013919 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013920 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013921 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013922 {
13923 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013924 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013925 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013926 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020013927 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13928 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013929 },
13930 {
13931 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013932 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013933 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013934 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013936 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013937 },
13938 {
13939 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013940 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013941 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013942 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013943 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013944 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013945 },
13946 {
13947 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013948 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013949 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013950 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013952 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013953 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013954 {
13955 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013956 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013957 .doit = nl80211_get_mpath,
13958 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013959 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013961 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013962 },
13963 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013964 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013965 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020013966 .doit = nl80211_get_mpp,
13967 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020013968 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013969 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13970 NL80211_FLAG_NEED_RTNL,
13971 },
13972 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013973 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013974 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013975 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013976 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013977 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013978 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013979 },
13980 {
13981 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013982 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013983 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013984 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013985 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013986 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013987 },
13988 {
13989 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013991 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013992 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013994 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013995 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013996 {
13997 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013998 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013999 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014000 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014002 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014003 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014004 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014005 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014006 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014007 .doit = nl80211_get_reg_do,
14008 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014009 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014010 /* can be retrieved by unprivileged users */
14011 },
Johannes Bergb6863032015-10-15 09:25:18 +020014012#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014013 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014014 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014015 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014016 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014017 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014018 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014019 },
Johannes Bergb6863032015-10-15 09:25:18 +020014020#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014021 {
14022 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014023 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014024 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014025 .flags = GENL_ADMIN_PERM,
14026 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014027 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014028 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014029 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014030 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014031 .flags = GENL_ADMIN_PERM,
14032 },
14033 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014034 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014035 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014036 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014037 /* can be retrieved by unprivileged users */
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,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014040 },
14041 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014042 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014043 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014044 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020014045 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014046 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014047 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014048 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020014049 {
Johannes Berg2a519312009-02-10 21:25:55 +010014050 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014051 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014052 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014053 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020014054 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014055 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010014056 },
14057 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014058 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014059 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014060 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014061 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014062 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14063 NL80211_FLAG_NEED_RTNL,
14064 },
14065 {
Johannes Berg2a519312009-02-10 21:25:55 +010014066 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014067 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014068 .dumpit = nl80211_dump_scan,
14069 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020014070 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014071 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014072 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014073 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014074 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14076 NL80211_FLAG_NEED_RTNL,
14077 },
14078 {
14079 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014080 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014081 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014082 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14084 NL80211_FLAG_NEED_RTNL,
14085 },
14086 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020014087 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014088 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014089 .doit = nl80211_authenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014090 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014092 NL80211_FLAG_NEED_RTNL |
14093 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014094 },
14095 {
14096 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014097 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014098 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014099 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014101 NL80211_FLAG_NEED_RTNL |
14102 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014103 },
14104 {
14105 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014106 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014107 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014108 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014109 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014110 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014111 },
14112 {
14113 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014114 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014115 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014116 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014117 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014118 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014119 },
Johannes Berg04a773a2009-04-19 21:24:32 +020014120 {
14121 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014122 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014123 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014124 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014125 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014126 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014127 },
14128 {
14129 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014130 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014131 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014132 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014133 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014134 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014135 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014136#ifdef CONFIG_NL80211_TESTMODE
14137 {
14138 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014139 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014140 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014141 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014142 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014143 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14144 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014145 },
14146#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014147 {
14148 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014149 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014150 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014151 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014153 NL80211_FLAG_NEED_RTNL |
14154 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014155 },
14156 {
vamsi krishna088e8df2016-10-27 16:51:11 +030014157 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014158 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030014159 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030014160 .flags = GENL_ADMIN_PERM,
14161 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014162 NL80211_FLAG_NEED_RTNL |
14163 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030014164 },
14165 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020014166 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014168 .doit = nl80211_disconnect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014172 },
Johannes Berg463d0182009-07-14 00:33:35 +020014173 {
14174 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020014176 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020014177 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014178 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14179 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020014180 },
Holger Schurig61fa7132009-11-11 12:25:40 +010014181 {
14182 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014183 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010014184 .dumpit = nl80211_dump_survey,
14185 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014186 {
14187 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014188 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014189 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014190 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014192 NL80211_FLAG_NEED_RTNL |
14193 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014194 },
14195 {
14196 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014198 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014199 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014201 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014202 },
14203 {
14204 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014205 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014206 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014207 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014208 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014209 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014210 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014211 {
14212 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014213 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014214 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014215 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014216 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014217 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014218 },
14219 {
14220 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014221 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014222 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014223 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014224 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014225 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014226 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014227 {
14228 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014229 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014230 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020014231 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014232 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14233 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014234 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014235 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014236 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014237 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014238 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014239 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014240 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014241 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014242 },
14243 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014244 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014246 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014247 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014248 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014249 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014250 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014251 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014252 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014253 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014254 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014255 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014256 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014257 NL80211_FLAG_NEED_RTNL,
14258 },
14259 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014260 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014262 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014263 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014264 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14265 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014266 },
14267 {
14268 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014270 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014271 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020014272 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14273 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014274 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014275 {
14276 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020014277 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014278 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020014279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014280 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14281 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014282 },
Johannes Bergf444de02010-05-05 15:25:02 +020014283 {
14284 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014285 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020014286 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014288 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14289 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020014290 },
Bill Jordane8347eb2010-10-01 13:54:28 -040014291 {
14292 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014293 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040014294 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020014295 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020014296 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14297 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040014298 },
Johannes Berg29cbe682010-12-03 09:20:44 +010014299 {
14300 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014301 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014302 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014303 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14305 NL80211_FLAG_NEED_RTNL,
14306 },
14307 {
14308 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014309 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014310 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014311 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14313 NL80211_FLAG_NEED_RTNL,
14314 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014315 {
14316 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014317 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014318 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014319 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014320 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14321 NL80211_FLAG_NEED_RTNL,
14322 },
14323 {
14324 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014325 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014326 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014327 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14329 NL80211_FLAG_NEED_RTNL,
14330 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014331#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020014332 {
14333 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014334 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014335 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014336 /* can be retrieved by unprivileged users */
14337 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14338 NL80211_FLAG_NEED_RTNL,
14339 },
14340 {
14341 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014342 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014343 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014344 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014345 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14346 NL80211_FLAG_NEED_RTNL,
14347 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014348#endif
Johannes Berge5497d72011-07-05 16:35:40 +020014349 {
14350 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020014351 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020014352 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020014353 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020014354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014355 NL80211_FLAG_NEED_RTNL |
14356 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020014357 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030014358 {
14359 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014360 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014361 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014362 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14364 NL80211_FLAG_NEED_RTNL,
14365 },
14366 {
14367 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014368 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014369 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020014370 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14372 NL80211_FLAG_NEED_RTNL,
14373 },
Johannes Berg28946da2011-11-04 11:18:12 +010014374 {
14375 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014376 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010014377 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020014378 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010014379 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14380 NL80211_FLAG_NEED_RTNL,
14381 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010014382 {
14383 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014384 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010014385 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020014386 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010014388 NL80211_FLAG_NEED_RTNL,
14389 },
Johannes Berg5e760232011-11-04 11:18:17 +010014390 {
14391 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014392 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010014393 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020014394 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010014395 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14396 NL80211_FLAG_NEED_RTNL,
14397 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014398 {
14399 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014400 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014401 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014402 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014403 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14404 NL80211_FLAG_NEED_RTNL,
14405 },
Johannes Berg98104fde2012-06-16 00:19:54 +020014406 {
14407 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014408 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014409 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014410 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014411 .internal_flags = NL80211_FLAG_NEED_WDEV |
14412 NL80211_FLAG_NEED_RTNL,
14413 },
14414 {
14415 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014417 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014419 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14420 NL80211_FLAG_NEED_RTNL,
14421 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014422 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014423 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014425 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014426 .flags = GENL_ADMIN_PERM,
14427 .internal_flags = NL80211_FLAG_NEED_WDEV |
14428 NL80211_FLAG_NEED_RTNL,
14429 },
14430 {
14431 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014432 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014433 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014434 .flags = GENL_ADMIN_PERM,
14435 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14436 NL80211_FLAG_NEED_RTNL,
14437 },
14438 {
Ayala Bekera442b762016-09-20 17:31:15 +030014439 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014441 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014442 .flags = GENL_ADMIN_PERM,
14443 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14444 NL80211_FLAG_NEED_RTNL,
14445 },
14446 {
14447 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014448 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014449 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014450 .flags = GENL_ADMIN_PERM,
14451 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14452 NL80211_FLAG_NEED_RTNL,
14453 },
14454 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014455 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014456 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014457 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014458 .flags = GENL_ADMIN_PERM,
14459 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14460 NL80211_FLAG_NEED_RTNL,
14461 },
14462 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014463 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014464 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014465 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014466 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014467 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14468 NL80211_FLAG_NEED_RTNL,
14469 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014470 {
14471 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014472 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014473 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020014474 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014475 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14476 NL80211_FLAG_NEED_RTNL,
14477 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014478 {
14479 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014480 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014481 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020014482 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14484 NL80211_FLAG_NEED_RTNL,
14485 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014486 {
14487 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014488 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014489 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014490 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014491 {
14492 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014493 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020014494 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020014495 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14497 NL80211_FLAG_NEED_RTNL,
14498 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014499 {
14500 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014501 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014502 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020014503 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014504 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14505 NL80211_FLAG_NEED_RTNL,
14506 },
14507 {
14508 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014509 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014510 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020014511 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014512 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14513 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014514 },
14515 {
14516 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014517 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014518 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014519 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14520 NL80211_FLAG_NEED_RTNL,
14521 },
14522 {
14523 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014524 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014525 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020014526 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014527 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14528 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014529 },
14530 {
14531 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014532 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014533 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014534 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014535 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14536 NL80211_FLAG_NEED_RTNL,
14537 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014538 {
14539 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014540 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010014541 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014542 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014543 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014544 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014545 NL80211_FLAG_NEED_RTNL |
14546 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010014547 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014548 {
14549 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014550 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014551 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014552 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14554 NL80211_FLAG_NEED_RTNL,
14555 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014556 {
14557 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014558 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014559 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014560 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14562 NL80211_FLAG_NEED_RTNL,
14563 },
14564 {
14565 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014566 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014567 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014568 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14570 NL80211_FLAG_NEED_RTNL,
14571 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014572 {
14573 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014574 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014575 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014576 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14578 NL80211_FLAG_NEED_RTNL,
14579 },
14580 {
14581 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014582 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014583 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014584 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14586 NL80211_FLAG_NEED_RTNL,
14587 },
Michael Braunce0ce132016-10-10 19:12:22 +020014588 {
14589 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020014590 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020014591 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020014592 .flags = GENL_UNS_ADMIN_PERM,
14593 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14594 NL80211_FLAG_NEED_RTNL,
14595 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014596 {
14597 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014598 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014599 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014600 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014601 NL80211_FLAG_NEED_RTNL |
14602 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010014603 },
14604 {
14605 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014606 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014607 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14609 NL80211_FLAG_NEED_RTNL,
14610 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014611 {
14612 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014613 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014614 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014615 .flags = GENL_ADMIN_PERM,
14616 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14617 NL80211_FLAG_NEED_RTNL,
14618 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014619 {
14620 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014621 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014622 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014623 .flags = GENL_UNS_ADMIN_PERM,
14624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14625 NL80211_FLAG_NEED_RTNL,
14626 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014627 {
14628 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014629 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014630 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014631 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14632 NL80211_FLAG_NEED_RTNL,
14633 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014634 {
14635 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014636 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014637 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014638 .flags = GENL_UNS_ADMIN_PERM,
14639 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14640 NL80211_FLAG_NEED_RTNL,
14641 },
Sriram R30c63112018-12-04 17:46:52 +053014642 {
14643 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014644 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053014645 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053014646 .flags = GENL_UNS_ADMIN_PERM,
14647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14648 NL80211_FLAG_NEED_RTNL,
14649 },
Sunil Duttcb74e972019-02-20 16:18:07 +053014650 {
14651 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14652 .doit = nl80211_update_owe_info,
14653 .flags = GENL_ADMIN_PERM,
14654 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14655 NL80211_FLAG_NEED_RTNL,
14656 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014657 {
14658 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14659 .doit = nl80211_probe_mesh_link,
14660 .flags = GENL_UNS_ADMIN_PERM,
14661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14662 NL80211_FLAG_NEED_RTNL,
14663 },
Johannes Berg55682962007-09-20 13:09:35 -040014664};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014665
Johannes Berg56989f62016-10-24 14:40:05 +020014666static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014667 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14668 .hdrsize = 0, /* no private header */
14669 .version = 1, /* no particular meaning now */
14670 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010014671 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020014672 .netnsok = true,
14673 .pre_doit = nl80211_pre_doit,
14674 .post_doit = nl80211_post_doit,
14675 .module = THIS_MODULE,
14676 .ops = nl80211_ops,
14677 .n_ops = ARRAY_SIZE(nl80211_ops),
14678 .mcgrps = nl80211_mcgrps,
14679 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
Johannes Berg50508d92019-07-29 16:31:09 +020014680 .parallel_ops = true,
Johannes Berg489111e2016-10-24 14:40:03 +020014681};
14682
Johannes Berg55682962007-09-20 13:09:35 -040014683/* notification functions */
14684
Johannes Berg3bb20552014-05-26 13:52:25 +020014685void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14686 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014687{
14688 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014689 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014690
Johannes Berg3bb20552014-05-26 13:52:25 +020014691 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14692 cmd != NL80211_CMD_DEL_WIPHY);
14693
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014695 if (!msg)
14696 return;
14697
Johannes Berg3bb20552014-05-26 13:52:25 +020014698 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014699 nlmsg_free(msg);
14700 return;
14701 }
14702
Johannes Berg68eb5502013-11-19 15:19:38 +010014703 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014704 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014705}
14706
Denis Kenzior896ff062016-08-03 16:58:33 -050014707void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14708 struct wireless_dev *wdev,
14709 enum nl80211_commands cmd)
14710{
14711 struct sk_buff *msg;
14712
Denis Kenzior896ff062016-08-03 16:58:33 -050014713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14714 if (!msg)
14715 return;
14716
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014717 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014718 nlmsg_free(msg);
14719 return;
14720 }
14721
14722 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14723 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14724}
14725
Johannes Berg362a4152009-05-24 16:43:15 +020014726static int nl80211_add_scan_req(struct sk_buff *msg,
14727 struct cfg80211_registered_device *rdev)
14728{
14729 struct cfg80211_scan_request *req = rdev->scan_req;
14730 struct nlattr *nest;
14731 int i;
14732
14733 if (WARN_ON(!req))
14734 return 0;
14735
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014736 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020014737 if (!nest)
14738 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014739 for (i = 0; i < req->n_ssids; i++) {
14740 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14741 goto nla_put_failure;
14742 }
Johannes Berg362a4152009-05-24 16:43:15 +020014743 nla_nest_end(msg, nest);
14744
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014745 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Johannes Berg362a4152009-05-24 16:43:15 +020014746 if (!nest)
14747 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014748 for (i = 0; i < req->n_channels; i++) {
14749 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14750 goto nla_put_failure;
14751 }
Johannes Berg362a4152009-05-24 16:43:15 +020014752 nla_nest_end(msg, nest);
14753
David S. Miller9360ffd2012-03-29 04:41:26 -040014754 if (req->ie &&
14755 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14756 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014757
Johannes Bergae917c92013-10-25 11:05:22 +020014758 if (req->flags &&
14759 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14760 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014761
Avraham Stern1d762502016-07-05 17:10:13 +030014762 if (req->info.scan_start_tsf &&
14763 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14764 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14765 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14766 req->info.tsf_bssid)))
14767 goto nla_put_failure;
14768
Johannes Berg362a4152009-05-24 16:43:15 +020014769 return 0;
14770 nla_put_failure:
14771 return -ENOBUFS;
14772}
14773
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014774static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014775 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014776 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014777 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014778 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014779{
14780 void *hdr;
14781
Eric W. Biederman15e47302012-09-07 20:12:54 +000014782 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014783 if (!hdr)
14784 return -1;
14785
David S. Miller9360ffd2012-03-29 04:41:26 -040014786 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014787 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14788 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014789 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14790 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014791 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014792
Johannes Berg362a4152009-05-24 16:43:15 +020014793 /* ignore errors and send incomplete event anyway */
14794 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014795
Johannes Berg053c0952015-01-16 22:09:00 +010014796 genlmsg_end(msg, hdr);
14797 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014798
14799 nla_put_failure:
14800 genlmsg_cancel(msg, hdr);
14801 return -EMSGSIZE;
14802}
14803
Luciano Coelho807f8a82011-05-11 17:09:35 +030014804static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014805nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014806 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014807{
14808 void *hdr;
14809
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014810 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014811 if (!hdr)
14812 return -1;
14813
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014814 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14815 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14816 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14817 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14818 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014819 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014820
Johannes Berg053c0952015-01-16 22:09:00 +010014821 genlmsg_end(msg, hdr);
14822 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014823
14824 nla_put_failure:
14825 genlmsg_cancel(msg, hdr);
14826 return -EMSGSIZE;
14827}
14828
Johannes Berga538e2d2009-06-16 19:56:42 +020014829void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014830 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014831{
14832 struct sk_buff *msg;
14833
Thomas Graf58050fc2012-06-28 03:57:45 +000014834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014835 if (!msg)
14836 return;
14837
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014838 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014839 NL80211_CMD_TRIGGER_SCAN) < 0) {
14840 nlmsg_free(msg);
14841 return;
14842 }
14843
Johannes Berg68eb5502013-11-19 15:19:38 +010014844 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014845 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014846}
14847
Johannes Bergf9d15d12014-01-22 11:14:19 +020014848struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14849 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014850{
14851 struct sk_buff *msg;
14852
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014854 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014855 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014856
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014857 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014858 aborted ? NL80211_CMD_SCAN_ABORTED :
14859 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014860 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014861 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014862 }
14863
Johannes Bergf9d15d12014-01-22 11:14:19 +020014864 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014865}
14866
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014867/* send message created by nl80211_build_scan_msg() */
14868void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14869 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014870{
Johannes Berg2a519312009-02-10 21:25:55 +010014871 if (!msg)
14872 return;
14873
Johannes Berg68eb5502013-11-19 15:19:38 +010014874 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014875 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014876}
14877
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014878void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014879{
14880 struct sk_buff *msg;
14881
Thomas Graf58050fc2012-06-28 03:57:45 +000014882 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014883 if (!msg)
14884 return;
14885
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014886 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014887 nlmsg_free(msg);
14888 return;
14889 }
14890
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014891 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014892 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014893}
14894
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014895static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14896 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014897{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014898 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014899 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14900 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014901
David S. Miller9360ffd2012-03-29 04:41:26 -040014902 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14903 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14904 NL80211_REGDOM_TYPE_WORLD))
14905 goto nla_put_failure;
14906 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14907 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14908 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14909 goto nla_put_failure;
14910 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14911 request->intersect) {
14912 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14913 NL80211_REGDOM_TYPE_INTERSECTION))
14914 goto nla_put_failure;
14915 } else {
14916 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14917 NL80211_REGDOM_TYPE_COUNTRY) ||
14918 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14919 request->alpha2))
14920 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014921 }
14922
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014923 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14924 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14925
14926 if (wiphy &&
14927 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14928 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014929
14930 if (wiphy &&
14931 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14932 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14933 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014934 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014935
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014936 return true;
14937
14938nla_put_failure:
14939 return false;
14940}
14941
14942/*
14943 * This can happen on global regulatory changes or device specific settings
14944 * based on custom regulatory domains.
14945 */
14946void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14947 struct regulatory_request *request)
14948{
14949 struct sk_buff *msg;
14950 void *hdr;
14951
14952 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14953 if (!msg)
14954 return;
14955
14956 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14957 if (!hdr) {
14958 nlmsg_free(msg);
14959 return;
14960 }
14961
14962 if (nl80211_reg_change_event_fill(msg, request) == false)
14963 goto nla_put_failure;
14964
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014965 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014966
Johannes Bergbc43b282009-07-25 10:54:13 +020014967 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014968 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014969 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014970 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014971
14972 return;
14973
14974nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014975 nlmsg_free(msg);
14976}
14977
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014978static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14979 struct net_device *netdev,
14980 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014981 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014982 int uapsd_queues, const u8 *req_ies,
14983 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014984{
14985 struct sk_buff *msg;
14986 void *hdr;
14987
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014988 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014989 if (!msg)
14990 return;
14991
14992 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14993 if (!hdr) {
14994 nlmsg_free(msg);
14995 return;
14996 }
14997
David S. Miller9360ffd2012-03-29 04:41:26 -040014998 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14999 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015000 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15001 (req_ies &&
15002 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015003 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015004
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015005 if (uapsd_queues >= 0) {
15006 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015007 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015008 if (!nla_wmm)
15009 goto nla_put_failure;
15010
15011 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15012 uapsd_queues))
15013 goto nla_put_failure;
15014
15015 nla_nest_end(msg, nla_wmm);
15016 }
15017
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015018 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015019
Johannes Berg68eb5502013-11-19 15:19:38 +010015020 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015021 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015022 return;
15023
15024 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015025 nlmsg_free(msg);
15026}
15027
15028void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015029 struct net_device *netdev, const u8 *buf,
15030 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015031{
15032 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015033 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015034}
15035
15036void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15037 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015038 size_t len, gfp_t gfp, int uapsd_queues,
15039 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015040{
Johannes Berge6d6e342009-07-01 21:26:47 +020015041 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015042 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15043 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015044}
15045
Jouni Malinen53b46b82009-03-27 20:53:56 +020015046void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015047 struct net_device *netdev, const u8 *buf,
15048 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015049{
15050 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015051 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015052}
15053
Jouni Malinen53b46b82009-03-27 20:53:56 +020015054void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15055 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020015056 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015057{
15058 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015059 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015060}
15061
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015062void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15063 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020015064{
Johannes Berg947add32013-02-22 22:05:20 +010015065 struct wireless_dev *wdev = dev->ieee80211_ptr;
15066 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015067 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015068 const struct ieee80211_mgmt *mgmt = (void *)buf;
15069 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020015070
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015071 if (WARN_ON(len < 2))
15072 return;
15073
15074 if (ieee80211_is_deauth(mgmt->frame_control))
15075 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15076 else
15077 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15078
15079 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015080 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15081 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015082}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015083EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015084
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040015085static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15086 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020015087 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015088{
15089 struct sk_buff *msg;
15090 void *hdr;
15091
Johannes Berge6d6e342009-07-01 21:26:47 +020015092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015093 if (!msg)
15094 return;
15095
15096 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15097 if (!hdr) {
15098 nlmsg_free(msg);
15099 return;
15100 }
15101
David S. Miller9360ffd2012-03-29 04:41:26 -040015102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15104 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15105 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15106 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030015107
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015108 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030015109
Johannes Berg68eb5502013-11-19 15:19:38 +010015110 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015111 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015112 return;
15113
15114 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030015115 nlmsg_free(msg);
15116}
15117
15118void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015119 struct net_device *netdev, const u8 *addr,
15120 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015121{
15122 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020015123 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015124}
15125
15126void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015127 struct net_device *netdev, const u8 *addr,
15128 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015129{
Johannes Berge6d6e342009-07-01 21:26:47 +020015130 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15131 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015132}
15133
Samuel Ortizb23aa672009-07-01 21:26:54 +020015134void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015135 struct net_device *netdev,
15136 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015137 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015138{
15139 struct sk_buff *msg;
15140 void *hdr;
15141
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015142 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020015143 cr->fils.kek_len + cr->fils.pmk_len +
15144 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015145 if (!msg)
15146 return;
15147
15148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15149 if (!hdr) {
15150 nlmsg_free(msg);
15151 return;
15152 }
15153
David S. Miller9360ffd2012-03-29 04:41:26 -040015154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015156 (cr->bssid &&
15157 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030015158 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015159 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15160 cr->status) ||
15161 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015162 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015163 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15164 cr->timeout_reason))) ||
15165 (cr->req_ie &&
15166 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15167 (cr->resp_ie &&
15168 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015169 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020015170 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015171 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020015172 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015173 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020015174 ((cr->fils.kek &&
15175 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15176 cr->fils.kek)) ||
15177 (cr->fils.pmk &&
15178 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15179 (cr->fils.pmkid &&
15180 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040015181 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015182
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015183 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015184
Johannes Berg68eb5502013-11-19 15:19:38 +010015185 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015186 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015187 return;
15188
15189 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015190 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015191}
15192
15193void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015194 struct net_device *netdev,
15195 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015196{
15197 struct sk_buff *msg;
15198 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015199 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015200
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015201 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15202 info->fils.kek_len + info->fils.pmk_len +
15203 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015204 if (!msg)
15205 return;
15206
15207 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15208 if (!hdr) {
15209 nlmsg_free(msg);
15210 return;
15211 }
15212
David S. Miller9360ffd2012-03-29 04:41:26 -040015213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15214 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15215 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015216 (info->req_ie &&
15217 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15218 info->req_ie)) ||
15219 (info->resp_ie &&
15220 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015221 info->resp_ie)) ||
15222 (info->fils.update_erp_next_seq_num &&
15223 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15224 info->fils.erp_next_seq_num)) ||
15225 (info->fils.kek &&
15226 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15227 info->fils.kek)) ||
15228 (info->fils.pmk &&
15229 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15230 (info->fils.pmkid &&
15231 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015232 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015233
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015234 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015235
Johannes Berg68eb5502013-11-19 15:19:38 +010015236 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015237 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015238 return;
15239
15240 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015241 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015242}
15243
Avraham Stern503c1fb2017-09-29 14:21:49 +020015244void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15245 struct net_device *netdev, const u8 *bssid)
15246{
15247 struct sk_buff *msg;
15248 void *hdr;
15249
15250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15251 if (!msg)
15252 return;
15253
15254 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15255 if (!hdr) {
15256 nlmsg_free(msg);
15257 return;
15258 }
15259
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000015260 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15261 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15262 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020015263 goto nla_put_failure;
15264
15265 genlmsg_end(msg, hdr);
15266
15267 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15268 NL80211_MCGRP_MLME, GFP_KERNEL);
15269 return;
15270
15271 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020015272 nlmsg_free(msg);
15273}
15274
Samuel Ortizb23aa672009-07-01 21:26:54 +020015275void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15276 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020015277 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015278{
15279 struct sk_buff *msg;
15280 void *hdr;
15281
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015282 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015283 if (!msg)
15284 return;
15285
15286 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15287 if (!hdr) {
15288 nlmsg_free(msg);
15289 return;
15290 }
15291
David S. Miller9360ffd2012-03-29 04:41:26 -040015292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020015294 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040015295 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15296 (from_ap &&
15297 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15298 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15299 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015300
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015301 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015302
Johannes Berg68eb5502013-11-19 15:19:38 +010015303 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015304 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015305 return;
15306
15307 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015308 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015309}
15310
Johannes Berg04a773a2009-04-19 21:24:32 +020015311void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15312 struct net_device *netdev, const u8 *bssid,
15313 gfp_t gfp)
15314{
15315 struct sk_buff *msg;
15316 void *hdr;
15317
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015318 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015319 if (!msg)
15320 return;
15321
15322 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15323 if (!hdr) {
15324 nlmsg_free(msg);
15325 return;
15326 }
15327
David S. Miller9360ffd2012-03-29 04:41:26 -040015328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15330 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15331 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020015332
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015333 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020015334
Johannes Berg68eb5502013-11-19 15:19:38 +010015335 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015336 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015337 return;
15338
15339 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020015340 nlmsg_free(msg);
15341}
15342
Johannes Berg947add32013-02-22 22:05:20 +010015343void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040015344 const u8 *ie, u8 ie_len,
15345 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070015346{
Johannes Berg947add32013-02-22 22:05:20 +010015347 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015348 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015349 struct sk_buff *msg;
15350 void *hdr;
15351
Johannes Berg947add32013-02-22 22:05:20 +010015352 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15353 return;
15354
15355 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15356
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015357 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015358 if (!msg)
15359 return;
15360
15361 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15362 if (!hdr) {
15363 nlmsg_free(msg);
15364 return;
15365 }
15366
David S. Miller9360ffd2012-03-29 04:41:26 -040015367 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015368 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15369 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015370 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040015371 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15372 (sig_dbm &&
15373 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015374 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070015375
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015376 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015377
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);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015380 return;
15381
15382 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070015383 nlmsg_free(msg);
15384}
Johannes Berg947add32013-02-22 22:05:20 +010015385EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015386
Jouni Malinena3b8b052009-03-27 21:59:49 +020015387void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15388 struct net_device *netdev, const u8 *addr,
15389 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020015390 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020015391{
15392 struct sk_buff *msg;
15393 void *hdr;
15394
Johannes Berge6d6e342009-07-01 21:26:47 +020015395 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015396 if (!msg)
15397 return;
15398
15399 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15400 if (!hdr) {
15401 nlmsg_free(msg);
15402 return;
15403 }
15404
David S. Miller9360ffd2012-03-29 04:41:26 -040015405 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15406 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15407 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15408 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15409 (key_id != -1 &&
15410 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15411 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15412 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020015413
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015414 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015415
Johannes Berg68eb5502013-11-19 15:19:38 +010015416 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015417 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015418 return;
15419
15420 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020015421 nlmsg_free(msg);
15422}
15423
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015424void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15425 struct ieee80211_channel *channel_before,
15426 struct ieee80211_channel *channel_after)
15427{
15428 struct sk_buff *msg;
15429 void *hdr;
15430 struct nlattr *nl_freq;
15431
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015433 if (!msg)
15434 return;
15435
15436 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15437 if (!hdr) {
15438 nlmsg_free(msg);
15439 return;
15440 }
15441
15442 /*
15443 * Since we are applying the beacon hint to a wiphy we know its
15444 * wiphy_idx is valid
15445 */
David S. Miller9360ffd2012-03-29 04:41:26 -040015446 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15447 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015448
15449 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015450 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015451 if (!nl_freq)
15452 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015453
15454 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015455 goto nla_put_failure;
15456 nla_nest_end(msg, nl_freq);
15457
15458 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015459 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015460 if (!nl_freq)
15461 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015462
15463 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015464 goto nla_put_failure;
15465 nla_nest_end(msg, nl_freq);
15466
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015467 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015468
Johannes Berg463d0182009-07-14 00:33:35 +020015469 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015470 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015471 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020015472 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015473
15474 return;
15475
15476nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015477 nlmsg_free(msg);
15478}
15479
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015480static void nl80211_send_remain_on_chan_event(
15481 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015482 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015483 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015484 unsigned int duration, gfp_t gfp)
15485{
15486 struct sk_buff *msg;
15487 void *hdr;
15488
15489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15490 if (!msg)
15491 return;
15492
15493 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15494 if (!hdr) {
15495 nlmsg_free(msg);
15496 return;
15497 }
15498
David S. Miller9360ffd2012-03-29 04:41:26 -040015499 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015500 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15501 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015502 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15503 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015504 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015505 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15506 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015507 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15508 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015509 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015510
David S. Miller9360ffd2012-03-29 04:41:26 -040015511 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15512 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15513 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015514
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015515 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015516
Johannes Berg68eb5502013-11-19 15:19:38 +010015517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015518 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015519 return;
15520
15521 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015522 nlmsg_free(msg);
15523}
15524
Johannes Berg947add32013-02-22 22:05:20 +010015525void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15526 struct ieee80211_channel *chan,
15527 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015528{
Johannes Berg947add32013-02-22 22:05:20 +010015529 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015530 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015531
15532 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015533 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015534 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015535 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015536}
Johannes Berg947add32013-02-22 22:05:20 +010015537EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015538
Johannes Berg947add32013-02-22 22:05:20 +010015539void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15540 struct ieee80211_channel *chan,
15541 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015542{
Johannes Berg947add32013-02-22 22:05:20 +010015543 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015544 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015545
15546 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015547 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015548 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015549}
Johannes Berg947add32013-02-22 22:05:20 +010015550EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015551
James Prestwood1c38c7f2019-06-12 12:35:09 -070015552void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
15553 struct ieee80211_channel *chan,
15554 gfp_t gfp)
15555{
15556 struct wiphy *wiphy = wdev->wiphy;
15557 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15558
15559 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
15560 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
15561 rdev, wdev, cookie, chan, 0, gfp);
15562}
15563EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
15564
Johannes Berg947add32013-02-22 22:05:20 +010015565void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15566 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015567{
Johannes Berg947add32013-02-22 22:05:20 +010015568 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015569 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015570 struct sk_buff *msg;
15571
Johannes Berg947add32013-02-22 22:05:20 +010015572 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15573
Thomas Graf58050fc2012-06-28 03:57:45 +000015574 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015575 if (!msg)
15576 return;
15577
Johannes Bergcf5ead82014-11-14 17:14:00 +010015578 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015579 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015580 nlmsg_free(msg);
15581 return;
15582 }
15583
Johannes Berg68eb5502013-11-19 15:19:38 +010015584 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015585 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015586}
Johannes Berg947add32013-02-22 22:05:20 +010015587EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015588
Johannes Bergcf5ead82014-11-14 17:14:00 +010015589void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15590 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015591{
Johannes Berg947add32013-02-22 22:05:20 +010015592 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015593 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015594 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015595 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015596
Johannes Berg73887fd2018-05-18 09:57:55 +020015597 if (!sinfo)
15598 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015599
Johannes Berg947add32013-02-22 22:05:20 +010015600 trace_cfg80211_del_sta(dev, mac_addr);
15601
Thomas Graf58050fc2012-06-28 03:57:45 +000015602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015603 if (!msg) {
15604 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015605 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015606 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015607
Johannes Bergcf5ead82014-11-14 17:14:00 +010015608 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015609 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015610 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015611 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015612 }
15613
Johannes Berg68eb5502013-11-19 15:19:38 +010015614 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015615 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015616}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015617EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015618
Johannes Berg947add32013-02-22 22:05:20 +010015619void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15620 enum nl80211_connect_failed_reason reason,
15621 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015622{
Johannes Berg947add32013-02-22 22:05:20 +010015623 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015624 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015625 struct sk_buff *msg;
15626 void *hdr;
15627
15628 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15629 if (!msg)
15630 return;
15631
15632 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15633 if (!hdr) {
15634 nlmsg_free(msg);
15635 return;
15636 }
15637
15638 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15639 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15640 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15641 goto nla_put_failure;
15642
15643 genlmsg_end(msg, hdr);
15644
Johannes Berg68eb5502013-11-19 15:19:38 +010015645 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015646 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015647 return;
15648
15649 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015650 nlmsg_free(msg);
15651}
Johannes Berg947add32013-02-22 22:05:20 +010015652EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015653
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015654static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15655 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015656{
15657 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015658 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015659 struct sk_buff *msg;
15660 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015661 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015662
Eric W. Biederman15e47302012-09-07 20:12:54 +000015663 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015664 return false;
15665
15666 msg = nlmsg_new(100, gfp);
15667 if (!msg)
15668 return true;
15669
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015670 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015671 if (!hdr) {
15672 nlmsg_free(msg);
15673 return true;
15674 }
15675
David S. Miller9360ffd2012-03-29 04:41:26 -040015676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15678 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15679 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015680
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015681 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015682 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015683 return true;
15684
15685 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015686 nlmsg_free(msg);
15687 return true;
15688}
15689
Johannes Berg947add32013-02-22 22:05:20 +010015690bool cfg80211_rx_spurious_frame(struct net_device *dev,
15691 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015692{
Johannes Berg947add32013-02-22 22:05:20 +010015693 struct wireless_dev *wdev = dev->ieee80211_ptr;
15694 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015695
Johannes Berg947add32013-02-22 22:05:20 +010015696 trace_cfg80211_rx_spurious_frame(dev, addr);
15697
15698 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15699 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15700 trace_cfg80211_return_bool(false);
15701 return false;
15702 }
15703 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15704 addr, gfp);
15705 trace_cfg80211_return_bool(ret);
15706 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015707}
Johannes Berg947add32013-02-22 22:05:20 +010015708EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15709
15710bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15711 const u8 *addr, gfp_t gfp)
15712{
15713 struct wireless_dev *wdev = dev->ieee80211_ptr;
15714 bool ret;
15715
15716 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15717
15718 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15719 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15720 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15721 trace_cfg80211_return_bool(false);
15722 return false;
15723 }
15724 ret = __nl80211_unexpected_frame(dev,
15725 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15726 addr, gfp);
15727 trace_cfg80211_return_bool(ret);
15728 return ret;
15729}
15730EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015731
Johannes Berg2e161f782010-08-12 15:38:38 +020015732int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015733 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015734 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015735 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015736{
Johannes Berg71bbc992012-06-15 15:30:18 +020015737 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015738 struct sk_buff *msg;
15739 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015740
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015741 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015742 if (!msg)
15743 return -ENOMEM;
15744
Johannes Berg2e161f782010-08-12 15:38:38 +020015745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015746 if (!hdr) {
15747 nlmsg_free(msg);
15748 return -ENOMEM;
15749 }
15750
David S. Miller9360ffd2012-03-29 04:41:26 -040015751 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015752 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15753 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015754 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15755 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015756 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15757 (sig_dbm &&
15758 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015759 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15760 (flags &&
15761 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015762 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015763
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015764 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015765
Eric W. Biederman15e47302012-09-07 20:12:54 +000015766 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015767
15768 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015769 nlmsg_free(msg);
15770 return -ENOBUFS;
15771}
15772
Johannes Berg947add32013-02-22 22:05:20 +010015773void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15774 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015775{
Johannes Berg947add32013-02-22 22:05:20 +010015776 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015777 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015778 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015779 struct sk_buff *msg;
15780 void *hdr;
15781
Johannes Berg947add32013-02-22 22:05:20 +010015782 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15783
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;
15787
Johannes Berg2e161f782010-08-12 15:38:38 +020015788 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015789 if (!hdr) {
15790 nlmsg_free(msg);
15791 return;
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(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015800 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15801 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015802 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15803 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015804
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015805 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015806
Johannes Berg68eb5502013-11-19 15:19:38 +010015807 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015808 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015809 return;
15810
15811 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015812 nlmsg_free(msg);
15813}
Johannes Berg947add32013-02-22 22:05:20 +010015814EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015815
Denis Kenzior6a671a52018-03-26 12:52:41 -050015816static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015817 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015818 bool unencrypted, gfp_t gfp)
15819{
15820 struct wireless_dev *wdev = dev->ieee80211_ptr;
15821 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015822 struct ethhdr *ehdr = eth_hdr(skb);
15823 const u8 *addr = ehdr->h_source;
15824 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015825 struct sk_buff *msg;
15826 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015827 struct nlattr *frame;
15828
Denis Kenzior6a671a52018-03-26 12:52:41 -050015829 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15830
15831 if (!nlportid)
15832 return -ENOENT;
15833
Denis Kenziora948f712018-07-03 15:05:48 -050015834 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015835 if (!msg)
15836 return -ENOMEM;
15837
15838 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15839 if (!hdr) {
15840 nlmsg_free(msg);
15841 return -ENOBUFS;
15842 }
15843
15844 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15845 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15846 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15847 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015848 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15849 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15850 (unencrypted && nla_put_flag(msg,
15851 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15852 goto nla_put_failure;
15853
Denis Kenziora948f712018-07-03 15:05:48 -050015854 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15855 if (!frame)
15856 goto nla_put_failure;
15857
15858 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015859 genlmsg_end(msg, hdr);
15860
15861 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15862
15863 nla_put_failure:
15864 nlmsg_free(msg);
15865 return -ENOBUFS;
15866}
15867
15868bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015869 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015870{
15871 int ret;
15872
Denis Kenziora948f712018-07-03 15:05:48 -050015873 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15874 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015875 trace_cfg80211_return_bool(ret == 0);
15876 return ret == 0;
15877}
15878EXPORT_SYMBOL(cfg80211_rx_control_port);
15879
Johannes Berg5b97f492014-11-26 12:37:43 +010015880static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15881 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015882{
Johannes Berg947add32013-02-22 22:05:20 +010015883 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015884 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15885 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15886 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015887
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015888 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015889 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015890
Johannes Berg5b97f492014-11-26 12:37:43 +010015891 cb = (void **)msg->cb;
15892
15893 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15894 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015895 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015896 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015897 }
15898
David S. Miller9360ffd2012-03-29 04:41:26 -040015899 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015900 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015901 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015902
Johannes Berg5b97f492014-11-26 12:37:43 +010015903 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015904 goto nla_put_failure;
15905
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015906 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010015907 if (!cb[1])
15908 goto nla_put_failure;
15909
15910 cb[2] = rdev;
15911
15912 return msg;
15913 nla_put_failure:
15914 nlmsg_free(msg);
15915 return NULL;
15916}
15917
15918static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15919{
15920 void **cb = (void **)msg->cb;
15921 struct cfg80211_registered_device *rdev = cb[2];
15922
15923 nla_nest_end(msg, cb[1]);
15924 genlmsg_end(msg, cb[0]);
15925
15926 memset(msg->cb, 0, sizeof(msg->cb));
15927
15928 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15929 NL80211_MCGRP_MLME, gfp);
15930}
15931
15932void cfg80211_cqm_rssi_notify(struct net_device *dev,
15933 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015934 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015935{
15936 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015937 struct wireless_dev *wdev = dev->ieee80211_ptr;
15938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015939
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015940 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015941
Johannes Berg98f03342014-11-26 12:42:02 +010015942 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15943 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15944 return;
15945
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015946 if (wdev->cqm_config) {
15947 wdev->cqm_config->last_rssi_event_value = rssi_level;
15948
15949 cfg80211_cqm_rssi_update(rdev, dev);
15950
15951 if (rssi_level == 0)
15952 rssi_level = wdev->cqm_config->last_rssi_event_value;
15953 }
15954
Johannes Berg5b97f492014-11-26 12:37:43 +010015955 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15956 if (!msg)
15957 return;
15958
David S. Miller9360ffd2012-03-29 04:41:26 -040015959 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15960 rssi_event))
15961 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015962
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015963 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15964 rssi_level))
15965 goto nla_put_failure;
15966
Johannes Berg5b97f492014-11-26 12:37:43 +010015967 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015968
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015969 return;
15970
15971 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015972 nlmsg_free(msg);
15973}
Johannes Berg947add32013-02-22 22:05:20 +010015974EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015975
Johannes Berg5b97f492014-11-26 12:37:43 +010015976void cfg80211_cqm_txe_notify(struct net_device *dev,
15977 const u8 *peer, u32 num_packets,
15978 u32 rate, u32 intvl, gfp_t gfp)
15979{
15980 struct sk_buff *msg;
15981
15982 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15983 if (!msg)
15984 return;
15985
15986 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15987 goto nla_put_failure;
15988
15989 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15990 goto nla_put_failure;
15991
15992 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15993 goto nla_put_failure;
15994
15995 cfg80211_send_cqm(msg, gfp);
15996 return;
15997
15998 nla_put_failure:
15999 nlmsg_free(msg);
16000}
16001EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16002
16003void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16004 const u8 *peer, u32 num_packets, gfp_t gfp)
16005{
16006 struct sk_buff *msg;
16007
16008 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16009
16010 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16011 if (!msg)
16012 return;
16013
16014 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16015 goto nla_put_failure;
16016
16017 cfg80211_send_cqm(msg, gfp);
16018 return;
16019
16020 nla_put_failure:
16021 nlmsg_free(msg);
16022}
16023EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16024
Johannes Berg98f03342014-11-26 12:42:02 +010016025void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16026{
16027 struct sk_buff *msg;
16028
16029 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16030 if (!msg)
16031 return;
16032
16033 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16034 goto nla_put_failure;
16035
16036 cfg80211_send_cqm(msg, gfp);
16037 return;
16038
16039 nla_put_failure:
16040 nlmsg_free(msg);
16041}
16042EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16043
Johannes Berg947add32013-02-22 22:05:20 +010016044static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16045 struct net_device *netdev, const u8 *bssid,
16046 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020016047{
16048 struct sk_buff *msg;
16049 struct nlattr *rekey_attr;
16050 void *hdr;
16051
Thomas Graf58050fc2012-06-28 03:57:45 +000016052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016053 if (!msg)
16054 return;
16055
16056 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16057 if (!hdr) {
16058 nlmsg_free(msg);
16059 return;
16060 }
16061
David S. Miller9360ffd2012-03-29 04:41:26 -040016062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16063 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16064 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16065 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016066
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016067 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020016068 if (!rekey_attr)
16069 goto nla_put_failure;
16070
David S. Miller9360ffd2012-03-29 04:41:26 -040016071 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16072 NL80211_REPLAY_CTR_LEN, replay_ctr))
16073 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016074
16075 nla_nest_end(msg, rekey_attr);
16076
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016077 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020016078
Johannes Berg68eb5502013-11-19 15:19:38 +010016079 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016080 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016081 return;
16082
16083 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020016084 nlmsg_free(msg);
16085}
16086
Johannes Berg947add32013-02-22 22:05:20 +010016087void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16088 const u8 *replay_ctr, gfp_t gfp)
16089{
16090 struct wireless_dev *wdev = dev->ieee80211_ptr;
16091 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016092 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016093
16094 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16095 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16096}
16097EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16098
16099static void
16100nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16101 struct net_device *netdev, int index,
16102 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016103{
16104 struct sk_buff *msg;
16105 struct nlattr *attr;
16106 void *hdr;
16107
Thomas Graf58050fc2012-06-28 03:57:45 +000016108 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016109 if (!msg)
16110 return;
16111
16112 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16113 if (!hdr) {
16114 nlmsg_free(msg);
16115 return;
16116 }
16117
David S. Miller9360ffd2012-03-29 04:41:26 -040016118 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16119 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16120 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016121
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016122 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016123 if (!attr)
16124 goto nla_put_failure;
16125
David S. Miller9360ffd2012-03-29 04:41:26 -040016126 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16127 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16128 (preauth &&
16129 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16130 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016131
16132 nla_nest_end(msg, attr);
16133
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016134 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016135
Johannes Berg68eb5502013-11-19 15:19:38 +010016136 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016137 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016138 return;
16139
16140 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016141 nlmsg_free(msg);
16142}
16143
Johannes Berg947add32013-02-22 22:05:20 +010016144void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16145 const u8 *bssid, bool preauth, gfp_t gfp)
16146{
16147 struct wireless_dev *wdev = dev->ieee80211_ptr;
16148 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016149 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016150
16151 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16152 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16153}
16154EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16155
16156static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16157 struct net_device *netdev,
16158 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020016159 gfp_t gfp,
16160 enum nl80211_commands notif,
16161 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070016162{
16163 struct sk_buff *msg;
16164 void *hdr;
16165
Thomas Graf58050fc2012-06-28 03:57:45 +000016166 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016167 if (!msg)
16168 return;
16169
Luciano Coelhof8d75522014-11-07 14:31:35 +020016170 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070016171 if (!hdr) {
16172 nlmsg_free(msg);
16173 return;
16174 }
16175
Johannes Berg683b6d32012-11-08 21:25:48 +010016176 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16177 goto nla_put_failure;
16178
16179 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040016180 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070016181
Luciano Coelhof8d75522014-11-07 14:31:35 +020016182 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16183 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16184 goto nla_put_failure;
16185
Thomas Pedersen53145262012-04-06 13:35:47 -070016186 genlmsg_end(msg, hdr);
16187
Johannes Berg68eb5502013-11-19 15:19:38 +010016188 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016189 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016190 return;
16191
16192 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070016193 nlmsg_free(msg);
16194}
16195
Johannes Berg947add32013-02-22 22:05:20 +010016196void cfg80211_ch_switch_notify(struct net_device *dev,
16197 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070016198{
Johannes Berg947add32013-02-22 22:05:20 +010016199 struct wireless_dev *wdev = dev->ieee80211_ptr;
16200 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016201 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016202
Simon Wunderliche487eae2013-11-21 18:19:51 +010016203 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016204
Simon Wunderliche487eae2013-11-21 18:19:51 +010016205 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016206
Michal Kazior9e0e2962014-01-29 14:22:27 +010016207 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016208 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016209
16210 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16211 !WARN_ON(!wdev->current_bss))
Sergey Matyukevich0afd4252019-07-26 16:39:34 +000016212 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016213
Michael Vassernisd34990b2019-07-29 06:01:16 +000016214 cfg80211_sched_dfs_chan_update(rdev);
16215
Luciano Coelhof8d75522014-11-07 14:31:35 +020016216 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16217 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010016218}
16219EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16220
Luciano Coelhof8d75522014-11-07 14:31:35 +020016221void cfg80211_ch_switch_started_notify(struct net_device *dev,
16222 struct cfg80211_chan_def *chandef,
16223 u8 count)
16224{
16225 struct wireless_dev *wdev = dev->ieee80211_ptr;
16226 struct wiphy *wiphy = wdev->wiphy;
16227 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16228
16229 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16230
16231 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16232 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16233}
16234EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16235
Thomas Pedersen84f10702012-07-12 16:17:33 -070016236void
Simon Wunderlich04f39042013-02-08 18:16:19 +010016237nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010016238 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010016239 enum nl80211_radar_event event,
16240 struct net_device *netdev, gfp_t gfp)
16241{
16242 struct sk_buff *msg;
16243 void *hdr;
16244
16245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16246 if (!msg)
16247 return;
16248
16249 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16250 if (!hdr) {
16251 nlmsg_free(msg);
16252 return;
16253 }
16254
16255 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16256 goto nla_put_failure;
16257
16258 /* NOP and radar events don't need a netdev parameter */
16259 if (netdev) {
16260 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16261
16262 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016263 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16264 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010016265 goto nla_put_failure;
16266 }
16267
16268 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16269 goto nla_put_failure;
16270
16271 if (nl80211_send_chandef(msg, chandef))
16272 goto nla_put_failure;
16273
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016274 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016275
Johannes Berg68eb5502013-11-19 15:19:38 +010016276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016277 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016278 return;
16279
16280 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010016281 nlmsg_free(msg);
16282}
16283
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053016284void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16285 struct sta_opmode_info *sta_opmode,
16286 gfp_t gfp)
16287{
16288 struct sk_buff *msg;
16289 struct wireless_dev *wdev = dev->ieee80211_ptr;
16290 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16291 void *hdr;
16292
16293 if (WARN_ON(!mac))
16294 return;
16295
16296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16297 if (!msg)
16298 return;
16299
16300 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16301 if (!hdr) {
16302 nlmsg_free(msg);
16303 return;
16304 }
16305
16306 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16307 goto nla_put_failure;
16308
16309 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16310 goto nla_put_failure;
16311
16312 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16313 goto nla_put_failure;
16314
16315 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16316 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16317 goto nla_put_failure;
16318
16319 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16320 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16321 goto nla_put_failure;
16322
16323 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16324 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16325 goto nla_put_failure;
16326
16327 genlmsg_end(msg, hdr);
16328
16329 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16330 NL80211_MCGRP_MLME, gfp);
16331
16332 return;
16333
16334nla_put_failure:
16335 nlmsg_free(msg);
16336}
16337EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16338
Johannes Berg7f6cf312011-11-04 11:18:15 +010016339void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016340 u64 cookie, bool acked, s32 ack_signal,
16341 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010016342{
16343 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016344 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016345 struct sk_buff *msg;
16346 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016347
Beni Lev4ee3e062012-08-27 12:49:39 +030016348 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16349
Thomas Graf58050fc2012-06-28 03:57:45 +000016350 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030016351
Johannes Berg7f6cf312011-11-04 11:18:15 +010016352 if (!msg)
16353 return;
16354
16355 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16356 if (!hdr) {
16357 nlmsg_free(msg);
16358 return;
16359 }
16360
David S. Miller9360ffd2012-03-29 04:41:26 -040016361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16362 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16363 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016364 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16365 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016366 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16367 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16368 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016369 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016370
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016371 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016372
Johannes Berg68eb5502013-11-19 15:19:38 +010016373 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016374 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016375 return;
16376
16377 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010016378 nlmsg_free(msg);
16379}
16380EXPORT_SYMBOL(cfg80211_probe_status);
16381
Johannes Berg5e760232011-11-04 11:18:17 +010016382void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16383 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070016384 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010016385{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016386 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010016387 struct sk_buff *msg;
16388 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070016389 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010016390
Beni Lev4ee3e062012-08-27 12:49:39 +030016391 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16392
Ben Greear37c73b52012-10-26 14:49:25 -070016393 spin_lock_bh(&rdev->beacon_registrations_lock);
16394 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16395 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16396 if (!msg) {
16397 spin_unlock_bh(&rdev->beacon_registrations_lock);
16398 return;
16399 }
Johannes Berg5e760232011-11-04 11:18:17 +010016400
Ben Greear37c73b52012-10-26 14:49:25 -070016401 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16402 if (!hdr)
16403 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010016404
Ben Greear37c73b52012-10-26 14:49:25 -070016405 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16406 (freq &&
16407 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16408 (sig_dbm &&
16409 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16410 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16411 goto nla_put_failure;
16412
16413 genlmsg_end(msg, hdr);
16414
16415 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010016416 }
Ben Greear37c73b52012-10-26 14:49:25 -070016417 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016418 return;
16419
16420 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070016421 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016422 nlmsg_free(msg);
16423}
16424EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16425
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016426#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016427static int cfg80211_net_detect_results(struct sk_buff *msg,
16428 struct cfg80211_wowlan_wakeup *wakeup)
16429{
16430 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16431 struct nlattr *nl_results, *nl_match, *nl_freqs;
16432 int i, j;
16433
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016434 nl_results = nla_nest_start_noflag(msg,
16435 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016436 if (!nl_results)
16437 return -EMSGSIZE;
16438
16439 for (i = 0; i < nd->n_matches; i++) {
16440 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16441
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016442 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016443 if (!nl_match)
16444 break;
16445
16446 /* The SSID attribute is optional in nl80211, but for
16447 * simplicity reasons it's always present in the
16448 * cfg80211 structure. If a driver can't pass the
16449 * SSID, that needs to be changed. A zero length SSID
16450 * is still a valid SSID (wildcard), so it cannot be
16451 * used for this purpose.
16452 */
16453 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16454 match->ssid.ssid)) {
16455 nla_nest_cancel(msg, nl_match);
16456 goto out;
16457 }
16458
16459 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016460 nl_freqs = nla_nest_start_noflag(msg,
16461 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016462 if (!nl_freqs) {
16463 nla_nest_cancel(msg, nl_match);
16464 goto out;
16465 }
16466
16467 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020016468 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016469 nla_nest_cancel(msg, nl_freqs);
16470 nla_nest_cancel(msg, nl_match);
16471 goto out;
16472 }
16473 }
16474
16475 nla_nest_end(msg, nl_freqs);
16476 }
16477
16478 nla_nest_end(msg, nl_match);
16479 }
16480
16481out:
16482 nla_nest_end(msg, nl_results);
16483 return 0;
16484}
16485
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016486void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16487 struct cfg80211_wowlan_wakeup *wakeup,
16488 gfp_t gfp)
16489{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016490 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016491 struct sk_buff *msg;
16492 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016493 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016494
16495 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16496
16497 if (wakeup)
16498 size += wakeup->packet_present_len;
16499
16500 msg = nlmsg_new(size, gfp);
16501 if (!msg)
16502 return;
16503
16504 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16505 if (!hdr)
16506 goto free_msg;
16507
16508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016509 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16510 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016511 goto free_msg;
16512
16513 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16514 wdev->netdev->ifindex))
16515 goto free_msg;
16516
16517 if (wakeup) {
16518 struct nlattr *reasons;
16519
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016520 reasons = nla_nest_start_noflag(msg,
16521 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016522 if (!reasons)
16523 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016524
16525 if (wakeup->disconnect &&
16526 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16527 goto free_msg;
16528 if (wakeup->magic_pkt &&
16529 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16530 goto free_msg;
16531 if (wakeup->gtk_rekey_failure &&
16532 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16533 goto free_msg;
16534 if (wakeup->eap_identity_req &&
16535 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16536 goto free_msg;
16537 if (wakeup->four_way_handshake &&
16538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16539 goto free_msg;
16540 if (wakeup->rfkill_release &&
16541 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16542 goto free_msg;
16543
16544 if (wakeup->pattern_idx >= 0 &&
16545 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16546 wakeup->pattern_idx))
16547 goto free_msg;
16548
Johannes Bergae917c92013-10-25 11:05:22 +020016549 if (wakeup->tcp_match &&
16550 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16551 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016552
Johannes Bergae917c92013-10-25 11:05:22 +020016553 if (wakeup->tcp_connlost &&
16554 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16555 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016556
Johannes Bergae917c92013-10-25 11:05:22 +020016557 if (wakeup->tcp_nomoretokens &&
16558 nla_put_flag(msg,
16559 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16560 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016561
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016562 if (wakeup->packet) {
16563 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16564 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16565
16566 if (!wakeup->packet_80211) {
16567 pkt_attr =
16568 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16569 len_attr =
16570 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16571 }
16572
16573 if (wakeup->packet_len &&
16574 nla_put_u32(msg, len_attr, wakeup->packet_len))
16575 goto free_msg;
16576
16577 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16578 wakeup->packet))
16579 goto free_msg;
16580 }
16581
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016582 if (wakeup->net_detect &&
16583 cfg80211_net_detect_results(msg, wakeup))
16584 goto free_msg;
16585
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016586 nla_nest_end(msg, reasons);
16587 }
16588
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016589 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016590
Johannes Berg68eb5502013-11-19 15:19:38 +010016591 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016592 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016593 return;
16594
16595 free_msg:
16596 nlmsg_free(msg);
16597}
16598EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16599#endif
16600
Jouni Malinen3475b092012-11-16 22:49:57 +020016601void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16602 enum nl80211_tdls_operation oper,
16603 u16 reason_code, gfp_t gfp)
16604{
16605 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016606 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016607 struct sk_buff *msg;
16608 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016609
16610 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16611 reason_code);
16612
16613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16614 if (!msg)
16615 return;
16616
16617 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16618 if (!hdr) {
16619 nlmsg_free(msg);
16620 return;
16621 }
16622
16623 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16624 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16625 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16626 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16627 (reason_code > 0 &&
16628 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16629 goto nla_put_failure;
16630
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016631 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016632
Johannes Berg68eb5502013-11-19 15:19:38 +010016633 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016634 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016635 return;
16636
16637 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016638 nlmsg_free(msg);
16639}
16640EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16641
Jouni Malinen026331c2010-02-15 12:53:10 +020016642static int nl80211_netlink_notify(struct notifier_block * nb,
16643 unsigned long state,
16644 void *_notify)
16645{
16646 struct netlink_notify *notify = _notify;
16647 struct cfg80211_registered_device *rdev;
16648 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016649 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016650
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016651 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016652 return NOTIFY_DONE;
16653
16654 rcu_read_lock();
16655
Johannes Berg5e760232011-11-04 11:18:17 +010016656 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016657 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016658
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016659 list_for_each_entry_rcu(sched_scan_req,
16660 &rdev->sched_scan_req_list,
16661 list) {
16662 if (sched_scan_req->owner_nlportid == notify->portid) {
16663 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010016664 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016665 }
Johannes Berg753aacf2017-01-05 10:57:14 +010016666 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016667
Johannes Berg53873f12016-05-03 16:52:04 +030016668 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016669 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016670
Johannes Bergab810072017-04-26 07:43:41 +020016671 if (wdev->owner_nlportid == notify->portid) {
16672 wdev->nl_owner_dead = true;
16673 schedule_work(&rdev->destroy_work);
16674 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016675 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016676 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016677
16678 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016679 }
16680
Ben Greear37c73b52012-10-26 14:49:25 -070016681 spin_lock_bh(&rdev->beacon_registrations_lock);
16682 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16683 list) {
16684 if (reg->nlportid == notify->portid) {
16685 list_del(&reg->list);
16686 kfree(reg);
16687 break;
16688 }
16689 }
16690 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016691 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016692
16693 rcu_read_unlock();
16694
Ilan peer05050752015-03-04 00:32:06 -050016695 /*
16696 * It is possible that the user space process that is controlling the
16697 * indoor setting disappeared, so notify the regulatory core.
16698 */
16699 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016700 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016701}
16702
16703static struct notifier_block nl80211_netlink_notifier = {
16704 .notifier_call = nl80211_netlink_notify,
16705};
16706
Jouni Malinen355199e2013-02-27 17:14:27 +020016707void cfg80211_ft_event(struct net_device *netdev,
16708 struct cfg80211_ft_event_params *ft_event)
16709{
16710 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016711 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016712 struct sk_buff *msg;
16713 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016714
16715 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16716
16717 if (!ft_event->target_ap)
16718 return;
16719
Dedy Lansky1039d082018-05-17 16:25:03 +030016720 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16721 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016722 if (!msg)
16723 return;
16724
16725 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016726 if (!hdr)
16727 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016728
Johannes Bergae917c92013-10-25 11:05:22 +020016729 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16730 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16731 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16732 goto out;
16733
16734 if (ft_event->ies &&
16735 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16736 goto out;
16737 if (ft_event->ric_ies &&
16738 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16739 ft_event->ric_ies))
16740 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016741
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016742 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016743
Johannes Berg68eb5502013-11-19 15:19:38 +010016744 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016745 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016746 return;
16747 out:
16748 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016749}
16750EXPORT_SYMBOL(cfg80211_ft_event);
16751
Arend van Spriel5de17982013-04-18 15:49:00 +020016752void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16753{
16754 struct cfg80211_registered_device *rdev;
16755 struct sk_buff *msg;
16756 void *hdr;
16757 u32 nlportid;
16758
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016759 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016760 if (!rdev->crit_proto_nlportid)
16761 return;
16762
16763 nlportid = rdev->crit_proto_nlportid;
16764 rdev->crit_proto_nlportid = 0;
16765
16766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16767 if (!msg)
16768 return;
16769
16770 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16771 if (!hdr)
16772 goto nla_put_failure;
16773
16774 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016775 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16776 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016777 goto nla_put_failure;
16778
16779 genlmsg_end(msg, hdr);
16780
16781 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16782 return;
16783
16784 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016785 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016786}
16787EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16788
Johannes Berg348baf02014-01-24 14:06:29 +010016789void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16790{
16791 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016792 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016793 struct sk_buff *msg;
16794 void *hdr;
16795
16796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16797 if (!msg)
16798 return;
16799
16800 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16801 if (!hdr)
16802 goto out;
16803
16804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16805 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016806 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16807 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016808 goto out;
16809
16810 genlmsg_end(msg, hdr);
16811
16812 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16813 NL80211_MCGRP_MLME, GFP_KERNEL);
16814 return;
16815 out:
16816 nlmsg_free(msg);
16817}
16818
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016819int cfg80211_external_auth_request(struct net_device *dev,
16820 struct cfg80211_external_auth_params *params,
16821 gfp_t gfp)
16822{
16823 struct wireless_dev *wdev = dev->ieee80211_ptr;
16824 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16825 struct sk_buff *msg;
16826 void *hdr;
16827
16828 if (!wdev->conn_owner_nlportid)
16829 return -EINVAL;
16830
16831 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16832 if (!msg)
16833 return -ENOMEM;
16834
16835 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16836 if (!hdr)
16837 goto nla_put_failure;
16838
16839 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16840 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16841 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16842 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16843 params->action) ||
16844 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16845 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16846 params->ssid.ssid))
16847 goto nla_put_failure;
16848
16849 genlmsg_end(msg, hdr);
16850 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16851 wdev->conn_owner_nlportid);
16852 return 0;
16853
16854 nla_put_failure:
16855 nlmsg_free(msg);
16856 return -ENOBUFS;
16857}
16858EXPORT_SYMBOL(cfg80211_external_auth_request);
16859
Sunil Duttcb74e972019-02-20 16:18:07 +053016860void cfg80211_update_owe_info_event(struct net_device *netdev,
16861 struct cfg80211_update_owe_info *owe_info,
16862 gfp_t gfp)
16863{
16864 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16865 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16866 struct sk_buff *msg;
16867 void *hdr;
16868
16869 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16870
16871 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16872 if (!msg)
16873 return;
16874
16875 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16876 if (!hdr)
16877 goto nla_put_failure;
16878
16879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16880 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16881 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16882 goto nla_put_failure;
16883
16884 if (!owe_info->ie_len ||
16885 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16886 goto nla_put_failure;
16887
16888 genlmsg_end(msg, hdr);
16889
16890 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16891 NL80211_MCGRP_MLME, gfp);
16892 return;
16893
16894nla_put_failure:
16895 genlmsg_cancel(msg, hdr);
16896 nlmsg_free(msg);
16897}
16898EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16899
Johannes Berg55682962007-09-20 13:09:35 -040016900/* initialisation/exit functions */
16901
Johannes Berg56989f62016-10-24 14:40:05 +020016902int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016903{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016904 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016905
Johannes Berg489111e2016-10-24 14:40:03 +020016906 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016907 if (err)
16908 return err;
16909
Jouni Malinen026331c2010-02-15 12:53:10 +020016910 err = netlink_register_notifier(&nl80211_netlink_notifier);
16911 if (err)
16912 goto err_out;
16913
Johannes Berg55682962007-09-20 13:09:35 -040016914 return 0;
16915 err_out:
16916 genl_unregister_family(&nl80211_fam);
16917 return err;
16918}
16919
16920void nl80211_exit(void)
16921{
Jouni Malinen026331c2010-02-15 12:53:10 +020016922 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016923 genl_unregister_family(&nl80211_fam);
16924}