blob: 68e5ab5394ddfd3fe9f61001501d3629cd8af219 [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
284const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400285 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
286 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700287 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200288 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100289
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200290 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530291 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100292 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
293 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
294 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
295
Johannes Bergab0d76f2018-10-02 10:00:07 +0200296 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
297 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200298 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100300 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200301 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400302
Johannes Bergab0d76f2018-10-02 10:00:07 +0200303 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400304 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
305 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100306
Johannes Berg1a28ed22019-05-28 14:18:07 +0200307 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
308 [NL80211_ATTR_PREV_BSSID] = {
309 .type = NLA_EXACT_LEN_WARN,
310 .len = ETH_ALEN
311 },
Johannes Berg41ade002007-12-19 02:03:29 +0100312
Johannes Bergb9454e82009-07-08 13:29:08 +0200313 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100314 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
315 .len = WLAN_MAX_KEY_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200316 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
Johannes Berg41ade002007-12-19 02:03:29 +0100317 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
318 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200319 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200320 [NL80211_ATTR_KEY_TYPE] =
321 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100322
323 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
324 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
325 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
326 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg3d7af872018-10-02 10:00:08 +0200327 [NL80211_ATTR_BEACON_TAIL] =
328 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
329 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200330 [NL80211_ATTR_STA_AID] =
331 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100332 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
333 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
334 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
335 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200336 [NL80211_ATTR_STA_PLINK_ACTION] =
337 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530338 [NL80211_ATTR_STA_TX_POWER_SETTING] =
339 NLA_POLICY_RANGE(NLA_U8,
340 NL80211_TX_POWER_AUTOMATIC,
341 NL80211_TX_POWER_FIXED),
342 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100343 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200344 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100345 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800346 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100347 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300348
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700349 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
350 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
351
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300352 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
353 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
354 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200355 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
356 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100357 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300358
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800359 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700360 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700361
Johannes Berg1a28ed22019-05-28 14:18:07 +0200362 [NL80211_ATTR_HT_CAPABILITY] = {
363 .type = NLA_EXACT_LEN_WARN,
364 .len = NL80211_HT_CAPABILITY_LEN
365 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200366
367 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200368 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
369 validate_ie_attr,
370 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100371 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
372 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200373
374 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
375 .len = IEEE80211_MAX_SSID_LEN },
376 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
377 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200378 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300379 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200380 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
381 NL80211_MFP_NO,
382 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300383 [NL80211_ATTR_STA_FLAGS2] = {
384 .len = sizeof(struct nl80211_sta_flag_update),
385 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300386 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300387 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
388 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500389 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200390 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
391 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
392 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200393 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100394 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200395 [NL80211_ATTR_PMKID] = {
396 .type = NLA_EXACT_LEN_WARN,
397 .len = WLAN_PMKID_LEN
398 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100399 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
400 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200401 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200402 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
403 .len = IEEE80211_MAX_DATA_LEN },
404 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200405 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
406 NL80211_PS_DISABLED,
407 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200408 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300409 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200410 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300411 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
412 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200413 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900414 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
415 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100416 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100417 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100418 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200419 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200420 [NL80211_ATTR_STA_PLINK_STATE] =
421 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
422 [NL80211_ATTR_MESH_PEER_AID] =
423 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300424 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200425 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200426 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200427 [NL80211_ATTR_HIDDEN_SSID] =
428 NLA_POLICY_RANGE(NLA_U32,
429 NL80211_HIDDEN_SSID_NOT_IN_USE,
430 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200431 [NL80211_ATTR_IE_PROBE_RESP] =
432 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
433 IEEE80211_MAX_DATA_LEN),
434 [NL80211_ATTR_IE_ASSOC_RESP] =
435 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
436 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530437 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300438 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530439 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300440 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
441 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
442 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
443 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
444 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300445 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100446 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200447 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
448 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700449 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800450 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
451 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
452 .len = NL80211_HT_CAPABILITY_LEN
453 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100454 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530455 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530456 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200457 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700458 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300459 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200460 [NL80211_ATTR_VHT_CAPABILITY] = {
461 .type = NLA_EXACT_LEN_WARN,
462 .len = NL80211_VHT_CAPABILITY_LEN
463 },
Sam Lefflered4737712012-10-11 21:03:31 -0700464 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200465 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
466 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
467 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
468 NLA_POLICY_RANGE(NLA_U32,
469 NL80211_MESH_POWER_UNKNOWN + 1,
470 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530471 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
472 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200473 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
474 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100475 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100476 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
477 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
478 .len = NL80211_VHT_CAPABILITY_LEN,
479 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200480 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
481 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
482 .len = IEEE80211_MAX_DATA_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200483 [NL80211_ATTR_PEER_AID] =
484 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200485 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
486 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
487 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300488 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
489 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530490 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
491 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200492 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100493 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100494 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
495 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
496 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800497 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
498 .len = IEEE80211_QOS_MAP_LEN_MAX },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200499 [NL80211_ATTR_MAC_HINT] = {
500 .type = NLA_EXACT_LEN_WARN,
501 .len = ETH_ALEN
502 },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200503 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530504 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200505 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300506 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300507 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200508 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
509 [NL80211_ATTR_USER_PRIO] =
510 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300511 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300512 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200513 [NL80211_ATTR_MAC_MASK] = {
514 .type = NLA_EXACT_LEN_WARN,
515 .len = ETH_ALEN
516 },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200517 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200518 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200519 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500520 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200521 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100522 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200523 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
524 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300525 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
526 .len = VHT_MUMIMO_GROUPS_DATA_LEN
527 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200528 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = {
529 .type = NLA_EXACT_LEN_WARN,
530 .len = ETH_ALEN
531 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200532 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200533 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300534 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300535 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
536 .len = FILS_MAX_KEK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200537 [NL80211_ATTR_FILS_NONCES] = {
538 .type = NLA_EXACT_LEN_WARN,
539 .len = 2 * FILS_NONCE_LEN
540 },
Michael Braunce0ce132016-10-10 19:12:22 +0200541 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200542 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200543 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
544 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
545 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
546 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200547 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300548 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
549 .len = FILS_ERP_MAX_USERNAME_LEN },
550 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
551 .len = FILS_ERP_MAX_REALM_LEN },
552 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
553 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
554 .len = FILS_ERP_MAX_RRK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200555 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300556 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100557 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200558 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200559
560 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
561 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
562 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300563 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
564 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700565
566 [NL80211_ATTR_FTM_RESPONDER] = {
567 .type = NLA_NESTED,
568 .validation_data = nl80211_ftm_responder_policy,
569 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200570 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
571 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100572 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800573 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000574 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
575 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200576 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400577};
578
Johannes Berge31b8212010-10-05 19:39:30 +0200579/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000580static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200581 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200582 [NL80211_KEY_IDX] = { .type = NLA_U8 },
583 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200584 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200585 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
586 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200587 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100588 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100589 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100590};
591
592/* policy for the key default flags */
593static const struct nla_policy
594nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
595 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
596 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200597};
598
Johannes Bergf83ace32016-10-17 08:04:07 +0200599#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200600/* policy for WoWLAN attributes */
601static const struct nla_policy
602nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
603 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
604 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
605 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
606 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200607 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
608 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
609 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
610 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100611 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300612 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100613};
614
615static const struct nla_policy
616nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
617 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
618 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200619 [NL80211_WOWLAN_TCP_DST_MAC] = {
620 .type = NLA_EXACT_LEN_WARN,
621 .len = ETH_ALEN
622 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100623 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
624 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200625 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100626 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
627 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
628 },
629 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
630 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
631 },
632 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200633 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
634 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200635};
Johannes Bergf83ace32016-10-17 08:04:07 +0200636#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200637
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700638/* policy for coalesce rule attributes */
639static const struct nla_policy
640nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
641 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200642 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
643 NLA_POLICY_RANGE(NLA_U32,
644 NL80211_COALESCE_CONDITION_MATCH,
645 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700646 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
647};
648
Johannes Berge5497d72011-07-05 16:35:40 +0200649/* policy for GTK rekey offload attributes */
650static const struct nla_policy
651nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Johannes Berg1a28ed22019-05-28 14:18:07 +0200652 [NL80211_REKEY_DATA_KEK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KEK_LEN },
653 [NL80211_REKEY_DATA_KCK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KCK_LEN },
654 [NL80211_REKEY_DATA_REPLAY_CTR] = {
655 .type = NLA_EXACT_LEN_WARN,
656 .len = NL80211_REPLAY_CTR_LEN
657 },
Johannes Berge5497d72011-07-05 16:35:40 +0200658};
659
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300660static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530661nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
662 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
663 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
664 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
665};
666
667static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300668nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200669 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300670 .len = IEEE80211_MAX_SSID_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200671 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
672 .type = NLA_EXACT_LEN_WARN,
673 .len = ETH_ALEN
674 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700675 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530676 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
677 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300678};
679
Avraham Stern3b06d272015-10-12 09:51:34 +0300680static const struct nla_policy
681nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
682 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
683 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
684};
685
Arend van Spriel38de03d2016-03-02 20:37:18 +0100686static const struct nla_policy
687nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
688 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
689 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
690 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
691 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
692 },
693};
694
Ayala Bekera442b762016-09-20 17:31:15 +0300695/* policy for NAN function attributes */
696static const struct nla_policy
697nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
698 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300699 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300700 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
701 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
702 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
703 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
704 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
705 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200706 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
707 .type = NLA_EXACT_LEN_WARN,
708 .len = ETH_ALEN
709 },
Ayala Bekera442b762016-09-20 17:31:15 +0300710 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
711 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
712 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
713 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
714 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
715 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
716 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
717 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
718 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
719};
720
721/* policy for Service Response Filter attributes */
722static const struct nla_policy
723nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
724 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
725 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
726 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
727 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
728 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
729};
730
Peng Xuad670232017-10-03 23:21:51 +0300731/* policy for packet pattern attributes */
732static const struct nla_policy
733nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
734 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
735 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
736 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
737};
738
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200739int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
740 struct cfg80211_registered_device **rdev,
741 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100742{
Johannes Berg67748892010-10-04 21:14:06 +0200743 int err;
744
Johannes Berg97990a02013-04-19 01:02:55 +0200745 if (!cb->args[0]) {
Johannes Berg8cb08172019-04-26 14:07:28 +0200746 err = nlmsg_parse_deprecated(cb->nlh,
747 GENL_HDRLEN + nl80211_fam.hdrsize,
748 genl_family_attrbuf(&nl80211_fam),
749 nl80211_fam.maxattr,
750 nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200751 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100752 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200753
Johannes Bergc90c39d2016-10-24 14:40:01 +0200754 *wdev = __cfg80211_wdev_from_attrs(
Johannes Berg5297c652018-09-27 14:36:44 +0200755 sock_net(cb->skb->sk),
Johannes Bergc90c39d2016-10-24 14:40:01 +0200756 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100757 if (IS_ERR(*wdev))
758 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800759 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200760 /* 0 is the first index - add 1 to parse only once */
761 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200762 cb->args[1] = (*wdev)->identifier;
763 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200764 /* subtract the 1 again here */
765 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200766 struct wireless_dev *tmp;
767
Johannes Bergea90e0d2017-03-15 14:26:04 +0100768 if (!wiphy)
769 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800770 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200771 *wdev = NULL;
772
Johannes Berg53873f12016-05-03 16:52:04 +0300773 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200774 if (tmp->identifier == cb->args[1]) {
775 *wdev = tmp;
776 break;
777 }
778 }
Johannes Berg97990a02013-04-19 01:02:55 +0200779
Johannes Bergea90e0d2017-03-15 14:26:04 +0100780 if (!*wdev)
781 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200782 }
783
Johannes Berg67748892010-10-04 21:14:06 +0200784 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200785}
786
Johannes Berg55682962007-09-20 13:09:35 -0400787/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200788void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
789 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400790{
791 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000792 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400793}
794
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300795static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
796 const struct ieee80211_reg_rule *rule)
797{
798 int j;
799 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200800 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300801
802 if (!nl_wmm_rules)
803 goto nla_put_failure;
804
805 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200806 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300807
808 if (!nl_wmm_rule)
809 goto nla_put_failure;
810
811 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200812 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300813 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200814 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300815 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200816 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300817 nla_put_u16(msg, NL80211_WMMR_TXOP,
818 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300819 goto nla_put_failure;
820
821 nla_nest_end(msg, nl_wmm_rule);
822 }
823 nla_nest_end(msg, nl_wmm_rules);
824
825 return 0;
826
827nla_put_failure:
828 return -ENOBUFS;
829}
830
831static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100832 struct ieee80211_channel *chan,
833 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400834{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200835 /* Some channels must be completely excluded from the
836 * list to protect old user-space tools from breaking
837 */
838 if (!large && chan->flags &
839 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
840 return 0;
841
David S. Miller9360ffd2012-03-29 04:41:26 -0400842 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
843 chan->center_freq))
844 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400845
David S. Miller9360ffd2012-03-29 04:41:26 -0400846 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
847 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
848 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200849 if (chan->flags & IEEE80211_CHAN_NO_IR) {
850 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
851 goto nla_put_failure;
852 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
853 goto nla_put_failure;
854 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100855 if (chan->flags & IEEE80211_CHAN_RADAR) {
856 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
857 goto nla_put_failure;
858 if (large) {
859 u32 time;
860
861 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
862
863 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
864 chan->dfs_state))
865 goto nla_put_failure;
866 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
867 time))
868 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100869 if (nla_put_u32(msg,
870 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
871 chan->dfs_cac_ms))
872 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100873 }
874 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400875
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100876 if (large) {
877 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
878 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
879 goto nla_put_failure;
880 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
881 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
882 goto nla_put_failure;
883 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
884 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
885 goto nla_put_failure;
886 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
887 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
888 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200889 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
890 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
891 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300892 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
893 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200894 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200895 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
896 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
897 goto nla_put_failure;
898 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
899 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
900 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100901 }
902
David S. Miller9360ffd2012-03-29 04:41:26 -0400903 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
904 DBM_TO_MBM(chan->max_power)))
905 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400906
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300907 if (large) {
908 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300909 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300910
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200911 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300912 if (nl80211_msg_put_wmm_rules(msg, rule))
913 goto nla_put_failure;
914 }
915 }
916
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400917 return 0;
918
919 nla_put_failure:
920 return -ENOBUFS;
921}
922
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200923static bool nl80211_put_txq_stats(struct sk_buff *msg,
924 struct cfg80211_txq_stats *txqstats,
925 int attrtype)
926{
927 struct nlattr *txqattr;
928
929#define PUT_TXQVAL_U32(attr, memb) do { \
930 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
931 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
932 return false; \
933 } while (0)
934
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200935 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200936 if (!txqattr)
937 return false;
938
939 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
940 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
941 PUT_TXQVAL_U32(FLOWS, flows);
942 PUT_TXQVAL_U32(DROPS, drops);
943 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
944 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
945 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
946 PUT_TXQVAL_U32(COLLISIONS, collisions);
947 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
948 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
949 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
950 nla_nest_end(msg, txqattr);
951
952#undef PUT_TXQVAL_U32
953 return true;
954}
955
Johannes Berg55682962007-09-20 13:09:35 -0400956/* netlink command implementations */
957
Johannes Bergb9454e82009-07-08 13:29:08 +0200958struct key_parse {
959 struct key_params p;
960 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200961 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200962 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100963 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200964};
965
Johannes Berg768075e2017-11-13 15:35:06 +0100966static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
967 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200968{
969 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +0200970 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
971 nl80211_key_policy,
972 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200973 if (err)
974 return err;
975
976 k->def = !!tb[NL80211_KEY_DEFAULT];
977 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
978
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100979 if (k->def) {
980 k->def_uni = true;
981 k->def_multi = true;
982 }
983 if (k->defmgmt)
984 k->def_multi = true;
985
Johannes Bergb9454e82009-07-08 13:29:08 +0200986 if (tb[NL80211_KEY_IDX])
987 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
988
989 if (tb[NL80211_KEY_DATA]) {
990 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
991 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
992 }
993
994 if (tb[NL80211_KEY_SEQ]) {
995 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
996 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
997 }
998
999 if (tb[NL80211_KEY_CIPHER])
1000 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1001
Johannes Bergab0d76f2018-10-02 10:00:07 +02001002 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001003 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001004
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001005 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1006 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001007
Johannes Berg8cb08172019-04-26 14:07:28 +02001008 err = nla_parse_nested_deprecated(kdt,
1009 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1010 tb[NL80211_KEY_DEFAULT_TYPES],
1011 nl80211_key_default_policy,
1012 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001013 if (err)
1014 return err;
1015
1016 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1017 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1018 }
1019
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001020 if (tb[NL80211_KEY_MODE])
1021 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1022
Johannes Bergb9454e82009-07-08 13:29:08 +02001023 return 0;
1024}
1025
1026static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1027{
1028 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1029 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1030 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1031 }
1032
1033 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1034 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1035 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1036 }
1037
1038 if (info->attrs[NL80211_ATTR_KEY_IDX])
1039 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1040
1041 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1042 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1043
1044 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1045 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1046
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001047 if (k->def) {
1048 k->def_uni = true;
1049 k->def_multi = true;
1050 }
1051 if (k->defmgmt)
1052 k->def_multi = true;
1053
Johannes Bergab0d76f2018-10-02 10:00:07 +02001054 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001055 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001056
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001057 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1058 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001059 int err = nla_parse_nested_deprecated(kdt,
1060 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1061 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1062 nl80211_key_default_policy,
1063 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001064 if (err)
1065 return err;
1066
1067 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1068 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1069 }
1070
Johannes Bergb9454e82009-07-08 13:29:08 +02001071 return 0;
1072}
1073
1074static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1075{
1076 int err;
1077
1078 memset(k, 0, sizeof(*k));
1079 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001080 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001081
1082 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001083 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001084 else
1085 err = nl80211_parse_key_old(info, k);
1086
1087 if (err)
1088 return err;
1089
Johannes Berg768075e2017-11-13 15:35:06 +01001090 if (k->def && k->defmgmt) {
1091 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001092 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001093 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001094
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001095 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001096 if (k->def_uni || !k->def_multi) {
1097 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001098 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001099 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001100 }
1101
Johannes Bergb9454e82009-07-08 13:29:08 +02001102 if (k->idx != -1) {
1103 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001104 if (k->idx < 4 || k->idx > 5) {
1105 GENL_SET_ERR_MSG(info,
1106 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001107 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001108 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001109 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001110 if (k->idx < 0 || k->idx > 3) {
1111 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001112 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001113 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001114 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001115 if (k->idx < 0 || k->idx > 5) {
1116 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001117 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001118 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001119 }
1120 }
1121
1122 return 0;
1123}
1124
Johannes Bergfffd0932009-07-08 14:22:54 +02001125static struct cfg80211_cached_keys *
1126nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001127 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001128{
Johannes Berg768075e2017-11-13 15:35:06 +01001129 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001130 struct key_parse parse;
1131 struct nlattr *key;
1132 struct cfg80211_cached_keys *result;
1133 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001134 bool have_key = false;
1135
1136 nla_for_each_nested(key, keys, rem) {
1137 have_key = true;
1138 break;
1139 }
1140
1141 if (!have_key)
1142 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001143
1144 result = kzalloc(sizeof(*result), GFP_KERNEL);
1145 if (!result)
1146 return ERR_PTR(-ENOMEM);
1147
1148 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001149
1150 nla_for_each_nested(key, keys, rem) {
1151 memset(&parse, 0, sizeof(parse));
1152 parse.idx = -1;
1153
Johannes Berg768075e2017-11-13 15:35:06 +01001154 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001155 if (err)
1156 goto error;
1157 err = -EINVAL;
1158 if (!parse.p.key)
1159 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001160 if (parse.idx < 0 || parse.idx > 3) {
1161 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001162 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001163 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001164 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001165 if (def) {
1166 GENL_SET_ERR_MSG(info,
1167 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001168 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001169 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001170 def = 1;
1171 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001172 if (!parse.def_uni || !parse.def_multi)
1173 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001174 } else if (parse.defmgmt)
1175 goto error;
1176 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001177 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001178 if (err)
1179 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001180 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1181 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001182 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001183 err = -EINVAL;
1184 goto error;
1185 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001186 result->params[parse.idx].cipher = parse.p.cipher;
1187 result->params[parse.idx].key_len = parse.p.key_len;
1188 result->params[parse.idx].key = result->data[parse.idx];
1189 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301190
Johannes Berg386b1f22016-09-13 16:10:02 +02001191 /* must be WEP key if we got here */
1192 if (no_ht)
1193 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001194 }
1195
Johannes Bergf1c1f172016-09-13 17:08:23 +02001196 if (result->def < 0) {
1197 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001198 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001199 goto error;
1200 }
1201
Johannes Bergfffd0932009-07-08 14:22:54 +02001202 return result;
1203 error:
1204 kfree(result);
1205 return ERR_PTR(err);
1206}
1207
1208static int nl80211_key_allowed(struct wireless_dev *wdev)
1209{
1210 ASSERT_WDEV_LOCK(wdev);
1211
Johannes Bergfffd0932009-07-08 14:22:54 +02001212 switch (wdev->iftype) {
1213 case NL80211_IFTYPE_AP:
1214 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001215 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001216 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001217 break;
1218 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001219 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001220 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001221 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001222 return -ENOLINK;
1223 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001224 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001225 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001226 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001227 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001228 case NL80211_IFTYPE_P2P_DEVICE:
1229 case NL80211_IFTYPE_WDS:
1230 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001231 return -EINVAL;
1232 }
1233
1234 return 0;
1235}
1236
Jouni Malinen664834d2014-01-15 00:01:44 +02001237static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1238 struct nlattr *tb)
1239{
1240 struct ieee80211_channel *chan;
1241
1242 if (tb == NULL)
1243 return NULL;
1244 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1245 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1246 return NULL;
1247 return chan;
1248}
1249
Johannes Berg7527a782011-05-13 10:58:57 +02001250static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1251{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001252 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001253 int i;
1254
1255 if (!nl_modes)
1256 goto nla_put_failure;
1257
1258 i = 0;
1259 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001260 if ((ifmodes & 1) && nla_put_flag(msg, i))
1261 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001262 ifmodes >>= 1;
1263 i++;
1264 }
1265
1266 nla_nest_end(msg, nl_modes);
1267 return 0;
1268
1269nla_put_failure:
1270 return -ENOBUFS;
1271}
1272
1273static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001274 struct sk_buff *msg,
1275 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001276{
1277 struct nlattr *nl_combis;
1278 int i, j;
1279
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001280 nl_combis = nla_nest_start_noflag(msg,
1281 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001282 if (!nl_combis)
1283 goto nla_put_failure;
1284
1285 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1286 const struct ieee80211_iface_combination *c;
1287 struct nlattr *nl_combi, *nl_limits;
1288
1289 c = &wiphy->iface_combinations[i];
1290
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001291 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001292 if (!nl_combi)
1293 goto nla_put_failure;
1294
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001295 nl_limits = nla_nest_start_noflag(msg,
1296 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001297 if (!nl_limits)
1298 goto nla_put_failure;
1299
1300 for (j = 0; j < c->n_limits; j++) {
1301 struct nlattr *nl_limit;
1302
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001303 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001304 if (!nl_limit)
1305 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001306 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1307 c->limits[j].max))
1308 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001309 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1310 c->limits[j].types))
1311 goto nla_put_failure;
1312 nla_nest_end(msg, nl_limit);
1313 }
1314
1315 nla_nest_end(msg, nl_limits);
1316
David S. Miller9360ffd2012-03-29 04:41:26 -04001317 if (c->beacon_int_infra_match &&
1318 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1319 goto nla_put_failure;
1320 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1321 c->num_different_channels) ||
1322 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1323 c->max_interfaces))
1324 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001325 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001326 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1327 c->radar_detect_widths) ||
1328 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1329 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001330 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301331 if (c->beacon_int_min_gcd &&
1332 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1333 c->beacon_int_min_gcd))
1334 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001335
1336 nla_nest_end(msg, nl_combi);
1337 }
1338
1339 nla_nest_end(msg, nl_combis);
1340
1341 return 0;
1342nla_put_failure:
1343 return -ENOBUFS;
1344}
1345
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001347static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1348 struct sk_buff *msg)
1349{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001350 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001351 struct nlattr *nl_tcp;
1352
1353 if (!tcp)
1354 return 0;
1355
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001356 nl_tcp = nla_nest_start_noflag(msg,
1357 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001358 if (!nl_tcp)
1359 return -ENOBUFS;
1360
1361 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1362 tcp->data_payload_max))
1363 return -ENOBUFS;
1364
1365 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1366 tcp->data_payload_max))
1367 return -ENOBUFS;
1368
1369 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1370 return -ENOBUFS;
1371
1372 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1373 sizeof(*tcp->tok), tcp->tok))
1374 return -ENOBUFS;
1375
1376 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1377 tcp->data_interval_max))
1378 return -ENOBUFS;
1379
1380 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1381 tcp->wake_payload_max))
1382 return -ENOBUFS;
1383
1384 nla_nest_end(msg, nl_tcp);
1385 return 0;
1386}
1387
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001389 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001390 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391{
1392 struct nlattr *nl_wowlan;
1393
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001394 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 return 0;
1396
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001397 nl_wowlan = nla_nest_start_noflag(msg,
1398 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 if (!nl_wowlan)
1400 return -ENOBUFS;
1401
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001404 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001406 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001408 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001410 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001412 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001414 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1418 return -ENOBUFS;
1419
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001420 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001421 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001422 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1423 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1424 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1425 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 };
1427
1428 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1429 sizeof(pat), &pat))
1430 return -ENOBUFS;
1431 }
1432
Luciano Coelho75453cc2015-01-09 14:06:37 +02001433 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1434 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1435 rdev->wiphy.wowlan->max_nd_match_sets))
1436 return -ENOBUFS;
1437
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001438 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001439 return -ENOBUFS;
1440
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441 nla_nest_end(msg, nl_wowlan);
1442
1443 return 0;
1444}
1445#endif
1446
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001447static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001448 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001449{
1450 struct nl80211_coalesce_rule_support rule;
1451
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001453 return 0;
1454
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001455 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1456 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1457 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1458 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1459 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1460 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001461
1462 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1463 return -ENOBUFS;
1464
1465 return 0;
1466}
1467
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001468static int
1469nl80211_send_iftype_data(struct sk_buff *msg,
1470 const struct ieee80211_sband_iftype_data *iftdata)
1471{
1472 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1473
1474 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1475 iftdata->types_mask))
1476 return -ENOBUFS;
1477
1478 if (he_cap->has_he) {
1479 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1480 sizeof(he_cap->he_cap_elem.mac_cap_info),
1481 he_cap->he_cap_elem.mac_cap_info) ||
1482 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1483 sizeof(he_cap->he_cap_elem.phy_cap_info),
1484 he_cap->he_cap_elem.phy_cap_info) ||
1485 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1486 sizeof(he_cap->he_mcs_nss_supp),
1487 &he_cap->he_mcs_nss_supp) ||
1488 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1489 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1490 return -ENOBUFS;
1491 }
1492
1493 return 0;
1494}
1495
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1497 struct ieee80211_supported_band *sband)
1498{
1499 struct nlattr *nl_rates, *nl_rate;
1500 struct ieee80211_rate *rate;
1501 int i;
1502
1503 /* add HT info */
1504 if (sband->ht_cap.ht_supported &&
1505 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1506 sizeof(sband->ht_cap.mcs),
1507 &sband->ht_cap.mcs) ||
1508 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1509 sband->ht_cap.cap) ||
1510 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1511 sband->ht_cap.ampdu_factor) ||
1512 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1513 sband->ht_cap.ampdu_density)))
1514 return -ENOBUFS;
1515
1516 /* add VHT info */
1517 if (sband->vht_cap.vht_supported &&
1518 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1519 sizeof(sband->vht_cap.vht_mcs),
1520 &sband->vht_cap.vht_mcs) ||
1521 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1522 sband->vht_cap.cap)))
1523 return -ENOBUFS;
1524
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001525 if (sband->n_iftype_data) {
1526 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001527 nla_nest_start_noflag(msg,
1528 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001529 int err;
1530
1531 if (!nl_iftype_data)
1532 return -ENOBUFS;
1533
1534 for (i = 0; i < sband->n_iftype_data; i++) {
1535 struct nlattr *iftdata;
1536
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001537 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001538 if (!iftdata)
1539 return -ENOBUFS;
1540
1541 err = nl80211_send_iftype_data(msg,
1542 &sband->iftype_data[i]);
1543 if (err)
1544 return err;
1545
1546 nla_nest_end(msg, iftdata);
1547 }
1548
1549 nla_nest_end(msg, nl_iftype_data);
1550 }
1551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001553 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 if (!nl_rates)
1555 return -ENOBUFS;
1556
1557 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001558 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 if (!nl_rate)
1560 return -ENOBUFS;
1561
1562 rate = &sband->bitrates[i];
1563 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1564 rate->bitrate))
1565 return -ENOBUFS;
1566 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1567 nla_put_flag(msg,
1568 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1569 return -ENOBUFS;
1570
1571 nla_nest_end(msg, nl_rate);
1572 }
1573
1574 nla_nest_end(msg, nl_rates);
1575
1576 return 0;
1577}
1578
1579static int
1580nl80211_send_mgmt_stypes(struct sk_buff *msg,
1581 const struct ieee80211_txrx_stypes *mgmt_stypes)
1582{
1583 u16 stypes;
1584 struct nlattr *nl_ftypes, *nl_ifs;
1585 enum nl80211_iftype ift;
1586 int i;
1587
1588 if (!mgmt_stypes)
1589 return 0;
1590
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001591 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 if (!nl_ifs)
1593 return -ENOBUFS;
1594
1595 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001596 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 if (!nl_ftypes)
1598 return -ENOBUFS;
1599 i = 0;
1600 stypes = mgmt_stypes[ift].tx;
1601 while (stypes) {
1602 if ((stypes & 1) &&
1603 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1604 (i << 4) | IEEE80211_FTYPE_MGMT))
1605 return -ENOBUFS;
1606 stypes >>= 1;
1607 i++;
1608 }
1609 nla_nest_end(msg, nl_ftypes);
1610 }
1611
1612 nla_nest_end(msg, nl_ifs);
1613
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001614 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_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].rx;
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 nla_nest_end(msg, nl_ifs);
1635
1636 return 0;
1637}
1638
Johannes Berg17948992016-10-26 11:42:04 +02001639#define CMD(op, n) \
1640 do { \
1641 if (rdev->ops->op) { \
1642 i++; \
1643 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1644 goto nla_put_failure; \
1645 } \
1646 } while (0)
1647
1648static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1649 struct sk_buff *msg)
1650{
1651 int i = 0;
1652
1653 /*
1654 * do *NOT* add anything into this function, new things need to be
1655 * advertised only to new versions of userspace that can deal with
1656 * the split (and they can't possibly care about new features...
1657 */
1658 CMD(add_virtual_intf, NEW_INTERFACE);
1659 CMD(change_virtual_intf, SET_INTERFACE);
1660 CMD(add_key, NEW_KEY);
1661 CMD(start_ap, START_AP);
1662 CMD(add_station, NEW_STATION);
1663 CMD(add_mpath, NEW_MPATH);
1664 CMD(update_mesh_config, SET_MESH_CONFIG);
1665 CMD(change_bss, SET_BSS);
1666 CMD(auth, AUTHENTICATE);
1667 CMD(assoc, ASSOCIATE);
1668 CMD(deauth, DEAUTHENTICATE);
1669 CMD(disassoc, DISASSOCIATE);
1670 CMD(join_ibss, JOIN_IBSS);
1671 CMD(join_mesh, JOIN_MESH);
1672 CMD(set_pmksa, SET_PMKSA);
1673 CMD(del_pmksa, DEL_PMKSA);
1674 CMD(flush_pmksa, FLUSH_PMKSA);
1675 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1676 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1677 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1678 CMD(mgmt_tx, FRAME);
1679 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1680 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1681 i++;
1682 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1683 goto nla_put_failure;
1684 }
1685 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1686 rdev->ops->join_mesh) {
1687 i++;
1688 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1689 goto nla_put_failure;
1690 }
1691 CMD(set_wds_peer, SET_WDS_PEER);
1692 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1693 CMD(tdls_mgmt, TDLS_MGMT);
1694 CMD(tdls_oper, TDLS_OPER);
1695 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001696 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001697 CMD(sched_scan_start, START_SCHED_SCAN);
1698 CMD(probe_client, PROBE_CLIENT);
1699 CMD(set_noack_map, SET_NOACK_MAP);
1700 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1701 i++;
1702 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1703 goto nla_put_failure;
1704 }
1705 CMD(start_p2p_device, START_P2P_DEVICE);
1706 CMD(set_mcast_rate, SET_MCAST_RATE);
1707#ifdef CONFIG_NL80211_TESTMODE
1708 CMD(testmode_cmd, TESTMODE);
1709#endif
1710
1711 if (rdev->ops->connect || rdev->ops->auth) {
1712 i++;
1713 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1714 goto nla_put_failure;
1715 }
1716
1717 if (rdev->ops->disconnect || rdev->ops->deauth) {
1718 i++;
1719 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1720 goto nla_put_failure;
1721 }
1722
1723 return i;
1724 nla_put_failure:
1725 return -ENOBUFS;
1726}
1727
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001728static int
1729nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1730 struct sk_buff *msg)
1731{
1732 struct nlattr *ftm;
1733
1734 if (!cap->ftm.supported)
1735 return 0;
1736
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001737 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001738 if (!ftm)
1739 return -ENOBUFS;
1740
1741 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1742 return -ENOBUFS;
1743 if (cap->ftm.non_asap &&
1744 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1745 return -ENOBUFS;
1746 if (cap->ftm.request_lci &&
1747 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1748 return -ENOBUFS;
1749 if (cap->ftm.request_civicloc &&
1750 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1751 return -ENOBUFS;
1752 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1753 cap->ftm.preambles))
1754 return -ENOBUFS;
1755 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1756 cap->ftm.bandwidths))
1757 return -ENOBUFS;
1758 if (cap->ftm.max_bursts_exponent >= 0 &&
1759 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1760 cap->ftm.max_bursts_exponent))
1761 return -ENOBUFS;
1762 if (cap->ftm.max_ftms_per_burst &&
1763 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1764 cap->ftm.max_ftms_per_burst))
1765 return -ENOBUFS;
1766
1767 nla_nest_end(msg, ftm);
1768 return 0;
1769}
1770
1771static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1772 struct sk_buff *msg)
1773{
1774 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1775 struct nlattr *pmsr, *caps;
1776
1777 if (!cap)
1778 return 0;
1779
1780 /*
1781 * we don't need to clean up anything here since the caller
1782 * will genlmsg_cancel() if we fail
1783 */
1784
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001785 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001786 if (!pmsr)
1787 return -ENOBUFS;
1788
1789 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1790 return -ENOBUFS;
1791
1792 if (cap->report_ap_tsf &&
1793 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1794 return -ENOBUFS;
1795
1796 if (cap->randomize_mac_addr &&
1797 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1798 return -ENOBUFS;
1799
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001800 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001801 if (!caps)
1802 return -ENOBUFS;
1803
1804 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1805 return -ENOBUFS;
1806
1807 nla_nest_end(msg, caps);
1808 nla_nest_end(msg, pmsr);
1809
1810 return 0;
1811}
1812
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813struct nl80211_dump_wiphy_state {
1814 s64 filter_wiphy;
1815 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301816 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001817 bool split;
1818};
1819
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001820static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001821 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001822 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001824{
1825 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001826 struct nlattr *nl_bands, *nl_band;
1827 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001828 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001829 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001830 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001831 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001832 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001833 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001834 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001835
Johannes Berg3bb20552014-05-26 13:52:25 +02001836 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001837 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001838 return -ENOBUFS;
1839
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840 if (WARN_ON(!state))
1841 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001842
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001844 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001845 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001846 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001847 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001848 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001849
Johannes Berg3bb20552014-05-26 13:52:25 +02001850 if (cmd != NL80211_CMD_NEW_WIPHY)
1851 goto finish;
1852
Johannes Berg86e8cf92013-06-19 10:57:22 +02001853 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001854 case 0:
1855 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001856 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001857 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001858 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001859 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001860 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001861 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001862 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001863 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001864 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001865 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001866 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001867 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001868 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001870 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001872 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001873 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001874 rdev->wiphy.max_match_sets) ||
1875 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1876 rdev->wiphy.max_sched_scan_plans) ||
1877 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1878 rdev->wiphy.max_sched_scan_plan_interval) ||
1879 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1880 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001881 goto nla_put_failure;
1882
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001883 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001884 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1885 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001886 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1888 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001889 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1891 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001892 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001893 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1894 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001895 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1897 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001898 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001899 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001900 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001901 state->split_start++;
1902 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001903 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001904 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001905 case 1:
1906 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001907 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1908 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001909 goto nla_put_failure;
1910
Johannes Berg3713b4e2013-02-14 16:19:38 +01001911 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001912 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001913 goto nla_put_failure;
1914
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001915 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001916 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1917 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001918
Johannes Berg3713b4e2013-02-14 16:19:38 +01001919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001920 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001921 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001922 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001923 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001924
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001925 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001926 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001927 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001928 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001929
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001930 if ((rdev->wiphy.available_antennas_tx ||
1931 rdev->wiphy.available_antennas_rx) &&
1932 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001933 u32 tx_ant = 0, rx_ant = 0;
1934 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001935
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001936 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001937 if (!res) {
1938 if (nla_put_u32(msg,
1939 NL80211_ATTR_WIPHY_ANTENNA_TX,
1940 tx_ant) ||
1941 nla_put_u32(msg,
1942 NL80211_ATTR_WIPHY_ANTENNA_RX,
1943 rx_ant))
1944 goto nla_put_failure;
1945 }
Johannes Bergee688b002008-01-24 19:38:39 +01001946 }
1947
Johannes Berg86e8cf92013-06-19 10:57:22 +02001948 state->split_start++;
1949 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001950 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001951 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001952 case 2:
1953 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001954 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001955 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001956 state->split_start++;
1957 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001958 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001959 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001961 nl_bands = nla_nest_start_noflag(msg,
1962 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001963 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001964 goto nla_put_failure;
1965
Johannes Berg86e8cf92013-06-19 10:57:22 +02001966 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001967 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001968 struct ieee80211_supported_band *sband;
1969
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001970 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001971
1972 if (!sband)
1973 continue;
1974
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001975 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001976 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001977 goto nla_put_failure;
1978
Johannes Berg86e8cf92013-06-19 10:57:22 +02001979 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001980 case 0:
1981 if (nl80211_send_band_rateinfo(msg, sband))
1982 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001983 state->chan_start++;
1984 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001985 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001986 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001987 default:
1988 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001989 nl_freqs = nla_nest_start_noflag(msg,
1990 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001991 if (!nl_freqs)
1992 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001993
Johannes Berg86e8cf92013-06-19 10:57:22 +02001994 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001995 i < sband->n_channels;
1996 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001997 nl_freq = nla_nest_start_noflag(msg,
1998 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001999 if (!nl_freq)
2000 goto nla_put_failure;
2001
2002 chan = &sband->channels[i];
2003
Johannes Berg86e8cf92013-06-19 10:57:22 +02002004 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002005 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002006 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002007 goto nla_put_failure;
2008
2009 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002010 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002011 break;
2012 }
2013 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002014 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002015 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002016 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002017 nla_nest_end(msg, nl_freqs);
2018 }
2019
2020 nla_nest_end(msg, nl_band);
2021
Johannes Berg86e8cf92013-06-19 10:57:22 +02002022 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002023 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002024 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002025 band--;
2026 break;
2027 }
Johannes Bergee688b002008-01-24 19:38:39 +01002028 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002029 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002030
Johannes Berg57fbcce2016-04-12 15:56:15 +02002031 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002032 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002033 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002034 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002035
Johannes Berg3713b4e2013-02-14 16:19:38 +01002036 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002037 if (state->band_start == 0 && state->chan_start == 0)
2038 state->split_start++;
2039 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002040 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002041 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002042 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002043 nl_cmds = nla_nest_start_noflag(msg,
2044 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002045 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002046 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002047
Johannes Berg17948992016-10-26 11:42:04 +02002048 i = nl80211_add_commands_unsplit(rdev, msg);
2049 if (i < 0)
2050 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002051 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002052 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2053 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002054 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002055 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002056 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002057 if (rdev->wiphy.features &
2058 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002059 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002060 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002061 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02002062 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002063#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002064
Johannes Berg3713b4e2013-02-14 16:19:38 +01002065 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002066 state->split_start++;
2067 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002068 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002069 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002070 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002071 if (rdev->ops->remain_on_channel &&
2072 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002073 nla_put_u32(msg,
2074 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002075 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002076 goto nla_put_failure;
2077
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002078 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002079 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2080 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002081
Johannes Berg3713b4e2013-02-14 16:19:38 +01002082 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2083 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002084 state->split_start++;
2085 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002086 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002087 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002088 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002089#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002090 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002091 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002092 state->split_start++;
2093 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002094 break;
2095#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002096 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002097#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002098 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002099 case 7:
2100 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002101 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002102 goto nla_put_failure;
2103
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002104 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002105 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002106 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002107
Johannes Berg86e8cf92013-06-19 10:57:22 +02002108 state->split_start++;
2109 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002110 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002111 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002112 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002113 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002114 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002115 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002116 goto nla_put_failure;
2117
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002118 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002119 /*
2120 * We can only add the per-channel limit information if the
2121 * dump is split, otherwise it makes it too big. Therefore
2122 * only advertise it in that case.
2123 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002124 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002125 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2126 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002127 goto nla_put_failure;
2128
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002129 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002130 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002131 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2132 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002133 goto nla_put_failure;
2134
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002135 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2136 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002137 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002138 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002139 goto nla_put_failure;
2140
2141 /*
2142 * Any information below this point is only available to
2143 * applications that can deal with it being split. This
2144 * helps ensure that newly added capabilities don't break
2145 * older tools by overrunning their buffers.
2146 *
2147 * We still increment split_start so that in the split
2148 * case we'll continue with more data in the next round,
2149 * but break unconditionally so unsplit data stops here.
2150 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002151 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002152 break;
2153 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002154 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002155 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002156 rdev->wiphy.extended_capabilities_len,
2157 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002158 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002159 rdev->wiphy.extended_capabilities_len,
2160 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002161 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002162
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002163 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002164 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002165 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2166 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002167 goto nla_put_failure;
2168
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002169 state->split_start++;
2170 break;
2171 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002172 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002173 goto nla_put_failure;
2174
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002175 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002176 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2178 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002179
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002180 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002181 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002182 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002183 goto nla_put_failure;
2184
Johannes Bergad7e7182013-11-13 13:37:47 +01002185 state->split_start++;
2186 break;
2187 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002188 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002189 const struct nl80211_vendor_cmd_info *info;
2190 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002191
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002192 nested = nla_nest_start_noflag(msg,
2193 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002194 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002195 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002196
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002197 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2198 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002199 if (nla_put(msg, i + 1, sizeof(*info), info))
2200 goto nla_put_failure;
2201 }
2202 nla_nest_end(msg, nested);
2203 }
2204
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002205 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002206 const struct nl80211_vendor_cmd_info *info;
2207 struct nlattr *nested;
2208
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002209 nested = nla_nest_start_noflag(msg,
2210 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002211 if (!nested)
2212 goto nla_put_failure;
2213
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002214 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2215 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002216 if (nla_put(msg, i + 1, sizeof(*info), info))
2217 goto nla_put_failure;
2218 }
2219 nla_nest_end(msg, nested);
2220 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002221 state->split_start++;
2222 break;
2223 case 12:
2224 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2225 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2226 rdev->wiphy.max_num_csa_counters))
2227 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002228
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002229 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2230 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2231 goto nla_put_failure;
2232
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002233 if (rdev->wiphy.max_sched_scan_reqs &&
2234 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2235 rdev->wiphy.max_sched_scan_reqs))
2236 goto nla_put_failure;
2237
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002238 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2239 sizeof(rdev->wiphy.ext_features),
2240 rdev->wiphy.ext_features))
2241 goto nla_put_failure;
2242
Arend van Spriel38de03d2016-03-02 20:37:18 +01002243 if (rdev->wiphy.bss_select_support) {
2244 struct nlattr *nested;
2245 u32 bss_select_support = rdev->wiphy.bss_select_support;
2246
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002247 nested = nla_nest_start_noflag(msg,
2248 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002249 if (!nested)
2250 goto nla_put_failure;
2251
2252 i = 0;
2253 while (bss_select_support) {
2254 if ((bss_select_support & 1) &&
2255 nla_put_flag(msg, i))
2256 goto nla_put_failure;
2257 i++;
2258 bss_select_support >>= 1;
2259 }
2260 nla_nest_end(msg, nested);
2261 }
2262
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302263 state->split_start++;
2264 break;
2265 case 13:
2266 if (rdev->wiphy.num_iftype_ext_capab &&
2267 rdev->wiphy.iftype_ext_capab) {
2268 struct nlattr *nested_ext_capab, *nested;
2269
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002270 nested = nla_nest_start_noflag(msg,
2271 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302272 if (!nested)
2273 goto nla_put_failure;
2274
2275 for (i = state->capa_start;
2276 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2277 const struct wiphy_iftype_ext_capab *capab;
2278
2279 capab = &rdev->wiphy.iftype_ext_capab[i];
2280
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002281 nested_ext_capab = nla_nest_start_noflag(msg,
2282 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302283 if (!nested_ext_capab ||
2284 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2285 capab->iftype) ||
2286 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2287 capab->extended_capabilities_len,
2288 capab->extended_capabilities) ||
2289 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2290 capab->extended_capabilities_len,
2291 capab->extended_capabilities_mask))
2292 goto nla_put_failure;
2293
2294 nla_nest_end(msg, nested_ext_capab);
2295 if (state->split)
2296 break;
2297 }
2298 nla_nest_end(msg, nested);
2299 if (i < rdev->wiphy.num_iftype_ext_capab) {
2300 state->capa_start = i + 1;
2301 break;
2302 }
2303 }
2304
Luca Coelho85859892017-02-08 15:00:34 +02002305 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2306 rdev->wiphy.nan_supported_bands))
2307 goto nla_put_failure;
2308
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002309 if (wiphy_ext_feature_isset(&rdev->wiphy,
2310 NL80211_EXT_FEATURE_TXQS)) {
2311 struct cfg80211_txq_stats txqstats = {};
2312 int res;
2313
2314 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2315 if (!res &&
2316 !nl80211_put_txq_stats(msg, &txqstats,
2317 NL80211_ATTR_TXQ_STATS))
2318 goto nla_put_failure;
2319
2320 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2321 rdev->wiphy.txq_limit))
2322 goto nla_put_failure;
2323 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2324 rdev->wiphy.txq_memory_limit))
2325 goto nla_put_failure;
2326 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2327 rdev->wiphy.txq_quantum))
2328 goto nla_put_failure;
2329 }
2330
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002331 state->split_start++;
2332 break;
2333 case 14:
2334 if (nl80211_send_pmsr_capa(rdev, msg))
2335 goto nla_put_failure;
2336
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302337 state->split_start++;
2338 break;
2339 case 15:
2340 if (rdev->wiphy.akm_suites &&
2341 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2342 sizeof(u32) * rdev->wiphy.n_akm_suites,
2343 rdev->wiphy.akm_suites))
2344 goto nla_put_failure;
2345
Johannes Berg3713b4e2013-02-14 16:19:38 +01002346 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002347 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002348 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002349 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002350 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002351 genlmsg_end(msg, hdr);
2352 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002353
2354 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002355 genlmsg_cancel(msg, hdr);
2356 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002357}
2358
Johannes Berg86e8cf92013-06-19 10:57:22 +02002359static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2360 struct netlink_callback *cb,
2361 struct nl80211_dump_wiphy_state *state)
2362{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002363 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Berg8cb08172019-04-26 14:07:28 +02002364 int ret = nlmsg_parse_deprecated(cb->nlh,
2365 GENL_HDRLEN + nl80211_fam.hdrsize,
2366 tb, nl80211_fam.maxattr,
2367 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002368 /* ignore parse errors for backward compatibility */
2369 if (ret)
2370 return 0;
2371
2372 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2373 if (tb[NL80211_ATTR_WIPHY])
2374 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2375 if (tb[NL80211_ATTR_WDEV])
2376 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2377 if (tb[NL80211_ATTR_IFINDEX]) {
2378 struct net_device *netdev;
2379 struct cfg80211_registered_device *rdev;
2380 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2381
Ying Xue7f2b8562014-01-15 10:23:45 +08002382 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002383 if (!netdev)
2384 return -ENODEV;
2385 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002386 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002387 netdev->ieee80211_ptr->wiphy);
2388 state->filter_wiphy = rdev->wiphy_idx;
2389 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002390 }
2391
2392 return 0;
2393}
2394
Johannes Berg55682962007-09-20 13:09:35 -04002395static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2396{
Johannes Berg645e77d2013-03-01 14:03:49 +01002397 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002398 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002399 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002400
Johannes Berg5fe231e2013-05-08 21:45:15 +02002401 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002402 if (!state) {
2403 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002404 if (!state) {
2405 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002406 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002407 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002408 state->filter_wiphy = -1;
2409 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2410 if (ret) {
2411 kfree(state);
2412 rtnl_unlock();
2413 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002414 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002415 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002416 }
2417
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002418 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2419 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002420 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002421 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002422 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002423 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002424 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002425 continue;
2426 /* attempt to fit multiple wiphy data chunks into the skb */
2427 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002428 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2429 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002430 NETLINK_CB(cb->skb).portid,
2431 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002432 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002433 if (ret < 0) {
2434 /*
2435 * If sending the wiphy data didn't fit (ENOBUFS
2436 * or EMSGSIZE returned), this SKB is still
2437 * empty (so it's not too big because another
2438 * wiphy dataset is already in the skb) and
2439 * we've not tried to adjust the dump allocation
2440 * yet ... then adjust the alloc size to be
2441 * bigger, and return 1 but with the empty skb.
2442 * This results in an empty message being RX'ed
2443 * in userspace, but that is ignored.
2444 *
2445 * We can then retry with the larger buffer.
2446 */
2447 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002448 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002449 cb->min_dump_alloc < 4096) {
2450 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002451 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002452 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002453 return 1;
2454 }
2455 idx--;
2456 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002457 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002458 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002459 break;
Johannes Berg55682962007-09-20 13:09:35 -04002460 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002461 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002462
Johannes Berg86e8cf92013-06-19 10:57:22 +02002463 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002464
2465 return skb->len;
2466}
2467
Johannes Berg86e8cf92013-06-19 10:57:22 +02002468static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2469{
2470 kfree((void *)cb->args[0]);
2471 return 0;
2472}
2473
Johannes Berg55682962007-09-20 13:09:35 -04002474static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2475{
2476 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002478 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002479
Johannes Berg645e77d2013-03-01 14:03:49 +01002480 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002481 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002482 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002483
Johannes Berg3bb20552014-05-26 13:52:25 +02002484 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2485 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002486 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002487 nlmsg_free(msg);
2488 return -ENOBUFS;
2489 }
Johannes Berg55682962007-09-20 13:09:35 -04002490
Johannes Berg134e6372009-07-10 09:51:34 +00002491 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002492}
2493
Jouni Malinen31888482008-10-30 16:59:24 +02002494static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2495 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2496 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2497 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2498 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2499 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2500};
2501
2502static int parse_txq_params(struct nlattr *tb[],
2503 struct ieee80211_txq_params *txq_params)
2504{
Dan Williams259d8c12018-01-29 17:03:15 -08002505 u8 ac;
2506
Johannes Berga3304b02012-03-28 11:04:24 +02002507 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002508 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2509 !tb[NL80211_TXQ_ATTR_AIFS])
2510 return -EINVAL;
2511
Dan Williams259d8c12018-01-29 17:03:15 -08002512 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002513 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2514 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2515 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2516 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2517
Dan Williams259d8c12018-01-29 17:03:15 -08002518 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002519 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002520 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002521 return 0;
2522}
2523
Johannes Bergf444de02010-05-05 15:25:02 +02002524static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2525{
2526 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002527 * You can only set the channel explicitly for WDS interfaces,
2528 * all others have their channel managed via their respective
2529 * "establish a connection" command (connect, join, ...)
2530 *
2531 * For AP/GO and mesh mode, the channel can be set with the
2532 * channel userspace API, but is only stored and passed to the
2533 * low-level driver when the AP starts or the mesh is joined.
2534 * This is for backward compatibility, userspace can also give
2535 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002536 *
2537 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002538 * whatever else is going on, so they have their own special
2539 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002540 */
2541 return !wdev ||
2542 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002543 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002544 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2545 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002546}
2547
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002548int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2549 struct genl_info *info,
2550 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002551{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002552 struct netlink_ext_ack *extack = info->extack;
2553 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302554 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002555
Johannes Berg49f9cf02018-10-01 11:55:09 +02002556 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002557 return -EINVAL;
2558
Johannes Berg49f9cf02018-10-01 11:55:09 +02002559 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002560
2561 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002562 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2563 chandef->center_freq1 = control_freq;
2564 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002565
2566 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002567 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2568 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2569 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002570 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002571 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002572
Johannes Berg49f9cf02018-10-01 11:55:09 +02002573 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002574 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002575
Johannes Berg49f9cf02018-10-01 11:55:09 +02002576 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002577
2578 switch (chantype) {
2579 case NL80211_CHAN_NO_HT:
2580 case NL80211_CHAN_HT20:
2581 case NL80211_CHAN_HT40PLUS:
2582 case NL80211_CHAN_HT40MINUS:
2583 cfg80211_chandef_create(chandef, chandef->chan,
2584 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002585 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002586 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2587 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2588 NL_SET_ERR_MSG_ATTR(extack,
2589 attrs[NL80211_ATTR_CENTER_FREQ1],
2590 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002591 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002592 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002593 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002594 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2595 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2596 NL_SET_ERR_MSG_ATTR(extack,
2597 attrs[NL80211_ATTR_CENTER_FREQ2],
2598 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002599 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002600 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002601 break;
2602 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002603 NL_SET_ERR_MSG_ATTR(extack,
2604 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2605 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002606 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002607 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002608 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002609 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002610 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2611 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002612 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002613 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2614 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002615 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002616 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002617 }
2618
Johannes Berg49f9cf02018-10-01 11:55:09 +02002619 if (!cfg80211_chandef_valid(chandef)) {
2620 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002621 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002622 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002623
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002624 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002625 IEEE80211_CHAN_DISABLED)) {
2626 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002627 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002628 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002629
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002630 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2631 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002632 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2633 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002634 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002635 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002636
Johannes Berg683b6d32012-11-08 21:25:48 +01002637 return 0;
2638}
2639
Johannes Bergf444de02010-05-05 15:25:02 +02002640static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002641 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002642 struct genl_info *info)
2643{
Johannes Berg683b6d32012-11-08 21:25:48 +01002644 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002645 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002646 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002647 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002648
Jouni Malinene16821b2014-04-28 11:22:08 +03002649 if (dev)
2650 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002651 if (!nl80211_can_set_dev_channel(wdev))
2652 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002653 if (wdev)
2654 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002655
Johannes Berg683b6d32012-11-08 21:25:48 +01002656 result = nl80211_parse_chandef(rdev, info, &chandef);
2657 if (result)
2658 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002659
Johannes Berge8c9bd52012-06-06 08:18:22 +02002660 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002661 case NL80211_IFTYPE_AP:
2662 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002663 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2664 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002665 result = -EINVAL;
2666 break;
2667 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002668 if (wdev->beacon_interval) {
2669 if (!dev || !rdev->ops->set_ap_chanwidth ||
2670 !(rdev->wiphy.features &
2671 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2672 result = -EBUSY;
2673 break;
2674 }
2675
2676 /* Only allow dynamic channel width changes */
2677 if (chandef.chan != wdev->preset_chandef.chan) {
2678 result = -EBUSY;
2679 break;
2680 }
2681 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2682 if (result)
2683 break;
2684 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002685 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002686 result = 0;
2687 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002688 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002689 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002690 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002691 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002692 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002693 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002694 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002695 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002696 }
Johannes Bergf444de02010-05-05 15:25:02 +02002697
2698 return result;
2699}
2700
2701static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2702{
Johannes Berg4c476992010-10-04 21:36:35 +02002703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2704 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002705
Jouni Malinene16821b2014-04-28 11:22:08 +03002706 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002707}
2708
Bill Jordane8347eb2010-10-01 13:54:28 -04002709static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2710{
Johannes Berg43b19952010-10-07 13:10:30 +02002711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2712 struct net_device *dev = info->user_ptr[1];
2713 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002714 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002715
2716 if (!info->attrs[NL80211_ATTR_MAC])
2717 return -EINVAL;
2718
Johannes Berg43b19952010-10-07 13:10:30 +02002719 if (netif_running(dev))
2720 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002721
Johannes Berg43b19952010-10-07 13:10:30 +02002722 if (!rdev->ops->set_wds_peer)
2723 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002724
Johannes Berg43b19952010-10-07 13:10:30 +02002725 if (wdev->iftype != NL80211_IFTYPE_WDS)
2726 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002727
2728 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002729 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002730}
2731
Johannes Berg55682962007-09-20 13:09:35 -04002732static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2733{
2734 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002735 struct net_device *netdev = NULL;
2736 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002737 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002738 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002739 u32 changed;
2740 u8 retry_short = 0, retry_long = 0;
2741 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002742 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002743 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002744
Johannes Berg5fe231e2013-05-08 21:45:15 +02002745 ASSERT_RTNL();
2746
Johannes Bergf444de02010-05-05 15:25:02 +02002747 /*
2748 * Try to find the wiphy and netdev. Normally this
2749 * function shouldn't need the netdev, but this is
2750 * done for backward compatibility -- previously
2751 * setting the channel was done per wiphy, but now
2752 * it is per netdev. Previous userland like hostapd
2753 * also passed a netdev to set_wiphy, so that it is
2754 * possible to let that go to the right netdev!
2755 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002756
Johannes Bergf444de02010-05-05 15:25:02 +02002757 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2758 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2759
Ying Xue7f2b8562014-01-15 10:23:45 +08002760 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002761 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002762 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002763 else
Johannes Bergf444de02010-05-05 15:25:02 +02002764 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002765 }
2766
Johannes Bergf444de02010-05-05 15:25:02 +02002767 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002768 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2769 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002770 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002771 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002772 wdev = NULL;
2773 netdev = NULL;
2774 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002775 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002776 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002777
2778 /*
2779 * end workaround code, by now the rdev is available
2780 * and locked, and wdev may or may not be NULL.
2781 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002782
2783 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002784 result = cfg80211_dev_rename(
2785 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002786
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002787 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002788 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002789
Jouni Malinen31888482008-10-30 16:59:24 +02002790 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2791 struct ieee80211_txq_params txq_params;
2792 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2793
Ying Xue7f2b8562014-01-15 10:23:45 +08002794 if (!rdev->ops->set_txq_params)
2795 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002796
Ying Xue7f2b8562014-01-15 10:23:45 +08002797 if (!netdev)
2798 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002799
Johannes Berg133a3ff2011-11-03 14:50:13 +01002800 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002801 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2802 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002803
Ying Xue7f2b8562014-01-15 10:23:45 +08002804 if (!netif_running(netdev))
2805 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002806
Jouni Malinen31888482008-10-30 16:59:24 +02002807 nla_for_each_nested(nl_txq_params,
2808 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2809 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02002810 result = nla_parse_nested_deprecated(tb,
2811 NL80211_TXQ_ATTR_MAX,
2812 nl_txq_params,
2813 txq_params_policy,
2814 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002815 if (result)
2816 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002817 result = parse_txq_params(tb, &txq_params);
2818 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002819 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002820
Hila Gonene35e4d22012-06-27 17:19:42 +03002821 result = rdev_set_txq_params(rdev, netdev,
2822 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002823 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002824 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002825 }
2826 }
2827
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002828 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002829 result = __nl80211_set_channel(
2830 rdev,
2831 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2832 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002833 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002834 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002835 }
2836
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002837 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002838 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002839 enum nl80211_tx_power_setting type;
2840 int idx, mbm = 0;
2841
Johannes Bergc8442112012-10-24 10:17:18 +02002842 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2843 txp_wdev = NULL;
2844
Ying Xue7f2b8562014-01-15 10:23:45 +08002845 if (!rdev->ops->set_tx_power)
2846 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002847
2848 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2849 type = nla_get_u32(info->attrs[idx]);
2850
2851 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002852 (type != NL80211_TX_POWER_AUTOMATIC))
2853 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002854
2855 if (type != NL80211_TX_POWER_AUTOMATIC) {
2856 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2857 mbm = nla_get_u32(info->attrs[idx]);
2858 }
2859
Johannes Bergc8442112012-10-24 10:17:18 +02002860 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002861 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002862 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002863 }
2864
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002865 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2866 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2867 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002868
Bruno Randolf7f531e02010-12-16 11:30:22 +09002869 if ((!rdev->wiphy.available_antennas_tx &&
2870 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002871 !rdev->ops->set_antenna)
2872 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002873
2874 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2875 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2876
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002877 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002878 * available antenna masks, except for the "all" mask */
2879 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002880 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2881 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002882
Bruno Randolf7f531e02010-12-16 11:30:22 +09002883 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2884 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002885
Hila Gonene35e4d22012-06-27 17:19:42 +03002886 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002887 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002888 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002889 }
2890
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002891 changed = 0;
2892
2893 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2894 retry_short = nla_get_u8(
2895 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002896
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002897 changed |= WIPHY_PARAM_RETRY_SHORT;
2898 }
2899
2900 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2901 retry_long = nla_get_u8(
2902 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002903
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002904 changed |= WIPHY_PARAM_RETRY_LONG;
2905 }
2906
2907 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2908 frag_threshold = nla_get_u32(
2909 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002910 if (frag_threshold < 256)
2911 return -EINVAL;
2912
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002913 if (frag_threshold != (u32) -1) {
2914 /*
2915 * Fragments (apart from the last one) are required to
2916 * have even length. Make the fragmentation code
2917 * simpler by stripping LSB should someone try to use
2918 * odd threshold value.
2919 */
2920 frag_threshold &= ~0x1;
2921 }
2922 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2923 }
2924
2925 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2926 rts_threshold = nla_get_u32(
2927 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2928 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2929 }
2930
Lukáš Turek81077e82009-12-21 22:50:47 +01002931 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002932 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2933 return -EINVAL;
2934
Lukáš Turek81077e82009-12-21 22:50:47 +01002935 coverage_class = nla_get_u8(
2936 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2937 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2938 }
2939
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002940 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2941 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2942 return -EOPNOTSUPP;
2943
2944 changed |= WIPHY_PARAM_DYN_ACK;
2945 }
2946
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002947 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2948 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2949 NL80211_EXT_FEATURE_TXQS))
2950 return -EOPNOTSUPP;
2951 txq_limit = nla_get_u32(
2952 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2953 changed |= WIPHY_PARAM_TXQ_LIMIT;
2954 }
2955
2956 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2957 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2958 NL80211_EXT_FEATURE_TXQS))
2959 return -EOPNOTSUPP;
2960 txq_memory_limit = nla_get_u32(
2961 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2962 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2963 }
2964
2965 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2966 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2967 NL80211_EXT_FEATURE_TXQS))
2968 return -EOPNOTSUPP;
2969 txq_quantum = nla_get_u32(
2970 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2971 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2972 }
2973
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002974 if (changed) {
2975 u8 old_retry_short, old_retry_long;
2976 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002977 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002978 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002979
Ying Xue7f2b8562014-01-15 10:23:45 +08002980 if (!rdev->ops->set_wiphy_params)
2981 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002982
2983 old_retry_short = rdev->wiphy.retry_short;
2984 old_retry_long = rdev->wiphy.retry_long;
2985 old_frag_threshold = rdev->wiphy.frag_threshold;
2986 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002987 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002988 old_txq_limit = rdev->wiphy.txq_limit;
2989 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2990 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002991
2992 if (changed & WIPHY_PARAM_RETRY_SHORT)
2993 rdev->wiphy.retry_short = retry_short;
2994 if (changed & WIPHY_PARAM_RETRY_LONG)
2995 rdev->wiphy.retry_long = retry_long;
2996 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2997 rdev->wiphy.frag_threshold = frag_threshold;
2998 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2999 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003000 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3001 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003002 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3003 rdev->wiphy.txq_limit = txq_limit;
3004 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3005 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3006 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3007 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003008
Hila Gonene35e4d22012-06-27 17:19:42 +03003009 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003010 if (result) {
3011 rdev->wiphy.retry_short = old_retry_short;
3012 rdev->wiphy.retry_long = old_retry_long;
3013 rdev->wiphy.frag_threshold = old_frag_threshold;
3014 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003015 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003016 rdev->wiphy.txq_limit = old_txq_limit;
3017 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3018 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003019 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003020 }
3021 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003022 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003023}
3024
Johannes Berg683b6d32012-11-08 21:25:48 +01003025static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003026 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003027{
Johannes Berg601555c2014-11-27 17:26:56 +01003028 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3029 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003030
Johannes Berg683b6d32012-11-08 21:25:48 +01003031 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3032 chandef->chan->center_freq))
3033 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003034 switch (chandef->width) {
3035 case NL80211_CHAN_WIDTH_20_NOHT:
3036 case NL80211_CHAN_WIDTH_20:
3037 case NL80211_CHAN_WIDTH_40:
3038 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3039 cfg80211_get_chandef_type(chandef)))
3040 return -ENOBUFS;
3041 break;
3042 default:
3043 break;
3044 }
3045 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3046 return -ENOBUFS;
3047 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3048 return -ENOBUFS;
3049 if (chandef->center_freq2 &&
3050 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003051 return -ENOBUFS;
3052 return 0;
3053}
3054
Eric W. Biederman15e47302012-09-07 20:12:54 +00003055static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003056 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003057 struct wireless_dev *wdev,
3058 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003059{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003060 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003061 void *hdr;
3062
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003063 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3064 cmd != NL80211_CMD_DEL_INTERFACE &&
3065 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003066
3067 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003068 if (!hdr)
3069 return -1;
3070
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003071 if (dev &&
3072 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003073 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003074 goto nla_put_failure;
3075
3076 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3077 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003078 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3079 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003080 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003081 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3082 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003083 (cfg80211_rdev_list_generation << 2)) ||
3084 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003085 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003086
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003087 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003088 int ret;
3089 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003090
Johannes Berg683b6d32012-11-08 21:25:48 +01003091 ret = rdev_get_channel(rdev, wdev, &chandef);
3092 if (ret == 0) {
3093 if (nl80211_send_chandef(msg, &chandef))
3094 goto nla_put_failure;
3095 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003096 }
3097
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003098 if (rdev->ops->get_tx_power) {
3099 int dbm, ret;
3100
3101 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3102 if (ret == 0 &&
3103 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3104 DBM_TO_MBM(dbm)))
3105 goto nla_put_failure;
3106 }
3107
Johannes Berg44905262017-10-17 21:56:01 +02003108 wdev_lock(wdev);
3109 switch (wdev->iftype) {
3110 case NL80211_IFTYPE_AP:
3111 if (wdev->ssid_len &&
3112 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003113 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003114 break;
3115 case NL80211_IFTYPE_STATION:
3116 case NL80211_IFTYPE_P2P_CLIENT:
3117 case NL80211_IFTYPE_ADHOC: {
3118 const u8 *ssid_ie;
3119 if (!wdev->current_bss)
3120 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003121 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003122 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3123 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003124 if (ssid_ie &&
3125 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3126 goto nla_put_failure_rcu_locked;
3127 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003128 break;
3129 }
3130 default:
3131 /* nothing */
3132 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003133 }
Johannes Berg44905262017-10-17 21:56:01 +02003134 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003135
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003136 if (rdev->ops->get_txq_stats) {
3137 struct cfg80211_txq_stats txqstats = {};
3138 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3139
3140 if (ret == 0 &&
3141 !nl80211_put_txq_stats(msg, &txqstats,
3142 NL80211_ATTR_TXQ_STATS))
3143 goto nla_put_failure;
3144 }
3145
Johannes Berg053c0952015-01-16 22:09:00 +01003146 genlmsg_end(msg, hdr);
3147 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003148
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003149 nla_put_failure_rcu_locked:
3150 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003151 nla_put_failure_locked:
3152 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003153 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003154 genlmsg_cancel(msg, hdr);
3155 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003156}
3157
3158static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3159{
3160 int wp_idx = 0;
3161 int if_idx = 0;
3162 int wp_start = cb->args[0];
3163 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003164 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003165 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003166 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003167 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003168
Johannes Berg5fe231e2013-05-08 21:45:15 +02003169 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003170 if (!cb->args[2]) {
3171 struct nl80211_dump_wiphy_state state = {
3172 .filter_wiphy = -1,
3173 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003174
3175 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3176 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003177 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003178
3179 filter_wiphy = state.filter_wiphy;
3180
3181 /*
3182 * if filtering, set cb->args[2] to +1 since 0 is the default
3183 * value needed to determine that parsing is necessary.
3184 */
3185 if (filter_wiphy >= 0)
3186 cb->args[2] = filter_wiphy + 1;
3187 else
3188 cb->args[2] = -1;
3189 } else if (cb->args[2] > 0) {
3190 filter_wiphy = cb->args[2] - 1;
3191 }
3192
Johannes Bergf5ea9122009-08-07 16:17:38 +02003193 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3194 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003195 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003196 if (wp_idx < wp_start) {
3197 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003198 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003199 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003200
3201 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3202 continue;
3203
Johannes Berg55682962007-09-20 13:09:35 -04003204 if_idx = 0;
3205
Johannes Berg53873f12016-05-03 16:52:04 +03003206 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003207 if (if_idx < if_start) {
3208 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003209 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003210 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003211 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003212 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003213 rdev, wdev,
3214 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003215 goto out;
3216 }
3217 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003218 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003219
3220 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003221 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003222 out:
Johannes Berg55682962007-09-20 13:09:35 -04003223 cb->args[0] = wp_idx;
3224 cb->args[1] = if_idx;
3225
Johannes Bergea90e0d2017-03-15 14:26:04 +01003226 ret = skb->len;
3227 out_unlock:
3228 rtnl_unlock();
3229
3230 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003231}
3232
3233static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3234{
3235 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003237 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003238
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003240 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003241 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003242
Eric W. Biederman15e47302012-09-07 20:12:54 +00003243 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003244 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003245 nlmsg_free(msg);
3246 return -ENOBUFS;
3247 }
Johannes Berg55682962007-09-20 13:09:35 -04003248
Johannes Berg134e6372009-07-10 09:51:34 +00003249 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003250}
3251
Michael Wu66f7ac52008-01-31 19:48:22 +01003252static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3253 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3254 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3255 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3256 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3257 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003258 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003259};
3260
3261static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3262{
3263 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3264 int flag;
3265
3266 *mntrflags = 0;
3267
3268 if (!nla)
3269 return -EINVAL;
3270
Johannes Berg8cb08172019-04-26 14:07:28 +02003271 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003272 return -EINVAL;
3273
3274 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3275 if (flags[flag])
3276 *mntrflags |= (1<<flag);
3277
Johannes Berg818a9862017-04-12 11:23:28 +02003278 *mntrflags |= MONITOR_FLAG_CHANGED;
3279
Michael Wu66f7ac52008-01-31 19:48:22 +01003280 return 0;
3281}
3282
Johannes Berg1db77592017-04-12 11:36:31 +02003283static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3284 enum nl80211_iftype type,
3285 struct genl_info *info,
3286 struct vif_params *params)
3287{
3288 bool change = false;
3289 int err;
3290
3291 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3292 if (type != NL80211_IFTYPE_MONITOR)
3293 return -EINVAL;
3294
3295 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3296 &params->flags);
3297 if (err)
3298 return err;
3299
3300 change = true;
3301 }
3302
3303 if (params->flags & MONITOR_FLAG_ACTIVE &&
3304 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3305 return -EOPNOTSUPP;
3306
3307 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3308 const u8 *mumimo_groups;
3309 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3310
3311 if (type != NL80211_IFTYPE_MONITOR)
3312 return -EINVAL;
3313
3314 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3315 return -EOPNOTSUPP;
3316
3317 mumimo_groups =
3318 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3319
3320 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003321 if ((mumimo_groups[0] & BIT(0)) ||
3322 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003323 return -EINVAL;
3324
3325 params->vht_mumimo_groups = mumimo_groups;
3326 change = true;
3327 }
3328
3329 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3330 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3331
3332 if (type != NL80211_IFTYPE_MONITOR)
3333 return -EINVAL;
3334
3335 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3336 return -EOPNOTSUPP;
3337
3338 params->vht_mumimo_follow_addr =
3339 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3340 change = true;
3341 }
3342
3343 return change ? 1 : 0;
3344}
3345
Johannes Berg9bc383d2009-11-19 11:55:19 +01003346static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003347 struct net_device *netdev, u8 use_4addr,
3348 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003349{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003350 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003351 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003352 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003353 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003354 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003355
3356 switch (iftype) {
3357 case NL80211_IFTYPE_AP_VLAN:
3358 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3359 return 0;
3360 break;
3361 case NL80211_IFTYPE_STATION:
3362 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3363 return 0;
3364 break;
3365 default:
3366 break;
3367 }
3368
3369 return -EOPNOTSUPP;
3370}
3371
Johannes Berg55682962007-09-20 13:09:35 -04003372static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3373{
Johannes Berg4c476992010-10-04 21:36:35 +02003374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003375 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003376 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003377 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003378 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003379 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003380
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003381 memset(&params, 0, sizeof(params));
3382
Johannes Berg04a773a2009-04-19 21:24:32 +02003383 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003384
Johannes Berg723b0382008-09-16 20:22:09 +02003385 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003386 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003387 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003388 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003389 }
3390
Johannes Berg92ffe052008-09-16 20:39:36 +02003391 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003392 struct wireless_dev *wdev = dev->ieee80211_ptr;
3393
Johannes Berg4c476992010-10-04 21:36:35 +02003394 if (ntype != NL80211_IFTYPE_MESH_POINT)
3395 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003396 if (netif_running(dev))
3397 return -EBUSY;
3398
3399 wdev_lock(wdev);
3400 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3401 IEEE80211_MAX_MESH_ID_LEN);
3402 wdev->mesh_id_up_len =
3403 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3404 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3405 wdev->mesh_id_up_len);
3406 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003407 }
3408
Felix Fietkau8b787642009-11-10 18:53:10 +01003409 if (info->attrs[NL80211_ATTR_4ADDR]) {
3410 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3411 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003412 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003413 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003414 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003415 } else {
3416 params.use_4addr = -1;
3417 }
3418
Johannes Berg1db77592017-04-12 11:36:31 +02003419 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3420 if (err < 0)
3421 return err;
3422 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003423 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003424
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003425 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003426 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003427 else
3428 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003429
Johannes Berg9bc383d2009-11-19 11:55:19 +01003430 if (!err && params.use_4addr != -1)
3431 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3432
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003433 if (change && !err) {
3434 struct wireless_dev *wdev = dev->ieee80211_ptr;
3435
3436 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3437 }
3438
Johannes Berg55682962007-09-20 13:09:35 -04003439 return err;
3440}
3441
3442static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3443{
Johannes Berg4c476992010-10-04 21:36:35 +02003444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003445 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003446 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003447 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003448 int err;
3449 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3450
Johannes Berg78f22b62014-03-24 17:57:27 +01003451 /* to avoid failing a new interface creation due to pending removal */
3452 cfg80211_destroy_ifaces(rdev);
3453
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003454 memset(&params, 0, sizeof(params));
3455
Johannes Berg55682962007-09-20 13:09:35 -04003456 if (!info->attrs[NL80211_ATTR_IFNAME])
3457 return -EINVAL;
3458
Johannes Bergab0d76f2018-10-02 10:00:07 +02003459 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003460 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003461
Johannes Berg79c97e92009-07-07 03:56:12 +02003462 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003463 !(rdev->wiphy.interface_modes & (1 << type)))
3464 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003465
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003466 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003467 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3468 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003469 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3470 ETH_ALEN);
3471 if (!is_valid_ether_addr(params.macaddr))
3472 return -EADDRNOTAVAIL;
3473 }
3474
Johannes Berg9bc383d2009-11-19 11:55:19 +01003475 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003476 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003477 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003478 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003479 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003480 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003481
Johannes Berg1db77592017-04-12 11:36:31 +02003482 err = nl80211_parse_mon_options(rdev, type, info, &params);
3483 if (err < 0)
3484 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003485
Johannes Berga18c7192015-02-24 10:56:42 +01003486 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3487 if (!msg)
3488 return -ENOMEM;
3489
Hila Gonene35e4d22012-06-27 17:19:42 +03003490 wdev = rdev_add_virtual_intf(rdev,
3491 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003492 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003493 if (WARN_ON(!wdev)) {
3494 nlmsg_free(msg);
3495 return -EPROTO;
3496 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003497 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003498 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003499 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003500
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003501 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003502 wdev->owner_nlportid = info->snd_portid;
3503
Johannes Berg98104fde2012-06-16 00:19:54 +02003504 switch (type) {
3505 case NL80211_IFTYPE_MESH_POINT:
3506 if (!info->attrs[NL80211_ATTR_MESH_ID])
3507 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003508 wdev_lock(wdev);
3509 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3510 IEEE80211_MAX_MESH_ID_LEN);
3511 wdev->mesh_id_up_len =
3512 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3513 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3514 wdev->mesh_id_up_len);
3515 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003516 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003517 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003518 case NL80211_IFTYPE_P2P_DEVICE:
3519 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003520 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003521 * through the netdev notifier and must be added here
3522 */
Johannes Berge4d42162018-09-13 14:12:03 +02003523 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003524 break;
3525 default:
3526 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003527 }
3528
Eric W. Biederman15e47302012-09-07 20:12:54 +00003529 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003530 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003531 nlmsg_free(msg);
3532 return -ENOBUFS;
3533 }
3534
3535 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003536}
3537
3538static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3539{
Johannes Berg4c476992010-10-04 21:36:35 +02003540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003541 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003542
Johannes Berg4c476992010-10-04 21:36:35 +02003543 if (!rdev->ops->del_virtual_intf)
3544 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003545
Johannes Berg84efbb82012-06-16 00:00:26 +02003546 /*
3547 * If we remove a wireless device without a netdev then clear
3548 * user_ptr[1] so that nl80211_post_doit won't dereference it
3549 * to check if it needs to do dev_put(). Otherwise it crashes
3550 * since the wdev has been freed, unlike with a netdev where
3551 * we need the dev_put() for the netdev to really be freed.
3552 */
3553 if (!wdev->netdev)
3554 info->user_ptr[1] = NULL;
3555
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003556 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003557}
3558
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003559static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3560{
3561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3562 struct net_device *dev = info->user_ptr[1];
3563 u16 noack_map;
3564
3565 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3566 return -EINVAL;
3567
3568 if (!rdev->ops->set_noack_map)
3569 return -EOPNOTSUPP;
3570
3571 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3572
Hila Gonene35e4d22012-06-27 17:19:42 +03003573 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003574}
3575
Johannes Berg41ade002007-12-19 02:03:29 +01003576struct get_key_cookie {
3577 struct sk_buff *msg;
3578 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003579 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003580};
3581
3582static void get_key_callback(void *c, struct key_params *params)
3583{
Johannes Bergb9454e82009-07-08 13:29:08 +02003584 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003585 struct get_key_cookie *cookie = c;
3586
David S. Miller9360ffd2012-03-29 04:41:26 -04003587 if ((params->key &&
3588 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3589 params->key_len, params->key)) ||
3590 (params->seq &&
3591 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3592 params->seq_len, params->seq)) ||
3593 (params->cipher &&
3594 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3595 params->cipher)))
3596 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003597
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003598 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003599 if (!key)
3600 goto nla_put_failure;
3601
David S. Miller9360ffd2012-03-29 04:41:26 -04003602 if ((params->key &&
3603 nla_put(cookie->msg, NL80211_KEY_DATA,
3604 params->key_len, params->key)) ||
3605 (params->seq &&
3606 nla_put(cookie->msg, NL80211_KEY_SEQ,
3607 params->seq_len, params->seq)) ||
3608 (params->cipher &&
3609 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3610 params->cipher)))
3611 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003612
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003613 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003614 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003615
3616 nla_nest_end(cookie->msg, key);
3617
Johannes Berg41ade002007-12-19 02:03:29 +01003618 return;
3619 nla_put_failure:
3620 cookie->error = 1;
3621}
3622
3623static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3624{
Johannes Berg4c476992010-10-04 21:36:35 +02003625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003626 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003627 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003628 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003629 const u8 *mac_addr = NULL;
3630 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003631 struct get_key_cookie cookie = {
3632 .error = 0,
3633 };
3634 void *hdr;
3635 struct sk_buff *msg;
3636
3637 if (info->attrs[NL80211_ATTR_KEY_IDX])
3638 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3639
Johannes Berg41ade002007-12-19 02:03:29 +01003640 if (info->attrs[NL80211_ATTR_MAC])
3641 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3642
Johannes Berge31b8212010-10-05 19:39:30 +02003643 pairwise = !!mac_addr;
3644 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3645 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003646
Johannes Berge31b8212010-10-05 19:39:30 +02003647 if (kt != NL80211_KEYTYPE_GROUP &&
3648 kt != NL80211_KEYTYPE_PAIRWISE)
3649 return -EINVAL;
3650 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3651 }
3652
Johannes Berg4c476992010-10-04 21:36:35 +02003653 if (!rdev->ops->get_key)
3654 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003655
Johannes Berg0fa7b392015-01-23 11:10:12 +01003656 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3657 return -ENOENT;
3658
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003659 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003660 if (!msg)
3661 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003662
Eric W. Biederman15e47302012-09-07 20:12:54 +00003663 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003664 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003665 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003666 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003667
3668 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003669 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003670
David S. Miller9360ffd2012-03-29 04:41:26 -04003671 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3672 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3673 goto nla_put_failure;
3674 if (mac_addr &&
3675 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3676 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003677
Hila Gonene35e4d22012-06-27 17:19:42 +03003678 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3679 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003680
3681 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003682 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003683
3684 if (cookie.error)
3685 goto nla_put_failure;
3686
3687 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003688 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003689
3690 nla_put_failure:
3691 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003692 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003693 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003694 return err;
3695}
3696
3697static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3698{
Johannes Berg4c476992010-10-04 21:36:35 +02003699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003700 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003701 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003702 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003703
Johannes Bergb9454e82009-07-08 13:29:08 +02003704 err = nl80211_parse_key(info, &key);
3705 if (err)
3706 return err;
3707
3708 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003709 return -EINVAL;
3710
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003711 /* Only support setting default key and
3712 * Extended Key ID action NL80211_KEY_SET_TX.
3713 */
3714 if (!key.def && !key.defmgmt &&
3715 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01003716 return -EINVAL;
3717
Johannes Bergfffd0932009-07-08 14:22:54 +02003718 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003719
3720 if (key.def) {
3721 if (!rdev->ops->set_default_key) {
3722 err = -EOPNOTSUPP;
3723 goto out;
3724 }
3725
3726 err = nl80211_key_allowed(dev->ieee80211_ptr);
3727 if (err)
3728 goto out;
3729
Hila Gonene35e4d22012-06-27 17:19:42 +03003730 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003731 key.def_uni, key.def_multi);
3732
3733 if (err)
3734 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003735
Johannes Berg3d23e342009-09-29 23:27:28 +02003736#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003737 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003738#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003739 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003740 if (key.def_uni || !key.def_multi) {
3741 err = -EINVAL;
3742 goto out;
3743 }
3744
3745 if (!rdev->ops->set_default_mgmt_key) {
3746 err = -EOPNOTSUPP;
3747 goto out;
3748 }
3749
3750 err = nl80211_key_allowed(dev->ieee80211_ptr);
3751 if (err)
3752 goto out;
3753
Hila Gonene35e4d22012-06-27 17:19:42 +03003754 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003755 if (err)
3756 goto out;
3757
3758#ifdef CONFIG_CFG80211_WEXT
3759 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3760#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003761 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3762 wiphy_ext_feature_isset(&rdev->wiphy,
3763 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3764 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003765
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003766 if (info->attrs[NL80211_ATTR_MAC])
3767 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3768
3769 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3770 err = -EINVAL;
3771 goto out;
3772 }
3773
3774 err = rdev_add_key(rdev, dev, key.idx,
3775 NL80211_KEYTYPE_PAIRWISE,
3776 mac_addr, &key.p);
3777 } else {
3778 err = -EINVAL;
3779 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003780 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003781 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003782
Johannes Berg41ade002007-12-19 02:03:29 +01003783 return err;
3784}
3785
3786static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3787{
Johannes Berg4c476992010-10-04 21:36:35 +02003788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003789 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003790 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003791 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003792 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003793
Johannes Bergb9454e82009-07-08 13:29:08 +02003794 err = nl80211_parse_key(info, &key);
3795 if (err)
3796 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003797
Johannes Bergb9454e82009-07-08 13:29:08 +02003798 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003799 return -EINVAL;
3800
Johannes Berg41ade002007-12-19 02:03:29 +01003801 if (info->attrs[NL80211_ATTR_MAC])
3802 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3803
Johannes Berge31b8212010-10-05 19:39:30 +02003804 if (key.type == -1) {
3805 if (mac_addr)
3806 key.type = NL80211_KEYTYPE_PAIRWISE;
3807 else
3808 key.type = NL80211_KEYTYPE_GROUP;
3809 }
3810
3811 /* for now */
3812 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3813 key.type != NL80211_KEYTYPE_GROUP)
3814 return -EINVAL;
3815
Johannes Berg4c476992010-10-04 21:36:35 +02003816 if (!rdev->ops->add_key)
3817 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003818
Johannes Berge31b8212010-10-05 19:39:30 +02003819 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3820 key.type == NL80211_KEYTYPE_PAIRWISE,
3821 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003822 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003823
3824 wdev_lock(dev->ieee80211_ptr);
3825 err = nl80211_key_allowed(dev->ieee80211_ptr);
3826 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003827 err = rdev_add_key(rdev, dev, key.idx,
3828 key.type == NL80211_KEYTYPE_PAIRWISE,
3829 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003830 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003831
Johannes Berg41ade002007-12-19 02:03:29 +01003832 return err;
3833}
3834
3835static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3836{
Johannes Berg4c476992010-10-04 21:36:35 +02003837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003838 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003839 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003840 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003841 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003842
Johannes Bergb9454e82009-07-08 13:29:08 +02003843 err = nl80211_parse_key(info, &key);
3844 if (err)
3845 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003846
3847 if (info->attrs[NL80211_ATTR_MAC])
3848 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3849
Johannes Berge31b8212010-10-05 19:39:30 +02003850 if (key.type == -1) {
3851 if (mac_addr)
3852 key.type = NL80211_KEYTYPE_PAIRWISE;
3853 else
3854 key.type = NL80211_KEYTYPE_GROUP;
3855 }
3856
3857 /* for now */
3858 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3859 key.type != NL80211_KEYTYPE_GROUP)
3860 return -EINVAL;
3861
Johannes Berg4c476992010-10-04 21:36:35 +02003862 if (!rdev->ops->del_key)
3863 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003864
Johannes Bergfffd0932009-07-08 14:22:54 +02003865 wdev_lock(dev->ieee80211_ptr);
3866 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003867
Johannes Berg0fa7b392015-01-23 11:10:12 +01003868 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003869 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3870 err = -ENOENT;
3871
Johannes Bergfffd0932009-07-08 14:22:54 +02003872 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003873 err = rdev_del_key(rdev, dev, key.idx,
3874 key.type == NL80211_KEYTYPE_PAIRWISE,
3875 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003876
Johannes Berg3d23e342009-09-29 23:27:28 +02003877#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003878 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003879 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003880 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003881 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003882 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3883 }
3884#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003885 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003886
Johannes Berg41ade002007-12-19 02:03:29 +01003887 return err;
3888}
3889
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303890/* This function returns an error or the number of nested attributes */
3891static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3892{
3893 struct nlattr *attr;
3894 int n_entries = 0, tmp;
3895
3896 nla_for_each_nested(attr, nl_attr, tmp) {
3897 if (nla_len(attr) != ETH_ALEN)
3898 return -EINVAL;
3899
3900 n_entries++;
3901 }
3902
3903 return n_entries;
3904}
3905
3906/*
3907 * This function parses ACL information and allocates memory for ACL data.
3908 * On successful return, the calling function is responsible to free the
3909 * ACL buffer returned by this function.
3910 */
3911static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3912 struct genl_info *info)
3913{
3914 enum nl80211_acl_policy acl_policy;
3915 struct nlattr *attr;
3916 struct cfg80211_acl_data *acl;
3917 int i = 0, n_entries, tmp;
3918
3919 if (!wiphy->max_acl_mac_addrs)
3920 return ERR_PTR(-EOPNOTSUPP);
3921
3922 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3923 return ERR_PTR(-EINVAL);
3924
3925 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3926 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3927 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3928 return ERR_PTR(-EINVAL);
3929
3930 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3931 return ERR_PTR(-EINVAL);
3932
3933 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3934 if (n_entries < 0)
3935 return ERR_PTR(n_entries);
3936
3937 if (n_entries > wiphy->max_acl_mac_addrs)
3938 return ERR_PTR(-ENOTSUPP);
3939
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05003940 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303941 if (!acl)
3942 return ERR_PTR(-ENOMEM);
3943
3944 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3945 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3946 i++;
3947 }
3948
3949 acl->n_acl_entries = n_entries;
3950 acl->acl_policy = acl_policy;
3951
3952 return acl;
3953}
3954
3955static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3956{
3957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3958 struct net_device *dev = info->user_ptr[1];
3959 struct cfg80211_acl_data *acl;
3960 int err;
3961
3962 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3964 return -EOPNOTSUPP;
3965
3966 if (!dev->ieee80211_ptr->beacon_interval)
3967 return -EINVAL;
3968
3969 acl = parse_acl_data(&rdev->wiphy, info);
3970 if (IS_ERR(acl))
3971 return PTR_ERR(acl);
3972
3973 err = rdev_set_mac_acl(rdev, dev, acl);
3974
3975 kfree(acl);
3976
3977 return err;
3978}
3979
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303980static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3981 u8 *rates, u8 rates_len)
3982{
3983 u8 i;
3984 u32 mask = 0;
3985
3986 for (i = 0; i < rates_len; i++) {
3987 int rate = (rates[i] & 0x7f) * 5;
3988 int ridx;
3989
3990 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3991 struct ieee80211_rate *srate =
3992 &sband->bitrates[ridx];
3993 if (rate == srate->bitrate) {
3994 mask |= 1 << ridx;
3995 break;
3996 }
3997 }
3998 if (ridx == sband->n_bitrates)
3999 return 0; /* rate not found */
4000 }
4001
4002 return mask;
4003}
4004
4005static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4006 u8 *rates, u8 rates_len,
4007 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4008{
4009 u8 i;
4010
4011 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4012
4013 for (i = 0; i < rates_len; i++) {
4014 int ridx, rbit;
4015
4016 ridx = rates[i] / 8;
4017 rbit = BIT(rates[i] % 8);
4018
4019 /* check validity */
4020 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4021 return false;
4022
4023 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004024 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304025 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4026 mcs[ridx] |= rbit;
4027 else
4028 return false;
4029 }
4030
4031 return true;
4032}
4033
4034static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4035{
4036 u16 mcs_mask = 0;
4037
4038 switch (vht_mcs_map) {
4039 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4040 break;
4041 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4042 mcs_mask = 0x00FF;
4043 break;
4044 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4045 mcs_mask = 0x01FF;
4046 break;
4047 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4048 mcs_mask = 0x03FF;
4049 break;
4050 default:
4051 break;
4052 }
4053
4054 return mcs_mask;
4055}
4056
4057static void vht_build_mcs_mask(u16 vht_mcs_map,
4058 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4059{
4060 u8 nss;
4061
4062 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4063 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4064 vht_mcs_map >>= 2;
4065 }
4066}
4067
4068static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4069 struct nl80211_txrate_vht *txrate,
4070 u16 mcs[NL80211_VHT_NSS_MAX])
4071{
4072 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4073 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4074 u8 i;
4075
4076 if (!sband->vht_cap.vht_supported)
4077 return false;
4078
4079 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4080
4081 /* Build vht_mcs_mask from VHT capabilities */
4082 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4083
4084 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4085 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4086 mcs[i] = txrate->mcs[i];
4087 else
4088 return false;
4089 }
4090
4091 return true;
4092}
4093
4094static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4095 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4096 .len = NL80211_MAX_SUPP_RATES },
4097 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4098 .len = NL80211_MAX_SUPP_HT_RATES },
Johannes Berg1a28ed22019-05-28 14:18:07 +02004099 [NL80211_TXRATE_VHT] = { .type = NLA_EXACT_LEN_WARN, .len = sizeof(struct nl80211_txrate_vht)},
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304100 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4101};
4102
4103static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4104 struct cfg80211_bitrate_mask *mask)
4105{
4106 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4108 int rem, i;
4109 struct nlattr *tx_rates;
4110 struct ieee80211_supported_band *sband;
4111 u16 vht_tx_mcs_map;
4112
4113 memset(mask, 0, sizeof(*mask));
4114 /* Default to all rates enabled */
4115 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4116 sband = rdev->wiphy.bands[i];
4117
4118 if (!sband)
4119 continue;
4120
4121 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4122 memcpy(mask->control[i].ht_mcs,
4123 sband->ht_cap.mcs.rx_mask,
4124 sizeof(mask->control[i].ht_mcs));
4125
4126 if (!sband->vht_cap.vht_supported)
4127 continue;
4128
4129 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4130 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4131 }
4132
4133 /* if no rates are given set it back to the defaults */
4134 if (!info->attrs[NL80211_ATTR_TX_RATES])
4135 goto out;
4136
4137 /* The nested attribute uses enum nl80211_band as the index. This maps
4138 * directly to the enum nl80211_band values used in cfg80211.
4139 */
4140 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4141 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4142 enum nl80211_band band = nla_type(tx_rates);
4143 int err;
4144
4145 if (band < 0 || band >= NUM_NL80211_BANDS)
4146 return -EINVAL;
4147 sband = rdev->wiphy.bands[band];
4148 if (sband == NULL)
4149 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004150 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4151 tx_rates,
4152 nl80211_txattr_policy,
4153 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304154 if (err)
4155 return err;
4156 if (tb[NL80211_TXRATE_LEGACY]) {
4157 mask->control[band].legacy = rateset_to_mask(
4158 sband,
4159 nla_data(tb[NL80211_TXRATE_LEGACY]),
4160 nla_len(tb[NL80211_TXRATE_LEGACY]));
4161 if ((mask->control[band].legacy == 0) &&
4162 nla_len(tb[NL80211_TXRATE_LEGACY]))
4163 return -EINVAL;
4164 }
4165 if (tb[NL80211_TXRATE_HT]) {
4166 if (!ht_rateset_to_mask(
4167 sband,
4168 nla_data(tb[NL80211_TXRATE_HT]),
4169 nla_len(tb[NL80211_TXRATE_HT]),
4170 mask->control[band].ht_mcs))
4171 return -EINVAL;
4172 }
4173 if (tb[NL80211_TXRATE_VHT]) {
4174 if (!vht_set_mcs_mask(
4175 sband,
4176 nla_data(tb[NL80211_TXRATE_VHT]),
4177 mask->control[band].vht_mcs))
4178 return -EINVAL;
4179 }
4180 if (tb[NL80211_TXRATE_GI]) {
4181 mask->control[band].gi =
4182 nla_get_u8(tb[NL80211_TXRATE_GI]);
4183 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4184 return -EINVAL;
4185 }
4186
4187 if (mask->control[band].legacy == 0) {
4188 /* don't allow empty legacy rates if HT or VHT
4189 * are not even supported.
4190 */
4191 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4192 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4193 return -EINVAL;
4194
4195 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4196 if (mask->control[band].ht_mcs[i])
4197 goto out;
4198
4199 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4200 if (mask->control[band].vht_mcs[i])
4201 goto out;
4202
4203 /* legacy and mcs rates may not be both empty */
4204 return -EINVAL;
4205 }
4206 }
4207
4208out:
4209 return 0;
4210}
4211
Johannes Berg8564e382016-09-19 09:44:44 +02004212static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4213 enum nl80211_band band,
4214 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304215{
Johannes Berg8564e382016-09-19 09:44:44 +02004216 u32 count_ht, count_vht, i;
4217 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304218
4219 /* Allow only one rate */
4220 if (hweight32(rate) > 1)
4221 return -EINVAL;
4222
4223 count_ht = 0;
4224 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004225 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304226 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004227 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304228 count_ht++;
4229 if (count_ht > 1)
4230 return -EINVAL;
4231 }
4232 if (count_ht && rate)
4233 return -EINVAL;
4234 }
4235
4236 count_vht = 0;
4237 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004238 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304239 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004240 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304241 count_vht++;
4242 if (count_vht > 1)
4243 return -EINVAL;
4244 }
4245 if (count_vht && rate)
4246 return -EINVAL;
4247 }
4248
4249 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4250 return -EINVAL;
4251
Johannes Berg8564e382016-09-19 09:44:44 +02004252 if (rate &&
4253 !wiphy_ext_feature_isset(&rdev->wiphy,
4254 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4255 return -EINVAL;
4256 if (count_ht &&
4257 !wiphy_ext_feature_isset(&rdev->wiphy,
4258 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4259 return -EINVAL;
4260 if (count_vht &&
4261 !wiphy_ext_feature_isset(&rdev->wiphy,
4262 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4263 return -EINVAL;
4264
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304265 return 0;
4266}
4267
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004268static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4269 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004270 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004271{
Johannes Berg88600202012-02-13 15:17:18 +01004272 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004273 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004274
Johannes Berg88600202012-02-13 15:17:18 +01004275 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004276
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004277 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4278 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4279 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004280 if (!bcn->head_len)
4281 return -EINVAL;
4282 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004283 }
4284
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004285 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4286 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4287 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004288 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004289 }
4290
Johannes Berg4c476992010-10-04 21:36:35 +02004291 if (!haveinfo)
4292 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004293
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004294 if (attrs[NL80211_ATTR_IE]) {
4295 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4296 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004297 }
4298
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004299 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004300 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004301 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004302 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004303 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004304 }
4305
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004306 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004307 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004308 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004309 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004310 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004311 }
4312
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004313 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4314 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4315 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004316 }
4317
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004318 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4319 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4320
Johannes Berg8cb08172019-04-26 14:07:28 +02004321 err = nla_parse_nested_deprecated(tb,
4322 NL80211_FTM_RESP_ATTR_MAX,
4323 attrs[NL80211_ATTR_FTM_RESPONDER],
4324 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004325 if (err)
4326 return err;
4327
4328 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4329 wiphy_ext_feature_isset(&rdev->wiphy,
4330 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4331 bcn->ftm_responder = 1;
4332 else
4333 return -EOPNOTSUPP;
4334
4335 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4336 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4337 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4338 }
4339
4340 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4341 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4342 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4343 }
4344 } else {
4345 bcn->ftm_responder = -1;
4346 }
4347
Johannes Berg88600202012-02-13 15:17:18 +01004348 return 0;
4349}
4350
Johannes Berg66cd7942017-02-07 22:40:44 +02004351static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4352 const u8 *rates)
4353{
4354 int i;
4355
4356 if (!rates)
4357 return;
4358
4359 for (i = 0; i < rates[1]; i++) {
4360 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4361 params->ht_required = true;
4362 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4363 params->vht_required = true;
4364 }
4365}
4366
4367/*
4368 * Since the nl80211 API didn't include, from the beginning, attributes about
4369 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4370 * benefit of drivers that rebuild IEs in the firmware.
4371 */
4372static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4373{
4374 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004375 size_t ies_len = bcn->tail_len;
4376 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004377 const u8 *rates;
4378 const u8 *cap;
4379
4380 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4381 nl80211_check_ap_rate_selectors(params, rates);
4382
4383 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4384 nl80211_check_ap_rate_selectors(params, rates);
4385
4386 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4387 if (cap && cap[1] >= sizeof(*params->ht_cap))
4388 params->ht_cap = (void *)(cap + 2);
4389 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4390 if (cap && cap[1] >= sizeof(*params->vht_cap))
4391 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004392 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4393 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4394 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004395}
4396
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004397static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4398 struct cfg80211_ap_settings *params)
4399{
4400 struct wireless_dev *wdev;
4401 bool ret = false;
4402
Johannes Berg53873f12016-05-03 16:52:04 +03004403 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004404 if (wdev->iftype != NL80211_IFTYPE_AP &&
4405 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4406 continue;
4407
Johannes Berg683b6d32012-11-08 21:25:48 +01004408 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004409 continue;
4410
Johannes Berg683b6d32012-11-08 21:25:48 +01004411 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004412 ret = true;
4413 break;
4414 }
4415
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004416 return ret;
4417}
4418
Jouni Malinene39e5b52012-09-30 19:29:39 +03004419static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4420 enum nl80211_auth_type auth_type,
4421 enum nl80211_commands cmd)
4422{
4423 if (auth_type > NL80211_AUTHTYPE_MAX)
4424 return false;
4425
4426 switch (cmd) {
4427 case NL80211_CMD_AUTHENTICATE:
4428 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4429 auth_type == NL80211_AUTHTYPE_SAE)
4430 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004431 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4432 NL80211_EXT_FEATURE_FILS_STA) &&
4433 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4434 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4435 auth_type == NL80211_AUTHTYPE_FILS_PK))
4436 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004437 return true;
4438 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004439 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00004440 !wiphy_ext_feature_isset(&rdev->wiphy,
4441 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02004442 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004443 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004444
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004445 /* FILS with SK PFS or PK not supported yet */
4446 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4447 auth_type == NL80211_AUTHTYPE_FILS_PK)
4448 return false;
4449 if (!wiphy_ext_feature_isset(
4450 &rdev->wiphy,
4451 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4452 auth_type == NL80211_AUTHTYPE_FILS_SK)
4453 return false;
4454 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004455 case NL80211_CMD_START_AP:
4456 /* SAE not supported yet */
4457 if (auth_type == NL80211_AUTHTYPE_SAE)
4458 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004459 /* FILS not supported yet */
4460 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4461 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4462 auth_type == NL80211_AUTHTYPE_FILS_PK)
4463 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004464 return true;
4465 default:
4466 return false;
4467 }
4468}
4469
Johannes Berg88600202012-02-13 15:17:18 +01004470static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4471{
4472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4473 struct net_device *dev = info->user_ptr[1];
4474 struct wireless_dev *wdev = dev->ieee80211_ptr;
4475 struct cfg80211_ap_settings params;
4476 int err;
4477
4478 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4479 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4480 return -EOPNOTSUPP;
4481
4482 if (!rdev->ops->start_ap)
4483 return -EOPNOTSUPP;
4484
4485 if (wdev->beacon_interval)
4486 return -EALREADY;
4487
4488 memset(&params, 0, sizeof(params));
4489
4490 /* these are required for START_AP */
4491 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4492 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4493 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4494 return -EINVAL;
4495
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004496 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004497 if (err)
4498 return err;
4499
4500 params.beacon_interval =
4501 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4502 params.dtim_period =
4503 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4504
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304505 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4506 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004507 if (err)
4508 return err;
4509
4510 /*
4511 * In theory, some of these attributes should be required here
4512 * but since they were not used when the command was originally
4513 * added, keep them optional for old user space programs to let
4514 * them continue to work with drivers that do not need the
4515 * additional information -- drivers must check!
4516 */
4517 if (info->attrs[NL80211_ATTR_SSID]) {
4518 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4519 params.ssid_len =
4520 nla_len(info->attrs[NL80211_ATTR_SSID]);
4521 if (params.ssid_len == 0 ||
4522 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4523 return -EINVAL;
4524 }
4525
Johannes Bergab0d76f2018-10-02 10:00:07 +02004526 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004527 params.hidden_ssid = nla_get_u32(
4528 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004529
4530 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4531
4532 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4533 params.auth_type = nla_get_u32(
4534 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004535 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4536 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004537 return -EINVAL;
4538 } else
4539 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4540
4541 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4542 NL80211_MAX_NR_CIPHER_SUITES);
4543 if (err)
4544 return err;
4545
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304546 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4547 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4548 return -EOPNOTSUPP;
4549 params.inactivity_timeout = nla_get_u16(
4550 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4551 }
4552
Johannes Berg53cabad2012-11-14 15:17:28 +01004553 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4554 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4555 return -EINVAL;
4556 params.p2p_ctwindow =
4557 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004558 if (params.p2p_ctwindow != 0 &&
4559 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4560 return -EINVAL;
4561 }
4562
4563 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4564 u8 tmp;
4565
4566 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4567 return -EINVAL;
4568 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004569 params.p2p_opp_ps = tmp;
4570 if (params.p2p_opp_ps != 0 &&
4571 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4572 return -EINVAL;
4573 }
4574
Johannes Bergaa430da2012-05-16 23:50:18 +02004575 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004576 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4577 if (err)
4578 return err;
4579 } else if (wdev->preset_chandef.chan) {
4580 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004581 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004582 return -EINVAL;
4583
Arik Nemtsov923b3522015-07-08 15:41:44 +03004584 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4585 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004586 return -EINVAL;
4587
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304588 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4589 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4590 if (err)
4591 return err;
4592
Johannes Berg8564e382016-09-19 09:44:44 +02004593 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4594 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304595 if (err)
4596 return err;
4597 }
4598
Eliad Peller18998c32014-09-10 14:07:34 +03004599 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4600 params.smps_mode =
4601 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4602 switch (params.smps_mode) {
4603 case NL80211_SMPS_OFF:
4604 break;
4605 case NL80211_SMPS_STATIC:
4606 if (!(rdev->wiphy.features &
4607 NL80211_FEATURE_STATIC_SMPS))
4608 return -EINVAL;
4609 break;
4610 case NL80211_SMPS_DYNAMIC:
4611 if (!(rdev->wiphy.features &
4612 NL80211_FEATURE_DYNAMIC_SMPS))
4613 return -EINVAL;
4614 break;
4615 default:
4616 return -EINVAL;
4617 }
4618 } else {
4619 params.smps_mode = NL80211_SMPS_OFF;
4620 }
4621
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304622 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4623 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4624 return -EOPNOTSUPP;
4625
Ola Olsson4baf6be2015-10-29 07:04:58 +01004626 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4627 params.acl = parse_acl_data(&rdev->wiphy, info);
4628 if (IS_ERR(params.acl))
4629 return PTR_ERR(params.acl);
4630 }
4631
John Crispina0de1ca32019-05-28 13:49:48 +02004632 params.twt_responder =
4633 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
4634
Johannes Berg66cd7942017-02-07 22:40:44 +02004635 nl80211_calculate_ap_params(&params);
4636
Srinivas Dasarife494372019-01-23 18:06:56 +05304637 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4638 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4639
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004640 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004641 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004642 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004643 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004644 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004645 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004646 wdev->ssid_len = params.ssid_len;
4647 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004648
4649 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4650 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004651 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004652 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304653
4654 kfree(params.acl);
4655
Johannes Berg56d18932011-05-09 18:41:15 +02004656 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004657}
4658
Johannes Berg88600202012-02-13 15:17:18 +01004659static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4660{
4661 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4662 struct net_device *dev = info->user_ptr[1];
4663 struct wireless_dev *wdev = dev->ieee80211_ptr;
4664 struct cfg80211_beacon_data params;
4665 int err;
4666
4667 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4668 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4669 return -EOPNOTSUPP;
4670
4671 if (!rdev->ops->change_beacon)
4672 return -EOPNOTSUPP;
4673
4674 if (!wdev->beacon_interval)
4675 return -EINVAL;
4676
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004677 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004678 if (err)
4679 return err;
4680
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004681 wdev_lock(wdev);
4682 err = rdev_change_beacon(rdev, dev, &params);
4683 wdev_unlock(wdev);
4684
4685 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004686}
4687
4688static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004689{
Johannes Berg4c476992010-10-04 21:36:35 +02004690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4691 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004692
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004693 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004694}
4695
Johannes Berg5727ef12007-12-19 02:03:34 +01004696static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4697 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4698 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4699 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004700 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004701 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004702 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004703};
4704
Johannes Bergeccb8e82009-05-11 21:57:56 +03004705static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004706 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004707 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004708{
4709 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004710 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004711 int flag;
4712
Johannes Bergeccb8e82009-05-11 21:57:56 +03004713 /*
4714 * Try parsing the new attribute first so userspace
4715 * can specify both for older kernels.
4716 */
4717 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4718 if (nla) {
4719 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004720
Johannes Bergeccb8e82009-05-11 21:57:56 +03004721 sta_flags = nla_data(nla);
4722 params->sta_flags_mask = sta_flags->mask;
4723 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004724 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004725 if ((params->sta_flags_mask |
4726 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4727 return -EINVAL;
4728 return 0;
4729 }
4730
4731 /* if present, parse the old attribute */
4732
4733 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004734 if (!nla)
4735 return 0;
4736
Johannes Berg8cb08172019-04-26 14:07:28 +02004737 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004738 return -EINVAL;
4739
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004740 /*
4741 * Only allow certain flags for interface types so that
4742 * other attributes are silently ignored. Remember that
4743 * this is backward compatibility code with old userspace
4744 * and shouldn't be hit in other cases anyway.
4745 */
4746 switch (iftype) {
4747 case NL80211_IFTYPE_AP:
4748 case NL80211_IFTYPE_AP_VLAN:
4749 case NL80211_IFTYPE_P2P_GO:
4750 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4751 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4752 BIT(NL80211_STA_FLAG_WME) |
4753 BIT(NL80211_STA_FLAG_MFP);
4754 break;
4755 case NL80211_IFTYPE_P2P_CLIENT:
4756 case NL80211_IFTYPE_STATION:
4757 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4758 BIT(NL80211_STA_FLAG_TDLS_PEER);
4759 break;
4760 case NL80211_IFTYPE_MESH_POINT:
4761 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4762 BIT(NL80211_STA_FLAG_MFP) |
4763 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004764 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004765 default:
4766 return -EINVAL;
4767 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004768
Johannes Berg3383b5a2012-05-10 20:14:43 +02004769 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4770 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004771 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004772
Johannes Berg3383b5a2012-05-10 20:14:43 +02004773 /* no longer support new API additions in old API */
4774 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4775 return -EINVAL;
4776 }
4777 }
4778
Johannes Berg5727ef12007-12-19 02:03:34 +01004779 return 0;
4780}
4781
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004782bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004783{
4784 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004785 u32 bitrate;
4786 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004787 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004788
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004789 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004790 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004791 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004792
4793 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4794 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004795 /* report 16-bit bitrate only if we can */
4796 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004797 if (bitrate > 0 &&
4798 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4799 return false;
4800 if (bitrate_compat > 0 &&
4801 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4802 return false;
4803
Johannes Bergb51f3be2015-01-15 16:14:02 +01004804 switch (info->bw) {
4805 case RATE_INFO_BW_5:
4806 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4807 break;
4808 case RATE_INFO_BW_10:
4809 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4810 break;
4811 default:
4812 WARN_ON(1);
4813 /* fall through */
4814 case RATE_INFO_BW_20:
4815 rate_flg = 0;
4816 break;
4817 case RATE_INFO_BW_40:
4818 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4819 break;
4820 case RATE_INFO_BW_80:
4821 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4822 break;
4823 case RATE_INFO_BW_160:
4824 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4825 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004826 case RATE_INFO_BW_HE_RU:
4827 rate_flg = 0;
4828 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004829 }
4830
4831 if (rate_flg && nla_put_flag(msg, rate_flg))
4832 return false;
4833
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004834 if (info->flags & RATE_INFO_FLAGS_MCS) {
4835 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4836 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004837 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4838 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4839 return false;
4840 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4841 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4842 return false;
4843 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4844 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004845 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4846 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4847 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004848 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4849 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4850 return false;
4851 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4852 return false;
4853 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4854 return false;
4855 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4856 return false;
4857 if (info->bw == RATE_INFO_BW_HE_RU &&
4858 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4859 info->he_ru_alloc))
4860 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004861 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004862
4863 nla_nest_end(msg, rate);
4864 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004865}
4866
Felix Fietkau119363c2013-04-22 16:29:30 +02004867static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4868 int id)
4869{
4870 void *attr;
4871 int i = 0;
4872
4873 if (!mask)
4874 return true;
4875
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004876 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02004877 if (!attr)
4878 return false;
4879
4880 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4881 if (!(mask & BIT(i)))
4882 continue;
4883
4884 if (nla_put_u8(msg, i, signal[i]))
4885 return false;
4886 }
4887
4888 nla_nest_end(msg, attr);
4889
4890 return true;
4891}
4892
Johannes Bergcf5ead82014-11-14 17:14:00 +01004893static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4894 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004895 struct cfg80211_registered_device *rdev,
4896 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004897 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004898{
4899 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004900 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004901
Johannes Bergcf5ead82014-11-14 17:14:00 +01004902 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004903 if (!hdr)
4904 return -1;
4905
David S. Miller9360ffd2012-03-29 04:41:26 -04004906 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4907 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4908 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4909 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004910
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004911 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004912 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004913 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004914
4915#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004916 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03004917 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004918 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4919 sinfo->memb)) \
4920 goto nla_put_failure; \
4921 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004922#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03004923 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004924 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4925 sinfo->memb, NL80211_STA_INFO_PAD)) \
4926 goto nla_put_failure; \
4927 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004928
4929 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4930 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4931
Omer Efrat397c6572018-06-17 13:06:14 +03004932 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4933 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004934 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004935 (u32)sinfo->rx_bytes))
4936 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004937
Omer Efrat397c6572018-06-17 13:06:14 +03004938 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4939 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004940 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4941 (u32)sinfo->tx_bytes))
4942 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004943
Johannes Bergd686b922016-04-26 09:54:11 +02004944 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4945 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004946 PUT_SINFO(LLID, llid, u16);
4947 PUT_SINFO(PLID, plid, u16);
4948 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004949 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08004950 PUT_SINFO_U64(TX_DURATION, tx_duration);
4951
4952 if (wiphy_ext_feature_isset(&rdev->wiphy,
4953 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4954 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01004955
John W. Linville66266b32012-03-15 13:25:41 -04004956 switch (rdev->wiphy.signal_type) {
4957 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004958 PUT_SINFO(SIGNAL, signal, u8);
4959 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004960 break;
4961 default:
4962 break;
4963 }
Omer Efrat397c6572018-06-17 13:06:14 +03004964 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004965 if (!nl80211_put_signal(msg, sinfo->chains,
4966 sinfo->chain_signal,
4967 NL80211_STA_INFO_CHAIN_SIGNAL))
4968 goto nla_put_failure;
4969 }
Omer Efrat397c6572018-06-17 13:06:14 +03004970 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004971 if (!nl80211_put_signal(msg, sinfo->chains,
4972 sinfo->chain_signal_avg,
4973 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4974 goto nla_put_failure;
4975 }
Omer Efrat397c6572018-06-17 13:06:14 +03004976 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004977 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4978 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004979 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004980 }
Omer Efrat397c6572018-06-17 13:06:14 +03004981 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004982 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4983 NL80211_STA_INFO_RX_BITRATE))
4984 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004985 }
Johannes Berg319090b2014-11-17 14:08:11 +01004986
4987 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4988 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4989 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4990 PUT_SINFO(TX_FAILED, tx_failed, u32);
4991 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08004992 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01004993 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4994 PUT_SINFO(LOCAL_PM, local_pm, u32);
4995 PUT_SINFO(PEER_PM, peer_pm, u32);
4996 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04004997 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004998
Omer Efrat397c6572018-06-17 13:06:14 +03004999 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005000 bss_param = nla_nest_start_noflag(msg,
5001 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005002 if (!bss_param)
5003 goto nla_put_failure;
5004
David S. Miller9360ffd2012-03-29 04:41:26 -04005005 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5006 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5007 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5008 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5009 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5010 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5011 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5012 sinfo->bss_param.dtim_period) ||
5013 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5014 sinfo->bss_param.beacon_interval))
5015 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005016
5017 nla_nest_end(msg, bss_param);
5018 }
Omer Efrat397c6572018-06-17 13:06:14 +03005019 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005020 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5021 sizeof(struct nl80211_sta_flag_update),
5022 &sinfo->sta_flags))
5023 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005024
Johannes Bergd686b922016-04-26 09:54:11 +02005025 PUT_SINFO_U64(T_OFFSET, t_offset);
5026 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5027 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005028 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005029 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5030 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305031 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305032 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5033 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5034 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5035 }
Johannes Berg319090b2014-11-17 14:08:11 +01005036
5037#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005038#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005039
Arend van Spriel8689c052018-05-10 13:50:12 +02005040 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005041 struct nlattr *tidsattr;
5042 int tid;
5043
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005044 tidsattr = nla_nest_start_noflag(msg,
5045 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005046 if (!tidsattr)
5047 goto nla_put_failure;
5048
5049 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5050 struct cfg80211_tid_stats *tidstats;
5051 struct nlattr *tidattr;
5052
5053 tidstats = &sinfo->pertid[tid];
5054
5055 if (!tidstats->filled)
5056 continue;
5057
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005058 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005059 if (!tidattr)
5060 goto nla_put_failure;
5061
Johannes Bergd686b922016-04-26 09:54:11 +02005062#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005063 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005064 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5065 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005066 goto nla_put_failure; \
5067 } while (0)
5068
Johannes Bergd686b922016-04-26 09:54:11 +02005069 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5070 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5071 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5072 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005073
Johannes Bergd686b922016-04-26 09:54:11 +02005074#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005075 if ((tidstats->filled &
5076 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5077 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5078 NL80211_TID_STATS_TXQ_STATS))
5079 goto nla_put_failure;
5080
Johannes Berg6de39802014-12-19 12:34:00 +01005081 nla_nest_end(msg, tidattr);
5082 }
5083
5084 nla_nest_end(msg, tidsattr);
5085 }
5086
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005087 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005088
Johannes Berg319090b2014-11-17 14:08:11 +01005089 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005090 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5091 sinfo->assoc_req_ies))
5092 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005093
Johannes Berg7ea3e112018-05-18 11:40:44 +02005094 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005095 genlmsg_end(msg, hdr);
5096 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005097
5098 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005099 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005100 genlmsg_cancel(msg, hdr);
5101 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005102}
5103
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005104static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005105 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005106{
Johannes Berg73887fd2018-05-18 09:57:55 +02005107 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005108 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005109 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005110 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005111 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005112 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005113
Johannes Bergea90e0d2017-03-15 14:26:04 +01005114 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005115 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005116 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005117 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005118
Johannes Berg97990a02013-04-19 01:02:55 +02005119 if (!wdev->netdev) {
5120 err = -EINVAL;
5121 goto out_err;
5122 }
5123
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005124 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005125 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005126 goto out_err;
5127 }
5128
Johannes Bergbba95fe2008-07-29 13:22:51 +02005129 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005130 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005131 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005132 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005133 if (err == -ENOENT)
5134 break;
5135 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005136 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005137
Johannes Bergcf5ead82014-11-14 17:14:00 +01005138 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005139 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005140 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005141 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005142 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005143 goto out;
5144
5145 sta_idx++;
5146 }
5147
Johannes Bergbba95fe2008-07-29 13:22:51 +02005148 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005149 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005150 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005151 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005152 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005153
5154 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005155}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005156
Johannes Berg5727ef12007-12-19 02:03:34 +01005157static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5158{
Johannes Berg4c476992010-10-04 21:36:35 +02005159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5160 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005161 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005162 struct sk_buff *msg;
5163 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005164 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005165
Johannes Berg73887fd2018-05-18 09:57:55 +02005166 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005167
Johannes Berg73887fd2018-05-18 09:57:55 +02005168 if (!info->attrs[NL80211_ATTR_MAC])
5169 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005170
5171 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5172
Johannes Berg73887fd2018-05-18 09:57:55 +02005173 if (!rdev->ops->get_station)
5174 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005175
Johannes Berg73887fd2018-05-18 09:57:55 +02005176 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005177 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005178 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005179
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005180 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005181 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005182 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005183 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005184 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005185
Johannes Bergcf5ead82014-11-14 17:14:00 +01005186 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5187 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005188 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005189 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005190 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005191 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005192
Johannes Berg73887fd2018-05-18 09:57:55 +02005193 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005194}
5195
Johannes Berg77ee7c82013-02-15 00:48:33 +01005196int cfg80211_check_station_change(struct wiphy *wiphy,
5197 struct station_parameters *params,
5198 enum cfg80211_station_type statype)
5199{
Ayala Bekere4208422015-10-23 11:20:06 +03005200 if (params->listen_interval != -1 &&
5201 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005202 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005203
Ayala Beker17b94242016-03-17 15:41:38 +02005204 if (params->support_p2p_ps != -1 &&
5205 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5206 return -EINVAL;
5207
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005208 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005209 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5210 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005211 return -EINVAL;
5212
5213 /* When you run into this, adjust the code below for the new flag */
5214 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5215
5216 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005217 case CFG80211_STA_MESH_PEER_KERNEL:
5218 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005219 /*
5220 * No ignoring the TDLS flag here -- the userspace mesh
5221 * code doesn't have the bug of including TDLS in the
5222 * mask everywhere.
5223 */
5224 if (params->sta_flags_mask &
5225 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5226 BIT(NL80211_STA_FLAG_MFP) |
5227 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5228 return -EINVAL;
5229 break;
5230 case CFG80211_STA_TDLS_PEER_SETUP:
5231 case CFG80211_STA_TDLS_PEER_ACTIVE:
5232 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5233 return -EINVAL;
5234 /* ignore since it can't change */
5235 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5236 break;
5237 default:
5238 /* disallow mesh-specific things */
5239 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5240 return -EINVAL;
5241 if (params->local_pm)
5242 return -EINVAL;
5243 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5244 return -EINVAL;
5245 }
5246
5247 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5248 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5249 /* TDLS can't be set, ... */
5250 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5251 return -EINVAL;
5252 /*
5253 * ... but don't bother the driver with it. This works around
5254 * a hostapd/wpa_supplicant issue -- it always includes the
5255 * TLDS_PEER flag in the mask even for AP mode.
5256 */
5257 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5258 }
5259
Ayala Beker47edb112015-09-21 15:49:53 +03005260 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5261 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005262 /* reject other things that can't change */
5263 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5264 return -EINVAL;
5265 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5266 return -EINVAL;
5267 if (params->supported_rates)
5268 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005269 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5270 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005271 return -EINVAL;
5272 }
5273
Ayala Beker47edb112015-09-21 15:49:53 +03005274 if (statype != CFG80211_STA_AP_CLIENT &&
5275 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005276 if (params->vlan)
5277 return -EINVAL;
5278 }
5279
5280 switch (statype) {
5281 case CFG80211_STA_AP_MLME_CLIENT:
5282 /* Use this only for authorizing/unauthorizing a station */
5283 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5284 return -EOPNOTSUPP;
5285 break;
5286 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005287 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005288 /* accept only the listed bits */
5289 if (params->sta_flags_mask &
5290 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5291 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5292 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5293 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5294 BIT(NL80211_STA_FLAG_WME) |
5295 BIT(NL80211_STA_FLAG_MFP)))
5296 return -EINVAL;
5297
5298 /* but authenticated/associated only if driver handles it */
5299 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5300 params->sta_flags_mask &
5301 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5302 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5303 return -EINVAL;
5304 break;
5305 case CFG80211_STA_IBSS:
5306 case CFG80211_STA_AP_STA:
5307 /* reject any changes other than AUTHORIZED */
5308 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5309 return -EINVAL;
5310 break;
5311 case CFG80211_STA_TDLS_PEER_SETUP:
5312 /* reject any changes other than AUTHORIZED or WME */
5313 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5314 BIT(NL80211_STA_FLAG_WME)))
5315 return -EINVAL;
5316 /* force (at least) rates when authorizing */
5317 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5318 !params->supported_rates)
5319 return -EINVAL;
5320 break;
5321 case CFG80211_STA_TDLS_PEER_ACTIVE:
5322 /* reject any changes */
5323 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005324 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005325 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5326 return -EINVAL;
5327 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005328 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005329 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5330 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005331 return -EINVAL;
5332 break;
5333 }
5334
Beni Lev06f7c882016-07-19 19:28:56 +03005335 /*
5336 * Older kernel versions ignored this attribute entirely, so don't
5337 * reject attempts to update it but mark it as unused instead so the
5338 * driver won't look at the data.
5339 */
5340 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5341 statype != CFG80211_STA_TDLS_PEER_SETUP)
5342 params->opmode_notif_used = false;
5343
Johannes Berg77ee7c82013-02-15 00:48:33 +01005344 return 0;
5345}
5346EXPORT_SYMBOL(cfg80211_check_station_change);
5347
Johannes Berg5727ef12007-12-19 02:03:34 +01005348/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005349 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005350 */
Johannes Berg80b99892011-11-18 16:23:01 +01005351static struct net_device *get_vlan(struct genl_info *info,
5352 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005353{
Johannes Berg463d0182009-07-14 00:33:35 +02005354 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005355 struct net_device *v;
5356 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005357
Johannes Berg80b99892011-11-18 16:23:01 +01005358 if (!vlanattr)
5359 return NULL;
5360
5361 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5362 if (!v)
5363 return ERR_PTR(-ENODEV);
5364
5365 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5366 ret = -EINVAL;
5367 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005368 }
Johannes Berg80b99892011-11-18 16:23:01 +01005369
Johannes Berg77ee7c82013-02-15 00:48:33 +01005370 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5371 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5372 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5373 ret = -EINVAL;
5374 goto error;
5375 }
5376
Johannes Berg80b99892011-11-18 16:23:01 +01005377 if (!netif_running(v)) {
5378 ret = -ENETDOWN;
5379 goto error;
5380 }
5381
5382 return v;
5383 error:
5384 dev_put(v);
5385 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005386}
5387
Johannes Berg94e860f2014-01-20 23:58:15 +01005388static const struct nla_policy
5389nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005390 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5391 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5392};
5393
Johannes Bergff276692013-02-15 00:09:01 +01005394static int nl80211_parse_sta_wme(struct genl_info *info,
5395 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005396{
Jouni Malinendf881292013-02-14 21:10:54 +02005397 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5398 struct nlattr *nla;
5399 int err;
5400
Jouni Malinendf881292013-02-14 21:10:54 +02005401 /* parse WME attributes if present */
5402 if (!info->attrs[NL80211_ATTR_STA_WME])
5403 return 0;
5404
5405 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02005406 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5407 nl80211_sta_wme_policy,
5408 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005409 if (err)
5410 return err;
5411
5412 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5413 params->uapsd_queues = nla_get_u8(
5414 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5415 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5416 return -EINVAL;
5417
5418 if (tb[NL80211_STA_WME_MAX_SP])
5419 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5420
5421 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5422 return -EINVAL;
5423
5424 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5425
5426 return 0;
5427}
5428
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305429static int nl80211_parse_sta_channel_info(struct genl_info *info,
5430 struct station_parameters *params)
5431{
5432 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5433 params->supported_channels =
5434 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5435 params->supported_channels_len =
5436 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5437 /*
5438 * Need to include at least one (first channel, number of
5439 * channels) tuple for each subband, and must have proper
5440 * tuples for the rest of the data as well.
5441 */
5442 if (params->supported_channels_len < 2)
5443 return -EINVAL;
5444 if (params->supported_channels_len % 2)
5445 return -EINVAL;
5446 }
5447
5448 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5449 params->supported_oper_classes =
5450 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5451 params->supported_oper_classes_len =
5452 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5453 /*
5454 * The value of the Length field of the Supported Operating
5455 * Classes element is between 2 and 253.
5456 */
5457 if (params->supported_oper_classes_len < 2 ||
5458 params->supported_oper_classes_len > 253)
5459 return -EINVAL;
5460 }
5461 return 0;
5462}
5463
Johannes Bergff276692013-02-15 00:09:01 +01005464static int nl80211_set_station_tdls(struct genl_info *info,
5465 struct station_parameters *params)
5466{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305467 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005468 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005469 if (info->attrs[NL80211_ATTR_PEER_AID])
5470 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005471 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5472 params->ht_capa =
5473 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5474 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5475 params->vht_capa =
5476 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005477 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5478 params->he_capa =
5479 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5480 params->he_capa_len =
5481 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5482
5483 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5484 return -EINVAL;
5485 }
Johannes Bergff276692013-02-15 00:09:01 +01005486
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305487 err = nl80211_parse_sta_channel_info(info, params);
5488 if (err)
5489 return err;
5490
Johannes Bergff276692013-02-15 00:09:01 +01005491 return nl80211_parse_sta_wme(info, params);
5492}
5493
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305494static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5495 struct station_parameters *params)
5496{
5497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5498 int idx;
5499
5500 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5501 if (!rdev->ops->set_tx_power ||
5502 !wiphy_ext_feature_isset(&rdev->wiphy,
5503 NL80211_EXT_FEATURE_STA_TX_PWR))
5504 return -EOPNOTSUPP;
5505
5506 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5507 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5508
5509 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5510 idx = NL80211_ATTR_STA_TX_POWER;
5511
5512 if (info->attrs[idx])
5513 params->txpwr.power =
5514 nla_get_s16(info->attrs[idx]);
5515 else
5516 return -EINVAL;
5517 }
5518 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5519 }
5520
5521 return 0;
5522}
5523
Johannes Berg5727ef12007-12-19 02:03:34 +01005524static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5525{
Johannes Berg4c476992010-10-04 21:36:35 +02005526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005527 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005528 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005529 u8 *mac_addr;
5530 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005531
5532 memset(&params, 0, sizeof(params));
5533
Johannes Berg77ee7c82013-02-15 00:48:33 +01005534 if (!rdev->ops->change_station)
5535 return -EOPNOTSUPP;
5536
Ayala Bekere4208422015-10-23 11:20:06 +03005537 /*
5538 * AID and listen_interval properties can be set only for unassociated
5539 * station. Include these parameters here and will check them in
5540 * cfg80211_check_station_change().
5541 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005542 if (info->attrs[NL80211_ATTR_STA_AID])
5543 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005544
5545 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5546 params.listen_interval =
5547 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5548 else
5549 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005550
Johannes Bergab0d76f2018-10-02 10:00:07 +02005551 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5552 params.support_p2p_ps =
5553 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5554 else
Ayala Beker17b94242016-03-17 15:41:38 +02005555 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005556
Johannes Berg5727ef12007-12-19 02:03:34 +01005557 if (!info->attrs[NL80211_ATTR_MAC])
5558 return -EINVAL;
5559
5560 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5561
5562 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5563 params.supported_rates =
5564 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5565 params.supported_rates_len =
5566 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5567 }
5568
Jouni Malinen9d62a982013-02-14 21:10:13 +02005569 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5570 params.capability =
5571 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5572 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5573 }
5574
5575 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5576 params.ext_capab =
5577 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5578 params.ext_capab_len =
5579 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5580 }
5581
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005582 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005583 return -EINVAL;
5584
Johannes Bergab0d76f2018-10-02 10:00:07 +02005585 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005586 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005587 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005588
Johannes Bergf8bacc22013-02-14 23:27:01 +01005589 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005590 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005591 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005592 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005593 params.peer_aid = nla_get_u16(
5594 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005595 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5596 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005597
Johannes Bergab0d76f2018-10-02 10:00:07 +02005598 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5599 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005600 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5601
Beni Lev06f7c882016-07-19 19:28:56 +03005602 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5603 params.opmode_notif_used = true;
5604 params.opmode_notif =
5605 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5606 }
5607
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005608 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5609 params.airtime_weight =
5610 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5611
5612 if (params.airtime_weight &&
5613 !wiphy_ext_feature_isset(&rdev->wiphy,
5614 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5615 return -EOPNOTSUPP;
5616
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305617 err = nl80211_parse_sta_txpower_setting(info, &params);
5618 if (err)
5619 return err;
5620
Johannes Berg77ee7c82013-02-15 00:48:33 +01005621 /* Include parameters for TDLS peer (will check later) */
5622 err = nl80211_set_station_tdls(info, &params);
5623 if (err)
5624 return err;
5625
5626 params.vlan = get_vlan(info, rdev);
5627 if (IS_ERR(params.vlan))
5628 return PTR_ERR(params.vlan);
5629
Johannes Berga97f4422009-06-18 17:23:43 +02005630 switch (dev->ieee80211_ptr->iftype) {
5631 case NL80211_IFTYPE_AP:
5632 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005633 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005634 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005635 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005636 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005637 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005638 break;
5639 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005640 err = -EOPNOTSUPP;
5641 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005642 }
5643
Johannes Berg77ee7c82013-02-15 00:48:33 +01005644 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005645 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005646
Johannes Berg77ee7c82013-02-15 00:48:33 +01005647 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005648 if (params.vlan)
5649 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005650
Johannes Berg5727ef12007-12-19 02:03:34 +01005651 return err;
5652}
5653
5654static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5655{
Johannes Berg4c476992010-10-04 21:36:35 +02005656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005657 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005658 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005659 struct station_parameters params;
5660 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005661 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5662 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005663
5664 memset(&params, 0, sizeof(params));
5665
Johannes Berg984c3112013-02-14 23:43:25 +01005666 if (!rdev->ops->add_station)
5667 return -EOPNOTSUPP;
5668
Johannes Berg5727ef12007-12-19 02:03:34 +01005669 if (!info->attrs[NL80211_ATTR_MAC])
5670 return -EINVAL;
5671
Johannes Berg5727ef12007-12-19 02:03:34 +01005672 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5673 return -EINVAL;
5674
5675 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5676 return -EINVAL;
5677
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005678 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5679 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005680 return -EINVAL;
5681
Johannes Berg5727ef12007-12-19 02:03:34 +01005682 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5683 params.supported_rates =
5684 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5685 params.supported_rates_len =
5686 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5687 params.listen_interval =
5688 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005689
Ayala Beker17b94242016-03-17 15:41:38 +02005690 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005691 params.support_p2p_ps =
5692 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005693 } else {
5694 /*
5695 * if not specified, assume it's supported for P2P GO interface,
5696 * and is NOT supported for AP interface
5697 */
5698 params.support_p2p_ps =
5699 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5700 }
5701
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005702 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005703 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005704 else
5705 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005706
Jouni Malinen9d62a982013-02-14 21:10:13 +02005707 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5708 params.capability =
5709 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5710 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5711 }
5712
5713 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5714 params.ext_capab =
5715 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5716 params.ext_capab_len =
5717 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5718 }
5719
Jouni Malinen36aedc92008-08-25 11:58:58 +03005720 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5721 params.ht_capa =
5722 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005723
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005724 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5725 params.vht_capa =
5726 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5727
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005728 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5729 params.he_capa =
5730 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5731 params.he_capa_len =
5732 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5733
5734 /* max len is validated in nla policy */
5735 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5736 return -EINVAL;
5737 }
5738
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005739 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5740 params.opmode_notif_used = true;
5741 params.opmode_notif =
5742 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5743 }
5744
Johannes Bergab0d76f2018-10-02 10:00:07 +02005745 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005746 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005747 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005748
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005749 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5750 params.airtime_weight =
5751 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5752
5753 if (params.airtime_weight &&
5754 !wiphy_ext_feature_isset(&rdev->wiphy,
5755 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5756 return -EOPNOTSUPP;
5757
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305758 err = nl80211_parse_sta_txpower_setting(info, &params);
5759 if (err)
5760 return err;
5761
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305762 err = nl80211_parse_sta_channel_info(info, &params);
5763 if (err)
5764 return err;
5765
Johannes Bergff276692013-02-15 00:09:01 +01005766 err = nl80211_parse_sta_wme(info, &params);
5767 if (err)
5768 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005769
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005770 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005771 return -EINVAL;
5772
Johannes Berg496fcc22015-03-12 08:53:27 +02005773 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5774 * as userspace might just pass through the capabilities from the IEs
5775 * directly, rather than enforcing this restriction and returning an
5776 * error in this case.
5777 */
5778 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5779 params.ht_capa = NULL;
5780 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005781
5782 /* HE requires WME */
5783 if (params.he_capa_len)
5784 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005785 }
5786
Johannes Berg77ee7c82013-02-15 00:48:33 +01005787 /* When you run into this, adjust the code below for the new flag */
5788 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5789
Johannes Bergbdd90d52011-12-14 12:20:27 +01005790 switch (dev->ieee80211_ptr->iftype) {
5791 case NL80211_IFTYPE_AP:
5792 case NL80211_IFTYPE_AP_VLAN:
5793 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005794 /* ignore WME attributes if iface/sta is not capable */
5795 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5796 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5797 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005798
Johannes Bergbdd90d52011-12-14 12:20:27 +01005799 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005800 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5801 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005802 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005803 /* but don't bother the driver with it */
5804 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005805
Johannes Bergd582cff2012-10-26 17:53:44 +02005806 /* allow authenticated/associated only if driver handles it */
5807 if (!(rdev->wiphy.features &
5808 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005809 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005810 return -EINVAL;
5811
Johannes Bergbda95eb2015-11-26 16:26:13 +01005812 /* Older userspace, or userspace wanting to be compatible with
5813 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5814 * and assoc flags in the mask, but assumes the station will be
5815 * added as associated anyway since this was the required driver
5816 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5817 * introduced.
5818 * In order to not bother drivers with this quirk in the API
5819 * set the flags in both the mask and set for new stations in
5820 * this case.
5821 */
5822 if (!(params.sta_flags_mask & auth_assoc)) {
5823 params.sta_flags_mask |= auth_assoc;
5824 params.sta_flags_set |= auth_assoc;
5825 }
5826
Johannes Bergbdd90d52011-12-14 12:20:27 +01005827 /* must be last in here for error handling */
5828 params.vlan = get_vlan(info, rdev);
5829 if (IS_ERR(params.vlan))
5830 return PTR_ERR(params.vlan);
5831 break;
5832 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005833 /* ignore uAPSD data */
5834 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5835
Johannes Bergd582cff2012-10-26 17:53:44 +02005836 /* associated is disallowed */
5837 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5838 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005839 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005840 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5841 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005842 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005843 break;
5844 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005845 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005846 /* ignore uAPSD data */
5847 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5848
Johannes Berg77ee7c82013-02-15 00:48:33 +01005849 /* these are disallowed */
5850 if (params.sta_flags_mask &
5851 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5852 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005853 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005854 /* Only TDLS peers can be added */
5855 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5856 return -EINVAL;
5857 /* Can only add if TDLS ... */
5858 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5859 return -EOPNOTSUPP;
5860 /* ... with external setup is supported */
5861 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5862 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005863 /*
5864 * Older wpa_supplicant versions always mark the TDLS peer
5865 * as authorized, but it shouldn't yet be.
5866 */
5867 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005868 break;
5869 default:
5870 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005871 }
5872
Johannes Bergbdd90d52011-12-14 12:20:27 +01005873 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005874
Hila Gonene35e4d22012-06-27 17:19:42 +03005875 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005876
Johannes Berg5727ef12007-12-19 02:03:34 +01005877 if (params.vlan)
5878 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005879 return err;
5880}
5881
5882static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5883{
Johannes Berg4c476992010-10-04 21:36:35 +02005884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5885 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005886 struct station_del_parameters params;
5887
5888 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005889
5890 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005891 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005892
Johannes Berge80cf852009-05-11 14:43:13 +02005893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005894 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005895 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005896 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5897 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005898
Johannes Berg4c476992010-10-04 21:36:35 +02005899 if (!rdev->ops->del_station)
5900 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005901
Jouni Malinen98856862014-10-20 13:20:45 +03005902 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5903 params.subtype =
5904 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5905 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5906 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5907 return -EINVAL;
5908 } else {
5909 /* Default to Deauthentication frame */
5910 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5911 }
5912
5913 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5914 params.reason_code =
5915 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5916 if (params.reason_code == 0)
5917 return -EINVAL; /* 0 is reserved */
5918 } else {
5919 /* Default to reason code 2 */
5920 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5921 }
5922
Jouni Malinen89c771e2014-10-10 20:52:40 +03005923 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005924}
5925
Eric W. Biederman15e47302012-09-07 20:12:54 +00005926static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005927 int flags, struct net_device *dev,
5928 u8 *dst, u8 *next_hop,
5929 struct mpath_info *pinfo)
5930{
5931 void *hdr;
5932 struct nlattr *pinfoattr;
5933
Henning Rogge1ef4c852014-11-04 16:14:58 +01005934 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005935 if (!hdr)
5936 return -1;
5937
David S. Miller9360ffd2012-03-29 04:41:26 -04005938 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5939 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5940 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5941 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5942 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005943
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005944 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005945 if (!pinfoattr)
5946 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005947 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5948 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5949 pinfo->frame_qlen))
5950 goto nla_put_failure;
5951 if (((pinfo->filled & MPATH_INFO_SN) &&
5952 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5953 ((pinfo->filled & MPATH_INFO_METRIC) &&
5954 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5955 pinfo->metric)) ||
5956 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5957 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5958 pinfo->exptime)) ||
5959 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5960 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5961 pinfo->flags)) ||
5962 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5963 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5964 pinfo->discovery_timeout)) ||
5965 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5966 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08005967 pinfo->discovery_retries)) ||
5968 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
5969 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08005970 pinfo->hop_count)) ||
5971 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
5972 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
5973 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005974 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005975
5976 nla_nest_end(msg, pinfoattr);
5977
Johannes Berg053c0952015-01-16 22:09:00 +01005978 genlmsg_end(msg, hdr);
5979 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005980
5981 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005982 genlmsg_cancel(msg, hdr);
5983 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005984}
5985
5986static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005987 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005988{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005989 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005990 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005991 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005992 u8 dst[ETH_ALEN];
5993 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005994 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005995 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005996
Johannes Bergea90e0d2017-03-15 14:26:04 +01005997 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005998 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005999 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006000 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006001
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006002 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006003 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006004 goto out_err;
6005 }
6006
Johannes Berg97990a02013-04-19 01:02:55 +02006007 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006008 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006009 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006010 }
6011
Johannes Bergbba95fe2008-07-29 13:22:51 +02006012 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006013 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006014 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006015 if (err == -ENOENT)
6016 break;
6017 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006018 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006019
Eric W. Biederman15e47302012-09-07 20:12:54 +00006020 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006021 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006022 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006023 &pinfo) < 0)
6024 goto out;
6025
6026 path_idx++;
6027 }
6028
Johannes Bergbba95fe2008-07-29 13:22:51 +02006029 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006030 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006031 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006032 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006033 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006034 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006035}
6036
6037static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6038{
Johannes Berg4c476992010-10-04 21:36:35 +02006039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006040 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006041 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006042 struct mpath_info pinfo;
6043 struct sk_buff *msg;
6044 u8 *dst = NULL;
6045 u8 next_hop[ETH_ALEN];
6046
6047 memset(&pinfo, 0, sizeof(pinfo));
6048
6049 if (!info->attrs[NL80211_ATTR_MAC])
6050 return -EINVAL;
6051
6052 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6053
Johannes Berg4c476992010-10-04 21:36:35 +02006054 if (!rdev->ops->get_mpath)
6055 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006056
Johannes Berg4c476992010-10-04 21:36:35 +02006057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6058 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006059
Hila Gonene35e4d22012-06-27 17:19:42 +03006060 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006061 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006062 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006063
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006064 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006065 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006066 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006067
Eric W. Biederman15e47302012-09-07 20:12:54 +00006068 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006069 dev, dst, next_hop, &pinfo) < 0) {
6070 nlmsg_free(msg);
6071 return -ENOBUFS;
6072 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006073
Johannes Berg4c476992010-10-04 21:36:35 +02006074 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006075}
6076
6077static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6078{
Johannes Berg4c476992010-10-04 21:36:35 +02006079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6080 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006081 u8 *dst = NULL;
6082 u8 *next_hop = NULL;
6083
6084 if (!info->attrs[NL80211_ATTR_MAC])
6085 return -EINVAL;
6086
6087 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6088 return -EINVAL;
6089
6090 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6091 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6092
Johannes Berg4c476992010-10-04 21:36:35 +02006093 if (!rdev->ops->change_mpath)
6094 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006095
Johannes Berg4c476992010-10-04 21:36:35 +02006096 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6097 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006098
Hila Gonene35e4d22012-06-27 17:19:42 +03006099 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006100}
Johannes Berg4c476992010-10-04 21:36:35 +02006101
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006102static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6103{
Johannes Berg4c476992010-10-04 21:36:35 +02006104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6105 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006106 u8 *dst = NULL;
6107 u8 *next_hop = NULL;
6108
6109 if (!info->attrs[NL80211_ATTR_MAC])
6110 return -EINVAL;
6111
6112 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6113 return -EINVAL;
6114
6115 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6116 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6117
Johannes Berg4c476992010-10-04 21:36:35 +02006118 if (!rdev->ops->add_mpath)
6119 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006120
Johannes Berg4c476992010-10-04 21:36:35 +02006121 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6122 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006123
Hila Gonene35e4d22012-06-27 17:19:42 +03006124 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006125}
6126
6127static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6128{
Johannes Berg4c476992010-10-04 21:36:35 +02006129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6130 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006131 u8 *dst = NULL;
6132
6133 if (info->attrs[NL80211_ATTR_MAC])
6134 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6135
Johannes Berg4c476992010-10-04 21:36:35 +02006136 if (!rdev->ops->del_mpath)
6137 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006138
Hila Gonene35e4d22012-06-27 17:19:42 +03006139 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006140}
6141
Henning Rogge66be7d22014-09-12 08:58:49 +02006142static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6143{
6144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6145 int err;
6146 struct net_device *dev = info->user_ptr[1];
6147 struct mpath_info pinfo;
6148 struct sk_buff *msg;
6149 u8 *dst = NULL;
6150 u8 mpp[ETH_ALEN];
6151
6152 memset(&pinfo, 0, sizeof(pinfo));
6153
6154 if (!info->attrs[NL80211_ATTR_MAC])
6155 return -EINVAL;
6156
6157 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6158
6159 if (!rdev->ops->get_mpp)
6160 return -EOPNOTSUPP;
6161
6162 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6163 return -EOPNOTSUPP;
6164
6165 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6166 if (err)
6167 return err;
6168
6169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6170 if (!msg)
6171 return -ENOMEM;
6172
6173 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6174 dev, dst, mpp, &pinfo) < 0) {
6175 nlmsg_free(msg);
6176 return -ENOBUFS;
6177 }
6178
6179 return genlmsg_reply(msg, info);
6180}
6181
6182static int nl80211_dump_mpp(struct sk_buff *skb,
6183 struct netlink_callback *cb)
6184{
6185 struct mpath_info pinfo;
6186 struct cfg80211_registered_device *rdev;
6187 struct wireless_dev *wdev;
6188 u8 dst[ETH_ALEN];
6189 u8 mpp[ETH_ALEN];
6190 int path_idx = cb->args[2];
6191 int err;
6192
Johannes Bergea90e0d2017-03-15 14:26:04 +01006193 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006194 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006195 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006196 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006197
6198 if (!rdev->ops->dump_mpp) {
6199 err = -EOPNOTSUPP;
6200 goto out_err;
6201 }
6202
6203 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6204 err = -EOPNOTSUPP;
6205 goto out_err;
6206 }
6207
6208 while (1) {
6209 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6210 mpp, &pinfo);
6211 if (err == -ENOENT)
6212 break;
6213 if (err)
6214 goto out_err;
6215
6216 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6217 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6218 wdev->netdev, dst, mpp,
6219 &pinfo) < 0)
6220 goto out;
6221
6222 path_idx++;
6223 }
6224
6225 out:
6226 cb->args[2] = path_idx;
6227 err = skb->len;
6228 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006229 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006230 return err;
6231}
6232
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006233static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6234{
Johannes Berg4c476992010-10-04 21:36:35 +02006235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6236 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006237 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006238 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006239 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006240
6241 memset(&params, 0, sizeof(params));
6242 /* default to not changing parameters */
6243 params.use_cts_prot = -1;
6244 params.use_short_preamble = -1;
6245 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006246 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006247 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006248 params.p2p_ctwindow = -1;
6249 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006250
6251 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6252 params.use_cts_prot =
6253 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6254 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6255 params.use_short_preamble =
6256 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6257 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6258 params.use_short_slot_time =
6259 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006260 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6261 params.basic_rates =
6262 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6263 params.basic_rates_len =
6264 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6265 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006266 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6267 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006268 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6269 params.ht_opmode =
6270 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006271
Johannes Berg53cabad2012-11-14 15:17:28 +01006272 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6273 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6274 return -EINVAL;
6275 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006276 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006277 if (params.p2p_ctwindow != 0 &&
6278 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6279 return -EINVAL;
6280 }
6281
6282 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6283 u8 tmp;
6284
6285 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6286 return -EINVAL;
6287 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006288 params.p2p_opp_ps = tmp;
6289 if (params.p2p_opp_ps &&
6290 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6291 return -EINVAL;
6292 }
6293
Johannes Berg4c476992010-10-04 21:36:35 +02006294 if (!rdev->ops->change_bss)
6295 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006296
Johannes Berg074ac8d2010-09-16 14:58:22 +02006297 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006298 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6299 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006300
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006301 wdev_lock(wdev);
6302 err = rdev_change_bss(rdev, dev, &params);
6303 wdev_unlock(wdev);
6304
6305 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006306}
6307
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006308static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6309{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006310 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006311 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006312 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006313 u32 owner_nlportid;
6314
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006315 /*
6316 * You should only get this when cfg80211 hasn't yet initialized
6317 * completely when built-in to the kernel right between the time
6318 * window between nl80211_init() and regulatory_init(), if that is
6319 * even possible.
6320 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006321 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006322 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006323
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006324 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6325 user_reg_hint_type =
6326 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6327 else
6328 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6329
6330 switch (user_reg_hint_type) {
6331 case NL80211_USER_REG_HINT_USER:
6332 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006333 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6334 return -EINVAL;
6335
6336 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6337 return regulatory_hint_user(data, user_reg_hint_type);
6338 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006339 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6340 owner_nlportid = info->snd_portid;
6341 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6342 } else {
6343 owner_nlportid = 0;
6344 is_indoor = true;
6345 }
6346
6347 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006348 default:
6349 return -EINVAL;
6350 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006351}
6352
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006353static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6354{
6355 return reg_reload_regdb();
6356}
6357
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006358static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006359 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006360{
Johannes Berg4c476992010-10-04 21:36:35 +02006361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006362 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006363 struct wireless_dev *wdev = dev->ieee80211_ptr;
6364 struct mesh_config cur_params;
6365 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006366 void *hdr;
6367 struct nlattr *pinfoattr;
6368 struct sk_buff *msg;
6369
Johannes Berg29cbe682010-12-03 09:20:44 +01006370 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6371 return -EOPNOTSUPP;
6372
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006373 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006374 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006375
Johannes Berg29cbe682010-12-03 09:20:44 +01006376 wdev_lock(wdev);
6377 /* If not connected, get default parameters */
6378 if (!wdev->mesh_id_len)
6379 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6380 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006381 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006382 wdev_unlock(wdev);
6383
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006384 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006385 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006386
6387 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006388 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006389 if (!msg)
6390 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006391 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006392 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006393 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006394 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006395 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006396 if (!pinfoattr)
6397 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006398 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6399 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6400 cur_params.dot11MeshRetryTimeout) ||
6401 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6402 cur_params.dot11MeshConfirmTimeout) ||
6403 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6404 cur_params.dot11MeshHoldingTimeout) ||
6405 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6406 cur_params.dot11MeshMaxPeerLinks) ||
6407 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6408 cur_params.dot11MeshMaxRetries) ||
6409 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6410 cur_params.dot11MeshTTL) ||
6411 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6412 cur_params.element_ttl) ||
6413 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6414 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006415 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6416 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006417 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6418 cur_params.dot11MeshHWMPmaxPREQretries) ||
6419 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6420 cur_params.path_refresh_time) ||
6421 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6422 cur_params.min_discovery_timeout) ||
6423 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6424 cur_params.dot11MeshHWMPactivePathTimeout) ||
6425 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6426 cur_params.dot11MeshHWMPpreqMinInterval) ||
6427 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6428 cur_params.dot11MeshHWMPperrMinInterval) ||
6429 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6430 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6431 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6432 cur_params.dot11MeshHWMPRootMode) ||
6433 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6434 cur_params.dot11MeshHWMPRannInterval) ||
6435 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6436 cur_params.dot11MeshGateAnnouncementProtocol) ||
6437 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6438 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006439 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006440 cur_params.rssi_threshold) ||
6441 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006442 cur_params.ht_opmode) ||
6443 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6444 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6445 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006446 cur_params.dot11MeshHWMProotInterval) ||
6447 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006448 cur_params.dot11MeshHWMPconfirmationInterval) ||
6449 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6450 cur_params.power_mode) ||
6451 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006452 cur_params.dot11MeshAwakeWindowDuration) ||
6453 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006454 cur_params.plink_timeout) ||
6455 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6456 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006457 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006458 nla_nest_end(msg, pinfoattr);
6459 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006460 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006461
Johannes Berg3b858752009-03-12 09:55:09 +01006462 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006463 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006464 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006465 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006466}
6467
Johannes Bergab0d76f2018-10-02 10:00:07 +02006468static const struct nla_policy
6469nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6470 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6471 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6472 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6473 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6474 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6475 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6476 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6477 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6478 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6479 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6480 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6481 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6482 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6483 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006484 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6485 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006486 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006487 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006488 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6489 NLA_POLICY_MIN(NLA_U16, 1),
6490 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6491 NLA_POLICY_MIN(NLA_U16, 1),
6492 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6493 NLA_POLICY_MIN(NLA_U16, 1),
6494 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6495 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6496 NLA_POLICY_MIN(NLA_U16, 1),
6497 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6498 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6499 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6500 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006501 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006502 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006503 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6504 NLA_POLICY_MIN(NLA_U16, 1),
6505 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6506 NLA_POLICY_MIN(NLA_U16, 1),
6507 [NL80211_MESHCONF_POWER_MODE] =
6508 NLA_POLICY_RANGE(NLA_U32,
6509 NL80211_MESH_POWER_ACTIVE,
6510 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006511 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006512 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006513 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006514};
6515
Javier Cardonac80d5452010-12-16 17:37:49 -08006516static const struct nla_policy
6517 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006518 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006519 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6520 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006521 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006522 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006523 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006524 [NL80211_MESH_SETUP_IE] =
6525 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6526 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006527 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006528};
6529
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006530static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006531 struct mesh_config *cfg,
6532 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006533{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006534 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006535 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006536 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006537
Johannes Bergab0d76f2018-10-02 10:00:07 +02006538#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6539do { \
6540 if (tb[attr]) { \
6541 cfg->param = fn(tb[attr]); \
6542 mask |= BIT((attr) - 1); \
6543 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006544} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006545
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006546 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006547 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006548 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 -07006549 return -EINVAL;
6550
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006551 /* This makes sure that there aren't more than 32 mesh config
6552 * parameters (otherwise our bitfield scheme would not work.) */
6553 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6554
6555 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006556 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6557 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6558 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6559 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6560 nla_get_u16);
6561 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6562 NL80211_MESHCONF_HOLDING_TIMEOUT,
6563 nla_get_u16);
6564 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6565 NL80211_MESHCONF_MAX_PEER_LINKS,
6566 nla_get_u16);
6567 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6568 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6569 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6570 NL80211_MESHCONF_TTL, nla_get_u8);
6571 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6572 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6573 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6574 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6575 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006576 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006577 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006578 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006579 nla_get_u32);
6580 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6581 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6582 nla_get_u8);
6583 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6584 NL80211_MESHCONF_PATH_REFRESH_TIME,
6585 nla_get_u32);
6586 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6587 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6588 return -EINVAL;
6589 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6590 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6591 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006592 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006593 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006594 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006595 nla_get_u32);
6596 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6597 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6598 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6599 return -EINVAL;
6600 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006601 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006602 nla_get_u16);
6603 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006604 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006605 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006606 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006607 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006608 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006609 nla_get_u16);
6610 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6611 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6612 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6613 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6614 nla_get_u16);
6615 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006616 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006617 nla_get_u8);
6618 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6619 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6620 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6621 NL80211_MESHCONF_RSSI_THRESHOLD,
6622 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006623 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6624 NL80211_MESHCONF_CONNECTED_TO_GATE,
6625 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006626 /*
6627 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006628 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006629 */
6630 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6631 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6632
6633 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6634 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6635 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6636 return -EINVAL;
6637
Bob Copeland188f60a2018-06-24 21:10:49 -04006638 /* NON_HT_STA bit is reserved, but some programs set it */
6639 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006640
Masashi Honma97572352016-08-03 10:07:44 +09006641 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006642 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006643 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006644 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006645 dot11MeshHWMPactivePathToRootTimeout, mask,
6646 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6647 nla_get_u32);
6648 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6649 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6650 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6651 return -EINVAL;
6652 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6653 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6654 nla_get_u16);
6655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6656 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006657 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006658 nla_get_u16);
6659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6660 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6662 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6664 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006665 if (mask_out)
6666 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006667
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006668 return 0;
6669
6670#undef FILL_IN_MESH_PARAM_IF_SET
6671}
6672
Javier Cardonac80d5452010-12-16 17:37:49 -08006673static int nl80211_parse_mesh_setup(struct genl_info *info,
6674 struct mesh_setup *setup)
6675{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006677 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6678
6679 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6680 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006681 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 -08006682 return -EINVAL;
6683
Javier Cardonad299a1f2012-03-31 11:31:33 -07006684 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6685 setup->sync_method =
6686 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6687 IEEE80211_SYNC_METHOD_VENDOR :
6688 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6689
Javier Cardonac80d5452010-12-16 17:37:49 -08006690 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6691 setup->path_sel_proto =
6692 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6693 IEEE80211_PATH_PROTOCOL_VENDOR :
6694 IEEE80211_PATH_PROTOCOL_HWMP;
6695
6696 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6697 setup->path_metric =
6698 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6699 IEEE80211_PATH_METRIC_VENDOR :
6700 IEEE80211_PATH_METRIC_AIRTIME;
6701
Javier Cardona581a8b02011-04-07 15:08:27 -07006702 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006703 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006704 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006705 setup->ie = nla_data(ieattr);
6706 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006707 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006708 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6709 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6710 return -EINVAL;
6711 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006712 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6713 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006714 if (setup->is_secure)
6715 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006716
Colleen Twitty6e16d902013-05-08 11:45:59 -07006717 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6718 if (!setup->user_mpm)
6719 return -EINVAL;
6720 setup->auth_id =
6721 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6722 }
6723
Javier Cardonac80d5452010-12-16 17:37:49 -08006724 return 0;
6725}
6726
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006727static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006728 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006729{
6730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6731 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006732 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006733 struct mesh_config cfg;
6734 u32 mask;
6735 int err;
6736
Johannes Berg29cbe682010-12-03 09:20:44 +01006737 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6738 return -EOPNOTSUPP;
6739
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006740 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006741 return -EOPNOTSUPP;
6742
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006743 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006744 if (err)
6745 return err;
6746
Johannes Berg29cbe682010-12-03 09:20:44 +01006747 wdev_lock(wdev);
6748 if (!wdev->mesh_id_len)
6749 err = -ENOLINK;
6750
6751 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006752 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006753
6754 wdev_unlock(wdev);
6755
6756 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006757}
6758
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006759static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6760 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006761{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006762 struct nlattr *nl_reg_rules;
6763 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006764
Johannes Berg458f4f92012-12-06 15:47:38 +01006765 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6766 (regdom->dfs_region &&
6767 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006768 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006769
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006770 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006771 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006772 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006773
Johannes Berg458f4f92012-12-06 15:47:38 +01006774 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006775 struct nlattr *nl_reg_rule;
6776 const struct ieee80211_reg_rule *reg_rule;
6777 const struct ieee80211_freq_range *freq_range;
6778 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006779 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006780
Johannes Berg458f4f92012-12-06 15:47:38 +01006781 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006782 freq_range = &reg_rule->freq_range;
6783 power_rule = &reg_rule->power_rule;
6784
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006785 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006786 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006787 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006788
Janusz Dziedzic97524822014-01-30 09:52:20 +01006789 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6790 if (!max_bandwidth_khz)
6791 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6792 reg_rule);
6793
David S. Miller9360ffd2012-03-29 04:41:26 -04006794 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6795 reg_rule->flags) ||
6796 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6797 freq_range->start_freq_khz) ||
6798 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6799 freq_range->end_freq_khz) ||
6800 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006801 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006802 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6803 power_rule->max_antenna_gain) ||
6804 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006805 power_rule->max_eirp) ||
6806 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6807 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006808 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006809
6810 nla_nest_end(msg, nl_reg_rule);
6811 }
6812
6813 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006814 return 0;
6815
6816nla_put_failure:
6817 return -EMSGSIZE;
6818}
6819
6820static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6821{
6822 const struct ieee80211_regdomain *regdom = NULL;
6823 struct cfg80211_registered_device *rdev;
6824 struct wiphy *wiphy = NULL;
6825 struct sk_buff *msg;
6826 void *hdr;
6827
6828 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6829 if (!msg)
6830 return -ENOBUFS;
6831
6832 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6833 NL80211_CMD_GET_REG);
6834 if (!hdr)
6835 goto put_failure;
6836
6837 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006838 bool self_managed;
6839
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006840 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6841 if (IS_ERR(rdev)) {
6842 nlmsg_free(msg);
6843 return PTR_ERR(rdev);
6844 }
6845
6846 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006847 self_managed = wiphy->regulatory_flags &
6848 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006849 regdom = get_wiphy_regdom(wiphy);
6850
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006851 /* a self-managed-reg device must have a private regdom */
6852 if (WARN_ON(!regdom && self_managed)) {
6853 nlmsg_free(msg);
6854 return -EINVAL;
6855 }
6856
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006857 if (regdom &&
6858 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6859 goto nla_put_failure;
6860 }
6861
6862 if (!wiphy && reg_last_request_cell_base() &&
6863 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6864 NL80211_USER_REG_HINT_CELL_BASE))
6865 goto nla_put_failure;
6866
6867 rcu_read_lock();
6868
6869 if (!regdom)
6870 regdom = rcu_dereference(cfg80211_regdomain);
6871
6872 if (nl80211_put_regdom(regdom, msg))
6873 goto nla_put_failure_rcu;
6874
6875 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006876
6877 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006878 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006879
Johannes Berg458f4f92012-12-06 15:47:38 +01006880nla_put_failure_rcu:
6881 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006882nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006883put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006884 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006885 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006886}
6887
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006888static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6889 u32 seq, int flags, struct wiphy *wiphy,
6890 const struct ieee80211_regdomain *regdom)
6891{
6892 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6893 NL80211_CMD_GET_REG);
6894
6895 if (!hdr)
6896 return -1;
6897
Michal Kubecek0a833c22017-11-15 13:09:32 +01006898 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006899
6900 if (nl80211_put_regdom(regdom, msg))
6901 goto nla_put_failure;
6902
6903 if (!wiphy && reg_last_request_cell_base() &&
6904 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6905 NL80211_USER_REG_HINT_CELL_BASE))
6906 goto nla_put_failure;
6907
6908 if (wiphy &&
6909 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6910 goto nla_put_failure;
6911
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006912 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6913 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6914 goto nla_put_failure;
6915
Johannes Berg053c0952015-01-16 22:09:00 +01006916 genlmsg_end(msg, hdr);
6917 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006918
6919nla_put_failure:
6920 genlmsg_cancel(msg, hdr);
6921 return -EMSGSIZE;
6922}
6923
6924static int nl80211_get_reg_dump(struct sk_buff *skb,
6925 struct netlink_callback *cb)
6926{
6927 const struct ieee80211_regdomain *regdom = NULL;
6928 struct cfg80211_registered_device *rdev;
6929 int err, reg_idx, start = cb->args[2];
6930
6931 rtnl_lock();
6932
6933 if (cfg80211_regdomain && start == 0) {
6934 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6935 NLM_F_MULTI, NULL,
6936 rtnl_dereference(cfg80211_regdomain));
6937 if (err < 0)
6938 goto out_err;
6939 }
6940
6941 /* the global regdom is idx 0 */
6942 reg_idx = 1;
6943 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6944 regdom = get_wiphy_regdom(&rdev->wiphy);
6945 if (!regdom)
6946 continue;
6947
6948 if (++reg_idx <= start)
6949 continue;
6950
6951 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6952 NLM_F_MULTI, &rdev->wiphy, regdom);
6953 if (err < 0) {
6954 reg_idx--;
6955 break;
6956 }
6957 }
6958
6959 cb->args[2] = reg_idx;
6960 err = skb->len;
6961out_err:
6962 rtnl_unlock();
6963 return err;
6964}
6965
Johannes Bergb6863032015-10-15 09:25:18 +02006966#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6967static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6968 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6969 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6970 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6971 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6972 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6973 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6974 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6975};
6976
6977static int parse_reg_rule(struct nlattr *tb[],
6978 struct ieee80211_reg_rule *reg_rule)
6979{
6980 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6981 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6982
6983 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6984 return -EINVAL;
6985 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6986 return -EINVAL;
6987 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6988 return -EINVAL;
6989 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6990 return -EINVAL;
6991 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6992 return -EINVAL;
6993
6994 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6995
6996 freq_range->start_freq_khz =
6997 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6998 freq_range->end_freq_khz =
6999 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7000 freq_range->max_bandwidth_khz =
7001 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7002
7003 power_rule->max_eirp =
7004 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7005
7006 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7007 power_rule->max_antenna_gain =
7008 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7009
7010 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7011 reg_rule->dfs_cac_ms =
7012 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7013
7014 return 0;
7015}
7016
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007017static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7018{
7019 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7020 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007021 char *alpha2;
7022 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007023 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007024 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007025 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007026
7027 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7028 return -EINVAL;
7029
7030 if (!info->attrs[NL80211_ATTR_REG_RULES])
7031 return -EINVAL;
7032
7033 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7034
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007035 if (info->attrs[NL80211_ATTR_DFS_REGION])
7036 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7037
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007038 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007039 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007040 num_rules++;
7041 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007042 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007043 }
7044
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007045 if (!reg_is_valid_request(alpha2))
7046 return -EINVAL;
7047
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007048 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007049 if (!rd)
7050 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007051
7052 rd->n_reg_rules = num_rules;
7053 rd->alpha2[0] = alpha2[0];
7054 rd->alpha2[1] = alpha2[1];
7055
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007056 /*
7057 * Disable DFS master mode if the DFS region was
7058 * not supported or known on this kernel.
7059 */
7060 if (reg_supported_dfs_region(dfs_region))
7061 rd->dfs_region = dfs_region;
7062
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007063 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007064 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007065 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7066 nl_reg_rule, reg_rule_policy,
7067 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007068 if (r)
7069 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007070 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7071 if (r)
7072 goto bad_reg;
7073
7074 rule_idx++;
7075
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007076 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7077 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007078 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007079 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007080 }
7081
Johannes Berg06627992016-06-09 10:40:09 +02007082 /* set_regdom takes ownership of rd */
7083 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007084 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007085 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007086 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007087}
Johannes Bergb6863032015-10-15 09:25:18 +02007088#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007089
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007090static int validate_scan_freqs(struct nlattr *freqs)
7091{
7092 struct nlattr *attr1, *attr2;
7093 int n_channels = 0, tmp1, tmp2;
7094
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007095 nla_for_each_nested(attr1, freqs, tmp1)
7096 if (nla_len(attr1) != sizeof(u32))
7097 return 0;
7098
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007099 nla_for_each_nested(attr1, freqs, tmp1) {
7100 n_channels++;
7101 /*
7102 * Some hardware has a limited channel list for
7103 * scanning, and it is pretty much nonsensical
7104 * to scan for a channel twice, so disallow that
7105 * and don't require drivers to check that the
7106 * channel list they get isn't longer than what
7107 * they can scan, as long as they can scan all
7108 * the channels they registered at once.
7109 */
7110 nla_for_each_nested(attr2, freqs, tmp2)
7111 if (attr1 != attr2 &&
7112 nla_get_u32(attr1) == nla_get_u32(attr2))
7113 return 0;
7114 }
7115
7116 return n_channels;
7117}
7118
Johannes Berg57fbcce2016-04-12 15:56:15 +02007119static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007120{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007121 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007122}
7123
7124static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7125 struct cfg80211_bss_selection *bss_select)
7126{
7127 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7128 struct nlattr *nest;
7129 int err;
7130 bool found = false;
7131 int i;
7132
7133 /* only process one nested attribute */
7134 nest = nla_data(nla);
7135 if (!nla_ok(nest, nla_len(nest)))
7136 return -EINVAL;
7137
Johannes Berg8cb08172019-04-26 14:07:28 +02007138 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7139 nest, nl80211_bss_select_policy,
7140 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007141 if (err)
7142 return err;
7143
7144 /* only one attribute may be given */
7145 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7146 if (attr[i]) {
7147 if (found)
7148 return -EINVAL;
7149 found = true;
7150 }
7151 }
7152
7153 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7154
7155 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7156 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7157
7158 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7159 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7160 bss_select->param.band_pref =
7161 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7162 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7163 return -EINVAL;
7164 }
7165
7166 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7167 struct nl80211_bss_select_rssi_adjust *adj_param;
7168
7169 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7170 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7171 bss_select->param.adjust.band = adj_param->band;
7172 bss_select->param.adjust.delta = adj_param->delta;
7173 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7174 return -EINVAL;
7175 }
7176
7177 /* user-space did not provide behaviour attribute */
7178 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7179 return -EINVAL;
7180
7181 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7182 return -EINVAL;
7183
7184 return 0;
7185}
7186
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007187int nl80211_parse_random_mac(struct nlattr **attrs,
7188 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007189{
7190 int i;
7191
7192 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007193 eth_zero_addr(mac_addr);
7194 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007195 mac_addr[0] = 0x2;
7196 mac_addr_mask[0] = 0x3;
7197
7198 return 0;
7199 }
7200
7201 /* need both or none */
7202 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7203 return -EINVAL;
7204
7205 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7206 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7207
7208 /* don't allow or configure an mcast address */
7209 if (!is_multicast_ether_addr(mac_addr_mask) ||
7210 is_multicast_ether_addr(mac_addr))
7211 return -EINVAL;
7212
7213 /*
7214 * allow users to pass a MAC address that has bits set outside
7215 * of the mask, but don't bother drivers with having to deal
7216 * with such bits
7217 */
7218 for (i = 0; i < ETH_ALEN; i++)
7219 mac_addr[i] &= mac_addr_mask[i];
7220
7221 return 0;
7222}
7223
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307224static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7225{
7226 ASSERT_WDEV_LOCK(wdev);
7227
7228 if (!cfg80211_beaconing_iface_active(wdev))
7229 return true;
7230
7231 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7232 return true;
7233
7234 return regulatory_pre_cac_allowed(wdev->wiphy);
7235}
7236
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007237static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7238 enum nl80211_ext_feature_index feat)
7239{
7240 if (!(flags & flag))
7241 return true;
7242 if (wiphy_ext_feature_isset(wiphy, feat))
7243 return true;
7244 return false;
7245}
7246
Roee Zamir2d23d072017-08-06 11:38:22 +03007247static int
7248nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7249 void *request, struct nlattr **attrs,
7250 bool is_sched_scan)
7251{
7252 u8 *mac_addr, *mac_addr_mask;
7253 u32 *flags;
7254 enum nl80211_feature_flags randomness_flag;
7255
7256 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7257 return 0;
7258
7259 if (is_sched_scan) {
7260 struct cfg80211_sched_scan_request *req = request;
7261
7262 randomness_flag = wdev ?
7263 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7264 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7265 flags = &req->flags;
7266 mac_addr = req->mac_addr;
7267 mac_addr_mask = req->mac_addr_mask;
7268 } else {
7269 struct cfg80211_scan_request *req = request;
7270
7271 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7272 flags = &req->flags;
7273 mac_addr = req->mac_addr;
7274 mac_addr_mask = req->mac_addr_mask;
7275 }
7276
7277 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7278
Sunil Dutt5037a002018-01-25 17:13:37 +02007279 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7280 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007281 !nl80211_check_scan_feat(wiphy, *flags,
7282 NL80211_SCAN_FLAG_LOW_SPAN,
7283 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7284 !nl80211_check_scan_feat(wiphy, *flags,
7285 NL80211_SCAN_FLAG_LOW_POWER,
7286 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7287 !nl80211_check_scan_feat(wiphy, *flags,
7288 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7289 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7290 !nl80211_check_scan_feat(wiphy, *flags,
7291 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7292 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7293 !nl80211_check_scan_feat(wiphy, *flags,
7294 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7295 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7296 !nl80211_check_scan_feat(wiphy, *flags,
7297 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7298 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7299 !nl80211_check_scan_feat(wiphy, *flags,
7300 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007301 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7302 !nl80211_check_scan_feat(wiphy, *flags,
7303 NL80211_SCAN_FLAG_RANDOM_SN,
7304 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7305 !nl80211_check_scan_feat(wiphy, *flags,
7306 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7307 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007308 return -EOPNOTSUPP;
7309
7310 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7311 int err;
7312
7313 if (!(wiphy->features & randomness_flag) ||
7314 (wdev && wdev->current_bss))
7315 return -EOPNOTSUPP;
7316
7317 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7318 if (err)
7319 return err;
7320 }
7321
Roee Zamir2d23d072017-08-06 11:38:22 +03007322 return 0;
7323}
7324
Johannes Berg2a519312009-02-10 21:25:55 +01007325static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7326{
Johannes Berg4c476992010-10-04 21:36:35 +02007327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007328 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007329 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007330 struct nlattr *attr;
7331 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007332 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007333 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007334
Johannes Berg79c97e92009-07-07 03:56:12 +02007335 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007336
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007337 if (wdev->iftype == NL80211_IFTYPE_NAN)
7338 return -EOPNOTSUPP;
7339
Johannes Berg4c476992010-10-04 21:36:35 +02007340 if (!rdev->ops->scan)
7341 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007342
Johannes Bergf9d15d12014-01-22 11:14:19 +02007343 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007344 err = -EBUSY;
7345 goto unlock;
7346 }
Johannes Berg2a519312009-02-10 21:25:55 +01007347
7348 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007349 n_channels = validate_scan_freqs(
7350 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007351 if (!n_channels) {
7352 err = -EINVAL;
7353 goto unlock;
7354 }
Johannes Berg2a519312009-02-10 21:25:55 +01007355 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007356 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007357 }
7358
7359 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7360 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7361 n_ssids++;
7362
Johannes Bergf9f47522013-03-19 15:04:07 +01007363 if (n_ssids > wiphy->max_scan_ssids) {
7364 err = -EINVAL;
7365 goto unlock;
7366 }
Johannes Berg2a519312009-02-10 21:25:55 +01007367
Jouni Malinen70692ad2009-02-16 19:39:13 +02007368 if (info->attrs[NL80211_ATTR_IE])
7369 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7370 else
7371 ie_len = 0;
7372
Johannes Bergf9f47522013-03-19 15:04:07 +01007373 if (ie_len > wiphy->max_scan_ie_len) {
7374 err = -EINVAL;
7375 goto unlock;
7376 }
Johannes Berg18a83652009-03-31 12:12:05 +02007377
Johannes Berg2a519312009-02-10 21:25:55 +01007378 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007379 + sizeof(*request->ssids) * n_ssids
7380 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007381 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007382 if (!request) {
7383 err = -ENOMEM;
7384 goto unlock;
7385 }
Johannes Berg2a519312009-02-10 21:25:55 +01007386
Johannes Berg2a519312009-02-10 21:25:55 +01007387 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007388 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007389 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007390 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007391 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007392 request->ie = (void *)(request->ssids + n_ssids);
7393 else
7394 request->ie = (void *)(request->channels + n_channels);
7395 }
Johannes Berg2a519312009-02-10 21:25:55 +01007396
Johannes Berg584991d2009-11-02 13:32:03 +01007397 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007398 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7399 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007400 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007401 struct ieee80211_channel *chan;
7402
7403 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7404
7405 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007406 err = -EINVAL;
7407 goto out_free;
7408 }
Johannes Berg584991d2009-11-02 13:32:03 +01007409
7410 /* ignore disabled channels */
7411 if (chan->flags & IEEE80211_CHAN_DISABLED)
7412 continue;
7413
7414 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007415 i++;
7416 }
7417 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007418 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007419
Johannes Berg2a519312009-02-10 21:25:55 +01007420 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007421 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007422 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007423
Johannes Berg2a519312009-02-10 21:25:55 +01007424 if (!wiphy->bands[band])
7425 continue;
7426 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007427 struct ieee80211_channel *chan;
7428
7429 chan = &wiphy->bands[band]->channels[j];
7430
7431 if (chan->flags & IEEE80211_CHAN_DISABLED)
7432 continue;
7433
7434 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007435 i++;
7436 }
7437 }
7438 }
7439
Johannes Berg584991d2009-11-02 13:32:03 +01007440 if (!i) {
7441 err = -EINVAL;
7442 goto out_free;
7443 }
7444
7445 request->n_channels = i;
7446
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307447 wdev_lock(wdev);
7448 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7449 struct ieee80211_channel *chan;
7450
7451 if (request->n_channels != 1) {
7452 wdev_unlock(wdev);
7453 err = -EBUSY;
7454 goto out_free;
7455 }
7456
7457 chan = request->channels[0];
7458 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7459 wdev_unlock(wdev);
7460 err = -EBUSY;
7461 goto out_free;
7462 }
7463 }
7464 wdev_unlock(wdev);
7465
Johannes Berg2a519312009-02-10 21:25:55 +01007466 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007467 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007468 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007469 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007470 err = -EINVAL;
7471 goto out_free;
7472 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007473 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007474 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007475 i++;
7476 }
7477 }
7478
Jouni Malinen70692ad2009-02-16 19:39:13 +02007479 if (info->attrs[NL80211_ATTR_IE]) {
7480 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007481 memcpy((void *)request->ie,
7482 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007483 request->ie_len);
7484 }
7485
Johannes Berg57fbcce2016-04-12 15:56:15 +02007486 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007487 if (wiphy->bands[i])
7488 request->rates[i] =
7489 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007490
7491 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7492 nla_for_each_nested(attr,
7493 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7494 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007495 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007496
Johannes Berg57fbcce2016-04-12 15:56:15 +02007497 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007498 err = -EINVAL;
7499 goto out_free;
7500 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007501
7502 if (!wiphy->bands[band])
7503 continue;
7504
Johannes Berg34850ab2011-07-18 18:08:35 +02007505 err = ieee80211_get_ratemask(wiphy->bands[band],
7506 nla_data(attr),
7507 nla_len(attr),
7508 &request->rates[band]);
7509 if (err)
7510 goto out_free;
7511 }
7512 }
7513
Avraham Stern1d762502016-07-05 17:10:13 +03007514 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7515 if (!wiphy_ext_feature_isset(wiphy,
7516 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7517 err = -EOPNOTSUPP;
7518 goto out_free;
7519 }
7520
7521 request->duration =
7522 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7523 request->duration_mandatory =
7524 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7525 }
7526
Roee Zamir2d23d072017-08-06 11:38:22 +03007527 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7528 false);
7529 if (err)
7530 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007531
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307532 request->no_cck =
7533 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7534
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007535 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7536 * BSSID to scan for. This was problematic because that same attribute
7537 * was already used for another purpose (local random MAC address). The
7538 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7539 * compatibility with older userspace components, also use the
7540 * NL80211_ATTR_MAC value here if it can be determined to be used for
7541 * the specific BSSID use case instead of the random MAC address
7542 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7543 */
7544 if (info->attrs[NL80211_ATTR_BSSID])
7545 memcpy(request->bssid,
7546 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7547 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7548 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007549 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7550 ETH_ALEN);
7551 else
7552 eth_broadcast_addr(request->bssid);
7553
Johannes Bergfd014282012-06-18 19:17:03 +02007554 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007555 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007556 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007557
Johannes Berg79c97e92009-07-07 03:56:12 +02007558 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007559 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007560
Johannes Berg463d0182009-07-14 00:33:35 +02007561 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007562 nl80211_send_scan_start(rdev, wdev);
7563 if (wdev->netdev)
7564 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007565 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007566 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007567 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007568 kfree(request);
7569 }
Johannes Berg3b858752009-03-12 09:55:09 +01007570
Johannes Bergf9f47522013-03-19 15:04:07 +01007571 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007572 return err;
7573}
7574
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307575static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7576{
7577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7578 struct wireless_dev *wdev = info->user_ptr[1];
7579
7580 if (!rdev->ops->abort_scan)
7581 return -EOPNOTSUPP;
7582
7583 if (rdev->scan_msg)
7584 return 0;
7585
7586 if (!rdev->scan_req)
7587 return -ENOENT;
7588
7589 rdev_abort_scan(rdev, wdev);
7590 return 0;
7591}
7592
Avraham Stern3b06d272015-10-12 09:51:34 +03007593static int
7594nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7595 struct cfg80211_sched_scan_request *request,
7596 struct nlattr **attrs)
7597{
7598 int tmp, err, i = 0;
7599 struct nlattr *attr;
7600
7601 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7602 u32 interval;
7603
7604 /*
7605 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007606 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007607 * case one scan plan will be set with the specified scan
7608 * interval and infinite number of iterations.
7609 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007610 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7611 if (!interval)
7612 return -EINVAL;
7613
7614 request->scan_plans[0].interval =
7615 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7616 if (!request->scan_plans[0].interval)
7617 return -EINVAL;
7618
7619 if (request->scan_plans[0].interval >
7620 wiphy->max_sched_scan_plan_interval)
7621 request->scan_plans[0].interval =
7622 wiphy->max_sched_scan_plan_interval;
7623
7624 return 0;
7625 }
7626
7627 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7628 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7629
7630 if (WARN_ON(i >= n_plans))
7631 return -EINVAL;
7632
Johannes Berg8cb08172019-04-26 14:07:28 +02007633 err = nla_parse_nested_deprecated(plan,
7634 NL80211_SCHED_SCAN_PLAN_MAX,
7635 attr, nl80211_plan_policy,
7636 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007637 if (err)
7638 return err;
7639
7640 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7641 return -EINVAL;
7642
7643 request->scan_plans[i].interval =
7644 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7645 if (!request->scan_plans[i].interval ||
7646 request->scan_plans[i].interval >
7647 wiphy->max_sched_scan_plan_interval)
7648 return -EINVAL;
7649
7650 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7651 request->scan_plans[i].iterations =
7652 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7653 if (!request->scan_plans[i].iterations ||
7654 (request->scan_plans[i].iterations >
7655 wiphy->max_sched_scan_plan_iterations))
7656 return -EINVAL;
7657 } else if (i < n_plans - 1) {
7658 /*
7659 * All scan plans but the last one must specify
7660 * a finite number of iterations
7661 */
7662 return -EINVAL;
7663 }
7664
7665 i++;
7666 }
7667
7668 /*
7669 * The last scan plan must not specify the number of
7670 * iterations, it is supposed to run infinitely
7671 */
7672 if (request->scan_plans[n_plans - 1].iterations)
7673 return -EINVAL;
7674
7675 return 0;
7676}
7677
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307678static int
7679nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7680 struct cfg80211_match_set *match_sets,
7681 struct nlattr *tb_band_rssi,
7682 s32 rssi_thold)
7683{
7684 struct nlattr *attr;
7685 int i, tmp, ret = 0;
7686
7687 if (!wiphy_ext_feature_isset(wiphy,
7688 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7689 if (tb_band_rssi)
7690 ret = -EOPNOTSUPP;
7691 else
7692 for (i = 0; i < NUM_NL80211_BANDS; i++)
7693 match_sets->per_band_rssi_thold[i] =
7694 NL80211_SCAN_RSSI_THOLD_OFF;
7695 return ret;
7696 }
7697
7698 for (i = 0; i < NUM_NL80211_BANDS; i++)
7699 match_sets->per_band_rssi_thold[i] = rssi_thold;
7700
7701 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7702 enum nl80211_band band = nla_type(attr);
7703
7704 if (band < 0 || band >= NUM_NL80211_BANDS)
7705 return -EINVAL;
7706
7707 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7708 }
7709
7710 return 0;
7711}
7712
Luciano Coelho256da022014-11-10 16:13:46 +02007713static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007714nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007715 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007716{
7717 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007718 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007719 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007720 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007721 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007722 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007723 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007724
Luciano Coelho256da022014-11-10 16:13:46 +02007725 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007726 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007727 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007728 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007729 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007730 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007731 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007732 }
7733
Luciano Coelho256da022014-11-10 16:13:46 +02007734 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7735 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007736 tmp)
7737 n_ssids++;
7738
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007739 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007740 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007741
Johannes Bergea73cbc2014-01-24 10:53:53 +01007742 /*
7743 * First, count the number of 'real' matchsets. Due to an issue with
7744 * the old implementation, matchsets containing only the RSSI attribute
7745 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7746 * RSSI for all matchsets, rather than their own matchset for reporting
7747 * all APs with a strong RSSI. This is needed to be compatible with
7748 * older userspace that treated a matchset with only the RSSI as the
7749 * global RSSI for all other matchsets - if there are other matchsets.
7750 */
Luciano Coelho256da022014-11-10 16:13:46 +02007751 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007752 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007753 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007754 tmp) {
7755 struct nlattr *rssi;
7756
Johannes Berg8cb08172019-04-26 14:07:28 +02007757 err = nla_parse_nested_deprecated(tb,
7758 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7759 attr,
7760 nl80211_match_policy,
7761 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007762 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007763 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007764
7765 /* SSID and BSSID are mutually exclusive */
7766 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7767 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7768 return ERR_PTR(-EINVAL);
7769
Johannes Bergea73cbc2014-01-24 10:53:53 +01007770 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007771 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7772 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007773 n_match_sets++;
7774 continue;
7775 }
7776 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7777 if (rssi)
7778 default_match_rssi = nla_get_s32(rssi);
7779 }
7780 }
7781
7782 /* However, if there's no other matchset, add the RSSI one */
7783 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7784 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007785
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007786 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007787 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007788
Luciano Coelho256da022014-11-10 16:13:46 +02007789 if (attrs[NL80211_ATTR_IE])
7790 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007791 else
7792 ie_len = 0;
7793
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007794 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007795 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007796
Avraham Stern3b06d272015-10-12 09:51:34 +03007797 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7798 /*
7799 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7800 * each scan plan already specifies its own interval
7801 */
7802 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7803 return ERR_PTR(-EINVAL);
7804
7805 nla_for_each_nested(attr,
7806 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7807 n_plans++;
7808 } else {
7809 /*
7810 * The scan interval attribute is kept for backward
7811 * compatibility. If no scan plans are specified and sched scan
7812 * interval is specified, one scan plan will be set with this
7813 * scan interval and infinite number of iterations.
7814 */
7815 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7816 return ERR_PTR(-EINVAL);
7817
7818 n_plans = 1;
7819 }
7820
7821 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7822 return ERR_PTR(-EINVAL);
7823
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007824 if (!wiphy_ext_feature_isset(
7825 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7826 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7827 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7828 return ERR_PTR(-EINVAL);
7829
Luciano Coelho807f8a82011-05-11 17:09:35 +03007830 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007831 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007832 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007833 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007834 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007835 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007836 if (!request)
7837 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007838
7839 if (n_ssids)
7840 request->ssids = (void *)&request->channels[n_channels];
7841 request->n_ssids = n_ssids;
7842 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007843 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007844 request->ie = (void *)(request->ssids + n_ssids);
7845 else
7846 request->ie = (void *)(request->channels + n_channels);
7847 }
7848
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007849 if (n_match_sets) {
7850 if (request->ie)
7851 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007852 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007853 request->match_sets =
7854 (void *)(request->ssids + n_ssids);
7855 else
7856 request->match_sets =
7857 (void *)(request->channels + n_channels);
7858 }
7859 request->n_match_sets = n_match_sets;
7860
Avraham Stern3b06d272015-10-12 09:51:34 +03007861 if (n_match_sets)
7862 request->scan_plans = (void *)(request->match_sets +
7863 n_match_sets);
7864 else if (request->ie)
7865 request->scan_plans = (void *)(request->ie + ie_len);
7866 else if (n_ssids)
7867 request->scan_plans = (void *)(request->ssids + n_ssids);
7868 else
7869 request->scan_plans = (void *)(request->channels + n_channels);
7870
7871 request->n_scan_plans = n_plans;
7872
Luciano Coelho807f8a82011-05-11 17:09:35 +03007873 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007874 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007875 /* user specified, bail out if channel not found */
7876 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007877 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007878 tmp) {
7879 struct ieee80211_channel *chan;
7880
7881 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7882
7883 if (!chan) {
7884 err = -EINVAL;
7885 goto out_free;
7886 }
7887
7888 /* ignore disabled channels */
7889 if (chan->flags & IEEE80211_CHAN_DISABLED)
7890 continue;
7891
7892 request->channels[i] = chan;
7893 i++;
7894 }
7895 } else {
7896 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007897 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007898 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007899
Luciano Coelho807f8a82011-05-11 17:09:35 +03007900 if (!wiphy->bands[band])
7901 continue;
7902 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7903 struct ieee80211_channel *chan;
7904
7905 chan = &wiphy->bands[band]->channels[j];
7906
7907 if (chan->flags & IEEE80211_CHAN_DISABLED)
7908 continue;
7909
7910 request->channels[i] = chan;
7911 i++;
7912 }
7913 }
7914 }
7915
7916 if (!i) {
7917 err = -EINVAL;
7918 goto out_free;
7919 }
7920
7921 request->n_channels = i;
7922
7923 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007924 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007925 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007926 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007927 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007928 err = -EINVAL;
7929 goto out_free;
7930 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007931 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007932 memcpy(request->ssids[i].ssid, nla_data(attr),
7933 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007934 i++;
7935 }
7936 }
7937
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007938 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007939 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007940 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007941 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007942 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007943 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007944
Johannes Berg8cb08172019-04-26 14:07:28 +02007945 err = nla_parse_nested_deprecated(tb,
7946 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7947 attr,
7948 nl80211_match_policy,
7949 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007950 if (err)
7951 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007952 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007953 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02007954
7955 if (!ssid && !bssid) {
7956 i++;
7957 continue;
7958 }
7959
7960 if (WARN_ON(i >= n_match_sets)) {
7961 /* this indicates a programming error,
7962 * the loop above should have verified
7963 * things properly
7964 */
7965 err = -EINVAL;
7966 goto out_free;
7967 }
7968
7969 if (ssid) {
7970 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007971 err = -EINVAL;
7972 goto out_free;
7973 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02007974 memcpy(request->match_sets[i].ssid.ssid,
7975 nla_data(ssid), nla_len(ssid));
7976 request->match_sets[i].ssid.ssid_len =
7977 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007978 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02007979 if (bssid) {
7980 if (nla_len(bssid) != ETH_ALEN) {
7981 err = -EINVAL;
7982 goto out_free;
7983 }
7984 memcpy(request->match_sets[i].bssid,
7985 nla_data(bssid), ETH_ALEN);
7986 }
7987
7988 /* special attribute - old implementation w/a */
7989 request->match_sets[i].rssi_thold = default_match_rssi;
7990 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7991 if (rssi)
7992 request->match_sets[i].rssi_thold =
7993 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307994
7995 /* Parse per band RSSI attribute */
7996 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
7997 &request->match_sets[i],
7998 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
7999 request->match_sets[i].rssi_thold);
8000 if (err)
8001 goto out_free;
8002
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008003 i++;
8004 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008005
8006 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008007 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008008 request->match_sets[0].rssi_thold = default_match_rssi;
8009
8010 request->min_rssi_thold = INT_MAX;
8011 for (i = 0; i < n_match_sets; i++)
8012 request->min_rssi_thold =
8013 min(request->match_sets[i].rssi_thold,
8014 request->min_rssi_thold);
8015 } else {
8016 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008017 }
8018
Johannes Berg9900e482014-02-04 21:01:25 +01008019 if (ie_len) {
8020 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008021 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008022 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008023 request->ie_len);
8024 }
8025
Roee Zamir2d23d072017-08-06 11:38:22 +03008026 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8027 if (err)
8028 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008029
Luciano Coelho9c748932015-01-16 16:04:09 +02008030 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8031 request->delay =
8032 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8033
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008034 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8035 request->relative_rssi = nla_get_s8(
8036 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8037 request->relative_rssi_set = true;
8038 }
8039
8040 if (request->relative_rssi_set &&
8041 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8042 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8043
8044 rssi_adjust = nla_data(
8045 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8046 request->rssi_adjust.band = rssi_adjust->band;
8047 request->rssi_adjust.delta = rssi_adjust->delta;
8048 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8049 err = -EINVAL;
8050 goto out_free;
8051 }
8052 }
8053
Avraham Stern3b06d272015-10-12 09:51:34 +03008054 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8055 if (err)
8056 goto out_free;
8057
Sam Leffler15d60302012-10-11 21:03:34 -07008058 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008059
Luciano Coelho256da022014-11-10 16:13:46 +02008060 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008061
8062out_free:
8063 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008064 return ERR_PTR(err);
8065}
8066
8067static int nl80211_start_sched_scan(struct sk_buff *skb,
8068 struct genl_info *info)
8069{
8070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8071 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008072 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008073 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008074 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008075 int err;
8076
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008077 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008078 return -EOPNOTSUPP;
8079
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008080 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8081 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8082 if (err)
8083 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008084
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008085 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008086 info->attrs,
8087 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008088
8089 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008090 if (err)
8091 goto out_err;
8092
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008093 /* leave request id zero for legacy request
8094 * or if driver does not support multi-scheduled scan
8095 */
8096 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
8097 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02008098 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008099 }
8100
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008101 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008102 if (err)
8103 goto out_free;
8104
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008105 sched_scan_req->dev = dev;
8106 sched_scan_req->wiphy = &rdev->wiphy;
8107
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008108 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8109 sched_scan_req->owner_nlportid = info->snd_portid;
8110
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008111 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008112
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008113 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008114 return 0;
8115
8116out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008117 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008118out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008119 return err;
8120}
8121
8122static int nl80211_stop_sched_scan(struct sk_buff *skb,
8123 struct genl_info *info)
8124{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008125 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008127 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008128
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008129 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008130 return -EOPNOTSUPP;
8131
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008132 if (info->attrs[NL80211_ATTR_COOKIE]) {
8133 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8134 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8135 }
8136
8137 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8138 struct cfg80211_sched_scan_request,
8139 list);
8140 if (!req || req->reqid ||
8141 (req->owner_nlportid &&
8142 req->owner_nlportid != info->snd_portid))
8143 return -ENOENT;
8144
8145 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008146}
8147
Simon Wunderlich04f39042013-02-08 18:16:19 +01008148static int nl80211_start_radar_detection(struct sk_buff *skb,
8149 struct genl_info *info)
8150{
8151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8152 struct net_device *dev = info->user_ptr[1];
8153 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008154 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008155 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008156 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008157 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008158 int err;
8159
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008160 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008161 if (dfs_region == NL80211_DFS_UNSET)
8162 return -EINVAL;
8163
Simon Wunderlich04f39042013-02-08 18:16:19 +01008164 err = nl80211_parse_chandef(rdev, info, &chandef);
8165 if (err)
8166 return err;
8167
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008168 if (netif_carrier_ok(dev))
8169 return -EBUSY;
8170
Simon Wunderlich04f39042013-02-08 18:16:19 +01008171 if (wdev->cac_started)
8172 return -EBUSY;
8173
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008174 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008175 if (err < 0)
8176 return err;
8177
8178 if (err == 0)
8179 return -EINVAL;
8180
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008181 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008182 return -EINVAL;
8183
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008184 /* CAC start is offloaded to HW and can't be started manually */
8185 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8186 return -EOPNOTSUPP;
8187
Simon Wunderlich04f39042013-02-08 18:16:19 +01008188 if (!rdev->ops->start_radar_detection)
8189 return -EOPNOTSUPP;
8190
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008191 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8192 if (WARN_ON(!cac_time_ms))
8193 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8194
Ilan Peera1056b1b2015-10-22 22:27:46 +03008195 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008196 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008197 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008198 wdev->cac_started = true;
8199 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008200 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008201 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008202 return err;
8203}
8204
Sriram R30c63112018-12-04 17:46:52 +05308205static int nl80211_notify_radar_detection(struct sk_buff *skb,
8206 struct genl_info *info)
8207{
8208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8209 struct net_device *dev = info->user_ptr[1];
8210 struct wireless_dev *wdev = dev->ieee80211_ptr;
8211 struct wiphy *wiphy = wdev->wiphy;
8212 struct cfg80211_chan_def chandef;
8213 enum nl80211_dfs_regions dfs_region;
8214 int err;
8215
8216 dfs_region = reg_get_dfs_region(wiphy);
8217 if (dfs_region == NL80211_DFS_UNSET) {
8218 GENL_SET_ERR_MSG(info,
8219 "DFS Region is not set. Unexpected Radar indication");
8220 return -EINVAL;
8221 }
8222
8223 err = nl80211_parse_chandef(rdev, info, &chandef);
8224 if (err) {
8225 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8226 return err;
8227 }
8228
8229 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8230 if (err < 0) {
8231 GENL_SET_ERR_MSG(info, "chandef is invalid");
8232 return err;
8233 }
8234
8235 if (err == 0) {
8236 GENL_SET_ERR_MSG(info,
8237 "Unexpected Radar indication for chandef/iftype");
8238 return -EINVAL;
8239 }
8240
8241 /* Do not process this notification if radar is already detected
8242 * by kernel on this channel, and return success.
8243 */
8244 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8245 return 0;
8246
8247 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8248
8249 cfg80211_sched_dfs_chan_update(rdev);
8250
Luca Coelhoa680fe42019-04-17 09:34:40 +03008251 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308252
8253 /* Propagate this notification to other radios as well */
8254 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8255
8256 return 0;
8257}
8258
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008259static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8260{
8261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8262 struct net_device *dev = info->user_ptr[1];
8263 struct wireless_dev *wdev = dev->ieee80211_ptr;
8264 struct cfg80211_csa_settings params;
8265 /* csa_attrs is defined static to avoid waste of stack size - this
8266 * function is called under RTNL lock, so this should not be a problem.
8267 */
8268 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008269 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008270 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008271 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008272 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008273 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008274
8275 if (!rdev->ops->channel_switch ||
8276 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8277 return -EOPNOTSUPP;
8278
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008279 switch (dev->ieee80211_ptr->iftype) {
8280 case NL80211_IFTYPE_AP:
8281 case NL80211_IFTYPE_P2P_GO:
8282 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008283 /* For all modes except AP the handle_dfs flag needs to be
8284 * supplied to tell the kernel that userspace will handle radar
8285 * events when they happen. Otherwise a switch to a channel
8286 * requiring DFS will be rejected.
8287 */
8288 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008289
8290 /* useless if AP is not running */
8291 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008292 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008293 break;
8294 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008295 if (!wdev->ssid_len)
8296 return -ENOTCONN;
8297 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008298 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008299 if (!wdev->mesh_id_len)
8300 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008301 break;
8302 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008303 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008304 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008305
8306 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008307 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008308
8309 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8310 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8311 return -EINVAL;
8312
8313 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008314 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008315 return -EINVAL;
8316
Luciano Coelho252e07c2014-10-08 09:48:34 +03008317 /* Even though the attribute is u32, the specification says
8318 * u8, so let's make sure we don't overflow.
8319 */
8320 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8321 if (cs_count > 255)
8322 return -EINVAL;
8323
8324 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008325
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008326 if (!need_new_beacon)
8327 goto skip_beacons;
8328
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008329 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008330 if (err)
8331 return err;
8332
Johannes Berg8cb08172019-04-26 14:07:28 +02008333 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8334 info->attrs[NL80211_ATTR_CSA_IES],
8335 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008336 if (err)
8337 return err;
8338
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008339 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008340 if (err)
8341 return err;
8342
8343 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8344 return -EINVAL;
8345
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008346 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8347 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008348 return -EINVAL;
8349
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008350 params.n_counter_offsets_beacon = len / sizeof(u16);
8351 if (rdev->wiphy.max_num_csa_counters &&
8352 (params.n_counter_offsets_beacon >
8353 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008354 return -EINVAL;
8355
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008356 params.counter_offsets_beacon =
8357 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8358
8359 /* sanity checks - counters should fit and be the same */
8360 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8361 u16 offset = params.counter_offsets_beacon[i];
8362
8363 if (offset >= params.beacon_csa.tail_len)
8364 return -EINVAL;
8365
8366 if (params.beacon_csa.tail[offset] != params.count)
8367 return -EINVAL;
8368 }
8369
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008370 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008371 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8372 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008373 return -EINVAL;
8374
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008375 params.n_counter_offsets_presp = len / sizeof(u16);
8376 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008377 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008378 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008379 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008380
8381 params.counter_offsets_presp =
8382 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8383
8384 /* sanity checks - counters should fit and be the same */
8385 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8386 u16 offset = params.counter_offsets_presp[i];
8387
8388 if (offset >= params.beacon_csa.probe_resp_len)
8389 return -EINVAL;
8390
8391 if (params.beacon_csa.probe_resp[offset] !=
8392 params.count)
8393 return -EINVAL;
8394 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008395 }
8396
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008397skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008398 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8399 if (err)
8400 return err;
8401
Arik Nemtsov923b3522015-07-08 15:41:44 +03008402 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8403 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008404 return -EINVAL;
8405
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008406 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8407 &params.chandef,
8408 wdev->iftype);
8409 if (err < 0)
8410 return err;
8411
Benjamin Berg8d9de162017-05-16 11:23:12 +02008412 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008413 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008414 if (need_handle_dfs_flag &&
8415 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8416 return -EINVAL;
8417 }
8418 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008419
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008420 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8421 params.block_tx = true;
8422
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008423 wdev_lock(wdev);
8424 err = rdev_channel_switch(rdev, dev, &params);
8425 wdev_unlock(wdev);
8426
8427 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008428}
8429
Johannes Berg9720bb32011-06-21 09:45:33 +02008430static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8431 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008432 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008433 struct wireless_dev *wdev,
8434 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008435{
Johannes Berg48ab9052009-07-10 18:42:31 +02008436 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008437 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008438 void *hdr;
8439 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008440
8441 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008442
Eric W. Biederman15e47302012-09-07 20:12:54 +00008443 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008444 NL80211_CMD_NEW_SCAN_RESULTS);
8445 if (!hdr)
8446 return -1;
8447
Michal Kubecek0a833c22017-11-15 13:09:32 +01008448 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008449
Johannes Berg97990a02013-04-19 01:02:55 +02008450 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8451 goto nla_put_failure;
8452 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008453 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8454 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008455 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8456 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008457 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008458
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008459 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01008460 if (!bss)
8461 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008462 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008463 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008464 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008465
8466 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008467 /* indicate whether we have probe response data or not */
8468 if (rcu_access_pointer(res->proberesp_ies) &&
8469 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8470 goto fail_unlock_rcu;
8471
8472 /* this pointer prefers to be pointed to probe response data
8473 * but is always valid
8474 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008475 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008476 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008477 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8478 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008479 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008480 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8481 ies->len, ies->data))
8482 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008483 }
Johannes Berg0e227082014-08-12 20:34:30 +02008484
8485 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008486 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008487 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008488 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8489 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008490 goto fail_unlock_rcu;
8491 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8492 ies->len, ies->data))
8493 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008494 }
8495 rcu_read_unlock();
8496
David S. Miller9360ffd2012-03-29 04:41:26 -04008497 if (res->beacon_interval &&
8498 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8499 goto nla_put_failure;
8500 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8501 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008502 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008503 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8504 jiffies_to_msecs(jiffies - intbss->ts)))
8505 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008506
Avraham Stern1d762502016-07-05 17:10:13 +03008507 if (intbss->parent_tsf &&
8508 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8509 intbss->parent_tsf, NL80211_BSS_PAD) ||
8510 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8511 intbss->parent_bssid)))
8512 goto nla_put_failure;
8513
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008514 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008515 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8516 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008517 goto nla_put_failure;
8518
Sunil Dutt983dafa2017-12-13 19:51:36 +02008519 if (!nl80211_put_signal(msg, intbss->pub.chains,
8520 intbss->pub.chain_signal,
8521 NL80211_BSS_CHAIN_SIGNAL))
8522 goto nla_put_failure;
8523
Johannes Berg77965c972009-02-18 18:45:06 +01008524 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008525 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008526 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8527 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008528 break;
8529 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008530 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8531 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008532 break;
8533 default:
8534 break;
8535 }
8536
Johannes Berg48ab9052009-07-10 18:42:31 +02008537 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008538 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008539 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008540 if (intbss == wdev->current_bss &&
8541 nla_put_u32(msg, NL80211_BSS_STATUS,
8542 NL80211_BSS_STATUS_ASSOCIATED))
8543 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008544 break;
8545 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008546 if (intbss == wdev->current_bss &&
8547 nla_put_u32(msg, NL80211_BSS_STATUS,
8548 NL80211_BSS_STATUS_IBSS_JOINED))
8549 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008550 break;
8551 default:
8552 break;
8553 }
8554
Johannes Berg2a519312009-02-10 21:25:55 +01008555 nla_nest_end(msg, bss);
8556
Johannes Berg053c0952015-01-16 22:09:00 +01008557 genlmsg_end(msg, hdr);
8558 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008559
Johannes Berg8cef2c92013-02-05 16:54:31 +01008560 fail_unlock_rcu:
8561 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008562 nla_put_failure:
8563 genlmsg_cancel(msg, hdr);
8564 return -EMSGSIZE;
8565}
8566
Johannes Berg97990a02013-04-19 01:02:55 +02008567static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008568{
Johannes Berg48ab9052009-07-10 18:42:31 +02008569 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008570 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008571 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008572 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008573 int err;
8574
Johannes Bergea90e0d2017-03-15 14:26:04 +01008575 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008576 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008577 if (err) {
8578 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008579 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008580 }
Johannes Berg2a519312009-02-10 21:25:55 +01008581
Johannes Berg48ab9052009-07-10 18:42:31 +02008582 wdev_lock(wdev);
8583 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008584
8585 /*
8586 * dump_scan will be called multiple times to break up the scan results
8587 * into multiple messages. It is unlikely that any more bss-es will be
8588 * expired after the first call, so only call only call this on the
8589 * first dump_scan invocation.
8590 */
8591 if (start == 0)
8592 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008593
Johannes Berg9720bb32011-06-21 09:45:33 +02008594 cb->seq = rdev->bss_generation;
8595
Johannes Berg48ab9052009-07-10 18:42:31 +02008596 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008597 if (++idx <= start)
8598 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008599 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008600 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008601 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008602 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008603 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008604 }
8605 }
8606
Johannes Berg48ab9052009-07-10 18:42:31 +02008607 spin_unlock_bh(&rdev->bss_lock);
8608 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008609
Johannes Berg97990a02013-04-19 01:02:55 +02008610 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008611 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008612
Johannes Berg67748892010-10-04 21:14:06 +02008613 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008614}
8615
Eric W. Biederman15e47302012-09-07 20:12:54 +00008616static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008617 int flags, struct net_device *dev,
8618 bool allow_radio_stats,
8619 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008620{
8621 void *hdr;
8622 struct nlattr *infoattr;
8623
Johannes Berg11f78ac2014-11-14 16:43:50 +01008624 /* skip radio stats if userspace didn't request them */
8625 if (!survey->channel && !allow_radio_stats)
8626 return 0;
8627
Eric W. Biederman15e47302012-09-07 20:12:54 +00008628 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008629 NL80211_CMD_NEW_SURVEY_RESULTS);
8630 if (!hdr)
8631 return -ENOMEM;
8632
David S. Miller9360ffd2012-03-29 04:41:26 -04008633 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8634 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008635
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008636 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01008637 if (!infoattr)
8638 goto nla_put_failure;
8639
Johannes Berg11f78ac2014-11-14 16:43:50 +01008640 if (survey->channel &&
8641 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008642 survey->channel->center_freq))
8643 goto nla_put_failure;
8644
8645 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8646 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8647 goto nla_put_failure;
8648 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8649 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8650 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008651 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008652 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8653 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008654 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008655 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008656 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8657 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008658 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008659 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008660 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8661 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008662 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008663 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008664 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8665 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008666 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008667 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008668 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8669 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008670 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008671 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008672 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8673 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008674 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008675
8676 nla_nest_end(msg, infoattr);
8677
Johannes Berg053c0952015-01-16 22:09:00 +01008678 genlmsg_end(msg, hdr);
8679 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008680
8681 nla_put_failure:
8682 genlmsg_cancel(msg, hdr);
8683 return -EMSGSIZE;
8684}
8685
Johannes Berg11f78ac2014-11-14 16:43:50 +01008686static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008687{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008688 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008689 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008690 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008691 struct wireless_dev *wdev;
8692 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008693 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008694 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008695
Johannes Bergea90e0d2017-03-15 14:26:04 +01008696 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008697 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008698 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008699 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008700
Johannes Berg11f78ac2014-11-14 16:43:50 +01008701 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008702 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008703
Johannes Berg97990a02013-04-19 01:02:55 +02008704 if (!wdev->netdev) {
8705 res = -EINVAL;
8706 goto out_err;
8707 }
8708
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008709 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008710 res = -EOPNOTSUPP;
8711 goto out_err;
8712 }
8713
8714 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008715 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008716 if (res == -ENOENT)
8717 break;
8718 if (res)
8719 goto out_err;
8720
Johannes Berg11f78ac2014-11-14 16:43:50 +01008721 /* don't send disabled channels, but do send non-channel data */
8722 if (survey.channel &&
8723 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008724 survey_idx++;
8725 continue;
8726 }
8727
Holger Schurig61fa7132009-11-11 12:25:40 +01008728 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008729 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008730 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008731 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008732 goto out;
8733 survey_idx++;
8734 }
8735
8736 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008737 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008738 res = skb->len;
8739 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008740 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008741 return res;
8742}
8743
Samuel Ortizb23aa672009-07-01 21:26:54 +02008744static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8745{
8746 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00008747 NL80211_WPA_VERSION_2 |
8748 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02008749}
8750
Jouni Malinen636a5d32009-03-19 13:39:22 +02008751static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8752{
Johannes Berg4c476992010-10-04 21:36:35 +02008753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8754 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008755 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008756 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8757 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008758 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008759 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008760 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008761
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008762 if (!info->attrs[NL80211_ATTR_MAC])
8763 return -EINVAL;
8764
Jouni Malinen17780922009-03-27 20:52:47 +02008765 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8766 return -EINVAL;
8767
Johannes Berg19957bb2009-07-02 17:20:43 +02008768 if (!info->attrs[NL80211_ATTR_SSID])
8769 return -EINVAL;
8770
8771 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8772 return -EINVAL;
8773
Johannes Bergfffd0932009-07-08 14:22:54 +02008774 err = nl80211_parse_key(info, &key);
8775 if (err)
8776 return err;
8777
8778 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008779 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8780 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008781 if (!key.p.key || !key.p.key_len)
8782 return -EINVAL;
8783 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8784 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8785 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8786 key.p.key_len != WLAN_KEY_LEN_WEP104))
8787 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008788 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008789 return -EINVAL;
8790 } else {
8791 key.p.key_len = 0;
8792 key.p.key = NULL;
8793 }
8794
Johannes Bergafea0b72010-08-10 09:46:42 +02008795 if (key.idx >= 0) {
8796 int i;
8797 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008798
Johannes Bergafea0b72010-08-10 09:46:42 +02008799 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8800 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8801 ok = true;
8802 break;
8803 }
8804 }
Johannes Berg4c476992010-10-04 21:36:35 +02008805 if (!ok)
8806 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008807 }
8808
Johannes Berg4c476992010-10-04 21:36:35 +02008809 if (!rdev->ops->auth)
8810 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008811
Johannes Berg074ac8d2010-09-16 14:58:22 +02008812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008813 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8814 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008815
Johannes Berg19957bb2009-07-02 17:20:43 +02008816 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008817 chan = nl80211_get_valid_chan(&rdev->wiphy,
8818 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8819 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008820 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008821
Johannes Berg19957bb2009-07-02 17:20:43 +02008822 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8823 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8824
8825 if (info->attrs[NL80211_ATTR_IE]) {
8826 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8827 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8828 }
8829
8830 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008831 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008832 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008833
Jouni Malinen63181062016-10-27 00:42:02 +03008834 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8835 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8836 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8837 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008838 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008839 return -EINVAL;
8840
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008841 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008842 if (auth_type != NL80211_AUTHTYPE_SAE &&
8843 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8844 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8845 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008846 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008847 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8848 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008849 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008850 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008851 return -EINVAL;
8852 }
8853
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008854 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8855
Johannes Berg95de8172012-01-20 13:55:25 +01008856 /*
8857 * Since we no longer track auth state, ignore
8858 * requests to only change local state.
8859 */
8860 if (local_state_change)
8861 return 0;
8862
Johannes Berg91bf9b22013-05-15 17:44:01 +02008863 wdev_lock(dev->ieee80211_ptr);
8864 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8865 ssid, ssid_len, ie, ie_len,
8866 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008867 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008868 wdev_unlock(dev->ieee80211_ptr);
8869 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008870}
8871
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008872static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8873 struct genl_info *info)
8874{
8875 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8876 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8877 return -EINVAL;
8878 }
8879
8880 if (!rdev->ops->tx_control_port ||
8881 !wiphy_ext_feature_isset(&rdev->wiphy,
8882 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8883 return -EOPNOTSUPP;
8884
8885 return 0;
8886}
8887
Johannes Bergc0692b82010-08-27 14:26:53 +03008888static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8889 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008890 struct cfg80211_crypto_settings *settings,
8891 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008892{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008893 memset(settings, 0, sizeof(*settings));
8894
Samuel Ortizb23aa672009-07-01 21:26:54 +02008895 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8896
Johannes Bergc0692b82010-08-27 14:26:53 +03008897 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8898 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008899
Johannes Bergc0692b82010-08-27 14:26:53 +03008900 proto = nla_get_u16(
8901 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8902 settings->control_port_ethertype = cpu_to_be16(proto);
8903 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8904 proto != ETH_P_PAE)
8905 return -EINVAL;
8906 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8907 settings->control_port_no_encrypt = true;
8908 } else
8909 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8910
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008911 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8912 int r = validate_pae_over_nl80211(rdev, info);
8913
8914 if (r < 0)
8915 return r;
8916
8917 settings->control_port_over_nl80211 = true;
8918 }
8919
Samuel Ortizb23aa672009-07-01 21:26:54 +02008920 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8921 void *data;
8922 int len, i;
8923
8924 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8925 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8926 settings->n_ciphers_pairwise = len / sizeof(u32);
8927
8928 if (len % sizeof(u32))
8929 return -EINVAL;
8930
Johannes Berg3dc27d22009-07-02 21:36:37 +02008931 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008932 return -EINVAL;
8933
8934 memcpy(settings->ciphers_pairwise, data, len);
8935
8936 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008937 if (!cfg80211_supported_cipher_suite(
8938 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008939 settings->ciphers_pairwise[i]))
8940 return -EINVAL;
8941 }
8942
8943 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8944 settings->cipher_group =
8945 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008946 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8947 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008948 return -EINVAL;
8949 }
8950
8951 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8952 settings->wpa_versions =
8953 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8954 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8955 return -EINVAL;
8956 }
8957
8958 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8959 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008960 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008961
8962 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8963 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8964 settings->n_akm_suites = len / sizeof(u32);
8965
8966 if (len % sizeof(u32))
8967 return -EINVAL;
8968
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008969 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8970 return -EINVAL;
8971
Samuel Ortizb23aa672009-07-01 21:26:54 +02008972 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008973 }
8974
Eliad Peller91b5ab62017-06-09 13:08:42 +01008975 if (info->attrs[NL80211_ATTR_PMK]) {
8976 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8977 return -EINVAL;
8978 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8979 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8980 return -EINVAL;
8981 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8982 }
8983
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00008984 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
8985 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8986 NL80211_EXT_FEATURE_SAE_OFFLOAD))
8987 return -EINVAL;
8988 settings->sae_pwd =
8989 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
8990 settings->sae_pwd_len =
8991 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
8992 }
8993
Samuel Ortizb23aa672009-07-01 21:26:54 +02008994 return 0;
8995}
8996
Jouni Malinen636a5d32009-03-19 13:39:22 +02008997static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8998{
Johannes Berg4c476992010-10-04 21:36:35 +02008999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9000 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009001 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009002 struct cfg80211_assoc_request req = {};
9003 const u8 *bssid, *ssid;
9004 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009005
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009006 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9007 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9008 return -EPERM;
9009
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009010 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009011 !info->attrs[NL80211_ATTR_SSID] ||
9012 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009013 return -EINVAL;
9014
Johannes Berg4c476992010-10-04 21:36:35 +02009015 if (!rdev->ops->assoc)
9016 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009017
Johannes Berg074ac8d2010-09-16 14:58:22 +02009018 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009019 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9020 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009021
Johannes Berg19957bb2009-07-02 17:20:43 +02009022 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009023
Jouni Malinen664834d2014-01-15 00:01:44 +02009024 chan = nl80211_get_valid_chan(&rdev->wiphy,
9025 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9026 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009027 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009028
Johannes Berg19957bb2009-07-02 17:20:43 +02009029 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9030 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009031
9032 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009033 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9034 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009035 }
9036
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009037 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009038 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009039 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009040 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009041 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009042 else if (mfp != NL80211_MFP_NO)
9043 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009044 }
9045
Johannes Berg3e5d7642009-07-07 14:37:26 +02009046 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009047 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009048
Ben Greear7e7c8922011-11-18 11:31:59 -08009049 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009050 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009051
9052 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009053 memcpy(&req.ht_capa_mask,
9054 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9055 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009056
9057 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009058 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009059 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009060 memcpy(&req.ht_capa,
9061 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9062 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009063 }
9064
Johannes Bergee2aca32013-02-21 17:36:01 +01009065 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009066 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009067
9068 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009069 memcpy(&req.vht_capa_mask,
9070 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9071 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009072
9073 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009074 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009075 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009076 memcpy(&req.vht_capa,
9077 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9078 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009079 }
9080
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009081 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009082 if (!((rdev->wiphy.features &
9083 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9084 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9085 !wiphy_ext_feature_isset(&rdev->wiphy,
9086 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009087 return -EINVAL;
9088 req.flags |= ASSOC_REQ_USE_RRM;
9089 }
9090
Jouni Malinen348bd452016-10-27 00:42:03 +03009091 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9092 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9093 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9094 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9095 return -EINVAL;
9096 req.fils_nonces =
9097 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9098 }
9099
Johannes Bergf62fab72013-02-21 20:09:09 +01009100 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009101 if (!err) {
9102 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009103
Johannes Bergf62fab72013-02-21 20:09:09 +01009104 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9105 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009106
9107 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9108 dev->ieee80211_ptr->conn_owner_nlportid =
9109 info->snd_portid;
9110 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9111 bssid, ETH_ALEN);
9112 }
9113
Johannes Berg91bf9b22013-05-15 17:44:01 +02009114 wdev_unlock(dev->ieee80211_ptr);
9115 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009116
Jouni Malinen636a5d32009-03-19 13:39:22 +02009117 return err;
9118}
9119
9120static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9121{
Johannes Berg4c476992010-10-04 21:36:35 +02009122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9123 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009124 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009125 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009126 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009127 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009128
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009129 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9130 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9131 return -EPERM;
9132
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009133 if (!info->attrs[NL80211_ATTR_MAC])
9134 return -EINVAL;
9135
9136 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9137 return -EINVAL;
9138
Johannes Berg4c476992010-10-04 21:36:35 +02009139 if (!rdev->ops->deauth)
9140 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009141
Johannes Berg074ac8d2010-09-16 14:58:22 +02009142 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009143 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9144 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009145
Johannes Berg19957bb2009-07-02 17:20:43 +02009146 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009147
Johannes Berg19957bb2009-07-02 17:20:43 +02009148 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9149 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009150 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009151 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009152 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009153
9154 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009155 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9156 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009157 }
9158
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009159 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9160
Johannes Berg91bf9b22013-05-15 17:44:01 +02009161 wdev_lock(dev->ieee80211_ptr);
9162 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9163 local_state_change);
9164 wdev_unlock(dev->ieee80211_ptr);
9165 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009166}
9167
9168static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9169{
Johannes Berg4c476992010-10-04 21:36:35 +02009170 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9171 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009172 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009173 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009174 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009175 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009176
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009177 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9178 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9179 return -EPERM;
9180
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009181 if (!info->attrs[NL80211_ATTR_MAC])
9182 return -EINVAL;
9183
9184 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9185 return -EINVAL;
9186
Johannes Berg4c476992010-10-04 21:36:35 +02009187 if (!rdev->ops->disassoc)
9188 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009189
Johannes Berg074ac8d2010-09-16 14:58:22 +02009190 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009191 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9192 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009193
Johannes Berg19957bb2009-07-02 17:20:43 +02009194 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009195
Johannes Berg19957bb2009-07-02 17:20:43 +02009196 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9197 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009198 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009199 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009200 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009201
9202 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009203 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9204 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009205 }
9206
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009207 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9208
Johannes Berg91bf9b22013-05-15 17:44:01 +02009209 wdev_lock(dev->ieee80211_ptr);
9210 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9211 local_state_change);
9212 wdev_unlock(dev->ieee80211_ptr);
9213 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009214}
9215
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009216static bool
9217nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009218 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009219 int rateval)
9220{
9221 struct wiphy *wiphy = &rdev->wiphy;
9222 bool found = false;
9223 int band, i;
9224
Johannes Berg57fbcce2016-04-12 15:56:15 +02009225 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009226 struct ieee80211_supported_band *sband;
9227
9228 sband = wiphy->bands[band];
9229 if (!sband)
9230 continue;
9231
9232 for (i = 0; i < sband->n_bitrates; i++) {
9233 if (sband->bitrates[i].bitrate == rateval) {
9234 mcast_rate[band] = i + 1;
9235 found = true;
9236 break;
9237 }
9238 }
9239 }
9240
9241 return found;
9242}
9243
Johannes Berg04a773a2009-04-19 21:24:32 +02009244static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9245{
Johannes Berg4c476992010-10-04 21:36:35 +02009246 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9247 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009248 struct cfg80211_ibss_params ibss;
9249 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009250 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009251 int err;
9252
Johannes Berg8e30bc52009-04-22 17:45:38 +02009253 memset(&ibss, 0, sizeof(ibss));
9254
Johannes Berg683b6d32012-11-08 21:25:48 +01009255 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009256 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9257 return -EINVAL;
9258
Johannes Berg8e30bc52009-04-22 17:45:38 +02009259 ibss.beacon_interval = 100;
9260
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309261 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009262 ibss.beacon_interval =
9263 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309264
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309265 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9266 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309267 if (err)
9268 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009269
Johannes Berg4c476992010-10-04 21:36:35 +02009270 if (!rdev->ops->join_ibss)
9271 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009272
Johannes Berg4c476992010-10-04 21:36:35 +02009273 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9274 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009275
Johannes Berg79c97e92009-07-07 03:56:12 +02009276 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009277
Johannes Berg39193492011-09-16 13:45:25 +02009278 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009279 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009280
9281 if (!is_valid_ether_addr(ibss.bssid))
9282 return -EINVAL;
9283 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009284 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9285 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9286
9287 if (info->attrs[NL80211_ATTR_IE]) {
9288 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9289 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9290 }
9291
Johannes Berg683b6d32012-11-08 21:25:48 +01009292 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9293 if (err)
9294 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009295
Ilan Peer174e0cd2014-02-23 09:13:01 +02009296 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9297 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009298 return -EINVAL;
9299
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009300 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009301 case NL80211_CHAN_WIDTH_5:
9302 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009303 case NL80211_CHAN_WIDTH_20_NOHT:
9304 break;
9305 case NL80211_CHAN_WIDTH_20:
9306 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009307 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9308 return -EINVAL;
9309 break;
9310 case NL80211_CHAN_WIDTH_80:
9311 case NL80211_CHAN_WIDTH_80P80:
9312 case NL80211_CHAN_WIDTH_160:
9313 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9314 return -EINVAL;
9315 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9316 NL80211_EXT_FEATURE_VHT_IBSS))
9317 return -EINVAL;
9318 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009319 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009320 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009321 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009322
Johannes Berg04a773a2009-04-19 21:24:32 +02009323 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009324 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009325
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009326 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9327 u8 *rates =
9328 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9329 int n_rates =
9330 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9331 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009332 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009333
Johannes Berg34850ab2011-07-18 18:08:35 +02009334 err = ieee80211_get_ratemask(sband, rates, n_rates,
9335 &ibss.basic_rates);
9336 if (err)
9337 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009338 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009339
Simon Wunderlich803768f2013-06-28 10:39:58 +02009340 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9341 memcpy(&ibss.ht_capa_mask,
9342 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9343 sizeof(ibss.ht_capa_mask));
9344
9345 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9346 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9347 return -EINVAL;
9348 memcpy(&ibss.ht_capa,
9349 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9350 sizeof(ibss.ht_capa));
9351 }
9352
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009353 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9354 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9355 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9356 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009357
Johannes Berg4c476992010-10-04 21:36:35 +02009358 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309359 bool no_ht = false;
9360
Johannes Berg768075e2017-11-13 15:35:06 +01009361 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009362 if (IS_ERR(connkeys))
9363 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309364
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009365 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9366 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009367 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309368 return -EINVAL;
9369 }
Johannes Berg4c476992010-10-04 21:36:35 +02009370 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009371
Antonio Quartulli267335d2012-01-31 20:25:47 +01009372 ibss.control_port =
9373 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9374
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009375 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9376 int r = validate_pae_over_nl80211(rdev, info);
9377
Johannes Bergd350a0f2018-12-15 11:03:22 +02009378 if (r < 0) {
9379 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009380 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009381 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009382
9383 ibss.control_port_over_nl80211 = true;
9384 }
9385
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009386 ibss.userspace_handles_dfs =
9387 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9388
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009389 wdev_lock(dev->ieee80211_ptr);
9390 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009391 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009392 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009393 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9394 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9395 wdev_unlock(dev->ieee80211_ptr);
9396
Johannes Berg04a773a2009-04-19 21:24:32 +02009397 return err;
9398}
9399
9400static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9401{
Johannes Berg4c476992010-10-04 21:36:35 +02009402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9403 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009404
Johannes Berg4c476992010-10-04 21:36:35 +02009405 if (!rdev->ops->leave_ibss)
9406 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009407
Johannes Berg4c476992010-10-04 21:36:35 +02009408 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9409 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009410
Johannes Berg4c476992010-10-04 21:36:35 +02009411 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009412}
9413
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009414static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9415{
9416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9417 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009418 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009419 u32 nla_rate;
9420 int err;
9421
9422 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009423 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9424 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009425 return -EOPNOTSUPP;
9426
9427 if (!rdev->ops->set_mcast_rate)
9428 return -EOPNOTSUPP;
9429
9430 memset(mcast_rate, 0, sizeof(mcast_rate));
9431
9432 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9433 return -EINVAL;
9434
9435 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9436 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9437 return -EINVAL;
9438
Ilan Peera1056b1b2015-10-22 22:27:46 +03009439 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009440
9441 return err;
9442}
9443
Johannes Bergad7e7182013-11-13 13:37:47 +01009444static struct sk_buff *
9445__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009446 struct wireless_dev *wdev, int approxlen,
9447 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009448 enum nl80211_attrs attr,
9449 const struct nl80211_vendor_cmd_info *info,
9450 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009451{
9452 struct sk_buff *skb;
9453 void *hdr;
9454 struct nlattr *data;
9455
9456 skb = nlmsg_new(approxlen + 100, gfp);
9457 if (!skb)
9458 return NULL;
9459
9460 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9461 if (!hdr) {
9462 kfree_skb(skb);
9463 return NULL;
9464 }
9465
9466 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9467 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009468
9469 if (info) {
9470 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9471 info->vendor_id))
9472 goto nla_put_failure;
9473 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9474 info->subcmd))
9475 goto nla_put_failure;
9476 }
9477
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009478 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009479 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9480 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009481 goto nla_put_failure;
9482 if (wdev->netdev &&
9483 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9484 wdev->netdev->ifindex))
9485 goto nla_put_failure;
9486 }
9487
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009488 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009489 if (!data)
9490 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009491
9492 ((void **)skb->cb)[0] = rdev;
9493 ((void **)skb->cb)[1] = hdr;
9494 ((void **)skb->cb)[2] = data;
9495
9496 return skb;
9497
9498 nla_put_failure:
9499 kfree_skb(skb);
9500 return NULL;
9501}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009502
Johannes Berge03ad6e2014-01-01 17:22:30 +01009503struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009504 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009505 enum nl80211_commands cmd,
9506 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009507 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009508 int vendor_event_idx,
9509 int approxlen, gfp_t gfp)
9510{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009511 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009512 const struct nl80211_vendor_cmd_info *info;
9513
9514 switch (cmd) {
9515 case NL80211_CMD_TESTMODE:
9516 if (WARN_ON(vendor_event_idx != -1))
9517 return NULL;
9518 info = NULL;
9519 break;
9520 case NL80211_CMD_VENDOR:
9521 if (WARN_ON(vendor_event_idx < 0 ||
9522 vendor_event_idx >= wiphy->n_vendor_events))
9523 return NULL;
9524 info = &wiphy->vendor_events[vendor_event_idx];
9525 break;
9526 default:
9527 WARN_ON(1);
9528 return NULL;
9529 }
9530
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009531 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009532 cmd, attr, info, gfp);
9533}
9534EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9535
9536void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9537{
9538 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9539 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009540 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009541 struct nlattr *data = ((void **)skb->cb)[2];
9542 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9543
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009544 /* clear CB data for netlink core to own from now on */
9545 memset(skb->cb, 0, sizeof(skb->cb));
9546
Johannes Berge03ad6e2014-01-01 17:22:30 +01009547 nla_nest_end(skb, data);
9548 genlmsg_end(skb, hdr);
9549
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009550 if (nlhdr->nlmsg_pid) {
9551 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9552 nlhdr->nlmsg_pid);
9553 } else {
9554 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9555 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +01009556
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009557 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9558 skb, 0, mcgrp, gfp);
9559 }
Johannes Berge03ad6e2014-01-01 17:22:30 +01009560}
9561EXPORT_SYMBOL(__cfg80211_send_event_skb);
9562
Johannes Bergaff89a92009-07-01 21:26:51 +02009563#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009564static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9565{
Johannes Berg4c476992010-10-04 21:36:35 +02009566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009567 struct wireless_dev *wdev =
9568 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009569 int err;
9570
David Spinadelfc73f112013-07-31 18:04:15 +03009571 if (!rdev->ops->testmode_cmd)
9572 return -EOPNOTSUPP;
9573
9574 if (IS_ERR(wdev)) {
9575 err = PTR_ERR(wdev);
9576 if (err != -EINVAL)
9577 return err;
9578 wdev = NULL;
9579 } else if (wdev->wiphy != &rdev->wiphy) {
9580 return -EINVAL;
9581 }
9582
Johannes Bergaff89a92009-07-01 21:26:51 +02009583 if (!info->attrs[NL80211_ATTR_TESTDATA])
9584 return -EINVAL;
9585
Johannes Bergad7e7182013-11-13 13:37:47 +01009586 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009587 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009588 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9589 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009590 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009591
Johannes Bergaff89a92009-07-01 21:26:51 +02009592 return err;
9593}
9594
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009595static int nl80211_testmode_dump(struct sk_buff *skb,
9596 struct netlink_callback *cb)
9597{
Johannes Berg00918d32011-12-13 17:22:05 +01009598 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009599 int err;
9600 long phy_idx;
9601 void *data = NULL;
9602 int data_len = 0;
9603
Johannes Berg5fe231e2013-05-08 21:45:15 +02009604 rtnl_lock();
9605
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009606 if (cb->args[0]) {
9607 /*
9608 * 0 is a valid index, but not valid for args[0],
9609 * so we need to offset by 1.
9610 */
9611 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009612
9613 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9614 if (!rdev) {
9615 err = -ENOENT;
9616 goto out_err;
9617 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009618 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009619 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9620
Johannes Berg8cb08172019-04-26 14:07:28 +02009621 err = nlmsg_parse_deprecated(cb->nlh,
9622 GENL_HDRLEN + nl80211_fam.hdrsize,
9623 attrbuf, nl80211_fam.maxattr,
9624 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009625 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009626 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009627
Johannes Bergc90c39d2016-10-24 14:40:01 +02009628 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009629 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009630 err = PTR_ERR(rdev);
9631 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009632 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009633 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009634
Johannes Bergc90c39d2016-10-24 14:40:01 +02009635 if (attrbuf[NL80211_ATTR_TESTDATA])
9636 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009637 }
9638
9639 if (cb->args[1]) {
9640 data = nla_data((void *)cb->args[1]);
9641 data_len = nla_len((void *)cb->args[1]);
9642 }
9643
Johannes Berg00918d32011-12-13 17:22:05 +01009644 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009645 err = -EOPNOTSUPP;
9646 goto out_err;
9647 }
9648
9649 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009650 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009651 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9652 NL80211_CMD_TESTMODE);
9653 struct nlattr *tmdata;
9654
Dan Carpentercb35fba2013-08-14 14:50:01 +03009655 if (!hdr)
9656 break;
9657
David S. Miller9360ffd2012-03-29 04:41:26 -04009658 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009659 genlmsg_cancel(skb, hdr);
9660 break;
9661 }
9662
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009663 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009664 if (!tmdata) {
9665 genlmsg_cancel(skb, hdr);
9666 break;
9667 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009668 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009669 nla_nest_end(skb, tmdata);
9670
9671 if (err == -ENOBUFS || err == -ENOENT) {
9672 genlmsg_cancel(skb, hdr);
9673 break;
9674 } else if (err) {
9675 genlmsg_cancel(skb, hdr);
9676 goto out_err;
9677 }
9678
9679 genlmsg_end(skb, hdr);
9680 }
9681
9682 err = skb->len;
9683 /* see above */
9684 cb->args[0] = phy_idx + 1;
9685 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009686 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009687 return err;
9688}
Johannes Bergaff89a92009-07-01 21:26:51 +02009689#endif
9690
Samuel Ortizb23aa672009-07-01 21:26:54 +02009691static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9692{
Johannes Berg4c476992010-10-04 21:36:35 +02009693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9694 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009695 struct cfg80211_connect_params connect;
9696 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009697 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009698 int err;
9699
9700 memset(&connect, 0, sizeof(connect));
9701
Samuel Ortizb23aa672009-07-01 21:26:54 +02009702 if (!info->attrs[NL80211_ATTR_SSID] ||
9703 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9704 return -EINVAL;
9705
9706 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9707 connect.auth_type =
9708 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009709 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9710 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009711 return -EINVAL;
9712 } else
9713 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9714
9715 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9716
Avraham Stern3a00df52017-06-09 13:08:43 +01009717 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9718 !wiphy_ext_feature_isset(&rdev->wiphy,
9719 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9720 return -EINVAL;
9721 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9722
Johannes Bergc0692b82010-08-27 14:26:53 +03009723 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009724 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009725 if (err)
9726 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009727
Johannes Berg074ac8d2010-09-16 14:58:22 +02009728 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009729 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9730 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009731
Johannes Berg79c97e92009-07-07 03:56:12 +02009732 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009733
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309734 connect.bg_scan_period = -1;
9735 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9736 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9737 connect.bg_scan_period =
9738 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9739 }
9740
Samuel Ortizb23aa672009-07-01 21:26:54 +02009741 if (info->attrs[NL80211_ATTR_MAC])
9742 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009743 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9744 connect.bssid_hint =
9745 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009746 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9747 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9748
9749 if (info->attrs[NL80211_ATTR_IE]) {
9750 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9751 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9752 }
9753
Jouni Malinencee00a92013-01-15 17:15:57 +02009754 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9755 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009756 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9757 !wiphy_ext_feature_isset(&rdev->wiphy,
9758 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9759 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009760 } else {
9761 connect.mfp = NL80211_MFP_NO;
9762 }
9763
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009764 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9765 connect.prev_bssid =
9766 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9767
Samuel Ortizb23aa672009-07-01 21:26:54 +02009768 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009769 connect.channel = nl80211_get_valid_chan(
9770 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9771 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009772 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009773 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009774 connect.channel_hint = nl80211_get_valid_chan(
9775 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9776 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009777 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009778 }
9779
Johannes Bergfffd0932009-07-08 14:22:54 +02009780 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009781 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009782 if (IS_ERR(connkeys))
9783 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009784 }
9785
Ben Greear7e7c8922011-11-18 11:31:59 -08009786 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9787 connect.flags |= ASSOC_REQ_DISABLE_HT;
9788
9789 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9790 memcpy(&connect.ht_capa_mask,
9791 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9792 sizeof(connect.ht_capa_mask));
9793
9794 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009795 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009796 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009797 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009798 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009799 memcpy(&connect.ht_capa,
9800 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9801 sizeof(connect.ht_capa));
9802 }
9803
Johannes Bergee2aca32013-02-21 17:36:01 +01009804 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9805 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9806
9807 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9808 memcpy(&connect.vht_capa_mask,
9809 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9810 sizeof(connect.vht_capa_mask));
9811
9812 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9813 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009814 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009815 return -EINVAL;
9816 }
9817 memcpy(&connect.vht_capa,
9818 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9819 sizeof(connect.vht_capa));
9820 }
9821
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009822 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009823 if (!((rdev->wiphy.features &
9824 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9825 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9826 !wiphy_ext_feature_isset(&rdev->wiphy,
9827 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009828 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009829 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009830 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009831 connect.flags |= ASSOC_REQ_USE_RRM;
9832 }
9833
Lior David34d50512016-01-28 10:58:25 +02009834 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009835 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009836 kzfree(connkeys);
9837 return -EOPNOTSUPP;
9838 }
9839
Arend van Spriel38de03d2016-03-02 20:37:18 +01009840 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9841 /* bss selection makes no sense if bssid is set */
9842 if (connect.bssid) {
9843 kzfree(connkeys);
9844 return -EINVAL;
9845 }
9846
9847 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9848 wiphy, &connect.bss_select);
9849 if (err) {
9850 kzfree(connkeys);
9851 return err;
9852 }
9853 }
9854
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009855 if (wiphy_ext_feature_isset(&rdev->wiphy,
9856 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9857 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9858 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9859 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9860 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9861 connect.fils_erp_username =
9862 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9863 connect.fils_erp_username_len =
9864 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9865 connect.fils_erp_realm =
9866 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9867 connect.fils_erp_realm_len =
9868 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9869 connect.fils_erp_next_seq_num =
9870 nla_get_u16(
9871 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9872 connect.fils_erp_rrk =
9873 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9874 connect.fils_erp_rrk_len =
9875 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9876 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9877 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9878 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9879 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9880 kzfree(connkeys);
9881 return -EINVAL;
9882 }
9883
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009884 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9885 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309886 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009887 GENL_SET_ERR_MSG(info,
9888 "external auth requires connection ownership");
9889 return -EINVAL;
9890 }
9891 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9892 }
9893
Johannes Berg83739b02013-05-15 17:44:01 +02009894 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009895
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009896 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9897 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009898 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009899 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009900
9901 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9902 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9903 if (connect.bssid)
9904 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9905 connect.bssid, ETH_ALEN);
9906 else
9907 memset(dev->ieee80211_ptr->disconnect_bssid,
9908 0, ETH_ALEN);
9909 }
9910
9911 wdev_unlock(dev->ieee80211_ptr);
9912
Samuel Ortizb23aa672009-07-01 21:26:54 +02009913 return err;
9914}
9915
vamsi krishna088e8df2016-10-27 16:51:11 +03009916static int nl80211_update_connect_params(struct sk_buff *skb,
9917 struct genl_info *info)
9918{
9919 struct cfg80211_connect_params connect = {};
9920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9921 struct net_device *dev = info->user_ptr[1];
9922 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009923 bool fils_sk_offload;
9924 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +03009925 u32 changed = 0;
9926 int ret;
9927
9928 if (!rdev->ops->update_connect_params)
9929 return -EOPNOTSUPP;
9930
9931 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +03009932 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9933 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9934 changed |= UPDATE_ASSOC_IES;
9935 }
9936
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009937 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
9938 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
9939
9940 /*
9941 * when driver supports fils-sk offload all attributes must be
9942 * provided. So the else covers "fils-sk-not-all" and
9943 * "no-fils-sk-any".
9944 */
9945 if (fils_sk_offload &&
9946 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9947 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9948 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9949 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9950 connect.fils_erp_username =
9951 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9952 connect.fils_erp_username_len =
9953 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9954 connect.fils_erp_realm =
9955 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9956 connect.fils_erp_realm_len =
9957 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9958 connect.fils_erp_next_seq_num =
9959 nla_get_u16(
9960 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9961 connect.fils_erp_rrk =
9962 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9963 connect.fils_erp_rrk_len =
9964 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9965 changed |= UPDATE_FILS_ERP_INFO;
9966 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9967 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9968 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9969 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9970 return -EINVAL;
9971 }
9972
9973 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9974 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9975 if (!nl80211_valid_auth_type(rdev, auth_type,
9976 NL80211_CMD_CONNECT))
9977 return -EINVAL;
9978
9979 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
9980 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
9981 return -EINVAL;
9982
9983 connect.auth_type = auth_type;
9984 changed |= UPDATE_AUTH_TYPE;
9985 }
9986
vamsi krishna088e8df2016-10-27 16:51:11 +03009987 wdev_lock(dev->ieee80211_ptr);
9988 if (!wdev->current_bss)
9989 ret = -ENOLINK;
9990 else
9991 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9992 wdev_unlock(dev->ieee80211_ptr);
9993
9994 return ret;
9995}
9996
Samuel Ortizb23aa672009-07-01 21:26:54 +02009997static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9998{
Johannes Berg4c476992010-10-04 21:36:35 +02009999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10000 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010001 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010002 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010003
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010004 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10005 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10006 return -EPERM;
10007
Samuel Ortizb23aa672009-07-01 21:26:54 +020010008 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10009 reason = WLAN_REASON_DEAUTH_LEAVING;
10010 else
10011 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10012
10013 if (reason == 0)
10014 return -EINVAL;
10015
Johannes Berg074ac8d2010-09-16 14:58:22 +020010016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010017 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10018 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010019
Johannes Berg83739b02013-05-15 17:44:01 +020010020 wdev_lock(dev->ieee80211_ptr);
10021 ret = cfg80211_disconnect(rdev, dev, reason, true);
10022 wdev_unlock(dev->ieee80211_ptr);
10023 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010024}
10025
Johannes Berg463d0182009-07-14 00:33:35 +020010026static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10027{
Johannes Berg4c476992010-10-04 21:36:35 +020010028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010029 struct net *net;
10030 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010031
Vadim Kochan4b681c82015-01-12 16:34:05 +020010032 if (info->attrs[NL80211_ATTR_PID]) {
10033 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10034
10035 net = get_net_ns_by_pid(pid);
10036 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10037 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10038
10039 net = get_net_ns_by_fd(fd);
10040 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010041 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010042 }
Johannes Berg463d0182009-07-14 00:33:35 +020010043
Johannes Berg4c476992010-10-04 21:36:35 +020010044 if (IS_ERR(net))
10045 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010046
10047 err = 0;
10048
10049 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010050 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10051 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010052
Johannes Berg463d0182009-07-14 00:33:35 +020010053 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010054 return err;
10055}
10056
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010057static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10058{
Johannes Berg4c476992010-10-04 21:36:35 +020010059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010060 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10061 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010062 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010063 struct cfg80211_pmksa pmksa;
10064
10065 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10066
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010067 if (!info->attrs[NL80211_ATTR_PMKID])
10068 return -EINVAL;
10069
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010070 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010071
10072 if (info->attrs[NL80211_ATTR_MAC]) {
10073 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10074 } else if (info->attrs[NL80211_ATTR_SSID] &&
10075 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10076 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10077 info->attrs[NL80211_ATTR_PMK])) {
10078 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10079 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10080 pmksa.cache_id =
10081 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10082 } else {
10083 return -EINVAL;
10084 }
10085 if (info->attrs[NL80211_ATTR_PMK]) {
10086 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10087 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10088 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010089
Johannes Berg074ac8d2010-09-16 14:58:22 +020010090 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010091 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10092 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10093 wiphy_ext_feature_isset(&rdev->wiphy,
10094 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010095 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010096
10097 switch (info->genlhdr->cmd) {
10098 case NL80211_CMD_SET_PMKSA:
10099 rdev_ops = rdev->ops->set_pmksa;
10100 break;
10101 case NL80211_CMD_DEL_PMKSA:
10102 rdev_ops = rdev->ops->del_pmksa;
10103 break;
10104 default:
10105 WARN_ON(1);
10106 break;
10107 }
10108
Johannes Berg4c476992010-10-04 21:36:35 +020010109 if (!rdev_ops)
10110 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010111
Johannes Berg4c476992010-10-04 21:36:35 +020010112 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010113}
10114
10115static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10116{
Johannes Berg4c476992010-10-04 21:36:35 +020010117 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10118 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010119
Johannes Berg074ac8d2010-09-16 14:58:22 +020010120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10122 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010123
Johannes Berg4c476992010-10-04 21:36:35 +020010124 if (!rdev->ops->flush_pmksa)
10125 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010126
Hila Gonene35e4d22012-06-27 17:19:42 +030010127 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010128}
10129
Arik Nemtsov109086c2011-09-28 14:12:50 +030010130static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10131{
10132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10133 struct net_device *dev = info->user_ptr[1];
10134 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010135 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010136 u16 status_code;
10137 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010138 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010139
10140 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10141 !rdev->ops->tdls_mgmt)
10142 return -EOPNOTSUPP;
10143
10144 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10145 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10146 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10147 !info->attrs[NL80211_ATTR_IE] ||
10148 !info->attrs[NL80211_ATTR_MAC])
10149 return -EINVAL;
10150
10151 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10152 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10153 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10154 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010155 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010156 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10157 peer_capability =
10158 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010159
Hila Gonene35e4d22012-06-27 17:19:42 +030010160 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010161 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010162 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010163 nla_data(info->attrs[NL80211_ATTR_IE]),
10164 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010165}
10166
10167static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10168{
10169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10170 struct net_device *dev = info->user_ptr[1];
10171 enum nl80211_tdls_operation operation;
10172 u8 *peer;
10173
10174 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10175 !rdev->ops->tdls_oper)
10176 return -EOPNOTSUPP;
10177
10178 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10179 !info->attrs[NL80211_ATTR_MAC])
10180 return -EINVAL;
10181
10182 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10183 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10184
Hila Gonene35e4d22012-06-27 17:19:42 +030010185 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010186}
10187
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010188static int nl80211_remain_on_channel(struct sk_buff *skb,
10189 struct genl_info *info)
10190{
Johannes Berg4c476992010-10-04 21:36:35 +020010191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010192 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010193 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010194 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010195 struct sk_buff *msg;
10196 void *hdr;
10197 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010198 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010199 int err;
10200
10201 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10202 !info->attrs[NL80211_ATTR_DURATION])
10203 return -EINVAL;
10204
10205 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10206
Johannes Berg7c4ef712011-11-18 15:33:48 +010010207 if (!rdev->ops->remain_on_channel ||
10208 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010209 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010210
Johannes Bergebf348f2012-06-01 12:50:54 +020010211 /*
10212 * We should be on that channel for at least a minimum amount of
10213 * time (10ms) but no longer than the driver supports.
10214 */
10215 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10216 duration > rdev->wiphy.max_remain_on_channel_duration)
10217 return -EINVAL;
10218
Johannes Berg683b6d32012-11-08 21:25:48 +010010219 err = nl80211_parse_chandef(rdev, info, &chandef);
10220 if (err)
10221 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010222
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010223 wdev_lock(wdev);
10224 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10225 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10226 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10227 &chandef);
10228 if (compat_chandef != &chandef) {
10229 wdev_unlock(wdev);
10230 return -EBUSY;
10231 }
10232 }
10233 wdev_unlock(wdev);
10234
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010235 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010236 if (!msg)
10237 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010238
Eric W. Biederman15e47302012-09-07 20:12:54 +000010239 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010240 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010241 if (!hdr) {
10242 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010243 goto free_msg;
10244 }
10245
Johannes Berg683b6d32012-11-08 21:25:48 +010010246 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10247 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010248
10249 if (err)
10250 goto free_msg;
10251
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010252 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10253 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010254 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010255
10256 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010257
10258 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010259
10260 nla_put_failure:
10261 err = -ENOBUFS;
10262 free_msg:
10263 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010264 return err;
10265}
10266
10267static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10268 struct genl_info *info)
10269{
Johannes Berg4c476992010-10-04 21:36:35 +020010270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010271 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010272 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010273
10274 if (!info->attrs[NL80211_ATTR_COOKIE])
10275 return -EINVAL;
10276
Johannes Berg4c476992010-10-04 21:36:35 +020010277 if (!rdev->ops->cancel_remain_on_channel)
10278 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010279
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010280 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10281
Hila Gonene35e4d22012-06-27 17:19:42 +030010282 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010283}
10284
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010285static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10286 struct genl_info *info)
10287{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010288 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010290 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010291 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010292
Johannes Berg4c476992010-10-04 21:36:35 +020010293 if (!rdev->ops->set_bitrate_mask)
10294 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010295
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010296 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10297 if (err)
10298 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010299
Hila Gonene35e4d22012-06-27 17:19:42 +030010300 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010301}
10302
Johannes Berg2e161f782010-08-12 15:38:38 +020010303static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010304{
Johannes Berg4c476992010-10-04 21:36:35 +020010305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010306 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010307 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010308
10309 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10310 return -EINVAL;
10311
Johannes Berg2e161f782010-08-12 15:38:38 +020010312 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10313 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010314
Johannes Berg71bbc992012-06-15 15:30:18 +020010315 switch (wdev->iftype) {
10316 case NL80211_IFTYPE_STATION:
10317 case NL80211_IFTYPE_ADHOC:
10318 case NL80211_IFTYPE_P2P_CLIENT:
10319 case NL80211_IFTYPE_AP:
10320 case NL80211_IFTYPE_AP_VLAN:
10321 case NL80211_IFTYPE_MESH_POINT:
10322 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010323 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010324 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010325 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010326 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010327 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010328 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010329
10330 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010331 if (!rdev->ops->mgmt_tx)
10332 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010333
Eric W. Biederman15e47302012-09-07 20:12:54 +000010334 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010335 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10336 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010337}
10338
Johannes Berg2e161f782010-08-12 15:38:38 +020010339static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010340{
Johannes Berg4c476992010-10-04 21:36:35 +020010341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010342 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010343 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010344 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010345 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010346 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010347 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010348 struct cfg80211_mgmt_tx_params params = {
10349 .dont_wait_for_ack =
10350 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10351 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010352
Johannes Berg683b6d32012-11-08 21:25:48 +010010353 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010354 return -EINVAL;
10355
Johannes Berg4c476992010-10-04 21:36:35 +020010356 if (!rdev->ops->mgmt_tx)
10357 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010358
Johannes Berg71bbc992012-06-15 15:30:18 +020010359 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010360 case NL80211_IFTYPE_P2P_DEVICE:
10361 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10362 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010363 case NL80211_IFTYPE_STATION:
10364 case NL80211_IFTYPE_ADHOC:
10365 case NL80211_IFTYPE_P2P_CLIENT:
10366 case NL80211_IFTYPE_AP:
10367 case NL80211_IFTYPE_AP_VLAN:
10368 case NL80211_IFTYPE_MESH_POINT:
10369 case NL80211_IFTYPE_P2P_GO:
10370 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010371 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010372 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010373 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010374 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010375
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010376 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010377 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010378 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010379 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010380
10381 /*
10382 * We should wait on the channel for at least a minimum amount
10383 * of time (10ms) but no longer than the driver supports.
10384 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010385 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10386 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010387 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010388 }
10389
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010390 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010391
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010392 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010393 return -EINVAL;
10394
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010395 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010396
Antonio Quartulliea141b752013-06-11 14:20:03 +020010397 /* get the channel if any has been specified, otherwise pass NULL to
10398 * the driver. The latter will use the current one
10399 */
10400 chandef.chan = NULL;
10401 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10402 err = nl80211_parse_chandef(rdev, info, &chandef);
10403 if (err)
10404 return err;
10405 }
10406
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010407 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010408 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010409
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010410 wdev_lock(wdev);
10411 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10412 wdev_unlock(wdev);
10413 return -EBUSY;
10414 }
10415 wdev_unlock(wdev);
10416
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010417 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10418 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10419
10420 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10421 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10422 int i;
10423
10424 if (len % sizeof(u16))
10425 return -EINVAL;
10426
10427 params.n_csa_offsets = len / sizeof(u16);
10428 params.csa_offsets =
10429 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10430
10431 /* check that all the offsets fit the frame */
10432 for (i = 0; i < params.n_csa_offsets; i++) {
10433 if (params.csa_offsets[i] >= params.len)
10434 return -EINVAL;
10435 }
10436 }
10437
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010438 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10440 if (!msg)
10441 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010442
Eric W. Biederman15e47302012-09-07 20:12:54 +000010443 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010444 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010445 if (!hdr) {
10446 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010447 goto free_msg;
10448 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010449 }
Johannes Berge247bd902011-11-04 11:18:21 +010010450
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010451 params.chan = chandef.chan;
10452 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010453 if (err)
10454 goto free_msg;
10455
Johannes Berge247bd902011-11-04 11:18:21 +010010456 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010457 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10458 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010459 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010460
Johannes Berge247bd902011-11-04 11:18:21 +010010461 genlmsg_end(msg, hdr);
10462 return genlmsg_reply(msg, info);
10463 }
10464
10465 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010466
10467 nla_put_failure:
10468 err = -ENOBUFS;
10469 free_msg:
10470 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010471 return err;
10472}
10473
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010474static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10475{
10476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010477 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010478 u64 cookie;
10479
10480 if (!info->attrs[NL80211_ATTR_COOKIE])
10481 return -EINVAL;
10482
10483 if (!rdev->ops->mgmt_tx_cancel_wait)
10484 return -EOPNOTSUPP;
10485
Johannes Berg71bbc992012-06-15 15:30:18 +020010486 switch (wdev->iftype) {
10487 case NL80211_IFTYPE_STATION:
10488 case NL80211_IFTYPE_ADHOC:
10489 case NL80211_IFTYPE_P2P_CLIENT:
10490 case NL80211_IFTYPE_AP:
10491 case NL80211_IFTYPE_AP_VLAN:
10492 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010493 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010494 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010495 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010496 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010497 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010498 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010499
10500 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10501
Hila Gonene35e4d22012-06-27 17:19:42 +030010502 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010503}
10504
Kalle Valoffb9eb32010-02-17 17:58:10 +020010505static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10506{
Johannes Berg4c476992010-10-04 21:36:35 +020010507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010508 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010509 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010510 u8 ps_state;
10511 bool state;
10512 int err;
10513
Johannes Berg4c476992010-10-04 21:36:35 +020010514 if (!info->attrs[NL80211_ATTR_PS_STATE])
10515 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010516
10517 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10518
Kalle Valoffb9eb32010-02-17 17:58:10 +020010519 wdev = dev->ieee80211_ptr;
10520
Johannes Berg4c476992010-10-04 21:36:35 +020010521 if (!rdev->ops->set_power_mgmt)
10522 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010523
10524 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10525
10526 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010527 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010528
Hila Gonene35e4d22012-06-27 17:19:42 +030010529 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010530 if (!err)
10531 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010532 return err;
10533}
10534
10535static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10536{
Johannes Berg4c476992010-10-04 21:36:35 +020010537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010538 enum nl80211_ps_state ps_state;
10539 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010540 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010541 struct sk_buff *msg;
10542 void *hdr;
10543 int err;
10544
Kalle Valoffb9eb32010-02-17 17:58:10 +020010545 wdev = dev->ieee80211_ptr;
10546
Johannes Berg4c476992010-10-04 21:36:35 +020010547 if (!rdev->ops->set_power_mgmt)
10548 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010549
10550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010551 if (!msg)
10552 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010553
Eric W. Biederman15e47302012-09-07 20:12:54 +000010554 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010555 NL80211_CMD_GET_POWER_SAVE);
10556 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010557 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010558 goto free_msg;
10559 }
10560
10561 if (wdev->ps)
10562 ps_state = NL80211_PS_ENABLED;
10563 else
10564 ps_state = NL80211_PS_DISABLED;
10565
David S. Miller9360ffd2012-03-29 04:41:26 -040010566 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10567 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010568
10569 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010570 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010571
Johannes Berg4c476992010-10-04 21:36:35 +020010572 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010573 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010574 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010575 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010576 return err;
10577}
10578
Johannes Berg94e860f2014-01-20 23:58:15 +010010579static const struct nla_policy
10580nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010581 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010582 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10583 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010584 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10585 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10586 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010587 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010588};
10589
Thomas Pedersen84f10702012-07-12 16:17:33 -070010590static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010591 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010592{
10593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010594 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010595 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010596
Johannes Bergd9d8b012012-11-26 12:51:52 +010010597 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010598 return -EINVAL;
10599
Thomas Pedersen84f10702012-07-12 16:17:33 -070010600 if (!rdev->ops->set_cqm_txe_config)
10601 return -EOPNOTSUPP;
10602
10603 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10604 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10605 return -EOPNOTSUPP;
10606
Hila Gonene35e4d22012-06-27 17:19:42 +030010607 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010608}
10609
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010610static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10611 struct net_device *dev)
10612{
10613 struct wireless_dev *wdev = dev->ieee80211_ptr;
10614 s32 last, low, high;
10615 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010616 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010617 int err;
10618
10619 /* RSSI reporting disabled? */
10620 if (!wdev->cqm_config)
10621 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10622
10623 /*
10624 * Obtain current RSSI value if possible, if not and no RSSI threshold
10625 * event has been received yet, we should receive an event after a
10626 * connection is established and enough beacons received to calculate
10627 * the average.
10628 */
10629 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10630 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010631 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010632 u8 *mac_addr;
10633
10634 mac_addr = wdev->current_bss->pub.bssid;
10635
Johannes Berg73887fd2018-05-18 09:57:55 +020010636 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10637 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010638 return err;
10639
Omer Efrat397c6572018-06-17 13:06:14 +030010640 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010641 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010642 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010643 }
10644
10645 last = wdev->cqm_config->last_rssi_event_value;
10646 hyst = wdev->cqm_config->rssi_hyst;
10647 n = wdev->cqm_config->n_rssi_thresholds;
10648
10649 for (i = 0; i < n; i++)
10650 if (last < wdev->cqm_config->rssi_thresholds[i])
10651 break;
10652
Masashi Honma1222a162018-09-25 11:15:01 +090010653 low_index = i - 1;
10654 if (low_index >= 0) {
10655 low_index = array_index_nospec(low_index, n);
10656 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10657 } else {
10658 low = S32_MIN;
10659 }
10660 if (i < n) {
10661 i = array_index_nospec(i, n);
10662 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10663 } else {
10664 high = S32_MAX;
10665 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010666
10667 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10668}
10669
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010670static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010671 const s32 *thresholds, int n_thresholds,
10672 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010673{
Johannes Berg4c476992010-10-04 21:36:35 +020010674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010675 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010676 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010677 int i, err;
10678 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010679
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010680 /* Check all values negative and sorted */
10681 for (i = 0; i < n_thresholds; i++) {
10682 if (thresholds[i] > 0 || thresholds[i] <= prev)
10683 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010684
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010685 prev = thresholds[i];
10686 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010687
Johannes Berg074ac8d2010-09-16 14:58:22 +020010688 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010689 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10690 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010691
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010692 wdev_lock(wdev);
10693 cfg80211_cqm_config_free(wdev);
10694 wdev_unlock(wdev);
10695
10696 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10697 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10698 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10699
10700 return rdev_set_cqm_rssi_config(rdev, dev,
10701 thresholds[0], hysteresis);
10702 }
10703
10704 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10705 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10706 return -EOPNOTSUPP;
10707
10708 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10709 n_thresholds = 0;
10710
10711 wdev_lock(wdev);
10712 if (n_thresholds) {
10713 struct cfg80211_cqm_config *cqm_config;
10714
10715 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10716 n_thresholds * sizeof(s32), GFP_KERNEL);
10717 if (!cqm_config) {
10718 err = -ENOMEM;
10719 goto unlock;
10720 }
10721
10722 cqm_config->rssi_hyst = hysteresis;
10723 cqm_config->n_rssi_thresholds = n_thresholds;
10724 memcpy(cqm_config->rssi_thresholds, thresholds,
10725 n_thresholds * sizeof(s32));
10726
10727 wdev->cqm_config = cqm_config;
10728 }
10729
10730 err = cfg80211_cqm_rssi_update(rdev, dev);
10731
10732unlock:
10733 wdev_unlock(wdev);
10734
10735 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010736}
10737
10738static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10739{
10740 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10741 struct nlattr *cqm;
10742 int err;
10743
10744 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010745 if (!cqm)
10746 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010747
Johannes Berg8cb08172019-04-26 14:07:28 +020010748 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10749 nl80211_attr_cqm_policy,
10750 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010751 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010752 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010753
10754 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10755 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010756 const s32 *thresholds =
10757 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10758 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010759 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010760
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010761 if (len % 4)
10762 return -EINVAL;
10763
10764 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10765 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010766 }
10767
10768 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10769 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10770 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10771 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10772 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10773 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10774
10775 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10776 }
10777
10778 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010779}
10780
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010781static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10782{
10783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10784 struct net_device *dev = info->user_ptr[1];
10785 struct ocb_setup setup = {};
10786 int err;
10787
10788 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10789 if (err)
10790 return err;
10791
10792 return cfg80211_join_ocb(rdev, dev, &setup);
10793}
10794
10795static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10796{
10797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10798 struct net_device *dev = info->user_ptr[1];
10799
10800 return cfg80211_leave_ocb(rdev, dev);
10801}
10802
Johannes Berg29cbe682010-12-03 09:20:44 +010010803static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10804{
10805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10806 struct net_device *dev = info->user_ptr[1];
10807 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010808 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010809 int err;
10810
10811 /* start with default */
10812 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010813 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010814
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010815 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010816 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010817 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010818 if (err)
10819 return err;
10820 }
10821
10822 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10823 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10824 return -EINVAL;
10825
Javier Cardonac80d5452010-12-16 17:37:49 -080010826 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10827 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10828
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010829 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10830 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10831 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10832 return -EINVAL;
10833
Marco Porsch9bdbf042013-01-07 16:04:51 +010010834 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10835 setup.beacon_interval =
10836 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010837
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010838 err = cfg80211_validate_beacon_int(rdev,
10839 NL80211_IFTYPE_MESH_POINT,
10840 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010841 if (err)
10842 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010843 }
10844
10845 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10846 setup.dtim_period =
10847 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10848 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10849 return -EINVAL;
10850 }
10851
Javier Cardonac80d5452010-12-16 17:37:49 -080010852 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10853 /* parse additional setup parameters if given */
10854 err = nl80211_parse_mesh_setup(info, &setup);
10855 if (err)
10856 return err;
10857 }
10858
Thomas Pedersend37bb182013-03-04 13:06:13 -080010859 if (setup.user_mpm)
10860 cfg.auto_open_plinks = false;
10861
Johannes Bergcc1d2802012-05-16 23:50:20 +020010862 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010863 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10864 if (err)
10865 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010866 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010867 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010868 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010869 }
10870
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010871 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10872 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10873 int n_rates =
10874 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10875 struct ieee80211_supported_band *sband;
10876
10877 if (!setup.chandef.chan)
10878 return -EINVAL;
10879
10880 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10881
10882 err = ieee80211_get_ratemask(sband, rates, n_rates,
10883 &setup.basic_rates);
10884 if (err)
10885 return err;
10886 }
10887
Johannes Berg8564e382016-09-19 09:44:44 +020010888 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10889 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10890 if (err)
10891 return err;
10892
Johannes Berg265698d2017-09-18 22:46:36 +020010893 if (!setup.chandef.chan)
10894 return -EINVAL;
10895
Johannes Berg8564e382016-09-19 09:44:44 +020010896 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10897 &setup.beacon_rate);
10898 if (err)
10899 return err;
10900 }
10901
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010902 setup.userspace_handles_dfs =
10903 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10904
Denis Kenzior1224f582018-03-26 12:52:49 -050010905 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10906 int r = validate_pae_over_nl80211(rdev, info);
10907
10908 if (r < 0)
10909 return r;
10910
10911 setup.control_port_over_nl80211 = true;
10912 }
10913
Denis Kenzior188c1b32018-03-26 12:52:46 -050010914 wdev_lock(dev->ieee80211_ptr);
10915 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10916 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10917 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10918 wdev_unlock(dev->ieee80211_ptr);
10919
10920 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010921}
10922
10923static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10924{
10925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10926 struct net_device *dev = info->user_ptr[1];
10927
10928 return cfg80211_leave_mesh(rdev, dev);
10929}
10930
Johannes Bergdfb89c52012-06-27 09:23:48 +020010931#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010932static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10933 struct cfg80211_registered_device *rdev)
10934{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010935 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010936 struct nlattr *nl_pats, *nl_pat;
10937 int i, pat_len;
10938
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010939 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010940 return 0;
10941
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010942 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010943 if (!nl_pats)
10944 return -ENOBUFS;
10945
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010946 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010947 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010948 if (!nl_pat)
10949 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010950 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010951 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010952 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010953 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10954 wowlan->patterns[i].pattern) ||
10955 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010956 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010957 return -ENOBUFS;
10958 nla_nest_end(msg, nl_pat);
10959 }
10960 nla_nest_end(msg, nl_pats);
10961
10962 return 0;
10963}
10964
Johannes Berg2a0e0472013-01-23 22:57:40 +010010965static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10966 struct cfg80211_wowlan_tcp *tcp)
10967{
10968 struct nlattr *nl_tcp;
10969
10970 if (!tcp)
10971 return 0;
10972
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010973 nl_tcp = nla_nest_start_noflag(msg,
10974 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010975 if (!nl_tcp)
10976 return -ENOBUFS;
10977
Jiri Benc930345e2015-03-29 16:59:25 +020010978 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10979 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010980 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10981 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10982 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10983 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10984 tcp->payload_len, tcp->payload) ||
10985 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10986 tcp->data_interval) ||
10987 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10988 tcp->wake_len, tcp->wake_data) ||
10989 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10990 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10991 return -ENOBUFS;
10992
10993 if (tcp->payload_seq.len &&
10994 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10995 sizeof(tcp->payload_seq), &tcp->payload_seq))
10996 return -ENOBUFS;
10997
10998 if (tcp->payload_tok.len &&
10999 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11000 sizeof(tcp->payload_tok) + tcp->tokens_size,
11001 &tcp->payload_tok))
11002 return -ENOBUFS;
11003
Johannes Berge248ad32013-05-16 10:24:28 +020011004 nla_nest_end(msg, nl_tcp);
11005
Johannes Berg2a0e0472013-01-23 22:57:40 +010011006 return 0;
11007}
11008
Luciano Coelho75453cc2015-01-09 14:06:37 +020011009static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11010 struct cfg80211_sched_scan_request *req)
11011{
Avraham Stern3b06d272015-10-12 09:51:34 +030011012 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011013 int i;
11014
11015 if (!req)
11016 return 0;
11017
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011018 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011019 if (!nd)
11020 return -ENOBUFS;
11021
Avraham Stern3b06d272015-10-12 09:51:34 +030011022 if (req->n_scan_plans == 1 &&
11023 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11024 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011025 return -ENOBUFS;
11026
Luciano Coelho21fea562015-03-17 16:36:01 +020011027 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11028 return -ENOBUFS;
11029
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011030 if (req->relative_rssi_set) {
11031 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11032
11033 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11034 req->relative_rssi))
11035 return -ENOBUFS;
11036
11037 rssi_adjust.band = req->rssi_adjust.band;
11038 rssi_adjust.delta = req->rssi_adjust.delta;
11039 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11040 sizeof(rssi_adjust), &rssi_adjust))
11041 return -ENOBUFS;
11042 }
11043
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011044 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011045 if (!freqs)
11046 return -ENOBUFS;
11047
Johannes Berg53b18982016-09-14 09:59:21 +020011048 for (i = 0; i < req->n_channels; i++) {
11049 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11050 return -ENOBUFS;
11051 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011052
11053 nla_nest_end(msg, freqs);
11054
11055 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011056 matches = nla_nest_start_noflag(msg,
11057 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011058 if (!matches)
11059 return -ENOBUFS;
11060
Luciano Coelho75453cc2015-01-09 14:06:37 +020011061 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011062 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011063 if (!match)
11064 return -ENOBUFS;
11065
Johannes Berg53b18982016-09-14 09:59:21 +020011066 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11067 req->match_sets[i].ssid.ssid_len,
11068 req->match_sets[i].ssid.ssid))
11069 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011070 nla_nest_end(msg, match);
11071 }
11072 nla_nest_end(msg, matches);
11073 }
11074
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011075 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011076 if (!scan_plans)
11077 return -ENOBUFS;
11078
11079 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011080 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011081 if (!scan_plan)
11082 return -ENOBUFS;
11083
Colin Ian King67626962018-09-06 10:58:44 +010011084 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011085 req->scan_plans[i].interval) ||
11086 (req->scan_plans[i].iterations &&
11087 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11088 req->scan_plans[i].iterations)))
11089 return -ENOBUFS;
11090 nla_nest_end(msg, scan_plan);
11091 }
11092 nla_nest_end(msg, scan_plans);
11093
Luciano Coelho75453cc2015-01-09 14:06:37 +020011094 nla_nest_end(msg, nd);
11095
11096 return 0;
11097}
11098
Johannes Bergff1b6e62011-05-04 15:37:28 +020011099static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11100{
11101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11102 struct sk_buff *msg;
11103 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011104 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011105
Johannes Berg964dc9e2013-06-03 17:25:34 +020011106 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011107 return -EOPNOTSUPP;
11108
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011109 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011110 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011111 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11112 rdev->wiphy.wowlan_config->tcp->payload_len +
11113 rdev->wiphy.wowlan_config->tcp->wake_len +
11114 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011115 }
11116
11117 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011118 if (!msg)
11119 return -ENOMEM;
11120
Eric W. Biederman15e47302012-09-07 20:12:54 +000011121 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011122 NL80211_CMD_GET_WOWLAN);
11123 if (!hdr)
11124 goto nla_put_failure;
11125
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011126 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011127 struct nlattr *nl_wowlan;
11128
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011129 nl_wowlan = nla_nest_start_noflag(msg,
11130 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011131 if (!nl_wowlan)
11132 goto nla_put_failure;
11133
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011134 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011136 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011138 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011139 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011140 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011141 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011142 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011144 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011146 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11148 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011149
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011150 if (nl80211_send_wowlan_patterns(msg, rdev))
11151 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011152
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011153 if (nl80211_send_wowlan_tcp(msg,
11154 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011155 goto nla_put_failure;
11156
Luciano Coelho75453cc2015-01-09 14:06:37 +020011157 if (nl80211_send_wowlan_nd(
11158 msg,
11159 rdev->wiphy.wowlan_config->nd_config))
11160 goto nla_put_failure;
11161
Johannes Bergff1b6e62011-05-04 15:37:28 +020011162 nla_nest_end(msg, nl_wowlan);
11163 }
11164
11165 genlmsg_end(msg, hdr);
11166 return genlmsg_reply(msg, info);
11167
11168nla_put_failure:
11169 nlmsg_free(msg);
11170 return -ENOBUFS;
11171}
11172
Johannes Berg2a0e0472013-01-23 22:57:40 +010011173static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11174 struct nlattr *attr,
11175 struct cfg80211_wowlan *trig)
11176{
11177 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11178 struct cfg80211_wowlan_tcp *cfg;
11179 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11180 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11181 u32 size;
11182 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11183 int err, port;
11184
Johannes Berg964dc9e2013-06-03 17:25:34 +020011185 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011186 return -EINVAL;
11187
Johannes Berg8cb08172019-04-26 14:07:28 +020011188 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11189 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011190 if (err)
11191 return err;
11192
11193 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11194 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11195 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11196 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11197 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11198 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11199 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11200 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11201 return -EINVAL;
11202
11203 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011204 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011205 return -EINVAL;
11206
11207 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011208 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011209 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011210 return -EINVAL;
11211
11212 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011213 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011214 return -EINVAL;
11215
11216 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11217 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11218 return -EINVAL;
11219
11220 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11221 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11222
11223 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11224 tokens_size = tokln - sizeof(*tok);
11225
11226 if (!tok->len || tokens_size % tok->len)
11227 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011228 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011229 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011230 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011231 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011232 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011233 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011234 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011235 return -EINVAL;
11236 if (tok->offset + tok->len > data_size)
11237 return -EINVAL;
11238 }
11239
11240 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11241 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011242 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011243 return -EINVAL;
11244 if (seq->len == 0 || seq->len > 4)
11245 return -EINVAL;
11246 if (seq->len + seq->offset > data_size)
11247 return -EINVAL;
11248 }
11249
11250 size = sizeof(*cfg);
11251 size += data_size;
11252 size += wake_size + wake_mask_size;
11253 size += tokens_size;
11254
11255 cfg = kzalloc(size, GFP_KERNEL);
11256 if (!cfg)
11257 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011258 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11259 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011260 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11261 ETH_ALEN);
11262 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11263 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11264 else
11265 port = 0;
11266#ifdef CONFIG_INET
11267 /* allocate a socket and port for it and use it */
11268 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11269 IPPROTO_TCP, &cfg->sock, 1);
11270 if (err) {
11271 kfree(cfg);
11272 return err;
11273 }
11274 if (inet_csk_get_port(cfg->sock->sk, port)) {
11275 sock_release(cfg->sock);
11276 kfree(cfg);
11277 return -EADDRINUSE;
11278 }
11279 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11280#else
11281 if (!port) {
11282 kfree(cfg);
11283 return -EINVAL;
11284 }
11285 cfg->src_port = port;
11286#endif
11287
11288 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11289 cfg->payload_len = data_size;
11290 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11291 memcpy((void *)cfg->payload,
11292 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11293 data_size);
11294 if (seq)
11295 cfg->payload_seq = *seq;
11296 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11297 cfg->wake_len = wake_size;
11298 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11299 memcpy((void *)cfg->wake_data,
11300 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11301 wake_size);
11302 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11303 data_size + wake_size;
11304 memcpy((void *)cfg->wake_mask,
11305 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11306 wake_mask_size);
11307 if (tok) {
11308 cfg->tokens_size = tokens_size;
11309 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11310 }
11311
11312 trig->tcp = cfg;
11313
11314 return 0;
11315}
11316
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011317static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11318 const struct wiphy_wowlan_support *wowlan,
11319 struct nlattr *attr,
11320 struct cfg80211_wowlan *trig)
11321{
11322 struct nlattr **tb;
11323 int err;
11324
Kees Cook6396bb22018-06-12 14:03:40 -070011325 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011326 if (!tb)
11327 return -ENOMEM;
11328
11329 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11330 err = -EOPNOTSUPP;
11331 goto out;
11332 }
11333
Johannes Berg8cb08172019-04-26 14:07:28 +020011334 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11335 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011336 if (err)
11337 goto out;
11338
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011339 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11340 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011341 err = PTR_ERR_OR_ZERO(trig->nd_config);
11342 if (err)
11343 trig->nd_config = NULL;
11344
11345out:
11346 kfree(tb);
11347 return err;
11348}
11349
Johannes Bergff1b6e62011-05-04 15:37:28 +020011350static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11351{
11352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11353 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011354 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011355 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011356 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011357 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011358 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011359 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011360
Johannes Berg964dc9e2013-06-03 17:25:34 +020011361 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011362 return -EOPNOTSUPP;
11363
Johannes Bergae33bd82012-07-12 16:25:02 +020011364 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11365 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011366 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011367 goto set_wakeup;
11368 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011369
Johannes Berg8cb08172019-04-26 14:07:28 +020011370 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11371 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11372 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011373 if (err)
11374 return err;
11375
11376 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11377 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11378 return -EINVAL;
11379 new_triggers.any = true;
11380 }
11381
11382 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11383 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11384 return -EINVAL;
11385 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011386 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011387 }
11388
11389 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11390 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11391 return -EINVAL;
11392 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011393 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011394 }
11395
Johannes Berg77dbbb12011-07-13 10:48:55 +020011396 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11397 return -EINVAL;
11398
11399 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11400 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11401 return -EINVAL;
11402 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011403 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011404 }
11405
11406 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11407 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11408 return -EINVAL;
11409 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011410 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011411 }
11412
11413 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11414 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11415 return -EINVAL;
11416 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011417 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011418 }
11419
11420 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11421 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11422 return -EINVAL;
11423 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011424 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011425 }
11426
Johannes Bergff1b6e62011-05-04 15:37:28 +020011427 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11428 struct nlattr *pat;
11429 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011430 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011431 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011432
Johannes Berg98fc4382015-03-01 09:10:13 +020011433 regular = true;
11434
Johannes Bergff1b6e62011-05-04 15:37:28 +020011435 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11436 rem)
11437 n_patterns++;
11438 if (n_patterns > wowlan->n_patterns)
11439 return -EINVAL;
11440
11441 new_triggers.patterns = kcalloc(n_patterns,
11442 sizeof(new_triggers.patterns[0]),
11443 GFP_KERNEL);
11444 if (!new_triggers.patterns)
11445 return -ENOMEM;
11446
11447 new_triggers.n_patterns = n_patterns;
11448 i = 0;
11449
11450 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11451 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011452 u8 *mask_pat;
11453
Johannes Berg8cb08172019-04-26 14:07:28 +020011454 err = nla_parse_nested_deprecated(pat_tb,
11455 MAX_NL80211_PKTPAT,
11456 pat,
11457 nl80211_packet_pattern_policy,
11458 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020011459 if (err)
11460 goto error;
11461
Johannes Bergff1b6e62011-05-04 15:37:28 +020011462 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011463 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11464 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011465 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011466 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011467 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011468 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011469 goto error;
11470 if (pat_len > wowlan->pattern_max_len ||
11471 pat_len < wowlan->pattern_min_len)
11472 goto error;
11473
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011474 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011475 pkt_offset = 0;
11476 else
11477 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011478 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011479 if (pkt_offset > wowlan->max_pkt_offset)
11480 goto error;
11481 new_triggers.patterns[i].pkt_offset = pkt_offset;
11482
Johannes Berg922bd802014-05-19 17:59:50 +020011483 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11484 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011485 err = -ENOMEM;
11486 goto error;
11487 }
Johannes Berg922bd802014-05-19 17:59:50 +020011488 new_triggers.patterns[i].mask = mask_pat;
11489 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011490 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011491 mask_pat += mask_len;
11492 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011493 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011494 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011495 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011496 pat_len);
11497 i++;
11498 }
11499 }
11500
Johannes Berg2a0e0472013-01-23 22:57:40 +010011501 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011502 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011503 err = nl80211_parse_wowlan_tcp(
11504 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11505 &new_triggers);
11506 if (err)
11507 goto error;
11508 }
11509
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011510 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011511 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011512 err = nl80211_parse_wowlan_nd(
11513 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11514 &new_triggers);
11515 if (err)
11516 goto error;
11517 }
11518
Johannes Berg98fc4382015-03-01 09:10:13 +020011519 /* The 'any' trigger means the device continues operating more or less
11520 * as in its normal operation mode and wakes up the host on most of the
11521 * normal interrupts (like packet RX, ...)
11522 * It therefore makes little sense to combine with the more constrained
11523 * wakeup trigger modes.
11524 */
11525 if (new_triggers.any && regular) {
11526 err = -EINVAL;
11527 goto error;
11528 }
11529
Johannes Bergae33bd82012-07-12 16:25:02 +020011530 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11531 if (!ntrig) {
11532 err = -ENOMEM;
11533 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011534 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011535 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011536 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011537
Johannes Bergae33bd82012-07-12 16:25:02 +020011538 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011539 if (rdev->ops->set_wakeup &&
11540 prev_enabled != !!rdev->wiphy.wowlan_config)
11541 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011542
Johannes Bergff1b6e62011-05-04 15:37:28 +020011543 return 0;
11544 error:
11545 for (i = 0; i < new_triggers.n_patterns; i++)
11546 kfree(new_triggers.patterns[i].mask);
11547 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011548 if (new_triggers.tcp && new_triggers.tcp->sock)
11549 sock_release(new_triggers.tcp->sock);
11550 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011551 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011552 return err;
11553}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011554#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011555
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011556static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11557 struct cfg80211_registered_device *rdev)
11558{
11559 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11560 int i, j, pat_len;
11561 struct cfg80211_coalesce_rules *rule;
11562
11563 if (!rdev->coalesce->n_rules)
11564 return 0;
11565
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011566 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011567 if (!nl_rules)
11568 return -ENOBUFS;
11569
11570 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011571 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011572 if (!nl_rule)
11573 return -ENOBUFS;
11574
11575 rule = &rdev->coalesce->rules[i];
11576 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11577 rule->delay))
11578 return -ENOBUFS;
11579
11580 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11581 rule->condition))
11582 return -ENOBUFS;
11583
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011584 nl_pats = nla_nest_start_noflag(msg,
11585 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011586 if (!nl_pats)
11587 return -ENOBUFS;
11588
11589 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011590 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011591 if (!nl_pat)
11592 return -ENOBUFS;
11593 pat_len = rule->patterns[j].pattern_len;
11594 if (nla_put(msg, NL80211_PKTPAT_MASK,
11595 DIV_ROUND_UP(pat_len, 8),
11596 rule->patterns[j].mask) ||
11597 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11598 rule->patterns[j].pattern) ||
11599 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11600 rule->patterns[j].pkt_offset))
11601 return -ENOBUFS;
11602 nla_nest_end(msg, nl_pat);
11603 }
11604 nla_nest_end(msg, nl_pats);
11605 nla_nest_end(msg, nl_rule);
11606 }
11607 nla_nest_end(msg, nl_rules);
11608
11609 return 0;
11610}
11611
11612static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11613{
11614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11615 struct sk_buff *msg;
11616 void *hdr;
11617
11618 if (!rdev->wiphy.coalesce)
11619 return -EOPNOTSUPP;
11620
11621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11622 if (!msg)
11623 return -ENOMEM;
11624
11625 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11626 NL80211_CMD_GET_COALESCE);
11627 if (!hdr)
11628 goto nla_put_failure;
11629
11630 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11631 goto nla_put_failure;
11632
11633 genlmsg_end(msg, hdr);
11634 return genlmsg_reply(msg, info);
11635
11636nla_put_failure:
11637 nlmsg_free(msg);
11638 return -ENOBUFS;
11639}
11640
11641void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11642{
11643 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11644 int i, j;
11645 struct cfg80211_coalesce_rules *rule;
11646
11647 if (!coalesce)
11648 return;
11649
11650 for (i = 0; i < coalesce->n_rules; i++) {
11651 rule = &coalesce->rules[i];
11652 for (j = 0; j < rule->n_patterns; j++)
11653 kfree(rule->patterns[j].mask);
11654 kfree(rule->patterns);
11655 }
11656 kfree(coalesce->rules);
11657 kfree(coalesce);
11658 rdev->coalesce = NULL;
11659}
11660
11661static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11662 struct nlattr *rule,
11663 struct cfg80211_coalesce_rules *new_rule)
11664{
11665 int err, i;
11666 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11667 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11668 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11669 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11670
Johannes Berg8cb08172019-04-26 14:07:28 +020011671 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11672 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011673 if (err)
11674 return err;
11675
11676 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11677 new_rule->delay =
11678 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11679 if (new_rule->delay > coalesce->max_delay)
11680 return -EINVAL;
11681
11682 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11683 new_rule->condition =
11684 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011685
11686 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11687 return -EINVAL;
11688
11689 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11690 rem)
11691 n_patterns++;
11692 if (n_patterns > coalesce->n_patterns)
11693 return -EINVAL;
11694
11695 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11696 GFP_KERNEL);
11697 if (!new_rule->patterns)
11698 return -ENOMEM;
11699
11700 new_rule->n_patterns = n_patterns;
11701 i = 0;
11702
11703 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11704 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011705 u8 *mask_pat;
11706
Johannes Berg8cb08172019-04-26 14:07:28 +020011707 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11708 pat,
11709 nl80211_packet_pattern_policy,
11710 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020011711 if (err)
11712 return err;
11713
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011714 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11715 !pat_tb[NL80211_PKTPAT_PATTERN])
11716 return -EINVAL;
11717 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11718 mask_len = DIV_ROUND_UP(pat_len, 8);
11719 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11720 return -EINVAL;
11721 if (pat_len > coalesce->pattern_max_len ||
11722 pat_len < coalesce->pattern_min_len)
11723 return -EINVAL;
11724
11725 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11726 pkt_offset = 0;
11727 else
11728 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11729 if (pkt_offset > coalesce->max_pkt_offset)
11730 return -EINVAL;
11731 new_rule->patterns[i].pkt_offset = pkt_offset;
11732
Johannes Berg922bd802014-05-19 17:59:50 +020011733 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11734 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011735 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011736
11737 new_rule->patterns[i].mask = mask_pat;
11738 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11739 mask_len);
11740
11741 mask_pat += mask_len;
11742 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011743 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011744 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11745 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011746 i++;
11747 }
11748
11749 return 0;
11750}
11751
11752static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11753{
11754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11755 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11756 struct cfg80211_coalesce new_coalesce = {};
11757 struct cfg80211_coalesce *n_coalesce;
11758 int err, rem_rule, n_rules = 0, i, j;
11759 struct nlattr *rule;
11760 struct cfg80211_coalesce_rules *tmp_rule;
11761
11762 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11763 return -EOPNOTSUPP;
11764
11765 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11766 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011767 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011768 return 0;
11769 }
11770
11771 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11772 rem_rule)
11773 n_rules++;
11774 if (n_rules > coalesce->n_rules)
11775 return -EINVAL;
11776
11777 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11778 GFP_KERNEL);
11779 if (!new_coalesce.rules)
11780 return -ENOMEM;
11781
11782 new_coalesce.n_rules = n_rules;
11783 i = 0;
11784
11785 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11786 rem_rule) {
11787 err = nl80211_parse_coalesce_rule(rdev, rule,
11788 &new_coalesce.rules[i]);
11789 if (err)
11790 goto error;
11791
11792 i++;
11793 }
11794
Ilan Peera1056b1b2015-10-22 22:27:46 +030011795 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011796 if (err)
11797 goto error;
11798
11799 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11800 if (!n_coalesce) {
11801 err = -ENOMEM;
11802 goto error;
11803 }
11804 cfg80211_rdev_free_coalesce(rdev);
11805 rdev->coalesce = n_coalesce;
11806
11807 return 0;
11808error:
11809 for (i = 0; i < new_coalesce.n_rules; i++) {
11810 tmp_rule = &new_coalesce.rules[i];
11811 for (j = 0; j < tmp_rule->n_patterns; j++)
11812 kfree(tmp_rule->patterns[j].mask);
11813 kfree(tmp_rule->patterns);
11814 }
11815 kfree(new_coalesce.rules);
11816
11817 return err;
11818}
11819
Johannes Berge5497d72011-07-05 16:35:40 +020011820static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11821{
11822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11823 struct net_device *dev = info->user_ptr[1];
11824 struct wireless_dev *wdev = dev->ieee80211_ptr;
11825 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11826 struct cfg80211_gtk_rekey_data rekey_data;
11827 int err;
11828
11829 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11830 return -EINVAL;
11831
Johannes Berg8cb08172019-04-26 14:07:28 +020011832 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
11833 info->attrs[NL80211_ATTR_REKEY_DATA],
11834 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011835 if (err)
11836 return err;
11837
Vladis Dronove785fa02017-09-13 00:21:21 +020011838 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11839 !tb[NL80211_REKEY_DATA_KCK])
11840 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011841 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11842 return -ERANGE;
11843 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11844 return -ERANGE;
11845 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11846 return -ERANGE;
11847
Johannes Berg78f686c2014-09-10 22:28:06 +030011848 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11849 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11850 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011851
11852 wdev_lock(wdev);
11853 if (!wdev->current_bss) {
11854 err = -ENOTCONN;
11855 goto out;
11856 }
11857
11858 if (!rdev->ops->set_rekey_data) {
11859 err = -EOPNOTSUPP;
11860 goto out;
11861 }
11862
Hila Gonene35e4d22012-06-27 17:19:42 +030011863 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011864 out:
11865 wdev_unlock(wdev);
11866 return err;
11867}
11868
Johannes Berg28946da2011-11-04 11:18:12 +010011869static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11870 struct genl_info *info)
11871{
11872 struct net_device *dev = info->user_ptr[1];
11873 struct wireless_dev *wdev = dev->ieee80211_ptr;
11874
11875 if (wdev->iftype != NL80211_IFTYPE_AP &&
11876 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11877 return -EINVAL;
11878
Eric W. Biederman15e47302012-09-07 20:12:54 +000011879 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011880 return -EBUSY;
11881
Eric W. Biederman15e47302012-09-07 20:12:54 +000011882 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011883 return 0;
11884}
11885
Johannes Berg7f6cf312011-11-04 11:18:15 +010011886static int nl80211_probe_client(struct sk_buff *skb,
11887 struct genl_info *info)
11888{
11889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11890 struct net_device *dev = info->user_ptr[1];
11891 struct wireless_dev *wdev = dev->ieee80211_ptr;
11892 struct sk_buff *msg;
11893 void *hdr;
11894 const u8 *addr;
11895 u64 cookie;
11896 int err;
11897
11898 if (wdev->iftype != NL80211_IFTYPE_AP &&
11899 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11900 return -EOPNOTSUPP;
11901
11902 if (!info->attrs[NL80211_ATTR_MAC])
11903 return -EINVAL;
11904
11905 if (!rdev->ops->probe_client)
11906 return -EOPNOTSUPP;
11907
11908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11909 if (!msg)
11910 return -ENOMEM;
11911
Eric W. Biederman15e47302012-09-07 20:12:54 +000011912 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011913 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011914 if (!hdr) {
11915 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011916 goto free_msg;
11917 }
11918
11919 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11920
Hila Gonene35e4d22012-06-27 17:19:42 +030011921 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011922 if (err)
11923 goto free_msg;
11924
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011925 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11926 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011927 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011928
11929 genlmsg_end(msg, hdr);
11930
11931 return genlmsg_reply(msg, info);
11932
11933 nla_put_failure:
11934 err = -ENOBUFS;
11935 free_msg:
11936 nlmsg_free(msg);
11937 return err;
11938}
11939
Johannes Berg5e760232011-11-04 11:18:17 +010011940static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11941{
11942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011943 struct cfg80211_beacon_registration *reg, *nreg;
11944 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011945
11946 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11947 return -EOPNOTSUPP;
11948
Ben Greear37c73b52012-10-26 14:49:25 -070011949 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11950 if (!nreg)
11951 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011952
Ben Greear37c73b52012-10-26 14:49:25 -070011953 /* First, check if already registered. */
11954 spin_lock_bh(&rdev->beacon_registrations_lock);
11955 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11956 if (reg->nlportid == info->snd_portid) {
11957 rv = -EALREADY;
11958 goto out_err;
11959 }
11960 }
11961 /* Add it to the list */
11962 nreg->nlportid = info->snd_portid;
11963 list_add(&nreg->list, &rdev->beacon_registrations);
11964
11965 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011966
11967 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011968out_err:
11969 spin_unlock_bh(&rdev->beacon_registrations_lock);
11970 kfree(nreg);
11971 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011972}
11973
Johannes Berg98104fde2012-06-16 00:19:54 +020011974static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11975{
11976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11977 struct wireless_dev *wdev = info->user_ptr[1];
11978 int err;
11979
11980 if (!rdev->ops->start_p2p_device)
11981 return -EOPNOTSUPP;
11982
11983 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11984 return -EOPNOTSUPP;
11985
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011986 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011987 return 0;
11988
Luciano Coelhob6a55012014-02-27 11:07:21 +020011989 if (rfkill_blocked(rdev->rfkill))
11990 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011991
Johannes Bergeeb126e2012-10-23 15:16:50 +020011992 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011993 if (err)
11994 return err;
11995
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011996 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011997 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011998
11999 return 0;
12000}
12001
12002static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12003{
12004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12005 struct wireless_dev *wdev = info->user_ptr[1];
12006
12007 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12008 return -EOPNOTSUPP;
12009
12010 if (!rdev->ops->stop_p2p_device)
12011 return -EOPNOTSUPP;
12012
Johannes Bergf9f47522013-03-19 15:04:07 +010012013 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012014
12015 return 0;
12016}
12017
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012018static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12019{
12020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12021 struct wireless_dev *wdev = info->user_ptr[1];
12022 struct cfg80211_nan_conf conf = {};
12023 int err;
12024
12025 if (wdev->iftype != NL80211_IFTYPE_NAN)
12026 return -EOPNOTSUPP;
12027
Johannes Bergeeb04a92016-11-21 13:55:48 +010012028 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012029 return -EEXIST;
12030
12031 if (rfkill_blocked(rdev->rfkill))
12032 return -ERFKILL;
12033
12034 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12035 return -EINVAL;
12036
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012037 conf.master_pref =
12038 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012039
Luca Coelho85859892017-02-08 15:00:34 +020012040 if (info->attrs[NL80211_ATTR_BANDS]) {
12041 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12042
12043 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12044 return -EOPNOTSUPP;
12045
12046 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12047 return -EINVAL;
12048
12049 conf.bands = bands;
12050 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012051
12052 err = rdev_start_nan(rdev, wdev, &conf);
12053 if (err)
12054 return err;
12055
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012056 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012057 rdev->opencount++;
12058
12059 return 0;
12060}
12061
12062static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12063{
12064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12065 struct wireless_dev *wdev = info->user_ptr[1];
12066
12067 if (wdev->iftype != NL80211_IFTYPE_NAN)
12068 return -EOPNOTSUPP;
12069
12070 cfg80211_stop_nan(rdev, wdev);
12071
12072 return 0;
12073}
12074
Ayala Bekera442b762016-09-20 17:31:15 +030012075static int validate_nan_filter(struct nlattr *filter_attr)
12076{
12077 struct nlattr *attr;
12078 int len = 0, n_entries = 0, rem;
12079
12080 nla_for_each_nested(attr, filter_attr, rem) {
12081 len += nla_len(attr);
12082 n_entries++;
12083 }
12084
12085 if (len >= U8_MAX)
12086 return -EINVAL;
12087
12088 return n_entries;
12089}
12090
12091static int handle_nan_filter(struct nlattr *attr_filter,
12092 struct cfg80211_nan_func *func,
12093 bool tx)
12094{
12095 struct nlattr *attr;
12096 int n_entries, rem, i;
12097 struct cfg80211_nan_func_filter *filter;
12098
12099 n_entries = validate_nan_filter(attr_filter);
12100 if (n_entries < 0)
12101 return n_entries;
12102
12103 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12104
12105 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12106 if (!filter)
12107 return -ENOMEM;
12108
12109 i = 0;
12110 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012111 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012112 filter[i].len = nla_len(attr);
12113 i++;
12114 }
12115 if (tx) {
12116 func->num_tx_filters = n_entries;
12117 func->tx_filters = filter;
12118 } else {
12119 func->num_rx_filters = n_entries;
12120 func->rx_filters = filter;
12121 }
12122
12123 return 0;
12124}
12125
12126static int nl80211_nan_add_func(struct sk_buff *skb,
12127 struct genl_info *info)
12128{
12129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12130 struct wireless_dev *wdev = info->user_ptr[1];
12131 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12132 struct cfg80211_nan_func *func;
12133 struct sk_buff *msg = NULL;
12134 void *hdr = NULL;
12135 int err = 0;
12136
12137 if (wdev->iftype != NL80211_IFTYPE_NAN)
12138 return -EOPNOTSUPP;
12139
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012140 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012141 return -ENOTCONN;
12142
12143 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12144 return -EINVAL;
12145
Johannes Berg8cb08172019-04-26 14:07:28 +020012146 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12147 info->attrs[NL80211_ATTR_NAN_FUNC],
12148 nl80211_nan_func_policy,
12149 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012150 if (err)
12151 return err;
12152
12153 func = kzalloc(sizeof(*func), GFP_KERNEL);
12154 if (!func)
12155 return -ENOMEM;
12156
Johannes Bergb60ad342018-10-01 11:52:07 +020012157 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012158
12159 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12160 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12161 err = -EINVAL;
12162 goto out;
12163 }
12164
12165
12166 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12167
12168 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12169 err = -EINVAL;
12170 goto out;
12171 }
12172
12173 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12174 sizeof(func->service_id));
12175
12176 func->close_range =
12177 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12178
12179 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12180 func->serv_spec_info_len =
12181 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12182 func->serv_spec_info =
12183 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12184 func->serv_spec_info_len,
12185 GFP_KERNEL);
12186 if (!func->serv_spec_info) {
12187 err = -ENOMEM;
12188 goto out;
12189 }
12190 }
12191
12192 if (tb[NL80211_NAN_FUNC_TTL])
12193 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12194
12195 switch (func->type) {
12196 case NL80211_NAN_FUNC_PUBLISH:
12197 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12198 err = -EINVAL;
12199 goto out;
12200 }
12201
12202 func->publish_type =
12203 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12204 func->publish_bcast =
12205 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12206
12207 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12208 func->publish_bcast) {
12209 err = -EINVAL;
12210 goto out;
12211 }
12212 break;
12213 case NL80211_NAN_FUNC_SUBSCRIBE:
12214 func->subscribe_active =
12215 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12216 break;
12217 case NL80211_NAN_FUNC_FOLLOW_UP:
12218 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012219 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12220 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012221 err = -EINVAL;
12222 goto out;
12223 }
12224
12225 func->followup_id =
12226 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12227 func->followup_reqid =
12228 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12229 memcpy(func->followup_dest.addr,
12230 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12231 sizeof(func->followup_dest.addr));
12232 if (func->ttl) {
12233 err = -EINVAL;
12234 goto out;
12235 }
12236 break;
12237 default:
12238 err = -EINVAL;
12239 goto out;
12240 }
12241
12242 if (tb[NL80211_NAN_FUNC_SRF]) {
12243 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12244
Johannes Berg8cb08172019-04-26 14:07:28 +020012245 err = nla_parse_nested_deprecated(srf_tb,
12246 NL80211_NAN_SRF_ATTR_MAX,
12247 tb[NL80211_NAN_FUNC_SRF],
12248 nl80211_nan_srf_policy,
12249 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012250 if (err)
12251 goto out;
12252
12253 func->srf_include =
12254 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12255
12256 if (srf_tb[NL80211_NAN_SRF_BF]) {
12257 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12258 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12259 err = -EINVAL;
12260 goto out;
12261 }
12262
12263 func->srf_bf_len =
12264 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12265 func->srf_bf =
12266 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12267 func->srf_bf_len, GFP_KERNEL);
12268 if (!func->srf_bf) {
12269 err = -ENOMEM;
12270 goto out;
12271 }
12272
12273 func->srf_bf_idx =
12274 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12275 } else {
12276 struct nlattr *attr, *mac_attr =
12277 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12278 int n_entries, rem, i = 0;
12279
12280 if (!mac_attr) {
12281 err = -EINVAL;
12282 goto out;
12283 }
12284
12285 n_entries = validate_acl_mac_addrs(mac_attr);
12286 if (n_entries <= 0) {
12287 err = -EINVAL;
12288 goto out;
12289 }
12290
12291 func->srf_num_macs = n_entries;
12292 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012293 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012294 GFP_KERNEL);
12295 if (!func->srf_macs) {
12296 err = -ENOMEM;
12297 goto out;
12298 }
12299
12300 nla_for_each_nested(attr, mac_attr, rem)
12301 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12302 sizeof(*func->srf_macs));
12303 }
12304 }
12305
12306 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12307 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12308 func, true);
12309 if (err)
12310 goto out;
12311 }
12312
12313 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12314 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12315 func, false);
12316 if (err)
12317 goto out;
12318 }
12319
12320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12321 if (!msg) {
12322 err = -ENOMEM;
12323 goto out;
12324 }
12325
12326 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12327 NL80211_CMD_ADD_NAN_FUNCTION);
12328 /* This can't really happen - we just allocated 4KB */
12329 if (WARN_ON(!hdr)) {
12330 err = -ENOMEM;
12331 goto out;
12332 }
12333
12334 err = rdev_add_nan_func(rdev, wdev, func);
12335out:
12336 if (err < 0) {
12337 cfg80211_free_nan_func(func);
12338 nlmsg_free(msg);
12339 return err;
12340 }
12341
12342 /* propagate the instance id and cookie to userspace */
12343 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12344 NL80211_ATTR_PAD))
12345 goto nla_put_failure;
12346
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012347 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030012348 if (!func_attr)
12349 goto nla_put_failure;
12350
12351 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12352 func->instance_id))
12353 goto nla_put_failure;
12354
12355 nla_nest_end(msg, func_attr);
12356
12357 genlmsg_end(msg, hdr);
12358 return genlmsg_reply(msg, info);
12359
12360nla_put_failure:
12361 nlmsg_free(msg);
12362 return -ENOBUFS;
12363}
12364
12365static int nl80211_nan_del_func(struct sk_buff *skb,
12366 struct genl_info *info)
12367{
12368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12369 struct wireless_dev *wdev = info->user_ptr[1];
12370 u64 cookie;
12371
12372 if (wdev->iftype != NL80211_IFTYPE_NAN)
12373 return -EOPNOTSUPP;
12374
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012375 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012376 return -ENOTCONN;
12377
12378 if (!info->attrs[NL80211_ATTR_COOKIE])
12379 return -EINVAL;
12380
Ayala Bekera442b762016-09-20 17:31:15 +030012381 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12382
12383 rdev_del_nan_func(rdev, wdev, cookie);
12384
12385 return 0;
12386}
12387
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012388static int nl80211_nan_change_config(struct sk_buff *skb,
12389 struct genl_info *info)
12390{
12391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12392 struct wireless_dev *wdev = info->user_ptr[1];
12393 struct cfg80211_nan_conf conf = {};
12394 u32 changed = 0;
12395
12396 if (wdev->iftype != NL80211_IFTYPE_NAN)
12397 return -EOPNOTSUPP;
12398
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012399 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012400 return -ENOTCONN;
12401
12402 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12403 conf.master_pref =
12404 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12405 if (conf.master_pref <= 1 || conf.master_pref == 255)
12406 return -EINVAL;
12407
12408 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12409 }
12410
Luca Coelho85859892017-02-08 15:00:34 +020012411 if (info->attrs[NL80211_ATTR_BANDS]) {
12412 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12413
12414 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12415 return -EOPNOTSUPP;
12416
12417 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12418 return -EINVAL;
12419
12420 conf.bands = bands;
12421 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012422 }
12423
12424 if (!changed)
12425 return -EINVAL;
12426
12427 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12428}
12429
Ayala Beker50bcd312016-09-20 17:31:17 +030012430void cfg80211_nan_match(struct wireless_dev *wdev,
12431 struct cfg80211_nan_match_params *match, gfp_t gfp)
12432{
12433 struct wiphy *wiphy = wdev->wiphy;
12434 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12435 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12436 struct sk_buff *msg;
12437 void *hdr;
12438
12439 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12440 return;
12441
12442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12443 if (!msg)
12444 return;
12445
12446 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12447 if (!hdr) {
12448 nlmsg_free(msg);
12449 return;
12450 }
12451
12452 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12453 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12454 wdev->netdev->ifindex)) ||
12455 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12456 NL80211_ATTR_PAD))
12457 goto nla_put_failure;
12458
12459 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12460 NL80211_ATTR_PAD) ||
12461 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12462 goto nla_put_failure;
12463
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012464 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030012465 if (!match_attr)
12466 goto nla_put_failure;
12467
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012468 local_func_attr = nla_nest_start_noflag(msg,
12469 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030012470 if (!local_func_attr)
12471 goto nla_put_failure;
12472
12473 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12474 goto nla_put_failure;
12475
12476 nla_nest_end(msg, local_func_attr);
12477
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012478 peer_func_attr = nla_nest_start_noflag(msg,
12479 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030012480 if (!peer_func_attr)
12481 goto nla_put_failure;
12482
12483 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12484 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12485 goto nla_put_failure;
12486
12487 if (match->info && match->info_len &&
12488 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12489 match->info))
12490 goto nla_put_failure;
12491
12492 nla_nest_end(msg, peer_func_attr);
12493 nla_nest_end(msg, match_attr);
12494 genlmsg_end(msg, hdr);
12495
12496 if (!wdev->owner_nlportid)
12497 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12498 msg, 0, NL80211_MCGRP_NAN, gfp);
12499 else
12500 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12501 wdev->owner_nlportid);
12502
12503 return;
12504
12505nla_put_failure:
12506 nlmsg_free(msg);
12507}
12508EXPORT_SYMBOL(cfg80211_nan_match);
12509
Ayala Beker368e5a72016-09-20 17:31:18 +030012510void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12511 u8 inst_id,
12512 enum nl80211_nan_func_term_reason reason,
12513 u64 cookie, gfp_t gfp)
12514{
12515 struct wiphy *wiphy = wdev->wiphy;
12516 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12517 struct sk_buff *msg;
12518 struct nlattr *func_attr;
12519 void *hdr;
12520
12521 if (WARN_ON(!inst_id))
12522 return;
12523
12524 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12525 if (!msg)
12526 return;
12527
12528 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12529 if (!hdr) {
12530 nlmsg_free(msg);
12531 return;
12532 }
12533
12534 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12535 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12536 wdev->netdev->ifindex)) ||
12537 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12538 NL80211_ATTR_PAD))
12539 goto nla_put_failure;
12540
12541 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12542 NL80211_ATTR_PAD))
12543 goto nla_put_failure;
12544
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012545 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030012546 if (!func_attr)
12547 goto nla_put_failure;
12548
12549 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12550 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12551 goto nla_put_failure;
12552
12553 nla_nest_end(msg, func_attr);
12554 genlmsg_end(msg, hdr);
12555
12556 if (!wdev->owner_nlportid)
12557 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12558 msg, 0, NL80211_MCGRP_NAN, gfp);
12559 else
12560 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12561 wdev->owner_nlportid);
12562
12563 return;
12564
12565nla_put_failure:
12566 nlmsg_free(msg);
12567}
12568EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12569
Johannes Berg3713b4e2013-02-14 16:19:38 +010012570static int nl80211_get_protocol_features(struct sk_buff *skb,
12571 struct genl_info *info)
12572{
12573 void *hdr;
12574 struct sk_buff *msg;
12575
12576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12577 if (!msg)
12578 return -ENOMEM;
12579
12580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12581 NL80211_CMD_GET_PROTOCOL_FEATURES);
12582 if (!hdr)
12583 goto nla_put_failure;
12584
12585 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12586 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12587 goto nla_put_failure;
12588
12589 genlmsg_end(msg, hdr);
12590 return genlmsg_reply(msg, info);
12591
12592 nla_put_failure:
12593 kfree_skb(msg);
12594 return -ENOBUFS;
12595}
12596
Jouni Malinen355199e2013-02-27 17:14:27 +020012597static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12598{
12599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12600 struct cfg80211_update_ft_ies_params ft_params;
12601 struct net_device *dev = info->user_ptr[1];
12602
12603 if (!rdev->ops->update_ft_ies)
12604 return -EOPNOTSUPP;
12605
12606 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012607 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012608 return -EINVAL;
12609
12610 memset(&ft_params, 0, sizeof(ft_params));
12611 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12612 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12613 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12614
12615 return rdev_update_ft_ies(rdev, dev, &ft_params);
12616}
12617
Arend van Spriel5de17982013-04-18 15:49:00 +020012618static int nl80211_crit_protocol_start(struct sk_buff *skb,
12619 struct genl_info *info)
12620{
12621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12622 struct wireless_dev *wdev = info->user_ptr[1];
12623 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12624 u16 duration;
12625 int ret;
12626
12627 if (!rdev->ops->crit_proto_start)
12628 return -EOPNOTSUPP;
12629
12630 if (WARN_ON(!rdev->ops->crit_proto_stop))
12631 return -EINVAL;
12632
12633 if (rdev->crit_proto_nlportid)
12634 return -EBUSY;
12635
12636 /* determine protocol if provided */
12637 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12638 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12639
12640 if (proto >= NUM_NL80211_CRIT_PROTO)
12641 return -EINVAL;
12642
12643 /* timeout must be provided */
12644 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12645 return -EINVAL;
12646
12647 duration =
12648 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12649
12650 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12651 return -ERANGE;
12652
12653 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12654 if (!ret)
12655 rdev->crit_proto_nlportid = info->snd_portid;
12656
12657 return ret;
12658}
12659
12660static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12661 struct genl_info *info)
12662{
12663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12664 struct wireless_dev *wdev = info->user_ptr[1];
12665
12666 if (!rdev->ops->crit_proto_stop)
12667 return -EOPNOTSUPP;
12668
12669 if (rdev->crit_proto_nlportid) {
12670 rdev->crit_proto_nlportid = 0;
12671 rdev_crit_proto_stop(rdev, wdev);
12672 }
12673 return 0;
12674}
12675
Johannes Berg901bb982019-05-28 10:56:03 +020012676static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
12677 struct nlattr *attr,
12678 struct netlink_ext_ack *extack)
12679{
12680 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
12681 if (attr->nla_type & NLA_F_NESTED) {
12682 NL_SET_ERR_MSG_ATTR(extack, attr,
12683 "unexpected nested data");
12684 return -EINVAL;
12685 }
12686
12687 return 0;
12688 }
12689
12690 if (!(attr->nla_type & NLA_F_NESTED)) {
12691 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
12692 return -EINVAL;
12693 }
12694
12695 return nl80211_validate_nested(attr, vcmd->maxattr, vcmd->policy,
12696 extack);
12697}
12698
Johannes Bergad7e7182013-11-13 13:37:47 +010012699static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12700{
12701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12702 struct wireless_dev *wdev =
12703 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12704 int i, err;
12705 u32 vid, subcmd;
12706
12707 if (!rdev->wiphy.vendor_commands)
12708 return -EOPNOTSUPP;
12709
12710 if (IS_ERR(wdev)) {
12711 err = PTR_ERR(wdev);
12712 if (err != -EINVAL)
12713 return err;
12714 wdev = NULL;
12715 } else if (wdev->wiphy != &rdev->wiphy) {
12716 return -EINVAL;
12717 }
12718
12719 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12720 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12721 return -EINVAL;
12722
12723 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12724 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12725 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12726 const struct wiphy_vendor_command *vcmd;
12727 void *data = NULL;
12728 int len = 0;
12729
12730 vcmd = &rdev->wiphy.vendor_commands[i];
12731
12732 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12733 continue;
12734
12735 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12736 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12737 if (!wdev)
12738 return -EINVAL;
12739 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12740 !wdev->netdev)
12741 return -EINVAL;
12742
12743 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012744 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012745 return -ENETDOWN;
12746 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012747
12748 if (!vcmd->doit)
12749 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012750 } else {
12751 wdev = NULL;
12752 }
12753
12754 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12755 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12756 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020012757
12758 err = nl80211_vendor_check_policy(vcmd,
12759 info->attrs[NL80211_ATTR_VENDOR_DATA],
12760 info->extack);
12761 if (err)
12762 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010012763 }
12764
12765 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020012766 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010012767 rdev->cur_cmd_info = NULL;
12768 return err;
12769 }
12770
12771 return -EOPNOTSUPP;
12772}
12773
Johannes Berg7bdbe402015-08-15 22:39:49 +030012774static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12775 struct netlink_callback *cb,
12776 struct cfg80211_registered_device **rdev,
12777 struct wireless_dev **wdev)
12778{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012779 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012780 u32 vid, subcmd;
12781 unsigned int i;
12782 int vcmd_idx = -1;
12783 int err;
12784 void *data = NULL;
12785 unsigned int data_len = 0;
12786
Johannes Berg7bdbe402015-08-15 22:39:49 +030012787 if (cb->args[0]) {
12788 /* subtract the 1 again here */
12789 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12790 struct wireless_dev *tmp;
12791
Johannes Bergea90e0d2017-03-15 14:26:04 +010012792 if (!wiphy)
12793 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012794 *rdev = wiphy_to_rdev(wiphy);
12795 *wdev = NULL;
12796
12797 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012798 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012799 if (tmp->identifier == cb->args[1] - 1) {
12800 *wdev = tmp;
12801 break;
12802 }
12803 }
12804 }
12805
12806 /* keep rtnl locked in successful case */
12807 return 0;
12808 }
12809
Johannes Berg8cb08172019-04-26 14:07:28 +020012810 err = nlmsg_parse_deprecated(cb->nlh,
12811 GENL_HDRLEN + nl80211_fam.hdrsize,
12812 attrbuf, nl80211_fam.maxattr,
12813 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012814 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012815 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012816
Johannes Bergc90c39d2016-10-24 14:40:01 +020012817 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012818 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12819 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012820
Johannes Bergc90c39d2016-10-24 14:40:01 +020012821 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012822 if (IS_ERR(*wdev))
12823 *wdev = NULL;
12824
Johannes Bergc90c39d2016-10-24 14:40:01 +020012825 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012826 if (IS_ERR(*rdev))
12827 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012828
Johannes Bergc90c39d2016-10-24 14:40:01 +020012829 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12830 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012831
12832 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12833 const struct wiphy_vendor_command *vcmd;
12834
12835 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12836
12837 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12838 continue;
12839
Johannes Bergea90e0d2017-03-15 14:26:04 +010012840 if (!vcmd->dumpit)
12841 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012842
12843 vcmd_idx = i;
12844 break;
12845 }
12846
Johannes Bergea90e0d2017-03-15 14:26:04 +010012847 if (vcmd_idx < 0)
12848 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012849
Johannes Bergc90c39d2016-10-24 14:40:01 +020012850 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12851 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12852 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020012853
12854 err = nl80211_vendor_check_policy(
12855 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
12856 attrbuf[NL80211_ATTR_VENDOR_DATA],
12857 cb->extack);
12858 if (err)
12859 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012860 }
12861
12862 /* 0 is the first index - add 1 to parse only once */
12863 cb->args[0] = (*rdev)->wiphy_idx + 1;
12864 /* add 1 to know if it was NULL */
12865 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12866 cb->args[2] = vcmd_idx;
12867 cb->args[3] = (unsigned long)data;
12868 cb->args[4] = data_len;
12869
12870 /* keep rtnl locked in successful case */
12871 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012872}
12873
12874static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12875 struct netlink_callback *cb)
12876{
12877 struct cfg80211_registered_device *rdev;
12878 struct wireless_dev *wdev;
12879 unsigned int vcmd_idx;
12880 const struct wiphy_vendor_command *vcmd;
12881 void *data;
12882 int data_len;
12883 int err;
12884 struct nlattr *vendor_data;
12885
Johannes Bergea90e0d2017-03-15 14:26:04 +010012886 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012887 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12888 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012889 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012890
12891 vcmd_idx = cb->args[2];
12892 data = (void *)cb->args[3];
12893 data_len = cb->args[4];
12894 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12895
12896 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12897 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012898 if (!wdev) {
12899 err = -EINVAL;
12900 goto out;
12901 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012902 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012903 !wdev->netdev) {
12904 err = -EINVAL;
12905 goto out;
12906 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012907
12908 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012909 if (!wdev_running(wdev)) {
12910 err = -ENETDOWN;
12911 goto out;
12912 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012913 }
12914 }
12915
12916 while (1) {
12917 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12918 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12919 NL80211_CMD_VENDOR);
12920 if (!hdr)
12921 break;
12922
12923 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012924 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12925 wdev_id(wdev),
12926 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012927 genlmsg_cancel(skb, hdr);
12928 break;
12929 }
12930
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012931 vendor_data = nla_nest_start_noflag(skb,
12932 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012933 if (!vendor_data) {
12934 genlmsg_cancel(skb, hdr);
12935 break;
12936 }
12937
12938 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12939 (unsigned long *)&cb->args[5]);
12940 nla_nest_end(skb, vendor_data);
12941
12942 if (err == -ENOBUFS || err == -ENOENT) {
12943 genlmsg_cancel(skb, hdr);
12944 break;
12945 } else if (err) {
12946 genlmsg_cancel(skb, hdr);
12947 goto out;
12948 }
12949
12950 genlmsg_end(skb, hdr);
12951 }
12952
12953 err = skb->len;
12954 out:
12955 rtnl_unlock();
12956 return err;
12957}
12958
Johannes Bergad7e7182013-11-13 13:37:47 +010012959struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12960 enum nl80211_commands cmd,
12961 enum nl80211_attrs attr,
12962 int approxlen)
12963{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012964 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012965
12966 if (WARN_ON(!rdev->cur_cmd_info))
12967 return NULL;
12968
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012969 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012970 rdev->cur_cmd_info->snd_portid,
12971 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012972 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012973}
12974EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12975
12976int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12977{
12978 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12979 void *hdr = ((void **)skb->cb)[1];
12980 struct nlattr *data = ((void **)skb->cb)[2];
12981
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012982 /* clear CB data for netlink core to own from now on */
12983 memset(skb->cb, 0, sizeof(skb->cb));
12984
Johannes Bergad7e7182013-11-13 13:37:47 +010012985 if (WARN_ON(!rdev->cur_cmd_info)) {
12986 kfree_skb(skb);
12987 return -EINVAL;
12988 }
12989
12990 nla_nest_end(skb, data);
12991 genlmsg_end(skb, hdr);
12992 return genlmsg_reply(skb, rdev->cur_cmd_info);
12993}
12994EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12995
Johannes Berg55c1fdf2019-02-06 13:17:19 +020012996unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
12997{
12998 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12999
13000 if (WARN_ON(!rdev->cur_cmd_info))
13001 return 0;
13002
13003 return rdev->cur_cmd_info->snd_portid;
13004}
13005EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13006
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013007static int nl80211_set_qos_map(struct sk_buff *skb,
13008 struct genl_info *info)
13009{
13010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13011 struct cfg80211_qos_map *qos_map = NULL;
13012 struct net_device *dev = info->user_ptr[1];
13013 u8 *pos, len, num_des, des_len, des;
13014 int ret;
13015
13016 if (!rdev->ops->set_qos_map)
13017 return -EOPNOTSUPP;
13018
13019 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13020 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13021 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13022
13023 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13024 len > IEEE80211_QOS_MAP_LEN_MAX)
13025 return -EINVAL;
13026
13027 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13028 if (!qos_map)
13029 return -ENOMEM;
13030
13031 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13032 if (num_des) {
13033 des_len = num_des *
13034 sizeof(struct cfg80211_dscp_exception);
13035 memcpy(qos_map->dscp_exception, pos, des_len);
13036 qos_map->num_des = num_des;
13037 for (des = 0; des < num_des; des++) {
13038 if (qos_map->dscp_exception[des].up > 7) {
13039 kfree(qos_map);
13040 return -EINVAL;
13041 }
13042 }
13043 pos += des_len;
13044 }
13045 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13046 }
13047
13048 wdev_lock(dev->ieee80211_ptr);
13049 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13050 if (!ret)
13051 ret = rdev_set_qos_map(rdev, dev, qos_map);
13052 wdev_unlock(dev->ieee80211_ptr);
13053
13054 kfree(qos_map);
13055 return ret;
13056}
13057
Johannes Berg960d01a2014-09-09 22:55:35 +030013058static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13059{
13060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13061 struct net_device *dev = info->user_ptr[1];
13062 struct wireless_dev *wdev = dev->ieee80211_ptr;
13063 const u8 *peer;
13064 u8 tsid, up;
13065 u16 admitted_time = 0;
13066 int err;
13067
Johannes Berg723e73a2014-10-22 09:25:06 +020013068 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013069 return -EOPNOTSUPP;
13070
13071 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13072 !info->attrs[NL80211_ATTR_USER_PRIO])
13073 return -EINVAL;
13074
13075 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013076 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013077
13078 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013079 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013080 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013081 * need more attributes for that (e.g. BA session requirement);
13082 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013083 */
13084 return -EINVAL;
13085 }
13086
13087 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13088
13089 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13090 admitted_time =
13091 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13092 if (!admitted_time)
13093 return -EINVAL;
13094 }
13095
13096 wdev_lock(wdev);
13097 switch (wdev->iftype) {
13098 case NL80211_IFTYPE_STATION:
13099 case NL80211_IFTYPE_P2P_CLIENT:
13100 if (wdev->current_bss)
13101 break;
13102 err = -ENOTCONN;
13103 goto out;
13104 default:
13105 err = -EOPNOTSUPP;
13106 goto out;
13107 }
13108
13109 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13110
13111 out:
13112 wdev_unlock(wdev);
13113 return err;
13114}
13115
13116static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13117{
13118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13119 struct net_device *dev = info->user_ptr[1];
13120 struct wireless_dev *wdev = dev->ieee80211_ptr;
13121 const u8 *peer;
13122 u8 tsid;
13123 int err;
13124
13125 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13126 return -EINVAL;
13127
13128 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13129 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13130
13131 wdev_lock(wdev);
13132 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13133 wdev_unlock(wdev);
13134
13135 return err;
13136}
13137
Arik Nemtsov1057d352014-11-19 12:54:26 +020013138static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13139 struct genl_info *info)
13140{
13141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13142 struct net_device *dev = info->user_ptr[1];
13143 struct wireless_dev *wdev = dev->ieee80211_ptr;
13144 struct cfg80211_chan_def chandef = {};
13145 const u8 *addr;
13146 u8 oper_class;
13147 int err;
13148
13149 if (!rdev->ops->tdls_channel_switch ||
13150 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13151 return -EOPNOTSUPP;
13152
13153 switch (dev->ieee80211_ptr->iftype) {
13154 case NL80211_IFTYPE_STATION:
13155 case NL80211_IFTYPE_P2P_CLIENT:
13156 break;
13157 default:
13158 return -EOPNOTSUPP;
13159 }
13160
13161 if (!info->attrs[NL80211_ATTR_MAC] ||
13162 !info->attrs[NL80211_ATTR_OPER_CLASS])
13163 return -EINVAL;
13164
13165 err = nl80211_parse_chandef(rdev, info, &chandef);
13166 if (err)
13167 return err;
13168
13169 /*
13170 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13171 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13172 * specification is not defined for them.
13173 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013174 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013175 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13176 chandef.width != NL80211_CHAN_WIDTH_20)
13177 return -EINVAL;
13178
13179 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013180 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13181 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013182 return -EINVAL;
13183
13184 /* don't allow switching to DFS channels */
13185 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13186 return -EINVAL;
13187
13188 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13189 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13190
13191 wdev_lock(wdev);
13192 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13193 wdev_unlock(wdev);
13194
13195 return err;
13196}
13197
13198static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13199 struct genl_info *info)
13200{
13201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13202 struct net_device *dev = info->user_ptr[1];
13203 struct wireless_dev *wdev = dev->ieee80211_ptr;
13204 const u8 *addr;
13205
13206 if (!rdev->ops->tdls_channel_switch ||
13207 !rdev->ops->tdls_cancel_channel_switch ||
13208 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13209 return -EOPNOTSUPP;
13210
13211 switch (dev->ieee80211_ptr->iftype) {
13212 case NL80211_IFTYPE_STATION:
13213 case NL80211_IFTYPE_P2P_CLIENT:
13214 break;
13215 default:
13216 return -EOPNOTSUPP;
13217 }
13218
13219 if (!info->attrs[NL80211_ATTR_MAC])
13220 return -EINVAL;
13221
13222 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13223
13224 wdev_lock(wdev);
13225 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13226 wdev_unlock(wdev);
13227
13228 return 0;
13229}
13230
Michael Braunce0ce132016-10-10 19:12:22 +020013231static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13232 struct genl_info *info)
13233{
13234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13235 struct net_device *dev = info->user_ptr[1];
13236 struct wireless_dev *wdev = dev->ieee80211_ptr;
13237 const struct nlattr *nla;
13238 bool enabled;
13239
Michael Braunce0ce132016-10-10 19:12:22 +020013240 if (!rdev->ops->set_multicast_to_unicast)
13241 return -EOPNOTSUPP;
13242
13243 if (wdev->iftype != NL80211_IFTYPE_AP &&
13244 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13245 return -EOPNOTSUPP;
13246
13247 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13248 enabled = nla_get_flag(nla);
13249
13250 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13251}
13252
Avraham Stern3a00df52017-06-09 13:08:43 +010013253static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13254{
13255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13256 struct net_device *dev = info->user_ptr[1];
13257 struct wireless_dev *wdev = dev->ieee80211_ptr;
13258 struct cfg80211_pmk_conf pmk_conf = {};
13259 int ret;
13260
13261 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13262 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13263 return -EOPNOTSUPP;
13264
13265 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13266 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13267 return -EOPNOTSUPP;
13268
13269 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13270 return -EINVAL;
13271
13272 wdev_lock(wdev);
13273 if (!wdev->current_bss) {
13274 ret = -ENOTCONN;
13275 goto out;
13276 }
13277
13278 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13279 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13280 ret = -EINVAL;
13281 goto out;
13282 }
13283
13284 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13285 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13286 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13287 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13288 ret = -EINVAL;
13289 goto out;
13290 }
13291
13292 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13293 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13294
13295 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13296 ret = -EINVAL;
13297 goto out;
13298 }
13299
13300 pmk_conf.pmk_r0_name =
13301 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13302 }
13303
13304 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13305out:
13306 wdev_unlock(wdev);
13307 return ret;
13308}
13309
13310static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13311{
13312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13313 struct net_device *dev = info->user_ptr[1];
13314 struct wireless_dev *wdev = dev->ieee80211_ptr;
13315 const u8 *aa;
13316 int ret;
13317
13318 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13319 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13320 return -EOPNOTSUPP;
13321
13322 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13323 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13324 return -EOPNOTSUPP;
13325
13326 if (!info->attrs[NL80211_ATTR_MAC])
13327 return -EINVAL;
13328
13329 wdev_lock(wdev);
13330 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13331 ret = rdev_del_pmk(rdev, dev, aa);
13332 wdev_unlock(wdev);
13333
13334 return ret;
13335}
13336
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013337static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13338{
13339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13340 struct net_device *dev = info->user_ptr[1];
13341 struct cfg80211_external_auth_params params;
13342
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013343 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013344 return -EOPNOTSUPP;
13345
Srinivas Dasarife494372019-01-23 18:06:56 +053013346 if (!info->attrs[NL80211_ATTR_SSID] &&
13347 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13348 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013349 return -EINVAL;
13350
13351 if (!info->attrs[NL80211_ATTR_BSSID])
13352 return -EINVAL;
13353
13354 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13355 return -EINVAL;
13356
13357 memset(&params, 0, sizeof(params));
13358
Srinivas Dasarife494372019-01-23 18:06:56 +053013359 if (info->attrs[NL80211_ATTR_SSID]) {
13360 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13361 if (params.ssid.ssid_len == 0 ||
13362 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13363 return -EINVAL;
13364 memcpy(params.ssid.ssid,
13365 nla_data(info->attrs[NL80211_ATTR_SSID]),
13366 params.ssid.ssid_len);
13367 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013368
13369 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13370 ETH_ALEN);
13371
13372 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13373
Srinivas Dasarife494372019-01-23 18:06:56 +053013374 if (info->attrs[NL80211_ATTR_PMKID])
13375 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13376
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013377 return rdev_external_auth(rdev, dev, &params);
13378}
13379
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013380static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13381{
13382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13383 struct net_device *dev = info->user_ptr[1];
13384 struct wireless_dev *wdev = dev->ieee80211_ptr;
13385 const u8 *buf;
13386 size_t len;
13387 u8 *dest;
13388 u16 proto;
13389 bool noencrypt;
13390 int err;
13391
13392 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13393 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13394 return -EOPNOTSUPP;
13395
13396 if (!rdev->ops->tx_control_port)
13397 return -EOPNOTSUPP;
13398
13399 if (!info->attrs[NL80211_ATTR_FRAME] ||
13400 !info->attrs[NL80211_ATTR_MAC] ||
13401 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13402 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13403 return -EINVAL;
13404 }
13405
13406 wdev_lock(wdev);
13407
13408 switch (wdev->iftype) {
13409 case NL80211_IFTYPE_AP:
13410 case NL80211_IFTYPE_P2P_GO:
13411 case NL80211_IFTYPE_MESH_POINT:
13412 break;
13413 case NL80211_IFTYPE_ADHOC:
13414 case NL80211_IFTYPE_STATION:
13415 case NL80211_IFTYPE_P2P_CLIENT:
13416 if (wdev->current_bss)
13417 break;
13418 err = -ENOTCONN;
13419 goto out;
13420 default:
13421 err = -EOPNOTSUPP;
13422 goto out;
13423 }
13424
13425 wdev_unlock(wdev);
13426
13427 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13428 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13429 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13430 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13431 noencrypt =
13432 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13433
13434 return rdev_tx_control_port(rdev, dev, buf, len,
13435 dest, cpu_to_be16(proto), noencrypt);
13436
13437 out:
13438 wdev_unlock(wdev);
13439 return err;
13440}
13441
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013442static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13443 struct genl_info *info)
13444{
13445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13446 struct net_device *dev = info->user_ptr[1];
13447 struct wireless_dev *wdev = dev->ieee80211_ptr;
13448 struct cfg80211_ftm_responder_stats ftm_stats = {};
13449 struct sk_buff *msg;
13450 void *hdr;
13451 struct nlattr *ftm_stats_attr;
13452 int err;
13453
13454 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13455 return -EOPNOTSUPP;
13456
13457 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13458 if (err)
13459 return err;
13460
13461 if (!ftm_stats.filled)
13462 return -ENODATA;
13463
13464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13465 if (!msg)
13466 return -ENOMEM;
13467
13468 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13469 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13470 if (!hdr)
13471 return -ENOBUFS;
13472
13473 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13474 goto nla_put_failure;
13475
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013476 ftm_stats_attr = nla_nest_start_noflag(msg,
13477 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013478 if (!ftm_stats_attr)
13479 goto nla_put_failure;
13480
13481#define SET_FTM(field, name, type) \
13482 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13483 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13484 ftm_stats.field)) \
13485 goto nla_put_failure; } while (0)
13486#define SET_FTM_U64(field, name) \
13487 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13488 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13489 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13490 goto nla_put_failure; } while (0)
13491
13492 SET_FTM(success_num, SUCCESS_NUM, u32);
13493 SET_FTM(partial_num, PARTIAL_NUM, u32);
13494 SET_FTM(failed_num, FAILED_NUM, u32);
13495 SET_FTM(asap_num, ASAP_NUM, u32);
13496 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13497 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13498 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13499 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13500 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13501#undef SET_FTM
13502
13503 nla_nest_end(msg, ftm_stats_attr);
13504
13505 genlmsg_end(msg, hdr);
13506 return genlmsg_reply(msg, info);
13507
13508nla_put_failure:
13509 nlmsg_free(msg);
13510 return -ENOBUFS;
13511}
13512
Sunil Duttcb74e972019-02-20 16:18:07 +053013513static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13514{
13515 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13516 struct cfg80211_update_owe_info owe_info;
13517 struct net_device *dev = info->user_ptr[1];
13518
13519 if (!rdev->ops->update_owe_info)
13520 return -EOPNOTSUPP;
13521
13522 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13523 !info->attrs[NL80211_ATTR_MAC])
13524 return -EINVAL;
13525
13526 memset(&owe_info, 0, sizeof(owe_info));
13527 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13528 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13529
13530 if (info->attrs[NL80211_ATTR_IE]) {
13531 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13532 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13533 }
13534
13535 return rdev_update_owe_info(rdev, dev, &owe_info);
13536}
13537
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013538static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13539{
13540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13541 struct net_device *dev = info->user_ptr[1];
13542 struct wireless_dev *wdev = dev->ieee80211_ptr;
13543 struct station_info sinfo = {};
13544 const u8 *buf;
13545 size_t len;
13546 u8 *dest;
13547 int err;
13548
13549 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13550 return -EOPNOTSUPP;
13551
13552 if (!info->attrs[NL80211_ATTR_MAC] ||
13553 !info->attrs[NL80211_ATTR_FRAME]) {
13554 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13555 return -EINVAL;
13556 }
13557
13558 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13559 return -EOPNOTSUPP;
13560
13561 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13562 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13563 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13564
13565 if (len < sizeof(struct ethhdr))
13566 return -EINVAL;
13567
13568 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13569 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13570 return -EINVAL;
13571
13572 err = rdev_get_station(rdev, dev, dest, &sinfo);
13573 if (err)
13574 return err;
13575
13576 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13577}
13578
Johannes Berg4c476992010-10-04 21:36:35 +020013579#define NL80211_FLAG_NEED_WIPHY 0x01
13580#define NL80211_FLAG_NEED_NETDEV 0x02
13581#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013582#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13583#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13584 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013585#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013586/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013587#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13588 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013589#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013590
Johannes Bergf84f7712013-11-14 17:14:45 +010013591static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013592 struct genl_info *info)
13593{
13594 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013595 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013596 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013597 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13598
13599 if (rtnl)
13600 rtnl_lock();
13601
13602 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013603 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013604 if (IS_ERR(rdev)) {
13605 if (rtnl)
13606 rtnl_unlock();
13607 return PTR_ERR(rdev);
13608 }
13609 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013610 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13611 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013612 ASSERT_RTNL();
13613
Johannes Berg89a54e42012-06-15 14:33:17 +020013614 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13615 info->attrs);
13616 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013617 if (rtnl)
13618 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013619 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013620 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013621
Johannes Berg89a54e42012-06-15 14:33:17 +020013622 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013623 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013624
Johannes Berg1bf614e2012-06-15 15:23:36 +020013625 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13626 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013627 if (rtnl)
13628 rtnl_unlock();
13629 return -EINVAL;
13630 }
13631
13632 info->user_ptr[1] = dev;
13633 } else {
13634 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013635 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013636
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013637 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13638 !wdev_running(wdev)) {
13639 if (rtnl)
13640 rtnl_unlock();
13641 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013642 }
13643
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013644 if (dev)
13645 dev_hold(dev);
13646
Johannes Berg4c476992010-10-04 21:36:35 +020013647 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013648 }
13649
13650 return 0;
13651}
13652
Johannes Bergf84f7712013-11-14 17:14:45 +010013653static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013654 struct genl_info *info)
13655{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013656 if (info->user_ptr[1]) {
13657 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13658 struct wireless_dev *wdev = info->user_ptr[1];
13659
13660 if (wdev->netdev)
13661 dev_put(wdev->netdev);
13662 } else {
13663 dev_put(info->user_ptr[1]);
13664 }
13665 }
Johannes Berg5393b912014-09-10 15:00:16 +030013666
Johannes Berg4c476992010-10-04 21:36:35 +020013667 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13668 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013669
13670 /* If needed, clear the netlink message payload from the SKB
13671 * as it might contain key data that shouldn't stick around on
13672 * the heap after the SKB is freed. The netlink message header
13673 * is still needed for further processing, so leave it intact.
13674 */
13675 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13676 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13677
13678 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13679 }
Johannes Berg4c476992010-10-04 21:36:35 +020013680}
13681
Johannes Berg4534de82013-11-14 17:14:46 +010013682static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013683 {
13684 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013685 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013686 .doit = nl80211_get_wiphy,
13687 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013688 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013689 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013690 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13691 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013692 },
13693 {
13694 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013695 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013696 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013697 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013698 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013699 },
13700 {
13701 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013702 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013703 .doit = nl80211_get_interface,
13704 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040013705 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013706 .internal_flags = NL80211_FLAG_NEED_WDEV |
13707 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013708 },
13709 {
13710 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013711 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013712 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013713 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013714 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13715 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013716 },
13717 {
13718 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013719 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013720 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013721 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013722 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13723 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013724 },
13725 {
13726 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013727 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013728 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013729 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013730 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013731 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013732 },
Johannes Berg41ade002007-12-19 02:03:29 +010013733 {
13734 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013735 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013736 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013737 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013739 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013740 },
13741 {
13742 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013743 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013744 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013745 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013747 NL80211_FLAG_NEED_RTNL |
13748 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013749 },
13750 {
13751 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013752 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013753 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013754 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013756 NL80211_FLAG_NEED_RTNL |
13757 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013758 },
13759 {
13760 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013761 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013762 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013763 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013764 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013765 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013766 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013767 {
13768 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020013769 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013770 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013771 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013773 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013774 },
13775 {
Johannes Berg88600202012-02-13 15:17:18 +010013776 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013777 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013778 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013779 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013781 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013782 },
13783 {
Johannes Berg88600202012-02-13 15:17:18 +010013784 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013785 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013786 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013787 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013789 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013790 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013791 {
13792 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013793 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013794 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013795 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020013796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13797 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013798 },
13799 {
13800 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013801 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013802 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013803 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013805 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013806 },
13807 {
13808 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013809 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013810 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013811 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013813 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013814 },
13815 {
13816 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013817 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013818 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013819 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013821 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013822 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013823 {
13824 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013825 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013826 .doit = nl80211_get_mpath,
13827 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013828 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013830 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013831 },
13832 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013833 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013834 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020013835 .doit = nl80211_get_mpp,
13836 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020013837 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013838 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13839 NL80211_FLAG_NEED_RTNL,
13840 },
13841 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013842 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013843 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013844 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013845 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013847 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013848 },
13849 {
13850 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013851 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013852 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013853 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013854 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013855 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013856 },
13857 {
13858 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013859 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013860 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013861 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013863 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013864 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013865 {
13866 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013867 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013868 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020013869 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013870 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013871 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013872 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013873 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013874 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013875 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013876 .doit = nl80211_get_reg_do,
13877 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013878 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013879 /* can be retrieved by unprivileged users */
13880 },
Johannes Bergb6863032015-10-15 09:25:18 +020013881#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013882 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013883 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013884 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013885 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013886 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013887 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013888 },
Johannes Bergb6863032015-10-15 09:25:18 +020013889#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013890 {
13891 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013892 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013893 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013894 .flags = GENL_ADMIN_PERM,
13895 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013896 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013897 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020013898 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013899 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013900 .flags = GENL_ADMIN_PERM,
13901 },
13902 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013903 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013904 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013905 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013906 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013908 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013909 },
13910 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013911 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013912 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013913 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020013914 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013916 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013917 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013918 {
Johannes Berg2a519312009-02-10 21:25:55 +010013919 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013920 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010013921 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013922 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013923 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013924 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013925 },
13926 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013927 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013928 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013929 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013930 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013931 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13932 NL80211_FLAG_NEED_RTNL,
13933 },
13934 {
Johannes Berg2a519312009-02-10 21:25:55 +010013935 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010013937 .dumpit = nl80211_dump_scan,
13938 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013939 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013940 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013941 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013942 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013943 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13945 NL80211_FLAG_NEED_RTNL,
13946 },
13947 {
13948 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013949 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013950 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013951 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13953 NL80211_FLAG_NEED_RTNL,
13954 },
13955 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013956 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013957 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013958 .doit = nl80211_authenticate,
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 Berg5393b912014-09-10 15:00:16 +030013961 NL80211_FLAG_NEED_RTNL |
13962 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013963 },
13964 {
13965 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013966 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013967 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013968 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013969 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053013970 NL80211_FLAG_NEED_RTNL |
13971 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013972 },
13973 {
13974 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013975 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013976 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013977 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013979 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013980 },
13981 {
13982 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013983 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013984 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013985 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013987 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013988 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013989 {
13990 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013991 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020013992 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020013993 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013995 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013996 },
13997 {
13998 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013999 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014000 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014001 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014003 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014004 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014005#ifdef CONFIG_NL80211_TESTMODE
14006 {
14007 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014009 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014010 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014011 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014012 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14013 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014014 },
14015#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014016 {
14017 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014018 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014019 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014020 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014022 NL80211_FLAG_NEED_RTNL |
14023 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014024 },
14025 {
vamsi krishna088e8df2016-10-27 16:51:11 +030014026 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014027 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030014028 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030014029 .flags = GENL_ADMIN_PERM,
14030 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014031 NL80211_FLAG_NEED_RTNL |
14032 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030014033 },
14034 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020014035 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014036 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014037 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014038 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014040 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014041 },
Johannes Berg463d0182009-07-14 00:33:35 +020014042 {
14043 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014044 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020014045 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020014046 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014047 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14048 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020014049 },
Holger Schurig61fa7132009-11-11 12:25:40 +010014050 {
14051 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014052 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010014053 .dumpit = nl80211_dump_survey,
14054 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014055 {
14056 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014057 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014058 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014059 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014061 NL80211_FLAG_NEED_RTNL |
14062 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014063 },
14064 {
14065 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014066 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014067 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014068 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014069 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014070 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014071 },
14072 {
14073 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014074 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014075 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014076 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014077 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014078 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014079 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014080 {
14081 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014082 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014083 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014084 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014085 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014086 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014087 },
14088 {
14089 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014090 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014091 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014092 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014093 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014094 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014095 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014096 {
14097 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014098 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014099 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020014100 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014101 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14102 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014103 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014104 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014105 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014106 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014107 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014108 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014109 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014110 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014111 },
14112 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014113 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014114 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014115 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014116 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014117 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014118 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014119 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014120 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014121 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014122 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014123 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014124 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014125 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014126 NL80211_FLAG_NEED_RTNL,
14127 },
14128 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014129 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014130 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014131 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014132 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014133 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14134 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014135 },
14136 {
14137 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014138 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014139 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014140 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020014141 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14142 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014143 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014144 {
14145 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020014146 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014147 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020014148 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014149 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14150 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014151 },
Johannes Bergf444de02010-05-05 15:25:02 +020014152 {
14153 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014154 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020014155 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014156 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014157 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14158 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020014159 },
Bill Jordane8347eb2010-10-01 13:54:28 -040014160 {
14161 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014162 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040014163 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020014164 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020014165 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14166 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040014167 },
Johannes Berg29cbe682010-12-03 09:20:44 +010014168 {
14169 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014170 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014171 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014172 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014173 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14174 NL80211_FLAG_NEED_RTNL,
14175 },
14176 {
14177 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014178 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014179 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014180 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014181 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14182 NL80211_FLAG_NEED_RTNL,
14183 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014184 {
14185 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014186 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014187 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014188 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014189 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14190 NL80211_FLAG_NEED_RTNL,
14191 },
14192 {
14193 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014194 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014195 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014196 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14198 NL80211_FLAG_NEED_RTNL,
14199 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014200#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020014201 {
14202 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014203 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014204 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014205 /* can be retrieved by unprivileged users */
14206 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14207 NL80211_FLAG_NEED_RTNL,
14208 },
14209 {
14210 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014211 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014212 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014213 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014214 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14215 NL80211_FLAG_NEED_RTNL,
14216 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014217#endif
Johannes Berge5497d72011-07-05 16:35:40 +020014218 {
14219 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020014220 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020014221 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020014222 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020014223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014224 NL80211_FLAG_NEED_RTNL |
14225 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020014226 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030014227 {
14228 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014229 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014230 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014231 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014232 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14233 NL80211_FLAG_NEED_RTNL,
14234 },
14235 {
14236 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014237 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014238 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020014239 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14241 NL80211_FLAG_NEED_RTNL,
14242 },
Johannes Berg28946da2011-11-04 11:18:12 +010014243 {
14244 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010014246 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020014247 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010014248 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14249 NL80211_FLAG_NEED_RTNL,
14250 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010014251 {
14252 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014253 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010014254 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020014255 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010014257 NL80211_FLAG_NEED_RTNL,
14258 },
Johannes Berg5e760232011-11-04 11:18:17 +010014259 {
14260 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010014262 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020014263 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010014264 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14265 NL80211_FLAG_NEED_RTNL,
14266 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014267 {
14268 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014270 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014271 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014272 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14273 NL80211_FLAG_NEED_RTNL,
14274 },
Johannes Berg98104fde2012-06-16 00:19:54 +020014275 {
14276 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014277 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014278 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014280 .internal_flags = NL80211_FLAG_NEED_WDEV |
14281 NL80211_FLAG_NEED_RTNL,
14282 },
14283 {
14284 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014285 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014286 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014288 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14289 NL80211_FLAG_NEED_RTNL,
14290 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014291 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014292 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014293 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014294 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014295 .flags = GENL_ADMIN_PERM,
14296 .internal_flags = NL80211_FLAG_NEED_WDEV |
14297 NL80211_FLAG_NEED_RTNL,
14298 },
14299 {
14300 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014301 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014302 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014303 .flags = GENL_ADMIN_PERM,
14304 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14305 NL80211_FLAG_NEED_RTNL,
14306 },
14307 {
Ayala Bekera442b762016-09-20 17:31:15 +030014308 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014309 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014310 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014311 .flags = GENL_ADMIN_PERM,
14312 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14313 NL80211_FLAG_NEED_RTNL,
14314 },
14315 {
14316 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014317 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014318 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014319 .flags = GENL_ADMIN_PERM,
14320 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14321 NL80211_FLAG_NEED_RTNL,
14322 },
14323 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014324 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014325 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014326 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014327 .flags = GENL_ADMIN_PERM,
14328 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14329 NL80211_FLAG_NEED_RTNL,
14330 },
14331 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014332 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014333 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014334 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014335 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014336 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14337 NL80211_FLAG_NEED_RTNL,
14338 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014339 {
14340 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014341 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014342 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020014343 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014344 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14345 NL80211_FLAG_NEED_RTNL,
14346 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014347 {
14348 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014349 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014350 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020014351 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014352 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14353 NL80211_FLAG_NEED_RTNL,
14354 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014355 {
14356 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014357 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014358 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014359 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014360 {
14361 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014362 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020014363 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020014364 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14366 NL80211_FLAG_NEED_RTNL,
14367 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014368 {
14369 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014370 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014371 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020014372 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014373 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14374 NL80211_FLAG_NEED_RTNL,
14375 },
14376 {
14377 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014378 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014379 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020014380 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014381 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14382 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014383 },
14384 {
14385 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014386 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014387 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014388 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14389 NL80211_FLAG_NEED_RTNL,
14390 },
14391 {
14392 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014393 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014394 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020014395 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014396 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14397 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014398 },
14399 {
14400 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014402 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014403 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014404 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14405 NL80211_FLAG_NEED_RTNL,
14406 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014407 {
14408 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014409 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010014410 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014411 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014412 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014413 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014414 NL80211_FLAG_NEED_RTNL |
14415 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010014416 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014417 {
14418 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014419 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014420 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014421 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14423 NL80211_FLAG_NEED_RTNL,
14424 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014425 {
14426 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014427 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014428 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014429 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014430 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14431 NL80211_FLAG_NEED_RTNL,
14432 },
14433 {
14434 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014435 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014436 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014437 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014438 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14439 NL80211_FLAG_NEED_RTNL,
14440 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014441 {
14442 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014443 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014444 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014445 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014446 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14447 NL80211_FLAG_NEED_RTNL,
14448 },
14449 {
14450 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014451 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014452 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014453 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014454 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14455 NL80211_FLAG_NEED_RTNL,
14456 },
Michael Braunce0ce132016-10-10 19:12:22 +020014457 {
14458 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020014459 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020014460 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020014461 .flags = GENL_UNS_ADMIN_PERM,
14462 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14463 NL80211_FLAG_NEED_RTNL,
14464 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014465 {
14466 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014467 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014468 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014470 NL80211_FLAG_NEED_RTNL |
14471 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010014472 },
14473 {
14474 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014475 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014476 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14478 NL80211_FLAG_NEED_RTNL,
14479 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014480 {
14481 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014482 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014483 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014484 .flags = GENL_ADMIN_PERM,
14485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14486 NL80211_FLAG_NEED_RTNL,
14487 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014488 {
14489 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014490 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014491 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014492 .flags = GENL_UNS_ADMIN_PERM,
14493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14494 NL80211_FLAG_NEED_RTNL,
14495 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014496 {
14497 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014498 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014499 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014500 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14501 NL80211_FLAG_NEED_RTNL,
14502 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014503 {
14504 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014505 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014506 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014507 .flags = GENL_UNS_ADMIN_PERM,
14508 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14509 NL80211_FLAG_NEED_RTNL,
14510 },
Sriram R30c63112018-12-04 17:46:52 +053014511 {
14512 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014513 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053014514 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053014515 .flags = GENL_UNS_ADMIN_PERM,
14516 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14517 NL80211_FLAG_NEED_RTNL,
14518 },
Sunil Duttcb74e972019-02-20 16:18:07 +053014519 {
14520 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14521 .doit = nl80211_update_owe_info,
14522 .flags = GENL_ADMIN_PERM,
14523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14524 NL80211_FLAG_NEED_RTNL,
14525 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014526 {
14527 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14528 .doit = nl80211_probe_mesh_link,
14529 .flags = GENL_UNS_ADMIN_PERM,
14530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14531 NL80211_FLAG_NEED_RTNL,
14532 },
Johannes Berg55682962007-09-20 13:09:35 -040014533};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014534
Johannes Berg56989f62016-10-24 14:40:05 +020014535static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014536 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14537 .hdrsize = 0, /* no private header */
14538 .version = 1, /* no particular meaning now */
14539 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010014540 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020014541 .netnsok = true,
14542 .pre_doit = nl80211_pre_doit,
14543 .post_doit = nl80211_post_doit,
14544 .module = THIS_MODULE,
14545 .ops = nl80211_ops,
14546 .n_ops = ARRAY_SIZE(nl80211_ops),
14547 .mcgrps = nl80211_mcgrps,
14548 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
14549};
14550
Johannes Berg55682962007-09-20 13:09:35 -040014551/* notification functions */
14552
Johannes Berg3bb20552014-05-26 13:52:25 +020014553void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14554 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014555{
14556 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014557 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014558
Johannes Berg3bb20552014-05-26 13:52:25 +020014559 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14560 cmd != NL80211_CMD_DEL_WIPHY);
14561
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014562 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014563 if (!msg)
14564 return;
14565
Johannes Berg3bb20552014-05-26 13:52:25 +020014566 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014567 nlmsg_free(msg);
14568 return;
14569 }
14570
Johannes Berg68eb5502013-11-19 15:19:38 +010014571 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014572 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014573}
14574
Denis Kenzior896ff062016-08-03 16:58:33 -050014575void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14576 struct wireless_dev *wdev,
14577 enum nl80211_commands cmd)
14578{
14579 struct sk_buff *msg;
14580
Denis Kenzior896ff062016-08-03 16:58:33 -050014581 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14582 if (!msg)
14583 return;
14584
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014585 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014586 nlmsg_free(msg);
14587 return;
14588 }
14589
14590 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14591 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14592}
14593
Johannes Berg362a4152009-05-24 16:43:15 +020014594static int nl80211_add_scan_req(struct sk_buff *msg,
14595 struct cfg80211_registered_device *rdev)
14596{
14597 struct cfg80211_scan_request *req = rdev->scan_req;
14598 struct nlattr *nest;
14599 int i;
14600
14601 if (WARN_ON(!req))
14602 return 0;
14603
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014604 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020014605 if (!nest)
14606 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014607 for (i = 0; i < req->n_ssids; i++) {
14608 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14609 goto nla_put_failure;
14610 }
Johannes Berg362a4152009-05-24 16:43:15 +020014611 nla_nest_end(msg, nest);
14612
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014613 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Johannes Berg362a4152009-05-24 16:43:15 +020014614 if (!nest)
14615 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014616 for (i = 0; i < req->n_channels; i++) {
14617 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14618 goto nla_put_failure;
14619 }
Johannes Berg362a4152009-05-24 16:43:15 +020014620 nla_nest_end(msg, nest);
14621
David S. Miller9360ffd2012-03-29 04:41:26 -040014622 if (req->ie &&
14623 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14624 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014625
Johannes Bergae917c92013-10-25 11:05:22 +020014626 if (req->flags &&
14627 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14628 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014629
Avraham Stern1d762502016-07-05 17:10:13 +030014630 if (req->info.scan_start_tsf &&
14631 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14632 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14633 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14634 req->info.tsf_bssid)))
14635 goto nla_put_failure;
14636
Johannes Berg362a4152009-05-24 16:43:15 +020014637 return 0;
14638 nla_put_failure:
14639 return -ENOBUFS;
14640}
14641
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014642static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014643 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014644 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014645 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014646 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014647{
14648 void *hdr;
14649
Eric W. Biederman15e47302012-09-07 20:12:54 +000014650 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014651 if (!hdr)
14652 return -1;
14653
David S. Miller9360ffd2012-03-29 04:41:26 -040014654 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014655 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14656 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014657 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14658 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014659 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014660
Johannes Berg362a4152009-05-24 16:43:15 +020014661 /* ignore errors and send incomplete event anyway */
14662 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014663
Johannes Berg053c0952015-01-16 22:09:00 +010014664 genlmsg_end(msg, hdr);
14665 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014666
14667 nla_put_failure:
14668 genlmsg_cancel(msg, hdr);
14669 return -EMSGSIZE;
14670}
14671
Luciano Coelho807f8a82011-05-11 17:09:35 +030014672static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014673nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014674 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014675{
14676 void *hdr;
14677
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014678 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014679 if (!hdr)
14680 return -1;
14681
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014682 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14683 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14684 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14685 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14686 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014687 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014688
Johannes Berg053c0952015-01-16 22:09:00 +010014689 genlmsg_end(msg, hdr);
14690 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014691
14692 nla_put_failure:
14693 genlmsg_cancel(msg, hdr);
14694 return -EMSGSIZE;
14695}
14696
Johannes Berga538e2d2009-06-16 19:56:42 +020014697void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014698 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014699{
14700 struct sk_buff *msg;
14701
Thomas Graf58050fc2012-06-28 03:57:45 +000014702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014703 if (!msg)
14704 return;
14705
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014706 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014707 NL80211_CMD_TRIGGER_SCAN) < 0) {
14708 nlmsg_free(msg);
14709 return;
14710 }
14711
Johannes Berg68eb5502013-11-19 15:19:38 +010014712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014713 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014714}
14715
Johannes Bergf9d15d12014-01-22 11:14:19 +020014716struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14717 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014718{
14719 struct sk_buff *msg;
14720
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014722 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014723 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014724
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014725 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014726 aborted ? NL80211_CMD_SCAN_ABORTED :
14727 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014728 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014729 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014730 }
14731
Johannes Bergf9d15d12014-01-22 11:14:19 +020014732 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014733}
14734
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014735/* send message created by nl80211_build_scan_msg() */
14736void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14737 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014738{
Johannes Berg2a519312009-02-10 21:25:55 +010014739 if (!msg)
14740 return;
14741
Johannes Berg68eb5502013-11-19 15:19:38 +010014742 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014743 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014744}
14745
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014746void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014747{
14748 struct sk_buff *msg;
14749
Thomas Graf58050fc2012-06-28 03:57:45 +000014750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014751 if (!msg)
14752 return;
14753
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014754 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014755 nlmsg_free(msg);
14756 return;
14757 }
14758
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014759 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014760 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014761}
14762
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014763static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14764 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014765{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014766 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014767 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14768 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014769
David S. Miller9360ffd2012-03-29 04:41:26 -040014770 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14771 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14772 NL80211_REGDOM_TYPE_WORLD))
14773 goto nla_put_failure;
14774 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14775 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14776 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14777 goto nla_put_failure;
14778 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14779 request->intersect) {
14780 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14781 NL80211_REGDOM_TYPE_INTERSECTION))
14782 goto nla_put_failure;
14783 } else {
14784 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14785 NL80211_REGDOM_TYPE_COUNTRY) ||
14786 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14787 request->alpha2))
14788 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014789 }
14790
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014791 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14792 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14793
14794 if (wiphy &&
14795 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14796 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014797
14798 if (wiphy &&
14799 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14800 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14801 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014802 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014803
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014804 return true;
14805
14806nla_put_failure:
14807 return false;
14808}
14809
14810/*
14811 * This can happen on global regulatory changes or device specific settings
14812 * based on custom regulatory domains.
14813 */
14814void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14815 struct regulatory_request *request)
14816{
14817 struct sk_buff *msg;
14818 void *hdr;
14819
14820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14821 if (!msg)
14822 return;
14823
14824 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14825 if (!hdr) {
14826 nlmsg_free(msg);
14827 return;
14828 }
14829
14830 if (nl80211_reg_change_event_fill(msg, request) == false)
14831 goto nla_put_failure;
14832
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014833 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014834
Johannes Bergbc43b282009-07-25 10:54:13 +020014835 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014836 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014837 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014838 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014839
14840 return;
14841
14842nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014843 nlmsg_free(msg);
14844}
14845
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014846static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14847 struct net_device *netdev,
14848 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014849 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014850 int uapsd_queues, const u8 *req_ies,
14851 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014852{
14853 struct sk_buff *msg;
14854 void *hdr;
14855
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014856 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014857 if (!msg)
14858 return;
14859
14860 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14861 if (!hdr) {
14862 nlmsg_free(msg);
14863 return;
14864 }
14865
David S. Miller9360ffd2012-03-29 04:41:26 -040014866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14867 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014868 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14869 (req_ies &&
14870 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014871 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014872
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014873 if (uapsd_queues >= 0) {
14874 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014875 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014876 if (!nla_wmm)
14877 goto nla_put_failure;
14878
14879 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14880 uapsd_queues))
14881 goto nla_put_failure;
14882
14883 nla_nest_end(msg, nla_wmm);
14884 }
14885
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014886 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014887
Johannes Berg68eb5502013-11-19 15:19:38 +010014888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014889 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014890 return;
14891
14892 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014893 nlmsg_free(msg);
14894}
14895
14896void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014897 struct net_device *netdev, const u8 *buf,
14898 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014899{
14900 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014901 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014902}
14903
14904void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14905 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014906 size_t len, gfp_t gfp, int uapsd_queues,
14907 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014908{
Johannes Berge6d6e342009-07-01 21:26:47 +020014909 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014910 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
14911 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014912}
14913
Jouni Malinen53b46b82009-03-27 20:53:56 +020014914void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014915 struct net_device *netdev, const u8 *buf,
14916 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014917{
14918 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014919 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014920}
14921
Jouni Malinen53b46b82009-03-27 20:53:56 +020014922void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14923 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014924 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014925{
14926 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014927 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014928}
14929
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014930void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14931 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014932{
Johannes Berg947add32013-02-22 22:05:20 +010014933 struct wireless_dev *wdev = dev->ieee80211_ptr;
14934 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014935 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014936 const struct ieee80211_mgmt *mgmt = (void *)buf;
14937 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014938
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014939 if (WARN_ON(len < 2))
14940 return;
14941
14942 if (ieee80211_is_deauth(mgmt->frame_control))
14943 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14944 else
14945 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14946
14947 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014948 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
14949 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014950}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014951EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014952
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014953static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14954 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014955 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014956{
14957 struct sk_buff *msg;
14958 void *hdr;
14959
Johannes Berge6d6e342009-07-01 21:26:47 +020014960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014961 if (!msg)
14962 return;
14963
14964 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14965 if (!hdr) {
14966 nlmsg_free(msg);
14967 return;
14968 }
14969
David S. Miller9360ffd2012-03-29 04:41:26 -040014970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14972 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14973 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14974 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014975
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014976 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014977
Johannes Berg68eb5502013-11-19 15:19:38 +010014978 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014979 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014980 return;
14981
14982 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014983 nlmsg_free(msg);
14984}
14985
14986void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014987 struct net_device *netdev, const u8 *addr,
14988 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014989{
14990 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014991 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014992}
14993
14994void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014995 struct net_device *netdev, const u8 *addr,
14996 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014997{
Johannes Berge6d6e342009-07-01 21:26:47 +020014998 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14999 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015000}
15001
Samuel Ortizb23aa672009-07-01 21:26:54 +020015002void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015003 struct net_device *netdev,
15004 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015005 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015006{
15007 struct sk_buff *msg;
15008 void *hdr;
15009
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015010 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020015011 cr->fils.kek_len + cr->fils.pmk_len +
15012 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015013 if (!msg)
15014 return;
15015
15016 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15017 if (!hdr) {
15018 nlmsg_free(msg);
15019 return;
15020 }
15021
David S. Miller9360ffd2012-03-29 04:41:26 -040015022 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15023 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015024 (cr->bssid &&
15025 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030015026 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015027 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15028 cr->status) ||
15029 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015030 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015031 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15032 cr->timeout_reason))) ||
15033 (cr->req_ie &&
15034 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15035 (cr->resp_ie &&
15036 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015037 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020015038 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015039 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020015040 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015041 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020015042 ((cr->fils.kek &&
15043 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15044 cr->fils.kek)) ||
15045 (cr->fils.pmk &&
15046 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15047 (cr->fils.pmkid &&
15048 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040015049 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015050
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015051 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015052
Johannes Berg68eb5502013-11-19 15:19:38 +010015053 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015054 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015055 return;
15056
15057 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015058 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015059}
15060
15061void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015062 struct net_device *netdev,
15063 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015064{
15065 struct sk_buff *msg;
15066 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015067 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015068
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015069 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15070 info->fils.kek_len + info->fils.pmk_len +
15071 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015072 if (!msg)
15073 return;
15074
15075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15076 if (!hdr) {
15077 nlmsg_free(msg);
15078 return;
15079 }
15080
David S. Miller9360ffd2012-03-29 04:41:26 -040015081 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15082 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15083 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015084 (info->req_ie &&
15085 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15086 info->req_ie)) ||
15087 (info->resp_ie &&
15088 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015089 info->resp_ie)) ||
15090 (info->fils.update_erp_next_seq_num &&
15091 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15092 info->fils.erp_next_seq_num)) ||
15093 (info->fils.kek &&
15094 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15095 info->fils.kek)) ||
15096 (info->fils.pmk &&
15097 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15098 (info->fils.pmkid &&
15099 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015100 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015101
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015102 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015103
Johannes Berg68eb5502013-11-19 15:19:38 +010015104 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015105 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015106 return;
15107
15108 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015109 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015110}
15111
Avraham Stern503c1fb2017-09-29 14:21:49 +020015112void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15113 struct net_device *netdev, const u8 *bssid)
15114{
15115 struct sk_buff *msg;
15116 void *hdr;
15117
15118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15119 if (!msg)
15120 return;
15121
15122 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15123 if (!hdr) {
15124 nlmsg_free(msg);
15125 return;
15126 }
15127
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000015128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15129 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15130 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020015131 goto nla_put_failure;
15132
15133 genlmsg_end(msg, hdr);
15134
15135 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15136 NL80211_MCGRP_MLME, GFP_KERNEL);
15137 return;
15138
15139 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020015140 nlmsg_free(msg);
15141}
15142
Samuel Ortizb23aa672009-07-01 21:26:54 +020015143void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15144 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020015145 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015146{
15147 struct sk_buff *msg;
15148 void *hdr;
15149
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015150 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015151 if (!msg)
15152 return;
15153
15154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15155 if (!hdr) {
15156 nlmsg_free(msg);
15157 return;
15158 }
15159
David S. Miller9360ffd2012-03-29 04:41:26 -040015160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020015162 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040015163 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15164 (from_ap &&
15165 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15166 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15167 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015168
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015169 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015170
Johannes Berg68eb5502013-11-19 15:19:38 +010015171 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015172 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015173 return;
15174
15175 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015176 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015177}
15178
Johannes Berg04a773a2009-04-19 21:24:32 +020015179void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15180 struct net_device *netdev, const u8 *bssid,
15181 gfp_t gfp)
15182{
15183 struct sk_buff *msg;
15184 void *hdr;
15185
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015187 if (!msg)
15188 return;
15189
15190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15191 if (!hdr) {
15192 nlmsg_free(msg);
15193 return;
15194 }
15195
David S. Miller9360ffd2012-03-29 04:41:26 -040015196 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15198 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15199 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020015200
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015201 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020015202
Johannes Berg68eb5502013-11-19 15:19:38 +010015203 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015204 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015205 return;
15206
15207 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020015208 nlmsg_free(msg);
15209}
15210
Johannes Berg947add32013-02-22 22:05:20 +010015211void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040015212 const u8 *ie, u8 ie_len,
15213 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070015214{
Johannes Berg947add32013-02-22 22:05:20 +010015215 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015216 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015217 struct sk_buff *msg;
15218 void *hdr;
15219
Johannes Berg947add32013-02-22 22:05:20 +010015220 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15221 return;
15222
15223 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15224
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015225 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015226 if (!msg)
15227 return;
15228
15229 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15230 if (!hdr) {
15231 nlmsg_free(msg);
15232 return;
15233 }
15234
David S. Miller9360ffd2012-03-29 04:41:26 -040015235 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015236 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15237 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015238 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040015239 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15240 (sig_dbm &&
15241 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015242 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070015243
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015244 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015245
Johannes Berg68eb5502013-11-19 15:19:38 +010015246 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015247 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015248 return;
15249
15250 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070015251 nlmsg_free(msg);
15252}
Johannes Berg947add32013-02-22 22:05:20 +010015253EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015254
Jouni Malinena3b8b052009-03-27 21:59:49 +020015255void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15256 struct net_device *netdev, const u8 *addr,
15257 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020015258 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020015259{
15260 struct sk_buff *msg;
15261 void *hdr;
15262
Johannes Berge6d6e342009-07-01 21:26:47 +020015263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015264 if (!msg)
15265 return;
15266
15267 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15268 if (!hdr) {
15269 nlmsg_free(msg);
15270 return;
15271 }
15272
David S. Miller9360ffd2012-03-29 04:41:26 -040015273 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15274 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15275 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15276 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15277 (key_id != -1 &&
15278 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15279 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15280 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020015281
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015282 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015283
Johannes Berg68eb5502013-11-19 15:19:38 +010015284 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015285 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015286 return;
15287
15288 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020015289 nlmsg_free(msg);
15290}
15291
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015292void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15293 struct ieee80211_channel *channel_before,
15294 struct ieee80211_channel *channel_after)
15295{
15296 struct sk_buff *msg;
15297 void *hdr;
15298 struct nlattr *nl_freq;
15299
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015301 if (!msg)
15302 return;
15303
15304 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15305 if (!hdr) {
15306 nlmsg_free(msg);
15307 return;
15308 }
15309
15310 /*
15311 * Since we are applying the beacon hint to a wiphy we know its
15312 * wiphy_idx is valid
15313 */
David S. Miller9360ffd2012-03-29 04:41:26 -040015314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15315 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015316
15317 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015318 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015319 if (!nl_freq)
15320 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015321
15322 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015323 goto nla_put_failure;
15324 nla_nest_end(msg, nl_freq);
15325
15326 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015327 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015328 if (!nl_freq)
15329 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015330
15331 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015332 goto nla_put_failure;
15333 nla_nest_end(msg, nl_freq);
15334
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015335 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015336
Johannes Berg463d0182009-07-14 00:33:35 +020015337 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015338 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015339 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020015340 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015341
15342 return;
15343
15344nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015345 nlmsg_free(msg);
15346}
15347
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015348static void nl80211_send_remain_on_chan_event(
15349 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015350 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015351 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015352 unsigned int duration, gfp_t gfp)
15353{
15354 struct sk_buff *msg;
15355 void *hdr;
15356
15357 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15358 if (!msg)
15359 return;
15360
15361 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
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 Berg71bbc992012-06-15 15:30:18 +020015368 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15369 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015370 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15371 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015372 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015373 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15374 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015375 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15376 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015377 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015378
David S. Miller9360ffd2012-03-29 04:41:26 -040015379 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15380 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15381 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015382
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015383 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015384
Johannes Berg68eb5502013-11-19 15:19:38 +010015385 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015386 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015387 return;
15388
15389 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015390 nlmsg_free(msg);
15391}
15392
Johannes Berg947add32013-02-22 22:05:20 +010015393void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15394 struct ieee80211_channel *chan,
15395 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015396{
Johannes Berg947add32013-02-22 22:05:20 +010015397 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015398 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015399
15400 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015401 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015402 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015403 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015404}
Johannes Berg947add32013-02-22 22:05:20 +010015405EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015406
Johannes Berg947add32013-02-22 22:05:20 +010015407void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15408 struct ieee80211_channel *chan,
15409 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015410{
Johannes Berg947add32013-02-22 22:05:20 +010015411 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015413
15414 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015415 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015416 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015417}
Johannes Berg947add32013-02-22 22:05:20 +010015418EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015419
Johannes Berg947add32013-02-22 22:05:20 +010015420void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15421 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015422{
Johannes Berg947add32013-02-22 22:05:20 +010015423 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015424 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015425 struct sk_buff *msg;
15426
Johannes Berg947add32013-02-22 22:05:20 +010015427 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15428
Thomas Graf58050fc2012-06-28 03:57:45 +000015429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015430 if (!msg)
15431 return;
15432
Johannes Bergcf5ead82014-11-14 17:14:00 +010015433 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015434 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015435 nlmsg_free(msg);
15436 return;
15437 }
15438
Johannes Berg68eb5502013-11-19 15:19:38 +010015439 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015440 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015441}
Johannes Berg947add32013-02-22 22:05:20 +010015442EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015443
Johannes Bergcf5ead82014-11-14 17:14:00 +010015444void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15445 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015446{
Johannes Berg947add32013-02-22 22:05:20 +010015447 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015448 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015449 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015450 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015451
Johannes Berg73887fd2018-05-18 09:57:55 +020015452 if (!sinfo)
15453 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015454
Johannes Berg947add32013-02-22 22:05:20 +010015455 trace_cfg80211_del_sta(dev, mac_addr);
15456
Thomas Graf58050fc2012-06-28 03:57:45 +000015457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015458 if (!msg) {
15459 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015460 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015461 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015462
Johannes Bergcf5ead82014-11-14 17:14:00 +010015463 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015464 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015465 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015466 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015467 }
15468
Johannes Berg68eb5502013-11-19 15:19:38 +010015469 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015470 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015471}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015472EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015473
Johannes Berg947add32013-02-22 22:05:20 +010015474void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15475 enum nl80211_connect_failed_reason reason,
15476 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015477{
Johannes Berg947add32013-02-22 22:05:20 +010015478 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015479 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015480 struct sk_buff *msg;
15481 void *hdr;
15482
15483 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15484 if (!msg)
15485 return;
15486
15487 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15488 if (!hdr) {
15489 nlmsg_free(msg);
15490 return;
15491 }
15492
15493 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15495 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15496 goto nla_put_failure;
15497
15498 genlmsg_end(msg, hdr);
15499
Johannes Berg68eb5502013-11-19 15:19:38 +010015500 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015501 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015502 return;
15503
15504 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015505 nlmsg_free(msg);
15506}
Johannes Berg947add32013-02-22 22:05:20 +010015507EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015508
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015509static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15510 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015511{
15512 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015513 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015514 struct sk_buff *msg;
15515 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015516 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015517
Eric W. Biederman15e47302012-09-07 20:12:54 +000015518 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015519 return false;
15520
15521 msg = nlmsg_new(100, gfp);
15522 if (!msg)
15523 return true;
15524
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015525 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015526 if (!hdr) {
15527 nlmsg_free(msg);
15528 return true;
15529 }
15530
David S. Miller9360ffd2012-03-29 04:41:26 -040015531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15532 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15533 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15534 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015535
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015536 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015537 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015538 return true;
15539
15540 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015541 nlmsg_free(msg);
15542 return true;
15543}
15544
Johannes Berg947add32013-02-22 22:05:20 +010015545bool cfg80211_rx_spurious_frame(struct net_device *dev,
15546 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015547{
Johannes Berg947add32013-02-22 22:05:20 +010015548 struct wireless_dev *wdev = dev->ieee80211_ptr;
15549 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015550
Johannes Berg947add32013-02-22 22:05:20 +010015551 trace_cfg80211_rx_spurious_frame(dev, addr);
15552
15553 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15554 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15555 trace_cfg80211_return_bool(false);
15556 return false;
15557 }
15558 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15559 addr, gfp);
15560 trace_cfg80211_return_bool(ret);
15561 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015562}
Johannes Berg947add32013-02-22 22:05:20 +010015563EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15564
15565bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15566 const u8 *addr, gfp_t gfp)
15567{
15568 struct wireless_dev *wdev = dev->ieee80211_ptr;
15569 bool ret;
15570
15571 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15572
15573 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15574 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15575 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15576 trace_cfg80211_return_bool(false);
15577 return false;
15578 }
15579 ret = __nl80211_unexpected_frame(dev,
15580 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15581 addr, gfp);
15582 trace_cfg80211_return_bool(ret);
15583 return ret;
15584}
15585EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015586
Johannes Berg2e161f782010-08-12 15:38:38 +020015587int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015588 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015589 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015590 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015591{
Johannes Berg71bbc992012-06-15 15:30:18 +020015592 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015593 struct sk_buff *msg;
15594 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015595
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015596 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015597 if (!msg)
15598 return -ENOMEM;
15599
Johannes Berg2e161f782010-08-12 15:38:38 +020015600 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015601 if (!hdr) {
15602 nlmsg_free(msg);
15603 return -ENOMEM;
15604 }
15605
David S. Miller9360ffd2012-03-29 04:41:26 -040015606 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015607 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15608 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015609 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15610 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015611 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15612 (sig_dbm &&
15613 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015614 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15615 (flags &&
15616 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015617 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015618
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015619 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015620
Eric W. Biederman15e47302012-09-07 20:12:54 +000015621 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015622
15623 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015624 nlmsg_free(msg);
15625 return -ENOBUFS;
15626}
15627
Johannes Berg947add32013-02-22 22:05:20 +010015628void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15629 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015630{
Johannes Berg947add32013-02-22 22:05:20 +010015631 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015632 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015633 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015634 struct sk_buff *msg;
15635 void *hdr;
15636
Johannes Berg947add32013-02-22 22:05:20 +010015637 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15638
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015639 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015640 if (!msg)
15641 return;
15642
Johannes Berg2e161f782010-08-12 15:38:38 +020015643 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015644 if (!hdr) {
15645 nlmsg_free(msg);
15646 return;
15647 }
15648
David S. Miller9360ffd2012-03-29 04:41:26 -040015649 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015650 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15651 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015652 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15653 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015654 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015655 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15656 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015657 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15658 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015659
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015660 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015661
Johannes Berg68eb5502013-11-19 15:19:38 +010015662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015663 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015664 return;
15665
15666 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015667 nlmsg_free(msg);
15668}
Johannes Berg947add32013-02-22 22:05:20 +010015669EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015670
Denis Kenzior6a671a52018-03-26 12:52:41 -050015671static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015672 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015673 bool unencrypted, gfp_t gfp)
15674{
15675 struct wireless_dev *wdev = dev->ieee80211_ptr;
15676 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015677 struct ethhdr *ehdr = eth_hdr(skb);
15678 const u8 *addr = ehdr->h_source;
15679 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015680 struct sk_buff *msg;
15681 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015682 struct nlattr *frame;
15683
Denis Kenzior6a671a52018-03-26 12:52:41 -050015684 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15685
15686 if (!nlportid)
15687 return -ENOENT;
15688
Denis Kenziora948f712018-07-03 15:05:48 -050015689 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015690 if (!msg)
15691 return -ENOMEM;
15692
15693 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15694 if (!hdr) {
15695 nlmsg_free(msg);
15696 return -ENOBUFS;
15697 }
15698
15699 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15700 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15701 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15702 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015703 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15704 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15705 (unencrypted && nla_put_flag(msg,
15706 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15707 goto nla_put_failure;
15708
Denis Kenziora948f712018-07-03 15:05:48 -050015709 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15710 if (!frame)
15711 goto nla_put_failure;
15712
15713 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015714 genlmsg_end(msg, hdr);
15715
15716 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15717
15718 nla_put_failure:
15719 nlmsg_free(msg);
15720 return -ENOBUFS;
15721}
15722
15723bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015724 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015725{
15726 int ret;
15727
Denis Kenziora948f712018-07-03 15:05:48 -050015728 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15729 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015730 trace_cfg80211_return_bool(ret == 0);
15731 return ret == 0;
15732}
15733EXPORT_SYMBOL(cfg80211_rx_control_port);
15734
Johannes Berg5b97f492014-11-26 12:37:43 +010015735static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15736 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015737{
Johannes Berg947add32013-02-22 22:05:20 +010015738 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015739 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15740 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15741 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015742
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015743 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015744 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015745
Johannes Berg5b97f492014-11-26 12:37:43 +010015746 cb = (void **)msg->cb;
15747
15748 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15749 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015750 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015751 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015752 }
15753
David S. Miller9360ffd2012-03-29 04:41:26 -040015754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015756 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015757
Johannes Berg5b97f492014-11-26 12:37:43 +010015758 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015759 goto nla_put_failure;
15760
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015761 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010015762 if (!cb[1])
15763 goto nla_put_failure;
15764
15765 cb[2] = rdev;
15766
15767 return msg;
15768 nla_put_failure:
15769 nlmsg_free(msg);
15770 return NULL;
15771}
15772
15773static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15774{
15775 void **cb = (void **)msg->cb;
15776 struct cfg80211_registered_device *rdev = cb[2];
15777
15778 nla_nest_end(msg, cb[1]);
15779 genlmsg_end(msg, cb[0]);
15780
15781 memset(msg->cb, 0, sizeof(msg->cb));
15782
15783 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15784 NL80211_MCGRP_MLME, gfp);
15785}
15786
15787void cfg80211_cqm_rssi_notify(struct net_device *dev,
15788 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015789 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015790{
15791 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015792 struct wireless_dev *wdev = dev->ieee80211_ptr;
15793 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015794
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015795 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015796
Johannes Berg98f03342014-11-26 12:42:02 +010015797 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15798 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15799 return;
15800
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015801 if (wdev->cqm_config) {
15802 wdev->cqm_config->last_rssi_event_value = rssi_level;
15803
15804 cfg80211_cqm_rssi_update(rdev, dev);
15805
15806 if (rssi_level == 0)
15807 rssi_level = wdev->cqm_config->last_rssi_event_value;
15808 }
15809
Johannes Berg5b97f492014-11-26 12:37:43 +010015810 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15811 if (!msg)
15812 return;
15813
David S. Miller9360ffd2012-03-29 04:41:26 -040015814 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15815 rssi_event))
15816 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015817
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015818 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15819 rssi_level))
15820 goto nla_put_failure;
15821
Johannes Berg5b97f492014-11-26 12:37:43 +010015822 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015823
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015824 return;
15825
15826 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015827 nlmsg_free(msg);
15828}
Johannes Berg947add32013-02-22 22:05:20 +010015829EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015830
Johannes Berg5b97f492014-11-26 12:37:43 +010015831void cfg80211_cqm_txe_notify(struct net_device *dev,
15832 const u8 *peer, u32 num_packets,
15833 u32 rate, u32 intvl, gfp_t gfp)
15834{
15835 struct sk_buff *msg;
15836
15837 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15838 if (!msg)
15839 return;
15840
15841 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15842 goto nla_put_failure;
15843
15844 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15845 goto nla_put_failure;
15846
15847 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15848 goto nla_put_failure;
15849
15850 cfg80211_send_cqm(msg, gfp);
15851 return;
15852
15853 nla_put_failure:
15854 nlmsg_free(msg);
15855}
15856EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15857
15858void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15859 const u8 *peer, u32 num_packets, gfp_t gfp)
15860{
15861 struct sk_buff *msg;
15862
15863 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15864
15865 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15866 if (!msg)
15867 return;
15868
15869 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15870 goto nla_put_failure;
15871
15872 cfg80211_send_cqm(msg, gfp);
15873 return;
15874
15875 nla_put_failure:
15876 nlmsg_free(msg);
15877}
15878EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15879
Johannes Berg98f03342014-11-26 12:42:02 +010015880void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15881{
15882 struct sk_buff *msg;
15883
15884 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15885 if (!msg)
15886 return;
15887
15888 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15889 goto nla_put_failure;
15890
15891 cfg80211_send_cqm(msg, gfp);
15892 return;
15893
15894 nla_put_failure:
15895 nlmsg_free(msg);
15896}
15897EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15898
Johannes Berg947add32013-02-22 22:05:20 +010015899static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15900 struct net_device *netdev, const u8 *bssid,
15901 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015902{
15903 struct sk_buff *msg;
15904 struct nlattr *rekey_attr;
15905 void *hdr;
15906
Thomas Graf58050fc2012-06-28 03:57:45 +000015907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015908 if (!msg)
15909 return;
15910
15911 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15912 if (!hdr) {
15913 nlmsg_free(msg);
15914 return;
15915 }
15916
David S. Miller9360ffd2012-03-29 04:41:26 -040015917 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15918 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15919 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15920 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015921
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015922 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020015923 if (!rekey_attr)
15924 goto nla_put_failure;
15925
David S. Miller9360ffd2012-03-29 04:41:26 -040015926 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15927 NL80211_REPLAY_CTR_LEN, replay_ctr))
15928 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015929
15930 nla_nest_end(msg, rekey_attr);
15931
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015932 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015933
Johannes Berg68eb5502013-11-19 15:19:38 +010015934 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015935 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015936 return;
15937
15938 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015939 nlmsg_free(msg);
15940}
15941
Johannes Berg947add32013-02-22 22:05:20 +010015942void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15943 const u8 *replay_ctr, gfp_t gfp)
15944{
15945 struct wireless_dev *wdev = dev->ieee80211_ptr;
15946 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015947 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015948
15949 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15950 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15951}
15952EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15953
15954static void
15955nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15956 struct net_device *netdev, int index,
15957 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015958{
15959 struct sk_buff *msg;
15960 struct nlattr *attr;
15961 void *hdr;
15962
Thomas Graf58050fc2012-06-28 03:57:45 +000015963 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015964 if (!msg)
15965 return;
15966
15967 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15968 if (!hdr) {
15969 nlmsg_free(msg);
15970 return;
15971 }
15972
David S. Miller9360ffd2012-03-29 04:41:26 -040015973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15974 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15975 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015976
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015977 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015978 if (!attr)
15979 goto nla_put_failure;
15980
David S. Miller9360ffd2012-03-29 04:41:26 -040015981 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15982 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15983 (preauth &&
15984 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15985 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015986
15987 nla_nest_end(msg, attr);
15988
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015989 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015990
Johannes Berg68eb5502013-11-19 15:19:38 +010015991 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015992 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015993 return;
15994
15995 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015996 nlmsg_free(msg);
15997}
15998
Johannes Berg947add32013-02-22 22:05:20 +010015999void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16000 const u8 *bssid, bool preauth, gfp_t gfp)
16001{
16002 struct wireless_dev *wdev = dev->ieee80211_ptr;
16003 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016004 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016005
16006 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16007 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16008}
16009EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16010
16011static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16012 struct net_device *netdev,
16013 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020016014 gfp_t gfp,
16015 enum nl80211_commands notif,
16016 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070016017{
16018 struct sk_buff *msg;
16019 void *hdr;
16020
Thomas Graf58050fc2012-06-28 03:57:45 +000016021 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016022 if (!msg)
16023 return;
16024
Luciano Coelhof8d75522014-11-07 14:31:35 +020016025 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070016026 if (!hdr) {
16027 nlmsg_free(msg);
16028 return;
16029 }
16030
Johannes Berg683b6d32012-11-08 21:25:48 +010016031 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16032 goto nla_put_failure;
16033
16034 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040016035 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070016036
Luciano Coelhof8d75522014-11-07 14:31:35 +020016037 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16038 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16039 goto nla_put_failure;
16040
Thomas Pedersen53145262012-04-06 13:35:47 -070016041 genlmsg_end(msg, hdr);
16042
Johannes Berg68eb5502013-11-19 15:19:38 +010016043 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016044 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016045 return;
16046
16047 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070016048 nlmsg_free(msg);
16049}
16050
Johannes Berg947add32013-02-22 22:05:20 +010016051void cfg80211_ch_switch_notify(struct net_device *dev,
16052 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070016053{
Johannes Berg947add32013-02-22 22:05:20 +010016054 struct wireless_dev *wdev = dev->ieee80211_ptr;
16055 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016056 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016057
Simon Wunderliche487eae2013-11-21 18:19:51 +010016058 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016059
Simon Wunderliche487eae2013-11-21 18:19:51 +010016060 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016061
Michal Kazior9e0e2962014-01-29 14:22:27 +010016062 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016063 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016064
16065 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16066 !WARN_ON(!wdev->current_bss))
16067 wdev->current_bss->pub.channel = chandef->chan;
16068
Luciano Coelhof8d75522014-11-07 14:31:35 +020016069 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16070 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010016071}
16072EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16073
Luciano Coelhof8d75522014-11-07 14:31:35 +020016074void cfg80211_ch_switch_started_notify(struct net_device *dev,
16075 struct cfg80211_chan_def *chandef,
16076 u8 count)
16077{
16078 struct wireless_dev *wdev = dev->ieee80211_ptr;
16079 struct wiphy *wiphy = wdev->wiphy;
16080 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16081
16082 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16083
16084 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16085 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16086}
16087EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16088
Thomas Pedersen84f10702012-07-12 16:17:33 -070016089void
Simon Wunderlich04f39042013-02-08 18:16:19 +010016090nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010016091 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010016092 enum nl80211_radar_event event,
16093 struct net_device *netdev, gfp_t gfp)
16094{
16095 struct sk_buff *msg;
16096 void *hdr;
16097
16098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16099 if (!msg)
16100 return;
16101
16102 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16103 if (!hdr) {
16104 nlmsg_free(msg);
16105 return;
16106 }
16107
16108 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16109 goto nla_put_failure;
16110
16111 /* NOP and radar events don't need a netdev parameter */
16112 if (netdev) {
16113 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16114
16115 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016116 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16117 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010016118 goto nla_put_failure;
16119 }
16120
16121 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16122 goto nla_put_failure;
16123
16124 if (nl80211_send_chandef(msg, chandef))
16125 goto nla_put_failure;
16126
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016127 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016128
Johannes Berg68eb5502013-11-19 15:19:38 +010016129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016130 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016131 return;
16132
16133 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010016134 nlmsg_free(msg);
16135}
16136
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053016137void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16138 struct sta_opmode_info *sta_opmode,
16139 gfp_t gfp)
16140{
16141 struct sk_buff *msg;
16142 struct wireless_dev *wdev = dev->ieee80211_ptr;
16143 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16144 void *hdr;
16145
16146 if (WARN_ON(!mac))
16147 return;
16148
16149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16150 if (!msg)
16151 return;
16152
16153 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16154 if (!hdr) {
16155 nlmsg_free(msg);
16156 return;
16157 }
16158
16159 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16160 goto nla_put_failure;
16161
16162 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16163 goto nla_put_failure;
16164
16165 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16166 goto nla_put_failure;
16167
16168 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16169 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16170 goto nla_put_failure;
16171
16172 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16173 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16174 goto nla_put_failure;
16175
16176 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16177 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16178 goto nla_put_failure;
16179
16180 genlmsg_end(msg, hdr);
16181
16182 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16183 NL80211_MCGRP_MLME, gfp);
16184
16185 return;
16186
16187nla_put_failure:
16188 nlmsg_free(msg);
16189}
16190EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16191
Johannes Berg7f6cf312011-11-04 11:18:15 +010016192void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016193 u64 cookie, bool acked, s32 ack_signal,
16194 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010016195{
16196 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016197 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016198 struct sk_buff *msg;
16199 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016200
Beni Lev4ee3e062012-08-27 12:49:39 +030016201 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16202
Thomas Graf58050fc2012-06-28 03:57:45 +000016203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030016204
Johannes Berg7f6cf312011-11-04 11:18:15 +010016205 if (!msg)
16206 return;
16207
16208 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16209 if (!hdr) {
16210 nlmsg_free(msg);
16211 return;
16212 }
16213
David S. Miller9360ffd2012-03-29 04:41:26 -040016214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16216 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016217 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16218 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016219 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16220 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16221 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016222 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016223
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016224 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016225
Johannes Berg68eb5502013-11-19 15:19:38 +010016226 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016227 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016228 return;
16229
16230 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010016231 nlmsg_free(msg);
16232}
16233EXPORT_SYMBOL(cfg80211_probe_status);
16234
Johannes Berg5e760232011-11-04 11:18:17 +010016235void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16236 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070016237 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010016238{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016239 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010016240 struct sk_buff *msg;
16241 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070016242 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010016243
Beni Lev4ee3e062012-08-27 12:49:39 +030016244 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16245
Ben Greear37c73b52012-10-26 14:49:25 -070016246 spin_lock_bh(&rdev->beacon_registrations_lock);
16247 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16248 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16249 if (!msg) {
16250 spin_unlock_bh(&rdev->beacon_registrations_lock);
16251 return;
16252 }
Johannes Berg5e760232011-11-04 11:18:17 +010016253
Ben Greear37c73b52012-10-26 14:49:25 -070016254 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16255 if (!hdr)
16256 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010016257
Ben Greear37c73b52012-10-26 14:49:25 -070016258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16259 (freq &&
16260 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16261 (sig_dbm &&
16262 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16263 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16264 goto nla_put_failure;
16265
16266 genlmsg_end(msg, hdr);
16267
16268 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010016269 }
Ben Greear37c73b52012-10-26 14:49:25 -070016270 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016271 return;
16272
16273 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070016274 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016275 nlmsg_free(msg);
16276}
16277EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16278
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016279#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016280static int cfg80211_net_detect_results(struct sk_buff *msg,
16281 struct cfg80211_wowlan_wakeup *wakeup)
16282{
16283 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16284 struct nlattr *nl_results, *nl_match, *nl_freqs;
16285 int i, j;
16286
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016287 nl_results = nla_nest_start_noflag(msg,
16288 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016289 if (!nl_results)
16290 return -EMSGSIZE;
16291
16292 for (i = 0; i < nd->n_matches; i++) {
16293 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16294
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016295 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016296 if (!nl_match)
16297 break;
16298
16299 /* The SSID attribute is optional in nl80211, but for
16300 * simplicity reasons it's always present in the
16301 * cfg80211 structure. If a driver can't pass the
16302 * SSID, that needs to be changed. A zero length SSID
16303 * is still a valid SSID (wildcard), so it cannot be
16304 * used for this purpose.
16305 */
16306 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16307 match->ssid.ssid)) {
16308 nla_nest_cancel(msg, nl_match);
16309 goto out;
16310 }
16311
16312 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016313 nl_freqs = nla_nest_start_noflag(msg,
16314 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016315 if (!nl_freqs) {
16316 nla_nest_cancel(msg, nl_match);
16317 goto out;
16318 }
16319
16320 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020016321 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016322 nla_nest_cancel(msg, nl_freqs);
16323 nla_nest_cancel(msg, nl_match);
16324 goto out;
16325 }
16326 }
16327
16328 nla_nest_end(msg, nl_freqs);
16329 }
16330
16331 nla_nest_end(msg, nl_match);
16332 }
16333
16334out:
16335 nla_nest_end(msg, nl_results);
16336 return 0;
16337}
16338
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016339void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16340 struct cfg80211_wowlan_wakeup *wakeup,
16341 gfp_t gfp)
16342{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016343 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016344 struct sk_buff *msg;
16345 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016346 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016347
16348 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16349
16350 if (wakeup)
16351 size += wakeup->packet_present_len;
16352
16353 msg = nlmsg_new(size, gfp);
16354 if (!msg)
16355 return;
16356
16357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16358 if (!hdr)
16359 goto free_msg;
16360
16361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016362 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16363 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016364 goto free_msg;
16365
16366 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16367 wdev->netdev->ifindex))
16368 goto free_msg;
16369
16370 if (wakeup) {
16371 struct nlattr *reasons;
16372
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016373 reasons = nla_nest_start_noflag(msg,
16374 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016375 if (!reasons)
16376 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016377
16378 if (wakeup->disconnect &&
16379 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16380 goto free_msg;
16381 if (wakeup->magic_pkt &&
16382 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16383 goto free_msg;
16384 if (wakeup->gtk_rekey_failure &&
16385 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16386 goto free_msg;
16387 if (wakeup->eap_identity_req &&
16388 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16389 goto free_msg;
16390 if (wakeup->four_way_handshake &&
16391 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16392 goto free_msg;
16393 if (wakeup->rfkill_release &&
16394 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16395 goto free_msg;
16396
16397 if (wakeup->pattern_idx >= 0 &&
16398 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16399 wakeup->pattern_idx))
16400 goto free_msg;
16401
Johannes Bergae917c92013-10-25 11:05:22 +020016402 if (wakeup->tcp_match &&
16403 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16404 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016405
Johannes Bergae917c92013-10-25 11:05:22 +020016406 if (wakeup->tcp_connlost &&
16407 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16408 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016409
Johannes Bergae917c92013-10-25 11:05:22 +020016410 if (wakeup->tcp_nomoretokens &&
16411 nla_put_flag(msg,
16412 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16413 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016414
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016415 if (wakeup->packet) {
16416 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16417 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16418
16419 if (!wakeup->packet_80211) {
16420 pkt_attr =
16421 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16422 len_attr =
16423 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16424 }
16425
16426 if (wakeup->packet_len &&
16427 nla_put_u32(msg, len_attr, wakeup->packet_len))
16428 goto free_msg;
16429
16430 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16431 wakeup->packet))
16432 goto free_msg;
16433 }
16434
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016435 if (wakeup->net_detect &&
16436 cfg80211_net_detect_results(msg, wakeup))
16437 goto free_msg;
16438
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016439 nla_nest_end(msg, reasons);
16440 }
16441
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016442 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016443
Johannes Berg68eb5502013-11-19 15:19:38 +010016444 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016445 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016446 return;
16447
16448 free_msg:
16449 nlmsg_free(msg);
16450}
16451EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16452#endif
16453
Jouni Malinen3475b092012-11-16 22:49:57 +020016454void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16455 enum nl80211_tdls_operation oper,
16456 u16 reason_code, gfp_t gfp)
16457{
16458 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016459 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016460 struct sk_buff *msg;
16461 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016462
16463 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16464 reason_code);
16465
16466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16467 if (!msg)
16468 return;
16469
16470 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16471 if (!hdr) {
16472 nlmsg_free(msg);
16473 return;
16474 }
16475
16476 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16478 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16479 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16480 (reason_code > 0 &&
16481 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16482 goto nla_put_failure;
16483
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016484 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016485
Johannes Berg68eb5502013-11-19 15:19:38 +010016486 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016487 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016488 return;
16489
16490 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016491 nlmsg_free(msg);
16492}
16493EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16494
Jouni Malinen026331c2010-02-15 12:53:10 +020016495static int nl80211_netlink_notify(struct notifier_block * nb,
16496 unsigned long state,
16497 void *_notify)
16498{
16499 struct netlink_notify *notify = _notify;
16500 struct cfg80211_registered_device *rdev;
16501 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016502 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016503
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016504 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016505 return NOTIFY_DONE;
16506
16507 rcu_read_lock();
16508
Johannes Berg5e760232011-11-04 11:18:17 +010016509 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016510 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016511
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016512 list_for_each_entry_rcu(sched_scan_req,
16513 &rdev->sched_scan_req_list,
16514 list) {
16515 if (sched_scan_req->owner_nlportid == notify->portid) {
16516 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010016517 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016518 }
Johannes Berg753aacf2017-01-05 10:57:14 +010016519 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016520
Johannes Berg53873f12016-05-03 16:52:04 +030016521 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016522 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016523
Johannes Bergab810072017-04-26 07:43:41 +020016524 if (wdev->owner_nlportid == notify->portid) {
16525 wdev->nl_owner_dead = true;
16526 schedule_work(&rdev->destroy_work);
16527 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016528 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016529 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016530
16531 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016532 }
16533
Ben Greear37c73b52012-10-26 14:49:25 -070016534 spin_lock_bh(&rdev->beacon_registrations_lock);
16535 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16536 list) {
16537 if (reg->nlportid == notify->portid) {
16538 list_del(&reg->list);
16539 kfree(reg);
16540 break;
16541 }
16542 }
16543 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016544 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016545
16546 rcu_read_unlock();
16547
Ilan peer05050752015-03-04 00:32:06 -050016548 /*
16549 * It is possible that the user space process that is controlling the
16550 * indoor setting disappeared, so notify the regulatory core.
16551 */
16552 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016553 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016554}
16555
16556static struct notifier_block nl80211_netlink_notifier = {
16557 .notifier_call = nl80211_netlink_notify,
16558};
16559
Jouni Malinen355199e2013-02-27 17:14:27 +020016560void cfg80211_ft_event(struct net_device *netdev,
16561 struct cfg80211_ft_event_params *ft_event)
16562{
16563 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016564 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016565 struct sk_buff *msg;
16566 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016567
16568 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16569
16570 if (!ft_event->target_ap)
16571 return;
16572
Dedy Lansky1039d082018-05-17 16:25:03 +030016573 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16574 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016575 if (!msg)
16576 return;
16577
16578 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016579 if (!hdr)
16580 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016581
Johannes Bergae917c92013-10-25 11:05:22 +020016582 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16583 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16584 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16585 goto out;
16586
16587 if (ft_event->ies &&
16588 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16589 goto out;
16590 if (ft_event->ric_ies &&
16591 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16592 ft_event->ric_ies))
16593 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016594
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016595 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016596
Johannes Berg68eb5502013-11-19 15:19:38 +010016597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016598 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016599 return;
16600 out:
16601 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016602}
16603EXPORT_SYMBOL(cfg80211_ft_event);
16604
Arend van Spriel5de17982013-04-18 15:49:00 +020016605void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16606{
16607 struct cfg80211_registered_device *rdev;
16608 struct sk_buff *msg;
16609 void *hdr;
16610 u32 nlportid;
16611
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016612 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016613 if (!rdev->crit_proto_nlportid)
16614 return;
16615
16616 nlportid = rdev->crit_proto_nlportid;
16617 rdev->crit_proto_nlportid = 0;
16618
16619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16620 if (!msg)
16621 return;
16622
16623 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16624 if (!hdr)
16625 goto nla_put_failure;
16626
16627 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016628 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16629 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016630 goto nla_put_failure;
16631
16632 genlmsg_end(msg, hdr);
16633
16634 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16635 return;
16636
16637 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016638 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016639}
16640EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16641
Johannes Berg348baf02014-01-24 14:06:29 +010016642void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16643{
16644 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016645 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016646 struct sk_buff *msg;
16647 void *hdr;
16648
16649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16650 if (!msg)
16651 return;
16652
16653 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16654 if (!hdr)
16655 goto out;
16656
16657 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16658 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016659 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16660 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016661 goto out;
16662
16663 genlmsg_end(msg, hdr);
16664
16665 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16666 NL80211_MCGRP_MLME, GFP_KERNEL);
16667 return;
16668 out:
16669 nlmsg_free(msg);
16670}
16671
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016672int cfg80211_external_auth_request(struct net_device *dev,
16673 struct cfg80211_external_auth_params *params,
16674 gfp_t gfp)
16675{
16676 struct wireless_dev *wdev = dev->ieee80211_ptr;
16677 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16678 struct sk_buff *msg;
16679 void *hdr;
16680
16681 if (!wdev->conn_owner_nlportid)
16682 return -EINVAL;
16683
16684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16685 if (!msg)
16686 return -ENOMEM;
16687
16688 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16689 if (!hdr)
16690 goto nla_put_failure;
16691
16692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16694 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16695 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16696 params->action) ||
16697 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16698 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16699 params->ssid.ssid))
16700 goto nla_put_failure;
16701
16702 genlmsg_end(msg, hdr);
16703 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16704 wdev->conn_owner_nlportid);
16705 return 0;
16706
16707 nla_put_failure:
16708 nlmsg_free(msg);
16709 return -ENOBUFS;
16710}
16711EXPORT_SYMBOL(cfg80211_external_auth_request);
16712
Sunil Duttcb74e972019-02-20 16:18:07 +053016713void cfg80211_update_owe_info_event(struct net_device *netdev,
16714 struct cfg80211_update_owe_info *owe_info,
16715 gfp_t gfp)
16716{
16717 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16718 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16719 struct sk_buff *msg;
16720 void *hdr;
16721
16722 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16723
16724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16725 if (!msg)
16726 return;
16727
16728 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16729 if (!hdr)
16730 goto nla_put_failure;
16731
16732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16734 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16735 goto nla_put_failure;
16736
16737 if (!owe_info->ie_len ||
16738 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16739 goto nla_put_failure;
16740
16741 genlmsg_end(msg, hdr);
16742
16743 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16744 NL80211_MCGRP_MLME, gfp);
16745 return;
16746
16747nla_put_failure:
16748 genlmsg_cancel(msg, hdr);
16749 nlmsg_free(msg);
16750}
16751EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16752
Johannes Berg55682962007-09-20 13:09:35 -040016753/* initialisation/exit functions */
16754
Johannes Berg56989f62016-10-24 14:40:05 +020016755int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016756{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016757 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016758
Johannes Berg489111e2016-10-24 14:40:03 +020016759 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016760 if (err)
16761 return err;
16762
Jouni Malinen026331c2010-02-15 12:53:10 +020016763 err = netlink_register_notifier(&nl80211_netlink_notifier);
16764 if (err)
16765 goto err_out;
16766
Johannes Berg55682962007-09-20 13:09:35 -040016767 return 0;
16768 err_out:
16769 genl_unregister_family(&nl80211_fam);
16770 return err;
16771}
16772
16773void nl80211_exit(void)
16774{
Jouni Malinen026331c2010-02-15 12:53:10 +020016775 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016776 genl_unregister_family(&nl80211_fam);
16777}