blob: 1c74ca377bd8efb52d832e09044b651f2ae701dd [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),
Johannes Berg55682962007-09-20 13:09:35 -0400574};
575
Johannes Berge31b8212010-10-05 19:39:30 +0200576/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000577static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200578 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200579 [NL80211_KEY_IDX] = { .type = NLA_U8 },
580 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200581 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200582 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
583 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200584 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100586 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100587};
588
589/* policy for the key default flags */
590static const struct nla_policy
591nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
592 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
593 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200594};
595
Johannes Bergf83ace32016-10-17 08:04:07 +0200596#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200597/* policy for WoWLAN attributes */
598static const struct nla_policy
599nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
600 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
601 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
602 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
603 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200604 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
605 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
606 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
607 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100608 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300609 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100610};
611
612static const struct nla_policy
613nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
614 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
615 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200616 [NL80211_WOWLAN_TCP_DST_MAC] = {
617 .type = NLA_EXACT_LEN_WARN,
618 .len = ETH_ALEN
619 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100620 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
621 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200622 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100623 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
624 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
625 },
626 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
627 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
628 },
629 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200630 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
631 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200632};
Johannes Bergf83ace32016-10-17 08:04:07 +0200633#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200634
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700635/* policy for coalesce rule attributes */
636static const struct nla_policy
637nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
638 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200639 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
640 NLA_POLICY_RANGE(NLA_U32,
641 NL80211_COALESCE_CONDITION_MATCH,
642 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700643 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
644};
645
Johannes Berge5497d72011-07-05 16:35:40 +0200646/* policy for GTK rekey offload attributes */
647static const struct nla_policy
648nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Johannes Berg1a28ed22019-05-28 14:18:07 +0200649 [NL80211_REKEY_DATA_KEK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KEK_LEN },
650 [NL80211_REKEY_DATA_KCK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KCK_LEN },
651 [NL80211_REKEY_DATA_REPLAY_CTR] = {
652 .type = NLA_EXACT_LEN_WARN,
653 .len = NL80211_REPLAY_CTR_LEN
654 },
Johannes Berge5497d72011-07-05 16:35:40 +0200655};
656
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300657static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530658nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
659 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
660 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
661 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
662};
663
664static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300665nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200666 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300667 .len = IEEE80211_MAX_SSID_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200668 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
669 .type = NLA_EXACT_LEN_WARN,
670 .len = ETH_ALEN
671 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700672 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530673 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
674 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300675};
676
Avraham Stern3b06d272015-10-12 09:51:34 +0300677static const struct nla_policy
678nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
679 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
680 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
681};
682
Arend van Spriel38de03d2016-03-02 20:37:18 +0100683static const struct nla_policy
684nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
685 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
686 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
687 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
688 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
689 },
690};
691
Ayala Bekera442b762016-09-20 17:31:15 +0300692/* policy for NAN function attributes */
693static const struct nla_policy
694nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
695 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300696 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300697 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
698 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
699 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
700 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
701 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
702 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200703 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
704 .type = NLA_EXACT_LEN_WARN,
705 .len = ETH_ALEN
706 },
Ayala Bekera442b762016-09-20 17:31:15 +0300707 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
708 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
709 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
710 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
711 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
712 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
713 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
714 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
715 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
716};
717
718/* policy for Service Response Filter attributes */
719static const struct nla_policy
720nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
721 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
722 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
723 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
724 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
725 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
726};
727
Peng Xuad670232017-10-03 23:21:51 +0300728/* policy for packet pattern attributes */
729static const struct nla_policy
730nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
731 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
732 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
733 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
734};
735
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200736int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
737 struct cfg80211_registered_device **rdev,
738 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100739{
Johannes Berg67748892010-10-04 21:14:06 +0200740 int err;
741
Johannes Berg97990a02013-04-19 01:02:55 +0200742 if (!cb->args[0]) {
Johannes Berg8cb08172019-04-26 14:07:28 +0200743 err = nlmsg_parse_deprecated(cb->nlh,
744 GENL_HDRLEN + nl80211_fam.hdrsize,
745 genl_family_attrbuf(&nl80211_fam),
746 nl80211_fam.maxattr,
747 nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200748 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100749 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200750
Johannes Bergc90c39d2016-10-24 14:40:01 +0200751 *wdev = __cfg80211_wdev_from_attrs(
Johannes Berg5297c652018-09-27 14:36:44 +0200752 sock_net(cb->skb->sk),
Johannes Bergc90c39d2016-10-24 14:40:01 +0200753 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100754 if (IS_ERR(*wdev))
755 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800756 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200757 /* 0 is the first index - add 1 to parse only once */
758 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200759 cb->args[1] = (*wdev)->identifier;
760 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200761 /* subtract the 1 again here */
762 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200763 struct wireless_dev *tmp;
764
Johannes Bergea90e0d2017-03-15 14:26:04 +0100765 if (!wiphy)
766 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800767 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200768 *wdev = NULL;
769
Johannes Berg53873f12016-05-03 16:52:04 +0300770 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200771 if (tmp->identifier == cb->args[1]) {
772 *wdev = tmp;
773 break;
774 }
775 }
Johannes Berg97990a02013-04-19 01:02:55 +0200776
Johannes Bergea90e0d2017-03-15 14:26:04 +0100777 if (!*wdev)
778 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200779 }
780
Johannes Berg67748892010-10-04 21:14:06 +0200781 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200782}
783
Johannes Berg55682962007-09-20 13:09:35 -0400784/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200785void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
786 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400787{
788 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000789 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400790}
791
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300792static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
793 const struct ieee80211_reg_rule *rule)
794{
795 int j;
796 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200797 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300798
799 if (!nl_wmm_rules)
800 goto nla_put_failure;
801
802 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200803 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300804
805 if (!nl_wmm_rule)
806 goto nla_put_failure;
807
808 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200809 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300810 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200811 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300812 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200813 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300814 nla_put_u16(msg, NL80211_WMMR_TXOP,
815 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300816 goto nla_put_failure;
817
818 nla_nest_end(msg, nl_wmm_rule);
819 }
820 nla_nest_end(msg, nl_wmm_rules);
821
822 return 0;
823
824nla_put_failure:
825 return -ENOBUFS;
826}
827
828static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100829 struct ieee80211_channel *chan,
830 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400831{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200832 /* Some channels must be completely excluded from the
833 * list to protect old user-space tools from breaking
834 */
835 if (!large && chan->flags &
836 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
837 return 0;
838
David S. Miller9360ffd2012-03-29 04:41:26 -0400839 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
840 chan->center_freq))
841 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400842
David S. Miller9360ffd2012-03-29 04:41:26 -0400843 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
844 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
845 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200846 if (chan->flags & IEEE80211_CHAN_NO_IR) {
847 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
848 goto nla_put_failure;
849 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
850 goto nla_put_failure;
851 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100852 if (chan->flags & IEEE80211_CHAN_RADAR) {
853 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
854 goto nla_put_failure;
855 if (large) {
856 u32 time;
857
858 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
859
860 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
861 chan->dfs_state))
862 goto nla_put_failure;
863 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
864 time))
865 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100866 if (nla_put_u32(msg,
867 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
868 chan->dfs_cac_ms))
869 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100870 }
871 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400872
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100873 if (large) {
874 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
875 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
876 goto nla_put_failure;
877 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
878 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
879 goto nla_put_failure;
880 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
881 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
882 goto nla_put_failure;
883 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
884 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
885 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200886 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
887 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
888 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300889 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
890 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200891 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200892 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
893 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
894 goto nla_put_failure;
895 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
896 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
897 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100898 }
899
David S. Miller9360ffd2012-03-29 04:41:26 -0400900 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
901 DBM_TO_MBM(chan->max_power)))
902 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400903
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300904 if (large) {
905 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300906 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300907
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200908 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300909 if (nl80211_msg_put_wmm_rules(msg, rule))
910 goto nla_put_failure;
911 }
912 }
913
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400914 return 0;
915
916 nla_put_failure:
917 return -ENOBUFS;
918}
919
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200920static bool nl80211_put_txq_stats(struct sk_buff *msg,
921 struct cfg80211_txq_stats *txqstats,
922 int attrtype)
923{
924 struct nlattr *txqattr;
925
926#define PUT_TXQVAL_U32(attr, memb) do { \
927 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
928 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
929 return false; \
930 } while (0)
931
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200932 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200933 if (!txqattr)
934 return false;
935
936 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
937 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
938 PUT_TXQVAL_U32(FLOWS, flows);
939 PUT_TXQVAL_U32(DROPS, drops);
940 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
941 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
942 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
943 PUT_TXQVAL_U32(COLLISIONS, collisions);
944 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
945 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
946 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
947 nla_nest_end(msg, txqattr);
948
949#undef PUT_TXQVAL_U32
950 return true;
951}
952
Johannes Berg55682962007-09-20 13:09:35 -0400953/* netlink command implementations */
954
Johannes Bergb9454e82009-07-08 13:29:08 +0200955struct key_parse {
956 struct key_params p;
957 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200958 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200959 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100960 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200961};
962
Johannes Berg768075e2017-11-13 15:35:06 +0100963static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
964 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200965{
966 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +0200967 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
968 nl80211_key_policy,
969 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200970 if (err)
971 return err;
972
973 k->def = !!tb[NL80211_KEY_DEFAULT];
974 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
975
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100976 if (k->def) {
977 k->def_uni = true;
978 k->def_multi = true;
979 }
980 if (k->defmgmt)
981 k->def_multi = true;
982
Johannes Bergb9454e82009-07-08 13:29:08 +0200983 if (tb[NL80211_KEY_IDX])
984 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
985
986 if (tb[NL80211_KEY_DATA]) {
987 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
988 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
989 }
990
991 if (tb[NL80211_KEY_SEQ]) {
992 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
993 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
994 }
995
996 if (tb[NL80211_KEY_CIPHER])
997 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
998
Johannes Bergab0d76f2018-10-02 10:00:07 +0200999 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001000 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001001
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001002 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1003 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001004
Johannes Berg8cb08172019-04-26 14:07:28 +02001005 err = nla_parse_nested_deprecated(kdt,
1006 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1007 tb[NL80211_KEY_DEFAULT_TYPES],
1008 nl80211_key_default_policy,
1009 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001010 if (err)
1011 return err;
1012
1013 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1014 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1015 }
1016
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001017 if (tb[NL80211_KEY_MODE])
1018 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1019
Johannes Bergb9454e82009-07-08 13:29:08 +02001020 return 0;
1021}
1022
1023static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1024{
1025 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1026 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1027 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1028 }
1029
1030 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1031 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1032 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1033 }
1034
1035 if (info->attrs[NL80211_ATTR_KEY_IDX])
1036 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1037
1038 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1039 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1040
1041 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1042 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1043
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001044 if (k->def) {
1045 k->def_uni = true;
1046 k->def_multi = true;
1047 }
1048 if (k->defmgmt)
1049 k->def_multi = true;
1050
Johannes Bergab0d76f2018-10-02 10:00:07 +02001051 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001052 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001053
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001054 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1055 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001056 int err = nla_parse_nested_deprecated(kdt,
1057 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1058 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1059 nl80211_key_default_policy,
1060 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001061 if (err)
1062 return err;
1063
1064 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1065 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1066 }
1067
Johannes Bergb9454e82009-07-08 13:29:08 +02001068 return 0;
1069}
1070
1071static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1072{
1073 int err;
1074
1075 memset(k, 0, sizeof(*k));
1076 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001077 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001078
1079 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001080 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001081 else
1082 err = nl80211_parse_key_old(info, k);
1083
1084 if (err)
1085 return err;
1086
Johannes Berg768075e2017-11-13 15:35:06 +01001087 if (k->def && k->defmgmt) {
1088 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001089 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001090 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001091
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001092 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001093 if (k->def_uni || !k->def_multi) {
1094 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001095 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001096 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001097 }
1098
Johannes Bergb9454e82009-07-08 13:29:08 +02001099 if (k->idx != -1) {
1100 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001101 if (k->idx < 4 || k->idx > 5) {
1102 GENL_SET_ERR_MSG(info,
1103 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001104 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001105 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001106 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001107 if (k->idx < 0 || k->idx > 3) {
1108 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001109 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001110 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001111 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001112 if (k->idx < 0 || k->idx > 5) {
1113 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001114 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001115 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001116 }
1117 }
1118
1119 return 0;
1120}
1121
Johannes Bergfffd0932009-07-08 14:22:54 +02001122static struct cfg80211_cached_keys *
1123nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001124 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001125{
Johannes Berg768075e2017-11-13 15:35:06 +01001126 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001127 struct key_parse parse;
1128 struct nlattr *key;
1129 struct cfg80211_cached_keys *result;
1130 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001131 bool have_key = false;
1132
1133 nla_for_each_nested(key, keys, rem) {
1134 have_key = true;
1135 break;
1136 }
1137
1138 if (!have_key)
1139 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001140
1141 result = kzalloc(sizeof(*result), GFP_KERNEL);
1142 if (!result)
1143 return ERR_PTR(-ENOMEM);
1144
1145 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001146
1147 nla_for_each_nested(key, keys, rem) {
1148 memset(&parse, 0, sizeof(parse));
1149 parse.idx = -1;
1150
Johannes Berg768075e2017-11-13 15:35:06 +01001151 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001152 if (err)
1153 goto error;
1154 err = -EINVAL;
1155 if (!parse.p.key)
1156 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001157 if (parse.idx < 0 || parse.idx > 3) {
1158 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001159 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001160 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001161 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001162 if (def) {
1163 GENL_SET_ERR_MSG(info,
1164 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001165 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001166 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001167 def = 1;
1168 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001169 if (!parse.def_uni || !parse.def_multi)
1170 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001171 } else if (parse.defmgmt)
1172 goto error;
1173 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001174 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001175 if (err)
1176 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001177 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1178 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001179 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001180 err = -EINVAL;
1181 goto error;
1182 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001183 result->params[parse.idx].cipher = parse.p.cipher;
1184 result->params[parse.idx].key_len = parse.p.key_len;
1185 result->params[parse.idx].key = result->data[parse.idx];
1186 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301187
Johannes Berg386b1f22016-09-13 16:10:02 +02001188 /* must be WEP key if we got here */
1189 if (no_ht)
1190 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001191 }
1192
Johannes Bergf1c1f172016-09-13 17:08:23 +02001193 if (result->def < 0) {
1194 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001195 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001196 goto error;
1197 }
1198
Johannes Bergfffd0932009-07-08 14:22:54 +02001199 return result;
1200 error:
1201 kfree(result);
1202 return ERR_PTR(err);
1203}
1204
1205static int nl80211_key_allowed(struct wireless_dev *wdev)
1206{
1207 ASSERT_WDEV_LOCK(wdev);
1208
Johannes Bergfffd0932009-07-08 14:22:54 +02001209 switch (wdev->iftype) {
1210 case NL80211_IFTYPE_AP:
1211 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001212 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001213 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001214 break;
1215 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001216 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001217 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001218 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001219 return -ENOLINK;
1220 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001221 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001222 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001223 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001224 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001225 case NL80211_IFTYPE_P2P_DEVICE:
1226 case NL80211_IFTYPE_WDS:
1227 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001228 return -EINVAL;
1229 }
1230
1231 return 0;
1232}
1233
Jouni Malinen664834d2014-01-15 00:01:44 +02001234static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1235 struct nlattr *tb)
1236{
1237 struct ieee80211_channel *chan;
1238
1239 if (tb == NULL)
1240 return NULL;
1241 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1242 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1243 return NULL;
1244 return chan;
1245}
1246
Johannes Berg7527a782011-05-13 10:58:57 +02001247static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1248{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001249 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001250 int i;
1251
1252 if (!nl_modes)
1253 goto nla_put_failure;
1254
1255 i = 0;
1256 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 if ((ifmodes & 1) && nla_put_flag(msg, i))
1258 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001259 ifmodes >>= 1;
1260 i++;
1261 }
1262
1263 nla_nest_end(msg, nl_modes);
1264 return 0;
1265
1266nla_put_failure:
1267 return -ENOBUFS;
1268}
1269
1270static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001271 struct sk_buff *msg,
1272 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001273{
1274 struct nlattr *nl_combis;
1275 int i, j;
1276
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001277 nl_combis = nla_nest_start_noflag(msg,
1278 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001279 if (!nl_combis)
1280 goto nla_put_failure;
1281
1282 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1283 const struct ieee80211_iface_combination *c;
1284 struct nlattr *nl_combi, *nl_limits;
1285
1286 c = &wiphy->iface_combinations[i];
1287
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001288 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001289 if (!nl_combi)
1290 goto nla_put_failure;
1291
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001292 nl_limits = nla_nest_start_noflag(msg,
1293 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001294 if (!nl_limits)
1295 goto nla_put_failure;
1296
1297 for (j = 0; j < c->n_limits; j++) {
1298 struct nlattr *nl_limit;
1299
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001300 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001301 if (!nl_limit)
1302 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1304 c->limits[j].max))
1305 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001306 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1307 c->limits[j].types))
1308 goto nla_put_failure;
1309 nla_nest_end(msg, nl_limit);
1310 }
1311
1312 nla_nest_end(msg, nl_limits);
1313
David S. Miller9360ffd2012-03-29 04:41:26 -04001314 if (c->beacon_int_infra_match &&
1315 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1316 goto nla_put_failure;
1317 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1318 c->num_different_channels) ||
1319 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1320 c->max_interfaces))
1321 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001322 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001323 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1324 c->radar_detect_widths) ||
1325 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1326 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001327 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301328 if (c->beacon_int_min_gcd &&
1329 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1330 c->beacon_int_min_gcd))
1331 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001332
1333 nla_nest_end(msg, nl_combi);
1334 }
1335
1336 nla_nest_end(msg, nl_combis);
1337
1338 return 0;
1339nla_put_failure:
1340 return -ENOBUFS;
1341}
1342
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001344static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1345 struct sk_buff *msg)
1346{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001347 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001348 struct nlattr *nl_tcp;
1349
1350 if (!tcp)
1351 return 0;
1352
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001353 nl_tcp = nla_nest_start_noflag(msg,
1354 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001355 if (!nl_tcp)
1356 return -ENOBUFS;
1357
1358 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1359 tcp->data_payload_max))
1360 return -ENOBUFS;
1361
1362 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1363 tcp->data_payload_max))
1364 return -ENOBUFS;
1365
1366 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1367 return -ENOBUFS;
1368
1369 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1370 sizeof(*tcp->tok), tcp->tok))
1371 return -ENOBUFS;
1372
1373 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1374 tcp->data_interval_max))
1375 return -ENOBUFS;
1376
1377 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1378 tcp->wake_payload_max))
1379 return -ENOBUFS;
1380
1381 nla_nest_end(msg, nl_tcp);
1382 return 0;
1383}
1384
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001386 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001387 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388{
1389 struct nlattr *nl_wowlan;
1390
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001391 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 return 0;
1393
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001394 nl_wowlan = nla_nest_start_noflag(msg,
1395 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001396 if (!nl_wowlan)
1397 return -ENOBUFS;
1398
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001399 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001401 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001402 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001403 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001405 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001407 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001409 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001411 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001412 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001413 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1415 return -ENOBUFS;
1416
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001417 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001418 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001419 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1420 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1421 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1422 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 };
1424
1425 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1426 sizeof(pat), &pat))
1427 return -ENOBUFS;
1428 }
1429
Luciano Coelho75453cc2015-01-09 14:06:37 +02001430 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1431 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1432 rdev->wiphy.wowlan->max_nd_match_sets))
1433 return -ENOBUFS;
1434
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001435 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001436 return -ENOBUFS;
1437
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 nla_nest_end(msg, nl_wowlan);
1439
1440 return 0;
1441}
1442#endif
1443
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001444static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001446{
1447 struct nl80211_coalesce_rule_support rule;
1448
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001449 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001450 return 0;
1451
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1453 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1454 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1455 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1456 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1457 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001458
1459 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1460 return -ENOBUFS;
1461
1462 return 0;
1463}
1464
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001465static int
1466nl80211_send_iftype_data(struct sk_buff *msg,
1467 const struct ieee80211_sband_iftype_data *iftdata)
1468{
1469 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1470
1471 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1472 iftdata->types_mask))
1473 return -ENOBUFS;
1474
1475 if (he_cap->has_he) {
1476 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1477 sizeof(he_cap->he_cap_elem.mac_cap_info),
1478 he_cap->he_cap_elem.mac_cap_info) ||
1479 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1480 sizeof(he_cap->he_cap_elem.phy_cap_info),
1481 he_cap->he_cap_elem.phy_cap_info) ||
1482 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1483 sizeof(he_cap->he_mcs_nss_supp),
1484 &he_cap->he_mcs_nss_supp) ||
1485 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1486 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1487 return -ENOBUFS;
1488 }
1489
1490 return 0;
1491}
1492
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1494 struct ieee80211_supported_band *sband)
1495{
1496 struct nlattr *nl_rates, *nl_rate;
1497 struct ieee80211_rate *rate;
1498 int i;
1499
1500 /* add HT info */
1501 if (sband->ht_cap.ht_supported &&
1502 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1503 sizeof(sband->ht_cap.mcs),
1504 &sband->ht_cap.mcs) ||
1505 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1506 sband->ht_cap.cap) ||
1507 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1508 sband->ht_cap.ampdu_factor) ||
1509 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1510 sband->ht_cap.ampdu_density)))
1511 return -ENOBUFS;
1512
1513 /* add VHT info */
1514 if (sband->vht_cap.vht_supported &&
1515 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1516 sizeof(sband->vht_cap.vht_mcs),
1517 &sband->vht_cap.vht_mcs) ||
1518 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1519 sband->vht_cap.cap)))
1520 return -ENOBUFS;
1521
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001522 if (sband->n_iftype_data) {
1523 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001524 nla_nest_start_noflag(msg,
1525 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001526 int err;
1527
1528 if (!nl_iftype_data)
1529 return -ENOBUFS;
1530
1531 for (i = 0; i < sband->n_iftype_data; i++) {
1532 struct nlattr *iftdata;
1533
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001534 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001535 if (!iftdata)
1536 return -ENOBUFS;
1537
1538 err = nl80211_send_iftype_data(msg,
1539 &sband->iftype_data[i]);
1540 if (err)
1541 return err;
1542
1543 nla_nest_end(msg, iftdata);
1544 }
1545
1546 nla_nest_end(msg, nl_iftype_data);
1547 }
1548
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001550 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 if (!nl_rates)
1552 return -ENOBUFS;
1553
1554 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001555 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 if (!nl_rate)
1557 return -ENOBUFS;
1558
1559 rate = &sband->bitrates[i];
1560 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1561 rate->bitrate))
1562 return -ENOBUFS;
1563 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1564 nla_put_flag(msg,
1565 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1566 return -ENOBUFS;
1567
1568 nla_nest_end(msg, nl_rate);
1569 }
1570
1571 nla_nest_end(msg, nl_rates);
1572
1573 return 0;
1574}
1575
1576static int
1577nl80211_send_mgmt_stypes(struct sk_buff *msg,
1578 const struct ieee80211_txrx_stypes *mgmt_stypes)
1579{
1580 u16 stypes;
1581 struct nlattr *nl_ftypes, *nl_ifs;
1582 enum nl80211_iftype ift;
1583 int i;
1584
1585 if (!mgmt_stypes)
1586 return 0;
1587
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001588 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 if (!nl_ifs)
1590 return -ENOBUFS;
1591
1592 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001593 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 if (!nl_ftypes)
1595 return -ENOBUFS;
1596 i = 0;
1597 stypes = mgmt_stypes[ift].tx;
1598 while (stypes) {
1599 if ((stypes & 1) &&
1600 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1601 (i << 4) | IEEE80211_FTYPE_MGMT))
1602 return -ENOBUFS;
1603 stypes >>= 1;
1604 i++;
1605 }
1606 nla_nest_end(msg, nl_ftypes);
1607 }
1608
1609 nla_nest_end(msg, nl_ifs);
1610
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001611 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 if (!nl_ifs)
1613 return -ENOBUFS;
1614
1615 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001616 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 if (!nl_ftypes)
1618 return -ENOBUFS;
1619 i = 0;
1620 stypes = mgmt_stypes[ift].rx;
1621 while (stypes) {
1622 if ((stypes & 1) &&
1623 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1624 (i << 4) | IEEE80211_FTYPE_MGMT))
1625 return -ENOBUFS;
1626 stypes >>= 1;
1627 i++;
1628 }
1629 nla_nest_end(msg, nl_ftypes);
1630 }
1631 nla_nest_end(msg, nl_ifs);
1632
1633 return 0;
1634}
1635
Johannes Berg17948992016-10-26 11:42:04 +02001636#define CMD(op, n) \
1637 do { \
1638 if (rdev->ops->op) { \
1639 i++; \
1640 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1641 goto nla_put_failure; \
1642 } \
1643 } while (0)
1644
1645static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1646 struct sk_buff *msg)
1647{
1648 int i = 0;
1649
1650 /*
1651 * do *NOT* add anything into this function, new things need to be
1652 * advertised only to new versions of userspace that can deal with
1653 * the split (and they can't possibly care about new features...
1654 */
1655 CMD(add_virtual_intf, NEW_INTERFACE);
1656 CMD(change_virtual_intf, SET_INTERFACE);
1657 CMD(add_key, NEW_KEY);
1658 CMD(start_ap, START_AP);
1659 CMD(add_station, NEW_STATION);
1660 CMD(add_mpath, NEW_MPATH);
1661 CMD(update_mesh_config, SET_MESH_CONFIG);
1662 CMD(change_bss, SET_BSS);
1663 CMD(auth, AUTHENTICATE);
1664 CMD(assoc, ASSOCIATE);
1665 CMD(deauth, DEAUTHENTICATE);
1666 CMD(disassoc, DISASSOCIATE);
1667 CMD(join_ibss, JOIN_IBSS);
1668 CMD(join_mesh, JOIN_MESH);
1669 CMD(set_pmksa, SET_PMKSA);
1670 CMD(del_pmksa, DEL_PMKSA);
1671 CMD(flush_pmksa, FLUSH_PMKSA);
1672 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1673 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1674 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1675 CMD(mgmt_tx, FRAME);
1676 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1677 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1678 i++;
1679 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1680 goto nla_put_failure;
1681 }
1682 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1683 rdev->ops->join_mesh) {
1684 i++;
1685 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1686 goto nla_put_failure;
1687 }
1688 CMD(set_wds_peer, SET_WDS_PEER);
1689 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1690 CMD(tdls_mgmt, TDLS_MGMT);
1691 CMD(tdls_oper, TDLS_OPER);
1692 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001693 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001694 CMD(sched_scan_start, START_SCHED_SCAN);
1695 CMD(probe_client, PROBE_CLIENT);
1696 CMD(set_noack_map, SET_NOACK_MAP);
1697 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1698 i++;
1699 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1700 goto nla_put_failure;
1701 }
1702 CMD(start_p2p_device, START_P2P_DEVICE);
1703 CMD(set_mcast_rate, SET_MCAST_RATE);
1704#ifdef CONFIG_NL80211_TESTMODE
1705 CMD(testmode_cmd, TESTMODE);
1706#endif
1707
1708 if (rdev->ops->connect || rdev->ops->auth) {
1709 i++;
1710 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1711 goto nla_put_failure;
1712 }
1713
1714 if (rdev->ops->disconnect || rdev->ops->deauth) {
1715 i++;
1716 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1717 goto nla_put_failure;
1718 }
1719
1720 return i;
1721 nla_put_failure:
1722 return -ENOBUFS;
1723}
1724
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001725static int
1726nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1727 struct sk_buff *msg)
1728{
1729 struct nlattr *ftm;
1730
1731 if (!cap->ftm.supported)
1732 return 0;
1733
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001734 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001735 if (!ftm)
1736 return -ENOBUFS;
1737
1738 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1739 return -ENOBUFS;
1740 if (cap->ftm.non_asap &&
1741 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1742 return -ENOBUFS;
1743 if (cap->ftm.request_lci &&
1744 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1745 return -ENOBUFS;
1746 if (cap->ftm.request_civicloc &&
1747 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1748 return -ENOBUFS;
1749 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1750 cap->ftm.preambles))
1751 return -ENOBUFS;
1752 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1753 cap->ftm.bandwidths))
1754 return -ENOBUFS;
1755 if (cap->ftm.max_bursts_exponent >= 0 &&
1756 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1757 cap->ftm.max_bursts_exponent))
1758 return -ENOBUFS;
1759 if (cap->ftm.max_ftms_per_burst &&
1760 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1761 cap->ftm.max_ftms_per_burst))
1762 return -ENOBUFS;
1763
1764 nla_nest_end(msg, ftm);
1765 return 0;
1766}
1767
1768static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1769 struct sk_buff *msg)
1770{
1771 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1772 struct nlattr *pmsr, *caps;
1773
1774 if (!cap)
1775 return 0;
1776
1777 /*
1778 * we don't need to clean up anything here since the caller
1779 * will genlmsg_cancel() if we fail
1780 */
1781
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001782 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001783 if (!pmsr)
1784 return -ENOBUFS;
1785
1786 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1787 return -ENOBUFS;
1788
1789 if (cap->report_ap_tsf &&
1790 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1791 return -ENOBUFS;
1792
1793 if (cap->randomize_mac_addr &&
1794 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1795 return -ENOBUFS;
1796
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001797 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001798 if (!caps)
1799 return -ENOBUFS;
1800
1801 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1802 return -ENOBUFS;
1803
1804 nla_nest_end(msg, caps);
1805 nla_nest_end(msg, pmsr);
1806
1807 return 0;
1808}
1809
Johannes Berg86e8cf92013-06-19 10:57:22 +02001810struct nl80211_dump_wiphy_state {
1811 s64 filter_wiphy;
1812 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301813 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 bool split;
1815};
1816
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001817static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001818 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001819 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001820 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001821{
1822 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001823 struct nlattr *nl_bands, *nl_band;
1824 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001825 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001826 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001827 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001828 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001829 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001830 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001831 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001832
Johannes Berg3bb20552014-05-26 13:52:25 +02001833 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001834 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001835 return -ENOBUFS;
1836
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 if (WARN_ON(!state))
1838 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001839
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001840 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001841 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001842 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001843 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001844 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001845 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001846
Johannes Berg3bb20552014-05-26 13:52:25 +02001847 if (cmd != NL80211_CMD_NEW_WIPHY)
1848 goto finish;
1849
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001851 case 0:
1852 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001853 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001854 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001855 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001856 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001857 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001858 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001859 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001860 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001861 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001862 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001864 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001865 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001866 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001867 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001868 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001869 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001870 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001871 rdev->wiphy.max_match_sets) ||
1872 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1873 rdev->wiphy.max_sched_scan_plans) ||
1874 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1875 rdev->wiphy.max_sched_scan_plan_interval) ||
1876 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1877 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001878 goto nla_put_failure;
1879
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001880 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001881 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1882 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001883 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001884 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1885 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001886 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1888 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001889 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1891 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001892 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001893 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1894 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001895 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001897 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001898 state->split_start++;
1899 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001900 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001901 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 case 1:
1903 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001904 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1905 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001906 goto nla_put_failure;
1907
Johannes Berg3713b4e2013-02-14 16:19:38 +01001908 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001909 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001910 goto nla_put_failure;
1911
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001912 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1914 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001915
Johannes Berg3713b4e2013-02-14 16:19:38 +01001916 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001917 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001918 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001919 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001920 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001921
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001922 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001923 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001924 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001925 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001926
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001927 if ((rdev->wiphy.available_antennas_tx ||
1928 rdev->wiphy.available_antennas_rx) &&
1929 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001930 u32 tx_ant = 0, rx_ant = 0;
1931 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001932
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001933 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001934 if (!res) {
1935 if (nla_put_u32(msg,
1936 NL80211_ATTR_WIPHY_ANTENNA_TX,
1937 tx_ant) ||
1938 nla_put_u32(msg,
1939 NL80211_ATTR_WIPHY_ANTENNA_RX,
1940 rx_ant))
1941 goto nla_put_failure;
1942 }
Johannes Bergee688b002008-01-24 19:38:39 +01001943 }
1944
Johannes Berg86e8cf92013-06-19 10:57:22 +02001945 state->split_start++;
1946 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001947 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001948 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001949 case 2:
1950 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001951 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001952 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001953 state->split_start++;
1954 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001955 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001956 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001957 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001958 nl_bands = nla_nest_start_noflag(msg,
1959 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001961 goto nla_put_failure;
1962
Johannes Berg86e8cf92013-06-19 10:57:22 +02001963 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001964 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001965 struct ieee80211_supported_band *sband;
1966
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001967 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001968
1969 if (!sband)
1970 continue;
1971
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001972 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001973 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001974 goto nla_put_failure;
1975
Johannes Berg86e8cf92013-06-19 10:57:22 +02001976 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001977 case 0:
1978 if (nl80211_send_band_rateinfo(msg, sband))
1979 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001980 state->chan_start++;
1981 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001982 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001983 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001984 default:
1985 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001986 nl_freqs = nla_nest_start_noflag(msg,
1987 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001988 if (!nl_freqs)
1989 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001990
Johannes Berg86e8cf92013-06-19 10:57:22 +02001991 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001992 i < sband->n_channels;
1993 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001994 nl_freq = nla_nest_start_noflag(msg,
1995 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001996 if (!nl_freq)
1997 goto nla_put_failure;
1998
1999 chan = &sband->channels[i];
2000
Johannes Berg86e8cf92013-06-19 10:57:22 +02002001 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002002 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002003 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002004 goto nla_put_failure;
2005
2006 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002007 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002008 break;
2009 }
2010 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002011 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002012 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002013 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002014 nla_nest_end(msg, nl_freqs);
2015 }
2016
2017 nla_nest_end(msg, nl_band);
2018
Johannes Berg86e8cf92013-06-19 10:57:22 +02002019 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002020 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002021 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002022 band--;
2023 break;
2024 }
Johannes Bergee688b002008-01-24 19:38:39 +01002025 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002026 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002027
Johannes Berg57fbcce2016-04-12 15:56:15 +02002028 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002029 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002030 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002031 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002032
Johannes Berg3713b4e2013-02-14 16:19:38 +01002033 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002034 if (state->band_start == 0 && state->chan_start == 0)
2035 state->split_start++;
2036 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002037 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002038 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002039 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002040 nl_cmds = nla_nest_start_noflag(msg,
2041 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002042 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002043 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002044
Johannes Berg17948992016-10-26 11:42:04 +02002045 i = nl80211_add_commands_unsplit(rdev, msg);
2046 if (i < 0)
2047 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002048 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002049 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2050 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002051 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002052 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002053 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002054 if (rdev->wiphy.features &
2055 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002056 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002057 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002058 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02002059 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002060#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002061
Johannes Berg3713b4e2013-02-14 16:19:38 +01002062 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002063 state->split_start++;
2064 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002065 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002066 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002067 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002068 if (rdev->ops->remain_on_channel &&
2069 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002070 nla_put_u32(msg,
2071 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002072 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002073 goto nla_put_failure;
2074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002075 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002076 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2077 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002078
Johannes Berg3713b4e2013-02-14 16:19:38 +01002079 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2080 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002081 state->split_start++;
2082 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002083 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002084 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002085 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002086#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002087 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002088 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002089 state->split_start++;
2090 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002091 break;
2092#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002093 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002094#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002095 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002096 case 7:
2097 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002098 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002099 goto nla_put_failure;
2100
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002101 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002102 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002103 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002104
Johannes Berg86e8cf92013-06-19 10:57:22 +02002105 state->split_start++;
2106 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002107 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002108 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002109 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002110 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002111 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002112 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002113 goto nla_put_failure;
2114
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002115 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002116 /*
2117 * We can only add the per-channel limit information if the
2118 * dump is split, otherwise it makes it too big. Therefore
2119 * only advertise it in that case.
2120 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002121 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002122 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2123 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002124 goto nla_put_failure;
2125
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002126 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002127 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002128 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2129 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002130 goto nla_put_failure;
2131
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002132 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2133 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002134 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002135 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002136 goto nla_put_failure;
2137
2138 /*
2139 * Any information below this point is only available to
2140 * applications that can deal with it being split. This
2141 * helps ensure that newly added capabilities don't break
2142 * older tools by overrunning their buffers.
2143 *
2144 * We still increment split_start so that in the split
2145 * case we'll continue with more data in the next round,
2146 * but break unconditionally so unsplit data stops here.
2147 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002148 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002149 break;
2150 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002151 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002152 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002153 rdev->wiphy.extended_capabilities_len,
2154 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002155 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002156 rdev->wiphy.extended_capabilities_len,
2157 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002158 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002159
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002160 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002161 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002162 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2163 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002164 goto nla_put_failure;
2165
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002166 state->split_start++;
2167 break;
2168 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002169 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002170 goto nla_put_failure;
2171
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002172 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002173 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2174 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2175 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002176
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002177 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002178 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002179 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002180 goto nla_put_failure;
2181
Johannes Bergad7e7182013-11-13 13:37:47 +01002182 state->split_start++;
2183 break;
2184 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002185 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002186 const struct nl80211_vendor_cmd_info *info;
2187 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002188
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002189 nested = nla_nest_start_noflag(msg,
2190 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002191 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002192 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002193
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002194 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2195 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002196 if (nla_put(msg, i + 1, sizeof(*info), info))
2197 goto nla_put_failure;
2198 }
2199 nla_nest_end(msg, nested);
2200 }
2201
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002202 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002203 const struct nl80211_vendor_cmd_info *info;
2204 struct nlattr *nested;
2205
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002206 nested = nla_nest_start_noflag(msg,
2207 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002208 if (!nested)
2209 goto nla_put_failure;
2210
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002211 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2212 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002213 if (nla_put(msg, i + 1, sizeof(*info), info))
2214 goto nla_put_failure;
2215 }
2216 nla_nest_end(msg, nested);
2217 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002218 state->split_start++;
2219 break;
2220 case 12:
2221 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2222 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2223 rdev->wiphy.max_num_csa_counters))
2224 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002225
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002226 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2227 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2228 goto nla_put_failure;
2229
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002230 if (rdev->wiphy.max_sched_scan_reqs &&
2231 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2232 rdev->wiphy.max_sched_scan_reqs))
2233 goto nla_put_failure;
2234
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002235 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2236 sizeof(rdev->wiphy.ext_features),
2237 rdev->wiphy.ext_features))
2238 goto nla_put_failure;
2239
Arend van Spriel38de03d2016-03-02 20:37:18 +01002240 if (rdev->wiphy.bss_select_support) {
2241 struct nlattr *nested;
2242 u32 bss_select_support = rdev->wiphy.bss_select_support;
2243
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002244 nested = nla_nest_start_noflag(msg,
2245 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002246 if (!nested)
2247 goto nla_put_failure;
2248
2249 i = 0;
2250 while (bss_select_support) {
2251 if ((bss_select_support & 1) &&
2252 nla_put_flag(msg, i))
2253 goto nla_put_failure;
2254 i++;
2255 bss_select_support >>= 1;
2256 }
2257 nla_nest_end(msg, nested);
2258 }
2259
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302260 state->split_start++;
2261 break;
2262 case 13:
2263 if (rdev->wiphy.num_iftype_ext_capab &&
2264 rdev->wiphy.iftype_ext_capab) {
2265 struct nlattr *nested_ext_capab, *nested;
2266
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002267 nested = nla_nest_start_noflag(msg,
2268 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302269 if (!nested)
2270 goto nla_put_failure;
2271
2272 for (i = state->capa_start;
2273 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2274 const struct wiphy_iftype_ext_capab *capab;
2275
2276 capab = &rdev->wiphy.iftype_ext_capab[i];
2277
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002278 nested_ext_capab = nla_nest_start_noflag(msg,
2279 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302280 if (!nested_ext_capab ||
2281 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2282 capab->iftype) ||
2283 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2284 capab->extended_capabilities_len,
2285 capab->extended_capabilities) ||
2286 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2287 capab->extended_capabilities_len,
2288 capab->extended_capabilities_mask))
2289 goto nla_put_failure;
2290
2291 nla_nest_end(msg, nested_ext_capab);
2292 if (state->split)
2293 break;
2294 }
2295 nla_nest_end(msg, nested);
2296 if (i < rdev->wiphy.num_iftype_ext_capab) {
2297 state->capa_start = i + 1;
2298 break;
2299 }
2300 }
2301
Luca Coelho85859892017-02-08 15:00:34 +02002302 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2303 rdev->wiphy.nan_supported_bands))
2304 goto nla_put_failure;
2305
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002306 if (wiphy_ext_feature_isset(&rdev->wiphy,
2307 NL80211_EXT_FEATURE_TXQS)) {
2308 struct cfg80211_txq_stats txqstats = {};
2309 int res;
2310
2311 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2312 if (!res &&
2313 !nl80211_put_txq_stats(msg, &txqstats,
2314 NL80211_ATTR_TXQ_STATS))
2315 goto nla_put_failure;
2316
2317 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2318 rdev->wiphy.txq_limit))
2319 goto nla_put_failure;
2320 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2321 rdev->wiphy.txq_memory_limit))
2322 goto nla_put_failure;
2323 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2324 rdev->wiphy.txq_quantum))
2325 goto nla_put_failure;
2326 }
2327
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002328 state->split_start++;
2329 break;
2330 case 14:
2331 if (nl80211_send_pmsr_capa(rdev, msg))
2332 goto nla_put_failure;
2333
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302334 state->split_start++;
2335 break;
2336 case 15:
2337 if (rdev->wiphy.akm_suites &&
2338 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2339 sizeof(u32) * rdev->wiphy.n_akm_suites,
2340 rdev->wiphy.akm_suites))
2341 goto nla_put_failure;
2342
Johannes Berg3713b4e2013-02-14 16:19:38 +01002343 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002344 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002345 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002346 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002347 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002348 genlmsg_end(msg, hdr);
2349 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002350
2351 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002352 genlmsg_cancel(msg, hdr);
2353 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002354}
2355
Johannes Berg86e8cf92013-06-19 10:57:22 +02002356static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2357 struct netlink_callback *cb,
2358 struct nl80211_dump_wiphy_state *state)
2359{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002360 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Berg8cb08172019-04-26 14:07:28 +02002361 int ret = nlmsg_parse_deprecated(cb->nlh,
2362 GENL_HDRLEN + nl80211_fam.hdrsize,
2363 tb, nl80211_fam.maxattr,
2364 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002365 /* ignore parse errors for backward compatibility */
2366 if (ret)
2367 return 0;
2368
2369 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2370 if (tb[NL80211_ATTR_WIPHY])
2371 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2372 if (tb[NL80211_ATTR_WDEV])
2373 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2374 if (tb[NL80211_ATTR_IFINDEX]) {
2375 struct net_device *netdev;
2376 struct cfg80211_registered_device *rdev;
2377 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2378
Ying Xue7f2b8562014-01-15 10:23:45 +08002379 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002380 if (!netdev)
2381 return -ENODEV;
2382 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002383 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002384 netdev->ieee80211_ptr->wiphy);
2385 state->filter_wiphy = rdev->wiphy_idx;
2386 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002387 }
2388
2389 return 0;
2390}
2391
Johannes Berg55682962007-09-20 13:09:35 -04002392static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2393{
Johannes Berg645e77d2013-03-01 14:03:49 +01002394 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002395 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002396 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002397
Johannes Berg5fe231e2013-05-08 21:45:15 +02002398 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002399 if (!state) {
2400 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002401 if (!state) {
2402 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002403 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002404 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002405 state->filter_wiphy = -1;
2406 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2407 if (ret) {
2408 kfree(state);
2409 rtnl_unlock();
2410 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002411 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002412 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002413 }
2414
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002415 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2416 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002417 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002418 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002419 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002420 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002421 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002422 continue;
2423 /* attempt to fit multiple wiphy data chunks into the skb */
2424 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002425 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2426 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002427 NETLINK_CB(cb->skb).portid,
2428 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002429 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002430 if (ret < 0) {
2431 /*
2432 * If sending the wiphy data didn't fit (ENOBUFS
2433 * or EMSGSIZE returned), this SKB is still
2434 * empty (so it's not too big because another
2435 * wiphy dataset is already in the skb) and
2436 * we've not tried to adjust the dump allocation
2437 * yet ... then adjust the alloc size to be
2438 * bigger, and return 1 but with the empty skb.
2439 * This results in an empty message being RX'ed
2440 * in userspace, but that is ignored.
2441 *
2442 * We can then retry with the larger buffer.
2443 */
2444 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002445 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002446 cb->min_dump_alloc < 4096) {
2447 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002448 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002449 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002450 return 1;
2451 }
2452 idx--;
2453 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002454 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002455 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002456 break;
Johannes Berg55682962007-09-20 13:09:35 -04002457 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002458 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002459
Johannes Berg86e8cf92013-06-19 10:57:22 +02002460 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002461
2462 return skb->len;
2463}
2464
Johannes Berg86e8cf92013-06-19 10:57:22 +02002465static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2466{
2467 kfree((void *)cb->args[0]);
2468 return 0;
2469}
2470
Johannes Berg55682962007-09-20 13:09:35 -04002471static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2472{
2473 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002475 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002476
Johannes Berg645e77d2013-03-01 14:03:49 +01002477 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002478 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002479 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002480
Johannes Berg3bb20552014-05-26 13:52:25 +02002481 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2482 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002483 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002484 nlmsg_free(msg);
2485 return -ENOBUFS;
2486 }
Johannes Berg55682962007-09-20 13:09:35 -04002487
Johannes Berg134e6372009-07-10 09:51:34 +00002488 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002489}
2490
Jouni Malinen31888482008-10-30 16:59:24 +02002491static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2492 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2493 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2494 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2495 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2496 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2497};
2498
2499static int parse_txq_params(struct nlattr *tb[],
2500 struct ieee80211_txq_params *txq_params)
2501{
Dan Williams259d8c12018-01-29 17:03:15 -08002502 u8 ac;
2503
Johannes Berga3304b02012-03-28 11:04:24 +02002504 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002505 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2506 !tb[NL80211_TXQ_ATTR_AIFS])
2507 return -EINVAL;
2508
Dan Williams259d8c12018-01-29 17:03:15 -08002509 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002510 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2511 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2512 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2513 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2514
Dan Williams259d8c12018-01-29 17:03:15 -08002515 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002516 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002517 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002518 return 0;
2519}
2520
Johannes Bergf444de02010-05-05 15:25:02 +02002521static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2522{
2523 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002524 * You can only set the channel explicitly for WDS interfaces,
2525 * all others have their channel managed via their respective
2526 * "establish a connection" command (connect, join, ...)
2527 *
2528 * For AP/GO and mesh mode, the channel can be set with the
2529 * channel userspace API, but is only stored and passed to the
2530 * low-level driver when the AP starts or the mesh is joined.
2531 * This is for backward compatibility, userspace can also give
2532 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002533 *
2534 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002535 * whatever else is going on, so they have their own special
2536 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002537 */
2538 return !wdev ||
2539 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002540 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002541 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2542 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002543}
2544
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002545int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2546 struct genl_info *info,
2547 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002548{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002549 struct netlink_ext_ack *extack = info->extack;
2550 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302551 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002552
Johannes Berg49f9cf02018-10-01 11:55:09 +02002553 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002554 return -EINVAL;
2555
Johannes Berg49f9cf02018-10-01 11:55:09 +02002556 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002557
2558 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002559 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2560 chandef->center_freq1 = control_freq;
2561 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002562
2563 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002564 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2565 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2566 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002567 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002568 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002569
Johannes Berg49f9cf02018-10-01 11:55:09 +02002570 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002571 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002572
Johannes Berg49f9cf02018-10-01 11:55:09 +02002573 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002574
2575 switch (chantype) {
2576 case NL80211_CHAN_NO_HT:
2577 case NL80211_CHAN_HT20:
2578 case NL80211_CHAN_HT40PLUS:
2579 case NL80211_CHAN_HT40MINUS:
2580 cfg80211_chandef_create(chandef, chandef->chan,
2581 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002582 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002583 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2584 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2585 NL_SET_ERR_MSG_ATTR(extack,
2586 attrs[NL80211_ATTR_CENTER_FREQ1],
2587 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002588 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002589 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002590 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002591 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2592 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2593 NL_SET_ERR_MSG_ATTR(extack,
2594 attrs[NL80211_ATTR_CENTER_FREQ2],
2595 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002596 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002597 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002598 break;
2599 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002600 NL_SET_ERR_MSG_ATTR(extack,
2601 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2602 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002603 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002604 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002605 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002606 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002607 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2608 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002609 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002610 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2611 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002612 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002613 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002614 }
2615
Johannes Berg49f9cf02018-10-01 11:55:09 +02002616 if (!cfg80211_chandef_valid(chandef)) {
2617 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002618 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002619 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002620
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002621 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002622 IEEE80211_CHAN_DISABLED)) {
2623 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002624 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002625 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002626
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002627 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2628 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002629 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2630 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002631 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002632 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002633
Johannes Berg683b6d32012-11-08 21:25:48 +01002634 return 0;
2635}
2636
Johannes Bergf444de02010-05-05 15:25:02 +02002637static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002638 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002639 struct genl_info *info)
2640{
Johannes Berg683b6d32012-11-08 21:25:48 +01002641 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002642 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002643 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002644 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002645
Jouni Malinene16821b2014-04-28 11:22:08 +03002646 if (dev)
2647 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002648 if (!nl80211_can_set_dev_channel(wdev))
2649 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002650 if (wdev)
2651 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002652
Johannes Berg683b6d32012-11-08 21:25:48 +01002653 result = nl80211_parse_chandef(rdev, info, &chandef);
2654 if (result)
2655 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002656
Johannes Berge8c9bd52012-06-06 08:18:22 +02002657 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002658 case NL80211_IFTYPE_AP:
2659 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002660 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2661 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002662 result = -EINVAL;
2663 break;
2664 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002665 if (wdev->beacon_interval) {
2666 if (!dev || !rdev->ops->set_ap_chanwidth ||
2667 !(rdev->wiphy.features &
2668 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2669 result = -EBUSY;
2670 break;
2671 }
2672
2673 /* Only allow dynamic channel width changes */
2674 if (chandef.chan != wdev->preset_chandef.chan) {
2675 result = -EBUSY;
2676 break;
2677 }
2678 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2679 if (result)
2680 break;
2681 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002682 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002683 result = 0;
2684 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002685 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002686 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002687 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002688 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002689 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002690 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002691 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002692 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002693 }
Johannes Bergf444de02010-05-05 15:25:02 +02002694
2695 return result;
2696}
2697
2698static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2699{
Johannes Berg4c476992010-10-04 21:36:35 +02002700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2701 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002702
Jouni Malinene16821b2014-04-28 11:22:08 +03002703 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002704}
2705
Bill Jordane8347eb2010-10-01 13:54:28 -04002706static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2707{
Johannes Berg43b19952010-10-07 13:10:30 +02002708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2709 struct net_device *dev = info->user_ptr[1];
2710 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002711 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002712
2713 if (!info->attrs[NL80211_ATTR_MAC])
2714 return -EINVAL;
2715
Johannes Berg43b19952010-10-07 13:10:30 +02002716 if (netif_running(dev))
2717 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002718
Johannes Berg43b19952010-10-07 13:10:30 +02002719 if (!rdev->ops->set_wds_peer)
2720 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002721
Johannes Berg43b19952010-10-07 13:10:30 +02002722 if (wdev->iftype != NL80211_IFTYPE_WDS)
2723 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002724
2725 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002726 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002727}
2728
Johannes Berg55682962007-09-20 13:09:35 -04002729static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2730{
2731 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002732 struct net_device *netdev = NULL;
2733 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002734 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002735 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002736 u32 changed;
2737 u8 retry_short = 0, retry_long = 0;
2738 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002739 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002740 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002741
Johannes Berg5fe231e2013-05-08 21:45:15 +02002742 ASSERT_RTNL();
2743
Johannes Bergf444de02010-05-05 15:25:02 +02002744 /*
2745 * Try to find the wiphy and netdev. Normally this
2746 * function shouldn't need the netdev, but this is
2747 * done for backward compatibility -- previously
2748 * setting the channel was done per wiphy, but now
2749 * it is per netdev. Previous userland like hostapd
2750 * also passed a netdev to set_wiphy, so that it is
2751 * possible to let that go to the right netdev!
2752 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002753
Johannes Bergf444de02010-05-05 15:25:02 +02002754 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2755 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2756
Ying Xue7f2b8562014-01-15 10:23:45 +08002757 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002758 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002759 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002760 else
Johannes Bergf444de02010-05-05 15:25:02 +02002761 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002762 }
2763
Johannes Bergf444de02010-05-05 15:25:02 +02002764 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002765 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2766 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002767 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002768 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002769 wdev = NULL;
2770 netdev = NULL;
2771 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002772 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002773 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002774
2775 /*
2776 * end workaround code, by now the rdev is available
2777 * and locked, and wdev may or may not be NULL.
2778 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002779
2780 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002781 result = cfg80211_dev_rename(
2782 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002783
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002784 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002785 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002786
Jouni Malinen31888482008-10-30 16:59:24 +02002787 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2788 struct ieee80211_txq_params txq_params;
2789 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2790
Ying Xue7f2b8562014-01-15 10:23:45 +08002791 if (!rdev->ops->set_txq_params)
2792 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002793
Ying Xue7f2b8562014-01-15 10:23:45 +08002794 if (!netdev)
2795 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002796
Johannes Berg133a3ff2011-11-03 14:50:13 +01002797 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002798 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2799 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002800
Ying Xue7f2b8562014-01-15 10:23:45 +08002801 if (!netif_running(netdev))
2802 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002803
Jouni Malinen31888482008-10-30 16:59:24 +02002804 nla_for_each_nested(nl_txq_params,
2805 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2806 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02002807 result = nla_parse_nested_deprecated(tb,
2808 NL80211_TXQ_ATTR_MAX,
2809 nl_txq_params,
2810 txq_params_policy,
2811 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002812 if (result)
2813 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002814 result = parse_txq_params(tb, &txq_params);
2815 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002816 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002817
Hila Gonene35e4d22012-06-27 17:19:42 +03002818 result = rdev_set_txq_params(rdev, netdev,
2819 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002820 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002821 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002822 }
2823 }
2824
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002825 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002826 result = __nl80211_set_channel(
2827 rdev,
2828 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2829 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002830 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002831 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002832 }
2833
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002834 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002835 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002836 enum nl80211_tx_power_setting type;
2837 int idx, mbm = 0;
2838
Johannes Bergc8442112012-10-24 10:17:18 +02002839 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2840 txp_wdev = NULL;
2841
Ying Xue7f2b8562014-01-15 10:23:45 +08002842 if (!rdev->ops->set_tx_power)
2843 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002844
2845 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2846 type = nla_get_u32(info->attrs[idx]);
2847
2848 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002849 (type != NL80211_TX_POWER_AUTOMATIC))
2850 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002851
2852 if (type != NL80211_TX_POWER_AUTOMATIC) {
2853 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2854 mbm = nla_get_u32(info->attrs[idx]);
2855 }
2856
Johannes Bergc8442112012-10-24 10:17:18 +02002857 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002858 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002859 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002860 }
2861
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002862 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2863 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2864 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002865
Bruno Randolf7f531e02010-12-16 11:30:22 +09002866 if ((!rdev->wiphy.available_antennas_tx &&
2867 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002868 !rdev->ops->set_antenna)
2869 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002870
2871 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2872 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2873
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002874 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002875 * available antenna masks, except for the "all" mask */
2876 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002877 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2878 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002879
Bruno Randolf7f531e02010-12-16 11:30:22 +09002880 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2881 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002882
Hila Gonene35e4d22012-06-27 17:19:42 +03002883 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002884 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002885 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002886 }
2887
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002888 changed = 0;
2889
2890 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2891 retry_short = nla_get_u8(
2892 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002893
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002894 changed |= WIPHY_PARAM_RETRY_SHORT;
2895 }
2896
2897 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2898 retry_long = nla_get_u8(
2899 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002900
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002901 changed |= WIPHY_PARAM_RETRY_LONG;
2902 }
2903
2904 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2905 frag_threshold = nla_get_u32(
2906 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002907 if (frag_threshold < 256)
2908 return -EINVAL;
2909
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002910 if (frag_threshold != (u32) -1) {
2911 /*
2912 * Fragments (apart from the last one) are required to
2913 * have even length. Make the fragmentation code
2914 * simpler by stripping LSB should someone try to use
2915 * odd threshold value.
2916 */
2917 frag_threshold &= ~0x1;
2918 }
2919 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2920 }
2921
2922 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2923 rts_threshold = nla_get_u32(
2924 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2925 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2926 }
2927
Lukáš Turek81077e82009-12-21 22:50:47 +01002928 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002929 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2930 return -EINVAL;
2931
Lukáš Turek81077e82009-12-21 22:50:47 +01002932 coverage_class = nla_get_u8(
2933 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2934 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2935 }
2936
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002937 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2938 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2939 return -EOPNOTSUPP;
2940
2941 changed |= WIPHY_PARAM_DYN_ACK;
2942 }
2943
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002944 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2945 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2946 NL80211_EXT_FEATURE_TXQS))
2947 return -EOPNOTSUPP;
2948 txq_limit = nla_get_u32(
2949 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2950 changed |= WIPHY_PARAM_TXQ_LIMIT;
2951 }
2952
2953 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2954 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2955 NL80211_EXT_FEATURE_TXQS))
2956 return -EOPNOTSUPP;
2957 txq_memory_limit = nla_get_u32(
2958 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2959 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2960 }
2961
2962 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2963 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2964 NL80211_EXT_FEATURE_TXQS))
2965 return -EOPNOTSUPP;
2966 txq_quantum = nla_get_u32(
2967 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2968 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2969 }
2970
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002971 if (changed) {
2972 u8 old_retry_short, old_retry_long;
2973 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002974 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002975 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002976
Ying Xue7f2b8562014-01-15 10:23:45 +08002977 if (!rdev->ops->set_wiphy_params)
2978 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002979
2980 old_retry_short = rdev->wiphy.retry_short;
2981 old_retry_long = rdev->wiphy.retry_long;
2982 old_frag_threshold = rdev->wiphy.frag_threshold;
2983 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002984 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002985 old_txq_limit = rdev->wiphy.txq_limit;
2986 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2987 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002988
2989 if (changed & WIPHY_PARAM_RETRY_SHORT)
2990 rdev->wiphy.retry_short = retry_short;
2991 if (changed & WIPHY_PARAM_RETRY_LONG)
2992 rdev->wiphy.retry_long = retry_long;
2993 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2994 rdev->wiphy.frag_threshold = frag_threshold;
2995 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2996 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002997 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2998 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002999 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3000 rdev->wiphy.txq_limit = txq_limit;
3001 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3002 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3003 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3004 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003005
Hila Gonene35e4d22012-06-27 17:19:42 +03003006 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003007 if (result) {
3008 rdev->wiphy.retry_short = old_retry_short;
3009 rdev->wiphy.retry_long = old_retry_long;
3010 rdev->wiphy.frag_threshold = old_frag_threshold;
3011 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003012 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003013 rdev->wiphy.txq_limit = old_txq_limit;
3014 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3015 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003016 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003017 }
3018 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003019 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003020}
3021
Johannes Berg683b6d32012-11-08 21:25:48 +01003022static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003023 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003024{
Johannes Berg601555c2014-11-27 17:26:56 +01003025 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3026 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003027
Johannes Berg683b6d32012-11-08 21:25:48 +01003028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3029 chandef->chan->center_freq))
3030 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003031 switch (chandef->width) {
3032 case NL80211_CHAN_WIDTH_20_NOHT:
3033 case NL80211_CHAN_WIDTH_20:
3034 case NL80211_CHAN_WIDTH_40:
3035 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3036 cfg80211_get_chandef_type(chandef)))
3037 return -ENOBUFS;
3038 break;
3039 default:
3040 break;
3041 }
3042 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3043 return -ENOBUFS;
3044 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3045 return -ENOBUFS;
3046 if (chandef->center_freq2 &&
3047 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003048 return -ENOBUFS;
3049 return 0;
3050}
3051
Eric W. Biederman15e47302012-09-07 20:12:54 +00003052static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003053 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003054 struct wireless_dev *wdev,
3055 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003056{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003057 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003058 void *hdr;
3059
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003060 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3061 cmd != NL80211_CMD_DEL_INTERFACE &&
3062 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003063
3064 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003065 if (!hdr)
3066 return -1;
3067
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003068 if (dev &&
3069 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003070 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003071 goto nla_put_failure;
3072
3073 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3074 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003075 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3076 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003077 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003078 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3079 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003080 (cfg80211_rdev_list_generation << 2)) ||
3081 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003082 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003083
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003084 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003085 int ret;
3086 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003087
Johannes Berg683b6d32012-11-08 21:25:48 +01003088 ret = rdev_get_channel(rdev, wdev, &chandef);
3089 if (ret == 0) {
3090 if (nl80211_send_chandef(msg, &chandef))
3091 goto nla_put_failure;
3092 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003093 }
3094
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003095 if (rdev->ops->get_tx_power) {
3096 int dbm, ret;
3097
3098 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3099 if (ret == 0 &&
3100 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3101 DBM_TO_MBM(dbm)))
3102 goto nla_put_failure;
3103 }
3104
Johannes Berg44905262017-10-17 21:56:01 +02003105 wdev_lock(wdev);
3106 switch (wdev->iftype) {
3107 case NL80211_IFTYPE_AP:
3108 if (wdev->ssid_len &&
3109 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003110 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003111 break;
3112 case NL80211_IFTYPE_STATION:
3113 case NL80211_IFTYPE_P2P_CLIENT:
3114 case NL80211_IFTYPE_ADHOC: {
3115 const u8 *ssid_ie;
3116 if (!wdev->current_bss)
3117 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003118 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003119 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3120 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003121 if (ssid_ie &&
3122 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3123 goto nla_put_failure_rcu_locked;
3124 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003125 break;
3126 }
3127 default:
3128 /* nothing */
3129 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003130 }
Johannes Berg44905262017-10-17 21:56:01 +02003131 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003132
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003133 if (rdev->ops->get_txq_stats) {
3134 struct cfg80211_txq_stats txqstats = {};
3135 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3136
3137 if (ret == 0 &&
3138 !nl80211_put_txq_stats(msg, &txqstats,
3139 NL80211_ATTR_TXQ_STATS))
3140 goto nla_put_failure;
3141 }
3142
Johannes Berg053c0952015-01-16 22:09:00 +01003143 genlmsg_end(msg, hdr);
3144 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003145
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003146 nla_put_failure_rcu_locked:
3147 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003148 nla_put_failure_locked:
3149 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003150 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003151 genlmsg_cancel(msg, hdr);
3152 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003153}
3154
3155static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3156{
3157 int wp_idx = 0;
3158 int if_idx = 0;
3159 int wp_start = cb->args[0];
3160 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003161 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003162 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003163 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003164 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003165
Johannes Berg5fe231e2013-05-08 21:45:15 +02003166 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003167 if (!cb->args[2]) {
3168 struct nl80211_dump_wiphy_state state = {
3169 .filter_wiphy = -1,
3170 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003171
3172 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3173 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003174 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003175
3176 filter_wiphy = state.filter_wiphy;
3177
3178 /*
3179 * if filtering, set cb->args[2] to +1 since 0 is the default
3180 * value needed to determine that parsing is necessary.
3181 */
3182 if (filter_wiphy >= 0)
3183 cb->args[2] = filter_wiphy + 1;
3184 else
3185 cb->args[2] = -1;
3186 } else if (cb->args[2] > 0) {
3187 filter_wiphy = cb->args[2] - 1;
3188 }
3189
Johannes Bergf5ea9122009-08-07 16:17:38 +02003190 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3191 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003192 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003193 if (wp_idx < wp_start) {
3194 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003195 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003196 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003197
3198 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3199 continue;
3200
Johannes Berg55682962007-09-20 13:09:35 -04003201 if_idx = 0;
3202
Johannes Berg53873f12016-05-03 16:52:04 +03003203 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003204 if (if_idx < if_start) {
3205 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003206 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003207 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003208 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003209 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003210 rdev, wdev,
3211 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003212 goto out;
3213 }
3214 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003215 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003216
3217 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003218 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003219 out:
Johannes Berg55682962007-09-20 13:09:35 -04003220 cb->args[0] = wp_idx;
3221 cb->args[1] = if_idx;
3222
Johannes Bergea90e0d2017-03-15 14:26:04 +01003223 ret = skb->len;
3224 out_unlock:
3225 rtnl_unlock();
3226
3227 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003228}
3229
3230static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3231{
3232 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003234 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003235
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003236 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003237 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003238 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003239
Eric W. Biederman15e47302012-09-07 20:12:54 +00003240 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003241 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003242 nlmsg_free(msg);
3243 return -ENOBUFS;
3244 }
Johannes Berg55682962007-09-20 13:09:35 -04003245
Johannes Berg134e6372009-07-10 09:51:34 +00003246 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003247}
3248
Michael Wu66f7ac52008-01-31 19:48:22 +01003249static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3250 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3251 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3252 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3253 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3254 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003255 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003256};
3257
3258static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3259{
3260 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3261 int flag;
3262
3263 *mntrflags = 0;
3264
3265 if (!nla)
3266 return -EINVAL;
3267
Johannes Berg8cb08172019-04-26 14:07:28 +02003268 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003269 return -EINVAL;
3270
3271 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3272 if (flags[flag])
3273 *mntrflags |= (1<<flag);
3274
Johannes Berg818a9862017-04-12 11:23:28 +02003275 *mntrflags |= MONITOR_FLAG_CHANGED;
3276
Michael Wu66f7ac52008-01-31 19:48:22 +01003277 return 0;
3278}
3279
Johannes Berg1db77592017-04-12 11:36:31 +02003280static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3281 enum nl80211_iftype type,
3282 struct genl_info *info,
3283 struct vif_params *params)
3284{
3285 bool change = false;
3286 int err;
3287
3288 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3289 if (type != NL80211_IFTYPE_MONITOR)
3290 return -EINVAL;
3291
3292 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3293 &params->flags);
3294 if (err)
3295 return err;
3296
3297 change = true;
3298 }
3299
3300 if (params->flags & MONITOR_FLAG_ACTIVE &&
3301 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3302 return -EOPNOTSUPP;
3303
3304 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3305 const u8 *mumimo_groups;
3306 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3307
3308 if (type != NL80211_IFTYPE_MONITOR)
3309 return -EINVAL;
3310
3311 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3312 return -EOPNOTSUPP;
3313
3314 mumimo_groups =
3315 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3316
3317 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003318 if ((mumimo_groups[0] & BIT(0)) ||
3319 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003320 return -EINVAL;
3321
3322 params->vht_mumimo_groups = mumimo_groups;
3323 change = true;
3324 }
3325
3326 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3327 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3328
3329 if (type != NL80211_IFTYPE_MONITOR)
3330 return -EINVAL;
3331
3332 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3333 return -EOPNOTSUPP;
3334
3335 params->vht_mumimo_follow_addr =
3336 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3337 change = true;
3338 }
3339
3340 return change ? 1 : 0;
3341}
3342
Johannes Berg9bc383d2009-11-19 11:55:19 +01003343static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003344 struct net_device *netdev, u8 use_4addr,
3345 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003346{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003347 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003348 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003349 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003350 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003351 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003352
3353 switch (iftype) {
3354 case NL80211_IFTYPE_AP_VLAN:
3355 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3356 return 0;
3357 break;
3358 case NL80211_IFTYPE_STATION:
3359 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3360 return 0;
3361 break;
3362 default:
3363 break;
3364 }
3365
3366 return -EOPNOTSUPP;
3367}
3368
Johannes Berg55682962007-09-20 13:09:35 -04003369static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3370{
Johannes Berg4c476992010-10-04 21:36:35 +02003371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003372 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003373 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003374 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003375 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003376 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003377
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003378 memset(&params, 0, sizeof(params));
3379
Johannes Berg04a773a2009-04-19 21:24:32 +02003380 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003381
Johannes Berg723b0382008-09-16 20:22:09 +02003382 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003383 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003384 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003385 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003386 }
3387
Johannes Berg92ffe052008-09-16 20:39:36 +02003388 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003389 struct wireless_dev *wdev = dev->ieee80211_ptr;
3390
Johannes Berg4c476992010-10-04 21:36:35 +02003391 if (ntype != NL80211_IFTYPE_MESH_POINT)
3392 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003393 if (netif_running(dev))
3394 return -EBUSY;
3395
3396 wdev_lock(wdev);
3397 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3398 IEEE80211_MAX_MESH_ID_LEN);
3399 wdev->mesh_id_up_len =
3400 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3401 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3402 wdev->mesh_id_up_len);
3403 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003404 }
3405
Felix Fietkau8b787642009-11-10 18:53:10 +01003406 if (info->attrs[NL80211_ATTR_4ADDR]) {
3407 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3408 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003409 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003410 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003411 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003412 } else {
3413 params.use_4addr = -1;
3414 }
3415
Johannes Berg1db77592017-04-12 11:36:31 +02003416 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3417 if (err < 0)
3418 return err;
3419 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003420 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003421
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003422 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003423 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003424 else
3425 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003426
Johannes Berg9bc383d2009-11-19 11:55:19 +01003427 if (!err && params.use_4addr != -1)
3428 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3429
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003430 if (change && !err) {
3431 struct wireless_dev *wdev = dev->ieee80211_ptr;
3432
3433 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3434 }
3435
Johannes Berg55682962007-09-20 13:09:35 -04003436 return err;
3437}
3438
3439static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3440{
Johannes Berg4c476992010-10-04 21:36:35 +02003441 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003442 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003443 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003444 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003445 int err;
3446 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3447
Johannes Berg78f22b62014-03-24 17:57:27 +01003448 /* to avoid failing a new interface creation due to pending removal */
3449 cfg80211_destroy_ifaces(rdev);
3450
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003451 memset(&params, 0, sizeof(params));
3452
Johannes Berg55682962007-09-20 13:09:35 -04003453 if (!info->attrs[NL80211_ATTR_IFNAME])
3454 return -EINVAL;
3455
Johannes Bergab0d76f2018-10-02 10:00:07 +02003456 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003457 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003458
Johannes Berg79c97e92009-07-07 03:56:12 +02003459 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003460 !(rdev->wiphy.interface_modes & (1 << type)))
3461 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003462
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003463 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003464 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3465 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003466 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3467 ETH_ALEN);
3468 if (!is_valid_ether_addr(params.macaddr))
3469 return -EADDRNOTAVAIL;
3470 }
3471
Johannes Berg9bc383d2009-11-19 11:55:19 +01003472 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003473 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003474 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003475 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003476 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003477 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003478
Johannes Berg1db77592017-04-12 11:36:31 +02003479 err = nl80211_parse_mon_options(rdev, type, info, &params);
3480 if (err < 0)
3481 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003482
Johannes Berga18c7192015-02-24 10:56:42 +01003483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3484 if (!msg)
3485 return -ENOMEM;
3486
Hila Gonene35e4d22012-06-27 17:19:42 +03003487 wdev = rdev_add_virtual_intf(rdev,
3488 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003489 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003490 if (WARN_ON(!wdev)) {
3491 nlmsg_free(msg);
3492 return -EPROTO;
3493 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003494 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003495 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003496 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003497
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003498 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003499 wdev->owner_nlportid = info->snd_portid;
3500
Johannes Berg98104fde2012-06-16 00:19:54 +02003501 switch (type) {
3502 case NL80211_IFTYPE_MESH_POINT:
3503 if (!info->attrs[NL80211_ATTR_MESH_ID])
3504 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003505 wdev_lock(wdev);
3506 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3507 IEEE80211_MAX_MESH_ID_LEN);
3508 wdev->mesh_id_up_len =
3509 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3510 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3511 wdev->mesh_id_up_len);
3512 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003513 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003514 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003515 case NL80211_IFTYPE_P2P_DEVICE:
3516 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003517 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003518 * through the netdev notifier and must be added here
3519 */
Johannes Berge4d42162018-09-13 14:12:03 +02003520 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003521 break;
3522 default:
3523 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003524 }
3525
Eric W. Biederman15e47302012-09-07 20:12:54 +00003526 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003527 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003528 nlmsg_free(msg);
3529 return -ENOBUFS;
3530 }
3531
3532 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003533}
3534
3535static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3536{
Johannes Berg4c476992010-10-04 21:36:35 +02003537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003538 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003539
Johannes Berg4c476992010-10-04 21:36:35 +02003540 if (!rdev->ops->del_virtual_intf)
3541 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003542
Johannes Berg84efbb82012-06-16 00:00:26 +02003543 /*
3544 * If we remove a wireless device without a netdev then clear
3545 * user_ptr[1] so that nl80211_post_doit won't dereference it
3546 * to check if it needs to do dev_put(). Otherwise it crashes
3547 * since the wdev has been freed, unlike with a netdev where
3548 * we need the dev_put() for the netdev to really be freed.
3549 */
3550 if (!wdev->netdev)
3551 info->user_ptr[1] = NULL;
3552
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003553 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003554}
3555
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003556static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3557{
3558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3559 struct net_device *dev = info->user_ptr[1];
3560 u16 noack_map;
3561
3562 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3563 return -EINVAL;
3564
3565 if (!rdev->ops->set_noack_map)
3566 return -EOPNOTSUPP;
3567
3568 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3569
Hila Gonene35e4d22012-06-27 17:19:42 +03003570 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003571}
3572
Johannes Berg41ade002007-12-19 02:03:29 +01003573struct get_key_cookie {
3574 struct sk_buff *msg;
3575 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003576 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003577};
3578
3579static void get_key_callback(void *c, struct key_params *params)
3580{
Johannes Bergb9454e82009-07-08 13:29:08 +02003581 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003582 struct get_key_cookie *cookie = c;
3583
David S. Miller9360ffd2012-03-29 04:41:26 -04003584 if ((params->key &&
3585 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3586 params->key_len, params->key)) ||
3587 (params->seq &&
3588 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3589 params->seq_len, params->seq)) ||
3590 (params->cipher &&
3591 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3592 params->cipher)))
3593 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003594
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003595 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003596 if (!key)
3597 goto nla_put_failure;
3598
David S. Miller9360ffd2012-03-29 04:41:26 -04003599 if ((params->key &&
3600 nla_put(cookie->msg, NL80211_KEY_DATA,
3601 params->key_len, params->key)) ||
3602 (params->seq &&
3603 nla_put(cookie->msg, NL80211_KEY_SEQ,
3604 params->seq_len, params->seq)) ||
3605 (params->cipher &&
3606 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3607 params->cipher)))
3608 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003609
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003610 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003611 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003612
3613 nla_nest_end(cookie->msg, key);
3614
Johannes Berg41ade002007-12-19 02:03:29 +01003615 return;
3616 nla_put_failure:
3617 cookie->error = 1;
3618}
3619
3620static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3621{
Johannes Berg4c476992010-10-04 21:36:35 +02003622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003623 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003624 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003625 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003626 const u8 *mac_addr = NULL;
3627 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003628 struct get_key_cookie cookie = {
3629 .error = 0,
3630 };
3631 void *hdr;
3632 struct sk_buff *msg;
3633
3634 if (info->attrs[NL80211_ATTR_KEY_IDX])
3635 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3636
Johannes Berg41ade002007-12-19 02:03:29 +01003637 if (info->attrs[NL80211_ATTR_MAC])
3638 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3639
Johannes Berge31b8212010-10-05 19:39:30 +02003640 pairwise = !!mac_addr;
3641 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3642 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003643
Johannes Berge31b8212010-10-05 19:39:30 +02003644 if (kt != NL80211_KEYTYPE_GROUP &&
3645 kt != NL80211_KEYTYPE_PAIRWISE)
3646 return -EINVAL;
3647 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3648 }
3649
Johannes Berg4c476992010-10-04 21:36:35 +02003650 if (!rdev->ops->get_key)
3651 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003652
Johannes Berg0fa7b392015-01-23 11:10:12 +01003653 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3654 return -ENOENT;
3655
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003657 if (!msg)
3658 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003659
Eric W. Biederman15e47302012-09-07 20:12:54 +00003660 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003661 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003662 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003663 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003664
3665 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003666 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003667
David S. Miller9360ffd2012-03-29 04:41:26 -04003668 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3669 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3670 goto nla_put_failure;
3671 if (mac_addr &&
3672 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3673 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003674
Hila Gonene35e4d22012-06-27 17:19:42 +03003675 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3676 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003677
3678 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003679 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003680
3681 if (cookie.error)
3682 goto nla_put_failure;
3683
3684 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003685 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003686
3687 nla_put_failure:
3688 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003689 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003690 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003691 return err;
3692}
3693
3694static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3695{
Johannes Berg4c476992010-10-04 21:36:35 +02003696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003697 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003698 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003699 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003700
Johannes Bergb9454e82009-07-08 13:29:08 +02003701 err = nl80211_parse_key(info, &key);
3702 if (err)
3703 return err;
3704
3705 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003706 return -EINVAL;
3707
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003708 /* Only support setting default key and
3709 * Extended Key ID action NL80211_KEY_SET_TX.
3710 */
3711 if (!key.def && !key.defmgmt &&
3712 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01003713 return -EINVAL;
3714
Johannes Bergfffd0932009-07-08 14:22:54 +02003715 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003716
3717 if (key.def) {
3718 if (!rdev->ops->set_default_key) {
3719 err = -EOPNOTSUPP;
3720 goto out;
3721 }
3722
3723 err = nl80211_key_allowed(dev->ieee80211_ptr);
3724 if (err)
3725 goto out;
3726
Hila Gonene35e4d22012-06-27 17:19:42 +03003727 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003728 key.def_uni, key.def_multi);
3729
3730 if (err)
3731 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003732
Johannes Berg3d23e342009-09-29 23:27:28 +02003733#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003734 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003735#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003736 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003737 if (key.def_uni || !key.def_multi) {
3738 err = -EINVAL;
3739 goto out;
3740 }
3741
3742 if (!rdev->ops->set_default_mgmt_key) {
3743 err = -EOPNOTSUPP;
3744 goto out;
3745 }
3746
3747 err = nl80211_key_allowed(dev->ieee80211_ptr);
3748 if (err)
3749 goto out;
3750
Hila Gonene35e4d22012-06-27 17:19:42 +03003751 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003752 if (err)
3753 goto out;
3754
3755#ifdef CONFIG_CFG80211_WEXT
3756 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3757#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003758 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3759 wiphy_ext_feature_isset(&rdev->wiphy,
3760 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3761 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003762
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003763 if (info->attrs[NL80211_ATTR_MAC])
3764 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3765
3766 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3767 err = -EINVAL;
3768 goto out;
3769 }
3770
3771 err = rdev_add_key(rdev, dev, key.idx,
3772 NL80211_KEYTYPE_PAIRWISE,
3773 mac_addr, &key.p);
3774 } else {
3775 err = -EINVAL;
3776 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003777 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003778 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003779
Johannes Berg41ade002007-12-19 02:03:29 +01003780 return err;
3781}
3782
3783static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3784{
Johannes Berg4c476992010-10-04 21:36:35 +02003785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003786 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003787 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003788 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003789 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003790
Johannes Bergb9454e82009-07-08 13:29:08 +02003791 err = nl80211_parse_key(info, &key);
3792 if (err)
3793 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003794
Johannes Bergb9454e82009-07-08 13:29:08 +02003795 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003796 return -EINVAL;
3797
Johannes Berg41ade002007-12-19 02:03:29 +01003798 if (info->attrs[NL80211_ATTR_MAC])
3799 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3800
Johannes Berge31b8212010-10-05 19:39:30 +02003801 if (key.type == -1) {
3802 if (mac_addr)
3803 key.type = NL80211_KEYTYPE_PAIRWISE;
3804 else
3805 key.type = NL80211_KEYTYPE_GROUP;
3806 }
3807
3808 /* for now */
3809 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3810 key.type != NL80211_KEYTYPE_GROUP)
3811 return -EINVAL;
3812
Johannes Berg4c476992010-10-04 21:36:35 +02003813 if (!rdev->ops->add_key)
3814 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003815
Johannes Berge31b8212010-10-05 19:39:30 +02003816 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3817 key.type == NL80211_KEYTYPE_PAIRWISE,
3818 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003819 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003820
3821 wdev_lock(dev->ieee80211_ptr);
3822 err = nl80211_key_allowed(dev->ieee80211_ptr);
3823 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003824 err = rdev_add_key(rdev, dev, key.idx,
3825 key.type == NL80211_KEYTYPE_PAIRWISE,
3826 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003827 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003828
Johannes Berg41ade002007-12-19 02:03:29 +01003829 return err;
3830}
3831
3832static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3833{
Johannes Berg4c476992010-10-04 21:36:35 +02003834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003835 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003836 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003837 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003838 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003839
Johannes Bergb9454e82009-07-08 13:29:08 +02003840 err = nl80211_parse_key(info, &key);
3841 if (err)
3842 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003843
3844 if (info->attrs[NL80211_ATTR_MAC])
3845 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3846
Johannes Berge31b8212010-10-05 19:39:30 +02003847 if (key.type == -1) {
3848 if (mac_addr)
3849 key.type = NL80211_KEYTYPE_PAIRWISE;
3850 else
3851 key.type = NL80211_KEYTYPE_GROUP;
3852 }
3853
3854 /* for now */
3855 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3856 key.type != NL80211_KEYTYPE_GROUP)
3857 return -EINVAL;
3858
Johannes Berg4c476992010-10-04 21:36:35 +02003859 if (!rdev->ops->del_key)
3860 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003861
Johannes Bergfffd0932009-07-08 14:22:54 +02003862 wdev_lock(dev->ieee80211_ptr);
3863 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003864
Johannes Berg0fa7b392015-01-23 11:10:12 +01003865 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003866 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3867 err = -ENOENT;
3868
Johannes Bergfffd0932009-07-08 14:22:54 +02003869 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003870 err = rdev_del_key(rdev, dev, key.idx,
3871 key.type == NL80211_KEYTYPE_PAIRWISE,
3872 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003873
Johannes Berg3d23e342009-09-29 23:27:28 +02003874#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003875 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003876 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003877 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003878 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003879 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3880 }
3881#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003882 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003883
Johannes Berg41ade002007-12-19 02:03:29 +01003884 return err;
3885}
3886
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303887/* This function returns an error or the number of nested attributes */
3888static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3889{
3890 struct nlattr *attr;
3891 int n_entries = 0, tmp;
3892
3893 nla_for_each_nested(attr, nl_attr, tmp) {
3894 if (nla_len(attr) != ETH_ALEN)
3895 return -EINVAL;
3896
3897 n_entries++;
3898 }
3899
3900 return n_entries;
3901}
3902
3903/*
3904 * This function parses ACL information and allocates memory for ACL data.
3905 * On successful return, the calling function is responsible to free the
3906 * ACL buffer returned by this function.
3907 */
3908static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3909 struct genl_info *info)
3910{
3911 enum nl80211_acl_policy acl_policy;
3912 struct nlattr *attr;
3913 struct cfg80211_acl_data *acl;
3914 int i = 0, n_entries, tmp;
3915
3916 if (!wiphy->max_acl_mac_addrs)
3917 return ERR_PTR(-EOPNOTSUPP);
3918
3919 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3920 return ERR_PTR(-EINVAL);
3921
3922 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3923 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3924 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3925 return ERR_PTR(-EINVAL);
3926
3927 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3928 return ERR_PTR(-EINVAL);
3929
3930 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3931 if (n_entries < 0)
3932 return ERR_PTR(n_entries);
3933
3934 if (n_entries > wiphy->max_acl_mac_addrs)
3935 return ERR_PTR(-ENOTSUPP);
3936
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05003937 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303938 if (!acl)
3939 return ERR_PTR(-ENOMEM);
3940
3941 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3942 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3943 i++;
3944 }
3945
3946 acl->n_acl_entries = n_entries;
3947 acl->acl_policy = acl_policy;
3948
3949 return acl;
3950}
3951
3952static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3953{
3954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3955 struct net_device *dev = info->user_ptr[1];
3956 struct cfg80211_acl_data *acl;
3957 int err;
3958
3959 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3961 return -EOPNOTSUPP;
3962
3963 if (!dev->ieee80211_ptr->beacon_interval)
3964 return -EINVAL;
3965
3966 acl = parse_acl_data(&rdev->wiphy, info);
3967 if (IS_ERR(acl))
3968 return PTR_ERR(acl);
3969
3970 err = rdev_set_mac_acl(rdev, dev, acl);
3971
3972 kfree(acl);
3973
3974 return err;
3975}
3976
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303977static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3978 u8 *rates, u8 rates_len)
3979{
3980 u8 i;
3981 u32 mask = 0;
3982
3983 for (i = 0; i < rates_len; i++) {
3984 int rate = (rates[i] & 0x7f) * 5;
3985 int ridx;
3986
3987 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3988 struct ieee80211_rate *srate =
3989 &sband->bitrates[ridx];
3990 if (rate == srate->bitrate) {
3991 mask |= 1 << ridx;
3992 break;
3993 }
3994 }
3995 if (ridx == sband->n_bitrates)
3996 return 0; /* rate not found */
3997 }
3998
3999 return mask;
4000}
4001
4002static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4003 u8 *rates, u8 rates_len,
4004 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4005{
4006 u8 i;
4007
4008 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4009
4010 for (i = 0; i < rates_len; i++) {
4011 int ridx, rbit;
4012
4013 ridx = rates[i] / 8;
4014 rbit = BIT(rates[i] % 8);
4015
4016 /* check validity */
4017 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4018 return false;
4019
4020 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004021 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304022 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4023 mcs[ridx] |= rbit;
4024 else
4025 return false;
4026 }
4027
4028 return true;
4029}
4030
4031static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4032{
4033 u16 mcs_mask = 0;
4034
4035 switch (vht_mcs_map) {
4036 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4037 break;
4038 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4039 mcs_mask = 0x00FF;
4040 break;
4041 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4042 mcs_mask = 0x01FF;
4043 break;
4044 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4045 mcs_mask = 0x03FF;
4046 break;
4047 default:
4048 break;
4049 }
4050
4051 return mcs_mask;
4052}
4053
4054static void vht_build_mcs_mask(u16 vht_mcs_map,
4055 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4056{
4057 u8 nss;
4058
4059 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4060 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4061 vht_mcs_map >>= 2;
4062 }
4063}
4064
4065static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4066 struct nl80211_txrate_vht *txrate,
4067 u16 mcs[NL80211_VHT_NSS_MAX])
4068{
4069 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4070 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4071 u8 i;
4072
4073 if (!sband->vht_cap.vht_supported)
4074 return false;
4075
4076 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4077
4078 /* Build vht_mcs_mask from VHT capabilities */
4079 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4080
4081 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4082 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4083 mcs[i] = txrate->mcs[i];
4084 else
4085 return false;
4086 }
4087
4088 return true;
4089}
4090
4091static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4092 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4093 .len = NL80211_MAX_SUPP_RATES },
4094 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4095 .len = NL80211_MAX_SUPP_HT_RATES },
Johannes Berg1a28ed22019-05-28 14:18:07 +02004096 [NL80211_TXRATE_VHT] = { .type = NLA_EXACT_LEN_WARN, .len = sizeof(struct nl80211_txrate_vht)},
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304097 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4098};
4099
4100static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4101 struct cfg80211_bitrate_mask *mask)
4102{
4103 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4105 int rem, i;
4106 struct nlattr *tx_rates;
4107 struct ieee80211_supported_band *sband;
4108 u16 vht_tx_mcs_map;
4109
4110 memset(mask, 0, sizeof(*mask));
4111 /* Default to all rates enabled */
4112 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4113 sband = rdev->wiphy.bands[i];
4114
4115 if (!sband)
4116 continue;
4117
4118 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4119 memcpy(mask->control[i].ht_mcs,
4120 sband->ht_cap.mcs.rx_mask,
4121 sizeof(mask->control[i].ht_mcs));
4122
4123 if (!sband->vht_cap.vht_supported)
4124 continue;
4125
4126 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4127 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4128 }
4129
4130 /* if no rates are given set it back to the defaults */
4131 if (!info->attrs[NL80211_ATTR_TX_RATES])
4132 goto out;
4133
4134 /* The nested attribute uses enum nl80211_band as the index. This maps
4135 * directly to the enum nl80211_band values used in cfg80211.
4136 */
4137 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4138 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4139 enum nl80211_band band = nla_type(tx_rates);
4140 int err;
4141
4142 if (band < 0 || band >= NUM_NL80211_BANDS)
4143 return -EINVAL;
4144 sband = rdev->wiphy.bands[band];
4145 if (sband == NULL)
4146 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004147 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4148 tx_rates,
4149 nl80211_txattr_policy,
4150 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304151 if (err)
4152 return err;
4153 if (tb[NL80211_TXRATE_LEGACY]) {
4154 mask->control[band].legacy = rateset_to_mask(
4155 sband,
4156 nla_data(tb[NL80211_TXRATE_LEGACY]),
4157 nla_len(tb[NL80211_TXRATE_LEGACY]));
4158 if ((mask->control[band].legacy == 0) &&
4159 nla_len(tb[NL80211_TXRATE_LEGACY]))
4160 return -EINVAL;
4161 }
4162 if (tb[NL80211_TXRATE_HT]) {
4163 if (!ht_rateset_to_mask(
4164 sband,
4165 nla_data(tb[NL80211_TXRATE_HT]),
4166 nla_len(tb[NL80211_TXRATE_HT]),
4167 mask->control[band].ht_mcs))
4168 return -EINVAL;
4169 }
4170 if (tb[NL80211_TXRATE_VHT]) {
4171 if (!vht_set_mcs_mask(
4172 sband,
4173 nla_data(tb[NL80211_TXRATE_VHT]),
4174 mask->control[band].vht_mcs))
4175 return -EINVAL;
4176 }
4177 if (tb[NL80211_TXRATE_GI]) {
4178 mask->control[band].gi =
4179 nla_get_u8(tb[NL80211_TXRATE_GI]);
4180 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4181 return -EINVAL;
4182 }
4183
4184 if (mask->control[band].legacy == 0) {
4185 /* don't allow empty legacy rates if HT or VHT
4186 * are not even supported.
4187 */
4188 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4189 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4190 return -EINVAL;
4191
4192 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4193 if (mask->control[band].ht_mcs[i])
4194 goto out;
4195
4196 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4197 if (mask->control[band].vht_mcs[i])
4198 goto out;
4199
4200 /* legacy and mcs rates may not be both empty */
4201 return -EINVAL;
4202 }
4203 }
4204
4205out:
4206 return 0;
4207}
4208
Johannes Berg8564e382016-09-19 09:44:44 +02004209static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4210 enum nl80211_band band,
4211 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304212{
Johannes Berg8564e382016-09-19 09:44:44 +02004213 u32 count_ht, count_vht, i;
4214 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304215
4216 /* Allow only one rate */
4217 if (hweight32(rate) > 1)
4218 return -EINVAL;
4219
4220 count_ht = 0;
4221 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004222 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304223 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004224 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304225 count_ht++;
4226 if (count_ht > 1)
4227 return -EINVAL;
4228 }
4229 if (count_ht && rate)
4230 return -EINVAL;
4231 }
4232
4233 count_vht = 0;
4234 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004235 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304236 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004237 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304238 count_vht++;
4239 if (count_vht > 1)
4240 return -EINVAL;
4241 }
4242 if (count_vht && rate)
4243 return -EINVAL;
4244 }
4245
4246 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4247 return -EINVAL;
4248
Johannes Berg8564e382016-09-19 09:44:44 +02004249 if (rate &&
4250 !wiphy_ext_feature_isset(&rdev->wiphy,
4251 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4252 return -EINVAL;
4253 if (count_ht &&
4254 !wiphy_ext_feature_isset(&rdev->wiphy,
4255 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4256 return -EINVAL;
4257 if (count_vht &&
4258 !wiphy_ext_feature_isset(&rdev->wiphy,
4259 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4260 return -EINVAL;
4261
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304262 return 0;
4263}
4264
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004265static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4266 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004267 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004268{
Johannes Berg88600202012-02-13 15:17:18 +01004269 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004270 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004271
Johannes Berg88600202012-02-13 15:17:18 +01004272 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004273
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004274 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4275 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4276 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004277 if (!bcn->head_len)
4278 return -EINVAL;
4279 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004280 }
4281
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004282 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4283 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4284 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004285 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004286 }
4287
Johannes Berg4c476992010-10-04 21:36:35 +02004288 if (!haveinfo)
4289 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004290
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004291 if (attrs[NL80211_ATTR_IE]) {
4292 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4293 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004294 }
4295
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004296 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004297 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004298 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004299 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004300 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004301 }
4302
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004303 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004304 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004305 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004306 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004307 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004308 }
4309
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004310 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4311 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4312 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004313 }
4314
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004315 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4316 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4317
Johannes Berg8cb08172019-04-26 14:07:28 +02004318 err = nla_parse_nested_deprecated(tb,
4319 NL80211_FTM_RESP_ATTR_MAX,
4320 attrs[NL80211_ATTR_FTM_RESPONDER],
4321 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004322 if (err)
4323 return err;
4324
4325 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4326 wiphy_ext_feature_isset(&rdev->wiphy,
4327 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4328 bcn->ftm_responder = 1;
4329 else
4330 return -EOPNOTSUPP;
4331
4332 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4333 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4334 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4335 }
4336
4337 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4338 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4339 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4340 }
4341 } else {
4342 bcn->ftm_responder = -1;
4343 }
4344
Johannes Berg88600202012-02-13 15:17:18 +01004345 return 0;
4346}
4347
Johannes Berg66cd7942017-02-07 22:40:44 +02004348static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4349 const u8 *rates)
4350{
4351 int i;
4352
4353 if (!rates)
4354 return;
4355
4356 for (i = 0; i < rates[1]; i++) {
4357 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4358 params->ht_required = true;
4359 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4360 params->vht_required = true;
4361 }
4362}
4363
4364/*
4365 * Since the nl80211 API didn't include, from the beginning, attributes about
4366 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4367 * benefit of drivers that rebuild IEs in the firmware.
4368 */
4369static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4370{
4371 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004372 size_t ies_len = bcn->tail_len;
4373 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004374 const u8 *rates;
4375 const u8 *cap;
4376
4377 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4378 nl80211_check_ap_rate_selectors(params, rates);
4379
4380 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4381 nl80211_check_ap_rate_selectors(params, rates);
4382
4383 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4384 if (cap && cap[1] >= sizeof(*params->ht_cap))
4385 params->ht_cap = (void *)(cap + 2);
4386 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4387 if (cap && cap[1] >= sizeof(*params->vht_cap))
4388 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004389 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4390 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4391 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004392}
4393
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004394static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4395 struct cfg80211_ap_settings *params)
4396{
4397 struct wireless_dev *wdev;
4398 bool ret = false;
4399
Johannes Berg53873f12016-05-03 16:52:04 +03004400 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004401 if (wdev->iftype != NL80211_IFTYPE_AP &&
4402 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4403 continue;
4404
Johannes Berg683b6d32012-11-08 21:25:48 +01004405 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004406 continue;
4407
Johannes Berg683b6d32012-11-08 21:25:48 +01004408 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004409 ret = true;
4410 break;
4411 }
4412
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004413 return ret;
4414}
4415
Jouni Malinene39e5b52012-09-30 19:29:39 +03004416static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4417 enum nl80211_auth_type auth_type,
4418 enum nl80211_commands cmd)
4419{
4420 if (auth_type > NL80211_AUTHTYPE_MAX)
4421 return false;
4422
4423 switch (cmd) {
4424 case NL80211_CMD_AUTHENTICATE:
4425 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4426 auth_type == NL80211_AUTHTYPE_SAE)
4427 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004428 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4429 NL80211_EXT_FEATURE_FILS_STA) &&
4430 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4431 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4432 auth_type == NL80211_AUTHTYPE_FILS_PK))
4433 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004434 return true;
4435 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004436 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4437 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004438 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004439
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004440 /* FILS with SK PFS or PK not supported yet */
4441 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4442 auth_type == NL80211_AUTHTYPE_FILS_PK)
4443 return false;
4444 if (!wiphy_ext_feature_isset(
4445 &rdev->wiphy,
4446 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4447 auth_type == NL80211_AUTHTYPE_FILS_SK)
4448 return false;
4449 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004450 case NL80211_CMD_START_AP:
4451 /* SAE not supported yet */
4452 if (auth_type == NL80211_AUTHTYPE_SAE)
4453 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004454 /* FILS not supported yet */
4455 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4456 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4457 auth_type == NL80211_AUTHTYPE_FILS_PK)
4458 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004459 return true;
4460 default:
4461 return false;
4462 }
4463}
4464
Johannes Berg88600202012-02-13 15:17:18 +01004465static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4466{
4467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4468 struct net_device *dev = info->user_ptr[1];
4469 struct wireless_dev *wdev = dev->ieee80211_ptr;
4470 struct cfg80211_ap_settings params;
4471 int err;
4472
4473 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4474 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4475 return -EOPNOTSUPP;
4476
4477 if (!rdev->ops->start_ap)
4478 return -EOPNOTSUPP;
4479
4480 if (wdev->beacon_interval)
4481 return -EALREADY;
4482
4483 memset(&params, 0, sizeof(params));
4484
4485 /* these are required for START_AP */
4486 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4487 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4488 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4489 return -EINVAL;
4490
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004491 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004492 if (err)
4493 return err;
4494
4495 params.beacon_interval =
4496 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4497 params.dtim_period =
4498 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4499
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304500 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4501 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004502 if (err)
4503 return err;
4504
4505 /*
4506 * In theory, some of these attributes should be required here
4507 * but since they were not used when the command was originally
4508 * added, keep them optional for old user space programs to let
4509 * them continue to work with drivers that do not need the
4510 * additional information -- drivers must check!
4511 */
4512 if (info->attrs[NL80211_ATTR_SSID]) {
4513 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4514 params.ssid_len =
4515 nla_len(info->attrs[NL80211_ATTR_SSID]);
4516 if (params.ssid_len == 0 ||
4517 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4518 return -EINVAL;
4519 }
4520
Johannes Bergab0d76f2018-10-02 10:00:07 +02004521 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004522 params.hidden_ssid = nla_get_u32(
4523 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004524
4525 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4526
4527 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4528 params.auth_type = nla_get_u32(
4529 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004530 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4531 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004532 return -EINVAL;
4533 } else
4534 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4535
4536 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4537 NL80211_MAX_NR_CIPHER_SUITES);
4538 if (err)
4539 return err;
4540
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304541 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4542 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4543 return -EOPNOTSUPP;
4544 params.inactivity_timeout = nla_get_u16(
4545 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4546 }
4547
Johannes Berg53cabad2012-11-14 15:17:28 +01004548 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4549 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4550 return -EINVAL;
4551 params.p2p_ctwindow =
4552 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004553 if (params.p2p_ctwindow != 0 &&
4554 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4555 return -EINVAL;
4556 }
4557
4558 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4559 u8 tmp;
4560
4561 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4562 return -EINVAL;
4563 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004564 params.p2p_opp_ps = tmp;
4565 if (params.p2p_opp_ps != 0 &&
4566 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4567 return -EINVAL;
4568 }
4569
Johannes Bergaa430da2012-05-16 23:50:18 +02004570 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004571 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4572 if (err)
4573 return err;
4574 } else if (wdev->preset_chandef.chan) {
4575 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004576 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004577 return -EINVAL;
4578
Arik Nemtsov923b3522015-07-08 15:41:44 +03004579 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4580 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004581 return -EINVAL;
4582
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304583 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4584 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4585 if (err)
4586 return err;
4587
Johannes Berg8564e382016-09-19 09:44:44 +02004588 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4589 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304590 if (err)
4591 return err;
4592 }
4593
Eliad Peller18998c32014-09-10 14:07:34 +03004594 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4595 params.smps_mode =
4596 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4597 switch (params.smps_mode) {
4598 case NL80211_SMPS_OFF:
4599 break;
4600 case NL80211_SMPS_STATIC:
4601 if (!(rdev->wiphy.features &
4602 NL80211_FEATURE_STATIC_SMPS))
4603 return -EINVAL;
4604 break;
4605 case NL80211_SMPS_DYNAMIC:
4606 if (!(rdev->wiphy.features &
4607 NL80211_FEATURE_DYNAMIC_SMPS))
4608 return -EINVAL;
4609 break;
4610 default:
4611 return -EINVAL;
4612 }
4613 } else {
4614 params.smps_mode = NL80211_SMPS_OFF;
4615 }
4616
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304617 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4618 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4619 return -EOPNOTSUPP;
4620
Ola Olsson4baf6be2015-10-29 07:04:58 +01004621 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4622 params.acl = parse_acl_data(&rdev->wiphy, info);
4623 if (IS_ERR(params.acl))
4624 return PTR_ERR(params.acl);
4625 }
4626
Johannes Berg66cd7942017-02-07 22:40:44 +02004627 nl80211_calculate_ap_params(&params);
4628
Srinivas Dasarife494372019-01-23 18:06:56 +05304629 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4630 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4631
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004632 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004633 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004634 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004635 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004636 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004637 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004638 wdev->ssid_len = params.ssid_len;
4639 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004640
4641 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4642 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004643 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004644 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304645
4646 kfree(params.acl);
4647
Johannes Berg56d18932011-05-09 18:41:15 +02004648 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004649}
4650
Johannes Berg88600202012-02-13 15:17:18 +01004651static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4652{
4653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4654 struct net_device *dev = info->user_ptr[1];
4655 struct wireless_dev *wdev = dev->ieee80211_ptr;
4656 struct cfg80211_beacon_data params;
4657 int err;
4658
4659 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4660 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4661 return -EOPNOTSUPP;
4662
4663 if (!rdev->ops->change_beacon)
4664 return -EOPNOTSUPP;
4665
4666 if (!wdev->beacon_interval)
4667 return -EINVAL;
4668
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004669 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004670 if (err)
4671 return err;
4672
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004673 wdev_lock(wdev);
4674 err = rdev_change_beacon(rdev, dev, &params);
4675 wdev_unlock(wdev);
4676
4677 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004678}
4679
4680static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004681{
Johannes Berg4c476992010-10-04 21:36:35 +02004682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4683 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004684
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004685 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004686}
4687
Johannes Berg5727ef12007-12-19 02:03:34 +01004688static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4689 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4690 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4691 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004692 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004693 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004694 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004695};
4696
Johannes Bergeccb8e82009-05-11 21:57:56 +03004697static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004698 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004699 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004700{
4701 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004702 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004703 int flag;
4704
Johannes Bergeccb8e82009-05-11 21:57:56 +03004705 /*
4706 * Try parsing the new attribute first so userspace
4707 * can specify both for older kernels.
4708 */
4709 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4710 if (nla) {
4711 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004712
Johannes Bergeccb8e82009-05-11 21:57:56 +03004713 sta_flags = nla_data(nla);
4714 params->sta_flags_mask = sta_flags->mask;
4715 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004716 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004717 if ((params->sta_flags_mask |
4718 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4719 return -EINVAL;
4720 return 0;
4721 }
4722
4723 /* if present, parse the old attribute */
4724
4725 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004726 if (!nla)
4727 return 0;
4728
Johannes Berg8cb08172019-04-26 14:07:28 +02004729 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004730 return -EINVAL;
4731
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004732 /*
4733 * Only allow certain flags for interface types so that
4734 * other attributes are silently ignored. Remember that
4735 * this is backward compatibility code with old userspace
4736 * and shouldn't be hit in other cases anyway.
4737 */
4738 switch (iftype) {
4739 case NL80211_IFTYPE_AP:
4740 case NL80211_IFTYPE_AP_VLAN:
4741 case NL80211_IFTYPE_P2P_GO:
4742 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4743 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4744 BIT(NL80211_STA_FLAG_WME) |
4745 BIT(NL80211_STA_FLAG_MFP);
4746 break;
4747 case NL80211_IFTYPE_P2P_CLIENT:
4748 case NL80211_IFTYPE_STATION:
4749 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4750 BIT(NL80211_STA_FLAG_TDLS_PEER);
4751 break;
4752 case NL80211_IFTYPE_MESH_POINT:
4753 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4754 BIT(NL80211_STA_FLAG_MFP) |
4755 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004756 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004757 default:
4758 return -EINVAL;
4759 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004760
Johannes Berg3383b5a2012-05-10 20:14:43 +02004761 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4762 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004763 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004764
Johannes Berg3383b5a2012-05-10 20:14:43 +02004765 /* no longer support new API additions in old API */
4766 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4767 return -EINVAL;
4768 }
4769 }
4770
Johannes Berg5727ef12007-12-19 02:03:34 +01004771 return 0;
4772}
4773
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004774bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004775{
4776 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004777 u32 bitrate;
4778 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004779 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004780
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004781 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004782 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004783 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004784
4785 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4786 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004787 /* report 16-bit bitrate only if we can */
4788 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004789 if (bitrate > 0 &&
4790 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4791 return false;
4792 if (bitrate_compat > 0 &&
4793 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4794 return false;
4795
Johannes Bergb51f3be2015-01-15 16:14:02 +01004796 switch (info->bw) {
4797 case RATE_INFO_BW_5:
4798 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4799 break;
4800 case RATE_INFO_BW_10:
4801 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4802 break;
4803 default:
4804 WARN_ON(1);
4805 /* fall through */
4806 case RATE_INFO_BW_20:
4807 rate_flg = 0;
4808 break;
4809 case RATE_INFO_BW_40:
4810 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4811 break;
4812 case RATE_INFO_BW_80:
4813 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4814 break;
4815 case RATE_INFO_BW_160:
4816 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4817 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004818 case RATE_INFO_BW_HE_RU:
4819 rate_flg = 0;
4820 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004821 }
4822
4823 if (rate_flg && nla_put_flag(msg, rate_flg))
4824 return false;
4825
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004826 if (info->flags & RATE_INFO_FLAGS_MCS) {
4827 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4828 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004829 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4830 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4831 return false;
4832 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4833 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4834 return false;
4835 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
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;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004840 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4841 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4842 return false;
4843 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4844 return false;
4845 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4846 return false;
4847 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4848 return false;
4849 if (info->bw == RATE_INFO_BW_HE_RU &&
4850 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4851 info->he_ru_alloc))
4852 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004853 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004854
4855 nla_nest_end(msg, rate);
4856 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004857}
4858
Felix Fietkau119363c2013-04-22 16:29:30 +02004859static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4860 int id)
4861{
4862 void *attr;
4863 int i = 0;
4864
4865 if (!mask)
4866 return true;
4867
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004868 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02004869 if (!attr)
4870 return false;
4871
4872 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4873 if (!(mask & BIT(i)))
4874 continue;
4875
4876 if (nla_put_u8(msg, i, signal[i]))
4877 return false;
4878 }
4879
4880 nla_nest_end(msg, attr);
4881
4882 return true;
4883}
4884
Johannes Bergcf5ead82014-11-14 17:14:00 +01004885static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4886 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004887 struct cfg80211_registered_device *rdev,
4888 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004889 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004890{
4891 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004892 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004893
Johannes Bergcf5ead82014-11-14 17:14:00 +01004894 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004895 if (!hdr)
4896 return -1;
4897
David S. Miller9360ffd2012-03-29 04:41:26 -04004898 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4899 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4900 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4901 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004902
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004903 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004905 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004906
4907#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004908 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03004909 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004910 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4911 sinfo->memb)) \
4912 goto nla_put_failure; \
4913 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004914#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03004915 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004916 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4917 sinfo->memb, NL80211_STA_INFO_PAD)) \
4918 goto nla_put_failure; \
4919 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004920
4921 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4922 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4923
Omer Efrat397c6572018-06-17 13:06:14 +03004924 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4925 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004926 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004927 (u32)sinfo->rx_bytes))
4928 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004929
Omer Efrat397c6572018-06-17 13:06:14 +03004930 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4931 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004932 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4933 (u32)sinfo->tx_bytes))
4934 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004935
Johannes Bergd686b922016-04-26 09:54:11 +02004936 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4937 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004938 PUT_SINFO(LLID, llid, u16);
4939 PUT_SINFO(PLID, plid, u16);
4940 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004941 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08004942 PUT_SINFO_U64(TX_DURATION, tx_duration);
4943
4944 if (wiphy_ext_feature_isset(&rdev->wiphy,
4945 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4946 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01004947
John W. Linville66266b32012-03-15 13:25:41 -04004948 switch (rdev->wiphy.signal_type) {
4949 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004950 PUT_SINFO(SIGNAL, signal, u8);
4951 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004952 break;
4953 default:
4954 break;
4955 }
Omer Efrat397c6572018-06-17 13:06:14 +03004956 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004957 if (!nl80211_put_signal(msg, sinfo->chains,
4958 sinfo->chain_signal,
4959 NL80211_STA_INFO_CHAIN_SIGNAL))
4960 goto nla_put_failure;
4961 }
Omer Efrat397c6572018-06-17 13:06:14 +03004962 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004963 if (!nl80211_put_signal(msg, sinfo->chains,
4964 sinfo->chain_signal_avg,
4965 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4966 goto nla_put_failure;
4967 }
Omer Efrat397c6572018-06-17 13:06:14 +03004968 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004969 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4970 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004971 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004972 }
Omer Efrat397c6572018-06-17 13:06:14 +03004973 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004974 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4975 NL80211_STA_INFO_RX_BITRATE))
4976 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004977 }
Johannes Berg319090b2014-11-17 14:08:11 +01004978
4979 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4980 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4981 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4982 PUT_SINFO(TX_FAILED, tx_failed, u32);
4983 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08004984 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01004985 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4986 PUT_SINFO(LOCAL_PM, local_pm, u32);
4987 PUT_SINFO(PEER_PM, peer_pm, u32);
4988 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04004989 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004990
Omer Efrat397c6572018-06-17 13:06:14 +03004991 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02004992 bss_param = nla_nest_start_noflag(msg,
4993 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07004994 if (!bss_param)
4995 goto nla_put_failure;
4996
David S. Miller9360ffd2012-03-29 04:41:26 -04004997 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4998 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4999 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5000 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5001 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5002 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5003 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5004 sinfo->bss_param.dtim_period) ||
5005 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5006 sinfo->bss_param.beacon_interval))
5007 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005008
5009 nla_nest_end(msg, bss_param);
5010 }
Omer Efrat397c6572018-06-17 13:06:14 +03005011 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005012 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5013 sizeof(struct nl80211_sta_flag_update),
5014 &sinfo->sta_flags))
5015 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005016
Johannes Bergd686b922016-04-26 09:54:11 +02005017 PUT_SINFO_U64(T_OFFSET, t_offset);
5018 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5019 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005020 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005021 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5022 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305023 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305024 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5025 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5026 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5027 }
Johannes Berg319090b2014-11-17 14:08:11 +01005028
5029#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005030#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005031
Arend van Spriel8689c052018-05-10 13:50:12 +02005032 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005033 struct nlattr *tidsattr;
5034 int tid;
5035
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005036 tidsattr = nla_nest_start_noflag(msg,
5037 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005038 if (!tidsattr)
5039 goto nla_put_failure;
5040
5041 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5042 struct cfg80211_tid_stats *tidstats;
5043 struct nlattr *tidattr;
5044
5045 tidstats = &sinfo->pertid[tid];
5046
5047 if (!tidstats->filled)
5048 continue;
5049
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005050 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005051 if (!tidattr)
5052 goto nla_put_failure;
5053
Johannes Bergd686b922016-04-26 09:54:11 +02005054#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005055 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005056 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5057 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005058 goto nla_put_failure; \
5059 } while (0)
5060
Johannes Bergd686b922016-04-26 09:54:11 +02005061 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5062 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5063 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5064 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005065
Johannes Bergd686b922016-04-26 09:54:11 +02005066#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005067 if ((tidstats->filled &
5068 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5069 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5070 NL80211_TID_STATS_TXQ_STATS))
5071 goto nla_put_failure;
5072
Johannes Berg6de39802014-12-19 12:34:00 +01005073 nla_nest_end(msg, tidattr);
5074 }
5075
5076 nla_nest_end(msg, tidsattr);
5077 }
5078
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005079 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005080
Johannes Berg319090b2014-11-17 14:08:11 +01005081 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005082 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5083 sinfo->assoc_req_ies))
5084 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005085
Johannes Berg7ea3e112018-05-18 11:40:44 +02005086 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005087 genlmsg_end(msg, hdr);
5088 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005089
5090 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005091 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005092 genlmsg_cancel(msg, hdr);
5093 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005094}
5095
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005096static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005097 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005098{
Johannes Berg73887fd2018-05-18 09:57:55 +02005099 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005100 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005101 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005102 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005103 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005104 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005105
Johannes Bergea90e0d2017-03-15 14:26:04 +01005106 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005107 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005108 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005109 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005110
Johannes Berg97990a02013-04-19 01:02:55 +02005111 if (!wdev->netdev) {
5112 err = -EINVAL;
5113 goto out_err;
5114 }
5115
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005116 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005117 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005118 goto out_err;
5119 }
5120
Johannes Bergbba95fe2008-07-29 13:22:51 +02005121 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005122 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005123 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005124 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005125 if (err == -ENOENT)
5126 break;
5127 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005128 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005129
Johannes Bergcf5ead82014-11-14 17:14:00 +01005130 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005131 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005132 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005133 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005134 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005135 goto out;
5136
5137 sta_idx++;
5138 }
5139
Johannes Bergbba95fe2008-07-29 13:22:51 +02005140 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005141 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005142 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005143 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005144 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005145
5146 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005147}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005148
Johannes Berg5727ef12007-12-19 02:03:34 +01005149static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5150{
Johannes Berg4c476992010-10-04 21:36:35 +02005151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5152 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005153 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005154 struct sk_buff *msg;
5155 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005156 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005157
Johannes Berg73887fd2018-05-18 09:57:55 +02005158 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005159
Johannes Berg73887fd2018-05-18 09:57:55 +02005160 if (!info->attrs[NL80211_ATTR_MAC])
5161 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005162
5163 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5164
Johannes Berg73887fd2018-05-18 09:57:55 +02005165 if (!rdev->ops->get_station)
5166 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005167
Johannes Berg73887fd2018-05-18 09:57:55 +02005168 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005169 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005170 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005171
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005173 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005174 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005175 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005176 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005177
Johannes Bergcf5ead82014-11-14 17:14:00 +01005178 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5179 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005180 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005181 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005182 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005183 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005184
Johannes Berg73887fd2018-05-18 09:57:55 +02005185 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005186}
5187
Johannes Berg77ee7c82013-02-15 00:48:33 +01005188int cfg80211_check_station_change(struct wiphy *wiphy,
5189 struct station_parameters *params,
5190 enum cfg80211_station_type statype)
5191{
Ayala Bekere4208422015-10-23 11:20:06 +03005192 if (params->listen_interval != -1 &&
5193 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005194 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005195
Ayala Beker17b94242016-03-17 15:41:38 +02005196 if (params->support_p2p_ps != -1 &&
5197 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5198 return -EINVAL;
5199
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005200 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005201 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5202 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005203 return -EINVAL;
5204
5205 /* When you run into this, adjust the code below for the new flag */
5206 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5207
5208 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005209 case CFG80211_STA_MESH_PEER_KERNEL:
5210 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005211 /*
5212 * No ignoring the TDLS flag here -- the userspace mesh
5213 * code doesn't have the bug of including TDLS in the
5214 * mask everywhere.
5215 */
5216 if (params->sta_flags_mask &
5217 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5218 BIT(NL80211_STA_FLAG_MFP) |
5219 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5220 return -EINVAL;
5221 break;
5222 case CFG80211_STA_TDLS_PEER_SETUP:
5223 case CFG80211_STA_TDLS_PEER_ACTIVE:
5224 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5225 return -EINVAL;
5226 /* ignore since it can't change */
5227 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5228 break;
5229 default:
5230 /* disallow mesh-specific things */
5231 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5232 return -EINVAL;
5233 if (params->local_pm)
5234 return -EINVAL;
5235 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5236 return -EINVAL;
5237 }
5238
5239 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5240 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5241 /* TDLS can't be set, ... */
5242 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5243 return -EINVAL;
5244 /*
5245 * ... but don't bother the driver with it. This works around
5246 * a hostapd/wpa_supplicant issue -- it always includes the
5247 * TLDS_PEER flag in the mask even for AP mode.
5248 */
5249 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5250 }
5251
Ayala Beker47edb112015-09-21 15:49:53 +03005252 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5253 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005254 /* reject other things that can't change */
5255 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5256 return -EINVAL;
5257 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5258 return -EINVAL;
5259 if (params->supported_rates)
5260 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005261 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5262 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005263 return -EINVAL;
5264 }
5265
Ayala Beker47edb112015-09-21 15:49:53 +03005266 if (statype != CFG80211_STA_AP_CLIENT &&
5267 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005268 if (params->vlan)
5269 return -EINVAL;
5270 }
5271
5272 switch (statype) {
5273 case CFG80211_STA_AP_MLME_CLIENT:
5274 /* Use this only for authorizing/unauthorizing a station */
5275 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5276 return -EOPNOTSUPP;
5277 break;
5278 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005279 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005280 /* accept only the listed bits */
5281 if (params->sta_flags_mask &
5282 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5283 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5284 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5285 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5286 BIT(NL80211_STA_FLAG_WME) |
5287 BIT(NL80211_STA_FLAG_MFP)))
5288 return -EINVAL;
5289
5290 /* but authenticated/associated only if driver handles it */
5291 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5292 params->sta_flags_mask &
5293 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5294 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5295 return -EINVAL;
5296 break;
5297 case CFG80211_STA_IBSS:
5298 case CFG80211_STA_AP_STA:
5299 /* reject any changes other than AUTHORIZED */
5300 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5301 return -EINVAL;
5302 break;
5303 case CFG80211_STA_TDLS_PEER_SETUP:
5304 /* reject any changes other than AUTHORIZED or WME */
5305 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5306 BIT(NL80211_STA_FLAG_WME)))
5307 return -EINVAL;
5308 /* force (at least) rates when authorizing */
5309 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5310 !params->supported_rates)
5311 return -EINVAL;
5312 break;
5313 case CFG80211_STA_TDLS_PEER_ACTIVE:
5314 /* reject any changes */
5315 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005316 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005317 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5318 return -EINVAL;
5319 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005320 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005321 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5322 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005323 return -EINVAL;
5324 break;
5325 }
5326
Beni Lev06f7c882016-07-19 19:28:56 +03005327 /*
5328 * Older kernel versions ignored this attribute entirely, so don't
5329 * reject attempts to update it but mark it as unused instead so the
5330 * driver won't look at the data.
5331 */
5332 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5333 statype != CFG80211_STA_TDLS_PEER_SETUP)
5334 params->opmode_notif_used = false;
5335
Johannes Berg77ee7c82013-02-15 00:48:33 +01005336 return 0;
5337}
5338EXPORT_SYMBOL(cfg80211_check_station_change);
5339
Johannes Berg5727ef12007-12-19 02:03:34 +01005340/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005341 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005342 */
Johannes Berg80b99892011-11-18 16:23:01 +01005343static struct net_device *get_vlan(struct genl_info *info,
5344 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005345{
Johannes Berg463d0182009-07-14 00:33:35 +02005346 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005347 struct net_device *v;
5348 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005349
Johannes Berg80b99892011-11-18 16:23:01 +01005350 if (!vlanattr)
5351 return NULL;
5352
5353 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5354 if (!v)
5355 return ERR_PTR(-ENODEV);
5356
5357 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5358 ret = -EINVAL;
5359 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005360 }
Johannes Berg80b99892011-11-18 16:23:01 +01005361
Johannes Berg77ee7c82013-02-15 00:48:33 +01005362 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5363 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5364 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5365 ret = -EINVAL;
5366 goto error;
5367 }
5368
Johannes Berg80b99892011-11-18 16:23:01 +01005369 if (!netif_running(v)) {
5370 ret = -ENETDOWN;
5371 goto error;
5372 }
5373
5374 return v;
5375 error:
5376 dev_put(v);
5377 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005378}
5379
Johannes Berg94e860f2014-01-20 23:58:15 +01005380static const struct nla_policy
5381nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005382 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5383 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5384};
5385
Johannes Bergff276692013-02-15 00:09:01 +01005386static int nl80211_parse_sta_wme(struct genl_info *info,
5387 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005388{
Jouni Malinendf881292013-02-14 21:10:54 +02005389 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5390 struct nlattr *nla;
5391 int err;
5392
Jouni Malinendf881292013-02-14 21:10:54 +02005393 /* parse WME attributes if present */
5394 if (!info->attrs[NL80211_ATTR_STA_WME])
5395 return 0;
5396
5397 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02005398 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5399 nl80211_sta_wme_policy,
5400 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005401 if (err)
5402 return err;
5403
5404 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5405 params->uapsd_queues = nla_get_u8(
5406 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5407 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5408 return -EINVAL;
5409
5410 if (tb[NL80211_STA_WME_MAX_SP])
5411 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5412
5413 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5414 return -EINVAL;
5415
5416 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5417
5418 return 0;
5419}
5420
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305421static int nl80211_parse_sta_channel_info(struct genl_info *info,
5422 struct station_parameters *params)
5423{
5424 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5425 params->supported_channels =
5426 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5427 params->supported_channels_len =
5428 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5429 /*
5430 * Need to include at least one (first channel, number of
5431 * channels) tuple for each subband, and must have proper
5432 * tuples for the rest of the data as well.
5433 */
5434 if (params->supported_channels_len < 2)
5435 return -EINVAL;
5436 if (params->supported_channels_len % 2)
5437 return -EINVAL;
5438 }
5439
5440 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5441 params->supported_oper_classes =
5442 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5443 params->supported_oper_classes_len =
5444 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5445 /*
5446 * The value of the Length field of the Supported Operating
5447 * Classes element is between 2 and 253.
5448 */
5449 if (params->supported_oper_classes_len < 2 ||
5450 params->supported_oper_classes_len > 253)
5451 return -EINVAL;
5452 }
5453 return 0;
5454}
5455
Johannes Bergff276692013-02-15 00:09:01 +01005456static int nl80211_set_station_tdls(struct genl_info *info,
5457 struct station_parameters *params)
5458{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305459 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005460 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005461 if (info->attrs[NL80211_ATTR_PEER_AID])
5462 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005463 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5464 params->ht_capa =
5465 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5466 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5467 params->vht_capa =
5468 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005469 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5470 params->he_capa =
5471 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5472 params->he_capa_len =
5473 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5474
5475 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5476 return -EINVAL;
5477 }
Johannes Bergff276692013-02-15 00:09:01 +01005478
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305479 err = nl80211_parse_sta_channel_info(info, params);
5480 if (err)
5481 return err;
5482
Johannes Bergff276692013-02-15 00:09:01 +01005483 return nl80211_parse_sta_wme(info, params);
5484}
5485
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305486static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5487 struct station_parameters *params)
5488{
5489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5490 int idx;
5491
5492 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5493 if (!rdev->ops->set_tx_power ||
5494 !wiphy_ext_feature_isset(&rdev->wiphy,
5495 NL80211_EXT_FEATURE_STA_TX_PWR))
5496 return -EOPNOTSUPP;
5497
5498 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5499 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5500
5501 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5502 idx = NL80211_ATTR_STA_TX_POWER;
5503
5504 if (info->attrs[idx])
5505 params->txpwr.power =
5506 nla_get_s16(info->attrs[idx]);
5507 else
5508 return -EINVAL;
5509 }
5510 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5511 }
5512
5513 return 0;
5514}
5515
Johannes Berg5727ef12007-12-19 02:03:34 +01005516static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5517{
Johannes Berg4c476992010-10-04 21:36:35 +02005518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005519 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005520 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005521 u8 *mac_addr;
5522 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005523
5524 memset(&params, 0, sizeof(params));
5525
Johannes Berg77ee7c82013-02-15 00:48:33 +01005526 if (!rdev->ops->change_station)
5527 return -EOPNOTSUPP;
5528
Ayala Bekere4208422015-10-23 11:20:06 +03005529 /*
5530 * AID and listen_interval properties can be set only for unassociated
5531 * station. Include these parameters here and will check them in
5532 * cfg80211_check_station_change().
5533 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005534 if (info->attrs[NL80211_ATTR_STA_AID])
5535 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005536
5537 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5538 params.listen_interval =
5539 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5540 else
5541 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005542
Johannes Bergab0d76f2018-10-02 10:00:07 +02005543 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5544 params.support_p2p_ps =
5545 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5546 else
Ayala Beker17b94242016-03-17 15:41:38 +02005547 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005548
Johannes Berg5727ef12007-12-19 02:03:34 +01005549 if (!info->attrs[NL80211_ATTR_MAC])
5550 return -EINVAL;
5551
5552 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5553
5554 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5555 params.supported_rates =
5556 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5557 params.supported_rates_len =
5558 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5559 }
5560
Jouni Malinen9d62a982013-02-14 21:10:13 +02005561 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5562 params.capability =
5563 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5564 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5565 }
5566
5567 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5568 params.ext_capab =
5569 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5570 params.ext_capab_len =
5571 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5572 }
5573
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005574 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005575 return -EINVAL;
5576
Johannes Bergab0d76f2018-10-02 10:00:07 +02005577 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005578 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005579 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005580
Johannes Bergf8bacc22013-02-14 23:27:01 +01005581 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005582 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005583 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005584 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005585 params.peer_aid = nla_get_u16(
5586 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005587 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5588 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005589
Johannes Bergab0d76f2018-10-02 10:00:07 +02005590 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5591 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005592 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5593
Beni Lev06f7c882016-07-19 19:28:56 +03005594 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5595 params.opmode_notif_used = true;
5596 params.opmode_notif =
5597 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5598 }
5599
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005600 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5601 params.airtime_weight =
5602 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5603
5604 if (params.airtime_weight &&
5605 !wiphy_ext_feature_isset(&rdev->wiphy,
5606 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5607 return -EOPNOTSUPP;
5608
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305609 err = nl80211_parse_sta_txpower_setting(info, &params);
5610 if (err)
5611 return err;
5612
Johannes Berg77ee7c82013-02-15 00:48:33 +01005613 /* Include parameters for TDLS peer (will check later) */
5614 err = nl80211_set_station_tdls(info, &params);
5615 if (err)
5616 return err;
5617
5618 params.vlan = get_vlan(info, rdev);
5619 if (IS_ERR(params.vlan))
5620 return PTR_ERR(params.vlan);
5621
Johannes Berga97f4422009-06-18 17:23:43 +02005622 switch (dev->ieee80211_ptr->iftype) {
5623 case NL80211_IFTYPE_AP:
5624 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005625 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005626 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005627 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005628 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005629 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005630 break;
5631 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005632 err = -EOPNOTSUPP;
5633 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005634 }
5635
Johannes Berg77ee7c82013-02-15 00:48:33 +01005636 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005637 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005638
Johannes Berg77ee7c82013-02-15 00:48:33 +01005639 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005640 if (params.vlan)
5641 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005642
Johannes Berg5727ef12007-12-19 02:03:34 +01005643 return err;
5644}
5645
5646static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5647{
Johannes Berg4c476992010-10-04 21:36:35 +02005648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005649 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005650 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005651 struct station_parameters params;
5652 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005653 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5654 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005655
5656 memset(&params, 0, sizeof(params));
5657
Johannes Berg984c3112013-02-14 23:43:25 +01005658 if (!rdev->ops->add_station)
5659 return -EOPNOTSUPP;
5660
Johannes Berg5727ef12007-12-19 02:03:34 +01005661 if (!info->attrs[NL80211_ATTR_MAC])
5662 return -EINVAL;
5663
Johannes Berg5727ef12007-12-19 02:03:34 +01005664 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5665 return -EINVAL;
5666
5667 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5668 return -EINVAL;
5669
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005670 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5671 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005672 return -EINVAL;
5673
Johannes Berg5727ef12007-12-19 02:03:34 +01005674 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5675 params.supported_rates =
5676 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5677 params.supported_rates_len =
5678 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5679 params.listen_interval =
5680 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005681
Ayala Beker17b94242016-03-17 15:41:38 +02005682 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005683 params.support_p2p_ps =
5684 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005685 } else {
5686 /*
5687 * if not specified, assume it's supported for P2P GO interface,
5688 * and is NOT supported for AP interface
5689 */
5690 params.support_p2p_ps =
5691 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5692 }
5693
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005694 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005695 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005696 else
5697 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005698
Jouni Malinen9d62a982013-02-14 21:10:13 +02005699 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5700 params.capability =
5701 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5702 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5703 }
5704
5705 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5706 params.ext_capab =
5707 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5708 params.ext_capab_len =
5709 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5710 }
5711
Jouni Malinen36aedc92008-08-25 11:58:58 +03005712 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5713 params.ht_capa =
5714 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005715
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005716 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5717 params.vht_capa =
5718 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5719
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005720 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5721 params.he_capa =
5722 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5723 params.he_capa_len =
5724 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5725
5726 /* max len is validated in nla policy */
5727 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5728 return -EINVAL;
5729 }
5730
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005731 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5732 params.opmode_notif_used = true;
5733 params.opmode_notif =
5734 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5735 }
5736
Johannes Bergab0d76f2018-10-02 10:00:07 +02005737 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005738 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005739 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005740
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005741 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5742 params.airtime_weight =
5743 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5744
5745 if (params.airtime_weight &&
5746 !wiphy_ext_feature_isset(&rdev->wiphy,
5747 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5748 return -EOPNOTSUPP;
5749
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305750 err = nl80211_parse_sta_txpower_setting(info, &params);
5751 if (err)
5752 return err;
5753
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305754 err = nl80211_parse_sta_channel_info(info, &params);
5755 if (err)
5756 return err;
5757
Johannes Bergff276692013-02-15 00:09:01 +01005758 err = nl80211_parse_sta_wme(info, &params);
5759 if (err)
5760 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005761
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005762 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005763 return -EINVAL;
5764
Johannes Berg496fcc22015-03-12 08:53:27 +02005765 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5766 * as userspace might just pass through the capabilities from the IEs
5767 * directly, rather than enforcing this restriction and returning an
5768 * error in this case.
5769 */
5770 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5771 params.ht_capa = NULL;
5772 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005773
5774 /* HE requires WME */
5775 if (params.he_capa_len)
5776 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005777 }
5778
Johannes Berg77ee7c82013-02-15 00:48:33 +01005779 /* When you run into this, adjust the code below for the new flag */
5780 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5781
Johannes Bergbdd90d52011-12-14 12:20:27 +01005782 switch (dev->ieee80211_ptr->iftype) {
5783 case NL80211_IFTYPE_AP:
5784 case NL80211_IFTYPE_AP_VLAN:
5785 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005786 /* ignore WME attributes if iface/sta is not capable */
5787 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5788 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5789 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005790
Johannes Bergbdd90d52011-12-14 12:20:27 +01005791 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005792 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5793 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005794 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005795 /* but don't bother the driver with it */
5796 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005797
Johannes Bergd582cff2012-10-26 17:53:44 +02005798 /* allow authenticated/associated only if driver handles it */
5799 if (!(rdev->wiphy.features &
5800 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005801 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005802 return -EINVAL;
5803
Johannes Bergbda95eb2015-11-26 16:26:13 +01005804 /* Older userspace, or userspace wanting to be compatible with
5805 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5806 * and assoc flags in the mask, but assumes the station will be
5807 * added as associated anyway since this was the required driver
5808 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5809 * introduced.
5810 * In order to not bother drivers with this quirk in the API
5811 * set the flags in both the mask and set for new stations in
5812 * this case.
5813 */
5814 if (!(params.sta_flags_mask & auth_assoc)) {
5815 params.sta_flags_mask |= auth_assoc;
5816 params.sta_flags_set |= auth_assoc;
5817 }
5818
Johannes Bergbdd90d52011-12-14 12:20:27 +01005819 /* must be last in here for error handling */
5820 params.vlan = get_vlan(info, rdev);
5821 if (IS_ERR(params.vlan))
5822 return PTR_ERR(params.vlan);
5823 break;
5824 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005825 /* ignore uAPSD data */
5826 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5827
Johannes Bergd582cff2012-10-26 17:53:44 +02005828 /* associated is disallowed */
5829 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5830 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005831 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005832 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5833 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005834 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005835 break;
5836 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005837 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005838 /* ignore uAPSD data */
5839 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5840
Johannes Berg77ee7c82013-02-15 00:48:33 +01005841 /* these are disallowed */
5842 if (params.sta_flags_mask &
5843 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5844 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005845 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005846 /* Only TDLS peers can be added */
5847 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5848 return -EINVAL;
5849 /* Can only add if TDLS ... */
5850 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5851 return -EOPNOTSUPP;
5852 /* ... with external setup is supported */
5853 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5854 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005855 /*
5856 * Older wpa_supplicant versions always mark the TDLS peer
5857 * as authorized, but it shouldn't yet be.
5858 */
5859 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005860 break;
5861 default:
5862 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005863 }
5864
Johannes Bergbdd90d52011-12-14 12:20:27 +01005865 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005866
Hila Gonene35e4d22012-06-27 17:19:42 +03005867 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005868
Johannes Berg5727ef12007-12-19 02:03:34 +01005869 if (params.vlan)
5870 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005871 return err;
5872}
5873
5874static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5875{
Johannes Berg4c476992010-10-04 21:36:35 +02005876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5877 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005878 struct station_del_parameters params;
5879
5880 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005881
5882 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005883 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005884
Johannes Berge80cf852009-05-11 14:43:13 +02005885 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005886 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005887 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5889 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005890
Johannes Berg4c476992010-10-04 21:36:35 +02005891 if (!rdev->ops->del_station)
5892 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005893
Jouni Malinen98856862014-10-20 13:20:45 +03005894 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5895 params.subtype =
5896 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5897 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5898 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5899 return -EINVAL;
5900 } else {
5901 /* Default to Deauthentication frame */
5902 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5903 }
5904
5905 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5906 params.reason_code =
5907 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5908 if (params.reason_code == 0)
5909 return -EINVAL; /* 0 is reserved */
5910 } else {
5911 /* Default to reason code 2 */
5912 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5913 }
5914
Jouni Malinen89c771e2014-10-10 20:52:40 +03005915 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005916}
5917
Eric W. Biederman15e47302012-09-07 20:12:54 +00005918static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005919 int flags, struct net_device *dev,
5920 u8 *dst, u8 *next_hop,
5921 struct mpath_info *pinfo)
5922{
5923 void *hdr;
5924 struct nlattr *pinfoattr;
5925
Henning Rogge1ef4c852014-11-04 16:14:58 +01005926 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005927 if (!hdr)
5928 return -1;
5929
David S. Miller9360ffd2012-03-29 04:41:26 -04005930 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5931 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5932 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5933 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5934 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005935
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005936 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005937 if (!pinfoattr)
5938 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005939 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5940 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5941 pinfo->frame_qlen))
5942 goto nla_put_failure;
5943 if (((pinfo->filled & MPATH_INFO_SN) &&
5944 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5945 ((pinfo->filled & MPATH_INFO_METRIC) &&
5946 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5947 pinfo->metric)) ||
5948 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5949 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5950 pinfo->exptime)) ||
5951 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5952 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5953 pinfo->flags)) ||
5954 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5955 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5956 pinfo->discovery_timeout)) ||
5957 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5958 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08005959 pinfo->discovery_retries)) ||
5960 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
5961 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08005962 pinfo->hop_count)) ||
5963 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
5964 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
5965 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005966 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005967
5968 nla_nest_end(msg, pinfoattr);
5969
Johannes Berg053c0952015-01-16 22:09:00 +01005970 genlmsg_end(msg, hdr);
5971 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005972
5973 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005974 genlmsg_cancel(msg, hdr);
5975 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005976}
5977
5978static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005979 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005980{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005981 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005982 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005983 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005984 u8 dst[ETH_ALEN];
5985 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005986 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005987 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005988
Johannes Bergea90e0d2017-03-15 14:26:04 +01005989 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005990 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005991 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005992 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005993
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005994 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005995 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005996 goto out_err;
5997 }
5998
Johannes Berg97990a02013-04-19 01:02:55 +02005999 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006000 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006001 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006002 }
6003
Johannes Bergbba95fe2008-07-29 13:22:51 +02006004 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006005 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006006 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006007 if (err == -ENOENT)
6008 break;
6009 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006010 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006011
Eric W. Biederman15e47302012-09-07 20:12:54 +00006012 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006013 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006014 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006015 &pinfo) < 0)
6016 goto out;
6017
6018 path_idx++;
6019 }
6020
Johannes Bergbba95fe2008-07-29 13:22:51 +02006021 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006022 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006023 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006024 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006025 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006026 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006027}
6028
6029static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6030{
Johannes Berg4c476992010-10-04 21:36:35 +02006031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006032 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006033 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006034 struct mpath_info pinfo;
6035 struct sk_buff *msg;
6036 u8 *dst = NULL;
6037 u8 next_hop[ETH_ALEN];
6038
6039 memset(&pinfo, 0, sizeof(pinfo));
6040
6041 if (!info->attrs[NL80211_ATTR_MAC])
6042 return -EINVAL;
6043
6044 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6045
Johannes Berg4c476992010-10-04 21:36:35 +02006046 if (!rdev->ops->get_mpath)
6047 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006048
Johannes Berg4c476992010-10-04 21:36:35 +02006049 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6050 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006051
Hila Gonene35e4d22012-06-27 17:19:42 +03006052 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006053 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006054 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006055
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006056 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006057 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006058 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006059
Eric W. Biederman15e47302012-09-07 20:12:54 +00006060 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006061 dev, dst, next_hop, &pinfo) < 0) {
6062 nlmsg_free(msg);
6063 return -ENOBUFS;
6064 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006065
Johannes Berg4c476992010-10-04 21:36:35 +02006066 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006067}
6068
6069static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6070{
Johannes Berg4c476992010-10-04 21:36:35 +02006071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6072 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006073 u8 *dst = NULL;
6074 u8 *next_hop = NULL;
6075
6076 if (!info->attrs[NL80211_ATTR_MAC])
6077 return -EINVAL;
6078
6079 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6080 return -EINVAL;
6081
6082 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6083 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6084
Johannes Berg4c476992010-10-04 21:36:35 +02006085 if (!rdev->ops->change_mpath)
6086 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006087
Johannes Berg4c476992010-10-04 21:36:35 +02006088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6089 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006090
Hila Gonene35e4d22012-06-27 17:19:42 +03006091 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006092}
Johannes Berg4c476992010-10-04 21:36:35 +02006093
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006094static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6095{
Johannes Berg4c476992010-10-04 21:36:35 +02006096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6097 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006098 u8 *dst = NULL;
6099 u8 *next_hop = NULL;
6100
6101 if (!info->attrs[NL80211_ATTR_MAC])
6102 return -EINVAL;
6103
6104 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6105 return -EINVAL;
6106
6107 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6108 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6109
Johannes Berg4c476992010-10-04 21:36:35 +02006110 if (!rdev->ops->add_mpath)
6111 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006112
Johannes Berg4c476992010-10-04 21:36:35 +02006113 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6114 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006115
Hila Gonene35e4d22012-06-27 17:19:42 +03006116 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006117}
6118
6119static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6120{
Johannes Berg4c476992010-10-04 21:36:35 +02006121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6122 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006123 u8 *dst = NULL;
6124
6125 if (info->attrs[NL80211_ATTR_MAC])
6126 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6127
Johannes Berg4c476992010-10-04 21:36:35 +02006128 if (!rdev->ops->del_mpath)
6129 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006130
Hila Gonene35e4d22012-06-27 17:19:42 +03006131 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006132}
6133
Henning Rogge66be7d22014-09-12 08:58:49 +02006134static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6135{
6136 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6137 int err;
6138 struct net_device *dev = info->user_ptr[1];
6139 struct mpath_info pinfo;
6140 struct sk_buff *msg;
6141 u8 *dst = NULL;
6142 u8 mpp[ETH_ALEN];
6143
6144 memset(&pinfo, 0, sizeof(pinfo));
6145
6146 if (!info->attrs[NL80211_ATTR_MAC])
6147 return -EINVAL;
6148
6149 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6150
6151 if (!rdev->ops->get_mpp)
6152 return -EOPNOTSUPP;
6153
6154 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6155 return -EOPNOTSUPP;
6156
6157 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6158 if (err)
6159 return err;
6160
6161 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6162 if (!msg)
6163 return -ENOMEM;
6164
6165 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6166 dev, dst, mpp, &pinfo) < 0) {
6167 nlmsg_free(msg);
6168 return -ENOBUFS;
6169 }
6170
6171 return genlmsg_reply(msg, info);
6172}
6173
6174static int nl80211_dump_mpp(struct sk_buff *skb,
6175 struct netlink_callback *cb)
6176{
6177 struct mpath_info pinfo;
6178 struct cfg80211_registered_device *rdev;
6179 struct wireless_dev *wdev;
6180 u8 dst[ETH_ALEN];
6181 u8 mpp[ETH_ALEN];
6182 int path_idx = cb->args[2];
6183 int err;
6184
Johannes Bergea90e0d2017-03-15 14:26:04 +01006185 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006186 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006187 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006188 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006189
6190 if (!rdev->ops->dump_mpp) {
6191 err = -EOPNOTSUPP;
6192 goto out_err;
6193 }
6194
6195 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6196 err = -EOPNOTSUPP;
6197 goto out_err;
6198 }
6199
6200 while (1) {
6201 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6202 mpp, &pinfo);
6203 if (err == -ENOENT)
6204 break;
6205 if (err)
6206 goto out_err;
6207
6208 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6209 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6210 wdev->netdev, dst, mpp,
6211 &pinfo) < 0)
6212 goto out;
6213
6214 path_idx++;
6215 }
6216
6217 out:
6218 cb->args[2] = path_idx;
6219 err = skb->len;
6220 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006221 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006222 return err;
6223}
6224
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006225static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6226{
Johannes Berg4c476992010-10-04 21:36:35 +02006227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6228 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006229 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006230 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006231 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006232
6233 memset(&params, 0, sizeof(params));
6234 /* default to not changing parameters */
6235 params.use_cts_prot = -1;
6236 params.use_short_preamble = -1;
6237 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006238 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006239 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006240 params.p2p_ctwindow = -1;
6241 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006242
6243 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6244 params.use_cts_prot =
6245 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6246 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6247 params.use_short_preamble =
6248 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6249 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6250 params.use_short_slot_time =
6251 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006252 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6253 params.basic_rates =
6254 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6255 params.basic_rates_len =
6256 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6257 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006258 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6259 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006260 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6261 params.ht_opmode =
6262 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006263
Johannes Berg53cabad2012-11-14 15:17:28 +01006264 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6265 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6266 return -EINVAL;
6267 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006268 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006269 if (params.p2p_ctwindow != 0 &&
6270 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6271 return -EINVAL;
6272 }
6273
6274 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6275 u8 tmp;
6276
6277 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6278 return -EINVAL;
6279 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006280 params.p2p_opp_ps = tmp;
6281 if (params.p2p_opp_ps &&
6282 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6283 return -EINVAL;
6284 }
6285
Johannes Berg4c476992010-10-04 21:36:35 +02006286 if (!rdev->ops->change_bss)
6287 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006288
Johannes Berg074ac8d2010-09-16 14:58:22 +02006289 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6291 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006292
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006293 wdev_lock(wdev);
6294 err = rdev_change_bss(rdev, dev, &params);
6295 wdev_unlock(wdev);
6296
6297 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006298}
6299
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006300static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6301{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006302 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006303 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006304 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006305 u32 owner_nlportid;
6306
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006307 /*
6308 * You should only get this when cfg80211 hasn't yet initialized
6309 * completely when built-in to the kernel right between the time
6310 * window between nl80211_init() and regulatory_init(), if that is
6311 * even possible.
6312 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006313 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006314 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006315
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006316 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6317 user_reg_hint_type =
6318 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6319 else
6320 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6321
6322 switch (user_reg_hint_type) {
6323 case NL80211_USER_REG_HINT_USER:
6324 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006325 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6326 return -EINVAL;
6327
6328 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6329 return regulatory_hint_user(data, user_reg_hint_type);
6330 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006331 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6332 owner_nlportid = info->snd_portid;
6333 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6334 } else {
6335 owner_nlportid = 0;
6336 is_indoor = true;
6337 }
6338
6339 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006340 default:
6341 return -EINVAL;
6342 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006343}
6344
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006345static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6346{
6347 return reg_reload_regdb();
6348}
6349
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006350static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006351 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006352{
Johannes Berg4c476992010-10-04 21:36:35 +02006353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006354 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006355 struct wireless_dev *wdev = dev->ieee80211_ptr;
6356 struct mesh_config cur_params;
6357 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006358 void *hdr;
6359 struct nlattr *pinfoattr;
6360 struct sk_buff *msg;
6361
Johannes Berg29cbe682010-12-03 09:20:44 +01006362 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6363 return -EOPNOTSUPP;
6364
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006365 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006366 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006367
Johannes Berg29cbe682010-12-03 09:20:44 +01006368 wdev_lock(wdev);
6369 /* If not connected, get default parameters */
6370 if (!wdev->mesh_id_len)
6371 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6372 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006373 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006374 wdev_unlock(wdev);
6375
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006376 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006377 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006378
6379 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006381 if (!msg)
6382 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006383 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006384 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006385 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006386 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006387 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006388 if (!pinfoattr)
6389 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006390 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6391 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6392 cur_params.dot11MeshRetryTimeout) ||
6393 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6394 cur_params.dot11MeshConfirmTimeout) ||
6395 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6396 cur_params.dot11MeshHoldingTimeout) ||
6397 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6398 cur_params.dot11MeshMaxPeerLinks) ||
6399 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6400 cur_params.dot11MeshMaxRetries) ||
6401 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6402 cur_params.dot11MeshTTL) ||
6403 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6404 cur_params.element_ttl) ||
6405 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6406 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006407 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6408 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006409 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6410 cur_params.dot11MeshHWMPmaxPREQretries) ||
6411 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6412 cur_params.path_refresh_time) ||
6413 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6414 cur_params.min_discovery_timeout) ||
6415 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6416 cur_params.dot11MeshHWMPactivePathTimeout) ||
6417 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6418 cur_params.dot11MeshHWMPpreqMinInterval) ||
6419 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6420 cur_params.dot11MeshHWMPperrMinInterval) ||
6421 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6422 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6423 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6424 cur_params.dot11MeshHWMPRootMode) ||
6425 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6426 cur_params.dot11MeshHWMPRannInterval) ||
6427 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6428 cur_params.dot11MeshGateAnnouncementProtocol) ||
6429 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6430 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006431 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006432 cur_params.rssi_threshold) ||
6433 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006434 cur_params.ht_opmode) ||
6435 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6436 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6437 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006438 cur_params.dot11MeshHWMProotInterval) ||
6439 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006440 cur_params.dot11MeshHWMPconfirmationInterval) ||
6441 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6442 cur_params.power_mode) ||
6443 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006444 cur_params.dot11MeshAwakeWindowDuration) ||
6445 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006446 cur_params.plink_timeout) ||
6447 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6448 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006449 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006450 nla_nest_end(msg, pinfoattr);
6451 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006452 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006453
Johannes Berg3b858752009-03-12 09:55:09 +01006454 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006455 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006456 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006457 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006458}
6459
Johannes Bergab0d76f2018-10-02 10:00:07 +02006460static const struct nla_policy
6461nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6462 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6463 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6464 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6465 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6466 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6467 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6468 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6469 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6470 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6471 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6472 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6473 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6474 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6475 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006476 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6477 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006478 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006479 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006480 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6481 NLA_POLICY_MIN(NLA_U16, 1),
6482 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6483 NLA_POLICY_MIN(NLA_U16, 1),
6484 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6485 NLA_POLICY_MIN(NLA_U16, 1),
6486 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6487 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6488 NLA_POLICY_MIN(NLA_U16, 1),
6489 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6490 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6491 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6492 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006493 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006494 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006495 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6496 NLA_POLICY_MIN(NLA_U16, 1),
6497 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6498 NLA_POLICY_MIN(NLA_U16, 1),
6499 [NL80211_MESHCONF_POWER_MODE] =
6500 NLA_POLICY_RANGE(NLA_U32,
6501 NL80211_MESH_POWER_ACTIVE,
6502 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006503 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006504 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006505 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006506};
6507
Javier Cardonac80d5452010-12-16 17:37:49 -08006508static const struct nla_policy
6509 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006510 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006511 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6512 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006513 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006514 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006515 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006516 [NL80211_MESH_SETUP_IE] =
6517 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6518 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006519 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006520};
6521
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006522static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006523 struct mesh_config *cfg,
6524 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006525{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006526 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006527 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006528 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006529
Johannes Bergab0d76f2018-10-02 10:00:07 +02006530#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6531do { \
6532 if (tb[attr]) { \
6533 cfg->param = fn(tb[attr]); \
6534 mask |= BIT((attr) - 1); \
6535 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006536} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006537
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006538 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006539 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006540 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 -07006541 return -EINVAL;
6542
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006543 /* This makes sure that there aren't more than 32 mesh config
6544 * parameters (otherwise our bitfield scheme would not work.) */
6545 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6546
6547 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006548 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6549 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6550 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6551 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6552 nla_get_u16);
6553 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6554 NL80211_MESHCONF_HOLDING_TIMEOUT,
6555 nla_get_u16);
6556 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6557 NL80211_MESHCONF_MAX_PEER_LINKS,
6558 nla_get_u16);
6559 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6560 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6561 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6562 NL80211_MESHCONF_TTL, nla_get_u8);
6563 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6564 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6565 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6566 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6567 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006568 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006569 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006570 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006571 nla_get_u32);
6572 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6573 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6574 nla_get_u8);
6575 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6576 NL80211_MESHCONF_PATH_REFRESH_TIME,
6577 nla_get_u32);
6578 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6579 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6580 return -EINVAL;
6581 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6582 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6583 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006584 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006585 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006586 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006587 nla_get_u32);
6588 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6589 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6590 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6591 return -EINVAL;
6592 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006593 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006594 nla_get_u16);
6595 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006596 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006597 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006598 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006599 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006600 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006601 nla_get_u16);
6602 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6603 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6604 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6605 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6606 nla_get_u16);
6607 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006608 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006609 nla_get_u8);
6610 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6611 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6612 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6613 NL80211_MESHCONF_RSSI_THRESHOLD,
6614 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006615 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6616 NL80211_MESHCONF_CONNECTED_TO_GATE,
6617 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006618 /*
6619 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006620 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006621 */
6622 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6623 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6624
6625 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6626 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6627 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6628 return -EINVAL;
6629
Bob Copeland188f60a2018-06-24 21:10:49 -04006630 /* NON_HT_STA bit is reserved, but some programs set it */
6631 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006632
Masashi Honma97572352016-08-03 10:07:44 +09006633 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006634 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006635 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006636 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006637 dot11MeshHWMPactivePathToRootTimeout, mask,
6638 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6639 nla_get_u32);
6640 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6641 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6642 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6643 return -EINVAL;
6644 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6645 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6646 nla_get_u16);
6647 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6648 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006649 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006650 nla_get_u16);
6651 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6652 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6653 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6654 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6656 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006657 if (mask_out)
6658 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006659
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006660 return 0;
6661
6662#undef FILL_IN_MESH_PARAM_IF_SET
6663}
6664
Javier Cardonac80d5452010-12-16 17:37:49 -08006665static int nl80211_parse_mesh_setup(struct genl_info *info,
6666 struct mesh_setup *setup)
6667{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006669 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6670
6671 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6672 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006673 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 -08006674 return -EINVAL;
6675
Javier Cardonad299a1f2012-03-31 11:31:33 -07006676 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6677 setup->sync_method =
6678 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6679 IEEE80211_SYNC_METHOD_VENDOR :
6680 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6681
Javier Cardonac80d5452010-12-16 17:37:49 -08006682 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6683 setup->path_sel_proto =
6684 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6685 IEEE80211_PATH_PROTOCOL_VENDOR :
6686 IEEE80211_PATH_PROTOCOL_HWMP;
6687
6688 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6689 setup->path_metric =
6690 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6691 IEEE80211_PATH_METRIC_VENDOR :
6692 IEEE80211_PATH_METRIC_AIRTIME;
6693
Javier Cardona581a8b02011-04-07 15:08:27 -07006694 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006695 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006696 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006697 setup->ie = nla_data(ieattr);
6698 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006699 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006700 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6701 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6702 return -EINVAL;
6703 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006704 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6705 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006706 if (setup->is_secure)
6707 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006708
Colleen Twitty6e16d902013-05-08 11:45:59 -07006709 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6710 if (!setup->user_mpm)
6711 return -EINVAL;
6712 setup->auth_id =
6713 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6714 }
6715
Javier Cardonac80d5452010-12-16 17:37:49 -08006716 return 0;
6717}
6718
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006719static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006720 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006721{
6722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6723 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006724 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006725 struct mesh_config cfg;
6726 u32 mask;
6727 int err;
6728
Johannes Berg29cbe682010-12-03 09:20:44 +01006729 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6730 return -EOPNOTSUPP;
6731
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006732 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006733 return -EOPNOTSUPP;
6734
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006735 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006736 if (err)
6737 return err;
6738
Johannes Berg29cbe682010-12-03 09:20:44 +01006739 wdev_lock(wdev);
6740 if (!wdev->mesh_id_len)
6741 err = -ENOLINK;
6742
6743 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006744 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006745
6746 wdev_unlock(wdev);
6747
6748 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006749}
6750
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006751static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6752 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006753{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006754 struct nlattr *nl_reg_rules;
6755 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006756
Johannes Berg458f4f92012-12-06 15:47:38 +01006757 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6758 (regdom->dfs_region &&
6759 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006760 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006761
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006762 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006763 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006764 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006765
Johannes Berg458f4f92012-12-06 15:47:38 +01006766 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006767 struct nlattr *nl_reg_rule;
6768 const struct ieee80211_reg_rule *reg_rule;
6769 const struct ieee80211_freq_range *freq_range;
6770 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006771 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006772
Johannes Berg458f4f92012-12-06 15:47:38 +01006773 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006774 freq_range = &reg_rule->freq_range;
6775 power_rule = &reg_rule->power_rule;
6776
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006777 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006778 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006779 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006780
Janusz Dziedzic97524822014-01-30 09:52:20 +01006781 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6782 if (!max_bandwidth_khz)
6783 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6784 reg_rule);
6785
David S. Miller9360ffd2012-03-29 04:41:26 -04006786 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6787 reg_rule->flags) ||
6788 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6789 freq_range->start_freq_khz) ||
6790 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6791 freq_range->end_freq_khz) ||
6792 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006793 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006794 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6795 power_rule->max_antenna_gain) ||
6796 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006797 power_rule->max_eirp) ||
6798 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6799 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006800 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006801
6802 nla_nest_end(msg, nl_reg_rule);
6803 }
6804
6805 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006806 return 0;
6807
6808nla_put_failure:
6809 return -EMSGSIZE;
6810}
6811
6812static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6813{
6814 const struct ieee80211_regdomain *regdom = NULL;
6815 struct cfg80211_registered_device *rdev;
6816 struct wiphy *wiphy = NULL;
6817 struct sk_buff *msg;
6818 void *hdr;
6819
6820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6821 if (!msg)
6822 return -ENOBUFS;
6823
6824 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6825 NL80211_CMD_GET_REG);
6826 if (!hdr)
6827 goto put_failure;
6828
6829 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006830 bool self_managed;
6831
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006832 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6833 if (IS_ERR(rdev)) {
6834 nlmsg_free(msg);
6835 return PTR_ERR(rdev);
6836 }
6837
6838 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006839 self_managed = wiphy->regulatory_flags &
6840 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006841 regdom = get_wiphy_regdom(wiphy);
6842
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006843 /* a self-managed-reg device must have a private regdom */
6844 if (WARN_ON(!regdom && self_managed)) {
6845 nlmsg_free(msg);
6846 return -EINVAL;
6847 }
6848
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006849 if (regdom &&
6850 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6851 goto nla_put_failure;
6852 }
6853
6854 if (!wiphy && reg_last_request_cell_base() &&
6855 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6856 NL80211_USER_REG_HINT_CELL_BASE))
6857 goto nla_put_failure;
6858
6859 rcu_read_lock();
6860
6861 if (!regdom)
6862 regdom = rcu_dereference(cfg80211_regdomain);
6863
6864 if (nl80211_put_regdom(regdom, msg))
6865 goto nla_put_failure_rcu;
6866
6867 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006868
6869 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006870 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006871
Johannes Berg458f4f92012-12-06 15:47:38 +01006872nla_put_failure_rcu:
6873 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006874nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006875put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006876 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006877 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006878}
6879
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006880static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6881 u32 seq, int flags, struct wiphy *wiphy,
6882 const struct ieee80211_regdomain *regdom)
6883{
6884 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6885 NL80211_CMD_GET_REG);
6886
6887 if (!hdr)
6888 return -1;
6889
Michal Kubecek0a833c22017-11-15 13:09:32 +01006890 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006891
6892 if (nl80211_put_regdom(regdom, msg))
6893 goto nla_put_failure;
6894
6895 if (!wiphy && reg_last_request_cell_base() &&
6896 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6897 NL80211_USER_REG_HINT_CELL_BASE))
6898 goto nla_put_failure;
6899
6900 if (wiphy &&
6901 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6902 goto nla_put_failure;
6903
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006904 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6905 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6906 goto nla_put_failure;
6907
Johannes Berg053c0952015-01-16 22:09:00 +01006908 genlmsg_end(msg, hdr);
6909 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006910
6911nla_put_failure:
6912 genlmsg_cancel(msg, hdr);
6913 return -EMSGSIZE;
6914}
6915
6916static int nl80211_get_reg_dump(struct sk_buff *skb,
6917 struct netlink_callback *cb)
6918{
6919 const struct ieee80211_regdomain *regdom = NULL;
6920 struct cfg80211_registered_device *rdev;
6921 int err, reg_idx, start = cb->args[2];
6922
6923 rtnl_lock();
6924
6925 if (cfg80211_regdomain && start == 0) {
6926 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6927 NLM_F_MULTI, NULL,
6928 rtnl_dereference(cfg80211_regdomain));
6929 if (err < 0)
6930 goto out_err;
6931 }
6932
6933 /* the global regdom is idx 0 */
6934 reg_idx = 1;
6935 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6936 regdom = get_wiphy_regdom(&rdev->wiphy);
6937 if (!regdom)
6938 continue;
6939
6940 if (++reg_idx <= start)
6941 continue;
6942
6943 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6944 NLM_F_MULTI, &rdev->wiphy, regdom);
6945 if (err < 0) {
6946 reg_idx--;
6947 break;
6948 }
6949 }
6950
6951 cb->args[2] = reg_idx;
6952 err = skb->len;
6953out_err:
6954 rtnl_unlock();
6955 return err;
6956}
6957
Johannes Bergb6863032015-10-15 09:25:18 +02006958#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6959static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6960 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6961 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6962 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6963 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6964 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6965 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6966 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6967};
6968
6969static int parse_reg_rule(struct nlattr *tb[],
6970 struct ieee80211_reg_rule *reg_rule)
6971{
6972 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6973 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6974
6975 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6976 return -EINVAL;
6977 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6978 return -EINVAL;
6979 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6980 return -EINVAL;
6981 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6982 return -EINVAL;
6983 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6984 return -EINVAL;
6985
6986 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6987
6988 freq_range->start_freq_khz =
6989 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6990 freq_range->end_freq_khz =
6991 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6992 freq_range->max_bandwidth_khz =
6993 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6994
6995 power_rule->max_eirp =
6996 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6997
6998 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6999 power_rule->max_antenna_gain =
7000 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7001
7002 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7003 reg_rule->dfs_cac_ms =
7004 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7005
7006 return 0;
7007}
7008
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007009static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7010{
7011 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7012 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007013 char *alpha2;
7014 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007015 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007016 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007017 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007018
7019 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7020 return -EINVAL;
7021
7022 if (!info->attrs[NL80211_ATTR_REG_RULES])
7023 return -EINVAL;
7024
7025 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7026
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007027 if (info->attrs[NL80211_ATTR_DFS_REGION])
7028 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7029
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007030 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007031 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007032 num_rules++;
7033 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007034 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007035 }
7036
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007037 if (!reg_is_valid_request(alpha2))
7038 return -EINVAL;
7039
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007040 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007041 if (!rd)
7042 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007043
7044 rd->n_reg_rules = num_rules;
7045 rd->alpha2[0] = alpha2[0];
7046 rd->alpha2[1] = alpha2[1];
7047
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007048 /*
7049 * Disable DFS master mode if the DFS region was
7050 * not supported or known on this kernel.
7051 */
7052 if (reg_supported_dfs_region(dfs_region))
7053 rd->dfs_region = dfs_region;
7054
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007055 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007056 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007057 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7058 nl_reg_rule, reg_rule_policy,
7059 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007060 if (r)
7061 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007062 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7063 if (r)
7064 goto bad_reg;
7065
7066 rule_idx++;
7067
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007068 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7069 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007070 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007071 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007072 }
7073
Johannes Berg06627992016-06-09 10:40:09 +02007074 /* set_regdom takes ownership of rd */
7075 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007076 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007077 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007078 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007079}
Johannes Bergb6863032015-10-15 09:25:18 +02007080#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007081
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007082static int validate_scan_freqs(struct nlattr *freqs)
7083{
7084 struct nlattr *attr1, *attr2;
7085 int n_channels = 0, tmp1, tmp2;
7086
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007087 nla_for_each_nested(attr1, freqs, tmp1)
7088 if (nla_len(attr1) != sizeof(u32))
7089 return 0;
7090
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007091 nla_for_each_nested(attr1, freqs, tmp1) {
7092 n_channels++;
7093 /*
7094 * Some hardware has a limited channel list for
7095 * scanning, and it is pretty much nonsensical
7096 * to scan for a channel twice, so disallow that
7097 * and don't require drivers to check that the
7098 * channel list they get isn't longer than what
7099 * they can scan, as long as they can scan all
7100 * the channels they registered at once.
7101 */
7102 nla_for_each_nested(attr2, freqs, tmp2)
7103 if (attr1 != attr2 &&
7104 nla_get_u32(attr1) == nla_get_u32(attr2))
7105 return 0;
7106 }
7107
7108 return n_channels;
7109}
7110
Johannes Berg57fbcce2016-04-12 15:56:15 +02007111static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007112{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007113 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007114}
7115
7116static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7117 struct cfg80211_bss_selection *bss_select)
7118{
7119 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7120 struct nlattr *nest;
7121 int err;
7122 bool found = false;
7123 int i;
7124
7125 /* only process one nested attribute */
7126 nest = nla_data(nla);
7127 if (!nla_ok(nest, nla_len(nest)))
7128 return -EINVAL;
7129
Johannes Berg8cb08172019-04-26 14:07:28 +02007130 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7131 nest, nl80211_bss_select_policy,
7132 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007133 if (err)
7134 return err;
7135
7136 /* only one attribute may be given */
7137 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7138 if (attr[i]) {
7139 if (found)
7140 return -EINVAL;
7141 found = true;
7142 }
7143 }
7144
7145 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7146
7147 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7148 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7149
7150 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7151 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7152 bss_select->param.band_pref =
7153 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7154 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7155 return -EINVAL;
7156 }
7157
7158 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7159 struct nl80211_bss_select_rssi_adjust *adj_param;
7160
7161 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7162 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7163 bss_select->param.adjust.band = adj_param->band;
7164 bss_select->param.adjust.delta = adj_param->delta;
7165 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7166 return -EINVAL;
7167 }
7168
7169 /* user-space did not provide behaviour attribute */
7170 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7171 return -EINVAL;
7172
7173 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7174 return -EINVAL;
7175
7176 return 0;
7177}
7178
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007179int nl80211_parse_random_mac(struct nlattr **attrs,
7180 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007181{
7182 int i;
7183
7184 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007185 eth_zero_addr(mac_addr);
7186 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007187 mac_addr[0] = 0x2;
7188 mac_addr_mask[0] = 0x3;
7189
7190 return 0;
7191 }
7192
7193 /* need both or none */
7194 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7195 return -EINVAL;
7196
7197 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7198 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7199
7200 /* don't allow or configure an mcast address */
7201 if (!is_multicast_ether_addr(mac_addr_mask) ||
7202 is_multicast_ether_addr(mac_addr))
7203 return -EINVAL;
7204
7205 /*
7206 * allow users to pass a MAC address that has bits set outside
7207 * of the mask, but don't bother drivers with having to deal
7208 * with such bits
7209 */
7210 for (i = 0; i < ETH_ALEN; i++)
7211 mac_addr[i] &= mac_addr_mask[i];
7212
7213 return 0;
7214}
7215
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307216static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7217{
7218 ASSERT_WDEV_LOCK(wdev);
7219
7220 if (!cfg80211_beaconing_iface_active(wdev))
7221 return true;
7222
7223 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7224 return true;
7225
7226 return regulatory_pre_cac_allowed(wdev->wiphy);
7227}
7228
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007229static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7230 enum nl80211_ext_feature_index feat)
7231{
7232 if (!(flags & flag))
7233 return true;
7234 if (wiphy_ext_feature_isset(wiphy, feat))
7235 return true;
7236 return false;
7237}
7238
Roee Zamir2d23d072017-08-06 11:38:22 +03007239static int
7240nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7241 void *request, struct nlattr **attrs,
7242 bool is_sched_scan)
7243{
7244 u8 *mac_addr, *mac_addr_mask;
7245 u32 *flags;
7246 enum nl80211_feature_flags randomness_flag;
7247
7248 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7249 return 0;
7250
7251 if (is_sched_scan) {
7252 struct cfg80211_sched_scan_request *req = request;
7253
7254 randomness_flag = wdev ?
7255 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7256 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7257 flags = &req->flags;
7258 mac_addr = req->mac_addr;
7259 mac_addr_mask = req->mac_addr_mask;
7260 } else {
7261 struct cfg80211_scan_request *req = request;
7262
7263 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7264 flags = &req->flags;
7265 mac_addr = req->mac_addr;
7266 mac_addr_mask = req->mac_addr_mask;
7267 }
7268
7269 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7270
Sunil Dutt5037a002018-01-25 17:13:37 +02007271 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7272 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007273 !nl80211_check_scan_feat(wiphy, *flags,
7274 NL80211_SCAN_FLAG_LOW_SPAN,
7275 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7276 !nl80211_check_scan_feat(wiphy, *flags,
7277 NL80211_SCAN_FLAG_LOW_POWER,
7278 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7279 !nl80211_check_scan_feat(wiphy, *flags,
7280 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7281 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7282 !nl80211_check_scan_feat(wiphy, *flags,
7283 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7284 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7285 !nl80211_check_scan_feat(wiphy, *flags,
7286 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7287 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7288 !nl80211_check_scan_feat(wiphy, *flags,
7289 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7290 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7291 !nl80211_check_scan_feat(wiphy, *flags,
7292 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007293 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7294 !nl80211_check_scan_feat(wiphy, *flags,
7295 NL80211_SCAN_FLAG_RANDOM_SN,
7296 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7297 !nl80211_check_scan_feat(wiphy, *flags,
7298 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7299 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007300 return -EOPNOTSUPP;
7301
7302 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7303 int err;
7304
7305 if (!(wiphy->features & randomness_flag) ||
7306 (wdev && wdev->current_bss))
7307 return -EOPNOTSUPP;
7308
7309 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7310 if (err)
7311 return err;
7312 }
7313
Roee Zamir2d23d072017-08-06 11:38:22 +03007314 return 0;
7315}
7316
Johannes Berg2a519312009-02-10 21:25:55 +01007317static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7318{
Johannes Berg4c476992010-10-04 21:36:35 +02007319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007320 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007321 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007322 struct nlattr *attr;
7323 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007324 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007325 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007326
Johannes Berg79c97e92009-07-07 03:56:12 +02007327 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007328
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007329 if (wdev->iftype == NL80211_IFTYPE_NAN)
7330 return -EOPNOTSUPP;
7331
Johannes Berg4c476992010-10-04 21:36:35 +02007332 if (!rdev->ops->scan)
7333 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007334
Johannes Bergf9d15d12014-01-22 11:14:19 +02007335 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007336 err = -EBUSY;
7337 goto unlock;
7338 }
Johannes Berg2a519312009-02-10 21:25:55 +01007339
7340 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007341 n_channels = validate_scan_freqs(
7342 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007343 if (!n_channels) {
7344 err = -EINVAL;
7345 goto unlock;
7346 }
Johannes Berg2a519312009-02-10 21:25:55 +01007347 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007348 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007349 }
7350
7351 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7352 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7353 n_ssids++;
7354
Johannes Bergf9f47522013-03-19 15:04:07 +01007355 if (n_ssids > wiphy->max_scan_ssids) {
7356 err = -EINVAL;
7357 goto unlock;
7358 }
Johannes Berg2a519312009-02-10 21:25:55 +01007359
Jouni Malinen70692ad2009-02-16 19:39:13 +02007360 if (info->attrs[NL80211_ATTR_IE])
7361 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7362 else
7363 ie_len = 0;
7364
Johannes Bergf9f47522013-03-19 15:04:07 +01007365 if (ie_len > wiphy->max_scan_ie_len) {
7366 err = -EINVAL;
7367 goto unlock;
7368 }
Johannes Berg18a83652009-03-31 12:12:05 +02007369
Johannes Berg2a519312009-02-10 21:25:55 +01007370 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007371 + sizeof(*request->ssids) * n_ssids
7372 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007373 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007374 if (!request) {
7375 err = -ENOMEM;
7376 goto unlock;
7377 }
Johannes Berg2a519312009-02-10 21:25:55 +01007378
Johannes Berg2a519312009-02-10 21:25:55 +01007379 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007380 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007381 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007382 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007383 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007384 request->ie = (void *)(request->ssids + n_ssids);
7385 else
7386 request->ie = (void *)(request->channels + n_channels);
7387 }
Johannes Berg2a519312009-02-10 21:25:55 +01007388
Johannes Berg584991d2009-11-02 13:32:03 +01007389 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007390 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7391 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007392 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007393 struct ieee80211_channel *chan;
7394
7395 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7396
7397 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007398 err = -EINVAL;
7399 goto out_free;
7400 }
Johannes Berg584991d2009-11-02 13:32:03 +01007401
7402 /* ignore disabled channels */
7403 if (chan->flags & IEEE80211_CHAN_DISABLED)
7404 continue;
7405
7406 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007407 i++;
7408 }
7409 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007410 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007411
Johannes Berg2a519312009-02-10 21:25:55 +01007412 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007413 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007414 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007415
Johannes Berg2a519312009-02-10 21:25:55 +01007416 if (!wiphy->bands[band])
7417 continue;
7418 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007419 struct ieee80211_channel *chan;
7420
7421 chan = &wiphy->bands[band]->channels[j];
7422
7423 if (chan->flags & IEEE80211_CHAN_DISABLED)
7424 continue;
7425
7426 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007427 i++;
7428 }
7429 }
7430 }
7431
Johannes Berg584991d2009-11-02 13:32:03 +01007432 if (!i) {
7433 err = -EINVAL;
7434 goto out_free;
7435 }
7436
7437 request->n_channels = i;
7438
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307439 wdev_lock(wdev);
7440 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7441 struct ieee80211_channel *chan;
7442
7443 if (request->n_channels != 1) {
7444 wdev_unlock(wdev);
7445 err = -EBUSY;
7446 goto out_free;
7447 }
7448
7449 chan = request->channels[0];
7450 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7451 wdev_unlock(wdev);
7452 err = -EBUSY;
7453 goto out_free;
7454 }
7455 }
7456 wdev_unlock(wdev);
7457
Johannes Berg2a519312009-02-10 21:25:55 +01007458 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007459 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007460 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007461 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007462 err = -EINVAL;
7463 goto out_free;
7464 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007465 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007466 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007467 i++;
7468 }
7469 }
7470
Jouni Malinen70692ad2009-02-16 19:39:13 +02007471 if (info->attrs[NL80211_ATTR_IE]) {
7472 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007473 memcpy((void *)request->ie,
7474 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007475 request->ie_len);
7476 }
7477
Johannes Berg57fbcce2016-04-12 15:56:15 +02007478 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007479 if (wiphy->bands[i])
7480 request->rates[i] =
7481 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007482
7483 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7484 nla_for_each_nested(attr,
7485 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7486 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007487 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007488
Johannes Berg57fbcce2016-04-12 15:56:15 +02007489 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007490 err = -EINVAL;
7491 goto out_free;
7492 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007493
7494 if (!wiphy->bands[band])
7495 continue;
7496
Johannes Berg34850ab2011-07-18 18:08:35 +02007497 err = ieee80211_get_ratemask(wiphy->bands[band],
7498 nla_data(attr),
7499 nla_len(attr),
7500 &request->rates[band]);
7501 if (err)
7502 goto out_free;
7503 }
7504 }
7505
Avraham Stern1d762502016-07-05 17:10:13 +03007506 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7507 if (!wiphy_ext_feature_isset(wiphy,
7508 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7509 err = -EOPNOTSUPP;
7510 goto out_free;
7511 }
7512
7513 request->duration =
7514 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7515 request->duration_mandatory =
7516 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7517 }
7518
Roee Zamir2d23d072017-08-06 11:38:22 +03007519 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7520 false);
7521 if (err)
7522 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007523
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307524 request->no_cck =
7525 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7526
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007527 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7528 * BSSID to scan for. This was problematic because that same attribute
7529 * was already used for another purpose (local random MAC address). The
7530 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7531 * compatibility with older userspace components, also use the
7532 * NL80211_ATTR_MAC value here if it can be determined to be used for
7533 * the specific BSSID use case instead of the random MAC address
7534 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7535 */
7536 if (info->attrs[NL80211_ATTR_BSSID])
7537 memcpy(request->bssid,
7538 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7539 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7540 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007541 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7542 ETH_ALEN);
7543 else
7544 eth_broadcast_addr(request->bssid);
7545
Johannes Bergfd014282012-06-18 19:17:03 +02007546 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007547 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007548 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007549
Johannes Berg79c97e92009-07-07 03:56:12 +02007550 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007551 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007552
Johannes Berg463d0182009-07-14 00:33:35 +02007553 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007554 nl80211_send_scan_start(rdev, wdev);
7555 if (wdev->netdev)
7556 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007557 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007558 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007559 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007560 kfree(request);
7561 }
Johannes Berg3b858752009-03-12 09:55:09 +01007562
Johannes Bergf9f47522013-03-19 15:04:07 +01007563 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007564 return err;
7565}
7566
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307567static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7568{
7569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7570 struct wireless_dev *wdev = info->user_ptr[1];
7571
7572 if (!rdev->ops->abort_scan)
7573 return -EOPNOTSUPP;
7574
7575 if (rdev->scan_msg)
7576 return 0;
7577
7578 if (!rdev->scan_req)
7579 return -ENOENT;
7580
7581 rdev_abort_scan(rdev, wdev);
7582 return 0;
7583}
7584
Avraham Stern3b06d272015-10-12 09:51:34 +03007585static int
7586nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7587 struct cfg80211_sched_scan_request *request,
7588 struct nlattr **attrs)
7589{
7590 int tmp, err, i = 0;
7591 struct nlattr *attr;
7592
7593 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7594 u32 interval;
7595
7596 /*
7597 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007598 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007599 * case one scan plan will be set with the specified scan
7600 * interval and infinite number of iterations.
7601 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007602 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7603 if (!interval)
7604 return -EINVAL;
7605
7606 request->scan_plans[0].interval =
7607 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7608 if (!request->scan_plans[0].interval)
7609 return -EINVAL;
7610
7611 if (request->scan_plans[0].interval >
7612 wiphy->max_sched_scan_plan_interval)
7613 request->scan_plans[0].interval =
7614 wiphy->max_sched_scan_plan_interval;
7615
7616 return 0;
7617 }
7618
7619 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7620 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7621
7622 if (WARN_ON(i >= n_plans))
7623 return -EINVAL;
7624
Johannes Berg8cb08172019-04-26 14:07:28 +02007625 err = nla_parse_nested_deprecated(plan,
7626 NL80211_SCHED_SCAN_PLAN_MAX,
7627 attr, nl80211_plan_policy,
7628 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007629 if (err)
7630 return err;
7631
7632 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7633 return -EINVAL;
7634
7635 request->scan_plans[i].interval =
7636 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7637 if (!request->scan_plans[i].interval ||
7638 request->scan_plans[i].interval >
7639 wiphy->max_sched_scan_plan_interval)
7640 return -EINVAL;
7641
7642 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7643 request->scan_plans[i].iterations =
7644 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7645 if (!request->scan_plans[i].iterations ||
7646 (request->scan_plans[i].iterations >
7647 wiphy->max_sched_scan_plan_iterations))
7648 return -EINVAL;
7649 } else if (i < n_plans - 1) {
7650 /*
7651 * All scan plans but the last one must specify
7652 * a finite number of iterations
7653 */
7654 return -EINVAL;
7655 }
7656
7657 i++;
7658 }
7659
7660 /*
7661 * The last scan plan must not specify the number of
7662 * iterations, it is supposed to run infinitely
7663 */
7664 if (request->scan_plans[n_plans - 1].iterations)
7665 return -EINVAL;
7666
7667 return 0;
7668}
7669
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307670static int
7671nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7672 struct cfg80211_match_set *match_sets,
7673 struct nlattr *tb_band_rssi,
7674 s32 rssi_thold)
7675{
7676 struct nlattr *attr;
7677 int i, tmp, ret = 0;
7678
7679 if (!wiphy_ext_feature_isset(wiphy,
7680 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7681 if (tb_band_rssi)
7682 ret = -EOPNOTSUPP;
7683 else
7684 for (i = 0; i < NUM_NL80211_BANDS; i++)
7685 match_sets->per_band_rssi_thold[i] =
7686 NL80211_SCAN_RSSI_THOLD_OFF;
7687 return ret;
7688 }
7689
7690 for (i = 0; i < NUM_NL80211_BANDS; i++)
7691 match_sets->per_band_rssi_thold[i] = rssi_thold;
7692
7693 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7694 enum nl80211_band band = nla_type(attr);
7695
7696 if (band < 0 || band >= NUM_NL80211_BANDS)
7697 return -EINVAL;
7698
7699 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7700 }
7701
7702 return 0;
7703}
7704
Luciano Coelho256da022014-11-10 16:13:46 +02007705static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007706nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007707 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007708{
7709 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007710 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007711 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007712 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007713 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007714 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007715 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007716
Luciano Coelho256da022014-11-10 16:13:46 +02007717 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007718 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007719 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007720 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007721 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007722 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007723 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007724 }
7725
Luciano Coelho256da022014-11-10 16:13:46 +02007726 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7727 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007728 tmp)
7729 n_ssids++;
7730
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007731 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007732 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007733
Johannes Bergea73cbc2014-01-24 10:53:53 +01007734 /*
7735 * First, count the number of 'real' matchsets. Due to an issue with
7736 * the old implementation, matchsets containing only the RSSI attribute
7737 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7738 * RSSI for all matchsets, rather than their own matchset for reporting
7739 * all APs with a strong RSSI. This is needed to be compatible with
7740 * older userspace that treated a matchset with only the RSSI as the
7741 * global RSSI for all other matchsets - if there are other matchsets.
7742 */
Luciano Coelho256da022014-11-10 16:13:46 +02007743 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007744 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007745 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007746 tmp) {
7747 struct nlattr *rssi;
7748
Johannes Berg8cb08172019-04-26 14:07:28 +02007749 err = nla_parse_nested_deprecated(tb,
7750 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7751 attr,
7752 nl80211_match_policy,
7753 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007754 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007755 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007756
7757 /* SSID and BSSID are mutually exclusive */
7758 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7759 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7760 return ERR_PTR(-EINVAL);
7761
Johannes Bergea73cbc2014-01-24 10:53:53 +01007762 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007763 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7764 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007765 n_match_sets++;
7766 continue;
7767 }
7768 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7769 if (rssi)
7770 default_match_rssi = nla_get_s32(rssi);
7771 }
7772 }
7773
7774 /* However, if there's no other matchset, add the RSSI one */
7775 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7776 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007777
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007778 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007779 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007780
Luciano Coelho256da022014-11-10 16:13:46 +02007781 if (attrs[NL80211_ATTR_IE])
7782 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007783 else
7784 ie_len = 0;
7785
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007786 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007787 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007788
Avraham Stern3b06d272015-10-12 09:51:34 +03007789 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7790 /*
7791 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7792 * each scan plan already specifies its own interval
7793 */
7794 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7795 return ERR_PTR(-EINVAL);
7796
7797 nla_for_each_nested(attr,
7798 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7799 n_plans++;
7800 } else {
7801 /*
7802 * The scan interval attribute is kept for backward
7803 * compatibility. If no scan plans are specified and sched scan
7804 * interval is specified, one scan plan will be set with this
7805 * scan interval and infinite number of iterations.
7806 */
7807 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7808 return ERR_PTR(-EINVAL);
7809
7810 n_plans = 1;
7811 }
7812
7813 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7814 return ERR_PTR(-EINVAL);
7815
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007816 if (!wiphy_ext_feature_isset(
7817 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7818 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7819 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7820 return ERR_PTR(-EINVAL);
7821
Luciano Coelho807f8a82011-05-11 17:09:35 +03007822 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007823 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007824 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007825 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007826 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007827 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007828 if (!request)
7829 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007830
7831 if (n_ssids)
7832 request->ssids = (void *)&request->channels[n_channels];
7833 request->n_ssids = n_ssids;
7834 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007835 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007836 request->ie = (void *)(request->ssids + n_ssids);
7837 else
7838 request->ie = (void *)(request->channels + n_channels);
7839 }
7840
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007841 if (n_match_sets) {
7842 if (request->ie)
7843 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007844 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007845 request->match_sets =
7846 (void *)(request->ssids + n_ssids);
7847 else
7848 request->match_sets =
7849 (void *)(request->channels + n_channels);
7850 }
7851 request->n_match_sets = n_match_sets;
7852
Avraham Stern3b06d272015-10-12 09:51:34 +03007853 if (n_match_sets)
7854 request->scan_plans = (void *)(request->match_sets +
7855 n_match_sets);
7856 else if (request->ie)
7857 request->scan_plans = (void *)(request->ie + ie_len);
7858 else if (n_ssids)
7859 request->scan_plans = (void *)(request->ssids + n_ssids);
7860 else
7861 request->scan_plans = (void *)(request->channels + n_channels);
7862
7863 request->n_scan_plans = n_plans;
7864
Luciano Coelho807f8a82011-05-11 17:09:35 +03007865 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007866 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007867 /* user specified, bail out if channel not found */
7868 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007869 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007870 tmp) {
7871 struct ieee80211_channel *chan;
7872
7873 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7874
7875 if (!chan) {
7876 err = -EINVAL;
7877 goto out_free;
7878 }
7879
7880 /* ignore disabled channels */
7881 if (chan->flags & IEEE80211_CHAN_DISABLED)
7882 continue;
7883
7884 request->channels[i] = chan;
7885 i++;
7886 }
7887 } else {
7888 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007889 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007890 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007891
Luciano Coelho807f8a82011-05-11 17:09:35 +03007892 if (!wiphy->bands[band])
7893 continue;
7894 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7895 struct ieee80211_channel *chan;
7896
7897 chan = &wiphy->bands[band]->channels[j];
7898
7899 if (chan->flags & IEEE80211_CHAN_DISABLED)
7900 continue;
7901
7902 request->channels[i] = chan;
7903 i++;
7904 }
7905 }
7906 }
7907
7908 if (!i) {
7909 err = -EINVAL;
7910 goto out_free;
7911 }
7912
7913 request->n_channels = i;
7914
7915 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007916 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007917 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007918 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007919 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007920 err = -EINVAL;
7921 goto out_free;
7922 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007923 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007924 memcpy(request->ssids[i].ssid, nla_data(attr),
7925 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007926 i++;
7927 }
7928 }
7929
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007930 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007931 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007932 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007933 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007934 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007935 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007936
Johannes Berg8cb08172019-04-26 14:07:28 +02007937 err = nla_parse_nested_deprecated(tb,
7938 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7939 attr,
7940 nl80211_match_policy,
7941 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007942 if (err)
7943 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007944 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007945 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02007946
7947 if (!ssid && !bssid) {
7948 i++;
7949 continue;
7950 }
7951
7952 if (WARN_ON(i >= n_match_sets)) {
7953 /* this indicates a programming error,
7954 * the loop above should have verified
7955 * things properly
7956 */
7957 err = -EINVAL;
7958 goto out_free;
7959 }
7960
7961 if (ssid) {
7962 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007963 err = -EINVAL;
7964 goto out_free;
7965 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02007966 memcpy(request->match_sets[i].ssid.ssid,
7967 nla_data(ssid), nla_len(ssid));
7968 request->match_sets[i].ssid.ssid_len =
7969 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007970 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02007971 if (bssid) {
7972 if (nla_len(bssid) != ETH_ALEN) {
7973 err = -EINVAL;
7974 goto out_free;
7975 }
7976 memcpy(request->match_sets[i].bssid,
7977 nla_data(bssid), ETH_ALEN);
7978 }
7979
7980 /* special attribute - old implementation w/a */
7981 request->match_sets[i].rssi_thold = default_match_rssi;
7982 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7983 if (rssi)
7984 request->match_sets[i].rssi_thold =
7985 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05307986
7987 /* Parse per band RSSI attribute */
7988 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
7989 &request->match_sets[i],
7990 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
7991 request->match_sets[i].rssi_thold);
7992 if (err)
7993 goto out_free;
7994
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007995 i++;
7996 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007997
7998 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007999 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008000 request->match_sets[0].rssi_thold = default_match_rssi;
8001
8002 request->min_rssi_thold = INT_MAX;
8003 for (i = 0; i < n_match_sets; i++)
8004 request->min_rssi_thold =
8005 min(request->match_sets[i].rssi_thold,
8006 request->min_rssi_thold);
8007 } else {
8008 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008009 }
8010
Johannes Berg9900e482014-02-04 21:01:25 +01008011 if (ie_len) {
8012 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008013 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008014 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008015 request->ie_len);
8016 }
8017
Roee Zamir2d23d072017-08-06 11:38:22 +03008018 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8019 if (err)
8020 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008021
Luciano Coelho9c748932015-01-16 16:04:09 +02008022 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8023 request->delay =
8024 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8025
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008026 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8027 request->relative_rssi = nla_get_s8(
8028 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8029 request->relative_rssi_set = true;
8030 }
8031
8032 if (request->relative_rssi_set &&
8033 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8034 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8035
8036 rssi_adjust = nla_data(
8037 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8038 request->rssi_adjust.band = rssi_adjust->band;
8039 request->rssi_adjust.delta = rssi_adjust->delta;
8040 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8041 err = -EINVAL;
8042 goto out_free;
8043 }
8044 }
8045
Avraham Stern3b06d272015-10-12 09:51:34 +03008046 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8047 if (err)
8048 goto out_free;
8049
Sam Leffler15d60302012-10-11 21:03:34 -07008050 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008051
Luciano Coelho256da022014-11-10 16:13:46 +02008052 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008053
8054out_free:
8055 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008056 return ERR_PTR(err);
8057}
8058
8059static int nl80211_start_sched_scan(struct sk_buff *skb,
8060 struct genl_info *info)
8061{
8062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8063 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008064 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008065 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008066 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008067 int err;
8068
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008069 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008070 return -EOPNOTSUPP;
8071
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008072 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8073 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8074 if (err)
8075 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008076
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008077 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008078 info->attrs,
8079 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008080
8081 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008082 if (err)
8083 goto out_err;
8084
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008085 /* leave request id zero for legacy request
8086 * or if driver does not support multi-scheduled scan
8087 */
8088 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
8089 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02008090 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008091 }
8092
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008093 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008094 if (err)
8095 goto out_free;
8096
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008097 sched_scan_req->dev = dev;
8098 sched_scan_req->wiphy = &rdev->wiphy;
8099
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008100 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8101 sched_scan_req->owner_nlportid = info->snd_portid;
8102
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008103 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008104
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008105 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008106 return 0;
8107
8108out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008109 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008110out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008111 return err;
8112}
8113
8114static int nl80211_stop_sched_scan(struct sk_buff *skb,
8115 struct genl_info *info)
8116{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008117 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008119 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008120
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008121 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008122 return -EOPNOTSUPP;
8123
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008124 if (info->attrs[NL80211_ATTR_COOKIE]) {
8125 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8126 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8127 }
8128
8129 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8130 struct cfg80211_sched_scan_request,
8131 list);
8132 if (!req || req->reqid ||
8133 (req->owner_nlportid &&
8134 req->owner_nlportid != info->snd_portid))
8135 return -ENOENT;
8136
8137 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008138}
8139
Simon Wunderlich04f39042013-02-08 18:16:19 +01008140static int nl80211_start_radar_detection(struct sk_buff *skb,
8141 struct genl_info *info)
8142{
8143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8144 struct net_device *dev = info->user_ptr[1];
8145 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008146 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008147 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008148 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008149 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008150 int err;
8151
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008152 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008153 if (dfs_region == NL80211_DFS_UNSET)
8154 return -EINVAL;
8155
Simon Wunderlich04f39042013-02-08 18:16:19 +01008156 err = nl80211_parse_chandef(rdev, info, &chandef);
8157 if (err)
8158 return err;
8159
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008160 if (netif_carrier_ok(dev))
8161 return -EBUSY;
8162
Simon Wunderlich04f39042013-02-08 18:16:19 +01008163 if (wdev->cac_started)
8164 return -EBUSY;
8165
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008166 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008167 if (err < 0)
8168 return err;
8169
8170 if (err == 0)
8171 return -EINVAL;
8172
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008173 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008174 return -EINVAL;
8175
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008176 /* CAC start is offloaded to HW and can't be started manually */
8177 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8178 return -EOPNOTSUPP;
8179
Simon Wunderlich04f39042013-02-08 18:16:19 +01008180 if (!rdev->ops->start_radar_detection)
8181 return -EOPNOTSUPP;
8182
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008183 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8184 if (WARN_ON(!cac_time_ms))
8185 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8186
Ilan Peera1056b1b2015-10-22 22:27:46 +03008187 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008188 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008189 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008190 wdev->cac_started = true;
8191 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008192 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008193 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008194 return err;
8195}
8196
Sriram R30c63112018-12-04 17:46:52 +05308197static int nl80211_notify_radar_detection(struct sk_buff *skb,
8198 struct genl_info *info)
8199{
8200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8201 struct net_device *dev = info->user_ptr[1];
8202 struct wireless_dev *wdev = dev->ieee80211_ptr;
8203 struct wiphy *wiphy = wdev->wiphy;
8204 struct cfg80211_chan_def chandef;
8205 enum nl80211_dfs_regions dfs_region;
8206 int err;
8207
8208 dfs_region = reg_get_dfs_region(wiphy);
8209 if (dfs_region == NL80211_DFS_UNSET) {
8210 GENL_SET_ERR_MSG(info,
8211 "DFS Region is not set. Unexpected Radar indication");
8212 return -EINVAL;
8213 }
8214
8215 err = nl80211_parse_chandef(rdev, info, &chandef);
8216 if (err) {
8217 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8218 return err;
8219 }
8220
8221 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8222 if (err < 0) {
8223 GENL_SET_ERR_MSG(info, "chandef is invalid");
8224 return err;
8225 }
8226
8227 if (err == 0) {
8228 GENL_SET_ERR_MSG(info,
8229 "Unexpected Radar indication for chandef/iftype");
8230 return -EINVAL;
8231 }
8232
8233 /* Do not process this notification if radar is already detected
8234 * by kernel on this channel, and return success.
8235 */
8236 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8237 return 0;
8238
8239 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8240
8241 cfg80211_sched_dfs_chan_update(rdev);
8242
Luca Coelhoa680fe42019-04-17 09:34:40 +03008243 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308244
8245 /* Propagate this notification to other radios as well */
8246 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8247
8248 return 0;
8249}
8250
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008251static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8252{
8253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8254 struct net_device *dev = info->user_ptr[1];
8255 struct wireless_dev *wdev = dev->ieee80211_ptr;
8256 struct cfg80211_csa_settings params;
8257 /* csa_attrs is defined static to avoid waste of stack size - this
8258 * function is called under RTNL lock, so this should not be a problem.
8259 */
8260 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008261 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008262 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008263 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008264 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008265 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008266
8267 if (!rdev->ops->channel_switch ||
8268 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8269 return -EOPNOTSUPP;
8270
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008271 switch (dev->ieee80211_ptr->iftype) {
8272 case NL80211_IFTYPE_AP:
8273 case NL80211_IFTYPE_P2P_GO:
8274 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008275 /* For all modes except AP the handle_dfs flag needs to be
8276 * supplied to tell the kernel that userspace will handle radar
8277 * events when they happen. Otherwise a switch to a channel
8278 * requiring DFS will be rejected.
8279 */
8280 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008281
8282 /* useless if AP is not running */
8283 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008284 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008285 break;
8286 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008287 if (!wdev->ssid_len)
8288 return -ENOTCONN;
8289 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008290 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008291 if (!wdev->mesh_id_len)
8292 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008293 break;
8294 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008295 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008296 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008297
8298 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008299 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008300
8301 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8302 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8303 return -EINVAL;
8304
8305 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008306 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008307 return -EINVAL;
8308
Luciano Coelho252e07c2014-10-08 09:48:34 +03008309 /* Even though the attribute is u32, the specification says
8310 * u8, so let's make sure we don't overflow.
8311 */
8312 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8313 if (cs_count > 255)
8314 return -EINVAL;
8315
8316 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008317
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008318 if (!need_new_beacon)
8319 goto skip_beacons;
8320
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008321 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008322 if (err)
8323 return err;
8324
Johannes Berg8cb08172019-04-26 14:07:28 +02008325 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8326 info->attrs[NL80211_ATTR_CSA_IES],
8327 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008328 if (err)
8329 return err;
8330
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008331 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008332 if (err)
8333 return err;
8334
8335 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8336 return -EINVAL;
8337
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008338 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8339 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008340 return -EINVAL;
8341
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008342 params.n_counter_offsets_beacon = len / sizeof(u16);
8343 if (rdev->wiphy.max_num_csa_counters &&
8344 (params.n_counter_offsets_beacon >
8345 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008346 return -EINVAL;
8347
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008348 params.counter_offsets_beacon =
8349 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8350
8351 /* sanity checks - counters should fit and be the same */
8352 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8353 u16 offset = params.counter_offsets_beacon[i];
8354
8355 if (offset >= params.beacon_csa.tail_len)
8356 return -EINVAL;
8357
8358 if (params.beacon_csa.tail[offset] != params.count)
8359 return -EINVAL;
8360 }
8361
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008362 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008363 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8364 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008365 return -EINVAL;
8366
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008367 params.n_counter_offsets_presp = len / sizeof(u16);
8368 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008369 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008370 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008371 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008372
8373 params.counter_offsets_presp =
8374 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8375
8376 /* sanity checks - counters should fit and be the same */
8377 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8378 u16 offset = params.counter_offsets_presp[i];
8379
8380 if (offset >= params.beacon_csa.probe_resp_len)
8381 return -EINVAL;
8382
8383 if (params.beacon_csa.probe_resp[offset] !=
8384 params.count)
8385 return -EINVAL;
8386 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008387 }
8388
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008389skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008390 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8391 if (err)
8392 return err;
8393
Arik Nemtsov923b3522015-07-08 15:41:44 +03008394 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8395 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008396 return -EINVAL;
8397
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008398 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8399 &params.chandef,
8400 wdev->iftype);
8401 if (err < 0)
8402 return err;
8403
Benjamin Berg8d9de162017-05-16 11:23:12 +02008404 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008405 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008406 if (need_handle_dfs_flag &&
8407 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8408 return -EINVAL;
8409 }
8410 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008411
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008412 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8413 params.block_tx = true;
8414
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008415 wdev_lock(wdev);
8416 err = rdev_channel_switch(rdev, dev, &params);
8417 wdev_unlock(wdev);
8418
8419 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008420}
8421
Johannes Berg9720bb32011-06-21 09:45:33 +02008422static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8423 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008424 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008425 struct wireless_dev *wdev,
8426 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008427{
Johannes Berg48ab9052009-07-10 18:42:31 +02008428 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008429 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008430 void *hdr;
8431 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008432
8433 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008434
Eric W. Biederman15e47302012-09-07 20:12:54 +00008435 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008436 NL80211_CMD_NEW_SCAN_RESULTS);
8437 if (!hdr)
8438 return -1;
8439
Michal Kubecek0a833c22017-11-15 13:09:32 +01008440 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008441
Johannes Berg97990a02013-04-19 01:02:55 +02008442 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8443 goto nla_put_failure;
8444 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008445 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8446 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008447 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8448 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008449 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008450
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008451 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01008452 if (!bss)
8453 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008454 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008455 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008456 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008457
8458 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008459 /* indicate whether we have probe response data or not */
8460 if (rcu_access_pointer(res->proberesp_ies) &&
8461 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8462 goto fail_unlock_rcu;
8463
8464 /* this pointer prefers to be pointed to probe response data
8465 * but is always valid
8466 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008467 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008468 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008469 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8470 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008471 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008472 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8473 ies->len, ies->data))
8474 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008475 }
Johannes Berg0e227082014-08-12 20:34:30 +02008476
8477 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008478 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008479 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008480 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8481 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008482 goto fail_unlock_rcu;
8483 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8484 ies->len, ies->data))
8485 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008486 }
8487 rcu_read_unlock();
8488
David S. Miller9360ffd2012-03-29 04:41:26 -04008489 if (res->beacon_interval &&
8490 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8491 goto nla_put_failure;
8492 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8493 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008494 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008495 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8496 jiffies_to_msecs(jiffies - intbss->ts)))
8497 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008498
Avraham Stern1d762502016-07-05 17:10:13 +03008499 if (intbss->parent_tsf &&
8500 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8501 intbss->parent_tsf, NL80211_BSS_PAD) ||
8502 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8503 intbss->parent_bssid)))
8504 goto nla_put_failure;
8505
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008506 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008507 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8508 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008509 goto nla_put_failure;
8510
Sunil Dutt983dafa2017-12-13 19:51:36 +02008511 if (!nl80211_put_signal(msg, intbss->pub.chains,
8512 intbss->pub.chain_signal,
8513 NL80211_BSS_CHAIN_SIGNAL))
8514 goto nla_put_failure;
8515
Johannes Berg77965c972009-02-18 18:45:06 +01008516 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008517 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008518 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8519 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008520 break;
8521 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008522 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8523 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008524 break;
8525 default:
8526 break;
8527 }
8528
Johannes Berg48ab9052009-07-10 18:42:31 +02008529 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008530 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008531 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008532 if (intbss == wdev->current_bss &&
8533 nla_put_u32(msg, NL80211_BSS_STATUS,
8534 NL80211_BSS_STATUS_ASSOCIATED))
8535 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008536 break;
8537 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008538 if (intbss == wdev->current_bss &&
8539 nla_put_u32(msg, NL80211_BSS_STATUS,
8540 NL80211_BSS_STATUS_IBSS_JOINED))
8541 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008542 break;
8543 default:
8544 break;
8545 }
8546
Johannes Berg2a519312009-02-10 21:25:55 +01008547 nla_nest_end(msg, bss);
8548
Johannes Berg053c0952015-01-16 22:09:00 +01008549 genlmsg_end(msg, hdr);
8550 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008551
Johannes Berg8cef2c92013-02-05 16:54:31 +01008552 fail_unlock_rcu:
8553 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008554 nla_put_failure:
8555 genlmsg_cancel(msg, hdr);
8556 return -EMSGSIZE;
8557}
8558
Johannes Berg97990a02013-04-19 01:02:55 +02008559static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008560{
Johannes Berg48ab9052009-07-10 18:42:31 +02008561 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008562 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008563 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008564 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008565 int err;
8566
Johannes Bergea90e0d2017-03-15 14:26:04 +01008567 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008568 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008569 if (err) {
8570 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008571 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008572 }
Johannes Berg2a519312009-02-10 21:25:55 +01008573
Johannes Berg48ab9052009-07-10 18:42:31 +02008574 wdev_lock(wdev);
8575 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008576
8577 /*
8578 * dump_scan will be called multiple times to break up the scan results
8579 * into multiple messages. It is unlikely that any more bss-es will be
8580 * expired after the first call, so only call only call this on the
8581 * first dump_scan invocation.
8582 */
8583 if (start == 0)
8584 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008585
Johannes Berg9720bb32011-06-21 09:45:33 +02008586 cb->seq = rdev->bss_generation;
8587
Johannes Berg48ab9052009-07-10 18:42:31 +02008588 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008589 if (++idx <= start)
8590 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008591 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008592 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008593 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008594 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008595 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008596 }
8597 }
8598
Johannes Berg48ab9052009-07-10 18:42:31 +02008599 spin_unlock_bh(&rdev->bss_lock);
8600 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008601
Johannes Berg97990a02013-04-19 01:02:55 +02008602 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008603 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008604
Johannes Berg67748892010-10-04 21:14:06 +02008605 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008606}
8607
Eric W. Biederman15e47302012-09-07 20:12:54 +00008608static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008609 int flags, struct net_device *dev,
8610 bool allow_radio_stats,
8611 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008612{
8613 void *hdr;
8614 struct nlattr *infoattr;
8615
Johannes Berg11f78ac2014-11-14 16:43:50 +01008616 /* skip radio stats if userspace didn't request them */
8617 if (!survey->channel && !allow_radio_stats)
8618 return 0;
8619
Eric W. Biederman15e47302012-09-07 20:12:54 +00008620 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008621 NL80211_CMD_NEW_SURVEY_RESULTS);
8622 if (!hdr)
8623 return -ENOMEM;
8624
David S. Miller9360ffd2012-03-29 04:41:26 -04008625 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8626 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008627
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008628 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01008629 if (!infoattr)
8630 goto nla_put_failure;
8631
Johannes Berg11f78ac2014-11-14 16:43:50 +01008632 if (survey->channel &&
8633 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008634 survey->channel->center_freq))
8635 goto nla_put_failure;
8636
8637 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8638 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8639 goto nla_put_failure;
8640 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8641 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8642 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008643 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008644 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8645 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008646 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008647 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008648 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8649 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008650 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008651 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008652 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8653 survey->time_ext_busy, 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_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008656 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8657 survey->time_rx, 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_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008660 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8661 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008662 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008663 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008664 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8665 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008666 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008667
8668 nla_nest_end(msg, infoattr);
8669
Johannes Berg053c0952015-01-16 22:09:00 +01008670 genlmsg_end(msg, hdr);
8671 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008672
8673 nla_put_failure:
8674 genlmsg_cancel(msg, hdr);
8675 return -EMSGSIZE;
8676}
8677
Johannes Berg11f78ac2014-11-14 16:43:50 +01008678static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008679{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008680 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008681 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008682 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008683 struct wireless_dev *wdev;
8684 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008685 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008686 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008687
Johannes Bergea90e0d2017-03-15 14:26:04 +01008688 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008689 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008690 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008691 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008692
Johannes Berg11f78ac2014-11-14 16:43:50 +01008693 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008694 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008695
Johannes Berg97990a02013-04-19 01:02:55 +02008696 if (!wdev->netdev) {
8697 res = -EINVAL;
8698 goto out_err;
8699 }
8700
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008701 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008702 res = -EOPNOTSUPP;
8703 goto out_err;
8704 }
8705
8706 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008707 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008708 if (res == -ENOENT)
8709 break;
8710 if (res)
8711 goto out_err;
8712
Johannes Berg11f78ac2014-11-14 16:43:50 +01008713 /* don't send disabled channels, but do send non-channel data */
8714 if (survey.channel &&
8715 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008716 survey_idx++;
8717 continue;
8718 }
8719
Holger Schurig61fa7132009-11-11 12:25:40 +01008720 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008721 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008722 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008723 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008724 goto out;
8725 survey_idx++;
8726 }
8727
8728 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008729 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008730 res = skb->len;
8731 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008732 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008733 return res;
8734}
8735
Samuel Ortizb23aa672009-07-01 21:26:54 +02008736static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8737{
8738 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8739 NL80211_WPA_VERSION_2));
8740}
8741
Jouni Malinen636a5d32009-03-19 13:39:22 +02008742static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8743{
Johannes Berg4c476992010-10-04 21:36:35 +02008744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8745 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008746 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008747 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8748 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008749 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008750 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008751 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008752
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008753 if (!info->attrs[NL80211_ATTR_MAC])
8754 return -EINVAL;
8755
Jouni Malinen17780922009-03-27 20:52:47 +02008756 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8757 return -EINVAL;
8758
Johannes Berg19957bb2009-07-02 17:20:43 +02008759 if (!info->attrs[NL80211_ATTR_SSID])
8760 return -EINVAL;
8761
8762 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8763 return -EINVAL;
8764
Johannes Bergfffd0932009-07-08 14:22:54 +02008765 err = nl80211_parse_key(info, &key);
8766 if (err)
8767 return err;
8768
8769 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008770 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8771 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008772 if (!key.p.key || !key.p.key_len)
8773 return -EINVAL;
8774 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8775 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8776 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8777 key.p.key_len != WLAN_KEY_LEN_WEP104))
8778 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008779 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008780 return -EINVAL;
8781 } else {
8782 key.p.key_len = 0;
8783 key.p.key = NULL;
8784 }
8785
Johannes Bergafea0b72010-08-10 09:46:42 +02008786 if (key.idx >= 0) {
8787 int i;
8788 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008789
Johannes Bergafea0b72010-08-10 09:46:42 +02008790 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8791 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8792 ok = true;
8793 break;
8794 }
8795 }
Johannes Berg4c476992010-10-04 21:36:35 +02008796 if (!ok)
8797 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008798 }
8799
Johannes Berg4c476992010-10-04 21:36:35 +02008800 if (!rdev->ops->auth)
8801 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008802
Johannes Berg074ac8d2010-09-16 14:58:22 +02008803 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008804 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8805 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008806
Johannes Berg19957bb2009-07-02 17:20:43 +02008807 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008808 chan = nl80211_get_valid_chan(&rdev->wiphy,
8809 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8810 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008811 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008812
Johannes Berg19957bb2009-07-02 17:20:43 +02008813 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8814 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8815
8816 if (info->attrs[NL80211_ATTR_IE]) {
8817 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8818 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8819 }
8820
8821 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008822 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008823 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008824
Jouni Malinen63181062016-10-27 00:42:02 +03008825 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8826 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8827 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8828 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008829 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008830 return -EINVAL;
8831
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008832 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008833 if (auth_type != NL80211_AUTHTYPE_SAE &&
8834 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8835 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8836 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008837 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008838 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8839 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008840 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008841 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008842 return -EINVAL;
8843 }
8844
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008845 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8846
Johannes Berg95de8172012-01-20 13:55:25 +01008847 /*
8848 * Since we no longer track auth state, ignore
8849 * requests to only change local state.
8850 */
8851 if (local_state_change)
8852 return 0;
8853
Johannes Berg91bf9b22013-05-15 17:44:01 +02008854 wdev_lock(dev->ieee80211_ptr);
8855 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8856 ssid, ssid_len, ie, ie_len,
8857 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008858 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008859 wdev_unlock(dev->ieee80211_ptr);
8860 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008861}
8862
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008863static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8864 struct genl_info *info)
8865{
8866 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8867 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8868 return -EINVAL;
8869 }
8870
8871 if (!rdev->ops->tx_control_port ||
8872 !wiphy_ext_feature_isset(&rdev->wiphy,
8873 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8874 return -EOPNOTSUPP;
8875
8876 return 0;
8877}
8878
Johannes Bergc0692b82010-08-27 14:26:53 +03008879static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8880 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008881 struct cfg80211_crypto_settings *settings,
8882 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008883{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008884 memset(settings, 0, sizeof(*settings));
8885
Samuel Ortizb23aa672009-07-01 21:26:54 +02008886 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8887
Johannes Bergc0692b82010-08-27 14:26:53 +03008888 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8889 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008890
Johannes Bergc0692b82010-08-27 14:26:53 +03008891 proto = nla_get_u16(
8892 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8893 settings->control_port_ethertype = cpu_to_be16(proto);
8894 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8895 proto != ETH_P_PAE)
8896 return -EINVAL;
8897 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8898 settings->control_port_no_encrypt = true;
8899 } else
8900 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8901
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008902 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8903 int r = validate_pae_over_nl80211(rdev, info);
8904
8905 if (r < 0)
8906 return r;
8907
8908 settings->control_port_over_nl80211 = true;
8909 }
8910
Samuel Ortizb23aa672009-07-01 21:26:54 +02008911 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8912 void *data;
8913 int len, i;
8914
8915 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8916 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8917 settings->n_ciphers_pairwise = len / sizeof(u32);
8918
8919 if (len % sizeof(u32))
8920 return -EINVAL;
8921
Johannes Berg3dc27d22009-07-02 21:36:37 +02008922 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008923 return -EINVAL;
8924
8925 memcpy(settings->ciphers_pairwise, data, len);
8926
8927 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008928 if (!cfg80211_supported_cipher_suite(
8929 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008930 settings->ciphers_pairwise[i]))
8931 return -EINVAL;
8932 }
8933
8934 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8935 settings->cipher_group =
8936 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008937 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8938 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008939 return -EINVAL;
8940 }
8941
8942 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8943 settings->wpa_versions =
8944 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8945 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8946 return -EINVAL;
8947 }
8948
8949 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8950 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008951 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008952
8953 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8954 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8955 settings->n_akm_suites = len / sizeof(u32);
8956
8957 if (len % sizeof(u32))
8958 return -EINVAL;
8959
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008960 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8961 return -EINVAL;
8962
Samuel Ortizb23aa672009-07-01 21:26:54 +02008963 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008964 }
8965
Eliad Peller91b5ab62017-06-09 13:08:42 +01008966 if (info->attrs[NL80211_ATTR_PMK]) {
8967 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8968 return -EINVAL;
8969 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8970 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8971 return -EINVAL;
8972 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8973 }
8974
Samuel Ortizb23aa672009-07-01 21:26:54 +02008975 return 0;
8976}
8977
Jouni Malinen636a5d32009-03-19 13:39:22 +02008978static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8979{
Johannes Berg4c476992010-10-04 21:36:35 +02008980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8981 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008982 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008983 struct cfg80211_assoc_request req = {};
8984 const u8 *bssid, *ssid;
8985 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008986
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008987 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8988 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8989 return -EPERM;
8990
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008991 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008992 !info->attrs[NL80211_ATTR_SSID] ||
8993 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008994 return -EINVAL;
8995
Johannes Berg4c476992010-10-04 21:36:35 +02008996 if (!rdev->ops->assoc)
8997 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008998
Johannes Berg074ac8d2010-09-16 14:58:22 +02008999 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009000 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9001 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009002
Johannes Berg19957bb2009-07-02 17:20:43 +02009003 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009004
Jouni Malinen664834d2014-01-15 00:01:44 +02009005 chan = nl80211_get_valid_chan(&rdev->wiphy,
9006 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9007 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009008 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009009
Johannes Berg19957bb2009-07-02 17:20:43 +02009010 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9011 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009012
9013 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009014 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9015 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009016 }
9017
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009018 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009019 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009020 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009021 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009022 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009023 else if (mfp != NL80211_MFP_NO)
9024 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009025 }
9026
Johannes Berg3e5d7642009-07-07 14:37:26 +02009027 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009028 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009029
Ben Greear7e7c8922011-11-18 11:31:59 -08009030 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009031 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009032
9033 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009034 memcpy(&req.ht_capa_mask,
9035 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9036 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009037
9038 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009039 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009040 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009041 memcpy(&req.ht_capa,
9042 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9043 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009044 }
9045
Johannes Bergee2aca32013-02-21 17:36:01 +01009046 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009047 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009048
9049 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009050 memcpy(&req.vht_capa_mask,
9051 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9052 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009053
9054 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009055 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009056 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009057 memcpy(&req.vht_capa,
9058 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9059 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009060 }
9061
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009062 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009063 if (!((rdev->wiphy.features &
9064 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9065 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9066 !wiphy_ext_feature_isset(&rdev->wiphy,
9067 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009068 return -EINVAL;
9069 req.flags |= ASSOC_REQ_USE_RRM;
9070 }
9071
Jouni Malinen348bd452016-10-27 00:42:03 +03009072 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9073 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9074 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9075 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9076 return -EINVAL;
9077 req.fils_nonces =
9078 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9079 }
9080
Johannes Bergf62fab72013-02-21 20:09:09 +01009081 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009082 if (!err) {
9083 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009084
Johannes Bergf62fab72013-02-21 20:09:09 +01009085 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9086 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009087
9088 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9089 dev->ieee80211_ptr->conn_owner_nlportid =
9090 info->snd_portid;
9091 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9092 bssid, ETH_ALEN);
9093 }
9094
Johannes Berg91bf9b22013-05-15 17:44:01 +02009095 wdev_unlock(dev->ieee80211_ptr);
9096 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009097
Jouni Malinen636a5d32009-03-19 13:39:22 +02009098 return err;
9099}
9100
9101static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9102{
Johannes Berg4c476992010-10-04 21:36:35 +02009103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9104 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009105 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009106 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009107 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009108 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009109
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009110 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9111 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9112 return -EPERM;
9113
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009114 if (!info->attrs[NL80211_ATTR_MAC])
9115 return -EINVAL;
9116
9117 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9118 return -EINVAL;
9119
Johannes Berg4c476992010-10-04 21:36:35 +02009120 if (!rdev->ops->deauth)
9121 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009122
Johannes Berg074ac8d2010-09-16 14:58:22 +02009123 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009124 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9125 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009126
Johannes Berg19957bb2009-07-02 17:20:43 +02009127 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009128
Johannes Berg19957bb2009-07-02 17:20:43 +02009129 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9130 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009131 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009132 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009133 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009134
9135 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009136 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9137 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009138 }
9139
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009140 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9141
Johannes Berg91bf9b22013-05-15 17:44:01 +02009142 wdev_lock(dev->ieee80211_ptr);
9143 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9144 local_state_change);
9145 wdev_unlock(dev->ieee80211_ptr);
9146 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009147}
9148
9149static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9150{
Johannes Berg4c476992010-10-04 21:36:35 +02009151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9152 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009153 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009154 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009155 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009156 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009157
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009158 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9159 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9160 return -EPERM;
9161
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009162 if (!info->attrs[NL80211_ATTR_MAC])
9163 return -EINVAL;
9164
9165 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9166 return -EINVAL;
9167
Johannes Berg4c476992010-10-04 21:36:35 +02009168 if (!rdev->ops->disassoc)
9169 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009170
Johannes Berg074ac8d2010-09-16 14:58:22 +02009171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9173 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009174
Johannes Berg19957bb2009-07-02 17:20:43 +02009175 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009176
Johannes Berg19957bb2009-07-02 17:20:43 +02009177 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9178 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009179 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009180 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009181 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009182
9183 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009184 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9185 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009186 }
9187
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009188 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9189
Johannes Berg91bf9b22013-05-15 17:44:01 +02009190 wdev_lock(dev->ieee80211_ptr);
9191 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9192 local_state_change);
9193 wdev_unlock(dev->ieee80211_ptr);
9194 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009195}
9196
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009197static bool
9198nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009199 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009200 int rateval)
9201{
9202 struct wiphy *wiphy = &rdev->wiphy;
9203 bool found = false;
9204 int band, i;
9205
Johannes Berg57fbcce2016-04-12 15:56:15 +02009206 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009207 struct ieee80211_supported_band *sband;
9208
9209 sband = wiphy->bands[band];
9210 if (!sband)
9211 continue;
9212
9213 for (i = 0; i < sband->n_bitrates; i++) {
9214 if (sband->bitrates[i].bitrate == rateval) {
9215 mcast_rate[band] = i + 1;
9216 found = true;
9217 break;
9218 }
9219 }
9220 }
9221
9222 return found;
9223}
9224
Johannes Berg04a773a2009-04-19 21:24:32 +02009225static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9226{
Johannes Berg4c476992010-10-04 21:36:35 +02009227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9228 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009229 struct cfg80211_ibss_params ibss;
9230 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009231 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009232 int err;
9233
Johannes Berg8e30bc52009-04-22 17:45:38 +02009234 memset(&ibss, 0, sizeof(ibss));
9235
Johannes Berg683b6d32012-11-08 21:25:48 +01009236 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009237 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9238 return -EINVAL;
9239
Johannes Berg8e30bc52009-04-22 17:45:38 +02009240 ibss.beacon_interval = 100;
9241
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309242 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009243 ibss.beacon_interval =
9244 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309245
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309246 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9247 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309248 if (err)
9249 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009250
Johannes Berg4c476992010-10-04 21:36:35 +02009251 if (!rdev->ops->join_ibss)
9252 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009253
Johannes Berg4c476992010-10-04 21:36:35 +02009254 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9255 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009256
Johannes Berg79c97e92009-07-07 03:56:12 +02009257 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009258
Johannes Berg39193492011-09-16 13:45:25 +02009259 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009260 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009261
9262 if (!is_valid_ether_addr(ibss.bssid))
9263 return -EINVAL;
9264 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009265 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9266 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9267
9268 if (info->attrs[NL80211_ATTR_IE]) {
9269 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9270 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9271 }
9272
Johannes Berg683b6d32012-11-08 21:25:48 +01009273 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9274 if (err)
9275 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009276
Ilan Peer174e0cd2014-02-23 09:13:01 +02009277 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9278 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009279 return -EINVAL;
9280
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009281 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009282 case NL80211_CHAN_WIDTH_5:
9283 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009284 case NL80211_CHAN_WIDTH_20_NOHT:
9285 break;
9286 case NL80211_CHAN_WIDTH_20:
9287 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009288 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9289 return -EINVAL;
9290 break;
9291 case NL80211_CHAN_WIDTH_80:
9292 case NL80211_CHAN_WIDTH_80P80:
9293 case NL80211_CHAN_WIDTH_160:
9294 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9295 return -EINVAL;
9296 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9297 NL80211_EXT_FEATURE_VHT_IBSS))
9298 return -EINVAL;
9299 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009300 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009301 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009302 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009303
Johannes Berg04a773a2009-04-19 21:24:32 +02009304 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009305 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009306
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009307 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9308 u8 *rates =
9309 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9310 int n_rates =
9311 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9312 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009313 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009314
Johannes Berg34850ab2011-07-18 18:08:35 +02009315 err = ieee80211_get_ratemask(sband, rates, n_rates,
9316 &ibss.basic_rates);
9317 if (err)
9318 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009319 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009320
Simon Wunderlich803768f2013-06-28 10:39:58 +02009321 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9322 memcpy(&ibss.ht_capa_mask,
9323 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9324 sizeof(ibss.ht_capa_mask));
9325
9326 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9327 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9328 return -EINVAL;
9329 memcpy(&ibss.ht_capa,
9330 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9331 sizeof(ibss.ht_capa));
9332 }
9333
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009334 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9335 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9336 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9337 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009338
Johannes Berg4c476992010-10-04 21:36:35 +02009339 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309340 bool no_ht = false;
9341
Johannes Berg768075e2017-11-13 15:35:06 +01009342 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009343 if (IS_ERR(connkeys))
9344 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309345
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009346 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9347 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009348 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309349 return -EINVAL;
9350 }
Johannes Berg4c476992010-10-04 21:36:35 +02009351 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009352
Antonio Quartulli267335d2012-01-31 20:25:47 +01009353 ibss.control_port =
9354 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9355
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009356 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9357 int r = validate_pae_over_nl80211(rdev, info);
9358
Johannes Bergd350a0f2018-12-15 11:03:22 +02009359 if (r < 0) {
9360 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009361 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009362 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009363
9364 ibss.control_port_over_nl80211 = true;
9365 }
9366
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009367 ibss.userspace_handles_dfs =
9368 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9369
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009370 wdev_lock(dev->ieee80211_ptr);
9371 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009372 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009373 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009374 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9375 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9376 wdev_unlock(dev->ieee80211_ptr);
9377
Johannes Berg04a773a2009-04-19 21:24:32 +02009378 return err;
9379}
9380
9381static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9382{
Johannes Berg4c476992010-10-04 21:36:35 +02009383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9384 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009385
Johannes Berg4c476992010-10-04 21:36:35 +02009386 if (!rdev->ops->leave_ibss)
9387 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009388
Johannes Berg4c476992010-10-04 21:36:35 +02009389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9390 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009391
Johannes Berg4c476992010-10-04 21:36:35 +02009392 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009393}
9394
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009395static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9396{
9397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9398 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009399 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009400 u32 nla_rate;
9401 int err;
9402
9403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9405 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009406 return -EOPNOTSUPP;
9407
9408 if (!rdev->ops->set_mcast_rate)
9409 return -EOPNOTSUPP;
9410
9411 memset(mcast_rate, 0, sizeof(mcast_rate));
9412
9413 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9414 return -EINVAL;
9415
9416 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9417 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9418 return -EINVAL;
9419
Ilan Peera1056b1b2015-10-22 22:27:46 +03009420 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009421
9422 return err;
9423}
9424
Johannes Bergad7e7182013-11-13 13:37:47 +01009425static struct sk_buff *
9426__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009427 struct wireless_dev *wdev, int approxlen,
9428 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009429 enum nl80211_attrs attr,
9430 const struct nl80211_vendor_cmd_info *info,
9431 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009432{
9433 struct sk_buff *skb;
9434 void *hdr;
9435 struct nlattr *data;
9436
9437 skb = nlmsg_new(approxlen + 100, gfp);
9438 if (!skb)
9439 return NULL;
9440
9441 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9442 if (!hdr) {
9443 kfree_skb(skb);
9444 return NULL;
9445 }
9446
9447 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9448 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009449
9450 if (info) {
9451 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9452 info->vendor_id))
9453 goto nla_put_failure;
9454 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9455 info->subcmd))
9456 goto nla_put_failure;
9457 }
9458
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009459 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009460 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9461 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009462 goto nla_put_failure;
9463 if (wdev->netdev &&
9464 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9465 wdev->netdev->ifindex))
9466 goto nla_put_failure;
9467 }
9468
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009469 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009470 if (!data)
9471 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009472
9473 ((void **)skb->cb)[0] = rdev;
9474 ((void **)skb->cb)[1] = hdr;
9475 ((void **)skb->cb)[2] = data;
9476
9477 return skb;
9478
9479 nla_put_failure:
9480 kfree_skb(skb);
9481 return NULL;
9482}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009483
Johannes Berge03ad6e2014-01-01 17:22:30 +01009484struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009485 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009486 enum nl80211_commands cmd,
9487 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009488 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009489 int vendor_event_idx,
9490 int approxlen, gfp_t gfp)
9491{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009492 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009493 const struct nl80211_vendor_cmd_info *info;
9494
9495 switch (cmd) {
9496 case NL80211_CMD_TESTMODE:
9497 if (WARN_ON(vendor_event_idx != -1))
9498 return NULL;
9499 info = NULL;
9500 break;
9501 case NL80211_CMD_VENDOR:
9502 if (WARN_ON(vendor_event_idx < 0 ||
9503 vendor_event_idx >= wiphy->n_vendor_events))
9504 return NULL;
9505 info = &wiphy->vendor_events[vendor_event_idx];
9506 break;
9507 default:
9508 WARN_ON(1);
9509 return NULL;
9510 }
9511
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009512 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009513 cmd, attr, info, gfp);
9514}
9515EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9516
9517void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9518{
9519 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9520 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009521 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009522 struct nlattr *data = ((void **)skb->cb)[2];
9523 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9524
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009525 /* clear CB data for netlink core to own from now on */
9526 memset(skb->cb, 0, sizeof(skb->cb));
9527
Johannes Berge03ad6e2014-01-01 17:22:30 +01009528 nla_nest_end(skb, data);
9529 genlmsg_end(skb, hdr);
9530
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009531 if (nlhdr->nlmsg_pid) {
9532 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9533 nlhdr->nlmsg_pid);
9534 } else {
9535 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9536 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +01009537
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9539 skb, 0, mcgrp, gfp);
9540 }
Johannes Berge03ad6e2014-01-01 17:22:30 +01009541}
9542EXPORT_SYMBOL(__cfg80211_send_event_skb);
9543
Johannes Bergaff89a92009-07-01 21:26:51 +02009544#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009545static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9546{
Johannes Berg4c476992010-10-04 21:36:35 +02009547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009548 struct wireless_dev *wdev =
9549 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009550 int err;
9551
David Spinadelfc73f112013-07-31 18:04:15 +03009552 if (!rdev->ops->testmode_cmd)
9553 return -EOPNOTSUPP;
9554
9555 if (IS_ERR(wdev)) {
9556 err = PTR_ERR(wdev);
9557 if (err != -EINVAL)
9558 return err;
9559 wdev = NULL;
9560 } else if (wdev->wiphy != &rdev->wiphy) {
9561 return -EINVAL;
9562 }
9563
Johannes Bergaff89a92009-07-01 21:26:51 +02009564 if (!info->attrs[NL80211_ATTR_TESTDATA])
9565 return -EINVAL;
9566
Johannes Bergad7e7182013-11-13 13:37:47 +01009567 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009568 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009569 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9570 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009571 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009572
Johannes Bergaff89a92009-07-01 21:26:51 +02009573 return err;
9574}
9575
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009576static int nl80211_testmode_dump(struct sk_buff *skb,
9577 struct netlink_callback *cb)
9578{
Johannes Berg00918d32011-12-13 17:22:05 +01009579 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009580 int err;
9581 long phy_idx;
9582 void *data = NULL;
9583 int data_len = 0;
9584
Johannes Berg5fe231e2013-05-08 21:45:15 +02009585 rtnl_lock();
9586
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009587 if (cb->args[0]) {
9588 /*
9589 * 0 is a valid index, but not valid for args[0],
9590 * so we need to offset by 1.
9591 */
9592 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009593
9594 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9595 if (!rdev) {
9596 err = -ENOENT;
9597 goto out_err;
9598 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009599 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009600 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9601
Johannes Berg8cb08172019-04-26 14:07:28 +02009602 err = nlmsg_parse_deprecated(cb->nlh,
9603 GENL_HDRLEN + nl80211_fam.hdrsize,
9604 attrbuf, nl80211_fam.maxattr,
9605 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009606 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009607 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009608
Johannes Bergc90c39d2016-10-24 14:40:01 +02009609 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009610 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009611 err = PTR_ERR(rdev);
9612 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009613 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009614 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009615
Johannes Bergc90c39d2016-10-24 14:40:01 +02009616 if (attrbuf[NL80211_ATTR_TESTDATA])
9617 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009618 }
9619
9620 if (cb->args[1]) {
9621 data = nla_data((void *)cb->args[1]);
9622 data_len = nla_len((void *)cb->args[1]);
9623 }
9624
Johannes Berg00918d32011-12-13 17:22:05 +01009625 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009626 err = -EOPNOTSUPP;
9627 goto out_err;
9628 }
9629
9630 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009631 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009632 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9633 NL80211_CMD_TESTMODE);
9634 struct nlattr *tmdata;
9635
Dan Carpentercb35fba2013-08-14 14:50:01 +03009636 if (!hdr)
9637 break;
9638
David S. Miller9360ffd2012-03-29 04:41:26 -04009639 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009640 genlmsg_cancel(skb, hdr);
9641 break;
9642 }
9643
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009644 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009645 if (!tmdata) {
9646 genlmsg_cancel(skb, hdr);
9647 break;
9648 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009649 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009650 nla_nest_end(skb, tmdata);
9651
9652 if (err == -ENOBUFS || err == -ENOENT) {
9653 genlmsg_cancel(skb, hdr);
9654 break;
9655 } else if (err) {
9656 genlmsg_cancel(skb, hdr);
9657 goto out_err;
9658 }
9659
9660 genlmsg_end(skb, hdr);
9661 }
9662
9663 err = skb->len;
9664 /* see above */
9665 cb->args[0] = phy_idx + 1;
9666 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009667 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009668 return err;
9669}
Johannes Bergaff89a92009-07-01 21:26:51 +02009670#endif
9671
Samuel Ortizb23aa672009-07-01 21:26:54 +02009672static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9673{
Johannes Berg4c476992010-10-04 21:36:35 +02009674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9675 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009676 struct cfg80211_connect_params connect;
9677 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009678 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009679 int err;
9680
9681 memset(&connect, 0, sizeof(connect));
9682
Samuel Ortizb23aa672009-07-01 21:26:54 +02009683 if (!info->attrs[NL80211_ATTR_SSID] ||
9684 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9685 return -EINVAL;
9686
9687 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9688 connect.auth_type =
9689 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009690 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9691 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009692 return -EINVAL;
9693 } else
9694 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9695
9696 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9697
Avraham Stern3a00df52017-06-09 13:08:43 +01009698 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9699 !wiphy_ext_feature_isset(&rdev->wiphy,
9700 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9701 return -EINVAL;
9702 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9703
Johannes Bergc0692b82010-08-27 14:26:53 +03009704 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009705 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009706 if (err)
9707 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009708
Johannes Berg074ac8d2010-09-16 14:58:22 +02009709 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009710 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9711 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009712
Johannes Berg79c97e92009-07-07 03:56:12 +02009713 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009714
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309715 connect.bg_scan_period = -1;
9716 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9717 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9718 connect.bg_scan_period =
9719 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9720 }
9721
Samuel Ortizb23aa672009-07-01 21:26:54 +02009722 if (info->attrs[NL80211_ATTR_MAC])
9723 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009724 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9725 connect.bssid_hint =
9726 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009727 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9728 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9729
9730 if (info->attrs[NL80211_ATTR_IE]) {
9731 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9732 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9733 }
9734
Jouni Malinencee00a92013-01-15 17:15:57 +02009735 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9736 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009737 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9738 !wiphy_ext_feature_isset(&rdev->wiphy,
9739 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9740 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009741 } else {
9742 connect.mfp = NL80211_MFP_NO;
9743 }
9744
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009745 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9746 connect.prev_bssid =
9747 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9748
Samuel Ortizb23aa672009-07-01 21:26:54 +02009749 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009750 connect.channel = nl80211_get_valid_chan(
9751 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9752 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009753 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009754 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009755 connect.channel_hint = nl80211_get_valid_chan(
9756 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9757 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009758 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009759 }
9760
Johannes Bergfffd0932009-07-08 14:22:54 +02009761 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009762 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009763 if (IS_ERR(connkeys))
9764 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009765 }
9766
Ben Greear7e7c8922011-11-18 11:31:59 -08009767 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9768 connect.flags |= ASSOC_REQ_DISABLE_HT;
9769
9770 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9771 memcpy(&connect.ht_capa_mask,
9772 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9773 sizeof(connect.ht_capa_mask));
9774
9775 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009776 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009777 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009778 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009779 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009780 memcpy(&connect.ht_capa,
9781 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9782 sizeof(connect.ht_capa));
9783 }
9784
Johannes Bergee2aca32013-02-21 17:36:01 +01009785 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9786 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9787
9788 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9789 memcpy(&connect.vht_capa_mask,
9790 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9791 sizeof(connect.vht_capa_mask));
9792
9793 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9794 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009795 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009796 return -EINVAL;
9797 }
9798 memcpy(&connect.vht_capa,
9799 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9800 sizeof(connect.vht_capa));
9801 }
9802
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009803 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009804 if (!((rdev->wiphy.features &
9805 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9806 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9807 !wiphy_ext_feature_isset(&rdev->wiphy,
9808 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009809 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009810 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009811 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009812 connect.flags |= ASSOC_REQ_USE_RRM;
9813 }
9814
Lior David34d50512016-01-28 10:58:25 +02009815 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009816 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009817 kzfree(connkeys);
9818 return -EOPNOTSUPP;
9819 }
9820
Arend van Spriel38de03d2016-03-02 20:37:18 +01009821 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9822 /* bss selection makes no sense if bssid is set */
9823 if (connect.bssid) {
9824 kzfree(connkeys);
9825 return -EINVAL;
9826 }
9827
9828 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9829 wiphy, &connect.bss_select);
9830 if (err) {
9831 kzfree(connkeys);
9832 return err;
9833 }
9834 }
9835
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009836 if (wiphy_ext_feature_isset(&rdev->wiphy,
9837 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9838 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9839 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9840 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9841 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9842 connect.fils_erp_username =
9843 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9844 connect.fils_erp_username_len =
9845 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9846 connect.fils_erp_realm =
9847 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9848 connect.fils_erp_realm_len =
9849 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9850 connect.fils_erp_next_seq_num =
9851 nla_get_u16(
9852 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9853 connect.fils_erp_rrk =
9854 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9855 connect.fils_erp_rrk_len =
9856 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9857 } else if (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 kzfree(connkeys);
9862 return -EINVAL;
9863 }
9864
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009865 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9866 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309867 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009868 GENL_SET_ERR_MSG(info,
9869 "external auth requires connection ownership");
9870 return -EINVAL;
9871 }
9872 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9873 }
9874
Johannes Berg83739b02013-05-15 17:44:01 +02009875 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009876
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009877 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9878 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009879 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009880 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009881
9882 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9883 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9884 if (connect.bssid)
9885 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9886 connect.bssid, ETH_ALEN);
9887 else
9888 memset(dev->ieee80211_ptr->disconnect_bssid,
9889 0, ETH_ALEN);
9890 }
9891
9892 wdev_unlock(dev->ieee80211_ptr);
9893
Samuel Ortizb23aa672009-07-01 21:26:54 +02009894 return err;
9895}
9896
vamsi krishna088e8df2016-10-27 16:51:11 +03009897static int nl80211_update_connect_params(struct sk_buff *skb,
9898 struct genl_info *info)
9899{
9900 struct cfg80211_connect_params connect = {};
9901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9902 struct net_device *dev = info->user_ptr[1];
9903 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009904 bool fils_sk_offload;
9905 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +03009906 u32 changed = 0;
9907 int ret;
9908
9909 if (!rdev->ops->update_connect_params)
9910 return -EOPNOTSUPP;
9911
9912 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +03009913 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9914 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9915 changed |= UPDATE_ASSOC_IES;
9916 }
9917
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009918 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
9919 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
9920
9921 /*
9922 * when driver supports fils-sk offload all attributes must be
9923 * provided. So the else covers "fils-sk-not-all" and
9924 * "no-fils-sk-any".
9925 */
9926 if (fils_sk_offload &&
9927 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9928 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9929 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9930 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9931 connect.fils_erp_username =
9932 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9933 connect.fils_erp_username_len =
9934 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9935 connect.fils_erp_realm =
9936 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9937 connect.fils_erp_realm_len =
9938 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9939 connect.fils_erp_next_seq_num =
9940 nla_get_u16(
9941 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9942 connect.fils_erp_rrk =
9943 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9944 connect.fils_erp_rrk_len =
9945 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9946 changed |= UPDATE_FILS_ERP_INFO;
9947 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9948 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9949 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9950 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9951 return -EINVAL;
9952 }
9953
9954 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9955 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9956 if (!nl80211_valid_auth_type(rdev, auth_type,
9957 NL80211_CMD_CONNECT))
9958 return -EINVAL;
9959
9960 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
9961 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
9962 return -EINVAL;
9963
9964 connect.auth_type = auth_type;
9965 changed |= UPDATE_AUTH_TYPE;
9966 }
9967
vamsi krishna088e8df2016-10-27 16:51:11 +03009968 wdev_lock(dev->ieee80211_ptr);
9969 if (!wdev->current_bss)
9970 ret = -ENOLINK;
9971 else
9972 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9973 wdev_unlock(dev->ieee80211_ptr);
9974
9975 return ret;
9976}
9977
Samuel Ortizb23aa672009-07-01 21:26:54 +02009978static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9979{
Johannes Berg4c476992010-10-04 21:36:35 +02009980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9981 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009982 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009983 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009984
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009985 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9986 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9987 return -EPERM;
9988
Samuel Ortizb23aa672009-07-01 21:26:54 +02009989 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9990 reason = WLAN_REASON_DEAUTH_LEAVING;
9991 else
9992 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9993
9994 if (reason == 0)
9995 return -EINVAL;
9996
Johannes Berg074ac8d2010-09-16 14:58:22 +02009997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9999 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010000
Johannes Berg83739b02013-05-15 17:44:01 +020010001 wdev_lock(dev->ieee80211_ptr);
10002 ret = cfg80211_disconnect(rdev, dev, reason, true);
10003 wdev_unlock(dev->ieee80211_ptr);
10004 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010005}
10006
Johannes Berg463d0182009-07-14 00:33:35 +020010007static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10008{
Johannes Berg4c476992010-10-04 21:36:35 +020010009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010010 struct net *net;
10011 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010012
Vadim Kochan4b681c82015-01-12 16:34:05 +020010013 if (info->attrs[NL80211_ATTR_PID]) {
10014 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10015
10016 net = get_net_ns_by_pid(pid);
10017 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10018 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10019
10020 net = get_net_ns_by_fd(fd);
10021 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010022 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010023 }
Johannes Berg463d0182009-07-14 00:33:35 +020010024
Johannes Berg4c476992010-10-04 21:36:35 +020010025 if (IS_ERR(net))
10026 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010027
10028 err = 0;
10029
10030 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010031 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10032 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010033
Johannes Berg463d0182009-07-14 00:33:35 +020010034 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010035 return err;
10036}
10037
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010038static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10039{
Johannes Berg4c476992010-10-04 21:36:35 +020010040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010041 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10042 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010043 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010044 struct cfg80211_pmksa pmksa;
10045
10046 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10047
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010048 if (!info->attrs[NL80211_ATTR_PMKID])
10049 return -EINVAL;
10050
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010051 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010052
10053 if (info->attrs[NL80211_ATTR_MAC]) {
10054 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10055 } else if (info->attrs[NL80211_ATTR_SSID] &&
10056 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10057 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10058 info->attrs[NL80211_ATTR_PMK])) {
10059 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10060 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10061 pmksa.cache_id =
10062 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10063 } else {
10064 return -EINVAL;
10065 }
10066 if (info->attrs[NL80211_ATTR_PMK]) {
10067 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10068 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10069 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010070
Johannes Berg074ac8d2010-09-16 14:58:22 +020010071 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010072 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10073 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10074 wiphy_ext_feature_isset(&rdev->wiphy,
10075 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010076 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010077
10078 switch (info->genlhdr->cmd) {
10079 case NL80211_CMD_SET_PMKSA:
10080 rdev_ops = rdev->ops->set_pmksa;
10081 break;
10082 case NL80211_CMD_DEL_PMKSA:
10083 rdev_ops = rdev->ops->del_pmksa;
10084 break;
10085 default:
10086 WARN_ON(1);
10087 break;
10088 }
10089
Johannes Berg4c476992010-10-04 21:36:35 +020010090 if (!rdev_ops)
10091 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010092
Johannes Berg4c476992010-10-04 21:36:35 +020010093 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010094}
10095
10096static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10097{
Johannes Berg4c476992010-10-04 21:36:35 +020010098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10099 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010100
Johannes Berg074ac8d2010-09-16 14:58:22 +020010101 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10103 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010104
Johannes Berg4c476992010-10-04 21:36:35 +020010105 if (!rdev->ops->flush_pmksa)
10106 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010107
Hila Gonene35e4d22012-06-27 17:19:42 +030010108 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010109}
10110
Arik Nemtsov109086c2011-09-28 14:12:50 +030010111static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10112{
10113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10114 struct net_device *dev = info->user_ptr[1];
10115 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010116 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010117 u16 status_code;
10118 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010119 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010120
10121 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10122 !rdev->ops->tdls_mgmt)
10123 return -EOPNOTSUPP;
10124
10125 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10126 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10127 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10128 !info->attrs[NL80211_ATTR_IE] ||
10129 !info->attrs[NL80211_ATTR_MAC])
10130 return -EINVAL;
10131
10132 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10133 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10134 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10135 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010136 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010137 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10138 peer_capability =
10139 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010140
Hila Gonene35e4d22012-06-27 17:19:42 +030010141 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010142 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010143 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010144 nla_data(info->attrs[NL80211_ATTR_IE]),
10145 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010146}
10147
10148static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10149{
10150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10151 struct net_device *dev = info->user_ptr[1];
10152 enum nl80211_tdls_operation operation;
10153 u8 *peer;
10154
10155 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10156 !rdev->ops->tdls_oper)
10157 return -EOPNOTSUPP;
10158
10159 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10160 !info->attrs[NL80211_ATTR_MAC])
10161 return -EINVAL;
10162
10163 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10164 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10165
Hila Gonene35e4d22012-06-27 17:19:42 +030010166 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010167}
10168
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010169static int nl80211_remain_on_channel(struct sk_buff *skb,
10170 struct genl_info *info)
10171{
Johannes Berg4c476992010-10-04 21:36:35 +020010172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010173 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010174 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010175 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010176 struct sk_buff *msg;
10177 void *hdr;
10178 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010179 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010180 int err;
10181
10182 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10183 !info->attrs[NL80211_ATTR_DURATION])
10184 return -EINVAL;
10185
10186 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10187
Johannes Berg7c4ef712011-11-18 15:33:48 +010010188 if (!rdev->ops->remain_on_channel ||
10189 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010190 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010191
Johannes Bergebf348f2012-06-01 12:50:54 +020010192 /*
10193 * We should be on that channel for at least a minimum amount of
10194 * time (10ms) but no longer than the driver supports.
10195 */
10196 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10197 duration > rdev->wiphy.max_remain_on_channel_duration)
10198 return -EINVAL;
10199
Johannes Berg683b6d32012-11-08 21:25:48 +010010200 err = nl80211_parse_chandef(rdev, info, &chandef);
10201 if (err)
10202 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010203
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010204 wdev_lock(wdev);
10205 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10206 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10207 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10208 &chandef);
10209 if (compat_chandef != &chandef) {
10210 wdev_unlock(wdev);
10211 return -EBUSY;
10212 }
10213 }
10214 wdev_unlock(wdev);
10215
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010217 if (!msg)
10218 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010219
Eric W. Biederman15e47302012-09-07 20:12:54 +000010220 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010221 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010222 if (!hdr) {
10223 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010224 goto free_msg;
10225 }
10226
Johannes Berg683b6d32012-11-08 21:25:48 +010010227 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10228 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010229
10230 if (err)
10231 goto free_msg;
10232
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010233 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10234 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010235 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010236
10237 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010238
10239 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010240
10241 nla_put_failure:
10242 err = -ENOBUFS;
10243 free_msg:
10244 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010245 return err;
10246}
10247
10248static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10249 struct genl_info *info)
10250{
Johannes Berg4c476992010-10-04 21:36:35 +020010251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010252 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010253 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010254
10255 if (!info->attrs[NL80211_ATTR_COOKIE])
10256 return -EINVAL;
10257
Johannes Berg4c476992010-10-04 21:36:35 +020010258 if (!rdev->ops->cancel_remain_on_channel)
10259 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010260
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010261 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10262
Hila Gonene35e4d22012-06-27 17:19:42 +030010263 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010264}
10265
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010266static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10267 struct genl_info *info)
10268{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010269 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010271 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010272 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010273
Johannes Berg4c476992010-10-04 21:36:35 +020010274 if (!rdev->ops->set_bitrate_mask)
10275 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010276
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010277 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10278 if (err)
10279 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010280
Hila Gonene35e4d22012-06-27 17:19:42 +030010281 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010282}
10283
Johannes Berg2e161f782010-08-12 15:38:38 +020010284static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010285{
Johannes Berg4c476992010-10-04 21:36:35 +020010286 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010287 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010288 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010289
10290 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10291 return -EINVAL;
10292
Johannes Berg2e161f782010-08-12 15:38:38 +020010293 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10294 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010295
Johannes Berg71bbc992012-06-15 15:30:18 +020010296 switch (wdev->iftype) {
10297 case NL80211_IFTYPE_STATION:
10298 case NL80211_IFTYPE_ADHOC:
10299 case NL80211_IFTYPE_P2P_CLIENT:
10300 case NL80211_IFTYPE_AP:
10301 case NL80211_IFTYPE_AP_VLAN:
10302 case NL80211_IFTYPE_MESH_POINT:
10303 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010304 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010305 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010306 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010307 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010308 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010309 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010310
10311 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010312 if (!rdev->ops->mgmt_tx)
10313 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010314
Eric W. Biederman15e47302012-09-07 20:12:54 +000010315 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010316 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10317 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010318}
10319
Johannes Berg2e161f782010-08-12 15:38:38 +020010320static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010321{
Johannes Berg4c476992010-10-04 21:36:35 +020010322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010323 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010324 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010325 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010326 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010327 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010328 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010329 struct cfg80211_mgmt_tx_params params = {
10330 .dont_wait_for_ack =
10331 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10332 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010333
Johannes Berg683b6d32012-11-08 21:25:48 +010010334 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010335 return -EINVAL;
10336
Johannes Berg4c476992010-10-04 21:36:35 +020010337 if (!rdev->ops->mgmt_tx)
10338 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010339
Johannes Berg71bbc992012-06-15 15:30:18 +020010340 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010341 case NL80211_IFTYPE_P2P_DEVICE:
10342 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10343 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010344 case NL80211_IFTYPE_STATION:
10345 case NL80211_IFTYPE_ADHOC:
10346 case NL80211_IFTYPE_P2P_CLIENT:
10347 case NL80211_IFTYPE_AP:
10348 case NL80211_IFTYPE_AP_VLAN:
10349 case NL80211_IFTYPE_MESH_POINT:
10350 case NL80211_IFTYPE_P2P_GO:
10351 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010352 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010353 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010354 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010355 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010356
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010357 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010358 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010359 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010360 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010361
10362 /*
10363 * We should wait on the channel for at least a minimum amount
10364 * of time (10ms) but no longer than the driver supports.
10365 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010366 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10367 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010368 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010369 }
10370
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010371 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010372
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010373 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010374 return -EINVAL;
10375
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010376 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010377
Antonio Quartulliea141b752013-06-11 14:20:03 +020010378 /* get the channel if any has been specified, otherwise pass NULL to
10379 * the driver. The latter will use the current one
10380 */
10381 chandef.chan = NULL;
10382 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10383 err = nl80211_parse_chandef(rdev, info, &chandef);
10384 if (err)
10385 return err;
10386 }
10387
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010388 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010389 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010390
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010391 wdev_lock(wdev);
10392 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10393 wdev_unlock(wdev);
10394 return -EBUSY;
10395 }
10396 wdev_unlock(wdev);
10397
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010398 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10399 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10400
10401 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10402 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10403 int i;
10404
10405 if (len % sizeof(u16))
10406 return -EINVAL;
10407
10408 params.n_csa_offsets = len / sizeof(u16);
10409 params.csa_offsets =
10410 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10411
10412 /* check that all the offsets fit the frame */
10413 for (i = 0; i < params.n_csa_offsets; i++) {
10414 if (params.csa_offsets[i] >= params.len)
10415 return -EINVAL;
10416 }
10417 }
10418
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010419 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10421 if (!msg)
10422 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010423
Eric W. Biederman15e47302012-09-07 20:12:54 +000010424 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010425 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010426 if (!hdr) {
10427 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010428 goto free_msg;
10429 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010430 }
Johannes Berge247bd902011-11-04 11:18:21 +010010431
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010432 params.chan = chandef.chan;
10433 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010434 if (err)
10435 goto free_msg;
10436
Johannes Berge247bd902011-11-04 11:18:21 +010010437 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010438 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10439 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010440 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010441
Johannes Berge247bd902011-11-04 11:18:21 +010010442 genlmsg_end(msg, hdr);
10443 return genlmsg_reply(msg, info);
10444 }
10445
10446 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010447
10448 nla_put_failure:
10449 err = -ENOBUFS;
10450 free_msg:
10451 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010452 return err;
10453}
10454
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010455static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10456{
10457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010458 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010459 u64 cookie;
10460
10461 if (!info->attrs[NL80211_ATTR_COOKIE])
10462 return -EINVAL;
10463
10464 if (!rdev->ops->mgmt_tx_cancel_wait)
10465 return -EOPNOTSUPP;
10466
Johannes Berg71bbc992012-06-15 15:30:18 +020010467 switch (wdev->iftype) {
10468 case NL80211_IFTYPE_STATION:
10469 case NL80211_IFTYPE_ADHOC:
10470 case NL80211_IFTYPE_P2P_CLIENT:
10471 case NL80211_IFTYPE_AP:
10472 case NL80211_IFTYPE_AP_VLAN:
10473 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010474 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010475 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010476 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010477 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010478 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010479 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010480
10481 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10482
Hila Gonene35e4d22012-06-27 17:19:42 +030010483 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010484}
10485
Kalle Valoffb9eb32010-02-17 17:58:10 +020010486static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10487{
Johannes Berg4c476992010-10-04 21:36:35 +020010488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010489 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010490 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010491 u8 ps_state;
10492 bool state;
10493 int err;
10494
Johannes Berg4c476992010-10-04 21:36:35 +020010495 if (!info->attrs[NL80211_ATTR_PS_STATE])
10496 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010497
10498 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10499
Kalle Valoffb9eb32010-02-17 17:58:10 +020010500 wdev = dev->ieee80211_ptr;
10501
Johannes Berg4c476992010-10-04 21:36:35 +020010502 if (!rdev->ops->set_power_mgmt)
10503 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010504
10505 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10506
10507 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010508 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010509
Hila Gonene35e4d22012-06-27 17:19:42 +030010510 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010511 if (!err)
10512 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010513 return err;
10514}
10515
10516static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10517{
Johannes Berg4c476992010-10-04 21:36:35 +020010518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010519 enum nl80211_ps_state ps_state;
10520 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010521 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010522 struct sk_buff *msg;
10523 void *hdr;
10524 int err;
10525
Kalle Valoffb9eb32010-02-17 17:58:10 +020010526 wdev = dev->ieee80211_ptr;
10527
Johannes Berg4c476992010-10-04 21:36:35 +020010528 if (!rdev->ops->set_power_mgmt)
10529 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010530
10531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010532 if (!msg)
10533 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010534
Eric W. Biederman15e47302012-09-07 20:12:54 +000010535 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010536 NL80211_CMD_GET_POWER_SAVE);
10537 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010538 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010539 goto free_msg;
10540 }
10541
10542 if (wdev->ps)
10543 ps_state = NL80211_PS_ENABLED;
10544 else
10545 ps_state = NL80211_PS_DISABLED;
10546
David S. Miller9360ffd2012-03-29 04:41:26 -040010547 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10548 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010549
10550 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010551 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010552
Johannes Berg4c476992010-10-04 21:36:35 +020010553 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010554 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010555 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010556 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010557 return err;
10558}
10559
Johannes Berg94e860f2014-01-20 23:58:15 +010010560static const struct nla_policy
10561nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010562 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010563 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10564 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010565 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10566 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10567 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010568 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010569};
10570
Thomas Pedersen84f10702012-07-12 16:17:33 -070010571static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010572 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010573{
10574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010575 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010576 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010577
Johannes Bergd9d8b012012-11-26 12:51:52 +010010578 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010579 return -EINVAL;
10580
Thomas Pedersen84f10702012-07-12 16:17:33 -070010581 if (!rdev->ops->set_cqm_txe_config)
10582 return -EOPNOTSUPP;
10583
10584 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10585 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10586 return -EOPNOTSUPP;
10587
Hila Gonene35e4d22012-06-27 17:19:42 +030010588 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010589}
10590
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010591static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10592 struct net_device *dev)
10593{
10594 struct wireless_dev *wdev = dev->ieee80211_ptr;
10595 s32 last, low, high;
10596 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010597 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010598 int err;
10599
10600 /* RSSI reporting disabled? */
10601 if (!wdev->cqm_config)
10602 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10603
10604 /*
10605 * Obtain current RSSI value if possible, if not and no RSSI threshold
10606 * event has been received yet, we should receive an event after a
10607 * connection is established and enough beacons received to calculate
10608 * the average.
10609 */
10610 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10611 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010612 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010613 u8 *mac_addr;
10614
10615 mac_addr = wdev->current_bss->pub.bssid;
10616
Johannes Berg73887fd2018-05-18 09:57:55 +020010617 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10618 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010619 return err;
10620
Omer Efrat397c6572018-06-17 13:06:14 +030010621 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010622 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010623 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010624 }
10625
10626 last = wdev->cqm_config->last_rssi_event_value;
10627 hyst = wdev->cqm_config->rssi_hyst;
10628 n = wdev->cqm_config->n_rssi_thresholds;
10629
10630 for (i = 0; i < n; i++)
10631 if (last < wdev->cqm_config->rssi_thresholds[i])
10632 break;
10633
Masashi Honma1222a162018-09-25 11:15:01 +090010634 low_index = i - 1;
10635 if (low_index >= 0) {
10636 low_index = array_index_nospec(low_index, n);
10637 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10638 } else {
10639 low = S32_MIN;
10640 }
10641 if (i < n) {
10642 i = array_index_nospec(i, n);
10643 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10644 } else {
10645 high = S32_MAX;
10646 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010647
10648 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10649}
10650
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010651static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010652 const s32 *thresholds, int n_thresholds,
10653 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010654{
Johannes Berg4c476992010-10-04 21:36:35 +020010655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010656 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010657 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010658 int i, err;
10659 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010660
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010661 /* Check all values negative and sorted */
10662 for (i = 0; i < n_thresholds; i++) {
10663 if (thresholds[i] > 0 || thresholds[i] <= prev)
10664 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010665
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010666 prev = thresholds[i];
10667 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010668
Johannes Berg074ac8d2010-09-16 14:58:22 +020010669 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010670 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10671 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010672
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010673 wdev_lock(wdev);
10674 cfg80211_cqm_config_free(wdev);
10675 wdev_unlock(wdev);
10676
10677 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10678 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10679 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10680
10681 return rdev_set_cqm_rssi_config(rdev, dev,
10682 thresholds[0], hysteresis);
10683 }
10684
10685 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10686 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10687 return -EOPNOTSUPP;
10688
10689 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10690 n_thresholds = 0;
10691
10692 wdev_lock(wdev);
10693 if (n_thresholds) {
10694 struct cfg80211_cqm_config *cqm_config;
10695
10696 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10697 n_thresholds * sizeof(s32), GFP_KERNEL);
10698 if (!cqm_config) {
10699 err = -ENOMEM;
10700 goto unlock;
10701 }
10702
10703 cqm_config->rssi_hyst = hysteresis;
10704 cqm_config->n_rssi_thresholds = n_thresholds;
10705 memcpy(cqm_config->rssi_thresholds, thresholds,
10706 n_thresholds * sizeof(s32));
10707
10708 wdev->cqm_config = cqm_config;
10709 }
10710
10711 err = cfg80211_cqm_rssi_update(rdev, dev);
10712
10713unlock:
10714 wdev_unlock(wdev);
10715
10716 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010717}
10718
10719static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10720{
10721 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10722 struct nlattr *cqm;
10723 int err;
10724
10725 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010726 if (!cqm)
10727 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010728
Johannes Berg8cb08172019-04-26 14:07:28 +020010729 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10730 nl80211_attr_cqm_policy,
10731 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010732 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010733 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010734
10735 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10736 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010737 const s32 *thresholds =
10738 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10739 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010740 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010741
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010742 if (len % 4)
10743 return -EINVAL;
10744
10745 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10746 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010747 }
10748
10749 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10750 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10751 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10752 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10753 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10754 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10755
10756 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10757 }
10758
10759 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010760}
10761
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010762static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10763{
10764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10765 struct net_device *dev = info->user_ptr[1];
10766 struct ocb_setup setup = {};
10767 int err;
10768
10769 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10770 if (err)
10771 return err;
10772
10773 return cfg80211_join_ocb(rdev, dev, &setup);
10774}
10775
10776static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10777{
10778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10779 struct net_device *dev = info->user_ptr[1];
10780
10781 return cfg80211_leave_ocb(rdev, dev);
10782}
10783
Johannes Berg29cbe682010-12-03 09:20:44 +010010784static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10785{
10786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10787 struct net_device *dev = info->user_ptr[1];
10788 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010789 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010790 int err;
10791
10792 /* start with default */
10793 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010794 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010795
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010796 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010797 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010798 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010799 if (err)
10800 return err;
10801 }
10802
10803 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10804 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10805 return -EINVAL;
10806
Javier Cardonac80d5452010-12-16 17:37:49 -080010807 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10808 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10809
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010810 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10811 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10812 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10813 return -EINVAL;
10814
Marco Porsch9bdbf042013-01-07 16:04:51 +010010815 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10816 setup.beacon_interval =
10817 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010818
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010819 err = cfg80211_validate_beacon_int(rdev,
10820 NL80211_IFTYPE_MESH_POINT,
10821 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010822 if (err)
10823 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010824 }
10825
10826 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10827 setup.dtim_period =
10828 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10829 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10830 return -EINVAL;
10831 }
10832
Javier Cardonac80d5452010-12-16 17:37:49 -080010833 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10834 /* parse additional setup parameters if given */
10835 err = nl80211_parse_mesh_setup(info, &setup);
10836 if (err)
10837 return err;
10838 }
10839
Thomas Pedersend37bb182013-03-04 13:06:13 -080010840 if (setup.user_mpm)
10841 cfg.auto_open_plinks = false;
10842
Johannes Bergcc1d2802012-05-16 23:50:20 +020010843 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010844 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10845 if (err)
10846 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010847 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010848 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010849 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010850 }
10851
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010852 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10853 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10854 int n_rates =
10855 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10856 struct ieee80211_supported_band *sband;
10857
10858 if (!setup.chandef.chan)
10859 return -EINVAL;
10860
10861 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10862
10863 err = ieee80211_get_ratemask(sband, rates, n_rates,
10864 &setup.basic_rates);
10865 if (err)
10866 return err;
10867 }
10868
Johannes Berg8564e382016-09-19 09:44:44 +020010869 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10870 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10871 if (err)
10872 return err;
10873
Johannes Berg265698d2017-09-18 22:46:36 +020010874 if (!setup.chandef.chan)
10875 return -EINVAL;
10876
Johannes Berg8564e382016-09-19 09:44:44 +020010877 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10878 &setup.beacon_rate);
10879 if (err)
10880 return err;
10881 }
10882
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010883 setup.userspace_handles_dfs =
10884 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10885
Denis Kenzior1224f582018-03-26 12:52:49 -050010886 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10887 int r = validate_pae_over_nl80211(rdev, info);
10888
10889 if (r < 0)
10890 return r;
10891
10892 setup.control_port_over_nl80211 = true;
10893 }
10894
Denis Kenzior188c1b32018-03-26 12:52:46 -050010895 wdev_lock(dev->ieee80211_ptr);
10896 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10897 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10898 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10899 wdev_unlock(dev->ieee80211_ptr);
10900
10901 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010902}
10903
10904static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10905{
10906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10907 struct net_device *dev = info->user_ptr[1];
10908
10909 return cfg80211_leave_mesh(rdev, dev);
10910}
10911
Johannes Bergdfb89c52012-06-27 09:23:48 +020010912#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010913static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10914 struct cfg80211_registered_device *rdev)
10915{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010916 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010917 struct nlattr *nl_pats, *nl_pat;
10918 int i, pat_len;
10919
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010920 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010921 return 0;
10922
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010923 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010924 if (!nl_pats)
10925 return -ENOBUFS;
10926
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010927 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010928 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010929 if (!nl_pat)
10930 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010931 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010932 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010933 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010934 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10935 wowlan->patterns[i].pattern) ||
10936 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010937 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010938 return -ENOBUFS;
10939 nla_nest_end(msg, nl_pat);
10940 }
10941 nla_nest_end(msg, nl_pats);
10942
10943 return 0;
10944}
10945
Johannes Berg2a0e0472013-01-23 22:57:40 +010010946static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10947 struct cfg80211_wowlan_tcp *tcp)
10948{
10949 struct nlattr *nl_tcp;
10950
10951 if (!tcp)
10952 return 0;
10953
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010954 nl_tcp = nla_nest_start_noflag(msg,
10955 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010956 if (!nl_tcp)
10957 return -ENOBUFS;
10958
Jiri Benc930345e2015-03-29 16:59:25 +020010959 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10960 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010961 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10962 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10963 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10964 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10965 tcp->payload_len, tcp->payload) ||
10966 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10967 tcp->data_interval) ||
10968 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10969 tcp->wake_len, tcp->wake_data) ||
10970 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10971 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10972 return -ENOBUFS;
10973
10974 if (tcp->payload_seq.len &&
10975 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10976 sizeof(tcp->payload_seq), &tcp->payload_seq))
10977 return -ENOBUFS;
10978
10979 if (tcp->payload_tok.len &&
10980 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10981 sizeof(tcp->payload_tok) + tcp->tokens_size,
10982 &tcp->payload_tok))
10983 return -ENOBUFS;
10984
Johannes Berge248ad32013-05-16 10:24:28 +020010985 nla_nest_end(msg, nl_tcp);
10986
Johannes Berg2a0e0472013-01-23 22:57:40 +010010987 return 0;
10988}
10989
Luciano Coelho75453cc2015-01-09 14:06:37 +020010990static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10991 struct cfg80211_sched_scan_request *req)
10992{
Avraham Stern3b06d272015-10-12 09:51:34 +030010993 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010994 int i;
10995
10996 if (!req)
10997 return 0;
10998
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010999 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011000 if (!nd)
11001 return -ENOBUFS;
11002
Avraham Stern3b06d272015-10-12 09:51:34 +030011003 if (req->n_scan_plans == 1 &&
11004 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11005 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011006 return -ENOBUFS;
11007
Luciano Coelho21fea562015-03-17 16:36:01 +020011008 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11009 return -ENOBUFS;
11010
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011011 if (req->relative_rssi_set) {
11012 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11013
11014 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11015 req->relative_rssi))
11016 return -ENOBUFS;
11017
11018 rssi_adjust.band = req->rssi_adjust.band;
11019 rssi_adjust.delta = req->rssi_adjust.delta;
11020 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11021 sizeof(rssi_adjust), &rssi_adjust))
11022 return -ENOBUFS;
11023 }
11024
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011025 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011026 if (!freqs)
11027 return -ENOBUFS;
11028
Johannes Berg53b18982016-09-14 09:59:21 +020011029 for (i = 0; i < req->n_channels; i++) {
11030 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11031 return -ENOBUFS;
11032 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011033
11034 nla_nest_end(msg, freqs);
11035
11036 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011037 matches = nla_nest_start_noflag(msg,
11038 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011039 if (!matches)
11040 return -ENOBUFS;
11041
Luciano Coelho75453cc2015-01-09 14:06:37 +020011042 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011043 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011044 if (!match)
11045 return -ENOBUFS;
11046
Johannes Berg53b18982016-09-14 09:59:21 +020011047 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11048 req->match_sets[i].ssid.ssid_len,
11049 req->match_sets[i].ssid.ssid))
11050 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011051 nla_nest_end(msg, match);
11052 }
11053 nla_nest_end(msg, matches);
11054 }
11055
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011056 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011057 if (!scan_plans)
11058 return -ENOBUFS;
11059
11060 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011061 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011062 if (!scan_plan)
11063 return -ENOBUFS;
11064
Colin Ian King67626962018-09-06 10:58:44 +010011065 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011066 req->scan_plans[i].interval) ||
11067 (req->scan_plans[i].iterations &&
11068 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11069 req->scan_plans[i].iterations)))
11070 return -ENOBUFS;
11071 nla_nest_end(msg, scan_plan);
11072 }
11073 nla_nest_end(msg, scan_plans);
11074
Luciano Coelho75453cc2015-01-09 14:06:37 +020011075 nla_nest_end(msg, nd);
11076
11077 return 0;
11078}
11079
Johannes Bergff1b6e62011-05-04 15:37:28 +020011080static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11081{
11082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11083 struct sk_buff *msg;
11084 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011085 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011086
Johannes Berg964dc9e2013-06-03 17:25:34 +020011087 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011088 return -EOPNOTSUPP;
11089
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011090 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011091 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011092 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11093 rdev->wiphy.wowlan_config->tcp->payload_len +
11094 rdev->wiphy.wowlan_config->tcp->wake_len +
11095 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011096 }
11097
11098 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011099 if (!msg)
11100 return -ENOMEM;
11101
Eric W. Biederman15e47302012-09-07 20:12:54 +000011102 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011103 NL80211_CMD_GET_WOWLAN);
11104 if (!hdr)
11105 goto nla_put_failure;
11106
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011107 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011108 struct nlattr *nl_wowlan;
11109
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011110 nl_wowlan = nla_nest_start_noflag(msg,
11111 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011112 if (!nl_wowlan)
11113 goto nla_put_failure;
11114
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011115 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011116 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011117 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011118 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011119 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011120 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011121 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011122 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011123 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011124 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011125 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011126 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011127 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011128 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11129 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011130
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011131 if (nl80211_send_wowlan_patterns(msg, rdev))
11132 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011133
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011134 if (nl80211_send_wowlan_tcp(msg,
11135 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011136 goto nla_put_failure;
11137
Luciano Coelho75453cc2015-01-09 14:06:37 +020011138 if (nl80211_send_wowlan_nd(
11139 msg,
11140 rdev->wiphy.wowlan_config->nd_config))
11141 goto nla_put_failure;
11142
Johannes Bergff1b6e62011-05-04 15:37:28 +020011143 nla_nest_end(msg, nl_wowlan);
11144 }
11145
11146 genlmsg_end(msg, hdr);
11147 return genlmsg_reply(msg, info);
11148
11149nla_put_failure:
11150 nlmsg_free(msg);
11151 return -ENOBUFS;
11152}
11153
Johannes Berg2a0e0472013-01-23 22:57:40 +010011154static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11155 struct nlattr *attr,
11156 struct cfg80211_wowlan *trig)
11157{
11158 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11159 struct cfg80211_wowlan_tcp *cfg;
11160 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11161 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11162 u32 size;
11163 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11164 int err, port;
11165
Johannes Berg964dc9e2013-06-03 17:25:34 +020011166 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011167 return -EINVAL;
11168
Johannes Berg8cb08172019-04-26 14:07:28 +020011169 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11170 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011171 if (err)
11172 return err;
11173
11174 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11175 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11176 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11177 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11178 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11179 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11180 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11181 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11182 return -EINVAL;
11183
11184 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011185 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011186 return -EINVAL;
11187
11188 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011189 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011190 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011191 return -EINVAL;
11192
11193 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011194 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011195 return -EINVAL;
11196
11197 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11198 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11199 return -EINVAL;
11200
11201 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11202 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11203
11204 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11205 tokens_size = tokln - sizeof(*tok);
11206
11207 if (!tok->len || tokens_size % tok->len)
11208 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011209 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011210 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011211 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011212 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011213 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011214 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011215 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011216 return -EINVAL;
11217 if (tok->offset + tok->len > data_size)
11218 return -EINVAL;
11219 }
11220
11221 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11222 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011223 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011224 return -EINVAL;
11225 if (seq->len == 0 || seq->len > 4)
11226 return -EINVAL;
11227 if (seq->len + seq->offset > data_size)
11228 return -EINVAL;
11229 }
11230
11231 size = sizeof(*cfg);
11232 size += data_size;
11233 size += wake_size + wake_mask_size;
11234 size += tokens_size;
11235
11236 cfg = kzalloc(size, GFP_KERNEL);
11237 if (!cfg)
11238 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011239 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11240 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011241 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11242 ETH_ALEN);
11243 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11244 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11245 else
11246 port = 0;
11247#ifdef CONFIG_INET
11248 /* allocate a socket and port for it and use it */
11249 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11250 IPPROTO_TCP, &cfg->sock, 1);
11251 if (err) {
11252 kfree(cfg);
11253 return err;
11254 }
11255 if (inet_csk_get_port(cfg->sock->sk, port)) {
11256 sock_release(cfg->sock);
11257 kfree(cfg);
11258 return -EADDRINUSE;
11259 }
11260 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11261#else
11262 if (!port) {
11263 kfree(cfg);
11264 return -EINVAL;
11265 }
11266 cfg->src_port = port;
11267#endif
11268
11269 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11270 cfg->payload_len = data_size;
11271 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11272 memcpy((void *)cfg->payload,
11273 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11274 data_size);
11275 if (seq)
11276 cfg->payload_seq = *seq;
11277 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11278 cfg->wake_len = wake_size;
11279 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11280 memcpy((void *)cfg->wake_data,
11281 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11282 wake_size);
11283 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11284 data_size + wake_size;
11285 memcpy((void *)cfg->wake_mask,
11286 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11287 wake_mask_size);
11288 if (tok) {
11289 cfg->tokens_size = tokens_size;
11290 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11291 }
11292
11293 trig->tcp = cfg;
11294
11295 return 0;
11296}
11297
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011298static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11299 const struct wiphy_wowlan_support *wowlan,
11300 struct nlattr *attr,
11301 struct cfg80211_wowlan *trig)
11302{
11303 struct nlattr **tb;
11304 int err;
11305
Kees Cook6396bb22018-06-12 14:03:40 -070011306 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011307 if (!tb)
11308 return -ENOMEM;
11309
11310 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11311 err = -EOPNOTSUPP;
11312 goto out;
11313 }
11314
Johannes Berg8cb08172019-04-26 14:07:28 +020011315 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11316 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011317 if (err)
11318 goto out;
11319
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011320 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11321 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011322 err = PTR_ERR_OR_ZERO(trig->nd_config);
11323 if (err)
11324 trig->nd_config = NULL;
11325
11326out:
11327 kfree(tb);
11328 return err;
11329}
11330
Johannes Bergff1b6e62011-05-04 15:37:28 +020011331static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11332{
11333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11334 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011335 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011336 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011337 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011338 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011339 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011340 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011341
Johannes Berg964dc9e2013-06-03 17:25:34 +020011342 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011343 return -EOPNOTSUPP;
11344
Johannes Bergae33bd82012-07-12 16:25:02 +020011345 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11346 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011347 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011348 goto set_wakeup;
11349 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011350
Johannes Berg8cb08172019-04-26 14:07:28 +020011351 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11352 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11353 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011354 if (err)
11355 return err;
11356
11357 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11358 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11359 return -EINVAL;
11360 new_triggers.any = true;
11361 }
11362
11363 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11364 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11365 return -EINVAL;
11366 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011367 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011368 }
11369
11370 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11371 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11372 return -EINVAL;
11373 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011374 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011375 }
11376
Johannes Berg77dbbb12011-07-13 10:48:55 +020011377 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11378 return -EINVAL;
11379
11380 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11381 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11382 return -EINVAL;
11383 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011384 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011385 }
11386
11387 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11388 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11389 return -EINVAL;
11390 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011391 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011392 }
11393
11394 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11395 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11396 return -EINVAL;
11397 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011398 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011399 }
11400
11401 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11402 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11403 return -EINVAL;
11404 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011405 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011406 }
11407
Johannes Bergff1b6e62011-05-04 15:37:28 +020011408 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11409 struct nlattr *pat;
11410 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011411 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011412 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011413
Johannes Berg98fc4382015-03-01 09:10:13 +020011414 regular = true;
11415
Johannes Bergff1b6e62011-05-04 15:37:28 +020011416 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11417 rem)
11418 n_patterns++;
11419 if (n_patterns > wowlan->n_patterns)
11420 return -EINVAL;
11421
11422 new_triggers.patterns = kcalloc(n_patterns,
11423 sizeof(new_triggers.patterns[0]),
11424 GFP_KERNEL);
11425 if (!new_triggers.patterns)
11426 return -ENOMEM;
11427
11428 new_triggers.n_patterns = n_patterns;
11429 i = 0;
11430
11431 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11432 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011433 u8 *mask_pat;
11434
Johannes Berg8cb08172019-04-26 14:07:28 +020011435 err = nla_parse_nested_deprecated(pat_tb,
11436 MAX_NL80211_PKTPAT,
11437 pat,
11438 nl80211_packet_pattern_policy,
11439 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020011440 if (err)
11441 goto error;
11442
Johannes Bergff1b6e62011-05-04 15:37:28 +020011443 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011444 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11445 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011446 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011447 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011448 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011449 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011450 goto error;
11451 if (pat_len > wowlan->pattern_max_len ||
11452 pat_len < wowlan->pattern_min_len)
11453 goto error;
11454
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011455 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011456 pkt_offset = 0;
11457 else
11458 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011459 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011460 if (pkt_offset > wowlan->max_pkt_offset)
11461 goto error;
11462 new_triggers.patterns[i].pkt_offset = pkt_offset;
11463
Johannes Berg922bd802014-05-19 17:59:50 +020011464 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11465 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011466 err = -ENOMEM;
11467 goto error;
11468 }
Johannes Berg922bd802014-05-19 17:59:50 +020011469 new_triggers.patterns[i].mask = mask_pat;
11470 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011471 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011472 mask_pat += mask_len;
11473 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011474 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011475 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011476 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011477 pat_len);
11478 i++;
11479 }
11480 }
11481
Johannes Berg2a0e0472013-01-23 22:57:40 +010011482 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011483 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011484 err = nl80211_parse_wowlan_tcp(
11485 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11486 &new_triggers);
11487 if (err)
11488 goto error;
11489 }
11490
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011491 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011492 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011493 err = nl80211_parse_wowlan_nd(
11494 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11495 &new_triggers);
11496 if (err)
11497 goto error;
11498 }
11499
Johannes Berg98fc4382015-03-01 09:10:13 +020011500 /* The 'any' trigger means the device continues operating more or less
11501 * as in its normal operation mode and wakes up the host on most of the
11502 * normal interrupts (like packet RX, ...)
11503 * It therefore makes little sense to combine with the more constrained
11504 * wakeup trigger modes.
11505 */
11506 if (new_triggers.any && regular) {
11507 err = -EINVAL;
11508 goto error;
11509 }
11510
Johannes Bergae33bd82012-07-12 16:25:02 +020011511 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11512 if (!ntrig) {
11513 err = -ENOMEM;
11514 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011515 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011516 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011517 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011518
Johannes Bergae33bd82012-07-12 16:25:02 +020011519 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011520 if (rdev->ops->set_wakeup &&
11521 prev_enabled != !!rdev->wiphy.wowlan_config)
11522 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011523
Johannes Bergff1b6e62011-05-04 15:37:28 +020011524 return 0;
11525 error:
11526 for (i = 0; i < new_triggers.n_patterns; i++)
11527 kfree(new_triggers.patterns[i].mask);
11528 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011529 if (new_triggers.tcp && new_triggers.tcp->sock)
11530 sock_release(new_triggers.tcp->sock);
11531 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011532 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011533 return err;
11534}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011535#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011536
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011537static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11538 struct cfg80211_registered_device *rdev)
11539{
11540 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11541 int i, j, pat_len;
11542 struct cfg80211_coalesce_rules *rule;
11543
11544 if (!rdev->coalesce->n_rules)
11545 return 0;
11546
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011547 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011548 if (!nl_rules)
11549 return -ENOBUFS;
11550
11551 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011552 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011553 if (!nl_rule)
11554 return -ENOBUFS;
11555
11556 rule = &rdev->coalesce->rules[i];
11557 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11558 rule->delay))
11559 return -ENOBUFS;
11560
11561 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11562 rule->condition))
11563 return -ENOBUFS;
11564
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011565 nl_pats = nla_nest_start_noflag(msg,
11566 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011567 if (!nl_pats)
11568 return -ENOBUFS;
11569
11570 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011571 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011572 if (!nl_pat)
11573 return -ENOBUFS;
11574 pat_len = rule->patterns[j].pattern_len;
11575 if (nla_put(msg, NL80211_PKTPAT_MASK,
11576 DIV_ROUND_UP(pat_len, 8),
11577 rule->patterns[j].mask) ||
11578 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11579 rule->patterns[j].pattern) ||
11580 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11581 rule->patterns[j].pkt_offset))
11582 return -ENOBUFS;
11583 nla_nest_end(msg, nl_pat);
11584 }
11585 nla_nest_end(msg, nl_pats);
11586 nla_nest_end(msg, nl_rule);
11587 }
11588 nla_nest_end(msg, nl_rules);
11589
11590 return 0;
11591}
11592
11593static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11594{
11595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11596 struct sk_buff *msg;
11597 void *hdr;
11598
11599 if (!rdev->wiphy.coalesce)
11600 return -EOPNOTSUPP;
11601
11602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11603 if (!msg)
11604 return -ENOMEM;
11605
11606 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11607 NL80211_CMD_GET_COALESCE);
11608 if (!hdr)
11609 goto nla_put_failure;
11610
11611 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11612 goto nla_put_failure;
11613
11614 genlmsg_end(msg, hdr);
11615 return genlmsg_reply(msg, info);
11616
11617nla_put_failure:
11618 nlmsg_free(msg);
11619 return -ENOBUFS;
11620}
11621
11622void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11623{
11624 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11625 int i, j;
11626 struct cfg80211_coalesce_rules *rule;
11627
11628 if (!coalesce)
11629 return;
11630
11631 for (i = 0; i < coalesce->n_rules; i++) {
11632 rule = &coalesce->rules[i];
11633 for (j = 0; j < rule->n_patterns; j++)
11634 kfree(rule->patterns[j].mask);
11635 kfree(rule->patterns);
11636 }
11637 kfree(coalesce->rules);
11638 kfree(coalesce);
11639 rdev->coalesce = NULL;
11640}
11641
11642static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11643 struct nlattr *rule,
11644 struct cfg80211_coalesce_rules *new_rule)
11645{
11646 int err, i;
11647 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11648 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11649 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11650 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11651
Johannes Berg8cb08172019-04-26 14:07:28 +020011652 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11653 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011654 if (err)
11655 return err;
11656
11657 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11658 new_rule->delay =
11659 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11660 if (new_rule->delay > coalesce->max_delay)
11661 return -EINVAL;
11662
11663 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11664 new_rule->condition =
11665 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011666
11667 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11668 return -EINVAL;
11669
11670 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11671 rem)
11672 n_patterns++;
11673 if (n_patterns > coalesce->n_patterns)
11674 return -EINVAL;
11675
11676 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11677 GFP_KERNEL);
11678 if (!new_rule->patterns)
11679 return -ENOMEM;
11680
11681 new_rule->n_patterns = n_patterns;
11682 i = 0;
11683
11684 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11685 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011686 u8 *mask_pat;
11687
Johannes Berg8cb08172019-04-26 14:07:28 +020011688 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11689 pat,
11690 nl80211_packet_pattern_policy,
11691 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020011692 if (err)
11693 return err;
11694
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011695 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11696 !pat_tb[NL80211_PKTPAT_PATTERN])
11697 return -EINVAL;
11698 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11699 mask_len = DIV_ROUND_UP(pat_len, 8);
11700 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11701 return -EINVAL;
11702 if (pat_len > coalesce->pattern_max_len ||
11703 pat_len < coalesce->pattern_min_len)
11704 return -EINVAL;
11705
11706 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11707 pkt_offset = 0;
11708 else
11709 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11710 if (pkt_offset > coalesce->max_pkt_offset)
11711 return -EINVAL;
11712 new_rule->patterns[i].pkt_offset = pkt_offset;
11713
Johannes Berg922bd802014-05-19 17:59:50 +020011714 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11715 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011716 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011717
11718 new_rule->patterns[i].mask = mask_pat;
11719 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11720 mask_len);
11721
11722 mask_pat += mask_len;
11723 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011724 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011725 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11726 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011727 i++;
11728 }
11729
11730 return 0;
11731}
11732
11733static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11734{
11735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11736 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11737 struct cfg80211_coalesce new_coalesce = {};
11738 struct cfg80211_coalesce *n_coalesce;
11739 int err, rem_rule, n_rules = 0, i, j;
11740 struct nlattr *rule;
11741 struct cfg80211_coalesce_rules *tmp_rule;
11742
11743 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11744 return -EOPNOTSUPP;
11745
11746 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11747 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011748 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011749 return 0;
11750 }
11751
11752 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11753 rem_rule)
11754 n_rules++;
11755 if (n_rules > coalesce->n_rules)
11756 return -EINVAL;
11757
11758 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11759 GFP_KERNEL);
11760 if (!new_coalesce.rules)
11761 return -ENOMEM;
11762
11763 new_coalesce.n_rules = n_rules;
11764 i = 0;
11765
11766 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11767 rem_rule) {
11768 err = nl80211_parse_coalesce_rule(rdev, rule,
11769 &new_coalesce.rules[i]);
11770 if (err)
11771 goto error;
11772
11773 i++;
11774 }
11775
Ilan Peera1056b1b2015-10-22 22:27:46 +030011776 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011777 if (err)
11778 goto error;
11779
11780 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11781 if (!n_coalesce) {
11782 err = -ENOMEM;
11783 goto error;
11784 }
11785 cfg80211_rdev_free_coalesce(rdev);
11786 rdev->coalesce = n_coalesce;
11787
11788 return 0;
11789error:
11790 for (i = 0; i < new_coalesce.n_rules; i++) {
11791 tmp_rule = &new_coalesce.rules[i];
11792 for (j = 0; j < tmp_rule->n_patterns; j++)
11793 kfree(tmp_rule->patterns[j].mask);
11794 kfree(tmp_rule->patterns);
11795 }
11796 kfree(new_coalesce.rules);
11797
11798 return err;
11799}
11800
Johannes Berge5497d72011-07-05 16:35:40 +020011801static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11802{
11803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11804 struct net_device *dev = info->user_ptr[1];
11805 struct wireless_dev *wdev = dev->ieee80211_ptr;
11806 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11807 struct cfg80211_gtk_rekey_data rekey_data;
11808 int err;
11809
11810 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11811 return -EINVAL;
11812
Johannes Berg8cb08172019-04-26 14:07:28 +020011813 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
11814 info->attrs[NL80211_ATTR_REKEY_DATA],
11815 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011816 if (err)
11817 return err;
11818
Vladis Dronove785fa02017-09-13 00:21:21 +020011819 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11820 !tb[NL80211_REKEY_DATA_KCK])
11821 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011822 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11823 return -ERANGE;
11824 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11825 return -ERANGE;
11826 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11827 return -ERANGE;
11828
Johannes Berg78f686c2014-09-10 22:28:06 +030011829 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11830 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11831 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011832
11833 wdev_lock(wdev);
11834 if (!wdev->current_bss) {
11835 err = -ENOTCONN;
11836 goto out;
11837 }
11838
11839 if (!rdev->ops->set_rekey_data) {
11840 err = -EOPNOTSUPP;
11841 goto out;
11842 }
11843
Hila Gonene35e4d22012-06-27 17:19:42 +030011844 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011845 out:
11846 wdev_unlock(wdev);
11847 return err;
11848}
11849
Johannes Berg28946da2011-11-04 11:18:12 +010011850static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11851 struct genl_info *info)
11852{
11853 struct net_device *dev = info->user_ptr[1];
11854 struct wireless_dev *wdev = dev->ieee80211_ptr;
11855
11856 if (wdev->iftype != NL80211_IFTYPE_AP &&
11857 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11858 return -EINVAL;
11859
Eric W. Biederman15e47302012-09-07 20:12:54 +000011860 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011861 return -EBUSY;
11862
Eric W. Biederman15e47302012-09-07 20:12:54 +000011863 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011864 return 0;
11865}
11866
Johannes Berg7f6cf312011-11-04 11:18:15 +010011867static int nl80211_probe_client(struct sk_buff *skb,
11868 struct genl_info *info)
11869{
11870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11871 struct net_device *dev = info->user_ptr[1];
11872 struct wireless_dev *wdev = dev->ieee80211_ptr;
11873 struct sk_buff *msg;
11874 void *hdr;
11875 const u8 *addr;
11876 u64 cookie;
11877 int err;
11878
11879 if (wdev->iftype != NL80211_IFTYPE_AP &&
11880 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11881 return -EOPNOTSUPP;
11882
11883 if (!info->attrs[NL80211_ATTR_MAC])
11884 return -EINVAL;
11885
11886 if (!rdev->ops->probe_client)
11887 return -EOPNOTSUPP;
11888
11889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11890 if (!msg)
11891 return -ENOMEM;
11892
Eric W. Biederman15e47302012-09-07 20:12:54 +000011893 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011894 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011895 if (!hdr) {
11896 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011897 goto free_msg;
11898 }
11899
11900 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11901
Hila Gonene35e4d22012-06-27 17:19:42 +030011902 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011903 if (err)
11904 goto free_msg;
11905
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011906 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11907 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011908 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011909
11910 genlmsg_end(msg, hdr);
11911
11912 return genlmsg_reply(msg, info);
11913
11914 nla_put_failure:
11915 err = -ENOBUFS;
11916 free_msg:
11917 nlmsg_free(msg);
11918 return err;
11919}
11920
Johannes Berg5e760232011-11-04 11:18:17 +010011921static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11922{
11923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011924 struct cfg80211_beacon_registration *reg, *nreg;
11925 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011926
11927 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11928 return -EOPNOTSUPP;
11929
Ben Greear37c73b52012-10-26 14:49:25 -070011930 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11931 if (!nreg)
11932 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011933
Ben Greear37c73b52012-10-26 14:49:25 -070011934 /* First, check if already registered. */
11935 spin_lock_bh(&rdev->beacon_registrations_lock);
11936 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11937 if (reg->nlportid == info->snd_portid) {
11938 rv = -EALREADY;
11939 goto out_err;
11940 }
11941 }
11942 /* Add it to the list */
11943 nreg->nlportid = info->snd_portid;
11944 list_add(&nreg->list, &rdev->beacon_registrations);
11945
11946 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011947
11948 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011949out_err:
11950 spin_unlock_bh(&rdev->beacon_registrations_lock);
11951 kfree(nreg);
11952 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011953}
11954
Johannes Berg98104fde2012-06-16 00:19:54 +020011955static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11956{
11957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11958 struct wireless_dev *wdev = info->user_ptr[1];
11959 int err;
11960
11961 if (!rdev->ops->start_p2p_device)
11962 return -EOPNOTSUPP;
11963
11964 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11965 return -EOPNOTSUPP;
11966
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011967 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011968 return 0;
11969
Luciano Coelhob6a55012014-02-27 11:07:21 +020011970 if (rfkill_blocked(rdev->rfkill))
11971 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011972
Johannes Bergeeb126e2012-10-23 15:16:50 +020011973 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011974 if (err)
11975 return err;
11976
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011977 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011978 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011979
11980 return 0;
11981}
11982
11983static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11984{
11985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11986 struct wireless_dev *wdev = info->user_ptr[1];
11987
11988 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11989 return -EOPNOTSUPP;
11990
11991 if (!rdev->ops->stop_p2p_device)
11992 return -EOPNOTSUPP;
11993
Johannes Bergf9f47522013-03-19 15:04:07 +010011994 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011995
11996 return 0;
11997}
11998
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011999static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12000{
12001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12002 struct wireless_dev *wdev = info->user_ptr[1];
12003 struct cfg80211_nan_conf conf = {};
12004 int err;
12005
12006 if (wdev->iftype != NL80211_IFTYPE_NAN)
12007 return -EOPNOTSUPP;
12008
Johannes Bergeeb04a92016-11-21 13:55:48 +010012009 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012010 return -EEXIST;
12011
12012 if (rfkill_blocked(rdev->rfkill))
12013 return -ERFKILL;
12014
12015 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12016 return -EINVAL;
12017
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012018 conf.master_pref =
12019 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012020
Luca Coelho85859892017-02-08 15:00:34 +020012021 if (info->attrs[NL80211_ATTR_BANDS]) {
12022 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12023
12024 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12025 return -EOPNOTSUPP;
12026
12027 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12028 return -EINVAL;
12029
12030 conf.bands = bands;
12031 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012032
12033 err = rdev_start_nan(rdev, wdev, &conf);
12034 if (err)
12035 return err;
12036
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012037 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012038 rdev->opencount++;
12039
12040 return 0;
12041}
12042
12043static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12044{
12045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12046 struct wireless_dev *wdev = info->user_ptr[1];
12047
12048 if (wdev->iftype != NL80211_IFTYPE_NAN)
12049 return -EOPNOTSUPP;
12050
12051 cfg80211_stop_nan(rdev, wdev);
12052
12053 return 0;
12054}
12055
Ayala Bekera442b762016-09-20 17:31:15 +030012056static int validate_nan_filter(struct nlattr *filter_attr)
12057{
12058 struct nlattr *attr;
12059 int len = 0, n_entries = 0, rem;
12060
12061 nla_for_each_nested(attr, filter_attr, rem) {
12062 len += nla_len(attr);
12063 n_entries++;
12064 }
12065
12066 if (len >= U8_MAX)
12067 return -EINVAL;
12068
12069 return n_entries;
12070}
12071
12072static int handle_nan_filter(struct nlattr *attr_filter,
12073 struct cfg80211_nan_func *func,
12074 bool tx)
12075{
12076 struct nlattr *attr;
12077 int n_entries, rem, i;
12078 struct cfg80211_nan_func_filter *filter;
12079
12080 n_entries = validate_nan_filter(attr_filter);
12081 if (n_entries < 0)
12082 return n_entries;
12083
12084 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12085
12086 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12087 if (!filter)
12088 return -ENOMEM;
12089
12090 i = 0;
12091 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012092 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012093 filter[i].len = nla_len(attr);
12094 i++;
12095 }
12096 if (tx) {
12097 func->num_tx_filters = n_entries;
12098 func->tx_filters = filter;
12099 } else {
12100 func->num_rx_filters = n_entries;
12101 func->rx_filters = filter;
12102 }
12103
12104 return 0;
12105}
12106
12107static int nl80211_nan_add_func(struct sk_buff *skb,
12108 struct genl_info *info)
12109{
12110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12111 struct wireless_dev *wdev = info->user_ptr[1];
12112 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12113 struct cfg80211_nan_func *func;
12114 struct sk_buff *msg = NULL;
12115 void *hdr = NULL;
12116 int err = 0;
12117
12118 if (wdev->iftype != NL80211_IFTYPE_NAN)
12119 return -EOPNOTSUPP;
12120
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012121 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012122 return -ENOTCONN;
12123
12124 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12125 return -EINVAL;
12126
Johannes Berg8cb08172019-04-26 14:07:28 +020012127 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12128 info->attrs[NL80211_ATTR_NAN_FUNC],
12129 nl80211_nan_func_policy,
12130 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012131 if (err)
12132 return err;
12133
12134 func = kzalloc(sizeof(*func), GFP_KERNEL);
12135 if (!func)
12136 return -ENOMEM;
12137
Johannes Bergb60ad342018-10-01 11:52:07 +020012138 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012139
12140 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12141 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12142 err = -EINVAL;
12143 goto out;
12144 }
12145
12146
12147 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12148
12149 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12150 err = -EINVAL;
12151 goto out;
12152 }
12153
12154 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12155 sizeof(func->service_id));
12156
12157 func->close_range =
12158 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12159
12160 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12161 func->serv_spec_info_len =
12162 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12163 func->serv_spec_info =
12164 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12165 func->serv_spec_info_len,
12166 GFP_KERNEL);
12167 if (!func->serv_spec_info) {
12168 err = -ENOMEM;
12169 goto out;
12170 }
12171 }
12172
12173 if (tb[NL80211_NAN_FUNC_TTL])
12174 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12175
12176 switch (func->type) {
12177 case NL80211_NAN_FUNC_PUBLISH:
12178 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12179 err = -EINVAL;
12180 goto out;
12181 }
12182
12183 func->publish_type =
12184 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12185 func->publish_bcast =
12186 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12187
12188 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12189 func->publish_bcast) {
12190 err = -EINVAL;
12191 goto out;
12192 }
12193 break;
12194 case NL80211_NAN_FUNC_SUBSCRIBE:
12195 func->subscribe_active =
12196 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12197 break;
12198 case NL80211_NAN_FUNC_FOLLOW_UP:
12199 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012200 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12201 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012202 err = -EINVAL;
12203 goto out;
12204 }
12205
12206 func->followup_id =
12207 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12208 func->followup_reqid =
12209 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12210 memcpy(func->followup_dest.addr,
12211 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12212 sizeof(func->followup_dest.addr));
12213 if (func->ttl) {
12214 err = -EINVAL;
12215 goto out;
12216 }
12217 break;
12218 default:
12219 err = -EINVAL;
12220 goto out;
12221 }
12222
12223 if (tb[NL80211_NAN_FUNC_SRF]) {
12224 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12225
Johannes Berg8cb08172019-04-26 14:07:28 +020012226 err = nla_parse_nested_deprecated(srf_tb,
12227 NL80211_NAN_SRF_ATTR_MAX,
12228 tb[NL80211_NAN_FUNC_SRF],
12229 nl80211_nan_srf_policy,
12230 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012231 if (err)
12232 goto out;
12233
12234 func->srf_include =
12235 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12236
12237 if (srf_tb[NL80211_NAN_SRF_BF]) {
12238 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12239 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12240 err = -EINVAL;
12241 goto out;
12242 }
12243
12244 func->srf_bf_len =
12245 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12246 func->srf_bf =
12247 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12248 func->srf_bf_len, GFP_KERNEL);
12249 if (!func->srf_bf) {
12250 err = -ENOMEM;
12251 goto out;
12252 }
12253
12254 func->srf_bf_idx =
12255 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12256 } else {
12257 struct nlattr *attr, *mac_attr =
12258 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12259 int n_entries, rem, i = 0;
12260
12261 if (!mac_attr) {
12262 err = -EINVAL;
12263 goto out;
12264 }
12265
12266 n_entries = validate_acl_mac_addrs(mac_attr);
12267 if (n_entries <= 0) {
12268 err = -EINVAL;
12269 goto out;
12270 }
12271
12272 func->srf_num_macs = n_entries;
12273 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012274 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012275 GFP_KERNEL);
12276 if (!func->srf_macs) {
12277 err = -ENOMEM;
12278 goto out;
12279 }
12280
12281 nla_for_each_nested(attr, mac_attr, rem)
12282 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12283 sizeof(*func->srf_macs));
12284 }
12285 }
12286
12287 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12288 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12289 func, true);
12290 if (err)
12291 goto out;
12292 }
12293
12294 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12295 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12296 func, false);
12297 if (err)
12298 goto out;
12299 }
12300
12301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12302 if (!msg) {
12303 err = -ENOMEM;
12304 goto out;
12305 }
12306
12307 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12308 NL80211_CMD_ADD_NAN_FUNCTION);
12309 /* This can't really happen - we just allocated 4KB */
12310 if (WARN_ON(!hdr)) {
12311 err = -ENOMEM;
12312 goto out;
12313 }
12314
12315 err = rdev_add_nan_func(rdev, wdev, func);
12316out:
12317 if (err < 0) {
12318 cfg80211_free_nan_func(func);
12319 nlmsg_free(msg);
12320 return err;
12321 }
12322
12323 /* propagate the instance id and cookie to userspace */
12324 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12325 NL80211_ATTR_PAD))
12326 goto nla_put_failure;
12327
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012328 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030012329 if (!func_attr)
12330 goto nla_put_failure;
12331
12332 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12333 func->instance_id))
12334 goto nla_put_failure;
12335
12336 nla_nest_end(msg, func_attr);
12337
12338 genlmsg_end(msg, hdr);
12339 return genlmsg_reply(msg, info);
12340
12341nla_put_failure:
12342 nlmsg_free(msg);
12343 return -ENOBUFS;
12344}
12345
12346static int nl80211_nan_del_func(struct sk_buff *skb,
12347 struct genl_info *info)
12348{
12349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12350 struct wireless_dev *wdev = info->user_ptr[1];
12351 u64 cookie;
12352
12353 if (wdev->iftype != NL80211_IFTYPE_NAN)
12354 return -EOPNOTSUPP;
12355
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012356 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012357 return -ENOTCONN;
12358
12359 if (!info->attrs[NL80211_ATTR_COOKIE])
12360 return -EINVAL;
12361
Ayala Bekera442b762016-09-20 17:31:15 +030012362 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12363
12364 rdev_del_nan_func(rdev, wdev, cookie);
12365
12366 return 0;
12367}
12368
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012369static int nl80211_nan_change_config(struct sk_buff *skb,
12370 struct genl_info *info)
12371{
12372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12373 struct wireless_dev *wdev = info->user_ptr[1];
12374 struct cfg80211_nan_conf conf = {};
12375 u32 changed = 0;
12376
12377 if (wdev->iftype != NL80211_IFTYPE_NAN)
12378 return -EOPNOTSUPP;
12379
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012380 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012381 return -ENOTCONN;
12382
12383 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12384 conf.master_pref =
12385 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12386 if (conf.master_pref <= 1 || conf.master_pref == 255)
12387 return -EINVAL;
12388
12389 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12390 }
12391
Luca Coelho85859892017-02-08 15:00:34 +020012392 if (info->attrs[NL80211_ATTR_BANDS]) {
12393 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12394
12395 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12396 return -EOPNOTSUPP;
12397
12398 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12399 return -EINVAL;
12400
12401 conf.bands = bands;
12402 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012403 }
12404
12405 if (!changed)
12406 return -EINVAL;
12407
12408 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12409}
12410
Ayala Beker50bcd312016-09-20 17:31:17 +030012411void cfg80211_nan_match(struct wireless_dev *wdev,
12412 struct cfg80211_nan_match_params *match, gfp_t gfp)
12413{
12414 struct wiphy *wiphy = wdev->wiphy;
12415 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12416 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12417 struct sk_buff *msg;
12418 void *hdr;
12419
12420 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12421 return;
12422
12423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12424 if (!msg)
12425 return;
12426
12427 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12428 if (!hdr) {
12429 nlmsg_free(msg);
12430 return;
12431 }
12432
12433 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12434 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12435 wdev->netdev->ifindex)) ||
12436 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12437 NL80211_ATTR_PAD))
12438 goto nla_put_failure;
12439
12440 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12441 NL80211_ATTR_PAD) ||
12442 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12443 goto nla_put_failure;
12444
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012445 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030012446 if (!match_attr)
12447 goto nla_put_failure;
12448
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012449 local_func_attr = nla_nest_start_noflag(msg,
12450 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030012451 if (!local_func_attr)
12452 goto nla_put_failure;
12453
12454 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12455 goto nla_put_failure;
12456
12457 nla_nest_end(msg, local_func_attr);
12458
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012459 peer_func_attr = nla_nest_start_noflag(msg,
12460 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030012461 if (!peer_func_attr)
12462 goto nla_put_failure;
12463
12464 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12465 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12466 goto nla_put_failure;
12467
12468 if (match->info && match->info_len &&
12469 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12470 match->info))
12471 goto nla_put_failure;
12472
12473 nla_nest_end(msg, peer_func_attr);
12474 nla_nest_end(msg, match_attr);
12475 genlmsg_end(msg, hdr);
12476
12477 if (!wdev->owner_nlportid)
12478 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12479 msg, 0, NL80211_MCGRP_NAN, gfp);
12480 else
12481 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12482 wdev->owner_nlportid);
12483
12484 return;
12485
12486nla_put_failure:
12487 nlmsg_free(msg);
12488}
12489EXPORT_SYMBOL(cfg80211_nan_match);
12490
Ayala Beker368e5a72016-09-20 17:31:18 +030012491void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12492 u8 inst_id,
12493 enum nl80211_nan_func_term_reason reason,
12494 u64 cookie, gfp_t gfp)
12495{
12496 struct wiphy *wiphy = wdev->wiphy;
12497 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12498 struct sk_buff *msg;
12499 struct nlattr *func_attr;
12500 void *hdr;
12501
12502 if (WARN_ON(!inst_id))
12503 return;
12504
12505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12506 if (!msg)
12507 return;
12508
12509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12510 if (!hdr) {
12511 nlmsg_free(msg);
12512 return;
12513 }
12514
12515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12516 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12517 wdev->netdev->ifindex)) ||
12518 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12519 NL80211_ATTR_PAD))
12520 goto nla_put_failure;
12521
12522 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12523 NL80211_ATTR_PAD))
12524 goto nla_put_failure;
12525
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012526 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030012527 if (!func_attr)
12528 goto nla_put_failure;
12529
12530 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12531 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12532 goto nla_put_failure;
12533
12534 nla_nest_end(msg, func_attr);
12535 genlmsg_end(msg, hdr);
12536
12537 if (!wdev->owner_nlportid)
12538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12539 msg, 0, NL80211_MCGRP_NAN, gfp);
12540 else
12541 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12542 wdev->owner_nlportid);
12543
12544 return;
12545
12546nla_put_failure:
12547 nlmsg_free(msg);
12548}
12549EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12550
Johannes Berg3713b4e2013-02-14 16:19:38 +010012551static int nl80211_get_protocol_features(struct sk_buff *skb,
12552 struct genl_info *info)
12553{
12554 void *hdr;
12555 struct sk_buff *msg;
12556
12557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12558 if (!msg)
12559 return -ENOMEM;
12560
12561 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12562 NL80211_CMD_GET_PROTOCOL_FEATURES);
12563 if (!hdr)
12564 goto nla_put_failure;
12565
12566 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12567 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12568 goto nla_put_failure;
12569
12570 genlmsg_end(msg, hdr);
12571 return genlmsg_reply(msg, info);
12572
12573 nla_put_failure:
12574 kfree_skb(msg);
12575 return -ENOBUFS;
12576}
12577
Jouni Malinen355199e2013-02-27 17:14:27 +020012578static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12579{
12580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12581 struct cfg80211_update_ft_ies_params ft_params;
12582 struct net_device *dev = info->user_ptr[1];
12583
12584 if (!rdev->ops->update_ft_ies)
12585 return -EOPNOTSUPP;
12586
12587 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012588 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012589 return -EINVAL;
12590
12591 memset(&ft_params, 0, sizeof(ft_params));
12592 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12593 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12594 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12595
12596 return rdev_update_ft_ies(rdev, dev, &ft_params);
12597}
12598
Arend van Spriel5de17982013-04-18 15:49:00 +020012599static int nl80211_crit_protocol_start(struct sk_buff *skb,
12600 struct genl_info *info)
12601{
12602 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12603 struct wireless_dev *wdev = info->user_ptr[1];
12604 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12605 u16 duration;
12606 int ret;
12607
12608 if (!rdev->ops->crit_proto_start)
12609 return -EOPNOTSUPP;
12610
12611 if (WARN_ON(!rdev->ops->crit_proto_stop))
12612 return -EINVAL;
12613
12614 if (rdev->crit_proto_nlportid)
12615 return -EBUSY;
12616
12617 /* determine protocol if provided */
12618 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12619 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12620
12621 if (proto >= NUM_NL80211_CRIT_PROTO)
12622 return -EINVAL;
12623
12624 /* timeout must be provided */
12625 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12626 return -EINVAL;
12627
12628 duration =
12629 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12630
12631 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12632 return -ERANGE;
12633
12634 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12635 if (!ret)
12636 rdev->crit_proto_nlportid = info->snd_portid;
12637
12638 return ret;
12639}
12640
12641static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12642 struct genl_info *info)
12643{
12644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12645 struct wireless_dev *wdev = info->user_ptr[1];
12646
12647 if (!rdev->ops->crit_proto_stop)
12648 return -EOPNOTSUPP;
12649
12650 if (rdev->crit_proto_nlportid) {
12651 rdev->crit_proto_nlportid = 0;
12652 rdev_crit_proto_stop(rdev, wdev);
12653 }
12654 return 0;
12655}
12656
Johannes Bergad7e7182013-11-13 13:37:47 +010012657static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12658{
12659 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12660 struct wireless_dev *wdev =
12661 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12662 int i, err;
12663 u32 vid, subcmd;
12664
12665 if (!rdev->wiphy.vendor_commands)
12666 return -EOPNOTSUPP;
12667
12668 if (IS_ERR(wdev)) {
12669 err = PTR_ERR(wdev);
12670 if (err != -EINVAL)
12671 return err;
12672 wdev = NULL;
12673 } else if (wdev->wiphy != &rdev->wiphy) {
12674 return -EINVAL;
12675 }
12676
12677 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12678 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12679 return -EINVAL;
12680
12681 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12682 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12683 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12684 const struct wiphy_vendor_command *vcmd;
12685 void *data = NULL;
12686 int len = 0;
12687
12688 vcmd = &rdev->wiphy.vendor_commands[i];
12689
12690 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12691 continue;
12692
12693 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12694 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12695 if (!wdev)
12696 return -EINVAL;
12697 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12698 !wdev->netdev)
12699 return -EINVAL;
12700
12701 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012702 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012703 return -ENETDOWN;
12704 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012705
12706 if (!vcmd->doit)
12707 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012708 } else {
12709 wdev = NULL;
12710 }
12711
12712 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12713 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12714 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12715 }
12716
12717 rdev->cur_cmd_info = info;
12718 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
12719 data, len);
12720 rdev->cur_cmd_info = NULL;
12721 return err;
12722 }
12723
12724 return -EOPNOTSUPP;
12725}
12726
Johannes Berg7bdbe402015-08-15 22:39:49 +030012727static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12728 struct netlink_callback *cb,
12729 struct cfg80211_registered_device **rdev,
12730 struct wireless_dev **wdev)
12731{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012732 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012733 u32 vid, subcmd;
12734 unsigned int i;
12735 int vcmd_idx = -1;
12736 int err;
12737 void *data = NULL;
12738 unsigned int data_len = 0;
12739
Johannes Berg7bdbe402015-08-15 22:39:49 +030012740 if (cb->args[0]) {
12741 /* subtract the 1 again here */
12742 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12743 struct wireless_dev *tmp;
12744
Johannes Bergea90e0d2017-03-15 14:26:04 +010012745 if (!wiphy)
12746 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012747 *rdev = wiphy_to_rdev(wiphy);
12748 *wdev = NULL;
12749
12750 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012751 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012752 if (tmp->identifier == cb->args[1] - 1) {
12753 *wdev = tmp;
12754 break;
12755 }
12756 }
12757 }
12758
12759 /* keep rtnl locked in successful case */
12760 return 0;
12761 }
12762
Johannes Berg8cb08172019-04-26 14:07:28 +020012763 err = nlmsg_parse_deprecated(cb->nlh,
12764 GENL_HDRLEN + nl80211_fam.hdrsize,
12765 attrbuf, nl80211_fam.maxattr,
12766 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012767 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012768 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012769
Johannes Bergc90c39d2016-10-24 14:40:01 +020012770 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012771 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12772 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012773
Johannes Bergc90c39d2016-10-24 14:40:01 +020012774 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012775 if (IS_ERR(*wdev))
12776 *wdev = NULL;
12777
Johannes Bergc90c39d2016-10-24 14:40:01 +020012778 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012779 if (IS_ERR(*rdev))
12780 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012781
Johannes Bergc90c39d2016-10-24 14:40:01 +020012782 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12783 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012784
12785 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12786 const struct wiphy_vendor_command *vcmd;
12787
12788 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12789
12790 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12791 continue;
12792
Johannes Bergea90e0d2017-03-15 14:26:04 +010012793 if (!vcmd->dumpit)
12794 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012795
12796 vcmd_idx = i;
12797 break;
12798 }
12799
Johannes Bergea90e0d2017-03-15 14:26:04 +010012800 if (vcmd_idx < 0)
12801 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012802
Johannes Bergc90c39d2016-10-24 14:40:01 +020012803 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12804 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12805 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012806 }
12807
12808 /* 0 is the first index - add 1 to parse only once */
12809 cb->args[0] = (*rdev)->wiphy_idx + 1;
12810 /* add 1 to know if it was NULL */
12811 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12812 cb->args[2] = vcmd_idx;
12813 cb->args[3] = (unsigned long)data;
12814 cb->args[4] = data_len;
12815
12816 /* keep rtnl locked in successful case */
12817 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012818}
12819
12820static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12821 struct netlink_callback *cb)
12822{
12823 struct cfg80211_registered_device *rdev;
12824 struct wireless_dev *wdev;
12825 unsigned int vcmd_idx;
12826 const struct wiphy_vendor_command *vcmd;
12827 void *data;
12828 int data_len;
12829 int err;
12830 struct nlattr *vendor_data;
12831
Johannes Bergea90e0d2017-03-15 14:26:04 +010012832 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012833 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12834 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012835 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012836
12837 vcmd_idx = cb->args[2];
12838 data = (void *)cb->args[3];
12839 data_len = cb->args[4];
12840 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12841
12842 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12843 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012844 if (!wdev) {
12845 err = -EINVAL;
12846 goto out;
12847 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012848 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012849 !wdev->netdev) {
12850 err = -EINVAL;
12851 goto out;
12852 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012853
12854 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012855 if (!wdev_running(wdev)) {
12856 err = -ENETDOWN;
12857 goto out;
12858 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012859 }
12860 }
12861
12862 while (1) {
12863 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12864 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12865 NL80211_CMD_VENDOR);
12866 if (!hdr)
12867 break;
12868
12869 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012870 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12871 wdev_id(wdev),
12872 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012873 genlmsg_cancel(skb, hdr);
12874 break;
12875 }
12876
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012877 vendor_data = nla_nest_start_noflag(skb,
12878 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012879 if (!vendor_data) {
12880 genlmsg_cancel(skb, hdr);
12881 break;
12882 }
12883
12884 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12885 (unsigned long *)&cb->args[5]);
12886 nla_nest_end(skb, vendor_data);
12887
12888 if (err == -ENOBUFS || err == -ENOENT) {
12889 genlmsg_cancel(skb, hdr);
12890 break;
12891 } else if (err) {
12892 genlmsg_cancel(skb, hdr);
12893 goto out;
12894 }
12895
12896 genlmsg_end(skb, hdr);
12897 }
12898
12899 err = skb->len;
12900 out:
12901 rtnl_unlock();
12902 return err;
12903}
12904
Johannes Bergad7e7182013-11-13 13:37:47 +010012905struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12906 enum nl80211_commands cmd,
12907 enum nl80211_attrs attr,
12908 int approxlen)
12909{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012910 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012911
12912 if (WARN_ON(!rdev->cur_cmd_info))
12913 return NULL;
12914
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012915 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012916 rdev->cur_cmd_info->snd_portid,
12917 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012918 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012919}
12920EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12921
12922int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12923{
12924 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12925 void *hdr = ((void **)skb->cb)[1];
12926 struct nlattr *data = ((void **)skb->cb)[2];
12927
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012928 /* clear CB data for netlink core to own from now on */
12929 memset(skb->cb, 0, sizeof(skb->cb));
12930
Johannes Bergad7e7182013-11-13 13:37:47 +010012931 if (WARN_ON(!rdev->cur_cmd_info)) {
12932 kfree_skb(skb);
12933 return -EINVAL;
12934 }
12935
12936 nla_nest_end(skb, data);
12937 genlmsg_end(skb, hdr);
12938 return genlmsg_reply(skb, rdev->cur_cmd_info);
12939}
12940EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12941
Johannes Berg55c1fdf2019-02-06 13:17:19 +020012942unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
12943{
12944 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12945
12946 if (WARN_ON(!rdev->cur_cmd_info))
12947 return 0;
12948
12949 return rdev->cur_cmd_info->snd_portid;
12950}
12951EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
12952
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012953static int nl80211_set_qos_map(struct sk_buff *skb,
12954 struct genl_info *info)
12955{
12956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12957 struct cfg80211_qos_map *qos_map = NULL;
12958 struct net_device *dev = info->user_ptr[1];
12959 u8 *pos, len, num_des, des_len, des;
12960 int ret;
12961
12962 if (!rdev->ops->set_qos_map)
12963 return -EOPNOTSUPP;
12964
12965 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12966 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12967 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12968
12969 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12970 len > IEEE80211_QOS_MAP_LEN_MAX)
12971 return -EINVAL;
12972
12973 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12974 if (!qos_map)
12975 return -ENOMEM;
12976
12977 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12978 if (num_des) {
12979 des_len = num_des *
12980 sizeof(struct cfg80211_dscp_exception);
12981 memcpy(qos_map->dscp_exception, pos, des_len);
12982 qos_map->num_des = num_des;
12983 for (des = 0; des < num_des; des++) {
12984 if (qos_map->dscp_exception[des].up > 7) {
12985 kfree(qos_map);
12986 return -EINVAL;
12987 }
12988 }
12989 pos += des_len;
12990 }
12991 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12992 }
12993
12994 wdev_lock(dev->ieee80211_ptr);
12995 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12996 if (!ret)
12997 ret = rdev_set_qos_map(rdev, dev, qos_map);
12998 wdev_unlock(dev->ieee80211_ptr);
12999
13000 kfree(qos_map);
13001 return ret;
13002}
13003
Johannes Berg960d01a2014-09-09 22:55:35 +030013004static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13005{
13006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13007 struct net_device *dev = info->user_ptr[1];
13008 struct wireless_dev *wdev = dev->ieee80211_ptr;
13009 const u8 *peer;
13010 u8 tsid, up;
13011 u16 admitted_time = 0;
13012 int err;
13013
Johannes Berg723e73a2014-10-22 09:25:06 +020013014 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013015 return -EOPNOTSUPP;
13016
13017 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13018 !info->attrs[NL80211_ATTR_USER_PRIO])
13019 return -EINVAL;
13020
13021 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013022 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013023
13024 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013025 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013026 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013027 * need more attributes for that (e.g. BA session requirement);
13028 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013029 */
13030 return -EINVAL;
13031 }
13032
13033 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13034
13035 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13036 admitted_time =
13037 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13038 if (!admitted_time)
13039 return -EINVAL;
13040 }
13041
13042 wdev_lock(wdev);
13043 switch (wdev->iftype) {
13044 case NL80211_IFTYPE_STATION:
13045 case NL80211_IFTYPE_P2P_CLIENT:
13046 if (wdev->current_bss)
13047 break;
13048 err = -ENOTCONN;
13049 goto out;
13050 default:
13051 err = -EOPNOTSUPP;
13052 goto out;
13053 }
13054
13055 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13056
13057 out:
13058 wdev_unlock(wdev);
13059 return err;
13060}
13061
13062static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13063{
13064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13065 struct net_device *dev = info->user_ptr[1];
13066 struct wireless_dev *wdev = dev->ieee80211_ptr;
13067 const u8 *peer;
13068 u8 tsid;
13069 int err;
13070
13071 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13072 return -EINVAL;
13073
13074 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13075 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13076
13077 wdev_lock(wdev);
13078 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13079 wdev_unlock(wdev);
13080
13081 return err;
13082}
13083
Arik Nemtsov1057d352014-11-19 12:54:26 +020013084static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13085 struct genl_info *info)
13086{
13087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13088 struct net_device *dev = info->user_ptr[1];
13089 struct wireless_dev *wdev = dev->ieee80211_ptr;
13090 struct cfg80211_chan_def chandef = {};
13091 const u8 *addr;
13092 u8 oper_class;
13093 int err;
13094
13095 if (!rdev->ops->tdls_channel_switch ||
13096 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13097 return -EOPNOTSUPP;
13098
13099 switch (dev->ieee80211_ptr->iftype) {
13100 case NL80211_IFTYPE_STATION:
13101 case NL80211_IFTYPE_P2P_CLIENT:
13102 break;
13103 default:
13104 return -EOPNOTSUPP;
13105 }
13106
13107 if (!info->attrs[NL80211_ATTR_MAC] ||
13108 !info->attrs[NL80211_ATTR_OPER_CLASS])
13109 return -EINVAL;
13110
13111 err = nl80211_parse_chandef(rdev, info, &chandef);
13112 if (err)
13113 return err;
13114
13115 /*
13116 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13117 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13118 * specification is not defined for them.
13119 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013120 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013121 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13122 chandef.width != NL80211_CHAN_WIDTH_20)
13123 return -EINVAL;
13124
13125 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013126 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13127 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013128 return -EINVAL;
13129
13130 /* don't allow switching to DFS channels */
13131 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13132 return -EINVAL;
13133
13134 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13135 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13136
13137 wdev_lock(wdev);
13138 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13139 wdev_unlock(wdev);
13140
13141 return err;
13142}
13143
13144static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13145 struct genl_info *info)
13146{
13147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13148 struct net_device *dev = info->user_ptr[1];
13149 struct wireless_dev *wdev = dev->ieee80211_ptr;
13150 const u8 *addr;
13151
13152 if (!rdev->ops->tdls_channel_switch ||
13153 !rdev->ops->tdls_cancel_channel_switch ||
13154 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13155 return -EOPNOTSUPP;
13156
13157 switch (dev->ieee80211_ptr->iftype) {
13158 case NL80211_IFTYPE_STATION:
13159 case NL80211_IFTYPE_P2P_CLIENT:
13160 break;
13161 default:
13162 return -EOPNOTSUPP;
13163 }
13164
13165 if (!info->attrs[NL80211_ATTR_MAC])
13166 return -EINVAL;
13167
13168 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13169
13170 wdev_lock(wdev);
13171 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13172 wdev_unlock(wdev);
13173
13174 return 0;
13175}
13176
Michael Braunce0ce132016-10-10 19:12:22 +020013177static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13178 struct genl_info *info)
13179{
13180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13181 struct net_device *dev = info->user_ptr[1];
13182 struct wireless_dev *wdev = dev->ieee80211_ptr;
13183 const struct nlattr *nla;
13184 bool enabled;
13185
Michael Braunce0ce132016-10-10 19:12:22 +020013186 if (!rdev->ops->set_multicast_to_unicast)
13187 return -EOPNOTSUPP;
13188
13189 if (wdev->iftype != NL80211_IFTYPE_AP &&
13190 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13191 return -EOPNOTSUPP;
13192
13193 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13194 enabled = nla_get_flag(nla);
13195
13196 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13197}
13198
Avraham Stern3a00df52017-06-09 13:08:43 +010013199static int nl80211_set_pmk(struct sk_buff *skb, 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 struct cfg80211_pmk_conf pmk_conf = {};
13205 int ret;
13206
13207 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13208 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13209 return -EOPNOTSUPP;
13210
13211 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13212 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13213 return -EOPNOTSUPP;
13214
13215 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13216 return -EINVAL;
13217
13218 wdev_lock(wdev);
13219 if (!wdev->current_bss) {
13220 ret = -ENOTCONN;
13221 goto out;
13222 }
13223
13224 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13225 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13226 ret = -EINVAL;
13227 goto out;
13228 }
13229
13230 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13231 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13232 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13233 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13234 ret = -EINVAL;
13235 goto out;
13236 }
13237
13238 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13239 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13240
13241 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13242 ret = -EINVAL;
13243 goto out;
13244 }
13245
13246 pmk_conf.pmk_r0_name =
13247 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13248 }
13249
13250 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13251out:
13252 wdev_unlock(wdev);
13253 return ret;
13254}
13255
13256static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13257{
13258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13259 struct net_device *dev = info->user_ptr[1];
13260 struct wireless_dev *wdev = dev->ieee80211_ptr;
13261 const u8 *aa;
13262 int ret;
13263
13264 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13265 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13266 return -EOPNOTSUPP;
13267
13268 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13269 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13270 return -EOPNOTSUPP;
13271
13272 if (!info->attrs[NL80211_ATTR_MAC])
13273 return -EINVAL;
13274
13275 wdev_lock(wdev);
13276 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13277 ret = rdev_del_pmk(rdev, dev, aa);
13278 wdev_unlock(wdev);
13279
13280 return ret;
13281}
13282
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013283static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13284{
13285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13286 struct net_device *dev = info->user_ptr[1];
13287 struct cfg80211_external_auth_params params;
13288
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013289 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013290 return -EOPNOTSUPP;
13291
Srinivas Dasarife494372019-01-23 18:06:56 +053013292 if (!info->attrs[NL80211_ATTR_SSID] &&
13293 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013295 return -EINVAL;
13296
13297 if (!info->attrs[NL80211_ATTR_BSSID])
13298 return -EINVAL;
13299
13300 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13301 return -EINVAL;
13302
13303 memset(&params, 0, sizeof(params));
13304
Srinivas Dasarife494372019-01-23 18:06:56 +053013305 if (info->attrs[NL80211_ATTR_SSID]) {
13306 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13307 if (params.ssid.ssid_len == 0 ||
13308 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13309 return -EINVAL;
13310 memcpy(params.ssid.ssid,
13311 nla_data(info->attrs[NL80211_ATTR_SSID]),
13312 params.ssid.ssid_len);
13313 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013314
13315 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13316 ETH_ALEN);
13317
13318 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13319
Srinivas Dasarife494372019-01-23 18:06:56 +053013320 if (info->attrs[NL80211_ATTR_PMKID])
13321 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13322
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013323 return rdev_external_auth(rdev, dev, &params);
13324}
13325
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013326static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13327{
13328 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13329 struct net_device *dev = info->user_ptr[1];
13330 struct wireless_dev *wdev = dev->ieee80211_ptr;
13331 const u8 *buf;
13332 size_t len;
13333 u8 *dest;
13334 u16 proto;
13335 bool noencrypt;
13336 int err;
13337
13338 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13339 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13340 return -EOPNOTSUPP;
13341
13342 if (!rdev->ops->tx_control_port)
13343 return -EOPNOTSUPP;
13344
13345 if (!info->attrs[NL80211_ATTR_FRAME] ||
13346 !info->attrs[NL80211_ATTR_MAC] ||
13347 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13348 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13349 return -EINVAL;
13350 }
13351
13352 wdev_lock(wdev);
13353
13354 switch (wdev->iftype) {
13355 case NL80211_IFTYPE_AP:
13356 case NL80211_IFTYPE_P2P_GO:
13357 case NL80211_IFTYPE_MESH_POINT:
13358 break;
13359 case NL80211_IFTYPE_ADHOC:
13360 case NL80211_IFTYPE_STATION:
13361 case NL80211_IFTYPE_P2P_CLIENT:
13362 if (wdev->current_bss)
13363 break;
13364 err = -ENOTCONN;
13365 goto out;
13366 default:
13367 err = -EOPNOTSUPP;
13368 goto out;
13369 }
13370
13371 wdev_unlock(wdev);
13372
13373 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13374 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13375 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13376 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13377 noencrypt =
13378 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13379
13380 return rdev_tx_control_port(rdev, dev, buf, len,
13381 dest, cpu_to_be16(proto), noencrypt);
13382
13383 out:
13384 wdev_unlock(wdev);
13385 return err;
13386}
13387
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013388static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13389 struct genl_info *info)
13390{
13391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13392 struct net_device *dev = info->user_ptr[1];
13393 struct wireless_dev *wdev = dev->ieee80211_ptr;
13394 struct cfg80211_ftm_responder_stats ftm_stats = {};
13395 struct sk_buff *msg;
13396 void *hdr;
13397 struct nlattr *ftm_stats_attr;
13398 int err;
13399
13400 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13401 return -EOPNOTSUPP;
13402
13403 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13404 if (err)
13405 return err;
13406
13407 if (!ftm_stats.filled)
13408 return -ENODATA;
13409
13410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13411 if (!msg)
13412 return -ENOMEM;
13413
13414 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13415 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13416 if (!hdr)
13417 return -ENOBUFS;
13418
13419 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13420 goto nla_put_failure;
13421
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013422 ftm_stats_attr = nla_nest_start_noflag(msg,
13423 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013424 if (!ftm_stats_attr)
13425 goto nla_put_failure;
13426
13427#define SET_FTM(field, name, type) \
13428 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13429 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13430 ftm_stats.field)) \
13431 goto nla_put_failure; } while (0)
13432#define SET_FTM_U64(field, name) \
13433 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13434 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13435 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13436 goto nla_put_failure; } while (0)
13437
13438 SET_FTM(success_num, SUCCESS_NUM, u32);
13439 SET_FTM(partial_num, PARTIAL_NUM, u32);
13440 SET_FTM(failed_num, FAILED_NUM, u32);
13441 SET_FTM(asap_num, ASAP_NUM, u32);
13442 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13443 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13444 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13445 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13446 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13447#undef SET_FTM
13448
13449 nla_nest_end(msg, ftm_stats_attr);
13450
13451 genlmsg_end(msg, hdr);
13452 return genlmsg_reply(msg, info);
13453
13454nla_put_failure:
13455 nlmsg_free(msg);
13456 return -ENOBUFS;
13457}
13458
Sunil Duttcb74e972019-02-20 16:18:07 +053013459static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13460{
13461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13462 struct cfg80211_update_owe_info owe_info;
13463 struct net_device *dev = info->user_ptr[1];
13464
13465 if (!rdev->ops->update_owe_info)
13466 return -EOPNOTSUPP;
13467
13468 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13469 !info->attrs[NL80211_ATTR_MAC])
13470 return -EINVAL;
13471
13472 memset(&owe_info, 0, sizeof(owe_info));
13473 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13474 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13475
13476 if (info->attrs[NL80211_ATTR_IE]) {
13477 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13478 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13479 }
13480
13481 return rdev_update_owe_info(rdev, dev, &owe_info);
13482}
13483
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013484static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13485{
13486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13487 struct net_device *dev = info->user_ptr[1];
13488 struct wireless_dev *wdev = dev->ieee80211_ptr;
13489 struct station_info sinfo = {};
13490 const u8 *buf;
13491 size_t len;
13492 u8 *dest;
13493 int err;
13494
13495 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13496 return -EOPNOTSUPP;
13497
13498 if (!info->attrs[NL80211_ATTR_MAC] ||
13499 !info->attrs[NL80211_ATTR_FRAME]) {
13500 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13501 return -EINVAL;
13502 }
13503
13504 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13505 return -EOPNOTSUPP;
13506
13507 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13508 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13509 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13510
13511 if (len < sizeof(struct ethhdr))
13512 return -EINVAL;
13513
13514 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13515 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13516 return -EINVAL;
13517
13518 err = rdev_get_station(rdev, dev, dest, &sinfo);
13519 if (err)
13520 return err;
13521
13522 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13523}
13524
Johannes Berg4c476992010-10-04 21:36:35 +020013525#define NL80211_FLAG_NEED_WIPHY 0x01
13526#define NL80211_FLAG_NEED_NETDEV 0x02
13527#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013528#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13529#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13530 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013531#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013532/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013533#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13534 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013535#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013536
Johannes Bergf84f7712013-11-14 17:14:45 +010013537static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013538 struct genl_info *info)
13539{
13540 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013541 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013542 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013543 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13544
13545 if (rtnl)
13546 rtnl_lock();
13547
13548 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013549 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013550 if (IS_ERR(rdev)) {
13551 if (rtnl)
13552 rtnl_unlock();
13553 return PTR_ERR(rdev);
13554 }
13555 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013556 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13557 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013558 ASSERT_RTNL();
13559
Johannes Berg89a54e42012-06-15 14:33:17 +020013560 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13561 info->attrs);
13562 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013563 if (rtnl)
13564 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013565 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013566 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013567
Johannes Berg89a54e42012-06-15 14:33:17 +020013568 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013569 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013570
Johannes Berg1bf614e2012-06-15 15:23:36 +020013571 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13572 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013573 if (rtnl)
13574 rtnl_unlock();
13575 return -EINVAL;
13576 }
13577
13578 info->user_ptr[1] = dev;
13579 } else {
13580 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013581 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013582
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013583 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13584 !wdev_running(wdev)) {
13585 if (rtnl)
13586 rtnl_unlock();
13587 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013588 }
13589
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013590 if (dev)
13591 dev_hold(dev);
13592
Johannes Berg4c476992010-10-04 21:36:35 +020013593 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013594 }
13595
13596 return 0;
13597}
13598
Johannes Bergf84f7712013-11-14 17:14:45 +010013599static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013600 struct genl_info *info)
13601{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013602 if (info->user_ptr[1]) {
13603 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13604 struct wireless_dev *wdev = info->user_ptr[1];
13605
13606 if (wdev->netdev)
13607 dev_put(wdev->netdev);
13608 } else {
13609 dev_put(info->user_ptr[1]);
13610 }
13611 }
Johannes Berg5393b912014-09-10 15:00:16 +030013612
Johannes Berg4c476992010-10-04 21:36:35 +020013613 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13614 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013615
13616 /* If needed, clear the netlink message payload from the SKB
13617 * as it might contain key data that shouldn't stick around on
13618 * the heap after the SKB is freed. The netlink message header
13619 * is still needed for further processing, so leave it intact.
13620 */
13621 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13622 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13623
13624 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13625 }
Johannes Berg4c476992010-10-04 21:36:35 +020013626}
13627
Johannes Berg4534de82013-11-14 17:14:46 +010013628static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013629 {
13630 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013631 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013632 .doit = nl80211_get_wiphy,
13633 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013634 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013635 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013636 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13637 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013638 },
13639 {
13640 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013641 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013642 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013643 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013644 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013645 },
13646 {
13647 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013648 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013649 .doit = nl80211_get_interface,
13650 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040013651 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013652 .internal_flags = NL80211_FLAG_NEED_WDEV |
13653 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013654 },
13655 {
13656 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013657 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013658 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013659 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013660 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13661 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013662 },
13663 {
13664 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013665 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013666 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013667 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013668 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13669 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013670 },
13671 {
13672 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013673 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040013674 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020013675 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013676 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013677 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013678 },
Johannes Berg41ade002007-12-19 02:03:29 +010013679 {
13680 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013681 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013682 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013683 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013685 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013686 },
13687 {
13688 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013689 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013690 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013691 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013693 NL80211_FLAG_NEED_RTNL |
13694 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013695 },
13696 {
13697 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013698 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013699 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013700 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013702 NL80211_FLAG_NEED_RTNL |
13703 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013704 },
13705 {
13706 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013707 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010013708 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020013709 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013710 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013711 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013712 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013713 {
13714 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020013715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013716 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013717 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013718 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013719 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013720 },
13721 {
Johannes Berg88600202012-02-13 15:17:18 +010013722 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013723 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013724 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013725 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013726 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013727 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013728 },
13729 {
Johannes Berg88600202012-02-13 15:17:18 +010013730 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013731 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020013732 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013733 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013734 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013735 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013736 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013737 {
13738 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013739 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013740 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013741 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020013742 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13743 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013744 },
13745 {
13746 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013747 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013748 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013749 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013750 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013751 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013752 },
13753 {
13754 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013755 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013756 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013757 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013758 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013759 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013760 },
13761 {
13762 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020013763 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010013764 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020013765 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013766 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013767 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013768 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013769 {
13770 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013771 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013772 .doit = nl80211_get_mpath,
13773 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013774 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013776 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013777 },
13778 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013779 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020013780 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020013781 .doit = nl80211_get_mpp,
13782 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020013783 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13785 NL80211_FLAG_NEED_RTNL,
13786 },
13787 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013788 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013789 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013790 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013791 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013793 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013794 },
13795 {
13796 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013797 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013798 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013799 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013801 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013802 },
13803 {
13804 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020013805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013806 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020013807 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013808 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013809 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013810 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013811 {
13812 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013814 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020013815 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013817 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013818 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013819 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013820 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013822 .doit = nl80211_get_reg_do,
13823 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013824 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013825 /* can be retrieved by unprivileged users */
13826 },
Johannes Bergb6863032015-10-15 09:25:18 +020013827#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013828 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013829 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013830 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013831 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013832 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013833 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013834 },
Johannes Bergb6863032015-10-15 09:25:18 +020013835#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013836 {
13837 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013838 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013839 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013840 .flags = GENL_ADMIN_PERM,
13841 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013842 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013843 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020013844 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013845 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013846 .flags = GENL_ADMIN_PERM,
13847 },
13848 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013849 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013850 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013851 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013852 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013854 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013855 },
13856 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013857 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020013858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013859 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020013860 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013862 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013863 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013864 {
Johannes Berg2a519312009-02-10 21:25:55 +010013865 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010013867 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013868 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013869 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013870 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013871 },
13872 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013873 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013874 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013875 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013876 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013877 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13878 NL80211_FLAG_NEED_RTNL,
13879 },
13880 {
Johannes Berg2a519312009-02-10 21:25:55 +010013881 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013882 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010013883 .dumpit = nl80211_dump_scan,
13884 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013885 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013886 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013887 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013888 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013889 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013890 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13891 NL80211_FLAG_NEED_RTNL,
13892 },
13893 {
13894 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020013895 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013896 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020013897 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13899 NL80211_FLAG_NEED_RTNL,
13900 },
13901 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013902 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013904 .doit = nl80211_authenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013905 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013906 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013907 NL80211_FLAG_NEED_RTNL |
13908 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013909 },
13910 {
13911 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013912 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013913 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013914 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053013916 NL80211_FLAG_NEED_RTNL |
13917 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013918 },
13919 {
13920 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013921 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013922 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013923 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013925 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013926 },
13927 {
13928 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013929 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013930 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020013931 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013932 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013933 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013934 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013935 {
13936 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013937 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020013938 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020013939 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013940 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013941 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013942 },
13943 {
13944 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013945 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020013946 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020013947 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013949 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013950 },
Johannes Bergaff89a92009-07-01 21:26:51 +020013951#ifdef CONFIG_NL80211_TESTMODE
13952 {
13953 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020013954 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020013955 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070013956 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020013957 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013958 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13959 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020013960 },
13961#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020013962 {
13963 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020013964 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013965 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020013966 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053013968 NL80211_FLAG_NEED_RTNL |
13969 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013970 },
13971 {
vamsi krishna088e8df2016-10-27 16:51:11 +030013972 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013973 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030013974 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030013975 .flags = GENL_ADMIN_PERM,
13976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053013977 NL80211_FLAG_NEED_RTNL |
13978 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030013979 },
13980 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020013981 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020013982 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013983 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020013984 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013985 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013986 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013987 },
Johannes Berg463d0182009-07-14 00:33:35 +020013988 {
13989 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020013990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020013991 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020013992 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013993 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13994 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013995 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013996 {
13997 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020013998 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010013999 .dumpit = nl80211_dump_survey,
14000 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014001 {
14002 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014003 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014004 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014005 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014007 NL80211_FLAG_NEED_RTNL |
14008 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014009 },
14010 {
14011 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014012 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014013 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014014 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014016 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014017 },
14018 {
14019 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014020 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014021 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014022 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014024 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014025 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014026 {
14027 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014028 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014029 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014030 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014031 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014032 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014033 },
14034 {
14035 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014036 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014037 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014038 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014039 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014040 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014041 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014042 {
14043 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014044 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014045 .doit = nl80211_set_tx_bitrate_mask,
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_NETDEV |
14048 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014049 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014050 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014051 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014052 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014053 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014054 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014055 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014056 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014057 },
14058 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014059 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014060 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014061 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014062 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014063 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014064 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014065 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014066 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014067 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014068 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014069 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014070 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014071 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014072 NL80211_FLAG_NEED_RTNL,
14073 },
14074 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014075 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014076 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014077 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014078 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014079 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14080 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014081 },
14082 {
14083 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014084 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014085 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014086 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020014087 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14088 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014089 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014090 {
14091 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020014092 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014093 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020014094 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014095 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14096 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014097 },
Johannes Bergf444de02010-05-05 15:25:02 +020014098 {
14099 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020014101 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014102 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014103 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14104 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020014105 },
Bill Jordane8347eb2010-10-01 13:54:28 -040014106 {
14107 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014108 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040014109 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020014110 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020014111 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14112 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040014113 },
Johannes Berg29cbe682010-12-03 09:20:44 +010014114 {
14115 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014116 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014117 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014118 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014119 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14120 NL80211_FLAG_NEED_RTNL,
14121 },
14122 {
14123 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014124 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014125 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014126 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014127 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14128 NL80211_FLAG_NEED_RTNL,
14129 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014130 {
14131 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014132 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014133 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014134 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014135 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14136 NL80211_FLAG_NEED_RTNL,
14137 },
14138 {
14139 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014140 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014141 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014142 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14144 NL80211_FLAG_NEED_RTNL,
14145 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014146#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020014147 {
14148 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014149 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014150 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014151 /* can be retrieved by unprivileged users */
14152 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14153 NL80211_FLAG_NEED_RTNL,
14154 },
14155 {
14156 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014157 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014158 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014159 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014160 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14161 NL80211_FLAG_NEED_RTNL,
14162 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014163#endif
Johannes Berge5497d72011-07-05 16:35:40 +020014164 {
14165 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020014166 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020014167 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020014168 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020014169 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014170 NL80211_FLAG_NEED_RTNL |
14171 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020014172 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030014173 {
14174 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014176 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014177 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14179 NL80211_FLAG_NEED_RTNL,
14180 },
14181 {
14182 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014183 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014184 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020014185 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14187 NL80211_FLAG_NEED_RTNL,
14188 },
Johannes Berg28946da2011-11-04 11:18:12 +010014189 {
14190 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014191 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010014192 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020014193 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010014194 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14195 NL80211_FLAG_NEED_RTNL,
14196 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010014197 {
14198 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014199 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010014200 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020014201 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014202 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010014203 NL80211_FLAG_NEED_RTNL,
14204 },
Johannes Berg5e760232011-11-04 11:18:17 +010014205 {
14206 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014207 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010014208 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020014209 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010014210 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14211 NL80211_FLAG_NEED_RTNL,
14212 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014213 {
14214 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014215 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014216 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014217 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014218 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14219 NL80211_FLAG_NEED_RTNL,
14220 },
Johannes Berg98104fde2012-06-16 00:19:54 +020014221 {
14222 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014223 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014224 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014225 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014226 .internal_flags = NL80211_FLAG_NEED_WDEV |
14227 NL80211_FLAG_NEED_RTNL,
14228 },
14229 {
14230 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014231 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014232 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014233 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014234 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14235 NL80211_FLAG_NEED_RTNL,
14236 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014237 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014238 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014239 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014240 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014241 .flags = GENL_ADMIN_PERM,
14242 .internal_flags = NL80211_FLAG_NEED_WDEV |
14243 NL80211_FLAG_NEED_RTNL,
14244 },
14245 {
14246 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014247 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014248 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014249 .flags = GENL_ADMIN_PERM,
14250 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14251 NL80211_FLAG_NEED_RTNL,
14252 },
14253 {
Ayala Bekera442b762016-09-20 17:31:15 +030014254 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014255 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014256 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014257 .flags = GENL_ADMIN_PERM,
14258 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14259 NL80211_FLAG_NEED_RTNL,
14260 },
14261 {
14262 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014263 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014264 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014265 .flags = GENL_ADMIN_PERM,
14266 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14267 NL80211_FLAG_NEED_RTNL,
14268 },
14269 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014270 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014271 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014272 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014273 .flags = GENL_ADMIN_PERM,
14274 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14275 NL80211_FLAG_NEED_RTNL,
14276 },
14277 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014278 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014279 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014280 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014281 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014282 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14283 NL80211_FLAG_NEED_RTNL,
14284 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014285 {
14286 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014287 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014288 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020014289 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014290 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14291 NL80211_FLAG_NEED_RTNL,
14292 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014293 {
14294 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014296 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020014297 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14299 NL80211_FLAG_NEED_RTNL,
14300 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014301 {
14302 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014303 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014304 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014305 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014306 {
14307 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014308 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020014309 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020014310 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014311 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14312 NL80211_FLAG_NEED_RTNL,
14313 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014314 {
14315 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014316 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014317 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020014318 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014319 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14320 NL80211_FLAG_NEED_RTNL,
14321 },
14322 {
14323 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014324 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014325 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020014326 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014327 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14328 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014329 },
14330 {
14331 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014332 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014333 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014334 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14335 NL80211_FLAG_NEED_RTNL,
14336 },
14337 {
14338 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014339 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014340 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020014341 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014342 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14343 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014344 },
14345 {
14346 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014347 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014348 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014349 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14351 NL80211_FLAG_NEED_RTNL,
14352 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014353 {
14354 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014355 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010014356 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014357 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014358 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014359 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014360 NL80211_FLAG_NEED_RTNL |
14361 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010014362 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014363 {
14364 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014365 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014366 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014367 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014368 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14369 NL80211_FLAG_NEED_RTNL,
14370 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014371 {
14372 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014373 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014374 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014375 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014376 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14377 NL80211_FLAG_NEED_RTNL,
14378 },
14379 {
14380 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014381 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014382 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014383 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14385 NL80211_FLAG_NEED_RTNL,
14386 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014387 {
14388 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014389 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014390 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014391 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14393 NL80211_FLAG_NEED_RTNL,
14394 },
14395 {
14396 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014397 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014398 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014399 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14401 NL80211_FLAG_NEED_RTNL,
14402 },
Michael Braunce0ce132016-10-10 19:12:22 +020014403 {
14404 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020014405 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020014406 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020014407 .flags = GENL_UNS_ADMIN_PERM,
14408 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14409 NL80211_FLAG_NEED_RTNL,
14410 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014411 {
14412 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014414 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014416 NL80211_FLAG_NEED_RTNL |
14417 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010014418 },
14419 {
14420 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014421 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014422 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014423 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14424 NL80211_FLAG_NEED_RTNL,
14425 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014426 {
14427 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014428 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014429 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014430 .flags = GENL_ADMIN_PERM,
14431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14432 NL80211_FLAG_NEED_RTNL,
14433 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014434 {
14435 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014436 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014437 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014438 .flags = GENL_UNS_ADMIN_PERM,
14439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14440 NL80211_FLAG_NEED_RTNL,
14441 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014442 {
14443 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014444 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014445 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014446 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14447 NL80211_FLAG_NEED_RTNL,
14448 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014449 {
14450 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014451 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014452 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014453 .flags = GENL_UNS_ADMIN_PERM,
14454 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14455 NL80211_FLAG_NEED_RTNL,
14456 },
Sriram R30c63112018-12-04 17:46:52 +053014457 {
14458 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014459 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053014460 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053014461 .flags = GENL_UNS_ADMIN_PERM,
14462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14463 NL80211_FLAG_NEED_RTNL,
14464 },
Sunil Duttcb74e972019-02-20 16:18:07 +053014465 {
14466 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14467 .doit = nl80211_update_owe_info,
14468 .flags = GENL_ADMIN_PERM,
14469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14470 NL80211_FLAG_NEED_RTNL,
14471 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014472 {
14473 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14474 .doit = nl80211_probe_mesh_link,
14475 .flags = GENL_UNS_ADMIN_PERM,
14476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14477 NL80211_FLAG_NEED_RTNL,
14478 },
Johannes Berg55682962007-09-20 13:09:35 -040014479};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014480
Johannes Berg56989f62016-10-24 14:40:05 +020014481static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014482 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14483 .hdrsize = 0, /* no private header */
14484 .version = 1, /* no particular meaning now */
14485 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010014486 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020014487 .netnsok = true,
14488 .pre_doit = nl80211_pre_doit,
14489 .post_doit = nl80211_post_doit,
14490 .module = THIS_MODULE,
14491 .ops = nl80211_ops,
14492 .n_ops = ARRAY_SIZE(nl80211_ops),
14493 .mcgrps = nl80211_mcgrps,
14494 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
14495};
14496
Johannes Berg55682962007-09-20 13:09:35 -040014497/* notification functions */
14498
Johannes Berg3bb20552014-05-26 13:52:25 +020014499void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14500 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014501{
14502 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014503 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014504
Johannes Berg3bb20552014-05-26 13:52:25 +020014505 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14506 cmd != NL80211_CMD_DEL_WIPHY);
14507
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014509 if (!msg)
14510 return;
14511
Johannes Berg3bb20552014-05-26 13:52:25 +020014512 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014513 nlmsg_free(msg);
14514 return;
14515 }
14516
Johannes Berg68eb5502013-11-19 15:19:38 +010014517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014518 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014519}
14520
Denis Kenzior896ff062016-08-03 16:58:33 -050014521void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14522 struct wireless_dev *wdev,
14523 enum nl80211_commands cmd)
14524{
14525 struct sk_buff *msg;
14526
Denis Kenzior896ff062016-08-03 16:58:33 -050014527 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14528 if (!msg)
14529 return;
14530
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014531 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014532 nlmsg_free(msg);
14533 return;
14534 }
14535
14536 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14537 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14538}
14539
Johannes Berg362a4152009-05-24 16:43:15 +020014540static int nl80211_add_scan_req(struct sk_buff *msg,
14541 struct cfg80211_registered_device *rdev)
14542{
14543 struct cfg80211_scan_request *req = rdev->scan_req;
14544 struct nlattr *nest;
14545 int i;
14546
14547 if (WARN_ON(!req))
14548 return 0;
14549
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014550 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020014551 if (!nest)
14552 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014553 for (i = 0; i < req->n_ssids; i++) {
14554 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14555 goto nla_put_failure;
14556 }
Johannes Berg362a4152009-05-24 16:43:15 +020014557 nla_nest_end(msg, nest);
14558
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014559 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Johannes Berg362a4152009-05-24 16:43:15 +020014560 if (!nest)
14561 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014562 for (i = 0; i < req->n_channels; i++) {
14563 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14564 goto nla_put_failure;
14565 }
Johannes Berg362a4152009-05-24 16:43:15 +020014566 nla_nest_end(msg, nest);
14567
David S. Miller9360ffd2012-03-29 04:41:26 -040014568 if (req->ie &&
14569 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14570 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014571
Johannes Bergae917c92013-10-25 11:05:22 +020014572 if (req->flags &&
14573 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14574 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014575
Avraham Stern1d762502016-07-05 17:10:13 +030014576 if (req->info.scan_start_tsf &&
14577 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14578 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14579 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14580 req->info.tsf_bssid)))
14581 goto nla_put_failure;
14582
Johannes Berg362a4152009-05-24 16:43:15 +020014583 return 0;
14584 nla_put_failure:
14585 return -ENOBUFS;
14586}
14587
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014588static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014589 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014590 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014591 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014592 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014593{
14594 void *hdr;
14595
Eric W. Biederman15e47302012-09-07 20:12:54 +000014596 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014597 if (!hdr)
14598 return -1;
14599
David S. Miller9360ffd2012-03-29 04:41:26 -040014600 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014601 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14602 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014603 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14604 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014605 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014606
Johannes Berg362a4152009-05-24 16:43:15 +020014607 /* ignore errors and send incomplete event anyway */
14608 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014609
Johannes Berg053c0952015-01-16 22:09:00 +010014610 genlmsg_end(msg, hdr);
14611 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014612
14613 nla_put_failure:
14614 genlmsg_cancel(msg, hdr);
14615 return -EMSGSIZE;
14616}
14617
Luciano Coelho807f8a82011-05-11 17:09:35 +030014618static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014619nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014620 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014621{
14622 void *hdr;
14623
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014624 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014625 if (!hdr)
14626 return -1;
14627
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14629 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14630 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14631 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14632 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014633 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014634
Johannes Berg053c0952015-01-16 22:09:00 +010014635 genlmsg_end(msg, hdr);
14636 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014637
14638 nla_put_failure:
14639 genlmsg_cancel(msg, hdr);
14640 return -EMSGSIZE;
14641}
14642
Johannes Berga538e2d2009-06-16 19:56:42 +020014643void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014644 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014645{
14646 struct sk_buff *msg;
14647
Thomas Graf58050fc2012-06-28 03:57:45 +000014648 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014649 if (!msg)
14650 return;
14651
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014652 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014653 NL80211_CMD_TRIGGER_SCAN) < 0) {
14654 nlmsg_free(msg);
14655 return;
14656 }
14657
Johannes Berg68eb5502013-11-19 15:19:38 +010014658 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014659 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014660}
14661
Johannes Bergf9d15d12014-01-22 11:14:19 +020014662struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14663 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014664{
14665 struct sk_buff *msg;
14666
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014668 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014669 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014670
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014671 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014672 aborted ? NL80211_CMD_SCAN_ABORTED :
14673 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014674 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014675 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014676 }
14677
Johannes Bergf9d15d12014-01-22 11:14:19 +020014678 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014679}
14680
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014681/* send message created by nl80211_build_scan_msg() */
14682void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14683 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014684{
Johannes Berg2a519312009-02-10 21:25:55 +010014685 if (!msg)
14686 return;
14687
Johannes Berg68eb5502013-11-19 15:19:38 +010014688 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014689 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014690}
14691
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014692void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014693{
14694 struct sk_buff *msg;
14695
Thomas Graf58050fc2012-06-28 03:57:45 +000014696 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014697 if (!msg)
14698 return;
14699
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014700 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014701 nlmsg_free(msg);
14702 return;
14703 }
14704
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014705 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014706 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014707}
14708
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014709static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14710 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014711{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014712 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014713 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14714 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014715
David S. Miller9360ffd2012-03-29 04:41:26 -040014716 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14717 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14718 NL80211_REGDOM_TYPE_WORLD))
14719 goto nla_put_failure;
14720 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14721 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14722 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14723 goto nla_put_failure;
14724 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14725 request->intersect) {
14726 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14727 NL80211_REGDOM_TYPE_INTERSECTION))
14728 goto nla_put_failure;
14729 } else {
14730 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14731 NL80211_REGDOM_TYPE_COUNTRY) ||
14732 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14733 request->alpha2))
14734 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014735 }
14736
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014737 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14738 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14739
14740 if (wiphy &&
14741 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14742 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014743
14744 if (wiphy &&
14745 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14746 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14747 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014748 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014749
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014750 return true;
14751
14752nla_put_failure:
14753 return false;
14754}
14755
14756/*
14757 * This can happen on global regulatory changes or device specific settings
14758 * based on custom regulatory domains.
14759 */
14760void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14761 struct regulatory_request *request)
14762{
14763 struct sk_buff *msg;
14764 void *hdr;
14765
14766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14767 if (!msg)
14768 return;
14769
14770 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14771 if (!hdr) {
14772 nlmsg_free(msg);
14773 return;
14774 }
14775
14776 if (nl80211_reg_change_event_fill(msg, request) == false)
14777 goto nla_put_failure;
14778
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014779 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014780
Johannes Bergbc43b282009-07-25 10:54:13 +020014781 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014782 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014783 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014784 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014785
14786 return;
14787
14788nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014789 nlmsg_free(msg);
14790}
14791
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014792static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14793 struct net_device *netdev,
14794 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014795 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014796 int uapsd_queues, const u8 *req_ies,
14797 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014798{
14799 struct sk_buff *msg;
14800 void *hdr;
14801
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014802 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014803 if (!msg)
14804 return;
14805
14806 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14807 if (!hdr) {
14808 nlmsg_free(msg);
14809 return;
14810 }
14811
David S. Miller9360ffd2012-03-29 04:41:26 -040014812 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14813 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014814 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14815 (req_ies &&
14816 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014817 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014818
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014819 if (uapsd_queues >= 0) {
14820 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014821 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014822 if (!nla_wmm)
14823 goto nla_put_failure;
14824
14825 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14826 uapsd_queues))
14827 goto nla_put_failure;
14828
14829 nla_nest_end(msg, nla_wmm);
14830 }
14831
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014832 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014833
Johannes Berg68eb5502013-11-19 15:19:38 +010014834 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014835 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014836 return;
14837
14838 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014839 nlmsg_free(msg);
14840}
14841
14842void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014843 struct net_device *netdev, const u8 *buf,
14844 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014845{
14846 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014847 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014848}
14849
14850void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14851 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014852 size_t len, gfp_t gfp, int uapsd_queues,
14853 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014854{
Johannes Berge6d6e342009-07-01 21:26:47 +020014855 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014856 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
14857 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014858}
14859
Jouni Malinen53b46b82009-03-27 20:53:56 +020014860void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014861 struct net_device *netdev, const u8 *buf,
14862 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014863{
14864 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014865 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014866}
14867
Jouni Malinen53b46b82009-03-27 20:53:56 +020014868void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14869 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014870 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014871{
14872 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014873 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014874}
14875
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014876void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14877 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014878{
Johannes Berg947add32013-02-22 22:05:20 +010014879 struct wireless_dev *wdev = dev->ieee80211_ptr;
14880 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014881 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014882 const struct ieee80211_mgmt *mgmt = (void *)buf;
14883 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014884
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014885 if (WARN_ON(len < 2))
14886 return;
14887
14888 if (ieee80211_is_deauth(mgmt->frame_control))
14889 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14890 else
14891 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14892
14893 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020014894 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
14895 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014896}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014897EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014898
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014899static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14900 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014901 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014902{
14903 struct sk_buff *msg;
14904 void *hdr;
14905
Johannes Berge6d6e342009-07-01 21:26:47 +020014906 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014907 if (!msg)
14908 return;
14909
14910 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14911 if (!hdr) {
14912 nlmsg_free(msg);
14913 return;
14914 }
14915
David S. Miller9360ffd2012-03-29 04:41:26 -040014916 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14917 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14918 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14919 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14920 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014921
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014922 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014923
Johannes Berg68eb5502013-11-19 15:19:38 +010014924 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014925 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014926 return;
14927
14928 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014929 nlmsg_free(msg);
14930}
14931
14932void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014933 struct net_device *netdev, const u8 *addr,
14934 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014935{
14936 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014937 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014938}
14939
14940void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014941 struct net_device *netdev, const u8 *addr,
14942 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014943{
Johannes Berge6d6e342009-07-01 21:26:47 +020014944 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14945 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014946}
14947
Samuel Ortizb23aa672009-07-01 21:26:54 +020014948void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014949 struct net_device *netdev,
14950 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014951 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014952{
14953 struct sk_buff *msg;
14954 void *hdr;
14955
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014956 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020014957 cr->fils.kek_len + cr->fils.pmk_len +
14958 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014959 if (!msg)
14960 return;
14961
14962 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
14963 if (!hdr) {
14964 nlmsg_free(msg);
14965 return;
14966 }
14967
David S. Miller9360ffd2012-03-29 04:41:26 -040014968 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14969 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014970 (cr->bssid &&
14971 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030014972 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014973 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
14974 cr->status) ||
14975 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014976 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014977 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
14978 cr->timeout_reason))) ||
14979 (cr->req_ie &&
14980 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
14981 (cr->resp_ie &&
14982 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014983 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020014984 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014985 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020014986 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014987 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020014988 ((cr->fils.kek &&
14989 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
14990 cr->fils.kek)) ||
14991 (cr->fils.pmk &&
14992 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
14993 (cr->fils.pmkid &&
14994 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040014995 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014996
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014997 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014998
Johannes Berg68eb5502013-11-19 15:19:38 +010014999 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015000 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015001 return;
15002
15003 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015004 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015005}
15006
15007void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015008 struct net_device *netdev,
15009 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015010{
15011 struct sk_buff *msg;
15012 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015013 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015014
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015015 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15016 info->fils.kek_len + info->fils.pmk_len +
15017 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015018 if (!msg)
15019 return;
15020
15021 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15022 if (!hdr) {
15023 nlmsg_free(msg);
15024 return;
15025 }
15026
David S. Miller9360ffd2012-03-29 04:41:26 -040015027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15028 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15029 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015030 (info->req_ie &&
15031 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15032 info->req_ie)) ||
15033 (info->resp_ie &&
15034 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015035 info->resp_ie)) ||
15036 (info->fils.update_erp_next_seq_num &&
15037 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15038 info->fils.erp_next_seq_num)) ||
15039 (info->fils.kek &&
15040 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15041 info->fils.kek)) ||
15042 (info->fils.pmk &&
15043 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15044 (info->fils.pmkid &&
15045 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015046 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015047
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015048 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015049
Johannes Berg68eb5502013-11-19 15:19:38 +010015050 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015051 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015052 return;
15053
15054 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015055 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015056}
15057
Avraham Stern503c1fb2017-09-29 14:21:49 +020015058void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15059 struct net_device *netdev, const u8 *bssid)
15060{
15061 struct sk_buff *msg;
15062 void *hdr;
15063
15064 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15065 if (!msg)
15066 return;
15067
15068 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15069 if (!hdr) {
15070 nlmsg_free(msg);
15071 return;
15072 }
15073
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000015074 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15075 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15076 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020015077 goto nla_put_failure;
15078
15079 genlmsg_end(msg, hdr);
15080
15081 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15082 NL80211_MCGRP_MLME, GFP_KERNEL);
15083 return;
15084
15085 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020015086 nlmsg_free(msg);
15087}
15088
Samuel Ortizb23aa672009-07-01 21:26:54 +020015089void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15090 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020015091 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015092{
15093 struct sk_buff *msg;
15094 void *hdr;
15095
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015096 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015097 if (!msg)
15098 return;
15099
15100 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15101 if (!hdr) {
15102 nlmsg_free(msg);
15103 return;
15104 }
15105
David S. Miller9360ffd2012-03-29 04:41:26 -040015106 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020015108 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040015109 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15110 (from_ap &&
15111 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15112 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15113 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015114
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015115 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015116
Johannes Berg68eb5502013-11-19 15:19:38 +010015117 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015118 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015119 return;
15120
15121 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015122 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015123}
15124
Johannes Berg04a773a2009-04-19 21:24:32 +020015125void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15126 struct net_device *netdev, const u8 *bssid,
15127 gfp_t gfp)
15128{
15129 struct sk_buff *msg;
15130 void *hdr;
15131
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015133 if (!msg)
15134 return;
15135
15136 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15137 if (!hdr) {
15138 nlmsg_free(msg);
15139 return;
15140 }
15141
David S. Miller9360ffd2012-03-29 04:41:26 -040015142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15143 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15145 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020015146
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015147 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020015148
Johannes Berg68eb5502013-11-19 15:19:38 +010015149 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015150 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015151 return;
15152
15153 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020015154 nlmsg_free(msg);
15155}
15156
Johannes Berg947add32013-02-22 22:05:20 +010015157void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040015158 const u8 *ie, u8 ie_len,
15159 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070015160{
Johannes Berg947add32013-02-22 22:05:20 +010015161 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015162 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015163 struct sk_buff *msg;
15164 void *hdr;
15165
Johannes Berg947add32013-02-22 22:05:20 +010015166 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15167 return;
15168
15169 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15170
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015171 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015172 if (!msg)
15173 return;
15174
15175 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15176 if (!hdr) {
15177 nlmsg_free(msg);
15178 return;
15179 }
15180
David S. Miller9360ffd2012-03-29 04:41:26 -040015181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015182 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15183 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015184 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040015185 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15186 (sig_dbm &&
15187 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015188 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070015189
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015190 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015191
Johannes Berg68eb5502013-11-19 15:19:38 +010015192 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015193 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015194 return;
15195
15196 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070015197 nlmsg_free(msg);
15198}
Johannes Berg947add32013-02-22 22:05:20 +010015199EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015200
Jouni Malinena3b8b052009-03-27 21:59:49 +020015201void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15202 struct net_device *netdev, const u8 *addr,
15203 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020015204 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020015205{
15206 struct sk_buff *msg;
15207 void *hdr;
15208
Johannes Berge6d6e342009-07-01 21:26:47 +020015209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015210 if (!msg)
15211 return;
15212
15213 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15214 if (!hdr) {
15215 nlmsg_free(msg);
15216 return;
15217 }
15218
David S. Miller9360ffd2012-03-29 04:41:26 -040015219 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15220 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15221 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15222 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15223 (key_id != -1 &&
15224 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15225 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15226 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020015227
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015228 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015229
Johannes Berg68eb5502013-11-19 15:19:38 +010015230 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015231 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015232 return;
15233
15234 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020015235 nlmsg_free(msg);
15236}
15237
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015238void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15239 struct ieee80211_channel *channel_before,
15240 struct ieee80211_channel *channel_after)
15241{
15242 struct sk_buff *msg;
15243 void *hdr;
15244 struct nlattr *nl_freq;
15245
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015246 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015247 if (!msg)
15248 return;
15249
15250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15251 if (!hdr) {
15252 nlmsg_free(msg);
15253 return;
15254 }
15255
15256 /*
15257 * Since we are applying the beacon hint to a wiphy we know its
15258 * wiphy_idx is valid
15259 */
David S. Miller9360ffd2012-03-29 04:41:26 -040015260 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15261 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015262
15263 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015264 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015265 if (!nl_freq)
15266 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015267
15268 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015269 goto nla_put_failure;
15270 nla_nest_end(msg, nl_freq);
15271
15272 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015273 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015274 if (!nl_freq)
15275 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015276
15277 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015278 goto nla_put_failure;
15279 nla_nest_end(msg, nl_freq);
15280
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015281 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015282
Johannes Berg463d0182009-07-14 00:33:35 +020015283 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015284 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015285 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020015286 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015287
15288 return;
15289
15290nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015291 nlmsg_free(msg);
15292}
15293
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015294static void nl80211_send_remain_on_chan_event(
15295 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015296 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015297 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015298 unsigned int duration, gfp_t gfp)
15299{
15300 struct sk_buff *msg;
15301 void *hdr;
15302
15303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15304 if (!msg)
15305 return;
15306
15307 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15308 if (!hdr) {
15309 nlmsg_free(msg);
15310 return;
15311 }
15312
David S. Miller9360ffd2012-03-29 04:41:26 -040015313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015314 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15315 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015316 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15317 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015318 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015319 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15320 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015321 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15322 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015323 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015324
David S. Miller9360ffd2012-03-29 04:41:26 -040015325 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15326 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15327 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015328
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015329 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015330
Johannes Berg68eb5502013-11-19 15:19:38 +010015331 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015332 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015333 return;
15334
15335 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015336 nlmsg_free(msg);
15337}
15338
Johannes Berg947add32013-02-22 22:05:20 +010015339void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15340 struct ieee80211_channel *chan,
15341 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015342{
Johannes Berg947add32013-02-22 22:05:20 +010015343 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015344 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015345
15346 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015347 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015348 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015349 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015350}
Johannes Berg947add32013-02-22 22:05:20 +010015351EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015352
Johannes Berg947add32013-02-22 22:05:20 +010015353void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15354 struct ieee80211_channel *chan,
15355 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015356{
Johannes Berg947add32013-02-22 22:05:20 +010015357 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015358 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015359
15360 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015361 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015362 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015363}
Johannes Berg947add32013-02-22 22:05:20 +010015364EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015365
Johannes Berg947add32013-02-22 22:05:20 +010015366void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15367 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015368{
Johannes Berg947add32013-02-22 22:05:20 +010015369 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015370 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015371 struct sk_buff *msg;
15372
Johannes Berg947add32013-02-22 22:05:20 +010015373 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15374
Thomas Graf58050fc2012-06-28 03:57:45 +000015375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015376 if (!msg)
15377 return;
15378
Johannes Bergcf5ead82014-11-14 17:14:00 +010015379 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015380 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015381 nlmsg_free(msg);
15382 return;
15383 }
15384
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);
Johannes Berg98b62182009-12-23 13:15:44 +010015387}
Johannes Berg947add32013-02-22 22:05:20 +010015388EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015389
Johannes Bergcf5ead82014-11-14 17:14:00 +010015390void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15391 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015392{
Johannes Berg947add32013-02-22 22:05:20 +010015393 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015394 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015395 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015396 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015397
Johannes Berg73887fd2018-05-18 09:57:55 +020015398 if (!sinfo)
15399 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015400
Johannes Berg947add32013-02-22 22:05:20 +010015401 trace_cfg80211_del_sta(dev, mac_addr);
15402
Thomas Graf58050fc2012-06-28 03:57:45 +000015403 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015404 if (!msg) {
15405 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015406 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015407 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015408
Johannes Bergcf5ead82014-11-14 17:14:00 +010015409 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015410 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015411 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015412 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015413 }
15414
Johannes Berg68eb5502013-11-19 15:19:38 +010015415 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015416 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015417}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015418EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015419
Johannes Berg947add32013-02-22 22:05:20 +010015420void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15421 enum nl80211_connect_failed_reason reason,
15422 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015423{
Johannes Berg947add32013-02-22 22:05:20 +010015424 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015425 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015426 struct sk_buff *msg;
15427 void *hdr;
15428
15429 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15430 if (!msg)
15431 return;
15432
15433 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15434 if (!hdr) {
15435 nlmsg_free(msg);
15436 return;
15437 }
15438
15439 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15440 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15441 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15442 goto nla_put_failure;
15443
15444 genlmsg_end(msg, hdr);
15445
Johannes Berg68eb5502013-11-19 15:19:38 +010015446 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015447 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015448 return;
15449
15450 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015451 nlmsg_free(msg);
15452}
Johannes Berg947add32013-02-22 22:05:20 +010015453EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015454
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015455static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15456 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015457{
15458 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015459 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015460 struct sk_buff *msg;
15461 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015462 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015463
Eric W. Biederman15e47302012-09-07 20:12:54 +000015464 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015465 return false;
15466
15467 msg = nlmsg_new(100, gfp);
15468 if (!msg)
15469 return true;
15470
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015471 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015472 if (!hdr) {
15473 nlmsg_free(msg);
15474 return true;
15475 }
15476
David S. Miller9360ffd2012-03-29 04:41:26 -040015477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15478 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15479 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15480 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015481
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015482 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015483 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015484 return true;
15485
15486 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015487 nlmsg_free(msg);
15488 return true;
15489}
15490
Johannes Berg947add32013-02-22 22:05:20 +010015491bool cfg80211_rx_spurious_frame(struct net_device *dev,
15492 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015493{
Johannes Berg947add32013-02-22 22:05:20 +010015494 struct wireless_dev *wdev = dev->ieee80211_ptr;
15495 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015496
Johannes Berg947add32013-02-22 22:05:20 +010015497 trace_cfg80211_rx_spurious_frame(dev, addr);
15498
15499 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15500 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15501 trace_cfg80211_return_bool(false);
15502 return false;
15503 }
15504 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15505 addr, gfp);
15506 trace_cfg80211_return_bool(ret);
15507 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015508}
Johannes Berg947add32013-02-22 22:05:20 +010015509EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15510
15511bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15512 const u8 *addr, gfp_t gfp)
15513{
15514 struct wireless_dev *wdev = dev->ieee80211_ptr;
15515 bool ret;
15516
15517 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15518
15519 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15520 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15521 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15522 trace_cfg80211_return_bool(false);
15523 return false;
15524 }
15525 ret = __nl80211_unexpected_frame(dev,
15526 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15527 addr, gfp);
15528 trace_cfg80211_return_bool(ret);
15529 return ret;
15530}
15531EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015532
Johannes Berg2e161f782010-08-12 15:38:38 +020015533int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015534 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015535 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015536 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015537{
Johannes Berg71bbc992012-06-15 15:30:18 +020015538 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015539 struct sk_buff *msg;
15540 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015541
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015542 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015543 if (!msg)
15544 return -ENOMEM;
15545
Johannes Berg2e161f782010-08-12 15:38:38 +020015546 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015547 if (!hdr) {
15548 nlmsg_free(msg);
15549 return -ENOMEM;
15550 }
15551
David S. Miller9360ffd2012-03-29 04:41:26 -040015552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015553 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15554 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015555 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15556 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015557 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15558 (sig_dbm &&
15559 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015560 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15561 (flags &&
15562 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015563 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015564
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015565 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015566
Eric W. Biederman15e47302012-09-07 20:12:54 +000015567 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015568
15569 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015570 nlmsg_free(msg);
15571 return -ENOBUFS;
15572}
15573
Johannes Berg947add32013-02-22 22:05:20 +010015574void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15575 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015576{
Johannes Berg947add32013-02-22 22:05:20 +010015577 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015578 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015579 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015580 struct sk_buff *msg;
15581 void *hdr;
15582
Johannes Berg947add32013-02-22 22:05:20 +010015583 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15584
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015585 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015586 if (!msg)
15587 return;
15588
Johannes Berg2e161f782010-08-12 15:38:38 +020015589 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015590 if (!hdr) {
15591 nlmsg_free(msg);
15592 return;
15593 }
15594
David S. Miller9360ffd2012-03-29 04:41:26 -040015595 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015596 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15597 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015598 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15599 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015600 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015601 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15602 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015603 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15604 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015605
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015606 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015607
Johannes Berg68eb5502013-11-19 15:19:38 +010015608 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015609 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015610 return;
15611
15612 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015613 nlmsg_free(msg);
15614}
Johannes Berg947add32013-02-22 22:05:20 +010015615EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015616
Denis Kenzior6a671a52018-03-26 12:52:41 -050015617static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015618 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015619 bool unencrypted, gfp_t gfp)
15620{
15621 struct wireless_dev *wdev = dev->ieee80211_ptr;
15622 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015623 struct ethhdr *ehdr = eth_hdr(skb);
15624 const u8 *addr = ehdr->h_source;
15625 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015626 struct sk_buff *msg;
15627 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015628 struct nlattr *frame;
15629
Denis Kenzior6a671a52018-03-26 12:52:41 -050015630 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15631
15632 if (!nlportid)
15633 return -ENOENT;
15634
Denis Kenziora948f712018-07-03 15:05:48 -050015635 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015636 if (!msg)
15637 return -ENOMEM;
15638
15639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15640 if (!hdr) {
15641 nlmsg_free(msg);
15642 return -ENOBUFS;
15643 }
15644
15645 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15646 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15647 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15648 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015649 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15650 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15651 (unencrypted && nla_put_flag(msg,
15652 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15653 goto nla_put_failure;
15654
Denis Kenziora948f712018-07-03 15:05:48 -050015655 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15656 if (!frame)
15657 goto nla_put_failure;
15658
15659 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015660 genlmsg_end(msg, hdr);
15661
15662 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15663
15664 nla_put_failure:
15665 nlmsg_free(msg);
15666 return -ENOBUFS;
15667}
15668
15669bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015670 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015671{
15672 int ret;
15673
Denis Kenziora948f712018-07-03 15:05:48 -050015674 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15675 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015676 trace_cfg80211_return_bool(ret == 0);
15677 return ret == 0;
15678}
15679EXPORT_SYMBOL(cfg80211_rx_control_port);
15680
Johannes Berg5b97f492014-11-26 12:37:43 +010015681static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15682 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015683{
Johannes Berg947add32013-02-22 22:05:20 +010015684 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015685 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15686 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15687 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015688
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015689 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015690 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015691
Johannes Berg5b97f492014-11-26 12:37:43 +010015692 cb = (void **)msg->cb;
15693
15694 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15695 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015696 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015697 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015698 }
15699
David S. Miller9360ffd2012-03-29 04:41:26 -040015700 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015701 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015702 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015703
Johannes Berg5b97f492014-11-26 12:37:43 +010015704 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015705 goto nla_put_failure;
15706
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015707 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010015708 if (!cb[1])
15709 goto nla_put_failure;
15710
15711 cb[2] = rdev;
15712
15713 return msg;
15714 nla_put_failure:
15715 nlmsg_free(msg);
15716 return NULL;
15717}
15718
15719static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15720{
15721 void **cb = (void **)msg->cb;
15722 struct cfg80211_registered_device *rdev = cb[2];
15723
15724 nla_nest_end(msg, cb[1]);
15725 genlmsg_end(msg, cb[0]);
15726
15727 memset(msg->cb, 0, sizeof(msg->cb));
15728
15729 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15730 NL80211_MCGRP_MLME, gfp);
15731}
15732
15733void cfg80211_cqm_rssi_notify(struct net_device *dev,
15734 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015735 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015736{
15737 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015738 struct wireless_dev *wdev = dev->ieee80211_ptr;
15739 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015740
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015741 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015742
Johannes Berg98f03342014-11-26 12:42:02 +010015743 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15744 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15745 return;
15746
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015747 if (wdev->cqm_config) {
15748 wdev->cqm_config->last_rssi_event_value = rssi_level;
15749
15750 cfg80211_cqm_rssi_update(rdev, dev);
15751
15752 if (rssi_level == 0)
15753 rssi_level = wdev->cqm_config->last_rssi_event_value;
15754 }
15755
Johannes Berg5b97f492014-11-26 12:37:43 +010015756 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15757 if (!msg)
15758 return;
15759
David S. Miller9360ffd2012-03-29 04:41:26 -040015760 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15761 rssi_event))
15762 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015763
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015764 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15765 rssi_level))
15766 goto nla_put_failure;
15767
Johannes Berg5b97f492014-11-26 12:37:43 +010015768 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015769
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015770 return;
15771
15772 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015773 nlmsg_free(msg);
15774}
Johannes Berg947add32013-02-22 22:05:20 +010015775EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015776
Johannes Berg5b97f492014-11-26 12:37:43 +010015777void cfg80211_cqm_txe_notify(struct net_device *dev,
15778 const u8 *peer, u32 num_packets,
15779 u32 rate, u32 intvl, gfp_t gfp)
15780{
15781 struct sk_buff *msg;
15782
15783 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15784 if (!msg)
15785 return;
15786
15787 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15788 goto nla_put_failure;
15789
15790 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15791 goto nla_put_failure;
15792
15793 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15794 goto nla_put_failure;
15795
15796 cfg80211_send_cqm(msg, gfp);
15797 return;
15798
15799 nla_put_failure:
15800 nlmsg_free(msg);
15801}
15802EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15803
15804void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15805 const u8 *peer, u32 num_packets, gfp_t gfp)
15806{
15807 struct sk_buff *msg;
15808
15809 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15810
15811 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15812 if (!msg)
15813 return;
15814
15815 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15816 goto nla_put_failure;
15817
15818 cfg80211_send_cqm(msg, gfp);
15819 return;
15820
15821 nla_put_failure:
15822 nlmsg_free(msg);
15823}
15824EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15825
Johannes Berg98f03342014-11-26 12:42:02 +010015826void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15827{
15828 struct sk_buff *msg;
15829
15830 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15831 if (!msg)
15832 return;
15833
15834 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15835 goto nla_put_failure;
15836
15837 cfg80211_send_cqm(msg, gfp);
15838 return;
15839
15840 nla_put_failure:
15841 nlmsg_free(msg);
15842}
15843EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15844
Johannes Berg947add32013-02-22 22:05:20 +010015845static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15846 struct net_device *netdev, const u8 *bssid,
15847 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015848{
15849 struct sk_buff *msg;
15850 struct nlattr *rekey_attr;
15851 void *hdr;
15852
Thomas Graf58050fc2012-06-28 03:57:45 +000015853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015854 if (!msg)
15855 return;
15856
15857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15858 if (!hdr) {
15859 nlmsg_free(msg);
15860 return;
15861 }
15862
David S. Miller9360ffd2012-03-29 04:41:26 -040015863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15864 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15865 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15866 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015867
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015868 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020015869 if (!rekey_attr)
15870 goto nla_put_failure;
15871
David S. Miller9360ffd2012-03-29 04:41:26 -040015872 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15873 NL80211_REPLAY_CTR_LEN, replay_ctr))
15874 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015875
15876 nla_nest_end(msg, rekey_attr);
15877
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015878 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015879
Johannes Berg68eb5502013-11-19 15:19:38 +010015880 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015881 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015882 return;
15883
15884 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015885 nlmsg_free(msg);
15886}
15887
Johannes Berg947add32013-02-22 22:05:20 +010015888void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15889 const u8 *replay_ctr, gfp_t gfp)
15890{
15891 struct wireless_dev *wdev = dev->ieee80211_ptr;
15892 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015894
15895 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15896 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15897}
15898EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15899
15900static void
15901nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15902 struct net_device *netdev, int index,
15903 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015904{
15905 struct sk_buff *msg;
15906 struct nlattr *attr;
15907 void *hdr;
15908
Thomas Graf58050fc2012-06-28 03:57:45 +000015909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015910 if (!msg)
15911 return;
15912
15913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15914 if (!hdr) {
15915 nlmsg_free(msg);
15916 return;
15917 }
15918
David S. Miller9360ffd2012-03-29 04:41:26 -040015919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15921 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015922
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015923 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015924 if (!attr)
15925 goto nla_put_failure;
15926
David S. Miller9360ffd2012-03-29 04:41:26 -040015927 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15928 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15929 (preauth &&
15930 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15931 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015932
15933 nla_nest_end(msg, attr);
15934
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015935 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015936
Johannes Berg68eb5502013-11-19 15:19:38 +010015937 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015938 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015939 return;
15940
15941 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015942 nlmsg_free(msg);
15943}
15944
Johannes Berg947add32013-02-22 22:05:20 +010015945void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
15946 const u8 *bssid, bool preauth, gfp_t gfp)
15947{
15948 struct wireless_dev *wdev = dev->ieee80211_ptr;
15949 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015951
15952 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
15953 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
15954}
15955EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
15956
15957static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
15958 struct net_device *netdev,
15959 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020015960 gfp_t gfp,
15961 enum nl80211_commands notif,
15962 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070015963{
15964 struct sk_buff *msg;
15965 void *hdr;
15966
Thomas Graf58050fc2012-06-28 03:57:45 +000015967 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015968 if (!msg)
15969 return;
15970
Luciano Coelhof8d75522014-11-07 14:31:35 +020015971 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070015972 if (!hdr) {
15973 nlmsg_free(msg);
15974 return;
15975 }
15976
Johannes Berg683b6d32012-11-08 21:25:48 +010015977 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15978 goto nla_put_failure;
15979
15980 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040015981 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070015982
Luciano Coelhof8d75522014-11-07 14:31:35 +020015983 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
15984 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
15985 goto nla_put_failure;
15986
Thomas Pedersen53145262012-04-06 13:35:47 -070015987 genlmsg_end(msg, hdr);
15988
Johannes Berg68eb5502013-11-19 15:19:38 +010015989 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015990 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015991 return;
15992
15993 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070015994 nlmsg_free(msg);
15995}
15996
Johannes Berg947add32013-02-22 22:05:20 +010015997void cfg80211_ch_switch_notify(struct net_device *dev,
15998 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070015999{
Johannes Berg947add32013-02-22 22:05:20 +010016000 struct wireless_dev *wdev = dev->ieee80211_ptr;
16001 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016002 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016003
Simon Wunderliche487eae2013-11-21 18:19:51 +010016004 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016005
Simon Wunderliche487eae2013-11-21 18:19:51 +010016006 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016007
Michal Kazior9e0e2962014-01-29 14:22:27 +010016008 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016009 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016010
16011 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16012 !WARN_ON(!wdev->current_bss))
16013 wdev->current_bss->pub.channel = chandef->chan;
16014
Luciano Coelhof8d75522014-11-07 14:31:35 +020016015 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16016 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010016017}
16018EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16019
Luciano Coelhof8d75522014-11-07 14:31:35 +020016020void cfg80211_ch_switch_started_notify(struct net_device *dev,
16021 struct cfg80211_chan_def *chandef,
16022 u8 count)
16023{
16024 struct wireless_dev *wdev = dev->ieee80211_ptr;
16025 struct wiphy *wiphy = wdev->wiphy;
16026 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16027
16028 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16029
16030 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16031 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16032}
16033EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16034
Thomas Pedersen84f10702012-07-12 16:17:33 -070016035void
Simon Wunderlich04f39042013-02-08 18:16:19 +010016036nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010016037 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010016038 enum nl80211_radar_event event,
16039 struct net_device *netdev, gfp_t gfp)
16040{
16041 struct sk_buff *msg;
16042 void *hdr;
16043
16044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16045 if (!msg)
16046 return;
16047
16048 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16049 if (!hdr) {
16050 nlmsg_free(msg);
16051 return;
16052 }
16053
16054 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16055 goto nla_put_failure;
16056
16057 /* NOP and radar events don't need a netdev parameter */
16058 if (netdev) {
16059 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16060
16061 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016062 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16063 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010016064 goto nla_put_failure;
16065 }
16066
16067 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16068 goto nla_put_failure;
16069
16070 if (nl80211_send_chandef(msg, chandef))
16071 goto nla_put_failure;
16072
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016073 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016074
Johannes Berg68eb5502013-11-19 15:19:38 +010016075 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016076 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016077 return;
16078
16079 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010016080 nlmsg_free(msg);
16081}
16082
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053016083void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16084 struct sta_opmode_info *sta_opmode,
16085 gfp_t gfp)
16086{
16087 struct sk_buff *msg;
16088 struct wireless_dev *wdev = dev->ieee80211_ptr;
16089 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16090 void *hdr;
16091
16092 if (WARN_ON(!mac))
16093 return;
16094
16095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16096 if (!msg)
16097 return;
16098
16099 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16100 if (!hdr) {
16101 nlmsg_free(msg);
16102 return;
16103 }
16104
16105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16106 goto nla_put_failure;
16107
16108 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16109 goto nla_put_failure;
16110
16111 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16112 goto nla_put_failure;
16113
16114 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16115 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16116 goto nla_put_failure;
16117
16118 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16119 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16120 goto nla_put_failure;
16121
16122 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16123 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16124 goto nla_put_failure;
16125
16126 genlmsg_end(msg, hdr);
16127
16128 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16129 NL80211_MCGRP_MLME, gfp);
16130
16131 return;
16132
16133nla_put_failure:
16134 nlmsg_free(msg);
16135}
16136EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16137
Johannes Berg7f6cf312011-11-04 11:18:15 +010016138void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016139 u64 cookie, bool acked, s32 ack_signal,
16140 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010016141{
16142 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016143 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016144 struct sk_buff *msg;
16145 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016146
Beni Lev4ee3e062012-08-27 12:49:39 +030016147 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16148
Thomas Graf58050fc2012-06-28 03:57:45 +000016149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030016150
Johannes Berg7f6cf312011-11-04 11:18:15 +010016151 if (!msg)
16152 return;
16153
16154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16155 if (!hdr) {
16156 nlmsg_free(msg);
16157 return;
16158 }
16159
David S. Miller9360ffd2012-03-29 04:41:26 -040016160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16162 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016163 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16164 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016165 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16166 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16167 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016168 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016169
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016170 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016171
Johannes Berg68eb5502013-11-19 15:19:38 +010016172 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016173 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016174 return;
16175
16176 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010016177 nlmsg_free(msg);
16178}
16179EXPORT_SYMBOL(cfg80211_probe_status);
16180
Johannes Berg5e760232011-11-04 11:18:17 +010016181void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16182 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070016183 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010016184{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016185 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010016186 struct sk_buff *msg;
16187 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070016188 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010016189
Beni Lev4ee3e062012-08-27 12:49:39 +030016190 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16191
Ben Greear37c73b52012-10-26 14:49:25 -070016192 spin_lock_bh(&rdev->beacon_registrations_lock);
16193 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16194 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16195 if (!msg) {
16196 spin_unlock_bh(&rdev->beacon_registrations_lock);
16197 return;
16198 }
Johannes Berg5e760232011-11-04 11:18:17 +010016199
Ben Greear37c73b52012-10-26 14:49:25 -070016200 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16201 if (!hdr)
16202 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010016203
Ben Greear37c73b52012-10-26 14:49:25 -070016204 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16205 (freq &&
16206 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16207 (sig_dbm &&
16208 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16209 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16210 goto nla_put_failure;
16211
16212 genlmsg_end(msg, hdr);
16213
16214 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010016215 }
Ben Greear37c73b52012-10-26 14:49:25 -070016216 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016217 return;
16218
16219 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070016220 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016221 nlmsg_free(msg);
16222}
16223EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16224
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016225#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016226static int cfg80211_net_detect_results(struct sk_buff *msg,
16227 struct cfg80211_wowlan_wakeup *wakeup)
16228{
16229 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16230 struct nlattr *nl_results, *nl_match, *nl_freqs;
16231 int i, j;
16232
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016233 nl_results = nla_nest_start_noflag(msg,
16234 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016235 if (!nl_results)
16236 return -EMSGSIZE;
16237
16238 for (i = 0; i < nd->n_matches; i++) {
16239 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16240
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016241 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016242 if (!nl_match)
16243 break;
16244
16245 /* The SSID attribute is optional in nl80211, but for
16246 * simplicity reasons it's always present in the
16247 * cfg80211 structure. If a driver can't pass the
16248 * SSID, that needs to be changed. A zero length SSID
16249 * is still a valid SSID (wildcard), so it cannot be
16250 * used for this purpose.
16251 */
16252 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16253 match->ssid.ssid)) {
16254 nla_nest_cancel(msg, nl_match);
16255 goto out;
16256 }
16257
16258 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016259 nl_freqs = nla_nest_start_noflag(msg,
16260 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016261 if (!nl_freqs) {
16262 nla_nest_cancel(msg, nl_match);
16263 goto out;
16264 }
16265
16266 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020016267 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016268 nla_nest_cancel(msg, nl_freqs);
16269 nla_nest_cancel(msg, nl_match);
16270 goto out;
16271 }
16272 }
16273
16274 nla_nest_end(msg, nl_freqs);
16275 }
16276
16277 nla_nest_end(msg, nl_match);
16278 }
16279
16280out:
16281 nla_nest_end(msg, nl_results);
16282 return 0;
16283}
16284
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016285void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16286 struct cfg80211_wowlan_wakeup *wakeup,
16287 gfp_t gfp)
16288{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016289 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016290 struct sk_buff *msg;
16291 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016292 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016293
16294 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16295
16296 if (wakeup)
16297 size += wakeup->packet_present_len;
16298
16299 msg = nlmsg_new(size, gfp);
16300 if (!msg)
16301 return;
16302
16303 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16304 if (!hdr)
16305 goto free_msg;
16306
16307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016308 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16309 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016310 goto free_msg;
16311
16312 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16313 wdev->netdev->ifindex))
16314 goto free_msg;
16315
16316 if (wakeup) {
16317 struct nlattr *reasons;
16318
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016319 reasons = nla_nest_start_noflag(msg,
16320 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016321 if (!reasons)
16322 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016323
16324 if (wakeup->disconnect &&
16325 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16326 goto free_msg;
16327 if (wakeup->magic_pkt &&
16328 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16329 goto free_msg;
16330 if (wakeup->gtk_rekey_failure &&
16331 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16332 goto free_msg;
16333 if (wakeup->eap_identity_req &&
16334 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16335 goto free_msg;
16336 if (wakeup->four_way_handshake &&
16337 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16338 goto free_msg;
16339 if (wakeup->rfkill_release &&
16340 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16341 goto free_msg;
16342
16343 if (wakeup->pattern_idx >= 0 &&
16344 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16345 wakeup->pattern_idx))
16346 goto free_msg;
16347
Johannes Bergae917c92013-10-25 11:05:22 +020016348 if (wakeup->tcp_match &&
16349 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16350 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016351
Johannes Bergae917c92013-10-25 11:05:22 +020016352 if (wakeup->tcp_connlost &&
16353 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16354 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016355
Johannes Bergae917c92013-10-25 11:05:22 +020016356 if (wakeup->tcp_nomoretokens &&
16357 nla_put_flag(msg,
16358 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16359 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016360
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016361 if (wakeup->packet) {
16362 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16363 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16364
16365 if (!wakeup->packet_80211) {
16366 pkt_attr =
16367 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16368 len_attr =
16369 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16370 }
16371
16372 if (wakeup->packet_len &&
16373 nla_put_u32(msg, len_attr, wakeup->packet_len))
16374 goto free_msg;
16375
16376 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16377 wakeup->packet))
16378 goto free_msg;
16379 }
16380
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016381 if (wakeup->net_detect &&
16382 cfg80211_net_detect_results(msg, wakeup))
16383 goto free_msg;
16384
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016385 nla_nest_end(msg, reasons);
16386 }
16387
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016388 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016389
Johannes Berg68eb5502013-11-19 15:19:38 +010016390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016391 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016392 return;
16393
16394 free_msg:
16395 nlmsg_free(msg);
16396}
16397EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16398#endif
16399
Jouni Malinen3475b092012-11-16 22:49:57 +020016400void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16401 enum nl80211_tdls_operation oper,
16402 u16 reason_code, gfp_t gfp)
16403{
16404 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016405 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016406 struct sk_buff *msg;
16407 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016408
16409 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16410 reason_code);
16411
16412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16413 if (!msg)
16414 return;
16415
16416 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16417 if (!hdr) {
16418 nlmsg_free(msg);
16419 return;
16420 }
16421
16422 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16423 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16424 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16425 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16426 (reason_code > 0 &&
16427 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16428 goto nla_put_failure;
16429
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016430 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016431
Johannes Berg68eb5502013-11-19 15:19:38 +010016432 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016433 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016434 return;
16435
16436 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016437 nlmsg_free(msg);
16438}
16439EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16440
Jouni Malinen026331c2010-02-15 12:53:10 +020016441static int nl80211_netlink_notify(struct notifier_block * nb,
16442 unsigned long state,
16443 void *_notify)
16444{
16445 struct netlink_notify *notify = _notify;
16446 struct cfg80211_registered_device *rdev;
16447 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016448 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016449
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016450 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016451 return NOTIFY_DONE;
16452
16453 rcu_read_lock();
16454
Johannes Berg5e760232011-11-04 11:18:17 +010016455 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016456 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016457
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016458 list_for_each_entry_rcu(sched_scan_req,
16459 &rdev->sched_scan_req_list,
16460 list) {
16461 if (sched_scan_req->owner_nlportid == notify->portid) {
16462 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010016463 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016464 }
Johannes Berg753aacf2017-01-05 10:57:14 +010016465 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016466
Johannes Berg53873f12016-05-03 16:52:04 +030016467 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016468 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016469
Johannes Bergab810072017-04-26 07:43:41 +020016470 if (wdev->owner_nlportid == notify->portid) {
16471 wdev->nl_owner_dead = true;
16472 schedule_work(&rdev->destroy_work);
16473 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016474 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016475 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016476
16477 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016478 }
16479
Ben Greear37c73b52012-10-26 14:49:25 -070016480 spin_lock_bh(&rdev->beacon_registrations_lock);
16481 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16482 list) {
16483 if (reg->nlportid == notify->portid) {
16484 list_del(&reg->list);
16485 kfree(reg);
16486 break;
16487 }
16488 }
16489 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016490 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016491
16492 rcu_read_unlock();
16493
Ilan peer05050752015-03-04 00:32:06 -050016494 /*
16495 * It is possible that the user space process that is controlling the
16496 * indoor setting disappeared, so notify the regulatory core.
16497 */
16498 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016499 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016500}
16501
16502static struct notifier_block nl80211_netlink_notifier = {
16503 .notifier_call = nl80211_netlink_notify,
16504};
16505
Jouni Malinen355199e2013-02-27 17:14:27 +020016506void cfg80211_ft_event(struct net_device *netdev,
16507 struct cfg80211_ft_event_params *ft_event)
16508{
16509 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016510 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016511 struct sk_buff *msg;
16512 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016513
16514 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16515
16516 if (!ft_event->target_ap)
16517 return;
16518
Dedy Lansky1039d082018-05-17 16:25:03 +030016519 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16520 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016521 if (!msg)
16522 return;
16523
16524 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016525 if (!hdr)
16526 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016527
Johannes Bergae917c92013-10-25 11:05:22 +020016528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16530 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16531 goto out;
16532
16533 if (ft_event->ies &&
16534 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16535 goto out;
16536 if (ft_event->ric_ies &&
16537 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16538 ft_event->ric_ies))
16539 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016540
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016541 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016542
Johannes Berg68eb5502013-11-19 15:19:38 +010016543 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016544 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016545 return;
16546 out:
16547 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016548}
16549EXPORT_SYMBOL(cfg80211_ft_event);
16550
Arend van Spriel5de17982013-04-18 15:49:00 +020016551void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16552{
16553 struct cfg80211_registered_device *rdev;
16554 struct sk_buff *msg;
16555 void *hdr;
16556 u32 nlportid;
16557
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016558 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016559 if (!rdev->crit_proto_nlportid)
16560 return;
16561
16562 nlportid = rdev->crit_proto_nlportid;
16563 rdev->crit_proto_nlportid = 0;
16564
16565 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16566 if (!msg)
16567 return;
16568
16569 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16570 if (!hdr)
16571 goto nla_put_failure;
16572
16573 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016574 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16575 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016576 goto nla_put_failure;
16577
16578 genlmsg_end(msg, hdr);
16579
16580 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16581 return;
16582
16583 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016584 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016585}
16586EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16587
Johannes Berg348baf02014-01-24 14:06:29 +010016588void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16589{
16590 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016591 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016592 struct sk_buff *msg;
16593 void *hdr;
16594
16595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16596 if (!msg)
16597 return;
16598
16599 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16600 if (!hdr)
16601 goto out;
16602
16603 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16604 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016605 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16606 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016607 goto out;
16608
16609 genlmsg_end(msg, hdr);
16610
16611 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16612 NL80211_MCGRP_MLME, GFP_KERNEL);
16613 return;
16614 out:
16615 nlmsg_free(msg);
16616}
16617
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016618int cfg80211_external_auth_request(struct net_device *dev,
16619 struct cfg80211_external_auth_params *params,
16620 gfp_t gfp)
16621{
16622 struct wireless_dev *wdev = dev->ieee80211_ptr;
16623 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16624 struct sk_buff *msg;
16625 void *hdr;
16626
16627 if (!wdev->conn_owner_nlportid)
16628 return -EINVAL;
16629
16630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16631 if (!msg)
16632 return -ENOMEM;
16633
16634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16635 if (!hdr)
16636 goto nla_put_failure;
16637
16638 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16639 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16640 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16641 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16642 params->action) ||
16643 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16644 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16645 params->ssid.ssid))
16646 goto nla_put_failure;
16647
16648 genlmsg_end(msg, hdr);
16649 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16650 wdev->conn_owner_nlportid);
16651 return 0;
16652
16653 nla_put_failure:
16654 nlmsg_free(msg);
16655 return -ENOBUFS;
16656}
16657EXPORT_SYMBOL(cfg80211_external_auth_request);
16658
Sunil Duttcb74e972019-02-20 16:18:07 +053016659void cfg80211_update_owe_info_event(struct net_device *netdev,
16660 struct cfg80211_update_owe_info *owe_info,
16661 gfp_t gfp)
16662{
16663 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16664 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16665 struct sk_buff *msg;
16666 void *hdr;
16667
16668 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16669
16670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16671 if (!msg)
16672 return;
16673
16674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16675 if (!hdr)
16676 goto nla_put_failure;
16677
16678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16680 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16681 goto nla_put_failure;
16682
16683 if (!owe_info->ie_len ||
16684 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16685 goto nla_put_failure;
16686
16687 genlmsg_end(msg, hdr);
16688
16689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16690 NL80211_MCGRP_MLME, gfp);
16691 return;
16692
16693nla_put_failure:
16694 genlmsg_cancel(msg, hdr);
16695 nlmsg_free(msg);
16696}
16697EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16698
Johannes Berg55682962007-09-20 13:09:35 -040016699/* initialisation/exit functions */
16700
Johannes Berg56989f62016-10-24 14:40:05 +020016701int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016702{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016703 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016704
Johannes Berg489111e2016-10-24 14:40:03 +020016705 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016706 if (err)
16707 return err;
16708
Jouni Malinen026331c2010-02-15 12:53:10 +020016709 err = netlink_register_notifier(&nl80211_netlink_notifier);
16710 if (err)
16711 goto err_out;
16712
Johannes Berg55682962007-09-20 13:09:35 -040016713 return 0;
16714 err_out:
16715 genl_unregister_family(&nl80211_fam);
16716 return err;
16717}
16718
16719void nl80211_exit(void)
16720{
Jouni Malinen026331c2010-02-15 12:53:10 +020016721 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016722 genl_unregister_family(&nl80211_fam);
16723}