blob: dc96077afe5e73ccb296320bba46335905662a0d [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg66cd7942017-02-07 22:40:44 +02006 * Copyright 2015-2017 Intel Deutschland GmbH
Haim Dreyfuss50f32712018-04-20 13:49:26 +03007 * Copyright (C) 2018 Intel Corporation
Johannes Berg55682962007-09-20 13:09:35 -04008 */
9
10#include <linux/if.h>
11#include <linux/module.h>
12#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040014#include <linux/list.h>
15#include <linux/if_ether.h>
16#include <linux/ieee80211.h>
17#include <linux/nl80211.h>
18#include <linux/rtnetlink.h>
19#include <linux/netlink.h>
Dan Williams259d8c12018-01-29 17:03:15 -080020#include <linux/nospec.h>
Johannes Berg2a519312009-02-10 21:25:55 +010021#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include <net/genetlink.h>
24#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020025#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010026#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040027#include "core.h"
28#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070029#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030030#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040031
Jouni Malinen5fb628e2011-08-10 23:54:35 +030032static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
33 struct genl_info *info,
34 struct cfg80211_crypto_settings *settings,
35 int cipher_limit);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020038static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040039
Johannes Berg2a94fe42013-11-19 15:19:39 +010040/* multicast groups */
41enum nl80211_multicast_groups {
42 NL80211_MCGRP_CONFIG,
43 NL80211_MCGRP_SCAN,
44 NL80211_MCGRP_REGULATORY,
45 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010046 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030047 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010048 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
49};
50
51static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010052 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
53 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
54 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
55 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
56 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030057 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010059 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010060#endif
61};
62
Johannes Berg89a54e42012-06-15 14:33:17 +020063/* returns ERR_PTR values */
64static struct wireless_dev *
65__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040066{
Johannes Berg89a54e42012-06-15 14:33:17 +020067 struct cfg80211_registered_device *rdev;
68 struct wireless_dev *result = NULL;
69 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
70 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
71 u64 wdev_id;
72 int wiphy_idx = -1;
73 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg5fe231e2013-05-08 21:45:15 +020075 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040076
Johannes Berg89a54e42012-06-15 14:33:17 +020077 if (!have_ifidx && !have_wdev_id)
78 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040079
Johannes Berg89a54e42012-06-15 14:33:17 +020080 if (have_ifidx)
81 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
82 if (have_wdev_id) {
83 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
84 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040085 }
86
Johannes Berg89a54e42012-06-15 14:33:17 +020087 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
88 struct wireless_dev *wdev;
89
90 if (wiphy_net(&rdev->wiphy) != netns)
91 continue;
92
93 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
94 continue;
95
Johannes Berg53873f12016-05-03 16:52:04 +030096 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020097 if (have_ifidx && wdev->netdev &&
98 wdev->netdev->ifindex == ifidx) {
99 result = wdev;
100 break;
101 }
102 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
103 result = wdev;
104 break;
105 }
106 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200107
108 if (result)
109 break;
110 }
111
112 if (result)
113 return result;
114 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400115}
116
Johannes Berga9455402012-06-15 13:32:49 +0200117static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200118__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200119{
Johannes Berg7fee47782012-06-15 14:09:58 +0200120 struct cfg80211_registered_device *rdev = NULL, *tmp;
121 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg5fe231e2013-05-08 21:45:15 +0200123 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200124
Johannes Berg878d9ec2012-06-15 14:18:32 +0200125 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200126 !attrs[NL80211_ATTR_IFINDEX] &&
127 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200128 return ERR_PTR(-EINVAL);
129
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200131 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200132 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 if (attrs[NL80211_ATTR_WDEV]) {
135 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
136 struct wireless_dev *wdev;
137 bool found = false;
138
139 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
140 if (tmp) {
141 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300142 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (wdev->identifier != (u32)wdev_id)
144 continue;
145 found = true;
146 break;
147 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200148
149 if (!found)
150 tmp = NULL;
151
152 if (rdev && tmp != rdev)
153 return ERR_PTR(-EINVAL);
154 rdev = tmp;
155 }
156 }
157
Johannes Berg878d9ec2012-06-15 14:18:32 +0200158 if (attrs[NL80211_ATTR_IFINDEX]) {
159 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700160
Ying Xue7f2b8562014-01-15 10:23:45 +0800161 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200162 if (netdev) {
163 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800164 tmp = wiphy_to_rdev(
165 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200166 else
167 tmp = NULL;
168
Johannes Berg7fee47782012-06-15 14:09:58 +0200169 /* not wireless device -- return error */
170 if (!tmp)
171 return ERR_PTR(-EINVAL);
172
173 /* mismatch -- return error */
174 if (rdev && tmp != rdev)
175 return ERR_PTR(-EINVAL);
176
177 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200178 }
Johannes Berga9455402012-06-15 13:32:49 +0200179 }
180
Johannes Berg4f7eff12012-06-15 14:14:22 +0200181 if (!rdev)
182 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200183
Johannes Berg4f7eff12012-06-15 14:14:22 +0200184 if (netns != wiphy_net(&rdev->wiphy))
185 return ERR_PTR(-ENODEV);
186
187 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200188}
189
190/*
191 * This function returns a pointer to the driver
192 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200193 *
194 * The result of this can be a PTR_ERR and hence must
195 * be checked with IS_ERR() for errors.
196 */
197static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200198cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200199{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200200 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200201}
202
Johannes Berg3d7af872018-10-02 10:00:08 +0200203static int validate_ie_attr(const struct nlattr *attr,
204 struct netlink_ext_ack *extack)
205{
206 const u8 *pos;
207 int len;
208
209 pos = nla_data(attr);
210 len = nla_len(attr);
211
212 while (len) {
213 u8 elemlen;
214
215 if (len < 2)
216 goto error;
217 len -= 2;
218
219 elemlen = pos[1];
220 if (elemlen > len)
221 goto error;
222
223 len -= elemlen;
224 pos += 2 + elemlen;
225 }
226
227 return 0;
228error:
229 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
230 return -EINVAL;
231}
232
Johannes Berg55682962007-09-20 13:09:35 -0400233/* policy for the attributes */
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700234static const struct nla_policy
235nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
236 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
237 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
238 .len = U8_MAX },
239 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
240 .len = U8_MAX },
241};
242
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200243static const struct nla_policy
244nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
245 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
246 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
247 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
248 NLA_POLICY_MAX(NLA_U8, 15),
249 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
250 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
251 NLA_POLICY_MAX(NLA_U8, 15),
252 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
253 NLA_POLICY_MAX(NLA_U8, 15),
254 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
255 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
256 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
257};
258
259static const struct nla_policy
260nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
261 [NL80211_PMSR_TYPE_FTM] =
262 NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX,
263 nl80211_pmsr_ftm_req_attr_policy),
264};
265
266static const struct nla_policy
267nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
268 [NL80211_PMSR_REQ_ATTR_DATA] =
269 NLA_POLICY_NESTED(NL80211_PMSR_TYPE_MAX,
270 nl80211_pmsr_req_data_policy),
271 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
272};
273
274static const struct nla_policy
275nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
276 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
277 /*
278 * we could specify this again to be the top-level policy,
279 * but that would open us up to recursion problems ...
280 */
281 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED },
282 [NL80211_PMSR_PEER_ATTR_REQ] =
283 NLA_POLICY_NESTED(NL80211_PMSR_REQ_ATTR_MAX,
284 nl80211_pmsr_req_attr_policy),
285 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
286};
287
288static const struct nla_policy
289nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
290 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
291 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
292 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
293 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
294 [NL80211_PMSR_ATTR_PEERS] =
295 NLA_POLICY_NESTED_ARRAY(NL80211_PMSR_PEER_ATTR_MAX,
296 nl80211_psmr_peer_attr_policy),
297};
298
299const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400300 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
301 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700302 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200303 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100304
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200305 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530306 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100307 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
308 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
309 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
310
Johannes Bergab0d76f2018-10-02 10:00:07 +0200311 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
312 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200313 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
314 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100315 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200316 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400317
Johannes Bergab0d76f2018-10-02 10:00:07 +0200318 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400319 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
320 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100321
Eliad Pellere007b852011-11-24 18:13:56 +0200322 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
323 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100324
Johannes Bergb9454e82009-07-08 13:29:08 +0200325 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100326 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
327 .len = WLAN_MAX_KEY_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200328 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
Johannes Berg41ade002007-12-19 02:03:29 +0100329 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
330 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200331 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200332 [NL80211_ATTR_KEY_TYPE] =
333 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100334
335 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
336 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
337 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
338 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg3d7af872018-10-02 10:00:08 +0200339 [NL80211_ATTR_BEACON_TAIL] =
340 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
341 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200342 [NL80211_ATTR_STA_AID] =
343 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100344 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
345 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
346 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
347 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200348 [NL80211_ATTR_STA_PLINK_ACTION] =
349 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Johannes Berg5727ef12007-12-19 02:03:34 +0100350 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200351 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100352 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800353 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100354 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300355
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700356 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
357 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
358
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300359 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
360 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
361 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200362 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
363 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100364 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300365
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800366 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700367 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700368
Johannes Berg6c739412011-11-03 09:27:01 +0100369 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200370
371 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200372 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
373 validate_ie_attr,
374 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100375 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
376 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200377
378 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
379 .len = IEEE80211_MAX_SSID_LEN },
380 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
381 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200382 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300383 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200384 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
385 NL80211_MFP_NO,
386 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300387 [NL80211_ATTR_STA_FLAGS2] = {
388 .len = sizeof(struct nl80211_sta_flag_update),
389 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300390 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300391 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
392 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500393 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200394 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
395 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
396 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200397 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100398 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300399 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100400 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
401 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200402 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200403 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
404 .len = IEEE80211_MAX_DATA_LEN },
405 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200406 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
407 NL80211_PS_DISABLED,
408 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200409 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300410 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200411 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300412 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
413 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200414 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900415 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
416 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100417 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100418 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100419 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200420 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200421 [NL80211_ATTR_STA_PLINK_STATE] =
422 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
423 [NL80211_ATTR_MESH_PEER_AID] =
424 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300425 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200426 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200427 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200428 [NL80211_ATTR_HIDDEN_SSID] =
429 NLA_POLICY_RANGE(NLA_U32,
430 NL80211_HIDDEN_SSID_NOT_IN_USE,
431 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200432 [NL80211_ATTR_IE_PROBE_RESP] =
433 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
434 IEEE80211_MAX_DATA_LEN),
435 [NL80211_ATTR_IE_ASSOC_RESP] =
436 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
437 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530438 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300439 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530440 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300441 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
442 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
443 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
444 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
445 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300446 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100447 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200448 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
449 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700450 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800451 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
452 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
453 .len = NL80211_HT_CAPABILITY_LEN
454 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100455 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530456 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530457 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200458 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700459 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300460 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000461 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700462 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200463 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
464 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
465 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
466 NLA_POLICY_RANGE(NLA_U32,
467 NL80211_MESH_POWER_UNKNOWN + 1,
468 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530469 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
470 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200471 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
472 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100473 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100474 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
475 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
476 .len = NL80211_VHT_CAPABILITY_LEN,
477 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200478 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
479 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
480 .len = IEEE80211_MAX_DATA_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200481 [NL80211_ATTR_PEER_AID] =
482 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200483 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
484 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
485 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300486 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
487 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530488 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
489 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200490 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100491 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100492 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
493 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
494 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800495 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
496 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200497 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
498 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530499 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200500 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300501 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300502 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200503 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
504 [NL80211_ATTR_USER_PRIO] =
505 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300506 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300507 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200508 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200509 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200510 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200511 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500512 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200513 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100514 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200515 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
516 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300517 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
518 .len = VHT_MUMIMO_GROUPS_DATA_LEN
519 },
520 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200521 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200522 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300523 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300524 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
525 .len = FILS_MAX_KEK_LEN },
526 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200527 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200528 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200529 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
530 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
531 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
532 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200533 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300534 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
535 .len = FILS_ERP_MAX_USERNAME_LEN },
536 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
537 .len = FILS_ERP_MAX_REALM_LEN },
538 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
539 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
540 .len = FILS_ERP_MAX_RRK_LEN },
541 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
542 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100543 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200544 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200545
546 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
547 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
548 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300549 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
550 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700551
552 [NL80211_ATTR_FTM_RESPONDER] = {
553 .type = NLA_NESTED,
554 .validation_data = nl80211_ftm_responder_policy,
555 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200556 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
557 [NL80211_ATTR_PEER_MEASUREMENTS] =
558 NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX,
559 nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800560 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Johannes Berg55682962007-09-20 13:09:35 -0400561};
562
Johannes Berge31b8212010-10-05 19:39:30 +0200563/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000564static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200565 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200566 [NL80211_KEY_IDX] = { .type = NLA_U8 },
567 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200568 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200569 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
570 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200571 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100572 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
573};
574
575/* policy for the key default flags */
576static const struct nla_policy
577nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
578 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
579 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200580};
581
Johannes Bergf83ace32016-10-17 08:04:07 +0200582#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200583/* policy for WoWLAN attributes */
584static const struct nla_policy
585nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
586 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
587 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
588 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
589 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200590 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
591 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
592 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
593 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100594 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300595 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100596};
597
598static const struct nla_policy
599nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
600 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
601 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
602 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
603 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
604 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
605 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
606 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
607 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
608 },
609 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
610 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
611 },
612 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
613 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
614 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200615};
Johannes Bergf83ace32016-10-17 08:04:07 +0200616#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200617
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700618/* policy for coalesce rule attributes */
619static const struct nla_policy
620nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
621 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200622 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
623 NLA_POLICY_RANGE(NLA_U32,
624 NL80211_COALESCE_CONDITION_MATCH,
625 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700626 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
627};
628
Johannes Berge5497d72011-07-05 16:35:40 +0200629/* policy for GTK rekey offload attributes */
630static const struct nla_policy
631nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
632 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
633 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
634 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
635};
636
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300637static const struct nla_policy
638nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200639 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300640 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100641 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700642 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300643};
644
Avraham Stern3b06d272015-10-12 09:51:34 +0300645static const struct nla_policy
646nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
647 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
648 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
649};
650
Arend van Spriel38de03d2016-03-02 20:37:18 +0100651static const struct nla_policy
652nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
653 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
654 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
655 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
656 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
657 },
658};
659
Ayala Bekera442b762016-09-20 17:31:15 +0300660/* policy for NAN function attributes */
661static const struct nla_policy
662nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
663 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300664 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300665 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
666 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
667 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
668 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
669 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
670 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
671 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
672 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
673 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
674 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
675 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
676 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
677 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
678 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
679 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
680 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
681};
682
683/* policy for Service Response Filter attributes */
684static const struct nla_policy
685nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
686 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
687 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
688 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
689 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
690 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
691};
692
Peng Xuad670232017-10-03 23:21:51 +0300693/* policy for packet pattern attributes */
694static const struct nla_policy
695nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
696 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
697 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
698 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
699};
700
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200701int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
702 struct cfg80211_registered_device **rdev,
703 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100704{
Johannes Berg67748892010-10-04 21:14:06 +0200705 int err;
706
Johannes Berg97990a02013-04-19 01:02:55 +0200707 if (!cb->args[0]) {
708 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200709 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200710 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200711 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100712 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200713
Johannes Bergc90c39d2016-10-24 14:40:01 +0200714 *wdev = __cfg80211_wdev_from_attrs(
Johannes Berg5297c652018-09-27 14:36:44 +0200715 sock_net(cb->skb->sk),
Johannes Bergc90c39d2016-10-24 14:40:01 +0200716 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100717 if (IS_ERR(*wdev))
718 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800719 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200720 /* 0 is the first index - add 1 to parse only once */
721 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200722 cb->args[1] = (*wdev)->identifier;
723 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200724 /* subtract the 1 again here */
725 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200726 struct wireless_dev *tmp;
727
Johannes Bergea90e0d2017-03-15 14:26:04 +0100728 if (!wiphy)
729 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800730 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200731 *wdev = NULL;
732
Johannes Berg53873f12016-05-03 16:52:04 +0300733 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200734 if (tmp->identifier == cb->args[1]) {
735 *wdev = tmp;
736 break;
737 }
738 }
Johannes Berg97990a02013-04-19 01:02:55 +0200739
Johannes Bergea90e0d2017-03-15 14:26:04 +0100740 if (!*wdev)
741 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200742 }
743
Johannes Berg67748892010-10-04 21:14:06 +0200744 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200745}
746
Johannes Berg55682962007-09-20 13:09:35 -0400747/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200748void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
749 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400750{
751 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000752 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400753}
754
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300755static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
756 const struct ieee80211_reg_rule *rule)
757{
758 int j;
759 struct nlattr *nl_wmm_rules =
760 nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM);
761
762 if (!nl_wmm_rules)
763 goto nla_put_failure;
764
765 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
766 struct nlattr *nl_wmm_rule = nla_nest_start(msg, j);
767
768 if (!nl_wmm_rule)
769 goto nla_put_failure;
770
771 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200772 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300773 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200774 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300775 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200776 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300777 nla_put_u16(msg, NL80211_WMMR_TXOP,
778 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300779 goto nla_put_failure;
780
781 nla_nest_end(msg, nl_wmm_rule);
782 }
783 nla_nest_end(msg, nl_wmm_rules);
784
785 return 0;
786
787nla_put_failure:
788 return -ENOBUFS;
789}
790
791static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100792 struct ieee80211_channel *chan,
793 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400794{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200795 /* Some channels must be completely excluded from the
796 * list to protect old user-space tools from breaking
797 */
798 if (!large && chan->flags &
799 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
800 return 0;
801
David S. Miller9360ffd2012-03-29 04:41:26 -0400802 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
803 chan->center_freq))
804 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400805
David S. Miller9360ffd2012-03-29 04:41:26 -0400806 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
807 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
808 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200809 if (chan->flags & IEEE80211_CHAN_NO_IR) {
810 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
811 goto nla_put_failure;
812 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
813 goto nla_put_failure;
814 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100815 if (chan->flags & IEEE80211_CHAN_RADAR) {
816 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
817 goto nla_put_failure;
818 if (large) {
819 u32 time;
820
821 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
822
823 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
824 chan->dfs_state))
825 goto nla_put_failure;
826 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
827 time))
828 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100829 if (nla_put_u32(msg,
830 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
831 chan->dfs_cac_ms))
832 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100833 }
834 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400835
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100836 if (large) {
837 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
838 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
839 goto nla_put_failure;
840 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
841 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
842 goto nla_put_failure;
843 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
844 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
845 goto nla_put_failure;
846 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
847 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
848 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200849 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
850 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
851 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300852 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
853 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200854 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200855 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
856 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
857 goto nla_put_failure;
858 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
859 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
860 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100861 }
862
David S. Miller9360ffd2012-03-29 04:41:26 -0400863 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
864 DBM_TO_MBM(chan->max_power)))
865 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400866
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300867 if (large) {
868 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300869 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300870
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200871 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300872 if (nl80211_msg_put_wmm_rules(msg, rule))
873 goto nla_put_failure;
874 }
875 }
876
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400877 return 0;
878
879 nla_put_failure:
880 return -ENOBUFS;
881}
882
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200883static bool nl80211_put_txq_stats(struct sk_buff *msg,
884 struct cfg80211_txq_stats *txqstats,
885 int attrtype)
886{
887 struct nlattr *txqattr;
888
889#define PUT_TXQVAL_U32(attr, memb) do { \
890 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
891 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
892 return false; \
893 } while (0)
894
895 txqattr = nla_nest_start(msg, attrtype);
896 if (!txqattr)
897 return false;
898
899 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
900 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
901 PUT_TXQVAL_U32(FLOWS, flows);
902 PUT_TXQVAL_U32(DROPS, drops);
903 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
904 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
905 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
906 PUT_TXQVAL_U32(COLLISIONS, collisions);
907 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
908 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
909 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
910 nla_nest_end(msg, txqattr);
911
912#undef PUT_TXQVAL_U32
913 return true;
914}
915
Johannes Berg55682962007-09-20 13:09:35 -0400916/* netlink command implementations */
917
Johannes Bergb9454e82009-07-08 13:29:08 +0200918struct key_parse {
919 struct key_params p;
920 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200921 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200922 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100923 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200924};
925
Johannes Berg768075e2017-11-13 15:35:06 +0100926static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
927 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200928{
929 struct nlattr *tb[NL80211_KEY_MAX + 1];
930 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Berg768075e2017-11-13 15:35:06 +0100931 nl80211_key_policy, info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200932 if (err)
933 return err;
934
935 k->def = !!tb[NL80211_KEY_DEFAULT];
936 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
937
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100938 if (k->def) {
939 k->def_uni = true;
940 k->def_multi = true;
941 }
942 if (k->defmgmt)
943 k->def_multi = true;
944
Johannes Bergb9454e82009-07-08 13:29:08 +0200945 if (tb[NL80211_KEY_IDX])
946 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
947
948 if (tb[NL80211_KEY_DATA]) {
949 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
950 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
951 }
952
953 if (tb[NL80211_KEY_SEQ]) {
954 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
955 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
956 }
957
958 if (tb[NL80211_KEY_CIPHER])
959 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
960
Johannes Bergab0d76f2018-10-02 10:00:07 +0200961 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +0200962 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +0200963
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100964 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
965 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700966
Johannes Berg2da8f412012-01-20 13:52:37 +0100967 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
968 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Berg768075e2017-11-13 15:35:06 +0100969 nl80211_key_default_policy,
970 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100971 if (err)
972 return err;
973
974 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
975 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
976 }
977
Johannes Bergb9454e82009-07-08 13:29:08 +0200978 return 0;
979}
980
981static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
982{
983 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
984 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
985 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
986 }
987
988 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
989 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
990 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
991 }
992
993 if (info->attrs[NL80211_ATTR_KEY_IDX])
994 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
995
996 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
997 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
998
999 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1000 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1001
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001002 if (k->def) {
1003 k->def_uni = true;
1004 k->def_multi = true;
1005 }
1006 if (k->defmgmt)
1007 k->def_multi = true;
1008
Johannes Bergab0d76f2018-10-02 10:00:07 +02001009 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001010 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001011
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001012 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1013 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +02001014 int err = nla_parse_nested(kdt,
1015 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1016 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +02001017 nl80211_key_default_policy,
1018 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001019 if (err)
1020 return err;
1021
1022 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1023 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1024 }
1025
Johannes Bergb9454e82009-07-08 13:29:08 +02001026 return 0;
1027}
1028
1029static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1030{
1031 int err;
1032
1033 memset(k, 0, sizeof(*k));
1034 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001035 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001036
1037 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001038 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001039 else
1040 err = nl80211_parse_key_old(info, k);
1041
1042 if (err)
1043 return err;
1044
Johannes Berg768075e2017-11-13 15:35:06 +01001045 if (k->def && k->defmgmt) {
1046 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001047 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001048 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001049
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001050 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001051 if (k->def_uni || !k->def_multi) {
1052 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001053 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001054 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001055 }
1056
Johannes Bergb9454e82009-07-08 13:29:08 +02001057 if (k->idx != -1) {
1058 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001059 if (k->idx < 4 || k->idx > 5) {
1060 GENL_SET_ERR_MSG(info,
1061 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001062 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001063 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001064 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001065 if (k->idx < 0 || k->idx > 3) {
1066 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001067 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001068 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001069 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001070 if (k->idx < 0 || k->idx > 5) {
1071 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001072 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001073 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001074 }
1075 }
1076
1077 return 0;
1078}
1079
Johannes Bergfffd0932009-07-08 14:22:54 +02001080static struct cfg80211_cached_keys *
1081nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001082 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001083{
Johannes Berg768075e2017-11-13 15:35:06 +01001084 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001085 struct key_parse parse;
1086 struct nlattr *key;
1087 struct cfg80211_cached_keys *result;
1088 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001089 bool have_key = false;
1090
1091 nla_for_each_nested(key, keys, rem) {
1092 have_key = true;
1093 break;
1094 }
1095
1096 if (!have_key)
1097 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001098
1099 result = kzalloc(sizeof(*result), GFP_KERNEL);
1100 if (!result)
1101 return ERR_PTR(-ENOMEM);
1102
1103 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001104
1105 nla_for_each_nested(key, keys, rem) {
1106 memset(&parse, 0, sizeof(parse));
1107 parse.idx = -1;
1108
Johannes Berg768075e2017-11-13 15:35:06 +01001109 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001110 if (err)
1111 goto error;
1112 err = -EINVAL;
1113 if (!parse.p.key)
1114 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001115 if (parse.idx < 0 || parse.idx > 3) {
1116 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001117 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001118 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001119 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001120 if (def) {
1121 GENL_SET_ERR_MSG(info,
1122 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001123 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001124 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001125 def = 1;
1126 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001127 if (!parse.def_uni || !parse.def_multi)
1128 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001129 } else if (parse.defmgmt)
1130 goto error;
1131 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001132 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001133 if (err)
1134 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001135 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1136 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001137 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001138 err = -EINVAL;
1139 goto error;
1140 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001141 result->params[parse.idx].cipher = parse.p.cipher;
1142 result->params[parse.idx].key_len = parse.p.key_len;
1143 result->params[parse.idx].key = result->data[parse.idx];
1144 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301145
Johannes Berg386b1f22016-09-13 16:10:02 +02001146 /* must be WEP key if we got here */
1147 if (no_ht)
1148 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001149 }
1150
Johannes Bergf1c1f172016-09-13 17:08:23 +02001151 if (result->def < 0) {
1152 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001153 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001154 goto error;
1155 }
1156
Johannes Bergfffd0932009-07-08 14:22:54 +02001157 return result;
1158 error:
1159 kfree(result);
1160 return ERR_PTR(err);
1161}
1162
1163static int nl80211_key_allowed(struct wireless_dev *wdev)
1164{
1165 ASSERT_WDEV_LOCK(wdev);
1166
Johannes Bergfffd0932009-07-08 14:22:54 +02001167 switch (wdev->iftype) {
1168 case NL80211_IFTYPE_AP:
1169 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001170 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001171 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001172 break;
1173 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001174 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001175 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001176 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001177 return -ENOLINK;
1178 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001179 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001180 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001181 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001182 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001183 case NL80211_IFTYPE_P2P_DEVICE:
1184 case NL80211_IFTYPE_WDS:
1185 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001186 return -EINVAL;
1187 }
1188
1189 return 0;
1190}
1191
Jouni Malinen664834d2014-01-15 00:01:44 +02001192static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1193 struct nlattr *tb)
1194{
1195 struct ieee80211_channel *chan;
1196
1197 if (tb == NULL)
1198 return NULL;
1199 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1200 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1201 return NULL;
1202 return chan;
1203}
1204
Johannes Berg7527a782011-05-13 10:58:57 +02001205static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1206{
1207 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1208 int i;
1209
1210 if (!nl_modes)
1211 goto nla_put_failure;
1212
1213 i = 0;
1214 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001215 if ((ifmodes & 1) && nla_put_flag(msg, i))
1216 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001217 ifmodes >>= 1;
1218 i++;
1219 }
1220
1221 nla_nest_end(msg, nl_modes);
1222 return 0;
1223
1224nla_put_failure:
1225 return -ENOBUFS;
1226}
1227
1228static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001229 struct sk_buff *msg,
1230 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001231{
1232 struct nlattr *nl_combis;
1233 int i, j;
1234
1235 nl_combis = nla_nest_start(msg,
1236 NL80211_ATTR_INTERFACE_COMBINATIONS);
1237 if (!nl_combis)
1238 goto nla_put_failure;
1239
1240 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1241 const struct ieee80211_iface_combination *c;
1242 struct nlattr *nl_combi, *nl_limits;
1243
1244 c = &wiphy->iface_combinations[i];
1245
1246 nl_combi = nla_nest_start(msg, i + 1);
1247 if (!nl_combi)
1248 goto nla_put_failure;
1249
1250 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1251 if (!nl_limits)
1252 goto nla_put_failure;
1253
1254 for (j = 0; j < c->n_limits; j++) {
1255 struct nlattr *nl_limit;
1256
1257 nl_limit = nla_nest_start(msg, j + 1);
1258 if (!nl_limit)
1259 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001260 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1261 c->limits[j].max))
1262 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001263 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1264 c->limits[j].types))
1265 goto nla_put_failure;
1266 nla_nest_end(msg, nl_limit);
1267 }
1268
1269 nla_nest_end(msg, nl_limits);
1270
David S. Miller9360ffd2012-03-29 04:41:26 -04001271 if (c->beacon_int_infra_match &&
1272 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1273 goto nla_put_failure;
1274 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1275 c->num_different_channels) ||
1276 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1277 c->max_interfaces))
1278 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001279 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001280 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1281 c->radar_detect_widths) ||
1282 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1283 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001284 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301285 if (c->beacon_int_min_gcd &&
1286 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1287 c->beacon_int_min_gcd))
1288 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001289
1290 nla_nest_end(msg, nl_combi);
1291 }
1292
1293 nla_nest_end(msg, nl_combis);
1294
1295 return 0;
1296nla_put_failure:
1297 return -ENOBUFS;
1298}
1299
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001301static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1302 struct sk_buff *msg)
1303{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001304 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001305 struct nlattr *nl_tcp;
1306
1307 if (!tcp)
1308 return 0;
1309
1310 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1311 if (!nl_tcp)
1312 return -ENOBUFS;
1313
1314 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1315 tcp->data_payload_max))
1316 return -ENOBUFS;
1317
1318 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1319 tcp->data_payload_max))
1320 return -ENOBUFS;
1321
1322 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1323 return -ENOBUFS;
1324
1325 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1326 sizeof(*tcp->tok), tcp->tok))
1327 return -ENOBUFS;
1328
1329 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1330 tcp->data_interval_max))
1331 return -ENOBUFS;
1332
1333 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1334 tcp->wake_payload_max))
1335 return -ENOBUFS;
1336
1337 nla_nest_end(msg, nl_tcp);
1338 return 0;
1339}
1340
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001342 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001343 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344{
1345 struct nlattr *nl_wowlan;
1346
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 return 0;
1349
1350 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1351 if (!nl_wowlan)
1352 return -ENOBUFS;
1353
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001356 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001358 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001364 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001366 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1370 return -ENOBUFS;
1371
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001373 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001374 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1375 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1376 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1377 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 };
1379
1380 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1381 sizeof(pat), &pat))
1382 return -ENOBUFS;
1383 }
1384
Luciano Coelho75453cc2015-01-09 14:06:37 +02001385 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1386 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1387 rdev->wiphy.wowlan->max_nd_match_sets))
1388 return -ENOBUFS;
1389
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001390 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001391 return -ENOBUFS;
1392
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 nla_nest_end(msg, nl_wowlan);
1394
1395 return 0;
1396}
1397#endif
1398
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001399static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001400 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001401{
1402 struct nl80211_coalesce_rule_support rule;
1403
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001404 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001405 return 0;
1406
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001407 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1408 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1409 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1410 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1411 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1412 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001413
1414 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1415 return -ENOBUFS;
1416
1417 return 0;
1418}
1419
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001420static int
1421nl80211_send_iftype_data(struct sk_buff *msg,
1422 const struct ieee80211_sband_iftype_data *iftdata)
1423{
1424 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1425
1426 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1427 iftdata->types_mask))
1428 return -ENOBUFS;
1429
1430 if (he_cap->has_he) {
1431 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1432 sizeof(he_cap->he_cap_elem.mac_cap_info),
1433 he_cap->he_cap_elem.mac_cap_info) ||
1434 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1435 sizeof(he_cap->he_cap_elem.phy_cap_info),
1436 he_cap->he_cap_elem.phy_cap_info) ||
1437 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1438 sizeof(he_cap->he_mcs_nss_supp),
1439 &he_cap->he_mcs_nss_supp) ||
1440 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1441 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1442 return -ENOBUFS;
1443 }
1444
1445 return 0;
1446}
1447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1449 struct ieee80211_supported_band *sband)
1450{
1451 struct nlattr *nl_rates, *nl_rate;
1452 struct ieee80211_rate *rate;
1453 int i;
1454
1455 /* add HT info */
1456 if (sband->ht_cap.ht_supported &&
1457 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1458 sizeof(sband->ht_cap.mcs),
1459 &sband->ht_cap.mcs) ||
1460 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1461 sband->ht_cap.cap) ||
1462 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1463 sband->ht_cap.ampdu_factor) ||
1464 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1465 sband->ht_cap.ampdu_density)))
1466 return -ENOBUFS;
1467
1468 /* add VHT info */
1469 if (sband->vht_cap.vht_supported &&
1470 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1471 sizeof(sband->vht_cap.vht_mcs),
1472 &sband->vht_cap.vht_mcs) ||
1473 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1474 sband->vht_cap.cap)))
1475 return -ENOBUFS;
1476
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001477 if (sband->n_iftype_data) {
1478 struct nlattr *nl_iftype_data =
1479 nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA);
1480 int err;
1481
1482 if (!nl_iftype_data)
1483 return -ENOBUFS;
1484
1485 for (i = 0; i < sband->n_iftype_data; i++) {
1486 struct nlattr *iftdata;
1487
1488 iftdata = nla_nest_start(msg, i + 1);
1489 if (!iftdata)
1490 return -ENOBUFS;
1491
1492 err = nl80211_send_iftype_data(msg,
1493 &sband->iftype_data[i]);
1494 if (err)
1495 return err;
1496
1497 nla_nest_end(msg, iftdata);
1498 }
1499
1500 nla_nest_end(msg, nl_iftype_data);
1501 }
1502
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 /* add bitrates */
1504 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1505 if (!nl_rates)
1506 return -ENOBUFS;
1507
1508 for (i = 0; i < sband->n_bitrates; i++) {
1509 nl_rate = nla_nest_start(msg, i);
1510 if (!nl_rate)
1511 return -ENOBUFS;
1512
1513 rate = &sband->bitrates[i];
1514 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1515 rate->bitrate))
1516 return -ENOBUFS;
1517 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1518 nla_put_flag(msg,
1519 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1520 return -ENOBUFS;
1521
1522 nla_nest_end(msg, nl_rate);
1523 }
1524
1525 nla_nest_end(msg, nl_rates);
1526
1527 return 0;
1528}
1529
1530static int
1531nl80211_send_mgmt_stypes(struct sk_buff *msg,
1532 const struct ieee80211_txrx_stypes *mgmt_stypes)
1533{
1534 u16 stypes;
1535 struct nlattr *nl_ftypes, *nl_ifs;
1536 enum nl80211_iftype ift;
1537 int i;
1538
1539 if (!mgmt_stypes)
1540 return 0;
1541
1542 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1543 if (!nl_ifs)
1544 return -ENOBUFS;
1545
1546 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1547 nl_ftypes = nla_nest_start(msg, ift);
1548 if (!nl_ftypes)
1549 return -ENOBUFS;
1550 i = 0;
1551 stypes = mgmt_stypes[ift].tx;
1552 while (stypes) {
1553 if ((stypes & 1) &&
1554 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1555 (i << 4) | IEEE80211_FTYPE_MGMT))
1556 return -ENOBUFS;
1557 stypes >>= 1;
1558 i++;
1559 }
1560 nla_nest_end(msg, nl_ftypes);
1561 }
1562
1563 nla_nest_end(msg, nl_ifs);
1564
1565 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1566 if (!nl_ifs)
1567 return -ENOBUFS;
1568
1569 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1570 nl_ftypes = nla_nest_start(msg, ift);
1571 if (!nl_ftypes)
1572 return -ENOBUFS;
1573 i = 0;
1574 stypes = mgmt_stypes[ift].rx;
1575 while (stypes) {
1576 if ((stypes & 1) &&
1577 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1578 (i << 4) | IEEE80211_FTYPE_MGMT))
1579 return -ENOBUFS;
1580 stypes >>= 1;
1581 i++;
1582 }
1583 nla_nest_end(msg, nl_ftypes);
1584 }
1585 nla_nest_end(msg, nl_ifs);
1586
1587 return 0;
1588}
1589
Johannes Berg17948992016-10-26 11:42:04 +02001590#define CMD(op, n) \
1591 do { \
1592 if (rdev->ops->op) { \
1593 i++; \
1594 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1595 goto nla_put_failure; \
1596 } \
1597 } while (0)
1598
1599static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1600 struct sk_buff *msg)
1601{
1602 int i = 0;
1603
1604 /*
1605 * do *NOT* add anything into this function, new things need to be
1606 * advertised only to new versions of userspace that can deal with
1607 * the split (and they can't possibly care about new features...
1608 */
1609 CMD(add_virtual_intf, NEW_INTERFACE);
1610 CMD(change_virtual_intf, SET_INTERFACE);
1611 CMD(add_key, NEW_KEY);
1612 CMD(start_ap, START_AP);
1613 CMD(add_station, NEW_STATION);
1614 CMD(add_mpath, NEW_MPATH);
1615 CMD(update_mesh_config, SET_MESH_CONFIG);
1616 CMD(change_bss, SET_BSS);
1617 CMD(auth, AUTHENTICATE);
1618 CMD(assoc, ASSOCIATE);
1619 CMD(deauth, DEAUTHENTICATE);
1620 CMD(disassoc, DISASSOCIATE);
1621 CMD(join_ibss, JOIN_IBSS);
1622 CMD(join_mesh, JOIN_MESH);
1623 CMD(set_pmksa, SET_PMKSA);
1624 CMD(del_pmksa, DEL_PMKSA);
1625 CMD(flush_pmksa, FLUSH_PMKSA);
1626 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1627 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1628 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1629 CMD(mgmt_tx, FRAME);
1630 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1631 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1632 i++;
1633 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1634 goto nla_put_failure;
1635 }
1636 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1637 rdev->ops->join_mesh) {
1638 i++;
1639 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1640 goto nla_put_failure;
1641 }
1642 CMD(set_wds_peer, SET_WDS_PEER);
1643 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1644 CMD(tdls_mgmt, TDLS_MGMT);
1645 CMD(tdls_oper, TDLS_OPER);
1646 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001647 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001648 CMD(sched_scan_start, START_SCHED_SCAN);
1649 CMD(probe_client, PROBE_CLIENT);
1650 CMD(set_noack_map, SET_NOACK_MAP);
1651 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1652 i++;
1653 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1654 goto nla_put_failure;
1655 }
1656 CMD(start_p2p_device, START_P2P_DEVICE);
1657 CMD(set_mcast_rate, SET_MCAST_RATE);
1658#ifdef CONFIG_NL80211_TESTMODE
1659 CMD(testmode_cmd, TESTMODE);
1660#endif
1661
1662 if (rdev->ops->connect || rdev->ops->auth) {
1663 i++;
1664 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1665 goto nla_put_failure;
1666 }
1667
1668 if (rdev->ops->disconnect || rdev->ops->deauth) {
1669 i++;
1670 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1671 goto nla_put_failure;
1672 }
1673
1674 return i;
1675 nla_put_failure:
1676 return -ENOBUFS;
1677}
1678
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001679static int
1680nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1681 struct sk_buff *msg)
1682{
1683 struct nlattr *ftm;
1684
1685 if (!cap->ftm.supported)
1686 return 0;
1687
1688 ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM);
1689 if (!ftm)
1690 return -ENOBUFS;
1691
1692 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1693 return -ENOBUFS;
1694 if (cap->ftm.non_asap &&
1695 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1696 return -ENOBUFS;
1697 if (cap->ftm.request_lci &&
1698 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1699 return -ENOBUFS;
1700 if (cap->ftm.request_civicloc &&
1701 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1702 return -ENOBUFS;
1703 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1704 cap->ftm.preambles))
1705 return -ENOBUFS;
1706 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1707 cap->ftm.bandwidths))
1708 return -ENOBUFS;
1709 if (cap->ftm.max_bursts_exponent >= 0 &&
1710 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1711 cap->ftm.max_bursts_exponent))
1712 return -ENOBUFS;
1713 if (cap->ftm.max_ftms_per_burst &&
1714 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1715 cap->ftm.max_ftms_per_burst))
1716 return -ENOBUFS;
1717
1718 nla_nest_end(msg, ftm);
1719 return 0;
1720}
1721
1722static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1723 struct sk_buff *msg)
1724{
1725 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1726 struct nlattr *pmsr, *caps;
1727
1728 if (!cap)
1729 return 0;
1730
1731 /*
1732 * we don't need to clean up anything here since the caller
1733 * will genlmsg_cancel() if we fail
1734 */
1735
1736 pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1737 if (!pmsr)
1738 return -ENOBUFS;
1739
1740 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1741 return -ENOBUFS;
1742
1743 if (cap->report_ap_tsf &&
1744 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1745 return -ENOBUFS;
1746
1747 if (cap->randomize_mac_addr &&
1748 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1749 return -ENOBUFS;
1750
1751 caps = nla_nest_start(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
1752 if (!caps)
1753 return -ENOBUFS;
1754
1755 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1756 return -ENOBUFS;
1757
1758 nla_nest_end(msg, caps);
1759 nla_nest_end(msg, pmsr);
1760
1761 return 0;
1762}
1763
Johannes Berg86e8cf92013-06-19 10:57:22 +02001764struct nl80211_dump_wiphy_state {
1765 s64 filter_wiphy;
1766 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301767 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 bool split;
1769};
1770
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001772 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001773 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001774 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001775{
1776 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001777 struct nlattr *nl_bands, *nl_band;
1778 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001779 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001780 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001781 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001782 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001783 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001785 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001786
Johannes Berg3bb20552014-05-26 13:52:25 +02001787 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001788 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 return -ENOBUFS;
1790
Johannes Berg86e8cf92013-06-19 10:57:22 +02001791 if (WARN_ON(!state))
1792 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001793
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001796 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001797 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001798 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001799 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001800
Johannes Berg3bb20552014-05-26 13:52:25 +02001801 if (cmd != NL80211_CMD_NEW_WIPHY)
1802 goto finish;
1803
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 case 0:
1806 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001807 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001808 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001809 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001810 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001811 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001812 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001813 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001815 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001816 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001817 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001818 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001819 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001820 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001821 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001822 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001823 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001824 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001825 rdev->wiphy.max_match_sets) ||
1826 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1827 rdev->wiphy.max_sched_scan_plans) ||
1828 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1829 rdev->wiphy.max_sched_scan_plan_interval) ||
1830 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1831 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001832 goto nla_put_failure;
1833
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001834 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001835 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1836 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001837 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001838 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1839 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001840 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001841 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1842 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001843 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001844 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1845 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001846 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001847 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1848 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001849 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001850 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001851 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001852 state->split_start++;
1853 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001854 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001855 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001856 case 1:
1857 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001858 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1859 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001860 goto nla_put_failure;
1861
Johannes Berg3713b4e2013-02-14 16:19:38 +01001862 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001864 goto nla_put_failure;
1865
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001866 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001867 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1868 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001869
Johannes Berg3713b4e2013-02-14 16:19:38 +01001870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001871 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001872 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001873 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001874 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001875
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001876 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001877 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001878 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001879 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001880
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001881 if ((rdev->wiphy.available_antennas_tx ||
1882 rdev->wiphy.available_antennas_rx) &&
1883 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001884 u32 tx_ant = 0, rx_ant = 0;
1885 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001886
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001887 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001888 if (!res) {
1889 if (nla_put_u32(msg,
1890 NL80211_ATTR_WIPHY_ANTENNA_TX,
1891 tx_ant) ||
1892 nla_put_u32(msg,
1893 NL80211_ATTR_WIPHY_ANTENNA_RX,
1894 rx_ant))
1895 goto nla_put_failure;
1896 }
Johannes Bergee688b002008-01-24 19:38:39 +01001897 }
1898
Johannes Berg86e8cf92013-06-19 10:57:22 +02001899 state->split_start++;
1900 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001901 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001902 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001903 case 2:
1904 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001905 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001906 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001907 state->split_start++;
1908 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001909 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001910 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001911 case 3:
1912 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1913 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001914 goto nla_put_failure;
1915
Johannes Berg86e8cf92013-06-19 10:57:22 +02001916 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001917 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001918 struct ieee80211_supported_band *sband;
1919
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001920 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001921
1922 if (!sband)
1923 continue;
1924
1925 nl_band = nla_nest_start(msg, band);
1926 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001927 goto nla_put_failure;
1928
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001930 case 0:
1931 if (nl80211_send_band_rateinfo(msg, sband))
1932 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001933 state->chan_start++;
1934 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001935 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001936 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001937 default:
1938 /* add frequencies */
1939 nl_freqs = nla_nest_start(
1940 msg, NL80211_BAND_ATTR_FREQS);
1941 if (!nl_freqs)
1942 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001943
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001945 i < sband->n_channels;
1946 i++) {
1947 nl_freq = nla_nest_start(msg, i);
1948 if (!nl_freq)
1949 goto nla_put_failure;
1950
1951 chan = &sband->channels[i];
1952
Johannes Berg86e8cf92013-06-19 10:57:22 +02001953 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001954 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001955 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001956 goto nla_put_failure;
1957
1958 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001959 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 break;
1961 }
1962 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001963 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001964 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001965 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001966 nla_nest_end(msg, nl_freqs);
1967 }
1968
1969 nla_nest_end(msg, nl_band);
1970
Johannes Berg86e8cf92013-06-19 10:57:22 +02001971 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001972 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001973 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001974 band--;
1975 break;
1976 }
Johannes Bergee688b002008-01-24 19:38:39 +01001977 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001978 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001979
Johannes Berg57fbcce2016-04-12 15:56:15 +02001980 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001981 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001982 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001983 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001984
Johannes Berg3713b4e2013-02-14 16:19:38 +01001985 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001986 if (state->band_start == 0 && state->chan_start == 0)
1987 state->split_start++;
1988 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001989 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001990 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001991 case 4:
1992 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1993 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001994 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001995
Johannes Berg17948992016-10-26 11:42:04 +02001996 i = nl80211_add_commands_unsplit(rdev, msg);
1997 if (i < 0)
1998 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001999 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002000 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2001 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002002 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002003 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002004 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002005 if (rdev->wiphy.features &
2006 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002007 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002008 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002009 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02002010 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002011#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002012
Johannes Berg3713b4e2013-02-14 16:19:38 +01002013 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002014 state->split_start++;
2015 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002016 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002017 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002018 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002019 if (rdev->ops->remain_on_channel &&
2020 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002021 nla_put_u32(msg,
2022 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002023 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002024 goto nla_put_failure;
2025
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002026 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002027 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2028 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002029
Johannes Berg3713b4e2013-02-14 16:19:38 +01002030 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2031 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002032 state->split_start++;
2033 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002034 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002035 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002036 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002037#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002038 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002039 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002040 state->split_start++;
2041 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002042 break;
2043#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002044 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002045#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002046 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002047 case 7:
2048 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002049 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002050 goto nla_put_failure;
2051
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002052 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002053 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002054 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002055
Johannes Berg86e8cf92013-06-19 10:57:22 +02002056 state->split_start++;
2057 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002058 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002059 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002060 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002061 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002062 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002063 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002064 goto nla_put_failure;
2065
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002066 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002067 /*
2068 * We can only add the per-channel limit information if the
2069 * dump is split, otherwise it makes it too big. Therefore
2070 * only advertise it in that case.
2071 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002072 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002073 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2074 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002075 goto nla_put_failure;
2076
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002077 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002078 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002079 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2080 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002081 goto nla_put_failure;
2082
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002083 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2084 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002085 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002086 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002087 goto nla_put_failure;
2088
2089 /*
2090 * Any information below this point is only available to
2091 * applications that can deal with it being split. This
2092 * helps ensure that newly added capabilities don't break
2093 * older tools by overrunning their buffers.
2094 *
2095 * We still increment split_start so that in the split
2096 * case we'll continue with more data in the next round,
2097 * but break unconditionally so unsplit data stops here.
2098 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002099 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002100 break;
2101 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002102 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002103 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002104 rdev->wiphy.extended_capabilities_len,
2105 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002106 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002107 rdev->wiphy.extended_capabilities_len,
2108 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002109 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002110
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002111 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002112 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002113 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2114 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002115 goto nla_put_failure;
2116
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002117 state->split_start++;
2118 break;
2119 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002120 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002121 goto nla_put_failure;
2122
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002123 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002124 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2125 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2126 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002127
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002128 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002129 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002130 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002131 goto nla_put_failure;
2132
Johannes Bergad7e7182013-11-13 13:37:47 +01002133 state->split_start++;
2134 break;
2135 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002136 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002137 const struct nl80211_vendor_cmd_info *info;
2138 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002139
Johannes Berg567ffc32013-12-18 14:43:31 +01002140 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
2141 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002142 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002143
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002144 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2145 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002146 if (nla_put(msg, i + 1, sizeof(*info), info))
2147 goto nla_put_failure;
2148 }
2149 nla_nest_end(msg, nested);
2150 }
2151
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002152 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002153 const struct nl80211_vendor_cmd_info *info;
2154 struct nlattr *nested;
2155
2156 nested = nla_nest_start(msg,
2157 NL80211_ATTR_VENDOR_EVENTS);
2158 if (!nested)
2159 goto nla_put_failure;
2160
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002161 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2162 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002163 if (nla_put(msg, i + 1, sizeof(*info), info))
2164 goto nla_put_failure;
2165 }
2166 nla_nest_end(msg, nested);
2167 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002168 state->split_start++;
2169 break;
2170 case 12:
2171 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2172 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2173 rdev->wiphy.max_num_csa_counters))
2174 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002175
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002176 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2177 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2178 goto nla_put_failure;
2179
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002180 if (rdev->wiphy.max_sched_scan_reqs &&
2181 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2182 rdev->wiphy.max_sched_scan_reqs))
2183 goto nla_put_failure;
2184
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002185 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2186 sizeof(rdev->wiphy.ext_features),
2187 rdev->wiphy.ext_features))
2188 goto nla_put_failure;
2189
Arend van Spriel38de03d2016-03-02 20:37:18 +01002190 if (rdev->wiphy.bss_select_support) {
2191 struct nlattr *nested;
2192 u32 bss_select_support = rdev->wiphy.bss_select_support;
2193
2194 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
2195 if (!nested)
2196 goto nla_put_failure;
2197
2198 i = 0;
2199 while (bss_select_support) {
2200 if ((bss_select_support & 1) &&
2201 nla_put_flag(msg, i))
2202 goto nla_put_failure;
2203 i++;
2204 bss_select_support >>= 1;
2205 }
2206 nla_nest_end(msg, nested);
2207 }
2208
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302209 state->split_start++;
2210 break;
2211 case 13:
2212 if (rdev->wiphy.num_iftype_ext_capab &&
2213 rdev->wiphy.iftype_ext_capab) {
2214 struct nlattr *nested_ext_capab, *nested;
2215
2216 nested = nla_nest_start(msg,
2217 NL80211_ATTR_IFTYPE_EXT_CAPA);
2218 if (!nested)
2219 goto nla_put_failure;
2220
2221 for (i = state->capa_start;
2222 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2223 const struct wiphy_iftype_ext_capab *capab;
2224
2225 capab = &rdev->wiphy.iftype_ext_capab[i];
2226
2227 nested_ext_capab = nla_nest_start(msg, i);
2228 if (!nested_ext_capab ||
2229 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2230 capab->iftype) ||
2231 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2232 capab->extended_capabilities_len,
2233 capab->extended_capabilities) ||
2234 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2235 capab->extended_capabilities_len,
2236 capab->extended_capabilities_mask))
2237 goto nla_put_failure;
2238
2239 nla_nest_end(msg, nested_ext_capab);
2240 if (state->split)
2241 break;
2242 }
2243 nla_nest_end(msg, nested);
2244 if (i < rdev->wiphy.num_iftype_ext_capab) {
2245 state->capa_start = i + 1;
2246 break;
2247 }
2248 }
2249
Luca Coelho85859892017-02-08 15:00:34 +02002250 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2251 rdev->wiphy.nan_supported_bands))
2252 goto nla_put_failure;
2253
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002254 if (wiphy_ext_feature_isset(&rdev->wiphy,
2255 NL80211_EXT_FEATURE_TXQS)) {
2256 struct cfg80211_txq_stats txqstats = {};
2257 int res;
2258
2259 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2260 if (!res &&
2261 !nl80211_put_txq_stats(msg, &txqstats,
2262 NL80211_ATTR_TXQ_STATS))
2263 goto nla_put_failure;
2264
2265 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2266 rdev->wiphy.txq_limit))
2267 goto nla_put_failure;
2268 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2269 rdev->wiphy.txq_memory_limit))
2270 goto nla_put_failure;
2271 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2272 rdev->wiphy.txq_quantum))
2273 goto nla_put_failure;
2274 }
2275
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002276 state->split_start++;
2277 break;
2278 case 14:
2279 if (nl80211_send_pmsr_capa(rdev, msg))
2280 goto nla_put_failure;
2281
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302282 state->split_start++;
2283 break;
2284 case 15:
2285 if (rdev->wiphy.akm_suites &&
2286 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2287 sizeof(u32) * rdev->wiphy.n_akm_suites,
2288 rdev->wiphy.akm_suites))
2289 goto nla_put_failure;
2290
Johannes Berg3713b4e2013-02-14 16:19:38 +01002291 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002292 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002293 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002294 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002295 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002296 genlmsg_end(msg, hdr);
2297 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002298
2299 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002300 genlmsg_cancel(msg, hdr);
2301 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002302}
2303
Johannes Berg86e8cf92013-06-19 10:57:22 +02002304static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2305 struct netlink_callback *cb,
2306 struct nl80211_dump_wiphy_state *state)
2307{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002308 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02002309 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
2310 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002311 /* ignore parse errors for backward compatibility */
2312 if (ret)
2313 return 0;
2314
2315 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2316 if (tb[NL80211_ATTR_WIPHY])
2317 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2318 if (tb[NL80211_ATTR_WDEV])
2319 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2320 if (tb[NL80211_ATTR_IFINDEX]) {
2321 struct net_device *netdev;
2322 struct cfg80211_registered_device *rdev;
2323 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2324
Ying Xue7f2b8562014-01-15 10:23:45 +08002325 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002326 if (!netdev)
2327 return -ENODEV;
2328 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002329 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002330 netdev->ieee80211_ptr->wiphy);
2331 state->filter_wiphy = rdev->wiphy_idx;
2332 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002333 }
2334
2335 return 0;
2336}
2337
Johannes Berg55682962007-09-20 13:09:35 -04002338static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2339{
Johannes Berg645e77d2013-03-01 14:03:49 +01002340 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002341 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002342 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002343
Johannes Berg5fe231e2013-05-08 21:45:15 +02002344 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002345 if (!state) {
2346 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002347 if (!state) {
2348 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002349 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002350 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002351 state->filter_wiphy = -1;
2352 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2353 if (ret) {
2354 kfree(state);
2355 rtnl_unlock();
2356 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002357 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002358 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002359 }
2360
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002361 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2362 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002363 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002364 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002365 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002366 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002367 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002368 continue;
2369 /* attempt to fit multiple wiphy data chunks into the skb */
2370 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002371 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2372 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002373 NETLINK_CB(cb->skb).portid,
2374 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002375 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002376 if (ret < 0) {
2377 /*
2378 * If sending the wiphy data didn't fit (ENOBUFS
2379 * or EMSGSIZE returned), this SKB is still
2380 * empty (so it's not too big because another
2381 * wiphy dataset is already in the skb) and
2382 * we've not tried to adjust the dump allocation
2383 * yet ... then adjust the alloc size to be
2384 * bigger, and return 1 but with the empty skb.
2385 * This results in an empty message being RX'ed
2386 * in userspace, but that is ignored.
2387 *
2388 * We can then retry with the larger buffer.
2389 */
2390 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002391 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002392 cb->min_dump_alloc < 4096) {
2393 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002394 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002395 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002396 return 1;
2397 }
2398 idx--;
2399 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002400 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002401 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002402 break;
Johannes Berg55682962007-09-20 13:09:35 -04002403 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002404 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002405
Johannes Berg86e8cf92013-06-19 10:57:22 +02002406 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002407
2408 return skb->len;
2409}
2410
Johannes Berg86e8cf92013-06-19 10:57:22 +02002411static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2412{
2413 kfree((void *)cb->args[0]);
2414 return 0;
2415}
2416
Johannes Berg55682962007-09-20 13:09:35 -04002417static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2418{
2419 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002421 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002422
Johannes Berg645e77d2013-03-01 14:03:49 +01002423 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002424 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002425 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002426
Johannes Berg3bb20552014-05-26 13:52:25 +02002427 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2428 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002429 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002430 nlmsg_free(msg);
2431 return -ENOBUFS;
2432 }
Johannes Berg55682962007-09-20 13:09:35 -04002433
Johannes Berg134e6372009-07-10 09:51:34 +00002434 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002435}
2436
Jouni Malinen31888482008-10-30 16:59:24 +02002437static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2438 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2439 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2440 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2441 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2442 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2443};
2444
2445static int parse_txq_params(struct nlattr *tb[],
2446 struct ieee80211_txq_params *txq_params)
2447{
Dan Williams259d8c12018-01-29 17:03:15 -08002448 u8 ac;
2449
Johannes Berga3304b02012-03-28 11:04:24 +02002450 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002451 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2452 !tb[NL80211_TXQ_ATTR_AIFS])
2453 return -EINVAL;
2454
Dan Williams259d8c12018-01-29 17:03:15 -08002455 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002456 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2457 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2458 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2459 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2460
Dan Williams259d8c12018-01-29 17:03:15 -08002461 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002462 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002463 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002464 return 0;
2465}
2466
Johannes Bergf444de02010-05-05 15:25:02 +02002467static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2468{
2469 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002470 * You can only set the channel explicitly for WDS interfaces,
2471 * all others have their channel managed via their respective
2472 * "establish a connection" command (connect, join, ...)
2473 *
2474 * For AP/GO and mesh mode, the channel can be set with the
2475 * channel userspace API, but is only stored and passed to the
2476 * low-level driver when the AP starts or the mesh is joined.
2477 * This is for backward compatibility, userspace can also give
2478 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002479 *
2480 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002481 * whatever else is going on, so they have their own special
2482 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002483 */
2484 return !wdev ||
2485 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002486 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002487 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2488 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002489}
2490
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002491int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2492 struct genl_info *info,
2493 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002494{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002495 struct netlink_ext_ack *extack = info->extack;
2496 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302497 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002498
Johannes Berg49f9cf02018-10-01 11:55:09 +02002499 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002500 return -EINVAL;
2501
Johannes Berg49f9cf02018-10-01 11:55:09 +02002502 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002503
2504 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002505 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2506 chandef->center_freq1 = control_freq;
2507 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002508
2509 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002510 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2511 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2512 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002513 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002514 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002515
Johannes Berg49f9cf02018-10-01 11:55:09 +02002516 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002517 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002518
Johannes Berg49f9cf02018-10-01 11:55:09 +02002519 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002520
2521 switch (chantype) {
2522 case NL80211_CHAN_NO_HT:
2523 case NL80211_CHAN_HT20:
2524 case NL80211_CHAN_HT40PLUS:
2525 case NL80211_CHAN_HT40MINUS:
2526 cfg80211_chandef_create(chandef, chandef->chan,
2527 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002528 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002529 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2530 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2531 NL_SET_ERR_MSG_ATTR(extack,
2532 attrs[NL80211_ATTR_CENTER_FREQ1],
2533 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002534 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002535 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002536 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002537 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2538 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2539 NL_SET_ERR_MSG_ATTR(extack,
2540 attrs[NL80211_ATTR_CENTER_FREQ2],
2541 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002542 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002543 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002544 break;
2545 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002546 NL_SET_ERR_MSG_ATTR(extack,
2547 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2548 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002549 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002550 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002551 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002552 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002553 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2554 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002555 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002556 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2557 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002558 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002559 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002560 }
2561
Johannes Berg49f9cf02018-10-01 11:55:09 +02002562 if (!cfg80211_chandef_valid(chandef)) {
2563 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002564 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002565 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002566
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002567 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002568 IEEE80211_CHAN_DISABLED)) {
2569 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002570 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002571 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002572
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002573 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2574 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002575 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2576 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002577 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002578 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002579
Johannes Berg683b6d32012-11-08 21:25:48 +01002580 return 0;
2581}
2582
Johannes Bergf444de02010-05-05 15:25:02 +02002583static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002584 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002585 struct genl_info *info)
2586{
Johannes Berg683b6d32012-11-08 21:25:48 +01002587 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002588 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002589 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002590 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002591
Jouni Malinene16821b2014-04-28 11:22:08 +03002592 if (dev)
2593 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002594 if (!nl80211_can_set_dev_channel(wdev))
2595 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002596 if (wdev)
2597 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002598
Johannes Berg683b6d32012-11-08 21:25:48 +01002599 result = nl80211_parse_chandef(rdev, info, &chandef);
2600 if (result)
2601 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002602
Johannes Berge8c9bd52012-06-06 08:18:22 +02002603 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002604 case NL80211_IFTYPE_AP:
2605 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002606 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2607 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002608 result = -EINVAL;
2609 break;
2610 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002611 if (wdev->beacon_interval) {
2612 if (!dev || !rdev->ops->set_ap_chanwidth ||
2613 !(rdev->wiphy.features &
2614 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2615 result = -EBUSY;
2616 break;
2617 }
2618
2619 /* Only allow dynamic channel width changes */
2620 if (chandef.chan != wdev->preset_chandef.chan) {
2621 result = -EBUSY;
2622 break;
2623 }
2624 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2625 if (result)
2626 break;
2627 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002628 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002629 result = 0;
2630 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002631 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002632 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002633 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002634 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002635 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002636 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002637 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002638 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002639 }
Johannes Bergf444de02010-05-05 15:25:02 +02002640
2641 return result;
2642}
2643
2644static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2645{
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2647 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002648
Jouni Malinene16821b2014-04-28 11:22:08 +03002649 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002650}
2651
Bill Jordane8347eb2010-10-01 13:54:28 -04002652static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2653{
Johannes Berg43b19952010-10-07 13:10:30 +02002654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2655 struct net_device *dev = info->user_ptr[1];
2656 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002657 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002658
2659 if (!info->attrs[NL80211_ATTR_MAC])
2660 return -EINVAL;
2661
Johannes Berg43b19952010-10-07 13:10:30 +02002662 if (netif_running(dev))
2663 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002664
Johannes Berg43b19952010-10-07 13:10:30 +02002665 if (!rdev->ops->set_wds_peer)
2666 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002667
Johannes Berg43b19952010-10-07 13:10:30 +02002668 if (wdev->iftype != NL80211_IFTYPE_WDS)
2669 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002670
2671 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002672 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002673}
2674
Johannes Berg55682962007-09-20 13:09:35 -04002675static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2676{
2677 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002678 struct net_device *netdev = NULL;
2679 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002680 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002681 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002682 u32 changed;
2683 u8 retry_short = 0, retry_long = 0;
2684 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002685 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002686 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002687
Johannes Berg5fe231e2013-05-08 21:45:15 +02002688 ASSERT_RTNL();
2689
Johannes Bergf444de02010-05-05 15:25:02 +02002690 /*
2691 * Try to find the wiphy and netdev. Normally this
2692 * function shouldn't need the netdev, but this is
2693 * done for backward compatibility -- previously
2694 * setting the channel was done per wiphy, but now
2695 * it is per netdev. Previous userland like hostapd
2696 * also passed a netdev to set_wiphy, so that it is
2697 * possible to let that go to the right netdev!
2698 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002699
Johannes Bergf444de02010-05-05 15:25:02 +02002700 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2701 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2702
Ying Xue7f2b8562014-01-15 10:23:45 +08002703 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002704 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002705 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002706 else
Johannes Bergf444de02010-05-05 15:25:02 +02002707 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002708 }
2709
Johannes Bergf444de02010-05-05 15:25:02 +02002710 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002711 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2712 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002713 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002714 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002715 wdev = NULL;
2716 netdev = NULL;
2717 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002718 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002719 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002720
2721 /*
2722 * end workaround code, by now the rdev is available
2723 * and locked, and wdev may or may not be NULL.
2724 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002725
2726 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002727 result = cfg80211_dev_rename(
2728 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002729
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002730 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002731 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002732
Jouni Malinen31888482008-10-30 16:59:24 +02002733 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2734 struct ieee80211_txq_params txq_params;
2735 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2736
Ying Xue7f2b8562014-01-15 10:23:45 +08002737 if (!rdev->ops->set_txq_params)
2738 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002739
Ying Xue7f2b8562014-01-15 10:23:45 +08002740 if (!netdev)
2741 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002742
Johannes Berg133a3ff2011-11-03 14:50:13 +01002743 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002744 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2745 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002746
Ying Xue7f2b8562014-01-15 10:23:45 +08002747 if (!netif_running(netdev))
2748 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002749
Jouni Malinen31888482008-10-30 16:59:24 +02002750 nla_for_each_nested(nl_txq_params,
2751 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2752 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002753 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2754 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002755 txq_params_policy,
2756 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002757 if (result)
2758 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002759 result = parse_txq_params(tb, &txq_params);
2760 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002761 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002762
Hila Gonene35e4d22012-06-27 17:19:42 +03002763 result = rdev_set_txq_params(rdev, netdev,
2764 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002765 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002766 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002767 }
2768 }
2769
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002770 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002771 result = __nl80211_set_channel(
2772 rdev,
2773 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2774 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002775 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002776 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002777 }
2778
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002779 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002780 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002781 enum nl80211_tx_power_setting type;
2782 int idx, mbm = 0;
2783
Johannes Bergc8442112012-10-24 10:17:18 +02002784 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2785 txp_wdev = NULL;
2786
Ying Xue7f2b8562014-01-15 10:23:45 +08002787 if (!rdev->ops->set_tx_power)
2788 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002789
2790 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2791 type = nla_get_u32(info->attrs[idx]);
2792
2793 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002794 (type != NL80211_TX_POWER_AUTOMATIC))
2795 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002796
2797 if (type != NL80211_TX_POWER_AUTOMATIC) {
2798 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2799 mbm = nla_get_u32(info->attrs[idx]);
2800 }
2801
Johannes Bergc8442112012-10-24 10:17:18 +02002802 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002803 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002804 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002805 }
2806
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002807 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2808 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2809 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002810
Bruno Randolf7f531e02010-12-16 11:30:22 +09002811 if ((!rdev->wiphy.available_antennas_tx &&
2812 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002813 !rdev->ops->set_antenna)
2814 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002815
2816 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2817 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2818
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002819 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002820 * available antenna masks, except for the "all" mask */
2821 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002822 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2823 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002824
Bruno Randolf7f531e02010-12-16 11:30:22 +09002825 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2826 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002827
Hila Gonene35e4d22012-06-27 17:19:42 +03002828 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002829 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002830 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002831 }
2832
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002833 changed = 0;
2834
2835 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2836 retry_short = nla_get_u8(
2837 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002838
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002839 changed |= WIPHY_PARAM_RETRY_SHORT;
2840 }
2841
2842 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2843 retry_long = nla_get_u8(
2844 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002845
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002846 changed |= WIPHY_PARAM_RETRY_LONG;
2847 }
2848
2849 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2850 frag_threshold = nla_get_u32(
2851 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002852 if (frag_threshold < 256)
2853 return -EINVAL;
2854
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002855 if (frag_threshold != (u32) -1) {
2856 /*
2857 * Fragments (apart from the last one) are required to
2858 * have even length. Make the fragmentation code
2859 * simpler by stripping LSB should someone try to use
2860 * odd threshold value.
2861 */
2862 frag_threshold &= ~0x1;
2863 }
2864 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2865 }
2866
2867 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2868 rts_threshold = nla_get_u32(
2869 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2870 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2871 }
2872
Lukáš Turek81077e82009-12-21 22:50:47 +01002873 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002874 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2875 return -EINVAL;
2876
Lukáš Turek81077e82009-12-21 22:50:47 +01002877 coverage_class = nla_get_u8(
2878 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2879 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2880 }
2881
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002882 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2883 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2884 return -EOPNOTSUPP;
2885
2886 changed |= WIPHY_PARAM_DYN_ACK;
2887 }
2888
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002889 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2890 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2891 NL80211_EXT_FEATURE_TXQS))
2892 return -EOPNOTSUPP;
2893 txq_limit = nla_get_u32(
2894 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2895 changed |= WIPHY_PARAM_TXQ_LIMIT;
2896 }
2897
2898 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2899 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2900 NL80211_EXT_FEATURE_TXQS))
2901 return -EOPNOTSUPP;
2902 txq_memory_limit = nla_get_u32(
2903 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2904 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2905 }
2906
2907 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2908 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2909 NL80211_EXT_FEATURE_TXQS))
2910 return -EOPNOTSUPP;
2911 txq_quantum = nla_get_u32(
2912 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2913 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2914 }
2915
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002916 if (changed) {
2917 u8 old_retry_short, old_retry_long;
2918 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002919 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002920 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002921
Ying Xue7f2b8562014-01-15 10:23:45 +08002922 if (!rdev->ops->set_wiphy_params)
2923 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002924
2925 old_retry_short = rdev->wiphy.retry_short;
2926 old_retry_long = rdev->wiphy.retry_long;
2927 old_frag_threshold = rdev->wiphy.frag_threshold;
2928 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002929 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002930 old_txq_limit = rdev->wiphy.txq_limit;
2931 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2932 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002933
2934 if (changed & WIPHY_PARAM_RETRY_SHORT)
2935 rdev->wiphy.retry_short = retry_short;
2936 if (changed & WIPHY_PARAM_RETRY_LONG)
2937 rdev->wiphy.retry_long = retry_long;
2938 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2939 rdev->wiphy.frag_threshold = frag_threshold;
2940 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2941 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002942 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2943 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002944 if (changed & WIPHY_PARAM_TXQ_LIMIT)
2945 rdev->wiphy.txq_limit = txq_limit;
2946 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
2947 rdev->wiphy.txq_memory_limit = txq_memory_limit;
2948 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
2949 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002950
Hila Gonene35e4d22012-06-27 17:19:42 +03002951 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002952 if (result) {
2953 rdev->wiphy.retry_short = old_retry_short;
2954 rdev->wiphy.retry_long = old_retry_long;
2955 rdev->wiphy.frag_threshold = old_frag_threshold;
2956 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002957 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002958 rdev->wiphy.txq_limit = old_txq_limit;
2959 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
2960 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02002961 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002962 }
2963 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002964 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002965}
2966
Johannes Berg683b6d32012-11-08 21:25:48 +01002967static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002968 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002969{
Johannes Berg601555c2014-11-27 17:26:56 +01002970 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2971 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002972
Johannes Berg683b6d32012-11-08 21:25:48 +01002973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2974 chandef->chan->center_freq))
2975 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002976 switch (chandef->width) {
2977 case NL80211_CHAN_WIDTH_20_NOHT:
2978 case NL80211_CHAN_WIDTH_20:
2979 case NL80211_CHAN_WIDTH_40:
2980 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2981 cfg80211_get_chandef_type(chandef)))
2982 return -ENOBUFS;
2983 break;
2984 default:
2985 break;
2986 }
2987 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2988 return -ENOBUFS;
2989 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2990 return -ENOBUFS;
2991 if (chandef->center_freq2 &&
2992 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002993 return -ENOBUFS;
2994 return 0;
2995}
2996
Eric W. Biederman15e47302012-09-07 20:12:54 +00002997static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002998 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02002999 struct wireless_dev *wdev,
3000 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003001{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003002 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003003 void *hdr;
3004
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003005 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3006 cmd != NL80211_CMD_DEL_INTERFACE &&
3007 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003008
3009 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003010 if (!hdr)
3011 return -1;
3012
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003013 if (dev &&
3014 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003015 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003016 goto nla_put_failure;
3017
3018 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3019 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003020 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3021 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003022 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003023 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3024 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003025 (cfg80211_rdev_list_generation << 2)) ||
3026 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003027 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003028
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003029 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003030 int ret;
3031 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003032
Johannes Berg683b6d32012-11-08 21:25:48 +01003033 ret = rdev_get_channel(rdev, wdev, &chandef);
3034 if (ret == 0) {
3035 if (nl80211_send_chandef(msg, &chandef))
3036 goto nla_put_failure;
3037 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003038 }
3039
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003040 if (rdev->ops->get_tx_power) {
3041 int dbm, ret;
3042
3043 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3044 if (ret == 0 &&
3045 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3046 DBM_TO_MBM(dbm)))
3047 goto nla_put_failure;
3048 }
3049
Johannes Berg44905262017-10-17 21:56:01 +02003050 wdev_lock(wdev);
3051 switch (wdev->iftype) {
3052 case NL80211_IFTYPE_AP:
3053 if (wdev->ssid_len &&
3054 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003055 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003056 break;
3057 case NL80211_IFTYPE_STATION:
3058 case NL80211_IFTYPE_P2P_CLIENT:
3059 case NL80211_IFTYPE_ADHOC: {
3060 const u8 *ssid_ie;
3061 if (!wdev->current_bss)
3062 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003063 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003064 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3065 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003066 if (ssid_ie &&
3067 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3068 goto nla_put_failure_rcu_locked;
3069 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003070 break;
3071 }
3072 default:
3073 /* nothing */
3074 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003075 }
Johannes Berg44905262017-10-17 21:56:01 +02003076 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003077
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003078 if (rdev->ops->get_txq_stats) {
3079 struct cfg80211_txq_stats txqstats = {};
3080 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3081
3082 if (ret == 0 &&
3083 !nl80211_put_txq_stats(msg, &txqstats,
3084 NL80211_ATTR_TXQ_STATS))
3085 goto nla_put_failure;
3086 }
3087
Johannes Berg053c0952015-01-16 22:09:00 +01003088 genlmsg_end(msg, hdr);
3089 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003090
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003091 nla_put_failure_rcu_locked:
3092 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003093 nla_put_failure_locked:
3094 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003095 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003096 genlmsg_cancel(msg, hdr);
3097 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003098}
3099
3100static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3101{
3102 int wp_idx = 0;
3103 int if_idx = 0;
3104 int wp_start = cb->args[0];
3105 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003106 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003107 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003108 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003109 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003110
Johannes Berg5fe231e2013-05-08 21:45:15 +02003111 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003112 if (!cb->args[2]) {
3113 struct nl80211_dump_wiphy_state state = {
3114 .filter_wiphy = -1,
3115 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003116
3117 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3118 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003119 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003120
3121 filter_wiphy = state.filter_wiphy;
3122
3123 /*
3124 * if filtering, set cb->args[2] to +1 since 0 is the default
3125 * value needed to determine that parsing is necessary.
3126 */
3127 if (filter_wiphy >= 0)
3128 cb->args[2] = filter_wiphy + 1;
3129 else
3130 cb->args[2] = -1;
3131 } else if (cb->args[2] > 0) {
3132 filter_wiphy = cb->args[2] - 1;
3133 }
3134
Johannes Bergf5ea9122009-08-07 16:17:38 +02003135 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3136 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003137 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003138 if (wp_idx < wp_start) {
3139 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003140 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003141 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003142
3143 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3144 continue;
3145
Johannes Berg55682962007-09-20 13:09:35 -04003146 if_idx = 0;
3147
Johannes Berg53873f12016-05-03 16:52:04 +03003148 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003149 if (if_idx < if_start) {
3150 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003151 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003152 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003153 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003154 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003155 rdev, wdev,
3156 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003157 goto out;
3158 }
3159 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003160 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003161
3162 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003163 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003164 out:
Johannes Berg55682962007-09-20 13:09:35 -04003165 cb->args[0] = wp_idx;
3166 cb->args[1] = if_idx;
3167
Johannes Bergea90e0d2017-03-15 14:26:04 +01003168 ret = skb->len;
3169 out_unlock:
3170 rtnl_unlock();
3171
3172 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003173}
3174
3175static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3176{
3177 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003179 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003180
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003181 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003182 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003183 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003184
Eric W. Biederman15e47302012-09-07 20:12:54 +00003185 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003186 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003187 nlmsg_free(msg);
3188 return -ENOBUFS;
3189 }
Johannes Berg55682962007-09-20 13:09:35 -04003190
Johannes Berg134e6372009-07-10 09:51:34 +00003191 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003192}
3193
Michael Wu66f7ac52008-01-31 19:48:22 +01003194static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3195 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3196 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3197 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3198 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3199 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003200 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003201};
3202
3203static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3204{
3205 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3206 int flag;
3207
3208 *mntrflags = 0;
3209
3210 if (!nla)
3211 return -EINVAL;
3212
Johannes Bergfceb6432017-04-12 14:34:07 +02003213 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
3214 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003215 return -EINVAL;
3216
3217 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3218 if (flags[flag])
3219 *mntrflags |= (1<<flag);
3220
Johannes Berg818a9862017-04-12 11:23:28 +02003221 *mntrflags |= MONITOR_FLAG_CHANGED;
3222
Michael Wu66f7ac52008-01-31 19:48:22 +01003223 return 0;
3224}
3225
Johannes Berg1db77592017-04-12 11:36:31 +02003226static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3227 enum nl80211_iftype type,
3228 struct genl_info *info,
3229 struct vif_params *params)
3230{
3231 bool change = false;
3232 int err;
3233
3234 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3235 if (type != NL80211_IFTYPE_MONITOR)
3236 return -EINVAL;
3237
3238 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3239 &params->flags);
3240 if (err)
3241 return err;
3242
3243 change = true;
3244 }
3245
3246 if (params->flags & MONITOR_FLAG_ACTIVE &&
3247 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3248 return -EOPNOTSUPP;
3249
3250 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3251 const u8 *mumimo_groups;
3252 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3253
3254 if (type != NL80211_IFTYPE_MONITOR)
3255 return -EINVAL;
3256
3257 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3258 return -EOPNOTSUPP;
3259
3260 mumimo_groups =
3261 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3262
3263 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003264 if ((mumimo_groups[0] & BIT(0)) ||
3265 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003266 return -EINVAL;
3267
3268 params->vht_mumimo_groups = mumimo_groups;
3269 change = true;
3270 }
3271
3272 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3273 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3274
3275 if (type != NL80211_IFTYPE_MONITOR)
3276 return -EINVAL;
3277
3278 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3279 return -EOPNOTSUPP;
3280
3281 params->vht_mumimo_follow_addr =
3282 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3283 change = true;
3284 }
3285
3286 return change ? 1 : 0;
3287}
3288
Johannes Berg9bc383d2009-11-19 11:55:19 +01003289static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003290 struct net_device *netdev, u8 use_4addr,
3291 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003292{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003293 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003294 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003295 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003296 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003297 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003298
3299 switch (iftype) {
3300 case NL80211_IFTYPE_AP_VLAN:
3301 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3302 return 0;
3303 break;
3304 case NL80211_IFTYPE_STATION:
3305 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3306 return 0;
3307 break;
3308 default:
3309 break;
3310 }
3311
3312 return -EOPNOTSUPP;
3313}
3314
Johannes Berg55682962007-09-20 13:09:35 -04003315static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3316{
Johannes Berg4c476992010-10-04 21:36:35 +02003317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003318 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003319 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003320 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003321 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003322 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003323
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003324 memset(&params, 0, sizeof(params));
3325
Johannes Berg04a773a2009-04-19 21:24:32 +02003326 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003327
Johannes Berg723b0382008-09-16 20:22:09 +02003328 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003329 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003330 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003331 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003332 }
3333
Johannes Berg92ffe052008-09-16 20:39:36 +02003334 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003335 struct wireless_dev *wdev = dev->ieee80211_ptr;
3336
Johannes Berg4c476992010-10-04 21:36:35 +02003337 if (ntype != NL80211_IFTYPE_MESH_POINT)
3338 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003339 if (netif_running(dev))
3340 return -EBUSY;
3341
3342 wdev_lock(wdev);
3343 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3344 IEEE80211_MAX_MESH_ID_LEN);
3345 wdev->mesh_id_up_len =
3346 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3347 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3348 wdev->mesh_id_up_len);
3349 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003350 }
3351
Felix Fietkau8b787642009-11-10 18:53:10 +01003352 if (info->attrs[NL80211_ATTR_4ADDR]) {
3353 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3354 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003355 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003356 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003357 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003358 } else {
3359 params.use_4addr = -1;
3360 }
3361
Johannes Berg1db77592017-04-12 11:36:31 +02003362 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3363 if (err < 0)
3364 return err;
3365 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003366 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003367
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003368 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003369 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003370 else
3371 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003372
Johannes Berg9bc383d2009-11-19 11:55:19 +01003373 if (!err && params.use_4addr != -1)
3374 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3375
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003376 if (change && !err) {
3377 struct wireless_dev *wdev = dev->ieee80211_ptr;
3378
3379 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3380 }
3381
Johannes Berg55682962007-09-20 13:09:35 -04003382 return err;
3383}
3384
3385static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3386{
Johannes Berg4c476992010-10-04 21:36:35 +02003387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003388 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003389 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003390 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003391 int err;
3392 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3393
Johannes Berg78f22b62014-03-24 17:57:27 +01003394 /* to avoid failing a new interface creation due to pending removal */
3395 cfg80211_destroy_ifaces(rdev);
3396
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003397 memset(&params, 0, sizeof(params));
3398
Johannes Berg55682962007-09-20 13:09:35 -04003399 if (!info->attrs[NL80211_ATTR_IFNAME])
3400 return -EINVAL;
3401
Johannes Bergab0d76f2018-10-02 10:00:07 +02003402 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003403 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003404
Johannes Berg79c97e92009-07-07 03:56:12 +02003405 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003406 !(rdev->wiphy.interface_modes & (1 << type)))
3407 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003408
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003409 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003410 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3411 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003412 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3413 ETH_ALEN);
3414 if (!is_valid_ether_addr(params.macaddr))
3415 return -EADDRNOTAVAIL;
3416 }
3417
Johannes Berg9bc383d2009-11-19 11:55:19 +01003418 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003419 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003420 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003421 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003422 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003423 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003424
Johannes Berg1db77592017-04-12 11:36:31 +02003425 err = nl80211_parse_mon_options(rdev, type, info, &params);
3426 if (err < 0)
3427 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003428
Johannes Berga18c7192015-02-24 10:56:42 +01003429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3430 if (!msg)
3431 return -ENOMEM;
3432
Hila Gonene35e4d22012-06-27 17:19:42 +03003433 wdev = rdev_add_virtual_intf(rdev,
3434 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003435 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003436 if (WARN_ON(!wdev)) {
3437 nlmsg_free(msg);
3438 return -EPROTO;
3439 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003440 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003441 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003442 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003443
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003444 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003445 wdev->owner_nlportid = info->snd_portid;
3446
Johannes Berg98104fde2012-06-16 00:19:54 +02003447 switch (type) {
3448 case NL80211_IFTYPE_MESH_POINT:
3449 if (!info->attrs[NL80211_ATTR_MESH_ID])
3450 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003451 wdev_lock(wdev);
3452 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3453 IEEE80211_MAX_MESH_ID_LEN);
3454 wdev->mesh_id_up_len =
3455 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3456 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3457 wdev->mesh_id_up_len);
3458 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003459 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003460 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003461 case NL80211_IFTYPE_P2P_DEVICE:
3462 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003463 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003464 * through the netdev notifier and must be added here
3465 */
Johannes Berge4d42162018-09-13 14:12:03 +02003466 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003467 break;
3468 default:
3469 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003470 }
3471
Eric W. Biederman15e47302012-09-07 20:12:54 +00003472 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003473 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003474 nlmsg_free(msg);
3475 return -ENOBUFS;
3476 }
3477
3478 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003479}
3480
3481static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3482{
Johannes Berg4c476992010-10-04 21:36:35 +02003483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003484 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003485
Johannes Berg4c476992010-10-04 21:36:35 +02003486 if (!rdev->ops->del_virtual_intf)
3487 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003488
Johannes Berg84efbb82012-06-16 00:00:26 +02003489 /*
3490 * If we remove a wireless device without a netdev then clear
3491 * user_ptr[1] so that nl80211_post_doit won't dereference it
3492 * to check if it needs to do dev_put(). Otherwise it crashes
3493 * since the wdev has been freed, unlike with a netdev where
3494 * we need the dev_put() for the netdev to really be freed.
3495 */
3496 if (!wdev->netdev)
3497 info->user_ptr[1] = NULL;
3498
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003499 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003500}
3501
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003502static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3503{
3504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3505 struct net_device *dev = info->user_ptr[1];
3506 u16 noack_map;
3507
3508 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3509 return -EINVAL;
3510
3511 if (!rdev->ops->set_noack_map)
3512 return -EOPNOTSUPP;
3513
3514 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3515
Hila Gonene35e4d22012-06-27 17:19:42 +03003516 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003517}
3518
Johannes Berg41ade002007-12-19 02:03:29 +01003519struct get_key_cookie {
3520 struct sk_buff *msg;
3521 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003522 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003523};
3524
3525static void get_key_callback(void *c, struct key_params *params)
3526{
Johannes Bergb9454e82009-07-08 13:29:08 +02003527 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003528 struct get_key_cookie *cookie = c;
3529
David S. Miller9360ffd2012-03-29 04:41:26 -04003530 if ((params->key &&
3531 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3532 params->key_len, params->key)) ||
3533 (params->seq &&
3534 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3535 params->seq_len, params->seq)) ||
3536 (params->cipher &&
3537 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3538 params->cipher)))
3539 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003540
Johannes Bergb9454e82009-07-08 13:29:08 +02003541 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3542 if (!key)
3543 goto nla_put_failure;
3544
David S. Miller9360ffd2012-03-29 04:41:26 -04003545 if ((params->key &&
3546 nla_put(cookie->msg, NL80211_KEY_DATA,
3547 params->key_len, params->key)) ||
3548 (params->seq &&
3549 nla_put(cookie->msg, NL80211_KEY_SEQ,
3550 params->seq_len, params->seq)) ||
3551 (params->cipher &&
3552 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3553 params->cipher)))
3554 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003555
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003556 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003557 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003558
3559 nla_nest_end(cookie->msg, key);
3560
Johannes Berg41ade002007-12-19 02:03:29 +01003561 return;
3562 nla_put_failure:
3563 cookie->error = 1;
3564}
3565
3566static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3567{
Johannes Berg4c476992010-10-04 21:36:35 +02003568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003569 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003570 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003571 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003572 const u8 *mac_addr = NULL;
3573 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003574 struct get_key_cookie cookie = {
3575 .error = 0,
3576 };
3577 void *hdr;
3578 struct sk_buff *msg;
3579
3580 if (info->attrs[NL80211_ATTR_KEY_IDX])
3581 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3582
Johannes Berg41ade002007-12-19 02:03:29 +01003583 if (info->attrs[NL80211_ATTR_MAC])
3584 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3585
Johannes Berge31b8212010-10-05 19:39:30 +02003586 pairwise = !!mac_addr;
3587 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3588 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003589
Johannes Berge31b8212010-10-05 19:39:30 +02003590 if (kt != NL80211_KEYTYPE_GROUP &&
3591 kt != NL80211_KEYTYPE_PAIRWISE)
3592 return -EINVAL;
3593 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3594 }
3595
Johannes Berg4c476992010-10-04 21:36:35 +02003596 if (!rdev->ops->get_key)
3597 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003598
Johannes Berg0fa7b392015-01-23 11:10:12 +01003599 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3600 return -ENOENT;
3601
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003603 if (!msg)
3604 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003605
Eric W. Biederman15e47302012-09-07 20:12:54 +00003606 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003607 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003608 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003609 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003610
3611 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003612 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003613
David S. Miller9360ffd2012-03-29 04:41:26 -04003614 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3615 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3616 goto nla_put_failure;
3617 if (mac_addr &&
3618 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3619 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003620
Hila Gonene35e4d22012-06-27 17:19:42 +03003621 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3622 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003623
3624 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003625 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003626
3627 if (cookie.error)
3628 goto nla_put_failure;
3629
3630 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003631 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003632
3633 nla_put_failure:
3634 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003635 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003636 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003637 return err;
3638}
3639
3640static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3641{
Johannes Berg4c476992010-10-04 21:36:35 +02003642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003643 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003644 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003645 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003646
Johannes Bergb9454e82009-07-08 13:29:08 +02003647 err = nl80211_parse_key(info, &key);
3648 if (err)
3649 return err;
3650
3651 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003652 return -EINVAL;
3653
Johannes Bergb9454e82009-07-08 13:29:08 +02003654 /* only support setting default key */
3655 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003656 return -EINVAL;
3657
Johannes Bergfffd0932009-07-08 14:22:54 +02003658 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003659
3660 if (key.def) {
3661 if (!rdev->ops->set_default_key) {
3662 err = -EOPNOTSUPP;
3663 goto out;
3664 }
3665
3666 err = nl80211_key_allowed(dev->ieee80211_ptr);
3667 if (err)
3668 goto out;
3669
Hila Gonene35e4d22012-06-27 17:19:42 +03003670 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003671 key.def_uni, key.def_multi);
3672
3673 if (err)
3674 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003675
Johannes Berg3d23e342009-09-29 23:27:28 +02003676#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003677 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003678#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003679 } else {
3680 if (key.def_uni || !key.def_multi) {
3681 err = -EINVAL;
3682 goto out;
3683 }
3684
3685 if (!rdev->ops->set_default_mgmt_key) {
3686 err = -EOPNOTSUPP;
3687 goto out;
3688 }
3689
3690 err = nl80211_key_allowed(dev->ieee80211_ptr);
3691 if (err)
3692 goto out;
3693
Hila Gonene35e4d22012-06-27 17:19:42 +03003694 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003695 if (err)
3696 goto out;
3697
3698#ifdef CONFIG_CFG80211_WEXT
3699 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3700#endif
3701 }
3702
3703 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003704 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003705
Johannes Berg41ade002007-12-19 02:03:29 +01003706 return err;
3707}
3708
3709static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3710{
Johannes Berg4c476992010-10-04 21:36:35 +02003711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003712 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003713 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003714 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003715 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003716
Johannes Bergb9454e82009-07-08 13:29:08 +02003717 err = nl80211_parse_key(info, &key);
3718 if (err)
3719 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003720
Johannes Bergb9454e82009-07-08 13:29:08 +02003721 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003722 return -EINVAL;
3723
Johannes Berg41ade002007-12-19 02:03:29 +01003724 if (info->attrs[NL80211_ATTR_MAC])
3725 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3726
Johannes Berge31b8212010-10-05 19:39:30 +02003727 if (key.type == -1) {
3728 if (mac_addr)
3729 key.type = NL80211_KEYTYPE_PAIRWISE;
3730 else
3731 key.type = NL80211_KEYTYPE_GROUP;
3732 }
3733
3734 /* for now */
3735 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3736 key.type != NL80211_KEYTYPE_GROUP)
3737 return -EINVAL;
3738
Johannes Berg4c476992010-10-04 21:36:35 +02003739 if (!rdev->ops->add_key)
3740 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003741
Johannes Berge31b8212010-10-05 19:39:30 +02003742 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3743 key.type == NL80211_KEYTYPE_PAIRWISE,
3744 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003745 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003746
3747 wdev_lock(dev->ieee80211_ptr);
3748 err = nl80211_key_allowed(dev->ieee80211_ptr);
3749 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003750 err = rdev_add_key(rdev, dev, key.idx,
3751 key.type == NL80211_KEYTYPE_PAIRWISE,
3752 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003753 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003754
Johannes Berg41ade002007-12-19 02:03:29 +01003755 return err;
3756}
3757
3758static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3759{
Johannes Berg4c476992010-10-04 21:36:35 +02003760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003761 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003762 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003763 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003764 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003765
Johannes Bergb9454e82009-07-08 13:29:08 +02003766 err = nl80211_parse_key(info, &key);
3767 if (err)
3768 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003769
3770 if (info->attrs[NL80211_ATTR_MAC])
3771 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3772
Johannes Berge31b8212010-10-05 19:39:30 +02003773 if (key.type == -1) {
3774 if (mac_addr)
3775 key.type = NL80211_KEYTYPE_PAIRWISE;
3776 else
3777 key.type = NL80211_KEYTYPE_GROUP;
3778 }
3779
3780 /* for now */
3781 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3782 key.type != NL80211_KEYTYPE_GROUP)
3783 return -EINVAL;
3784
Johannes Berg4c476992010-10-04 21:36:35 +02003785 if (!rdev->ops->del_key)
3786 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003787
Johannes Bergfffd0932009-07-08 14:22:54 +02003788 wdev_lock(dev->ieee80211_ptr);
3789 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003790
Johannes Berg0fa7b392015-01-23 11:10:12 +01003791 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003792 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3793 err = -ENOENT;
3794
Johannes Bergfffd0932009-07-08 14:22:54 +02003795 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003796 err = rdev_del_key(rdev, dev, key.idx,
3797 key.type == NL80211_KEYTYPE_PAIRWISE,
3798 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003799
Johannes Berg3d23e342009-09-29 23:27:28 +02003800#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003801 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003802 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003803 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003804 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003805 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3806 }
3807#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003808 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003809
Johannes Berg41ade002007-12-19 02:03:29 +01003810 return err;
3811}
3812
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303813/* This function returns an error or the number of nested attributes */
3814static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3815{
3816 struct nlattr *attr;
3817 int n_entries = 0, tmp;
3818
3819 nla_for_each_nested(attr, nl_attr, tmp) {
3820 if (nla_len(attr) != ETH_ALEN)
3821 return -EINVAL;
3822
3823 n_entries++;
3824 }
3825
3826 return n_entries;
3827}
3828
3829/*
3830 * This function parses ACL information and allocates memory for ACL data.
3831 * On successful return, the calling function is responsible to free the
3832 * ACL buffer returned by this function.
3833 */
3834static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3835 struct genl_info *info)
3836{
3837 enum nl80211_acl_policy acl_policy;
3838 struct nlattr *attr;
3839 struct cfg80211_acl_data *acl;
3840 int i = 0, n_entries, tmp;
3841
3842 if (!wiphy->max_acl_mac_addrs)
3843 return ERR_PTR(-EOPNOTSUPP);
3844
3845 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3846 return ERR_PTR(-EINVAL);
3847
3848 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3849 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3850 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3851 return ERR_PTR(-EINVAL);
3852
3853 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3854 return ERR_PTR(-EINVAL);
3855
3856 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3857 if (n_entries < 0)
3858 return ERR_PTR(n_entries);
3859
3860 if (n_entries > wiphy->max_acl_mac_addrs)
3861 return ERR_PTR(-ENOTSUPP);
3862
3863 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3864 GFP_KERNEL);
3865 if (!acl)
3866 return ERR_PTR(-ENOMEM);
3867
3868 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3869 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3870 i++;
3871 }
3872
3873 acl->n_acl_entries = n_entries;
3874 acl->acl_policy = acl_policy;
3875
3876 return acl;
3877}
3878
3879static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3880{
3881 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3882 struct net_device *dev = info->user_ptr[1];
3883 struct cfg80211_acl_data *acl;
3884 int err;
3885
3886 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3887 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3888 return -EOPNOTSUPP;
3889
3890 if (!dev->ieee80211_ptr->beacon_interval)
3891 return -EINVAL;
3892
3893 acl = parse_acl_data(&rdev->wiphy, info);
3894 if (IS_ERR(acl))
3895 return PTR_ERR(acl);
3896
3897 err = rdev_set_mac_acl(rdev, dev, acl);
3898
3899 kfree(acl);
3900
3901 return err;
3902}
3903
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303904static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3905 u8 *rates, u8 rates_len)
3906{
3907 u8 i;
3908 u32 mask = 0;
3909
3910 for (i = 0; i < rates_len; i++) {
3911 int rate = (rates[i] & 0x7f) * 5;
3912 int ridx;
3913
3914 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3915 struct ieee80211_rate *srate =
3916 &sband->bitrates[ridx];
3917 if (rate == srate->bitrate) {
3918 mask |= 1 << ridx;
3919 break;
3920 }
3921 }
3922 if (ridx == sband->n_bitrates)
3923 return 0; /* rate not found */
3924 }
3925
3926 return mask;
3927}
3928
3929static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3930 u8 *rates, u8 rates_len,
3931 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3932{
3933 u8 i;
3934
3935 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3936
3937 for (i = 0; i < rates_len; i++) {
3938 int ridx, rbit;
3939
3940 ridx = rates[i] / 8;
3941 rbit = BIT(rates[i] % 8);
3942
3943 /* check validity */
3944 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3945 return false;
3946
3947 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09003948 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303949 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3950 mcs[ridx] |= rbit;
3951 else
3952 return false;
3953 }
3954
3955 return true;
3956}
3957
3958static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3959{
3960 u16 mcs_mask = 0;
3961
3962 switch (vht_mcs_map) {
3963 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3964 break;
3965 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3966 mcs_mask = 0x00FF;
3967 break;
3968 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3969 mcs_mask = 0x01FF;
3970 break;
3971 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3972 mcs_mask = 0x03FF;
3973 break;
3974 default:
3975 break;
3976 }
3977
3978 return mcs_mask;
3979}
3980
3981static void vht_build_mcs_mask(u16 vht_mcs_map,
3982 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3983{
3984 u8 nss;
3985
3986 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3987 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3988 vht_mcs_map >>= 2;
3989 }
3990}
3991
3992static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3993 struct nl80211_txrate_vht *txrate,
3994 u16 mcs[NL80211_VHT_NSS_MAX])
3995{
3996 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3997 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3998 u8 i;
3999
4000 if (!sband->vht_cap.vht_supported)
4001 return false;
4002
4003 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4004
4005 /* Build vht_mcs_mask from VHT capabilities */
4006 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4007
4008 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4009 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4010 mcs[i] = txrate->mcs[i];
4011 else
4012 return false;
4013 }
4014
4015 return true;
4016}
4017
4018static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4019 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4020 .len = NL80211_MAX_SUPP_RATES },
4021 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4022 .len = NL80211_MAX_SUPP_HT_RATES },
4023 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
4024 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4025};
4026
4027static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4028 struct cfg80211_bitrate_mask *mask)
4029{
4030 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4032 int rem, i;
4033 struct nlattr *tx_rates;
4034 struct ieee80211_supported_band *sband;
4035 u16 vht_tx_mcs_map;
4036
4037 memset(mask, 0, sizeof(*mask));
4038 /* Default to all rates enabled */
4039 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4040 sband = rdev->wiphy.bands[i];
4041
4042 if (!sband)
4043 continue;
4044
4045 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4046 memcpy(mask->control[i].ht_mcs,
4047 sband->ht_cap.mcs.rx_mask,
4048 sizeof(mask->control[i].ht_mcs));
4049
4050 if (!sband->vht_cap.vht_supported)
4051 continue;
4052
4053 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4054 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4055 }
4056
4057 /* if no rates are given set it back to the defaults */
4058 if (!info->attrs[NL80211_ATTR_TX_RATES])
4059 goto out;
4060
4061 /* The nested attribute uses enum nl80211_band as the index. This maps
4062 * directly to the enum nl80211_band values used in cfg80211.
4063 */
4064 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4065 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4066 enum nl80211_band band = nla_type(tx_rates);
4067 int err;
4068
4069 if (band < 0 || band >= NUM_NL80211_BANDS)
4070 return -EINVAL;
4071 sband = rdev->wiphy.bands[band];
4072 if (sband == NULL)
4073 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02004074 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02004075 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304076 if (err)
4077 return err;
4078 if (tb[NL80211_TXRATE_LEGACY]) {
4079 mask->control[band].legacy = rateset_to_mask(
4080 sband,
4081 nla_data(tb[NL80211_TXRATE_LEGACY]),
4082 nla_len(tb[NL80211_TXRATE_LEGACY]));
4083 if ((mask->control[band].legacy == 0) &&
4084 nla_len(tb[NL80211_TXRATE_LEGACY]))
4085 return -EINVAL;
4086 }
4087 if (tb[NL80211_TXRATE_HT]) {
4088 if (!ht_rateset_to_mask(
4089 sband,
4090 nla_data(tb[NL80211_TXRATE_HT]),
4091 nla_len(tb[NL80211_TXRATE_HT]),
4092 mask->control[band].ht_mcs))
4093 return -EINVAL;
4094 }
4095 if (tb[NL80211_TXRATE_VHT]) {
4096 if (!vht_set_mcs_mask(
4097 sband,
4098 nla_data(tb[NL80211_TXRATE_VHT]),
4099 mask->control[band].vht_mcs))
4100 return -EINVAL;
4101 }
4102 if (tb[NL80211_TXRATE_GI]) {
4103 mask->control[band].gi =
4104 nla_get_u8(tb[NL80211_TXRATE_GI]);
4105 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4106 return -EINVAL;
4107 }
4108
4109 if (mask->control[band].legacy == 0) {
4110 /* don't allow empty legacy rates if HT or VHT
4111 * are not even supported.
4112 */
4113 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4114 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4115 return -EINVAL;
4116
4117 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4118 if (mask->control[band].ht_mcs[i])
4119 goto out;
4120
4121 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4122 if (mask->control[band].vht_mcs[i])
4123 goto out;
4124
4125 /* legacy and mcs rates may not be both empty */
4126 return -EINVAL;
4127 }
4128 }
4129
4130out:
4131 return 0;
4132}
4133
Johannes Berg8564e382016-09-19 09:44:44 +02004134static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4135 enum nl80211_band band,
4136 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304137{
Johannes Berg8564e382016-09-19 09:44:44 +02004138 u32 count_ht, count_vht, i;
4139 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304140
4141 /* Allow only one rate */
4142 if (hweight32(rate) > 1)
4143 return -EINVAL;
4144
4145 count_ht = 0;
4146 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004147 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304148 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004149 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304150 count_ht++;
4151 if (count_ht > 1)
4152 return -EINVAL;
4153 }
4154 if (count_ht && rate)
4155 return -EINVAL;
4156 }
4157
4158 count_vht = 0;
4159 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004160 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304161 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004162 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304163 count_vht++;
4164 if (count_vht > 1)
4165 return -EINVAL;
4166 }
4167 if (count_vht && rate)
4168 return -EINVAL;
4169 }
4170
4171 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4172 return -EINVAL;
4173
Johannes Berg8564e382016-09-19 09:44:44 +02004174 if (rate &&
4175 !wiphy_ext_feature_isset(&rdev->wiphy,
4176 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4177 return -EINVAL;
4178 if (count_ht &&
4179 !wiphy_ext_feature_isset(&rdev->wiphy,
4180 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4181 return -EINVAL;
4182 if (count_vht &&
4183 !wiphy_ext_feature_isset(&rdev->wiphy,
4184 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4185 return -EINVAL;
4186
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304187 return 0;
4188}
4189
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004190static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4191 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004192 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004193{
Johannes Berg88600202012-02-13 15:17:18 +01004194 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004195 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004196
Johannes Berg88600202012-02-13 15:17:18 +01004197 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004198
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004199 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4200 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4201 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004202 if (!bcn->head_len)
4203 return -EINVAL;
4204 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004205 }
4206
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004207 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4208 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4209 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004210 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004211 }
4212
Johannes Berg4c476992010-10-04 21:36:35 +02004213 if (!haveinfo)
4214 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004215
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004216 if (attrs[NL80211_ATTR_IE]) {
4217 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4218 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004219 }
4220
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004221 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004222 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004223 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004224 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004225 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004226 }
4227
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004228 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004229 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004230 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004231 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004232 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004233 }
4234
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004235 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4236 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4237 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004238 }
4239
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004240 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4241 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4242
4243 err = nla_parse_nested(tb, NL80211_FTM_RESP_ATTR_MAX,
4244 attrs[NL80211_ATTR_FTM_RESPONDER],
4245 NULL, NULL);
4246 if (err)
4247 return err;
4248
4249 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4250 wiphy_ext_feature_isset(&rdev->wiphy,
4251 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4252 bcn->ftm_responder = 1;
4253 else
4254 return -EOPNOTSUPP;
4255
4256 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4257 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4258 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4259 }
4260
4261 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4262 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4263 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4264 }
4265 } else {
4266 bcn->ftm_responder = -1;
4267 }
4268
Johannes Berg88600202012-02-13 15:17:18 +01004269 return 0;
4270}
4271
Johannes Berg66cd7942017-02-07 22:40:44 +02004272static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4273 const u8 *rates)
4274{
4275 int i;
4276
4277 if (!rates)
4278 return;
4279
4280 for (i = 0; i < rates[1]; i++) {
4281 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4282 params->ht_required = true;
4283 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4284 params->vht_required = true;
4285 }
4286}
4287
4288/*
4289 * Since the nl80211 API didn't include, from the beginning, attributes about
4290 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4291 * benefit of drivers that rebuild IEs in the firmware.
4292 */
4293static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4294{
4295 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004296 size_t ies_len = bcn->tail_len;
4297 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004298 const u8 *rates;
4299 const u8 *cap;
4300
4301 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4302 nl80211_check_ap_rate_selectors(params, rates);
4303
4304 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4305 nl80211_check_ap_rate_selectors(params, rates);
4306
4307 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4308 if (cap && cap[1] >= sizeof(*params->ht_cap))
4309 params->ht_cap = (void *)(cap + 2);
4310 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4311 if (cap && cap[1] >= sizeof(*params->vht_cap))
4312 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004313 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4314 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4315 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004316}
4317
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004318static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4319 struct cfg80211_ap_settings *params)
4320{
4321 struct wireless_dev *wdev;
4322 bool ret = false;
4323
Johannes Berg53873f12016-05-03 16:52:04 +03004324 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004325 if (wdev->iftype != NL80211_IFTYPE_AP &&
4326 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4327 continue;
4328
Johannes Berg683b6d32012-11-08 21:25:48 +01004329 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004330 continue;
4331
Johannes Berg683b6d32012-11-08 21:25:48 +01004332 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004333 ret = true;
4334 break;
4335 }
4336
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004337 return ret;
4338}
4339
Jouni Malinene39e5b52012-09-30 19:29:39 +03004340static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4341 enum nl80211_auth_type auth_type,
4342 enum nl80211_commands cmd)
4343{
4344 if (auth_type > NL80211_AUTHTYPE_MAX)
4345 return false;
4346
4347 switch (cmd) {
4348 case NL80211_CMD_AUTHENTICATE:
4349 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4350 auth_type == NL80211_AUTHTYPE_SAE)
4351 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004352 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4353 NL80211_EXT_FEATURE_FILS_STA) &&
4354 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4355 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4356 auth_type == NL80211_AUTHTYPE_FILS_PK))
4357 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004358 return true;
4359 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004360 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4361 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004362 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004363
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004364 /* FILS with SK PFS or PK not supported yet */
4365 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4366 auth_type == NL80211_AUTHTYPE_FILS_PK)
4367 return false;
4368 if (!wiphy_ext_feature_isset(
4369 &rdev->wiphy,
4370 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4371 auth_type == NL80211_AUTHTYPE_FILS_SK)
4372 return false;
4373 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004374 case NL80211_CMD_START_AP:
4375 /* SAE not supported yet */
4376 if (auth_type == NL80211_AUTHTYPE_SAE)
4377 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004378 /* FILS not supported yet */
4379 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4380 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4381 auth_type == NL80211_AUTHTYPE_FILS_PK)
4382 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004383 return true;
4384 default:
4385 return false;
4386 }
4387}
4388
Johannes Berg88600202012-02-13 15:17:18 +01004389static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4390{
4391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4392 struct net_device *dev = info->user_ptr[1];
4393 struct wireless_dev *wdev = dev->ieee80211_ptr;
4394 struct cfg80211_ap_settings params;
4395 int err;
4396
4397 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4398 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4399 return -EOPNOTSUPP;
4400
4401 if (!rdev->ops->start_ap)
4402 return -EOPNOTSUPP;
4403
4404 if (wdev->beacon_interval)
4405 return -EALREADY;
4406
4407 memset(&params, 0, sizeof(params));
4408
4409 /* these are required for START_AP */
4410 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4411 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4412 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4413 return -EINVAL;
4414
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004415 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004416 if (err)
4417 return err;
4418
4419 params.beacon_interval =
4420 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4421 params.dtim_period =
4422 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4423
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304424 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4425 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004426 if (err)
4427 return err;
4428
4429 /*
4430 * In theory, some of these attributes should be required here
4431 * but since they were not used when the command was originally
4432 * added, keep them optional for old user space programs to let
4433 * them continue to work with drivers that do not need the
4434 * additional information -- drivers must check!
4435 */
4436 if (info->attrs[NL80211_ATTR_SSID]) {
4437 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4438 params.ssid_len =
4439 nla_len(info->attrs[NL80211_ATTR_SSID]);
4440 if (params.ssid_len == 0 ||
4441 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4442 return -EINVAL;
4443 }
4444
Johannes Bergab0d76f2018-10-02 10:00:07 +02004445 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004446 params.hidden_ssid = nla_get_u32(
4447 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004448
4449 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4450
4451 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4452 params.auth_type = nla_get_u32(
4453 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004454 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4455 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004456 return -EINVAL;
4457 } else
4458 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4459
4460 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4461 NL80211_MAX_NR_CIPHER_SUITES);
4462 if (err)
4463 return err;
4464
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304465 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4466 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4467 return -EOPNOTSUPP;
4468 params.inactivity_timeout = nla_get_u16(
4469 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4470 }
4471
Johannes Berg53cabad2012-11-14 15:17:28 +01004472 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4473 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4474 return -EINVAL;
4475 params.p2p_ctwindow =
4476 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004477 if (params.p2p_ctwindow != 0 &&
4478 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4479 return -EINVAL;
4480 }
4481
4482 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4483 u8 tmp;
4484
4485 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4486 return -EINVAL;
4487 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004488 params.p2p_opp_ps = tmp;
4489 if (params.p2p_opp_ps != 0 &&
4490 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4491 return -EINVAL;
4492 }
4493
Johannes Bergaa430da2012-05-16 23:50:18 +02004494 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004495 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4496 if (err)
4497 return err;
4498 } else if (wdev->preset_chandef.chan) {
4499 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004500 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004501 return -EINVAL;
4502
Arik Nemtsov923b3522015-07-08 15:41:44 +03004503 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4504 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004505 return -EINVAL;
4506
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304507 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4508 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4509 if (err)
4510 return err;
4511
Johannes Berg8564e382016-09-19 09:44:44 +02004512 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4513 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304514 if (err)
4515 return err;
4516 }
4517
Eliad Peller18998c32014-09-10 14:07:34 +03004518 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4519 params.smps_mode =
4520 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4521 switch (params.smps_mode) {
4522 case NL80211_SMPS_OFF:
4523 break;
4524 case NL80211_SMPS_STATIC:
4525 if (!(rdev->wiphy.features &
4526 NL80211_FEATURE_STATIC_SMPS))
4527 return -EINVAL;
4528 break;
4529 case NL80211_SMPS_DYNAMIC:
4530 if (!(rdev->wiphy.features &
4531 NL80211_FEATURE_DYNAMIC_SMPS))
4532 return -EINVAL;
4533 break;
4534 default:
4535 return -EINVAL;
4536 }
4537 } else {
4538 params.smps_mode = NL80211_SMPS_OFF;
4539 }
4540
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304541 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4542 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4543 return -EOPNOTSUPP;
4544
Ola Olsson4baf6be2015-10-29 07:04:58 +01004545 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4546 params.acl = parse_acl_data(&rdev->wiphy, info);
4547 if (IS_ERR(params.acl))
4548 return PTR_ERR(params.acl);
4549 }
4550
Johannes Berg66cd7942017-02-07 22:40:44 +02004551 nl80211_calculate_ap_params(&params);
4552
Srinivas Dasarife494372019-01-23 18:06:56 +05304553 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4554 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4555
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004556 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004557 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004558 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004559 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004560 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004561 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004562 wdev->ssid_len = params.ssid_len;
4563 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004564
4565 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4566 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004567 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004568 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304569
4570 kfree(params.acl);
4571
Johannes Berg56d18932011-05-09 18:41:15 +02004572 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004573}
4574
Johannes Berg88600202012-02-13 15:17:18 +01004575static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4576{
4577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4578 struct net_device *dev = info->user_ptr[1];
4579 struct wireless_dev *wdev = dev->ieee80211_ptr;
4580 struct cfg80211_beacon_data params;
4581 int err;
4582
4583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4584 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4585 return -EOPNOTSUPP;
4586
4587 if (!rdev->ops->change_beacon)
4588 return -EOPNOTSUPP;
4589
4590 if (!wdev->beacon_interval)
4591 return -EINVAL;
4592
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004593 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004594 if (err)
4595 return err;
4596
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004597 wdev_lock(wdev);
4598 err = rdev_change_beacon(rdev, dev, &params);
4599 wdev_unlock(wdev);
4600
4601 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004602}
4603
4604static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004605{
Johannes Berg4c476992010-10-04 21:36:35 +02004606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4607 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004608
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004609 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004610}
4611
Johannes Berg5727ef12007-12-19 02:03:34 +01004612static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4613 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4614 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4615 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004616 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004617 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004618 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004619};
4620
Johannes Bergeccb8e82009-05-11 21:57:56 +03004621static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004622 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004623 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004624{
4625 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004626 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004627 int flag;
4628
Johannes Bergeccb8e82009-05-11 21:57:56 +03004629 /*
4630 * Try parsing the new attribute first so userspace
4631 * can specify both for older kernels.
4632 */
4633 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4634 if (nla) {
4635 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004636
Johannes Bergeccb8e82009-05-11 21:57:56 +03004637 sta_flags = nla_data(nla);
4638 params->sta_flags_mask = sta_flags->mask;
4639 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004640 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004641 if ((params->sta_flags_mask |
4642 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4643 return -EINVAL;
4644 return 0;
4645 }
4646
4647 /* if present, parse the old attribute */
4648
4649 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004650 if (!nla)
4651 return 0;
4652
Johannes Bergfceb6432017-04-12 14:34:07 +02004653 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004654 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004655 return -EINVAL;
4656
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004657 /*
4658 * Only allow certain flags for interface types so that
4659 * other attributes are silently ignored. Remember that
4660 * this is backward compatibility code with old userspace
4661 * and shouldn't be hit in other cases anyway.
4662 */
4663 switch (iftype) {
4664 case NL80211_IFTYPE_AP:
4665 case NL80211_IFTYPE_AP_VLAN:
4666 case NL80211_IFTYPE_P2P_GO:
4667 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4668 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4669 BIT(NL80211_STA_FLAG_WME) |
4670 BIT(NL80211_STA_FLAG_MFP);
4671 break;
4672 case NL80211_IFTYPE_P2P_CLIENT:
4673 case NL80211_IFTYPE_STATION:
4674 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4675 BIT(NL80211_STA_FLAG_TDLS_PEER);
4676 break;
4677 case NL80211_IFTYPE_MESH_POINT:
4678 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4679 BIT(NL80211_STA_FLAG_MFP) |
4680 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004681 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004682 default:
4683 return -EINVAL;
4684 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004685
Johannes Berg3383b5a2012-05-10 20:14:43 +02004686 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4687 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004688 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004689
Johannes Berg3383b5a2012-05-10 20:14:43 +02004690 /* no longer support new API additions in old API */
4691 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4692 return -EINVAL;
4693 }
4694 }
4695
Johannes Berg5727ef12007-12-19 02:03:34 +01004696 return 0;
4697}
4698
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004699bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004700{
4701 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004702 u32 bitrate;
4703 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004704 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004705
4706 rate = nla_nest_start(msg, attr);
4707 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004708 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004709
4710 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4711 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004712 /* report 16-bit bitrate only if we can */
4713 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004714 if (bitrate > 0 &&
4715 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4716 return false;
4717 if (bitrate_compat > 0 &&
4718 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4719 return false;
4720
Johannes Bergb51f3be2015-01-15 16:14:02 +01004721 switch (info->bw) {
4722 case RATE_INFO_BW_5:
4723 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4724 break;
4725 case RATE_INFO_BW_10:
4726 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4727 break;
4728 default:
4729 WARN_ON(1);
4730 /* fall through */
4731 case RATE_INFO_BW_20:
4732 rate_flg = 0;
4733 break;
4734 case RATE_INFO_BW_40:
4735 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4736 break;
4737 case RATE_INFO_BW_80:
4738 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4739 break;
4740 case RATE_INFO_BW_160:
4741 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4742 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004743 case RATE_INFO_BW_HE_RU:
4744 rate_flg = 0;
4745 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004746 }
4747
4748 if (rate_flg && nla_put_flag(msg, rate_flg))
4749 return false;
4750
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004751 if (info->flags & RATE_INFO_FLAGS_MCS) {
4752 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4753 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004754 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4755 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4756 return false;
4757 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4758 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4759 return false;
4760 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4761 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004762 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4763 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4764 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004765 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4766 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4767 return false;
4768 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4769 return false;
4770 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4771 return false;
4772 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4773 return false;
4774 if (info->bw == RATE_INFO_BW_HE_RU &&
4775 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4776 info->he_ru_alloc))
4777 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004778 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004779
4780 nla_nest_end(msg, rate);
4781 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004782}
4783
Felix Fietkau119363c2013-04-22 16:29:30 +02004784static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4785 int id)
4786{
4787 void *attr;
4788 int i = 0;
4789
4790 if (!mask)
4791 return true;
4792
4793 attr = nla_nest_start(msg, id);
4794 if (!attr)
4795 return false;
4796
4797 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4798 if (!(mask & BIT(i)))
4799 continue;
4800
4801 if (nla_put_u8(msg, i, signal[i]))
4802 return false;
4803 }
4804
4805 nla_nest_end(msg, attr);
4806
4807 return true;
4808}
4809
Johannes Bergcf5ead82014-11-14 17:14:00 +01004810static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4811 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004812 struct cfg80211_registered_device *rdev,
4813 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004814 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004815{
4816 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004817 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004818
Johannes Bergcf5ead82014-11-14 17:14:00 +01004819 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004820 if (!hdr)
4821 return -1;
4822
David S. Miller9360ffd2012-03-29 04:41:26 -04004823 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4824 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4825 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4826 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004827
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004828 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4829 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004830 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004831
4832#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004833 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03004834 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004835 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4836 sinfo->memb)) \
4837 goto nla_put_failure; \
4838 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004839#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03004840 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004841 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4842 sinfo->memb, NL80211_STA_INFO_PAD)) \
4843 goto nla_put_failure; \
4844 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004845
4846 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4847 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4848
Omer Efrat397c6572018-06-17 13:06:14 +03004849 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4850 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004851 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004852 (u32)sinfo->rx_bytes))
4853 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004854
Omer Efrat397c6572018-06-17 13:06:14 +03004855 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4856 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004857 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4858 (u32)sinfo->tx_bytes))
4859 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004860
Johannes Bergd686b922016-04-26 09:54:11 +02004861 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4862 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004863 PUT_SINFO(LLID, llid, u16);
4864 PUT_SINFO(PLID, plid, u16);
4865 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004866 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08004867 PUT_SINFO_U64(TX_DURATION, tx_duration);
4868
4869 if (wiphy_ext_feature_isset(&rdev->wiphy,
4870 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4871 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01004872
John W. Linville66266b32012-03-15 13:25:41 -04004873 switch (rdev->wiphy.signal_type) {
4874 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004875 PUT_SINFO(SIGNAL, signal, u8);
4876 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004877 break;
4878 default:
4879 break;
4880 }
Omer Efrat397c6572018-06-17 13:06:14 +03004881 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004882 if (!nl80211_put_signal(msg, sinfo->chains,
4883 sinfo->chain_signal,
4884 NL80211_STA_INFO_CHAIN_SIGNAL))
4885 goto nla_put_failure;
4886 }
Omer Efrat397c6572018-06-17 13:06:14 +03004887 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004888 if (!nl80211_put_signal(msg, sinfo->chains,
4889 sinfo->chain_signal_avg,
4890 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4891 goto nla_put_failure;
4892 }
Omer Efrat397c6572018-06-17 13:06:14 +03004893 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004894 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4895 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004896 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004897 }
Omer Efrat397c6572018-06-17 13:06:14 +03004898 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004899 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4900 NL80211_STA_INFO_RX_BITRATE))
4901 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004902 }
Johannes Berg319090b2014-11-17 14:08:11 +01004903
4904 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4905 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4906 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4907 PUT_SINFO(TX_FAILED, tx_failed, u32);
4908 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4909 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4910 PUT_SINFO(LOCAL_PM, local_pm, u32);
4911 PUT_SINFO(PEER_PM, peer_pm, u32);
4912 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04004913 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004914
Omer Efrat397c6572018-06-17 13:06:14 +03004915 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004916 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4917 if (!bss_param)
4918 goto nla_put_failure;
4919
David S. Miller9360ffd2012-03-29 04:41:26 -04004920 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4921 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4922 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4923 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4924 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4925 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4926 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4927 sinfo->bss_param.dtim_period) ||
4928 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4929 sinfo->bss_param.beacon_interval))
4930 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004931
4932 nla_nest_end(msg, bss_param);
4933 }
Omer Efrat397c6572018-06-17 13:06:14 +03004934 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004935 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4936 sizeof(struct nl80211_sta_flag_update),
4937 &sinfo->sta_flags))
4938 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004939
Johannes Bergd686b922016-04-26 09:54:11 +02004940 PUT_SINFO_U64(T_OFFSET, t_offset);
4941 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4942 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004943 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03004944 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
4945 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05304946 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05304947 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
4948 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
4949 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
4950 }
Johannes Berg319090b2014-11-17 14:08:11 +01004951
4952#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004953#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004954
Arend van Spriel8689c052018-05-10 13:50:12 +02004955 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01004956 struct nlattr *tidsattr;
4957 int tid;
4958
4959 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4960 if (!tidsattr)
4961 goto nla_put_failure;
4962
4963 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4964 struct cfg80211_tid_stats *tidstats;
4965 struct nlattr *tidattr;
4966
4967 tidstats = &sinfo->pertid[tid];
4968
4969 if (!tidstats->filled)
4970 continue;
4971
4972 tidattr = nla_nest_start(msg, tid + 1);
4973 if (!tidattr)
4974 goto nla_put_failure;
4975
Johannes Bergd686b922016-04-26 09:54:11 +02004976#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004977 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004978 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4979 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004980 goto nla_put_failure; \
4981 } while (0)
4982
Johannes Bergd686b922016-04-26 09:54:11 +02004983 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4984 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4985 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4986 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004987
Johannes Bergd686b922016-04-26 09:54:11 +02004988#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02004989 if ((tidstats->filled &
4990 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
4991 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
4992 NL80211_TID_STATS_TXQ_STATS))
4993 goto nla_put_failure;
4994
Johannes Berg6de39802014-12-19 12:34:00 +01004995 nla_nest_end(msg, tidattr);
4996 }
4997
4998 nla_nest_end(msg, tidsattr);
4999 }
5000
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005001 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005002
Johannes Berg319090b2014-11-17 14:08:11 +01005003 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005004 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5005 sinfo->assoc_req_ies))
5006 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005007
Johannes Berg7ea3e112018-05-18 11:40:44 +02005008 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005009 genlmsg_end(msg, hdr);
5010 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005011
5012 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005013 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005014 genlmsg_cancel(msg, hdr);
5015 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005016}
5017
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005018static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005019 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005020{
Johannes Berg73887fd2018-05-18 09:57:55 +02005021 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005022 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005023 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005024 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005025 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005026 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005027
Johannes Bergea90e0d2017-03-15 14:26:04 +01005028 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005029 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005030 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005031 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005032
Johannes Berg97990a02013-04-19 01:02:55 +02005033 if (!wdev->netdev) {
5034 err = -EINVAL;
5035 goto out_err;
5036 }
5037
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005038 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005039 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005040 goto out_err;
5041 }
5042
Johannes Bergbba95fe2008-07-29 13:22:51 +02005043 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005044 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005045 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005046 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005047 if (err == -ENOENT)
5048 break;
5049 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005050 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005051
Johannes Bergcf5ead82014-11-14 17:14:00 +01005052 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005053 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005054 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005055 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005056 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005057 goto out;
5058
5059 sta_idx++;
5060 }
5061
Johannes Bergbba95fe2008-07-29 13:22:51 +02005062 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005063 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005064 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005065 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005066 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005067
5068 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005069}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005070
Johannes Berg5727ef12007-12-19 02:03:34 +01005071static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5072{
Johannes Berg4c476992010-10-04 21:36:35 +02005073 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5074 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005075 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005076 struct sk_buff *msg;
5077 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005078 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005079
Johannes Berg73887fd2018-05-18 09:57:55 +02005080 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005081
Johannes Berg73887fd2018-05-18 09:57:55 +02005082 if (!info->attrs[NL80211_ATTR_MAC])
5083 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005084
5085 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5086
Johannes Berg73887fd2018-05-18 09:57:55 +02005087 if (!rdev->ops->get_station)
5088 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005089
Johannes Berg73887fd2018-05-18 09:57:55 +02005090 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005091 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005092 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005093
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005095 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005096 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005097 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005098 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005099
Johannes Bergcf5ead82014-11-14 17:14:00 +01005100 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5101 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005102 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005103 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005104 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005105 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005106
Johannes Berg73887fd2018-05-18 09:57:55 +02005107 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005108}
5109
Johannes Berg77ee7c82013-02-15 00:48:33 +01005110int cfg80211_check_station_change(struct wiphy *wiphy,
5111 struct station_parameters *params,
5112 enum cfg80211_station_type statype)
5113{
Ayala Bekere4208422015-10-23 11:20:06 +03005114 if (params->listen_interval != -1 &&
5115 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005116 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005117
Ayala Beker17b94242016-03-17 15:41:38 +02005118 if (params->support_p2p_ps != -1 &&
5119 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5120 return -EINVAL;
5121
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005122 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005123 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5124 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005125 return -EINVAL;
5126
5127 /* When you run into this, adjust the code below for the new flag */
5128 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5129
5130 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005131 case CFG80211_STA_MESH_PEER_KERNEL:
5132 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005133 /*
5134 * No ignoring the TDLS flag here -- the userspace mesh
5135 * code doesn't have the bug of including TDLS in the
5136 * mask everywhere.
5137 */
5138 if (params->sta_flags_mask &
5139 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5140 BIT(NL80211_STA_FLAG_MFP) |
5141 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5142 return -EINVAL;
5143 break;
5144 case CFG80211_STA_TDLS_PEER_SETUP:
5145 case CFG80211_STA_TDLS_PEER_ACTIVE:
5146 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5147 return -EINVAL;
5148 /* ignore since it can't change */
5149 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5150 break;
5151 default:
5152 /* disallow mesh-specific things */
5153 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5154 return -EINVAL;
5155 if (params->local_pm)
5156 return -EINVAL;
5157 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5158 return -EINVAL;
5159 }
5160
5161 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5162 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5163 /* TDLS can't be set, ... */
5164 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5165 return -EINVAL;
5166 /*
5167 * ... but don't bother the driver with it. This works around
5168 * a hostapd/wpa_supplicant issue -- it always includes the
5169 * TLDS_PEER flag in the mask even for AP mode.
5170 */
5171 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5172 }
5173
Ayala Beker47edb112015-09-21 15:49:53 +03005174 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5175 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005176 /* reject other things that can't change */
5177 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5178 return -EINVAL;
5179 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5180 return -EINVAL;
5181 if (params->supported_rates)
5182 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005183 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5184 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005185 return -EINVAL;
5186 }
5187
Ayala Beker47edb112015-09-21 15:49:53 +03005188 if (statype != CFG80211_STA_AP_CLIENT &&
5189 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005190 if (params->vlan)
5191 return -EINVAL;
5192 }
5193
5194 switch (statype) {
5195 case CFG80211_STA_AP_MLME_CLIENT:
5196 /* Use this only for authorizing/unauthorizing a station */
5197 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5198 return -EOPNOTSUPP;
5199 break;
5200 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005201 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005202 /* accept only the listed bits */
5203 if (params->sta_flags_mask &
5204 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5205 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5206 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5207 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5208 BIT(NL80211_STA_FLAG_WME) |
5209 BIT(NL80211_STA_FLAG_MFP)))
5210 return -EINVAL;
5211
5212 /* but authenticated/associated only if driver handles it */
5213 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5214 params->sta_flags_mask &
5215 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5216 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5217 return -EINVAL;
5218 break;
5219 case CFG80211_STA_IBSS:
5220 case CFG80211_STA_AP_STA:
5221 /* reject any changes other than AUTHORIZED */
5222 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5223 return -EINVAL;
5224 break;
5225 case CFG80211_STA_TDLS_PEER_SETUP:
5226 /* reject any changes other than AUTHORIZED or WME */
5227 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5228 BIT(NL80211_STA_FLAG_WME)))
5229 return -EINVAL;
5230 /* force (at least) rates when authorizing */
5231 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5232 !params->supported_rates)
5233 return -EINVAL;
5234 break;
5235 case CFG80211_STA_TDLS_PEER_ACTIVE:
5236 /* reject any changes */
5237 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005238 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005239 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5240 return -EINVAL;
5241 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005242 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005243 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5244 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005245 return -EINVAL;
5246 break;
5247 }
5248
Beni Lev06f7c882016-07-19 19:28:56 +03005249 /*
5250 * Older kernel versions ignored this attribute entirely, so don't
5251 * reject attempts to update it but mark it as unused instead so the
5252 * driver won't look at the data.
5253 */
5254 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5255 statype != CFG80211_STA_TDLS_PEER_SETUP)
5256 params->opmode_notif_used = false;
5257
Johannes Berg77ee7c82013-02-15 00:48:33 +01005258 return 0;
5259}
5260EXPORT_SYMBOL(cfg80211_check_station_change);
5261
Johannes Berg5727ef12007-12-19 02:03:34 +01005262/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005263 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005264 */
Johannes Berg80b99892011-11-18 16:23:01 +01005265static struct net_device *get_vlan(struct genl_info *info,
5266 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005267{
Johannes Berg463d0182009-07-14 00:33:35 +02005268 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005269 struct net_device *v;
5270 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005271
Johannes Berg80b99892011-11-18 16:23:01 +01005272 if (!vlanattr)
5273 return NULL;
5274
5275 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5276 if (!v)
5277 return ERR_PTR(-ENODEV);
5278
5279 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5280 ret = -EINVAL;
5281 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005282 }
Johannes Berg80b99892011-11-18 16:23:01 +01005283
Johannes Berg77ee7c82013-02-15 00:48:33 +01005284 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5285 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5286 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5287 ret = -EINVAL;
5288 goto error;
5289 }
5290
Johannes Berg80b99892011-11-18 16:23:01 +01005291 if (!netif_running(v)) {
5292 ret = -ENETDOWN;
5293 goto error;
5294 }
5295
5296 return v;
5297 error:
5298 dev_put(v);
5299 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005300}
5301
Johannes Berg94e860f2014-01-20 23:58:15 +01005302static const struct nla_policy
5303nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005304 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5305 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5306};
5307
Johannes Bergff276692013-02-15 00:09:01 +01005308static int nl80211_parse_sta_wme(struct genl_info *info,
5309 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005310{
Jouni Malinendf881292013-02-14 21:10:54 +02005311 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5312 struct nlattr *nla;
5313 int err;
5314
Jouni Malinendf881292013-02-14 21:10:54 +02005315 /* parse WME attributes if present */
5316 if (!info->attrs[NL80211_ATTR_STA_WME])
5317 return 0;
5318
5319 nla = info->attrs[NL80211_ATTR_STA_WME];
5320 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02005321 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005322 if (err)
5323 return err;
5324
5325 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5326 params->uapsd_queues = nla_get_u8(
5327 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5328 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5329 return -EINVAL;
5330
5331 if (tb[NL80211_STA_WME_MAX_SP])
5332 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5333
5334 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5335 return -EINVAL;
5336
5337 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5338
5339 return 0;
5340}
5341
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305342static int nl80211_parse_sta_channel_info(struct genl_info *info,
5343 struct station_parameters *params)
5344{
5345 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5346 params->supported_channels =
5347 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5348 params->supported_channels_len =
5349 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5350 /*
5351 * Need to include at least one (first channel, number of
5352 * channels) tuple for each subband, and must have proper
5353 * tuples for the rest of the data as well.
5354 */
5355 if (params->supported_channels_len < 2)
5356 return -EINVAL;
5357 if (params->supported_channels_len % 2)
5358 return -EINVAL;
5359 }
5360
5361 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5362 params->supported_oper_classes =
5363 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5364 params->supported_oper_classes_len =
5365 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5366 /*
5367 * The value of the Length field of the Supported Operating
5368 * Classes element is between 2 and 253.
5369 */
5370 if (params->supported_oper_classes_len < 2 ||
5371 params->supported_oper_classes_len > 253)
5372 return -EINVAL;
5373 }
5374 return 0;
5375}
5376
Johannes Bergff276692013-02-15 00:09:01 +01005377static int nl80211_set_station_tdls(struct genl_info *info,
5378 struct station_parameters *params)
5379{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305380 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005381 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005382 if (info->attrs[NL80211_ATTR_PEER_AID])
5383 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005384 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5385 params->ht_capa =
5386 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5387 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5388 params->vht_capa =
5389 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005390 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5391 params->he_capa =
5392 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5393 params->he_capa_len =
5394 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5395
5396 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5397 return -EINVAL;
5398 }
Johannes Bergff276692013-02-15 00:09:01 +01005399
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305400 err = nl80211_parse_sta_channel_info(info, params);
5401 if (err)
5402 return err;
5403
Johannes Bergff276692013-02-15 00:09:01 +01005404 return nl80211_parse_sta_wme(info, params);
5405}
5406
Johannes Berg5727ef12007-12-19 02:03:34 +01005407static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5408{
Johannes Berg4c476992010-10-04 21:36:35 +02005409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005410 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005411 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005412 u8 *mac_addr;
5413 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005414
5415 memset(&params, 0, sizeof(params));
5416
Johannes Berg77ee7c82013-02-15 00:48:33 +01005417 if (!rdev->ops->change_station)
5418 return -EOPNOTSUPP;
5419
Ayala Bekere4208422015-10-23 11:20:06 +03005420 /*
5421 * AID and listen_interval properties can be set only for unassociated
5422 * station. Include these parameters here and will check them in
5423 * cfg80211_check_station_change().
5424 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005425 if (info->attrs[NL80211_ATTR_STA_AID])
5426 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005427
5428 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5429 params.listen_interval =
5430 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5431 else
5432 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005433
Johannes Bergab0d76f2018-10-02 10:00:07 +02005434 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5435 params.support_p2p_ps =
5436 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5437 else
Ayala Beker17b94242016-03-17 15:41:38 +02005438 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005439
Johannes Berg5727ef12007-12-19 02:03:34 +01005440 if (!info->attrs[NL80211_ATTR_MAC])
5441 return -EINVAL;
5442
5443 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5444
5445 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5446 params.supported_rates =
5447 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5448 params.supported_rates_len =
5449 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5450 }
5451
Jouni Malinen9d62a982013-02-14 21:10:13 +02005452 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5453 params.capability =
5454 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5455 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5456 }
5457
5458 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5459 params.ext_capab =
5460 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5461 params.ext_capab_len =
5462 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5463 }
5464
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005465 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005466 return -EINVAL;
5467
Johannes Bergab0d76f2018-10-02 10:00:07 +02005468 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005469 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005470 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005471
Johannes Bergf8bacc22013-02-14 23:27:01 +01005472 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005473 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005474 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005475 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005476 params.peer_aid = nla_get_u16(
5477 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005478 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5479 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005480
Johannes Bergab0d76f2018-10-02 10:00:07 +02005481 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5482 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005483 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5484
Beni Lev06f7c882016-07-19 19:28:56 +03005485 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5486 params.opmode_notif_used = true;
5487 params.opmode_notif =
5488 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5489 }
5490
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005491 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5492 params.airtime_weight =
5493 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5494
5495 if (params.airtime_weight &&
5496 !wiphy_ext_feature_isset(&rdev->wiphy,
5497 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5498 return -EOPNOTSUPP;
5499
Johannes Berg77ee7c82013-02-15 00:48:33 +01005500 /* Include parameters for TDLS peer (will check later) */
5501 err = nl80211_set_station_tdls(info, &params);
5502 if (err)
5503 return err;
5504
5505 params.vlan = get_vlan(info, rdev);
5506 if (IS_ERR(params.vlan))
5507 return PTR_ERR(params.vlan);
5508
Johannes Berga97f4422009-06-18 17:23:43 +02005509 switch (dev->ieee80211_ptr->iftype) {
5510 case NL80211_IFTYPE_AP:
5511 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005512 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005513 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005514 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005515 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005516 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005517 break;
5518 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005519 err = -EOPNOTSUPP;
5520 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005521 }
5522
Johannes Berg77ee7c82013-02-15 00:48:33 +01005523 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005524 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005525
Johannes Berg77ee7c82013-02-15 00:48:33 +01005526 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005527 if (params.vlan)
5528 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005529
Johannes Berg5727ef12007-12-19 02:03:34 +01005530 return err;
5531}
5532
5533static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5534{
Johannes Berg4c476992010-10-04 21:36:35 +02005535 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005536 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005537 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005538 struct station_parameters params;
5539 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005540 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5541 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005542
5543 memset(&params, 0, sizeof(params));
5544
Johannes Berg984c3112013-02-14 23:43:25 +01005545 if (!rdev->ops->add_station)
5546 return -EOPNOTSUPP;
5547
Johannes Berg5727ef12007-12-19 02:03:34 +01005548 if (!info->attrs[NL80211_ATTR_MAC])
5549 return -EINVAL;
5550
Johannes Berg5727ef12007-12-19 02:03:34 +01005551 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5552 return -EINVAL;
5553
5554 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5555 return -EINVAL;
5556
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005557 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5558 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005559 return -EINVAL;
5560
Johannes Berg5727ef12007-12-19 02:03:34 +01005561 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5562 params.supported_rates =
5563 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5564 params.supported_rates_len =
5565 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5566 params.listen_interval =
5567 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005568
Ayala Beker17b94242016-03-17 15:41:38 +02005569 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005570 params.support_p2p_ps =
5571 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005572 } else {
5573 /*
5574 * if not specified, assume it's supported for P2P GO interface,
5575 * and is NOT supported for AP interface
5576 */
5577 params.support_p2p_ps =
5578 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5579 }
5580
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005581 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005582 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005583 else
5584 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005585
Jouni Malinen9d62a982013-02-14 21:10:13 +02005586 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5587 params.capability =
5588 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5589 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5590 }
5591
5592 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5593 params.ext_capab =
5594 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5595 params.ext_capab_len =
5596 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5597 }
5598
Jouni Malinen36aedc92008-08-25 11:58:58 +03005599 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5600 params.ht_capa =
5601 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005602
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005603 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5604 params.vht_capa =
5605 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5606
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005607 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5608 params.he_capa =
5609 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5610 params.he_capa_len =
5611 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5612
5613 /* max len is validated in nla policy */
5614 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5615 return -EINVAL;
5616 }
5617
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005618 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5619 params.opmode_notif_used = true;
5620 params.opmode_notif =
5621 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5622 }
5623
Johannes Bergab0d76f2018-10-02 10:00:07 +02005624 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005625 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005626 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005627
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005628 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5629 params.airtime_weight =
5630 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5631
5632 if (params.airtime_weight &&
5633 !wiphy_ext_feature_isset(&rdev->wiphy,
5634 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5635 return -EOPNOTSUPP;
5636
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305637 err = nl80211_parse_sta_channel_info(info, &params);
5638 if (err)
5639 return err;
5640
Johannes Bergff276692013-02-15 00:09:01 +01005641 err = nl80211_parse_sta_wme(info, &params);
5642 if (err)
5643 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005644
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005645 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005646 return -EINVAL;
5647
Johannes Berg496fcc22015-03-12 08:53:27 +02005648 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5649 * as userspace might just pass through the capabilities from the IEs
5650 * directly, rather than enforcing this restriction and returning an
5651 * error in this case.
5652 */
5653 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5654 params.ht_capa = NULL;
5655 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005656
5657 /* HE requires WME */
5658 if (params.he_capa_len)
5659 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005660 }
5661
Johannes Berg77ee7c82013-02-15 00:48:33 +01005662 /* When you run into this, adjust the code below for the new flag */
5663 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5664
Johannes Bergbdd90d52011-12-14 12:20:27 +01005665 switch (dev->ieee80211_ptr->iftype) {
5666 case NL80211_IFTYPE_AP:
5667 case NL80211_IFTYPE_AP_VLAN:
5668 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005669 /* ignore WME attributes if iface/sta is not capable */
5670 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5671 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5672 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005673
Johannes Bergbdd90d52011-12-14 12:20:27 +01005674 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005675 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5676 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005677 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005678 /* but don't bother the driver with it */
5679 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005680
Johannes Bergd582cff2012-10-26 17:53:44 +02005681 /* allow authenticated/associated only if driver handles it */
5682 if (!(rdev->wiphy.features &
5683 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005684 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005685 return -EINVAL;
5686
Johannes Bergbda95eb2015-11-26 16:26:13 +01005687 /* Older userspace, or userspace wanting to be compatible with
5688 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5689 * and assoc flags in the mask, but assumes the station will be
5690 * added as associated anyway since this was the required driver
5691 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5692 * introduced.
5693 * In order to not bother drivers with this quirk in the API
5694 * set the flags in both the mask and set for new stations in
5695 * this case.
5696 */
5697 if (!(params.sta_flags_mask & auth_assoc)) {
5698 params.sta_flags_mask |= auth_assoc;
5699 params.sta_flags_set |= auth_assoc;
5700 }
5701
Johannes Bergbdd90d52011-12-14 12:20:27 +01005702 /* must be last in here for error handling */
5703 params.vlan = get_vlan(info, rdev);
5704 if (IS_ERR(params.vlan))
5705 return PTR_ERR(params.vlan);
5706 break;
5707 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005708 /* ignore uAPSD data */
5709 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5710
Johannes Bergd582cff2012-10-26 17:53:44 +02005711 /* associated is disallowed */
5712 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5713 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005714 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005715 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5716 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005717 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005718 break;
5719 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005720 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005721 /* ignore uAPSD data */
5722 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5723
Johannes Berg77ee7c82013-02-15 00:48:33 +01005724 /* these are disallowed */
5725 if (params.sta_flags_mask &
5726 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5727 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005728 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005729 /* Only TDLS peers can be added */
5730 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5731 return -EINVAL;
5732 /* Can only add if TDLS ... */
5733 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5734 return -EOPNOTSUPP;
5735 /* ... with external setup is supported */
5736 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5737 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005738 /*
5739 * Older wpa_supplicant versions always mark the TDLS peer
5740 * as authorized, but it shouldn't yet be.
5741 */
5742 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005743 break;
5744 default:
5745 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005746 }
5747
Johannes Bergbdd90d52011-12-14 12:20:27 +01005748 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005749
Hila Gonene35e4d22012-06-27 17:19:42 +03005750 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005751
Johannes Berg5727ef12007-12-19 02:03:34 +01005752 if (params.vlan)
5753 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005754 return err;
5755}
5756
5757static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5758{
Johannes Berg4c476992010-10-04 21:36:35 +02005759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5760 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005761 struct station_del_parameters params;
5762
5763 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005764
5765 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005766 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005767
Johannes Berge80cf852009-05-11 14:43:13 +02005768 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005769 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005770 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005771 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5772 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005773
Johannes Berg4c476992010-10-04 21:36:35 +02005774 if (!rdev->ops->del_station)
5775 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005776
Jouni Malinen98856862014-10-20 13:20:45 +03005777 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5778 params.subtype =
5779 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5780 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5781 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5782 return -EINVAL;
5783 } else {
5784 /* Default to Deauthentication frame */
5785 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5786 }
5787
5788 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5789 params.reason_code =
5790 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5791 if (params.reason_code == 0)
5792 return -EINVAL; /* 0 is reserved */
5793 } else {
5794 /* Default to reason code 2 */
5795 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5796 }
5797
Jouni Malinen89c771e2014-10-10 20:52:40 +03005798 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005799}
5800
Eric W. Biederman15e47302012-09-07 20:12:54 +00005801static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005802 int flags, struct net_device *dev,
5803 u8 *dst, u8 *next_hop,
5804 struct mpath_info *pinfo)
5805{
5806 void *hdr;
5807 struct nlattr *pinfoattr;
5808
Henning Rogge1ef4c852014-11-04 16:14:58 +01005809 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005810 if (!hdr)
5811 return -1;
5812
David S. Miller9360ffd2012-03-29 04:41:26 -04005813 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5814 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5815 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5816 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5817 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005818
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005819 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5820 if (!pinfoattr)
5821 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005822 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5823 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5824 pinfo->frame_qlen))
5825 goto nla_put_failure;
5826 if (((pinfo->filled & MPATH_INFO_SN) &&
5827 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5828 ((pinfo->filled & MPATH_INFO_METRIC) &&
5829 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5830 pinfo->metric)) ||
5831 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5832 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5833 pinfo->exptime)) ||
5834 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5835 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5836 pinfo->flags)) ||
5837 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5838 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5839 pinfo->discovery_timeout)) ||
5840 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5841 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08005842 pinfo->discovery_retries)) ||
5843 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
5844 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08005845 pinfo->hop_count)) ||
5846 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
5847 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
5848 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005849 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005850
5851 nla_nest_end(msg, pinfoattr);
5852
Johannes Berg053c0952015-01-16 22:09:00 +01005853 genlmsg_end(msg, hdr);
5854 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005855
5856 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005857 genlmsg_cancel(msg, hdr);
5858 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005859}
5860
5861static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005862 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005863{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005864 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005865 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005866 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005867 u8 dst[ETH_ALEN];
5868 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005869 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005870 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005871
Johannes Bergea90e0d2017-03-15 14:26:04 +01005872 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005873 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005874 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005875 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005876
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005877 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005878 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005879 goto out_err;
5880 }
5881
Johannes Berg97990a02013-04-19 01:02:55 +02005882 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005883 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005884 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005885 }
5886
Johannes Bergbba95fe2008-07-29 13:22:51 +02005887 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005888 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005889 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005890 if (err == -ENOENT)
5891 break;
5892 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005893 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005894
Eric W. Biederman15e47302012-09-07 20:12:54 +00005895 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005896 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005897 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005898 &pinfo) < 0)
5899 goto out;
5900
5901 path_idx++;
5902 }
5903
Johannes Bergbba95fe2008-07-29 13:22:51 +02005904 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005905 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005906 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005907 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005908 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005909 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005910}
5911
5912static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5913{
Johannes Berg4c476992010-10-04 21:36:35 +02005914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005915 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005916 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005917 struct mpath_info pinfo;
5918 struct sk_buff *msg;
5919 u8 *dst = NULL;
5920 u8 next_hop[ETH_ALEN];
5921
5922 memset(&pinfo, 0, sizeof(pinfo));
5923
5924 if (!info->attrs[NL80211_ATTR_MAC])
5925 return -EINVAL;
5926
5927 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5928
Johannes Berg4c476992010-10-04 21:36:35 +02005929 if (!rdev->ops->get_mpath)
5930 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005931
Johannes Berg4c476992010-10-04 21:36:35 +02005932 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5933 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005934
Hila Gonene35e4d22012-06-27 17:19:42 +03005935 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005936 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005937 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005938
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005940 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005941 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005942
Eric W. Biederman15e47302012-09-07 20:12:54 +00005943 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005944 dev, dst, next_hop, &pinfo) < 0) {
5945 nlmsg_free(msg);
5946 return -ENOBUFS;
5947 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005948
Johannes Berg4c476992010-10-04 21:36:35 +02005949 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005950}
5951
5952static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5953{
Johannes Berg4c476992010-10-04 21:36:35 +02005954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5955 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005956 u8 *dst = NULL;
5957 u8 *next_hop = NULL;
5958
5959 if (!info->attrs[NL80211_ATTR_MAC])
5960 return -EINVAL;
5961
5962 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5963 return -EINVAL;
5964
5965 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5966 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5967
Johannes Berg4c476992010-10-04 21:36:35 +02005968 if (!rdev->ops->change_mpath)
5969 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005970
Johannes Berg4c476992010-10-04 21:36:35 +02005971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5972 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005973
Hila Gonene35e4d22012-06-27 17:19:42 +03005974 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005975}
Johannes Berg4c476992010-10-04 21:36:35 +02005976
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005977static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5978{
Johannes Berg4c476992010-10-04 21:36:35 +02005979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5980 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005981 u8 *dst = NULL;
5982 u8 *next_hop = NULL;
5983
5984 if (!info->attrs[NL80211_ATTR_MAC])
5985 return -EINVAL;
5986
5987 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5988 return -EINVAL;
5989
5990 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5991 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5992
Johannes Berg4c476992010-10-04 21:36:35 +02005993 if (!rdev->ops->add_mpath)
5994 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005995
Johannes Berg4c476992010-10-04 21:36:35 +02005996 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5997 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005998
Hila Gonene35e4d22012-06-27 17:19:42 +03005999 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006000}
6001
6002static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6003{
Johannes Berg4c476992010-10-04 21:36:35 +02006004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6005 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006006 u8 *dst = NULL;
6007
6008 if (info->attrs[NL80211_ATTR_MAC])
6009 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6010
Johannes Berg4c476992010-10-04 21:36:35 +02006011 if (!rdev->ops->del_mpath)
6012 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006013
Hila Gonene35e4d22012-06-27 17:19:42 +03006014 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006015}
6016
Henning Rogge66be7d22014-09-12 08:58:49 +02006017static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6018{
6019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6020 int err;
6021 struct net_device *dev = info->user_ptr[1];
6022 struct mpath_info pinfo;
6023 struct sk_buff *msg;
6024 u8 *dst = NULL;
6025 u8 mpp[ETH_ALEN];
6026
6027 memset(&pinfo, 0, sizeof(pinfo));
6028
6029 if (!info->attrs[NL80211_ATTR_MAC])
6030 return -EINVAL;
6031
6032 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6033
6034 if (!rdev->ops->get_mpp)
6035 return -EOPNOTSUPP;
6036
6037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6038 return -EOPNOTSUPP;
6039
6040 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6041 if (err)
6042 return err;
6043
6044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6045 if (!msg)
6046 return -ENOMEM;
6047
6048 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6049 dev, dst, mpp, &pinfo) < 0) {
6050 nlmsg_free(msg);
6051 return -ENOBUFS;
6052 }
6053
6054 return genlmsg_reply(msg, info);
6055}
6056
6057static int nl80211_dump_mpp(struct sk_buff *skb,
6058 struct netlink_callback *cb)
6059{
6060 struct mpath_info pinfo;
6061 struct cfg80211_registered_device *rdev;
6062 struct wireless_dev *wdev;
6063 u8 dst[ETH_ALEN];
6064 u8 mpp[ETH_ALEN];
6065 int path_idx = cb->args[2];
6066 int err;
6067
Johannes Bergea90e0d2017-03-15 14:26:04 +01006068 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006069 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006070 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006071 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006072
6073 if (!rdev->ops->dump_mpp) {
6074 err = -EOPNOTSUPP;
6075 goto out_err;
6076 }
6077
6078 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6079 err = -EOPNOTSUPP;
6080 goto out_err;
6081 }
6082
6083 while (1) {
6084 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6085 mpp, &pinfo);
6086 if (err == -ENOENT)
6087 break;
6088 if (err)
6089 goto out_err;
6090
6091 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6092 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6093 wdev->netdev, dst, mpp,
6094 &pinfo) < 0)
6095 goto out;
6096
6097 path_idx++;
6098 }
6099
6100 out:
6101 cb->args[2] = path_idx;
6102 err = skb->len;
6103 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006104 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006105 return err;
6106}
6107
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006108static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6109{
Johannes Berg4c476992010-10-04 21:36:35 +02006110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6111 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006112 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006113 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006114 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006115
6116 memset(&params, 0, sizeof(params));
6117 /* default to not changing parameters */
6118 params.use_cts_prot = -1;
6119 params.use_short_preamble = -1;
6120 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006121 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006122 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006123 params.p2p_ctwindow = -1;
6124 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006125
6126 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6127 params.use_cts_prot =
6128 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6129 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6130 params.use_short_preamble =
6131 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6132 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6133 params.use_short_slot_time =
6134 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006135 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6136 params.basic_rates =
6137 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6138 params.basic_rates_len =
6139 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6140 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006141 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6142 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006143 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6144 params.ht_opmode =
6145 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006146
Johannes Berg53cabad2012-11-14 15:17:28 +01006147 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6148 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6149 return -EINVAL;
6150 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006151 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006152 if (params.p2p_ctwindow != 0 &&
6153 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6154 return -EINVAL;
6155 }
6156
6157 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6158 u8 tmp;
6159
6160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6161 return -EINVAL;
6162 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006163 params.p2p_opp_ps = tmp;
6164 if (params.p2p_opp_ps &&
6165 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6166 return -EINVAL;
6167 }
6168
Johannes Berg4c476992010-10-04 21:36:35 +02006169 if (!rdev->ops->change_bss)
6170 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006171
Johannes Berg074ac8d2010-09-16 14:58:22 +02006172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006173 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6174 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006175
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006176 wdev_lock(wdev);
6177 err = rdev_change_bss(rdev, dev, &params);
6178 wdev_unlock(wdev);
6179
6180 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006181}
6182
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006183static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6184{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006185 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006186 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006187 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006188 u32 owner_nlportid;
6189
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006190 /*
6191 * You should only get this when cfg80211 hasn't yet initialized
6192 * completely when built-in to the kernel right between the time
6193 * window between nl80211_init() and regulatory_init(), if that is
6194 * even possible.
6195 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006196 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006197 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006198
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006199 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6200 user_reg_hint_type =
6201 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6202 else
6203 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6204
6205 switch (user_reg_hint_type) {
6206 case NL80211_USER_REG_HINT_USER:
6207 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006208 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6209 return -EINVAL;
6210
6211 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6212 return regulatory_hint_user(data, user_reg_hint_type);
6213 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006214 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6215 owner_nlportid = info->snd_portid;
6216 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6217 } else {
6218 owner_nlportid = 0;
6219 is_indoor = true;
6220 }
6221
6222 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006223 default:
6224 return -EINVAL;
6225 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006226}
6227
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006228static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6229{
6230 return reg_reload_regdb();
6231}
6232
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006233static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006234 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006235{
Johannes Berg4c476992010-10-04 21:36:35 +02006236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006237 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006238 struct wireless_dev *wdev = dev->ieee80211_ptr;
6239 struct mesh_config cur_params;
6240 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006241 void *hdr;
6242 struct nlattr *pinfoattr;
6243 struct sk_buff *msg;
6244
Johannes Berg29cbe682010-12-03 09:20:44 +01006245 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6246 return -EOPNOTSUPP;
6247
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006248 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006249 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006250
Johannes Berg29cbe682010-12-03 09:20:44 +01006251 wdev_lock(wdev);
6252 /* If not connected, get default parameters */
6253 if (!wdev->mesh_id_len)
6254 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6255 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006256 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006257 wdev_unlock(wdev);
6258
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006259 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006260 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006261
6262 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006264 if (!msg)
6265 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006266 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006267 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006268 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006269 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006270 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006271 if (!pinfoattr)
6272 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006273 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6274 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6275 cur_params.dot11MeshRetryTimeout) ||
6276 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6277 cur_params.dot11MeshConfirmTimeout) ||
6278 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6279 cur_params.dot11MeshHoldingTimeout) ||
6280 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6281 cur_params.dot11MeshMaxPeerLinks) ||
6282 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6283 cur_params.dot11MeshMaxRetries) ||
6284 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6285 cur_params.dot11MeshTTL) ||
6286 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6287 cur_params.element_ttl) ||
6288 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6289 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006290 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6291 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006292 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6293 cur_params.dot11MeshHWMPmaxPREQretries) ||
6294 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6295 cur_params.path_refresh_time) ||
6296 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6297 cur_params.min_discovery_timeout) ||
6298 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6299 cur_params.dot11MeshHWMPactivePathTimeout) ||
6300 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6301 cur_params.dot11MeshHWMPpreqMinInterval) ||
6302 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6303 cur_params.dot11MeshHWMPperrMinInterval) ||
6304 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6305 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6306 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6307 cur_params.dot11MeshHWMPRootMode) ||
6308 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6309 cur_params.dot11MeshHWMPRannInterval) ||
6310 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6311 cur_params.dot11MeshGateAnnouncementProtocol) ||
6312 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6313 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006314 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006315 cur_params.rssi_threshold) ||
6316 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006317 cur_params.ht_opmode) ||
6318 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6319 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6320 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006321 cur_params.dot11MeshHWMProotInterval) ||
6322 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006323 cur_params.dot11MeshHWMPconfirmationInterval) ||
6324 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6325 cur_params.power_mode) ||
6326 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006327 cur_params.dot11MeshAwakeWindowDuration) ||
6328 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006329 cur_params.plink_timeout) ||
6330 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6331 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006332 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006333 nla_nest_end(msg, pinfoattr);
6334 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006335 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006336
Johannes Berg3b858752009-03-12 09:55:09 +01006337 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006338 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006339 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006340 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006341}
6342
Johannes Bergab0d76f2018-10-02 10:00:07 +02006343static const struct nla_policy
6344nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6345 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6346 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6347 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6348 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6349 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6350 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6351 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6352 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6353 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6354 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6355 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6356 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6357 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6358 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006359 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6360 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006361 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006362 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006363 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6364 NLA_POLICY_MIN(NLA_U16, 1),
6365 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6366 NLA_POLICY_MIN(NLA_U16, 1),
6367 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6368 NLA_POLICY_MIN(NLA_U16, 1),
6369 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6370 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6371 NLA_POLICY_MIN(NLA_U16, 1),
6372 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6373 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6374 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6375 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006376 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006377 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006378 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6379 NLA_POLICY_MIN(NLA_U16, 1),
6380 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6381 NLA_POLICY_MIN(NLA_U16, 1),
6382 [NL80211_MESHCONF_POWER_MODE] =
6383 NLA_POLICY_RANGE(NLA_U32,
6384 NL80211_MESH_POWER_ACTIVE,
6385 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006386 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006387 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006388 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006389};
6390
Javier Cardonac80d5452010-12-16 17:37:49 -08006391static const struct nla_policy
6392 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006393 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006394 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6395 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006396 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006397 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006398 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006399 [NL80211_MESH_SETUP_IE] =
6400 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6401 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006402 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006403};
6404
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006405static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006406 struct mesh_config *cfg,
6407 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006408{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006409 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006410 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006411 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006412
Johannes Bergab0d76f2018-10-02 10:00:07 +02006413#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6414do { \
6415 if (tb[attr]) { \
6416 cfg->param = fn(tb[attr]); \
6417 mask |= BIT((attr) - 1); \
6418 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006419} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006420
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006421 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006422 return -EINVAL;
6423 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006424 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02006425 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006426 return -EINVAL;
6427
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006428 /* This makes sure that there aren't more than 32 mesh config
6429 * parameters (otherwise our bitfield scheme would not work.) */
6430 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6431
6432 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006433 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6434 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6436 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6437 nla_get_u16);
6438 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6439 NL80211_MESHCONF_HOLDING_TIMEOUT,
6440 nla_get_u16);
6441 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6442 NL80211_MESHCONF_MAX_PEER_LINKS,
6443 nla_get_u16);
6444 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6445 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6446 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6447 NL80211_MESHCONF_TTL, nla_get_u8);
6448 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6449 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6450 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6451 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6452 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006454 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006455 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006456 nla_get_u32);
6457 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6458 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6459 nla_get_u8);
6460 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6461 NL80211_MESHCONF_PATH_REFRESH_TIME,
6462 nla_get_u32);
6463 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6464 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6465 return -EINVAL;
6466 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6467 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6468 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006469 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006470 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006471 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006472 nla_get_u32);
6473 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6474 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6475 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6476 return -EINVAL;
6477 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006478 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006479 nla_get_u16);
6480 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006481 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006482 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006483 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006484 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006485 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006486 nla_get_u16);
6487 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6488 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6489 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6490 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6491 nla_get_u16);
6492 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006493 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006494 nla_get_u8);
6495 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6496 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6497 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6498 NL80211_MESHCONF_RSSI_THRESHOLD,
6499 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006500 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6501 NL80211_MESHCONF_CONNECTED_TO_GATE,
6502 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006503 /*
6504 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006505 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006506 */
6507 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6508 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6509
6510 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6511 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6512 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6513 return -EINVAL;
6514
Bob Copeland188f60a2018-06-24 21:10:49 -04006515 /* NON_HT_STA bit is reserved, but some programs set it */
6516 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006517
Masashi Honma97572352016-08-03 10:07:44 +09006518 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006519 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006520 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006521 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006522 dot11MeshHWMPactivePathToRootTimeout, mask,
6523 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6524 nla_get_u32);
6525 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6526 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6527 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6528 return -EINVAL;
6529 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6530 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6531 nla_get_u16);
6532 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6533 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006534 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006535 nla_get_u16);
6536 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6537 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6538 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6539 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6540 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6541 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006542 if (mask_out)
6543 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006544
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006545 return 0;
6546
6547#undef FILL_IN_MESH_PARAM_IF_SET
6548}
6549
Javier Cardonac80d5452010-12-16 17:37:49 -08006550static int nl80211_parse_mesh_setup(struct genl_info *info,
6551 struct mesh_setup *setup)
6552{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006554 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6555
6556 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6557 return -EINVAL;
6558 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6559 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006560 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006561 return -EINVAL;
6562
Javier Cardonad299a1f2012-03-31 11:31:33 -07006563 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6564 setup->sync_method =
6565 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6566 IEEE80211_SYNC_METHOD_VENDOR :
6567 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6568
Javier Cardonac80d5452010-12-16 17:37:49 -08006569 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6570 setup->path_sel_proto =
6571 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6572 IEEE80211_PATH_PROTOCOL_VENDOR :
6573 IEEE80211_PATH_PROTOCOL_HWMP;
6574
6575 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6576 setup->path_metric =
6577 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6578 IEEE80211_PATH_METRIC_VENDOR :
6579 IEEE80211_PATH_METRIC_AIRTIME;
6580
Javier Cardona581a8b02011-04-07 15:08:27 -07006581 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006582 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006583 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006584 setup->ie = nla_data(ieattr);
6585 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006586 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006587 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6588 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6589 return -EINVAL;
6590 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006591 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6592 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006593 if (setup->is_secure)
6594 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006595
Colleen Twitty6e16d902013-05-08 11:45:59 -07006596 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6597 if (!setup->user_mpm)
6598 return -EINVAL;
6599 setup->auth_id =
6600 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6601 }
6602
Javier Cardonac80d5452010-12-16 17:37:49 -08006603 return 0;
6604}
6605
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006606static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006607 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006608{
6609 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6610 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006611 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006612 struct mesh_config cfg;
6613 u32 mask;
6614 int err;
6615
Johannes Berg29cbe682010-12-03 09:20:44 +01006616 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6617 return -EOPNOTSUPP;
6618
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006619 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006620 return -EOPNOTSUPP;
6621
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006622 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006623 if (err)
6624 return err;
6625
Johannes Berg29cbe682010-12-03 09:20:44 +01006626 wdev_lock(wdev);
6627 if (!wdev->mesh_id_len)
6628 err = -ENOLINK;
6629
6630 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006631 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006632
6633 wdev_unlock(wdev);
6634
6635 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006636}
6637
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006638static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6639 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006640{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006641 struct nlattr *nl_reg_rules;
6642 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006643
Johannes Berg458f4f92012-12-06 15:47:38 +01006644 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6645 (regdom->dfs_region &&
6646 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006647 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006648
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006649 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6650 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006651 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006652
Johannes Berg458f4f92012-12-06 15:47:38 +01006653 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006654 struct nlattr *nl_reg_rule;
6655 const struct ieee80211_reg_rule *reg_rule;
6656 const struct ieee80211_freq_range *freq_range;
6657 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006658 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006659
Johannes Berg458f4f92012-12-06 15:47:38 +01006660 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006661 freq_range = &reg_rule->freq_range;
6662 power_rule = &reg_rule->power_rule;
6663
6664 nl_reg_rule = nla_nest_start(msg, i);
6665 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006666 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006667
Janusz Dziedzic97524822014-01-30 09:52:20 +01006668 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6669 if (!max_bandwidth_khz)
6670 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6671 reg_rule);
6672
David S. Miller9360ffd2012-03-29 04:41:26 -04006673 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6674 reg_rule->flags) ||
6675 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6676 freq_range->start_freq_khz) ||
6677 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6678 freq_range->end_freq_khz) ||
6679 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006680 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006681 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6682 power_rule->max_antenna_gain) ||
6683 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006684 power_rule->max_eirp) ||
6685 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6686 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006687 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006688
6689 nla_nest_end(msg, nl_reg_rule);
6690 }
6691
6692 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006693 return 0;
6694
6695nla_put_failure:
6696 return -EMSGSIZE;
6697}
6698
6699static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6700{
6701 const struct ieee80211_regdomain *regdom = NULL;
6702 struct cfg80211_registered_device *rdev;
6703 struct wiphy *wiphy = NULL;
6704 struct sk_buff *msg;
6705 void *hdr;
6706
6707 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6708 if (!msg)
6709 return -ENOBUFS;
6710
6711 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6712 NL80211_CMD_GET_REG);
6713 if (!hdr)
6714 goto put_failure;
6715
6716 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006717 bool self_managed;
6718
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006719 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6720 if (IS_ERR(rdev)) {
6721 nlmsg_free(msg);
6722 return PTR_ERR(rdev);
6723 }
6724
6725 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006726 self_managed = wiphy->regulatory_flags &
6727 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006728 regdom = get_wiphy_regdom(wiphy);
6729
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006730 /* a self-managed-reg device must have a private regdom */
6731 if (WARN_ON(!regdom && self_managed)) {
6732 nlmsg_free(msg);
6733 return -EINVAL;
6734 }
6735
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006736 if (regdom &&
6737 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6738 goto nla_put_failure;
6739 }
6740
6741 if (!wiphy && reg_last_request_cell_base() &&
6742 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6743 NL80211_USER_REG_HINT_CELL_BASE))
6744 goto nla_put_failure;
6745
6746 rcu_read_lock();
6747
6748 if (!regdom)
6749 regdom = rcu_dereference(cfg80211_regdomain);
6750
6751 if (nl80211_put_regdom(regdom, msg))
6752 goto nla_put_failure_rcu;
6753
6754 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006755
6756 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006757 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006758
Johannes Berg458f4f92012-12-06 15:47:38 +01006759nla_put_failure_rcu:
6760 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006761nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006762put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006763 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006764 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006765}
6766
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006767static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6768 u32 seq, int flags, struct wiphy *wiphy,
6769 const struct ieee80211_regdomain *regdom)
6770{
6771 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6772 NL80211_CMD_GET_REG);
6773
6774 if (!hdr)
6775 return -1;
6776
Michal Kubecek0a833c22017-11-15 13:09:32 +01006777 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006778
6779 if (nl80211_put_regdom(regdom, msg))
6780 goto nla_put_failure;
6781
6782 if (!wiphy && reg_last_request_cell_base() &&
6783 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6784 NL80211_USER_REG_HINT_CELL_BASE))
6785 goto nla_put_failure;
6786
6787 if (wiphy &&
6788 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6789 goto nla_put_failure;
6790
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006791 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6792 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6793 goto nla_put_failure;
6794
Johannes Berg053c0952015-01-16 22:09:00 +01006795 genlmsg_end(msg, hdr);
6796 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006797
6798nla_put_failure:
6799 genlmsg_cancel(msg, hdr);
6800 return -EMSGSIZE;
6801}
6802
6803static int nl80211_get_reg_dump(struct sk_buff *skb,
6804 struct netlink_callback *cb)
6805{
6806 const struct ieee80211_regdomain *regdom = NULL;
6807 struct cfg80211_registered_device *rdev;
6808 int err, reg_idx, start = cb->args[2];
6809
6810 rtnl_lock();
6811
6812 if (cfg80211_regdomain && start == 0) {
6813 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6814 NLM_F_MULTI, NULL,
6815 rtnl_dereference(cfg80211_regdomain));
6816 if (err < 0)
6817 goto out_err;
6818 }
6819
6820 /* the global regdom is idx 0 */
6821 reg_idx = 1;
6822 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6823 regdom = get_wiphy_regdom(&rdev->wiphy);
6824 if (!regdom)
6825 continue;
6826
6827 if (++reg_idx <= start)
6828 continue;
6829
6830 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6831 NLM_F_MULTI, &rdev->wiphy, regdom);
6832 if (err < 0) {
6833 reg_idx--;
6834 break;
6835 }
6836 }
6837
6838 cb->args[2] = reg_idx;
6839 err = skb->len;
6840out_err:
6841 rtnl_unlock();
6842 return err;
6843}
6844
Johannes Bergb6863032015-10-15 09:25:18 +02006845#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6846static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6847 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6848 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6849 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6850 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6851 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6852 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6853 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6854};
6855
6856static int parse_reg_rule(struct nlattr *tb[],
6857 struct ieee80211_reg_rule *reg_rule)
6858{
6859 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6860 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6861
6862 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6863 return -EINVAL;
6864 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6865 return -EINVAL;
6866 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6867 return -EINVAL;
6868 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6869 return -EINVAL;
6870 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6871 return -EINVAL;
6872
6873 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6874
6875 freq_range->start_freq_khz =
6876 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6877 freq_range->end_freq_khz =
6878 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6879 freq_range->max_bandwidth_khz =
6880 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6881
6882 power_rule->max_eirp =
6883 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6884
6885 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6886 power_rule->max_antenna_gain =
6887 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6888
6889 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6890 reg_rule->dfs_cac_ms =
6891 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6892
6893 return 0;
6894}
6895
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006896static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6897{
6898 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6899 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006900 char *alpha2;
6901 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006902 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006903 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006904 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006905
6906 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6907 return -EINVAL;
6908
6909 if (!info->attrs[NL80211_ATTR_REG_RULES])
6910 return -EINVAL;
6911
6912 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6913
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006914 if (info->attrs[NL80211_ATTR_DFS_REGION])
6915 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6916
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006917 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006918 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006919 num_rules++;
6920 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006921 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006922 }
6923
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006924 if (!reg_is_valid_request(alpha2))
6925 return -EINVAL;
6926
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006927 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006928 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006929
6930 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006931 if (!rd)
6932 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006933
6934 rd->n_reg_rules = num_rules;
6935 rd->alpha2[0] = alpha2[0];
6936 rd->alpha2[1] = alpha2[1];
6937
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006938 /*
6939 * Disable DFS master mode if the DFS region was
6940 * not supported or known on this kernel.
6941 */
6942 if (reg_supported_dfs_region(dfs_region))
6943 rd->dfs_region = dfs_region;
6944
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006945 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006946 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006947 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006948 nl_reg_rule, reg_rule_policy,
6949 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006950 if (r)
6951 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006952 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6953 if (r)
6954 goto bad_reg;
6955
6956 rule_idx++;
6957
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006958 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6959 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006960 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006961 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006962 }
6963
Johannes Berg06627992016-06-09 10:40:09 +02006964 /* set_regdom takes ownership of rd */
6965 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006966 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006967 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006968 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006969}
Johannes Bergb6863032015-10-15 09:25:18 +02006970#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006971
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006972static int validate_scan_freqs(struct nlattr *freqs)
6973{
6974 struct nlattr *attr1, *attr2;
6975 int n_channels = 0, tmp1, tmp2;
6976
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006977 nla_for_each_nested(attr1, freqs, tmp1)
6978 if (nla_len(attr1) != sizeof(u32))
6979 return 0;
6980
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006981 nla_for_each_nested(attr1, freqs, tmp1) {
6982 n_channels++;
6983 /*
6984 * Some hardware has a limited channel list for
6985 * scanning, and it is pretty much nonsensical
6986 * to scan for a channel twice, so disallow that
6987 * and don't require drivers to check that the
6988 * channel list they get isn't longer than what
6989 * they can scan, as long as they can scan all
6990 * the channels they registered at once.
6991 */
6992 nla_for_each_nested(attr2, freqs, tmp2)
6993 if (attr1 != attr2 &&
6994 nla_get_u32(attr1) == nla_get_u32(attr2))
6995 return 0;
6996 }
6997
6998 return n_channels;
6999}
7000
Johannes Berg57fbcce2016-04-12 15:56:15 +02007001static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007002{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007003 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007004}
7005
7006static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7007 struct cfg80211_bss_selection *bss_select)
7008{
7009 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7010 struct nlattr *nest;
7011 int err;
7012 bool found = false;
7013 int i;
7014
7015 /* only process one nested attribute */
7016 nest = nla_data(nla);
7017 if (!nla_ok(nest, nla_len(nest)))
7018 return -EINVAL;
7019
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007020 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02007021 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007022 if (err)
7023 return err;
7024
7025 /* only one attribute may be given */
7026 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7027 if (attr[i]) {
7028 if (found)
7029 return -EINVAL;
7030 found = true;
7031 }
7032 }
7033
7034 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7035
7036 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7037 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7038
7039 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7040 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7041 bss_select->param.band_pref =
7042 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7043 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7044 return -EINVAL;
7045 }
7046
7047 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7048 struct nl80211_bss_select_rssi_adjust *adj_param;
7049
7050 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7051 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7052 bss_select->param.adjust.band = adj_param->band;
7053 bss_select->param.adjust.delta = adj_param->delta;
7054 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7055 return -EINVAL;
7056 }
7057
7058 /* user-space did not provide behaviour attribute */
7059 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7060 return -EINVAL;
7061
7062 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7063 return -EINVAL;
7064
7065 return 0;
7066}
7067
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007068int nl80211_parse_random_mac(struct nlattr **attrs,
7069 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007070{
7071 int i;
7072
7073 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007074 eth_zero_addr(mac_addr);
7075 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007076 mac_addr[0] = 0x2;
7077 mac_addr_mask[0] = 0x3;
7078
7079 return 0;
7080 }
7081
7082 /* need both or none */
7083 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7084 return -EINVAL;
7085
7086 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7087 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7088
7089 /* don't allow or configure an mcast address */
7090 if (!is_multicast_ether_addr(mac_addr_mask) ||
7091 is_multicast_ether_addr(mac_addr))
7092 return -EINVAL;
7093
7094 /*
7095 * allow users to pass a MAC address that has bits set outside
7096 * of the mask, but don't bother drivers with having to deal
7097 * with such bits
7098 */
7099 for (i = 0; i < ETH_ALEN; i++)
7100 mac_addr[i] &= mac_addr_mask[i];
7101
7102 return 0;
7103}
7104
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307105static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7106{
7107 ASSERT_WDEV_LOCK(wdev);
7108
7109 if (!cfg80211_beaconing_iface_active(wdev))
7110 return true;
7111
7112 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7113 return true;
7114
7115 return regulatory_pre_cac_allowed(wdev->wiphy);
7116}
7117
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007118static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7119 enum nl80211_ext_feature_index feat)
7120{
7121 if (!(flags & flag))
7122 return true;
7123 if (wiphy_ext_feature_isset(wiphy, feat))
7124 return true;
7125 return false;
7126}
7127
Roee Zamir2d23d072017-08-06 11:38:22 +03007128static int
7129nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7130 void *request, struct nlattr **attrs,
7131 bool is_sched_scan)
7132{
7133 u8 *mac_addr, *mac_addr_mask;
7134 u32 *flags;
7135 enum nl80211_feature_flags randomness_flag;
7136
7137 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7138 return 0;
7139
7140 if (is_sched_scan) {
7141 struct cfg80211_sched_scan_request *req = request;
7142
7143 randomness_flag = wdev ?
7144 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7145 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7146 flags = &req->flags;
7147 mac_addr = req->mac_addr;
7148 mac_addr_mask = req->mac_addr_mask;
7149 } else {
7150 struct cfg80211_scan_request *req = request;
7151
7152 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7153 flags = &req->flags;
7154 mac_addr = req->mac_addr;
7155 mac_addr_mask = req->mac_addr_mask;
7156 }
7157
7158 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7159
Sunil Dutt5037a002018-01-25 17:13:37 +02007160 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7161 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007162 !nl80211_check_scan_feat(wiphy, *flags,
7163 NL80211_SCAN_FLAG_LOW_SPAN,
7164 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7165 !nl80211_check_scan_feat(wiphy, *flags,
7166 NL80211_SCAN_FLAG_LOW_POWER,
7167 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7168 !nl80211_check_scan_feat(wiphy, *flags,
7169 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7170 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7171 !nl80211_check_scan_feat(wiphy, *flags,
7172 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7173 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7174 !nl80211_check_scan_feat(wiphy, *flags,
7175 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7176 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7177 !nl80211_check_scan_feat(wiphy, *flags,
7178 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7179 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7180 !nl80211_check_scan_feat(wiphy, *flags,
7181 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007182 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7183 !nl80211_check_scan_feat(wiphy, *flags,
7184 NL80211_SCAN_FLAG_RANDOM_SN,
7185 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7186 !nl80211_check_scan_feat(wiphy, *flags,
7187 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7188 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007189 return -EOPNOTSUPP;
7190
7191 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7192 int err;
7193
7194 if (!(wiphy->features & randomness_flag) ||
7195 (wdev && wdev->current_bss))
7196 return -EOPNOTSUPP;
7197
7198 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7199 if (err)
7200 return err;
7201 }
7202
Roee Zamir2d23d072017-08-06 11:38:22 +03007203 return 0;
7204}
7205
Johannes Berg2a519312009-02-10 21:25:55 +01007206static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7207{
Johannes Berg4c476992010-10-04 21:36:35 +02007208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007209 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007210 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007211 struct nlattr *attr;
7212 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007213 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007214 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007215
Johannes Berg79c97e92009-07-07 03:56:12 +02007216 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007217
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007218 if (wdev->iftype == NL80211_IFTYPE_NAN)
7219 return -EOPNOTSUPP;
7220
Johannes Berg4c476992010-10-04 21:36:35 +02007221 if (!rdev->ops->scan)
7222 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007223
Johannes Bergf9d15d12014-01-22 11:14:19 +02007224 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007225 err = -EBUSY;
7226 goto unlock;
7227 }
Johannes Berg2a519312009-02-10 21:25:55 +01007228
7229 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007230 n_channels = validate_scan_freqs(
7231 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007232 if (!n_channels) {
7233 err = -EINVAL;
7234 goto unlock;
7235 }
Johannes Berg2a519312009-02-10 21:25:55 +01007236 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007237 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007238 }
7239
7240 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7241 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7242 n_ssids++;
7243
Johannes Bergf9f47522013-03-19 15:04:07 +01007244 if (n_ssids > wiphy->max_scan_ssids) {
7245 err = -EINVAL;
7246 goto unlock;
7247 }
Johannes Berg2a519312009-02-10 21:25:55 +01007248
Jouni Malinen70692ad2009-02-16 19:39:13 +02007249 if (info->attrs[NL80211_ATTR_IE])
7250 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7251 else
7252 ie_len = 0;
7253
Johannes Bergf9f47522013-03-19 15:04:07 +01007254 if (ie_len > wiphy->max_scan_ie_len) {
7255 err = -EINVAL;
7256 goto unlock;
7257 }
Johannes Berg18a83652009-03-31 12:12:05 +02007258
Johannes Berg2a519312009-02-10 21:25:55 +01007259 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007260 + sizeof(*request->ssids) * n_ssids
7261 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007262 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007263 if (!request) {
7264 err = -ENOMEM;
7265 goto unlock;
7266 }
Johannes Berg2a519312009-02-10 21:25:55 +01007267
Johannes Berg2a519312009-02-10 21:25:55 +01007268 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007269 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007270 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007271 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007272 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007273 request->ie = (void *)(request->ssids + n_ssids);
7274 else
7275 request->ie = (void *)(request->channels + n_channels);
7276 }
Johannes Berg2a519312009-02-10 21:25:55 +01007277
Johannes Berg584991d2009-11-02 13:32:03 +01007278 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007279 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7280 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007281 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007282 struct ieee80211_channel *chan;
7283
7284 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7285
7286 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007287 err = -EINVAL;
7288 goto out_free;
7289 }
Johannes Berg584991d2009-11-02 13:32:03 +01007290
7291 /* ignore disabled channels */
7292 if (chan->flags & IEEE80211_CHAN_DISABLED)
7293 continue;
7294
7295 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007296 i++;
7297 }
7298 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007299 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007300
Johannes Berg2a519312009-02-10 21:25:55 +01007301 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007302 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007303 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007304
Johannes Berg2a519312009-02-10 21:25:55 +01007305 if (!wiphy->bands[band])
7306 continue;
7307 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007308 struct ieee80211_channel *chan;
7309
7310 chan = &wiphy->bands[band]->channels[j];
7311
7312 if (chan->flags & IEEE80211_CHAN_DISABLED)
7313 continue;
7314
7315 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007316 i++;
7317 }
7318 }
7319 }
7320
Johannes Berg584991d2009-11-02 13:32:03 +01007321 if (!i) {
7322 err = -EINVAL;
7323 goto out_free;
7324 }
7325
7326 request->n_channels = i;
7327
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307328 wdev_lock(wdev);
7329 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7330 struct ieee80211_channel *chan;
7331
7332 if (request->n_channels != 1) {
7333 wdev_unlock(wdev);
7334 err = -EBUSY;
7335 goto out_free;
7336 }
7337
7338 chan = request->channels[0];
7339 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7340 wdev_unlock(wdev);
7341 err = -EBUSY;
7342 goto out_free;
7343 }
7344 }
7345 wdev_unlock(wdev);
7346
Johannes Berg2a519312009-02-10 21:25:55 +01007347 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007348 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007349 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007350 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007351 err = -EINVAL;
7352 goto out_free;
7353 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007354 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007355 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007356 i++;
7357 }
7358 }
7359
Jouni Malinen70692ad2009-02-16 19:39:13 +02007360 if (info->attrs[NL80211_ATTR_IE]) {
7361 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007362 memcpy((void *)request->ie,
7363 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007364 request->ie_len);
7365 }
7366
Johannes Berg57fbcce2016-04-12 15:56:15 +02007367 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007368 if (wiphy->bands[i])
7369 request->rates[i] =
7370 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007371
7372 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7373 nla_for_each_nested(attr,
7374 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7375 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007376 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007377
Johannes Berg57fbcce2016-04-12 15:56:15 +02007378 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007379 err = -EINVAL;
7380 goto out_free;
7381 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007382
7383 if (!wiphy->bands[band])
7384 continue;
7385
Johannes Berg34850ab2011-07-18 18:08:35 +02007386 err = ieee80211_get_ratemask(wiphy->bands[band],
7387 nla_data(attr),
7388 nla_len(attr),
7389 &request->rates[band]);
7390 if (err)
7391 goto out_free;
7392 }
7393 }
7394
Avraham Stern1d762502016-07-05 17:10:13 +03007395 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7396 if (!wiphy_ext_feature_isset(wiphy,
7397 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7398 err = -EOPNOTSUPP;
7399 goto out_free;
7400 }
7401
7402 request->duration =
7403 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7404 request->duration_mandatory =
7405 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7406 }
7407
Roee Zamir2d23d072017-08-06 11:38:22 +03007408 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7409 false);
7410 if (err)
7411 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007412
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307413 request->no_cck =
7414 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7415
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007416 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7417 * BSSID to scan for. This was problematic because that same attribute
7418 * was already used for another purpose (local random MAC address). The
7419 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7420 * compatibility with older userspace components, also use the
7421 * NL80211_ATTR_MAC value here if it can be determined to be used for
7422 * the specific BSSID use case instead of the random MAC address
7423 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7424 */
7425 if (info->attrs[NL80211_ATTR_BSSID])
7426 memcpy(request->bssid,
7427 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7428 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7429 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007430 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7431 ETH_ALEN);
7432 else
7433 eth_broadcast_addr(request->bssid);
7434
Johannes Bergfd014282012-06-18 19:17:03 +02007435 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007436 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007437 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007438
Johannes Berg79c97e92009-07-07 03:56:12 +02007439 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007440 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007441
Johannes Berg463d0182009-07-14 00:33:35 +02007442 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007443 nl80211_send_scan_start(rdev, wdev);
7444 if (wdev->netdev)
7445 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007446 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007447 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007448 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007449 kfree(request);
7450 }
Johannes Berg3b858752009-03-12 09:55:09 +01007451
Johannes Bergf9f47522013-03-19 15:04:07 +01007452 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007453 return err;
7454}
7455
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307456static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7457{
7458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7459 struct wireless_dev *wdev = info->user_ptr[1];
7460
7461 if (!rdev->ops->abort_scan)
7462 return -EOPNOTSUPP;
7463
7464 if (rdev->scan_msg)
7465 return 0;
7466
7467 if (!rdev->scan_req)
7468 return -ENOENT;
7469
7470 rdev_abort_scan(rdev, wdev);
7471 return 0;
7472}
7473
Avraham Stern3b06d272015-10-12 09:51:34 +03007474static int
7475nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7476 struct cfg80211_sched_scan_request *request,
7477 struct nlattr **attrs)
7478{
7479 int tmp, err, i = 0;
7480 struct nlattr *attr;
7481
7482 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7483 u32 interval;
7484
7485 /*
7486 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007487 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007488 * case one scan plan will be set with the specified scan
7489 * interval and infinite number of iterations.
7490 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007491 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7492 if (!interval)
7493 return -EINVAL;
7494
7495 request->scan_plans[0].interval =
7496 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7497 if (!request->scan_plans[0].interval)
7498 return -EINVAL;
7499
7500 if (request->scan_plans[0].interval >
7501 wiphy->max_sched_scan_plan_interval)
7502 request->scan_plans[0].interval =
7503 wiphy->max_sched_scan_plan_interval;
7504
7505 return 0;
7506 }
7507
7508 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7509 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7510
7511 if (WARN_ON(i >= n_plans))
7512 return -EINVAL;
7513
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007514 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007515 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007516 if (err)
7517 return err;
7518
7519 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7520 return -EINVAL;
7521
7522 request->scan_plans[i].interval =
7523 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7524 if (!request->scan_plans[i].interval ||
7525 request->scan_plans[i].interval >
7526 wiphy->max_sched_scan_plan_interval)
7527 return -EINVAL;
7528
7529 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7530 request->scan_plans[i].iterations =
7531 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7532 if (!request->scan_plans[i].iterations ||
7533 (request->scan_plans[i].iterations >
7534 wiphy->max_sched_scan_plan_iterations))
7535 return -EINVAL;
7536 } else if (i < n_plans - 1) {
7537 /*
7538 * All scan plans but the last one must specify
7539 * a finite number of iterations
7540 */
7541 return -EINVAL;
7542 }
7543
7544 i++;
7545 }
7546
7547 /*
7548 * The last scan plan must not specify the number of
7549 * iterations, it is supposed to run infinitely
7550 */
7551 if (request->scan_plans[n_plans - 1].iterations)
7552 return -EINVAL;
7553
7554 return 0;
7555}
7556
Luciano Coelho256da022014-11-10 16:13:46 +02007557static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007558nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007559 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007560{
7561 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007562 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007563 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007564 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007565 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007566 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007567 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007568
Luciano Coelho256da022014-11-10 16:13:46 +02007569 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007570 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007571 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007572 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007573 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007574 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007575 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007576 }
7577
Luciano Coelho256da022014-11-10 16:13:46 +02007578 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7579 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007580 tmp)
7581 n_ssids++;
7582
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007583 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007584 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007585
Johannes Bergea73cbc2014-01-24 10:53:53 +01007586 /*
7587 * First, count the number of 'real' matchsets. Due to an issue with
7588 * the old implementation, matchsets containing only the RSSI attribute
7589 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7590 * RSSI for all matchsets, rather than their own matchset for reporting
7591 * all APs with a strong RSSI. This is needed to be compatible with
7592 * older userspace that treated a matchset with only the RSSI as the
7593 * global RSSI for all other matchsets - if there are other matchsets.
7594 */
Luciano Coelho256da022014-11-10 16:13:46 +02007595 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007596 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007597 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007598 tmp) {
7599 struct nlattr *rssi;
7600
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007601 err = nla_parse_nested(tb,
7602 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007603 attr, nl80211_match_policy,
7604 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007605 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007606 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007607
7608 /* SSID and BSSID are mutually exclusive */
7609 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7610 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7611 return ERR_PTR(-EINVAL);
7612
Johannes Bergea73cbc2014-01-24 10:53:53 +01007613 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007614 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7615 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007616 n_match_sets++;
7617 continue;
7618 }
7619 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7620 if (rssi)
7621 default_match_rssi = nla_get_s32(rssi);
7622 }
7623 }
7624
7625 /* However, if there's no other matchset, add the RSSI one */
7626 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7627 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007628
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007629 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007630 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007631
Luciano Coelho256da022014-11-10 16:13:46 +02007632 if (attrs[NL80211_ATTR_IE])
7633 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007634 else
7635 ie_len = 0;
7636
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007637 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007638 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007639
Avraham Stern3b06d272015-10-12 09:51:34 +03007640 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7641 /*
7642 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7643 * each scan plan already specifies its own interval
7644 */
7645 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7646 return ERR_PTR(-EINVAL);
7647
7648 nla_for_each_nested(attr,
7649 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7650 n_plans++;
7651 } else {
7652 /*
7653 * The scan interval attribute is kept for backward
7654 * compatibility. If no scan plans are specified and sched scan
7655 * interval is specified, one scan plan will be set with this
7656 * scan interval and infinite number of iterations.
7657 */
7658 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7659 return ERR_PTR(-EINVAL);
7660
7661 n_plans = 1;
7662 }
7663
7664 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7665 return ERR_PTR(-EINVAL);
7666
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007667 if (!wiphy_ext_feature_isset(
7668 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7669 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7670 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7671 return ERR_PTR(-EINVAL);
7672
Luciano Coelho807f8a82011-05-11 17:09:35 +03007673 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007674 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007675 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007676 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007677 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007678 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007679 if (!request)
7680 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007681
7682 if (n_ssids)
7683 request->ssids = (void *)&request->channels[n_channels];
7684 request->n_ssids = n_ssids;
7685 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007686 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007687 request->ie = (void *)(request->ssids + n_ssids);
7688 else
7689 request->ie = (void *)(request->channels + n_channels);
7690 }
7691
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007692 if (n_match_sets) {
7693 if (request->ie)
7694 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007695 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007696 request->match_sets =
7697 (void *)(request->ssids + n_ssids);
7698 else
7699 request->match_sets =
7700 (void *)(request->channels + n_channels);
7701 }
7702 request->n_match_sets = n_match_sets;
7703
Avraham Stern3b06d272015-10-12 09:51:34 +03007704 if (n_match_sets)
7705 request->scan_plans = (void *)(request->match_sets +
7706 n_match_sets);
7707 else if (request->ie)
7708 request->scan_plans = (void *)(request->ie + ie_len);
7709 else if (n_ssids)
7710 request->scan_plans = (void *)(request->ssids + n_ssids);
7711 else
7712 request->scan_plans = (void *)(request->channels + n_channels);
7713
7714 request->n_scan_plans = n_plans;
7715
Luciano Coelho807f8a82011-05-11 17:09:35 +03007716 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007717 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007718 /* user specified, bail out if channel not found */
7719 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007720 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007721 tmp) {
7722 struct ieee80211_channel *chan;
7723
7724 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7725
7726 if (!chan) {
7727 err = -EINVAL;
7728 goto out_free;
7729 }
7730
7731 /* ignore disabled channels */
7732 if (chan->flags & IEEE80211_CHAN_DISABLED)
7733 continue;
7734
7735 request->channels[i] = chan;
7736 i++;
7737 }
7738 } else {
7739 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007740 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007741 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007742
Luciano Coelho807f8a82011-05-11 17:09:35 +03007743 if (!wiphy->bands[band])
7744 continue;
7745 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7746 struct ieee80211_channel *chan;
7747
7748 chan = &wiphy->bands[band]->channels[j];
7749
7750 if (chan->flags & IEEE80211_CHAN_DISABLED)
7751 continue;
7752
7753 request->channels[i] = chan;
7754 i++;
7755 }
7756 }
7757 }
7758
7759 if (!i) {
7760 err = -EINVAL;
7761 goto out_free;
7762 }
7763
7764 request->n_channels = i;
7765
7766 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007767 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007768 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007769 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007770 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007771 err = -EINVAL;
7772 goto out_free;
7773 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007774 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007775 memcpy(request->ssids[i].ssid, nla_data(attr),
7776 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007777 i++;
7778 }
7779 }
7780
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007781 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007782 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007783 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007784 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007785 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007786 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007787
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007788 err = nla_parse_nested(tb,
7789 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007790 attr, nl80211_match_policy,
7791 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007792 if (err)
7793 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007794 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007795 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7796 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007797 if (WARN_ON(i >= n_match_sets)) {
7798 /* this indicates a programming error,
7799 * the loop above should have verified
7800 * things properly
7801 */
7802 err = -EINVAL;
7803 goto out_free;
7804 }
7805
Arend Van Spriel3007e352017-04-21 13:05:01 +01007806 if (ssid) {
7807 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7808 err = -EINVAL;
7809 goto out_free;
7810 }
7811 memcpy(request->match_sets[i].ssid.ssid,
7812 nla_data(ssid), nla_len(ssid));
7813 request->match_sets[i].ssid.ssid_len =
7814 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007815 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007816 if (bssid) {
7817 if (nla_len(bssid) != ETH_ALEN) {
7818 err = -EINVAL;
7819 goto out_free;
7820 }
7821 memcpy(request->match_sets[i].bssid,
7822 nla_data(bssid), ETH_ALEN);
7823 }
7824
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007825 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007826 request->match_sets[i].rssi_thold =
7827 default_match_rssi;
7828 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7829 if (rssi)
7830 request->match_sets[i].rssi_thold =
7831 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007832 }
7833 i++;
7834 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007835
7836 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007837 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007838 request->match_sets[0].rssi_thold = default_match_rssi;
7839
7840 request->min_rssi_thold = INT_MAX;
7841 for (i = 0; i < n_match_sets; i++)
7842 request->min_rssi_thold =
7843 min(request->match_sets[i].rssi_thold,
7844 request->min_rssi_thold);
7845 } else {
7846 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007847 }
7848
Johannes Berg9900e482014-02-04 21:01:25 +01007849 if (ie_len) {
7850 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007851 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007852 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007853 request->ie_len);
7854 }
7855
Roee Zamir2d23d072017-08-06 11:38:22 +03007856 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7857 if (err)
7858 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007859
Luciano Coelho9c748932015-01-16 16:04:09 +02007860 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7861 request->delay =
7862 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7863
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007864 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7865 request->relative_rssi = nla_get_s8(
7866 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7867 request->relative_rssi_set = true;
7868 }
7869
7870 if (request->relative_rssi_set &&
7871 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7872 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7873
7874 rssi_adjust = nla_data(
7875 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7876 request->rssi_adjust.band = rssi_adjust->band;
7877 request->rssi_adjust.delta = rssi_adjust->delta;
7878 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7879 err = -EINVAL;
7880 goto out_free;
7881 }
7882 }
7883
Avraham Stern3b06d272015-10-12 09:51:34 +03007884 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7885 if (err)
7886 goto out_free;
7887
Sam Leffler15d60302012-10-11 21:03:34 -07007888 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007889
Luciano Coelho256da022014-11-10 16:13:46 +02007890 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007891
7892out_free:
7893 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007894 return ERR_PTR(err);
7895}
7896
7897static int nl80211_start_sched_scan(struct sk_buff *skb,
7898 struct genl_info *info)
7899{
7900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7901 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007902 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007903 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007904 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007905 int err;
7906
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007907 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007908 return -EOPNOTSUPP;
7909
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007910 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7911 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7912 if (err)
7913 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007914
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007915 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007916 info->attrs,
7917 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007918
7919 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007920 if (err)
7921 goto out_err;
7922
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007923 /* leave request id zero for legacy request
7924 * or if driver does not support multi-scheduled scan
7925 */
7926 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7927 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02007928 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007929 }
7930
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007931 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007932 if (err)
7933 goto out_free;
7934
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007935 sched_scan_req->dev = dev;
7936 sched_scan_req->wiphy = &rdev->wiphy;
7937
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007938 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7939 sched_scan_req->owner_nlportid = info->snd_portid;
7940
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007941 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007942
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007943 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007944 return 0;
7945
7946out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007947 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007948out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007949 return err;
7950}
7951
7952static int nl80211_stop_sched_scan(struct sk_buff *skb,
7953 struct genl_info *info)
7954{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007955 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007957 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007958
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007959 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007960 return -EOPNOTSUPP;
7961
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007962 if (info->attrs[NL80211_ATTR_COOKIE]) {
7963 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7964 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7965 }
7966
7967 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7968 struct cfg80211_sched_scan_request,
7969 list);
7970 if (!req || req->reqid ||
7971 (req->owner_nlportid &&
7972 req->owner_nlportid != info->snd_portid))
7973 return -ENOENT;
7974
7975 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007976}
7977
Simon Wunderlich04f39042013-02-08 18:16:19 +01007978static int nl80211_start_radar_detection(struct sk_buff *skb,
7979 struct genl_info *info)
7980{
7981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7982 struct net_device *dev = info->user_ptr[1];
7983 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007984 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007985 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007986 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007987 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007988 int err;
7989
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007990 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007991 if (dfs_region == NL80211_DFS_UNSET)
7992 return -EINVAL;
7993
Simon Wunderlich04f39042013-02-08 18:16:19 +01007994 err = nl80211_parse_chandef(rdev, info, &chandef);
7995 if (err)
7996 return err;
7997
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007998 if (netif_carrier_ok(dev))
7999 return -EBUSY;
8000
Simon Wunderlich04f39042013-02-08 18:16:19 +01008001 if (wdev->cac_started)
8002 return -EBUSY;
8003
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008004 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008005 if (err < 0)
8006 return err;
8007
8008 if (err == 0)
8009 return -EINVAL;
8010
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008011 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008012 return -EINVAL;
8013
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008014 /* CAC start is offloaded to HW and can't be started manually */
8015 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8016 return -EOPNOTSUPP;
8017
Simon Wunderlich04f39042013-02-08 18:16:19 +01008018 if (!rdev->ops->start_radar_detection)
8019 return -EOPNOTSUPP;
8020
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008021 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8022 if (WARN_ON(!cac_time_ms))
8023 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8024
Ilan Peera1056b1b2015-10-22 22:27:46 +03008025 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008026 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008027 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008028 wdev->cac_started = true;
8029 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008030 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008031 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008032 return err;
8033}
8034
Sriram R30c63112018-12-04 17:46:52 +05308035static int nl80211_notify_radar_detection(struct sk_buff *skb,
8036 struct genl_info *info)
8037{
8038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8039 struct net_device *dev = info->user_ptr[1];
8040 struct wireless_dev *wdev = dev->ieee80211_ptr;
8041 struct wiphy *wiphy = wdev->wiphy;
8042 struct cfg80211_chan_def chandef;
8043 enum nl80211_dfs_regions dfs_region;
8044 int err;
8045
8046 dfs_region = reg_get_dfs_region(wiphy);
8047 if (dfs_region == NL80211_DFS_UNSET) {
8048 GENL_SET_ERR_MSG(info,
8049 "DFS Region is not set. Unexpected Radar indication");
8050 return -EINVAL;
8051 }
8052
8053 err = nl80211_parse_chandef(rdev, info, &chandef);
8054 if (err) {
8055 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8056 return err;
8057 }
8058
8059 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8060 if (err < 0) {
8061 GENL_SET_ERR_MSG(info, "chandef is invalid");
8062 return err;
8063 }
8064
8065 if (err == 0) {
8066 GENL_SET_ERR_MSG(info,
8067 "Unexpected Radar indication for chandef/iftype");
8068 return -EINVAL;
8069 }
8070
8071 /* Do not process this notification if radar is already detected
8072 * by kernel on this channel, and return success.
8073 */
8074 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8075 return 0;
8076
8077 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8078
8079 cfg80211_sched_dfs_chan_update(rdev);
8080
8081 memcpy(&rdev->radar_chandef, &chandef, sizeof(chandef));
8082
8083 /* Propagate this notification to other radios as well */
8084 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8085
8086 return 0;
8087}
8088
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008089static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8090{
8091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8092 struct net_device *dev = info->user_ptr[1];
8093 struct wireless_dev *wdev = dev->ieee80211_ptr;
8094 struct cfg80211_csa_settings params;
8095 /* csa_attrs is defined static to avoid waste of stack size - this
8096 * function is called under RTNL lock, so this should not be a problem.
8097 */
8098 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008099 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008100 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008101 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008102 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008103 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008104
8105 if (!rdev->ops->channel_switch ||
8106 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8107 return -EOPNOTSUPP;
8108
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008109 switch (dev->ieee80211_ptr->iftype) {
8110 case NL80211_IFTYPE_AP:
8111 case NL80211_IFTYPE_P2P_GO:
8112 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008113 /* For all modes except AP the handle_dfs flag needs to be
8114 * supplied to tell the kernel that userspace will handle radar
8115 * events when they happen. Otherwise a switch to a channel
8116 * requiring DFS will be rejected.
8117 */
8118 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008119
8120 /* useless if AP is not running */
8121 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008122 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008123 break;
8124 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008125 if (!wdev->ssid_len)
8126 return -ENOTCONN;
8127 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008128 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008129 if (!wdev->mesh_id_len)
8130 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008131 break;
8132 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008133 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008134 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008135
8136 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008137 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008138
8139 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8140 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8141 return -EINVAL;
8142
8143 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008144 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008145 return -EINVAL;
8146
Luciano Coelho252e07c2014-10-08 09:48:34 +03008147 /* Even though the attribute is u32, the specification says
8148 * u8, so let's make sure we don't overflow.
8149 */
8150 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8151 if (cs_count > 255)
8152 return -EINVAL;
8153
8154 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008155
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008156 if (!need_new_beacon)
8157 goto skip_beacons;
8158
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008159 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008160 if (err)
8161 return err;
8162
8163 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
8164 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02008165 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008166 if (err)
8167 return err;
8168
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008169 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008170 if (err)
8171 return err;
8172
8173 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8174 return -EINVAL;
8175
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008176 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8177 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008178 return -EINVAL;
8179
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008180 params.n_counter_offsets_beacon = len / sizeof(u16);
8181 if (rdev->wiphy.max_num_csa_counters &&
8182 (params.n_counter_offsets_beacon >
8183 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008184 return -EINVAL;
8185
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008186 params.counter_offsets_beacon =
8187 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8188
8189 /* sanity checks - counters should fit and be the same */
8190 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8191 u16 offset = params.counter_offsets_beacon[i];
8192
8193 if (offset >= params.beacon_csa.tail_len)
8194 return -EINVAL;
8195
8196 if (params.beacon_csa.tail[offset] != params.count)
8197 return -EINVAL;
8198 }
8199
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008200 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008201 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8202 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008203 return -EINVAL;
8204
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008205 params.n_counter_offsets_presp = len / sizeof(u16);
8206 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008207 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008208 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008209 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008210
8211 params.counter_offsets_presp =
8212 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8213
8214 /* sanity checks - counters should fit and be the same */
8215 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8216 u16 offset = params.counter_offsets_presp[i];
8217
8218 if (offset >= params.beacon_csa.probe_resp_len)
8219 return -EINVAL;
8220
8221 if (params.beacon_csa.probe_resp[offset] !=
8222 params.count)
8223 return -EINVAL;
8224 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008225 }
8226
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008227skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008228 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8229 if (err)
8230 return err;
8231
Arik Nemtsov923b3522015-07-08 15:41:44 +03008232 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8233 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008234 return -EINVAL;
8235
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008236 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8237 &params.chandef,
8238 wdev->iftype);
8239 if (err < 0)
8240 return err;
8241
Benjamin Berg8d9de162017-05-16 11:23:12 +02008242 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008243 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008244 if (need_handle_dfs_flag &&
8245 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8246 return -EINVAL;
8247 }
8248 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008249
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008250 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8251 params.block_tx = true;
8252
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008253 wdev_lock(wdev);
8254 err = rdev_channel_switch(rdev, dev, &params);
8255 wdev_unlock(wdev);
8256
8257 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008258}
8259
Johannes Berg9720bb32011-06-21 09:45:33 +02008260static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8261 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008262 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008263 struct wireless_dev *wdev,
8264 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008265{
Johannes Berg48ab9052009-07-10 18:42:31 +02008266 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008267 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008268 void *hdr;
8269 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008270
8271 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008272
Eric W. Biederman15e47302012-09-07 20:12:54 +00008273 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008274 NL80211_CMD_NEW_SCAN_RESULTS);
8275 if (!hdr)
8276 return -1;
8277
Michal Kubecek0a833c22017-11-15 13:09:32 +01008278 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008279
Johannes Berg97990a02013-04-19 01:02:55 +02008280 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8281 goto nla_put_failure;
8282 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008283 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8284 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008285 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8286 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008287 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008288
8289 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
8290 if (!bss)
8291 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008292 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008293 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008294 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008295
8296 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008297 /* indicate whether we have probe response data or not */
8298 if (rcu_access_pointer(res->proberesp_ies) &&
8299 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8300 goto fail_unlock_rcu;
8301
8302 /* this pointer prefers to be pointed to probe response data
8303 * but is always valid
8304 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008305 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008306 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008307 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8308 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008309 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008310 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8311 ies->len, ies->data))
8312 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008313 }
Johannes Berg0e227082014-08-12 20:34:30 +02008314
8315 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008316 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008317 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008318 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8319 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008320 goto fail_unlock_rcu;
8321 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8322 ies->len, ies->data))
8323 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008324 }
8325 rcu_read_unlock();
8326
David S. Miller9360ffd2012-03-29 04:41:26 -04008327 if (res->beacon_interval &&
8328 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8329 goto nla_put_failure;
8330 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8331 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008332 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008333 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8334 jiffies_to_msecs(jiffies - intbss->ts)))
8335 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008336
Avraham Stern1d762502016-07-05 17:10:13 +03008337 if (intbss->parent_tsf &&
8338 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8339 intbss->parent_tsf, NL80211_BSS_PAD) ||
8340 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8341 intbss->parent_bssid)))
8342 goto nla_put_failure;
8343
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008344 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008345 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8346 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008347 goto nla_put_failure;
8348
Sunil Dutt983dafa2017-12-13 19:51:36 +02008349 if (!nl80211_put_signal(msg, intbss->pub.chains,
8350 intbss->pub.chain_signal,
8351 NL80211_BSS_CHAIN_SIGNAL))
8352 goto nla_put_failure;
8353
Johannes Berg77965c972009-02-18 18:45:06 +01008354 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008355 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008356 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8357 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008358 break;
8359 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008360 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8361 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008362 break;
8363 default:
8364 break;
8365 }
8366
Johannes Berg48ab9052009-07-10 18:42:31 +02008367 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008368 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008369 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008370 if (intbss == wdev->current_bss &&
8371 nla_put_u32(msg, NL80211_BSS_STATUS,
8372 NL80211_BSS_STATUS_ASSOCIATED))
8373 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008374 break;
8375 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008376 if (intbss == wdev->current_bss &&
8377 nla_put_u32(msg, NL80211_BSS_STATUS,
8378 NL80211_BSS_STATUS_IBSS_JOINED))
8379 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008380 break;
8381 default:
8382 break;
8383 }
8384
Johannes Berg2a519312009-02-10 21:25:55 +01008385 nla_nest_end(msg, bss);
8386
Johannes Berg053c0952015-01-16 22:09:00 +01008387 genlmsg_end(msg, hdr);
8388 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008389
Johannes Berg8cef2c92013-02-05 16:54:31 +01008390 fail_unlock_rcu:
8391 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008392 nla_put_failure:
8393 genlmsg_cancel(msg, hdr);
8394 return -EMSGSIZE;
8395}
8396
Johannes Berg97990a02013-04-19 01:02:55 +02008397static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008398{
Johannes Berg48ab9052009-07-10 18:42:31 +02008399 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008400 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008401 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008402 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008403 int err;
8404
Johannes Bergea90e0d2017-03-15 14:26:04 +01008405 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008406 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008407 if (err) {
8408 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008409 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008410 }
Johannes Berg2a519312009-02-10 21:25:55 +01008411
Johannes Berg48ab9052009-07-10 18:42:31 +02008412 wdev_lock(wdev);
8413 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008414
8415 /*
8416 * dump_scan will be called multiple times to break up the scan results
8417 * into multiple messages. It is unlikely that any more bss-es will be
8418 * expired after the first call, so only call only call this on the
8419 * first dump_scan invocation.
8420 */
8421 if (start == 0)
8422 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008423
Johannes Berg9720bb32011-06-21 09:45:33 +02008424 cb->seq = rdev->bss_generation;
8425
Johannes Berg48ab9052009-07-10 18:42:31 +02008426 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008427 if (++idx <= start)
8428 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008429 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008430 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008431 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008432 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008433 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008434 }
8435 }
8436
Johannes Berg48ab9052009-07-10 18:42:31 +02008437 spin_unlock_bh(&rdev->bss_lock);
8438 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008439
Johannes Berg97990a02013-04-19 01:02:55 +02008440 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008441 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008442
Johannes Berg67748892010-10-04 21:14:06 +02008443 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008444}
8445
Eric W. Biederman15e47302012-09-07 20:12:54 +00008446static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008447 int flags, struct net_device *dev,
8448 bool allow_radio_stats,
8449 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008450{
8451 void *hdr;
8452 struct nlattr *infoattr;
8453
Johannes Berg11f78ac2014-11-14 16:43:50 +01008454 /* skip radio stats if userspace didn't request them */
8455 if (!survey->channel && !allow_radio_stats)
8456 return 0;
8457
Eric W. Biederman15e47302012-09-07 20:12:54 +00008458 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008459 NL80211_CMD_NEW_SURVEY_RESULTS);
8460 if (!hdr)
8461 return -ENOMEM;
8462
David S. Miller9360ffd2012-03-29 04:41:26 -04008463 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8464 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008465
8466 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
8467 if (!infoattr)
8468 goto nla_put_failure;
8469
Johannes Berg11f78ac2014-11-14 16:43:50 +01008470 if (survey->channel &&
8471 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008472 survey->channel->center_freq))
8473 goto nla_put_failure;
8474
8475 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8476 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8477 goto nla_put_failure;
8478 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8479 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8480 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008481 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008482 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8483 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008484 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008485 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008486 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8487 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008488 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008489 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008490 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8491 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008492 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008493 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008494 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8495 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008496 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008497 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008498 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8499 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008500 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008501 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008502 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8503 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008504 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008505
8506 nla_nest_end(msg, infoattr);
8507
Johannes Berg053c0952015-01-16 22:09:00 +01008508 genlmsg_end(msg, hdr);
8509 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008510
8511 nla_put_failure:
8512 genlmsg_cancel(msg, hdr);
8513 return -EMSGSIZE;
8514}
8515
Johannes Berg11f78ac2014-11-14 16:43:50 +01008516static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008517{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008518 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008519 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008520 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008521 struct wireless_dev *wdev;
8522 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008523 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008524 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008525
Johannes Bergea90e0d2017-03-15 14:26:04 +01008526 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008527 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008528 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008529 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008530
Johannes Berg11f78ac2014-11-14 16:43:50 +01008531 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008532 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008533
Johannes Berg97990a02013-04-19 01:02:55 +02008534 if (!wdev->netdev) {
8535 res = -EINVAL;
8536 goto out_err;
8537 }
8538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008539 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008540 res = -EOPNOTSUPP;
8541 goto out_err;
8542 }
8543
8544 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008545 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008546 if (res == -ENOENT)
8547 break;
8548 if (res)
8549 goto out_err;
8550
Johannes Berg11f78ac2014-11-14 16:43:50 +01008551 /* don't send disabled channels, but do send non-channel data */
8552 if (survey.channel &&
8553 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008554 survey_idx++;
8555 continue;
8556 }
8557
Holger Schurig61fa7132009-11-11 12:25:40 +01008558 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008559 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008560 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008561 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008562 goto out;
8563 survey_idx++;
8564 }
8565
8566 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008567 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008568 res = skb->len;
8569 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008570 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008571 return res;
8572}
8573
Samuel Ortizb23aa672009-07-01 21:26:54 +02008574static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8575{
8576 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8577 NL80211_WPA_VERSION_2));
8578}
8579
Jouni Malinen636a5d32009-03-19 13:39:22 +02008580static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8581{
Johannes Berg4c476992010-10-04 21:36:35 +02008582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8583 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008584 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008585 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8586 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008587 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008588 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008589 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008590
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008591 if (!info->attrs[NL80211_ATTR_MAC])
8592 return -EINVAL;
8593
Jouni Malinen17780922009-03-27 20:52:47 +02008594 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8595 return -EINVAL;
8596
Johannes Berg19957bb2009-07-02 17:20:43 +02008597 if (!info->attrs[NL80211_ATTR_SSID])
8598 return -EINVAL;
8599
8600 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8601 return -EINVAL;
8602
Johannes Bergfffd0932009-07-08 14:22:54 +02008603 err = nl80211_parse_key(info, &key);
8604 if (err)
8605 return err;
8606
8607 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008608 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8609 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008610 if (!key.p.key || !key.p.key_len)
8611 return -EINVAL;
8612 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8613 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8614 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8615 key.p.key_len != WLAN_KEY_LEN_WEP104))
8616 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008617 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008618 return -EINVAL;
8619 } else {
8620 key.p.key_len = 0;
8621 key.p.key = NULL;
8622 }
8623
Johannes Bergafea0b72010-08-10 09:46:42 +02008624 if (key.idx >= 0) {
8625 int i;
8626 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008627
Johannes Bergafea0b72010-08-10 09:46:42 +02008628 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8629 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8630 ok = true;
8631 break;
8632 }
8633 }
Johannes Berg4c476992010-10-04 21:36:35 +02008634 if (!ok)
8635 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008636 }
8637
Johannes Berg4c476992010-10-04 21:36:35 +02008638 if (!rdev->ops->auth)
8639 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008640
Johannes Berg074ac8d2010-09-16 14:58:22 +02008641 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008642 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8643 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008644
Johannes Berg19957bb2009-07-02 17:20:43 +02008645 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008646 chan = nl80211_get_valid_chan(&rdev->wiphy,
8647 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8648 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008649 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008650
Johannes Berg19957bb2009-07-02 17:20:43 +02008651 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8652 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8653
8654 if (info->attrs[NL80211_ATTR_IE]) {
8655 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8656 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8657 }
8658
8659 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008660 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008661 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008662
Jouni Malinen63181062016-10-27 00:42:02 +03008663 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8664 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8665 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8666 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008667 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008668 return -EINVAL;
8669
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008670 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008671 if (auth_type != NL80211_AUTHTYPE_SAE &&
8672 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8673 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8674 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008675 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008676 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8677 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008678 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008679 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008680 return -EINVAL;
8681 }
8682
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008683 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8684
Johannes Berg95de8172012-01-20 13:55:25 +01008685 /*
8686 * Since we no longer track auth state, ignore
8687 * requests to only change local state.
8688 */
8689 if (local_state_change)
8690 return 0;
8691
Johannes Berg91bf9b22013-05-15 17:44:01 +02008692 wdev_lock(dev->ieee80211_ptr);
8693 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8694 ssid, ssid_len, ie, ie_len,
8695 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008696 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008697 wdev_unlock(dev->ieee80211_ptr);
8698 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008699}
8700
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008701static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8702 struct genl_info *info)
8703{
8704 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8705 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8706 return -EINVAL;
8707 }
8708
8709 if (!rdev->ops->tx_control_port ||
8710 !wiphy_ext_feature_isset(&rdev->wiphy,
8711 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8712 return -EOPNOTSUPP;
8713
8714 return 0;
8715}
8716
Johannes Bergc0692b82010-08-27 14:26:53 +03008717static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8718 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008719 struct cfg80211_crypto_settings *settings,
8720 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008721{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008722 memset(settings, 0, sizeof(*settings));
8723
Samuel Ortizb23aa672009-07-01 21:26:54 +02008724 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8725
Johannes Bergc0692b82010-08-27 14:26:53 +03008726 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8727 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008728
Johannes Bergc0692b82010-08-27 14:26:53 +03008729 proto = nla_get_u16(
8730 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8731 settings->control_port_ethertype = cpu_to_be16(proto);
8732 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8733 proto != ETH_P_PAE)
8734 return -EINVAL;
8735 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8736 settings->control_port_no_encrypt = true;
8737 } else
8738 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8739
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008740 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8741 int r = validate_pae_over_nl80211(rdev, info);
8742
8743 if (r < 0)
8744 return r;
8745
8746 settings->control_port_over_nl80211 = true;
8747 }
8748
Samuel Ortizb23aa672009-07-01 21:26:54 +02008749 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8750 void *data;
8751 int len, i;
8752
8753 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8754 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8755 settings->n_ciphers_pairwise = len / sizeof(u32);
8756
8757 if (len % sizeof(u32))
8758 return -EINVAL;
8759
Johannes Berg3dc27d22009-07-02 21:36:37 +02008760 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008761 return -EINVAL;
8762
8763 memcpy(settings->ciphers_pairwise, data, len);
8764
8765 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008766 if (!cfg80211_supported_cipher_suite(
8767 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008768 settings->ciphers_pairwise[i]))
8769 return -EINVAL;
8770 }
8771
8772 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8773 settings->cipher_group =
8774 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008775 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8776 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008777 return -EINVAL;
8778 }
8779
8780 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8781 settings->wpa_versions =
8782 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8783 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8784 return -EINVAL;
8785 }
8786
8787 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8788 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008789 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008790
8791 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8792 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8793 settings->n_akm_suites = len / sizeof(u32);
8794
8795 if (len % sizeof(u32))
8796 return -EINVAL;
8797
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008798 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8799 return -EINVAL;
8800
Samuel Ortizb23aa672009-07-01 21:26:54 +02008801 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008802 }
8803
Eliad Peller91b5ab62017-06-09 13:08:42 +01008804 if (info->attrs[NL80211_ATTR_PMK]) {
8805 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8806 return -EINVAL;
8807 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8808 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8809 return -EINVAL;
8810 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8811 }
8812
Samuel Ortizb23aa672009-07-01 21:26:54 +02008813 return 0;
8814}
8815
Jouni Malinen636a5d32009-03-19 13:39:22 +02008816static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8817{
Johannes Berg4c476992010-10-04 21:36:35 +02008818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8819 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008820 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008821 struct cfg80211_assoc_request req = {};
8822 const u8 *bssid, *ssid;
8823 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008824
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008825 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8826 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8827 return -EPERM;
8828
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008829 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008830 !info->attrs[NL80211_ATTR_SSID] ||
8831 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008832 return -EINVAL;
8833
Johannes Berg4c476992010-10-04 21:36:35 +02008834 if (!rdev->ops->assoc)
8835 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008836
Johannes Berg074ac8d2010-09-16 14:58:22 +02008837 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008838 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8839 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008840
Johannes Berg19957bb2009-07-02 17:20:43 +02008841 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008842
Jouni Malinen664834d2014-01-15 00:01:44 +02008843 chan = nl80211_get_valid_chan(&rdev->wiphy,
8844 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8845 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008846 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008847
Johannes Berg19957bb2009-07-02 17:20:43 +02008848 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8849 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008850
8851 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008852 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8853 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008854 }
8855
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008856 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008857 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008858 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008859 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008860 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008861 else if (mfp != NL80211_MFP_NO)
8862 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008863 }
8864
Johannes Berg3e5d7642009-07-07 14:37:26 +02008865 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008866 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008867
Ben Greear7e7c8922011-11-18 11:31:59 -08008868 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008869 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008870
8871 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008872 memcpy(&req.ht_capa_mask,
8873 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8874 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008875
8876 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008877 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008878 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008879 memcpy(&req.ht_capa,
8880 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8881 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008882 }
8883
Johannes Bergee2aca32013-02-21 17:36:01 +01008884 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008885 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008886
8887 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008888 memcpy(&req.vht_capa_mask,
8889 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8890 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008891
8892 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008893 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008894 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008895 memcpy(&req.vht_capa,
8896 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8897 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008898 }
8899
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008900 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008901 if (!((rdev->wiphy.features &
8902 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8903 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8904 !wiphy_ext_feature_isset(&rdev->wiphy,
8905 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008906 return -EINVAL;
8907 req.flags |= ASSOC_REQ_USE_RRM;
8908 }
8909
Jouni Malinen348bd452016-10-27 00:42:03 +03008910 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8911 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8912 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8913 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8914 return -EINVAL;
8915 req.fils_nonces =
8916 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8917 }
8918
Johannes Bergf62fab72013-02-21 20:09:09 +01008919 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008920 if (!err) {
8921 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008922
Johannes Bergf62fab72013-02-21 20:09:09 +01008923 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8924 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008925
8926 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8927 dev->ieee80211_ptr->conn_owner_nlportid =
8928 info->snd_portid;
8929 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8930 bssid, ETH_ALEN);
8931 }
8932
Johannes Berg91bf9b22013-05-15 17:44:01 +02008933 wdev_unlock(dev->ieee80211_ptr);
8934 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008935
Jouni Malinen636a5d32009-03-19 13:39:22 +02008936 return err;
8937}
8938
8939static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8940{
Johannes Berg4c476992010-10-04 21:36:35 +02008941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8942 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008943 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008944 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008945 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008946 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008947
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008948 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8949 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8950 return -EPERM;
8951
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008952 if (!info->attrs[NL80211_ATTR_MAC])
8953 return -EINVAL;
8954
8955 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8956 return -EINVAL;
8957
Johannes Berg4c476992010-10-04 21:36:35 +02008958 if (!rdev->ops->deauth)
8959 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008960
Johannes Berg074ac8d2010-09-16 14:58:22 +02008961 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008962 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8963 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008964
Johannes Berg19957bb2009-07-02 17:20:43 +02008965 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008966
Johannes Berg19957bb2009-07-02 17:20:43 +02008967 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8968 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008969 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008970 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008971 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008972
8973 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008974 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8975 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008976 }
8977
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008978 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8979
Johannes Berg91bf9b22013-05-15 17:44:01 +02008980 wdev_lock(dev->ieee80211_ptr);
8981 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8982 local_state_change);
8983 wdev_unlock(dev->ieee80211_ptr);
8984 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008985}
8986
8987static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8988{
Johannes Berg4c476992010-10-04 21:36:35 +02008989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8990 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008991 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008992 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008993 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008994 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008995
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008996 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8997 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8998 return -EPERM;
8999
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009000 if (!info->attrs[NL80211_ATTR_MAC])
9001 return -EINVAL;
9002
9003 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9004 return -EINVAL;
9005
Johannes Berg4c476992010-10-04 21:36:35 +02009006 if (!rdev->ops->disassoc)
9007 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009008
Johannes Berg074ac8d2010-09-16 14:58:22 +02009009 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009010 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9011 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009012
Johannes Berg19957bb2009-07-02 17:20:43 +02009013 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009014
Johannes Berg19957bb2009-07-02 17:20:43 +02009015 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9016 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009017 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009018 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009019 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009020
9021 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009022 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9023 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009024 }
9025
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009026 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9027
Johannes Berg91bf9b22013-05-15 17:44:01 +02009028 wdev_lock(dev->ieee80211_ptr);
9029 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9030 local_state_change);
9031 wdev_unlock(dev->ieee80211_ptr);
9032 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009033}
9034
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009035static bool
9036nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009037 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009038 int rateval)
9039{
9040 struct wiphy *wiphy = &rdev->wiphy;
9041 bool found = false;
9042 int band, i;
9043
Johannes Berg57fbcce2016-04-12 15:56:15 +02009044 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009045 struct ieee80211_supported_band *sband;
9046
9047 sband = wiphy->bands[band];
9048 if (!sband)
9049 continue;
9050
9051 for (i = 0; i < sband->n_bitrates; i++) {
9052 if (sband->bitrates[i].bitrate == rateval) {
9053 mcast_rate[band] = i + 1;
9054 found = true;
9055 break;
9056 }
9057 }
9058 }
9059
9060 return found;
9061}
9062
Johannes Berg04a773a2009-04-19 21:24:32 +02009063static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9064{
Johannes Berg4c476992010-10-04 21:36:35 +02009065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9066 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009067 struct cfg80211_ibss_params ibss;
9068 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009069 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009070 int err;
9071
Johannes Berg8e30bc52009-04-22 17:45:38 +02009072 memset(&ibss, 0, sizeof(ibss));
9073
Johannes Berg683b6d32012-11-08 21:25:48 +01009074 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009075 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9076 return -EINVAL;
9077
Johannes Berg8e30bc52009-04-22 17:45:38 +02009078 ibss.beacon_interval = 100;
9079
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309080 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009081 ibss.beacon_interval =
9082 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309083
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309084 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9085 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309086 if (err)
9087 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009088
Johannes Berg4c476992010-10-04 21:36:35 +02009089 if (!rdev->ops->join_ibss)
9090 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009091
Johannes Berg4c476992010-10-04 21:36:35 +02009092 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9093 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009094
Johannes Berg79c97e92009-07-07 03:56:12 +02009095 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009096
Johannes Berg39193492011-09-16 13:45:25 +02009097 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009098 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009099
9100 if (!is_valid_ether_addr(ibss.bssid))
9101 return -EINVAL;
9102 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009103 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9104 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9105
9106 if (info->attrs[NL80211_ATTR_IE]) {
9107 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9108 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9109 }
9110
Johannes Berg683b6d32012-11-08 21:25:48 +01009111 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9112 if (err)
9113 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009114
Ilan Peer174e0cd2014-02-23 09:13:01 +02009115 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9116 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009117 return -EINVAL;
9118
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009119 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009120 case NL80211_CHAN_WIDTH_5:
9121 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009122 case NL80211_CHAN_WIDTH_20_NOHT:
9123 break;
9124 case NL80211_CHAN_WIDTH_20:
9125 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009126 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9127 return -EINVAL;
9128 break;
9129 case NL80211_CHAN_WIDTH_80:
9130 case NL80211_CHAN_WIDTH_80P80:
9131 case NL80211_CHAN_WIDTH_160:
9132 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9133 return -EINVAL;
9134 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9135 NL80211_EXT_FEATURE_VHT_IBSS))
9136 return -EINVAL;
9137 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009138 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009139 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009140 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009141
Johannes Berg04a773a2009-04-19 21:24:32 +02009142 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009143 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009144
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009145 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9146 u8 *rates =
9147 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9148 int n_rates =
9149 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9150 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009151 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009152
Johannes Berg34850ab2011-07-18 18:08:35 +02009153 err = ieee80211_get_ratemask(sband, rates, n_rates,
9154 &ibss.basic_rates);
9155 if (err)
9156 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009157 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009158
Simon Wunderlich803768f2013-06-28 10:39:58 +02009159 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9160 memcpy(&ibss.ht_capa_mask,
9161 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9162 sizeof(ibss.ht_capa_mask));
9163
9164 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9165 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9166 return -EINVAL;
9167 memcpy(&ibss.ht_capa,
9168 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9169 sizeof(ibss.ht_capa));
9170 }
9171
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009172 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9173 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9174 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9175 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009176
Johannes Berg4c476992010-10-04 21:36:35 +02009177 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309178 bool no_ht = false;
9179
Johannes Berg768075e2017-11-13 15:35:06 +01009180 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009181 if (IS_ERR(connkeys))
9182 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309183
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009184 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9185 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009186 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309187 return -EINVAL;
9188 }
Johannes Berg4c476992010-10-04 21:36:35 +02009189 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009190
Antonio Quartulli267335d2012-01-31 20:25:47 +01009191 ibss.control_port =
9192 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9193
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009194 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9195 int r = validate_pae_over_nl80211(rdev, info);
9196
Johannes Bergd350a0f2018-12-15 11:03:22 +02009197 if (r < 0) {
9198 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009199 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009200 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009201
9202 ibss.control_port_over_nl80211 = true;
9203 }
9204
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009205 ibss.userspace_handles_dfs =
9206 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9207
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009208 wdev_lock(dev->ieee80211_ptr);
9209 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009210 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009211 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009212 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9213 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9214 wdev_unlock(dev->ieee80211_ptr);
9215
Johannes Berg04a773a2009-04-19 21:24:32 +02009216 return err;
9217}
9218
9219static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9220{
Johannes Berg4c476992010-10-04 21:36:35 +02009221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9222 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009223
Johannes Berg4c476992010-10-04 21:36:35 +02009224 if (!rdev->ops->leave_ibss)
9225 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009226
Johannes Berg4c476992010-10-04 21:36:35 +02009227 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9228 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009229
Johannes Berg4c476992010-10-04 21:36:35 +02009230 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009231}
9232
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009233static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9234{
9235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9236 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009237 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009238 u32 nla_rate;
9239 int err;
9240
9241 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009242 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9243 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009244 return -EOPNOTSUPP;
9245
9246 if (!rdev->ops->set_mcast_rate)
9247 return -EOPNOTSUPP;
9248
9249 memset(mcast_rate, 0, sizeof(mcast_rate));
9250
9251 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9252 return -EINVAL;
9253
9254 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9255 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9256 return -EINVAL;
9257
Ilan Peera1056b1b2015-10-22 22:27:46 +03009258 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009259
9260 return err;
9261}
9262
Johannes Bergad7e7182013-11-13 13:37:47 +01009263static struct sk_buff *
9264__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009265 struct wireless_dev *wdev, int approxlen,
9266 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009267 enum nl80211_attrs attr,
9268 const struct nl80211_vendor_cmd_info *info,
9269 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009270{
9271 struct sk_buff *skb;
9272 void *hdr;
9273 struct nlattr *data;
9274
9275 skb = nlmsg_new(approxlen + 100, gfp);
9276 if (!skb)
9277 return NULL;
9278
9279 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9280 if (!hdr) {
9281 kfree_skb(skb);
9282 return NULL;
9283 }
9284
9285 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9286 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009287
9288 if (info) {
9289 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9290 info->vendor_id))
9291 goto nla_put_failure;
9292 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9293 info->subcmd))
9294 goto nla_put_failure;
9295 }
9296
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009297 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009298 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9299 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009300 goto nla_put_failure;
9301 if (wdev->netdev &&
9302 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9303 wdev->netdev->ifindex))
9304 goto nla_put_failure;
9305 }
9306
Johannes Bergad7e7182013-11-13 13:37:47 +01009307 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009308 if (!data)
9309 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009310
9311 ((void **)skb->cb)[0] = rdev;
9312 ((void **)skb->cb)[1] = hdr;
9313 ((void **)skb->cb)[2] = data;
9314
9315 return skb;
9316
9317 nla_put_failure:
9318 kfree_skb(skb);
9319 return NULL;
9320}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009321
Johannes Berge03ad6e2014-01-01 17:22:30 +01009322struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009323 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009324 enum nl80211_commands cmd,
9325 enum nl80211_attrs attr,
9326 int vendor_event_idx,
9327 int approxlen, gfp_t gfp)
9328{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009329 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009330 const struct nl80211_vendor_cmd_info *info;
9331
9332 switch (cmd) {
9333 case NL80211_CMD_TESTMODE:
9334 if (WARN_ON(vendor_event_idx != -1))
9335 return NULL;
9336 info = NULL;
9337 break;
9338 case NL80211_CMD_VENDOR:
9339 if (WARN_ON(vendor_event_idx < 0 ||
9340 vendor_event_idx >= wiphy->n_vendor_events))
9341 return NULL;
9342 info = &wiphy->vendor_events[vendor_event_idx];
9343 break;
9344 default:
9345 WARN_ON(1);
9346 return NULL;
9347 }
9348
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009349 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009350 cmd, attr, info, gfp);
9351}
9352EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9353
9354void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9355{
9356 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9357 void *hdr = ((void **)skb->cb)[1];
9358 struct nlattr *data = ((void **)skb->cb)[2];
9359 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9360
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009361 /* clear CB data for netlink core to own from now on */
9362 memset(skb->cb, 0, sizeof(skb->cb));
9363
Johannes Berge03ad6e2014-01-01 17:22:30 +01009364 nla_nest_end(skb, data);
9365 genlmsg_end(skb, hdr);
9366
9367 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9368 mcgrp = NL80211_MCGRP_VENDOR;
9369
9370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
9371 mcgrp, gfp);
9372}
9373EXPORT_SYMBOL(__cfg80211_send_event_skb);
9374
Johannes Bergaff89a92009-07-01 21:26:51 +02009375#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009376static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9377{
Johannes Berg4c476992010-10-04 21:36:35 +02009378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009379 struct wireless_dev *wdev =
9380 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009381 int err;
9382
David Spinadelfc73f112013-07-31 18:04:15 +03009383 if (!rdev->ops->testmode_cmd)
9384 return -EOPNOTSUPP;
9385
9386 if (IS_ERR(wdev)) {
9387 err = PTR_ERR(wdev);
9388 if (err != -EINVAL)
9389 return err;
9390 wdev = NULL;
9391 } else if (wdev->wiphy != &rdev->wiphy) {
9392 return -EINVAL;
9393 }
9394
Johannes Bergaff89a92009-07-01 21:26:51 +02009395 if (!info->attrs[NL80211_ATTR_TESTDATA])
9396 return -EINVAL;
9397
Johannes Bergad7e7182013-11-13 13:37:47 +01009398 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009399 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009400 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9401 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009402 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009403
Johannes Bergaff89a92009-07-01 21:26:51 +02009404 return err;
9405}
9406
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009407static int nl80211_testmode_dump(struct sk_buff *skb,
9408 struct netlink_callback *cb)
9409{
Johannes Berg00918d32011-12-13 17:22:05 +01009410 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009411 int err;
9412 long phy_idx;
9413 void *data = NULL;
9414 int data_len = 0;
9415
Johannes Berg5fe231e2013-05-08 21:45:15 +02009416 rtnl_lock();
9417
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009418 if (cb->args[0]) {
9419 /*
9420 * 0 is a valid index, but not valid for args[0],
9421 * so we need to offset by 1.
9422 */
9423 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009424
9425 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9426 if (!rdev) {
9427 err = -ENOENT;
9428 goto out_err;
9429 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009430 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009431 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9432
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009433 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02009434 attrbuf, nl80211_fam.maxattr,
9435 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009436 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009437 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009438
Johannes Bergc90c39d2016-10-24 14:40:01 +02009439 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009440 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009441 err = PTR_ERR(rdev);
9442 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009443 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009444 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009445
Johannes Bergc90c39d2016-10-24 14:40:01 +02009446 if (attrbuf[NL80211_ATTR_TESTDATA])
9447 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009448 }
9449
9450 if (cb->args[1]) {
9451 data = nla_data((void *)cb->args[1]);
9452 data_len = nla_len((void *)cb->args[1]);
9453 }
9454
Johannes Berg00918d32011-12-13 17:22:05 +01009455 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009456 err = -EOPNOTSUPP;
9457 goto out_err;
9458 }
9459
9460 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009461 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009462 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9463 NL80211_CMD_TESTMODE);
9464 struct nlattr *tmdata;
9465
Dan Carpentercb35fba2013-08-14 14:50:01 +03009466 if (!hdr)
9467 break;
9468
David S. Miller9360ffd2012-03-29 04:41:26 -04009469 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009470 genlmsg_cancel(skb, hdr);
9471 break;
9472 }
9473
9474 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
9475 if (!tmdata) {
9476 genlmsg_cancel(skb, hdr);
9477 break;
9478 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009479 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009480 nla_nest_end(skb, tmdata);
9481
9482 if (err == -ENOBUFS || err == -ENOENT) {
9483 genlmsg_cancel(skb, hdr);
9484 break;
9485 } else if (err) {
9486 genlmsg_cancel(skb, hdr);
9487 goto out_err;
9488 }
9489
9490 genlmsg_end(skb, hdr);
9491 }
9492
9493 err = skb->len;
9494 /* see above */
9495 cb->args[0] = phy_idx + 1;
9496 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009497 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009498 return err;
9499}
Johannes Bergaff89a92009-07-01 21:26:51 +02009500#endif
9501
Samuel Ortizb23aa672009-07-01 21:26:54 +02009502static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9503{
Johannes Berg4c476992010-10-04 21:36:35 +02009504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9505 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009506 struct cfg80211_connect_params connect;
9507 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009508 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009509 int err;
9510
9511 memset(&connect, 0, sizeof(connect));
9512
Samuel Ortizb23aa672009-07-01 21:26:54 +02009513 if (!info->attrs[NL80211_ATTR_SSID] ||
9514 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9515 return -EINVAL;
9516
9517 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9518 connect.auth_type =
9519 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009520 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9521 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009522 return -EINVAL;
9523 } else
9524 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9525
9526 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9527
Avraham Stern3a00df52017-06-09 13:08:43 +01009528 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9529 !wiphy_ext_feature_isset(&rdev->wiphy,
9530 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9531 return -EINVAL;
9532 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9533
Johannes Bergc0692b82010-08-27 14:26:53 +03009534 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009535 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009536 if (err)
9537 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009538
Johannes Berg074ac8d2010-09-16 14:58:22 +02009539 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009540 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9541 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009542
Johannes Berg79c97e92009-07-07 03:56:12 +02009543 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009544
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309545 connect.bg_scan_period = -1;
9546 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9547 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9548 connect.bg_scan_period =
9549 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9550 }
9551
Samuel Ortizb23aa672009-07-01 21:26:54 +02009552 if (info->attrs[NL80211_ATTR_MAC])
9553 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009554 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9555 connect.bssid_hint =
9556 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009557 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9558 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9559
9560 if (info->attrs[NL80211_ATTR_IE]) {
9561 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9562 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9563 }
9564
Jouni Malinencee00a92013-01-15 17:15:57 +02009565 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9566 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009567 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9568 !wiphy_ext_feature_isset(&rdev->wiphy,
9569 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9570 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009571 } else {
9572 connect.mfp = NL80211_MFP_NO;
9573 }
9574
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009575 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9576 connect.prev_bssid =
9577 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9578
Samuel Ortizb23aa672009-07-01 21:26:54 +02009579 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009580 connect.channel = nl80211_get_valid_chan(
9581 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9582 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009583 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009584 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009585 connect.channel_hint = nl80211_get_valid_chan(
9586 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9587 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009588 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009589 }
9590
Johannes Bergfffd0932009-07-08 14:22:54 +02009591 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009592 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009593 if (IS_ERR(connkeys))
9594 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009595 }
9596
Ben Greear7e7c8922011-11-18 11:31:59 -08009597 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9598 connect.flags |= ASSOC_REQ_DISABLE_HT;
9599
9600 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9601 memcpy(&connect.ht_capa_mask,
9602 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9603 sizeof(connect.ht_capa_mask));
9604
9605 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009606 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009607 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009608 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009609 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009610 memcpy(&connect.ht_capa,
9611 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9612 sizeof(connect.ht_capa));
9613 }
9614
Johannes Bergee2aca32013-02-21 17:36:01 +01009615 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9616 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9617
9618 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9619 memcpy(&connect.vht_capa_mask,
9620 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9621 sizeof(connect.vht_capa_mask));
9622
9623 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9624 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009625 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009626 return -EINVAL;
9627 }
9628 memcpy(&connect.vht_capa,
9629 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9630 sizeof(connect.vht_capa));
9631 }
9632
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009633 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009634 if (!((rdev->wiphy.features &
9635 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9636 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9637 !wiphy_ext_feature_isset(&rdev->wiphy,
9638 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009639 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009640 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009641 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009642 connect.flags |= ASSOC_REQ_USE_RRM;
9643 }
9644
Lior David34d50512016-01-28 10:58:25 +02009645 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009646 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009647 kzfree(connkeys);
9648 return -EOPNOTSUPP;
9649 }
9650
Arend van Spriel38de03d2016-03-02 20:37:18 +01009651 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9652 /* bss selection makes no sense if bssid is set */
9653 if (connect.bssid) {
9654 kzfree(connkeys);
9655 return -EINVAL;
9656 }
9657
9658 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9659 wiphy, &connect.bss_select);
9660 if (err) {
9661 kzfree(connkeys);
9662 return err;
9663 }
9664 }
9665
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009666 if (wiphy_ext_feature_isset(&rdev->wiphy,
9667 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9668 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9669 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9670 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9671 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9672 connect.fils_erp_username =
9673 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9674 connect.fils_erp_username_len =
9675 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9676 connect.fils_erp_realm =
9677 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9678 connect.fils_erp_realm_len =
9679 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9680 connect.fils_erp_next_seq_num =
9681 nla_get_u16(
9682 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9683 connect.fils_erp_rrk =
9684 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9685 connect.fils_erp_rrk_len =
9686 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9687 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9688 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9689 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9690 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9691 kzfree(connkeys);
9692 return -EINVAL;
9693 }
9694
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009695 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9696 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309697 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009698 GENL_SET_ERR_MSG(info,
9699 "external auth requires connection ownership");
9700 return -EINVAL;
9701 }
9702 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9703 }
9704
Johannes Berg83739b02013-05-15 17:44:01 +02009705 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009706
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009707 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9708 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009709 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009710 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009711
9712 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9713 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9714 if (connect.bssid)
9715 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9716 connect.bssid, ETH_ALEN);
9717 else
9718 memset(dev->ieee80211_ptr->disconnect_bssid,
9719 0, ETH_ALEN);
9720 }
9721
9722 wdev_unlock(dev->ieee80211_ptr);
9723
Samuel Ortizb23aa672009-07-01 21:26:54 +02009724 return err;
9725}
9726
vamsi krishna088e8df2016-10-27 16:51:11 +03009727static int nl80211_update_connect_params(struct sk_buff *skb,
9728 struct genl_info *info)
9729{
9730 struct cfg80211_connect_params connect = {};
9731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9732 struct net_device *dev = info->user_ptr[1];
9733 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009734 bool fils_sk_offload;
9735 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +03009736 u32 changed = 0;
9737 int ret;
9738
9739 if (!rdev->ops->update_connect_params)
9740 return -EOPNOTSUPP;
9741
9742 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +03009743 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9744 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9745 changed |= UPDATE_ASSOC_IES;
9746 }
9747
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009748 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
9749 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
9750
9751 /*
9752 * when driver supports fils-sk offload all attributes must be
9753 * provided. So the else covers "fils-sk-not-all" and
9754 * "no-fils-sk-any".
9755 */
9756 if (fils_sk_offload &&
9757 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9758 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9759 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9760 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9761 connect.fils_erp_username =
9762 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9763 connect.fils_erp_username_len =
9764 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9765 connect.fils_erp_realm =
9766 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9767 connect.fils_erp_realm_len =
9768 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9769 connect.fils_erp_next_seq_num =
9770 nla_get_u16(
9771 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9772 connect.fils_erp_rrk =
9773 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9774 connect.fils_erp_rrk_len =
9775 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9776 changed |= UPDATE_FILS_ERP_INFO;
9777 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9778 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9779 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9780 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9781 return -EINVAL;
9782 }
9783
9784 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9785 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9786 if (!nl80211_valid_auth_type(rdev, auth_type,
9787 NL80211_CMD_CONNECT))
9788 return -EINVAL;
9789
9790 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
9791 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
9792 return -EINVAL;
9793
9794 connect.auth_type = auth_type;
9795 changed |= UPDATE_AUTH_TYPE;
9796 }
9797
vamsi krishna088e8df2016-10-27 16:51:11 +03009798 wdev_lock(dev->ieee80211_ptr);
9799 if (!wdev->current_bss)
9800 ret = -ENOLINK;
9801 else
9802 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9803 wdev_unlock(dev->ieee80211_ptr);
9804
9805 return ret;
9806}
9807
Samuel Ortizb23aa672009-07-01 21:26:54 +02009808static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9809{
Johannes Berg4c476992010-10-04 21:36:35 +02009810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9811 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009812 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009813 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009814
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009815 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9816 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9817 return -EPERM;
9818
Samuel Ortizb23aa672009-07-01 21:26:54 +02009819 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9820 reason = WLAN_REASON_DEAUTH_LEAVING;
9821 else
9822 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9823
9824 if (reason == 0)
9825 return -EINVAL;
9826
Johannes Berg074ac8d2010-09-16 14:58:22 +02009827 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009828 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9829 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009830
Johannes Berg83739b02013-05-15 17:44:01 +02009831 wdev_lock(dev->ieee80211_ptr);
9832 ret = cfg80211_disconnect(rdev, dev, reason, true);
9833 wdev_unlock(dev->ieee80211_ptr);
9834 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009835}
9836
Johannes Berg463d0182009-07-14 00:33:35 +02009837static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9838{
Johannes Berg4c476992010-10-04 21:36:35 +02009839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009840 struct net *net;
9841 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009842
Vadim Kochan4b681c82015-01-12 16:34:05 +02009843 if (info->attrs[NL80211_ATTR_PID]) {
9844 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9845
9846 net = get_net_ns_by_pid(pid);
9847 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9848 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9849
9850 net = get_net_ns_by_fd(fd);
9851 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009852 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009853 }
Johannes Berg463d0182009-07-14 00:33:35 +02009854
Johannes Berg4c476992010-10-04 21:36:35 +02009855 if (IS_ERR(net))
9856 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009857
9858 err = 0;
9859
9860 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009861 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9862 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009863
Johannes Berg463d0182009-07-14 00:33:35 +02009864 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009865 return err;
9866}
9867
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009868static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9869{
Johannes Berg4c476992010-10-04 21:36:35 +02009870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009871 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9872 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009873 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009874 struct cfg80211_pmksa pmksa;
9875
9876 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9877
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009878 if (!info->attrs[NL80211_ATTR_PMKID])
9879 return -EINVAL;
9880
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009881 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009882
9883 if (info->attrs[NL80211_ATTR_MAC]) {
9884 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9885 } else if (info->attrs[NL80211_ATTR_SSID] &&
9886 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9887 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9888 info->attrs[NL80211_ATTR_PMK])) {
9889 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9890 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9891 pmksa.cache_id =
9892 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9893 } else {
9894 return -EINVAL;
9895 }
9896 if (info->attrs[NL80211_ATTR_PMK]) {
9897 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9898 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9899 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009900
Johannes Berg074ac8d2010-09-16 14:58:22 +02009901 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009902 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9903 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009904
9905 switch (info->genlhdr->cmd) {
9906 case NL80211_CMD_SET_PMKSA:
9907 rdev_ops = rdev->ops->set_pmksa;
9908 break;
9909 case NL80211_CMD_DEL_PMKSA:
9910 rdev_ops = rdev->ops->del_pmksa;
9911 break;
9912 default:
9913 WARN_ON(1);
9914 break;
9915 }
9916
Johannes Berg4c476992010-10-04 21:36:35 +02009917 if (!rdev_ops)
9918 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009919
Johannes Berg4c476992010-10-04 21:36:35 +02009920 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009921}
9922
9923static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9924{
Johannes Berg4c476992010-10-04 21:36:35 +02009925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9926 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009927
Johannes Berg074ac8d2010-09-16 14:58:22 +02009928 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009929 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9930 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009931
Johannes Berg4c476992010-10-04 21:36:35 +02009932 if (!rdev->ops->flush_pmksa)
9933 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009934
Hila Gonene35e4d22012-06-27 17:19:42 +03009935 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009936}
9937
Arik Nemtsov109086c2011-09-28 14:12:50 +03009938static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9939{
9940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9941 struct net_device *dev = info->user_ptr[1];
9942 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309943 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009944 u16 status_code;
9945 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009946 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009947
9948 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9949 !rdev->ops->tdls_mgmt)
9950 return -EOPNOTSUPP;
9951
9952 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9953 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9954 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9955 !info->attrs[NL80211_ATTR_IE] ||
9956 !info->attrs[NL80211_ATTR_MAC])
9957 return -EINVAL;
9958
9959 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9960 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9961 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9962 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009963 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309964 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9965 peer_capability =
9966 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009967
Hila Gonene35e4d22012-06-27 17:19:42 +03009968 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309969 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009970 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009971 nla_data(info->attrs[NL80211_ATTR_IE]),
9972 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009973}
9974
9975static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9976{
9977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9978 struct net_device *dev = info->user_ptr[1];
9979 enum nl80211_tdls_operation operation;
9980 u8 *peer;
9981
9982 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9983 !rdev->ops->tdls_oper)
9984 return -EOPNOTSUPP;
9985
9986 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9987 !info->attrs[NL80211_ATTR_MAC])
9988 return -EINVAL;
9989
9990 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9991 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9992
Hila Gonene35e4d22012-06-27 17:19:42 +03009993 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009994}
9995
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009996static int nl80211_remain_on_channel(struct sk_buff *skb,
9997 struct genl_info *info)
9998{
Johannes Berg4c476992010-10-04 21:36:35 +02009999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010000 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010001 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010002 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010003 struct sk_buff *msg;
10004 void *hdr;
10005 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010006 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010007 int err;
10008
10009 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10010 !info->attrs[NL80211_ATTR_DURATION])
10011 return -EINVAL;
10012
10013 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10014
Johannes Berg7c4ef712011-11-18 15:33:48 +010010015 if (!rdev->ops->remain_on_channel ||
10016 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010017 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010018
Johannes Bergebf348f2012-06-01 12:50:54 +020010019 /*
10020 * We should be on that channel for at least a minimum amount of
10021 * time (10ms) but no longer than the driver supports.
10022 */
10023 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10024 duration > rdev->wiphy.max_remain_on_channel_duration)
10025 return -EINVAL;
10026
Johannes Berg683b6d32012-11-08 21:25:48 +010010027 err = nl80211_parse_chandef(rdev, info, &chandef);
10028 if (err)
10029 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010030
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010031 wdev_lock(wdev);
10032 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10033 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10034 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10035 &chandef);
10036 if (compat_chandef != &chandef) {
10037 wdev_unlock(wdev);
10038 return -EBUSY;
10039 }
10040 }
10041 wdev_unlock(wdev);
10042
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010043 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010044 if (!msg)
10045 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010046
Eric W. Biederman15e47302012-09-07 20:12:54 +000010047 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010048 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010049 if (!hdr) {
10050 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010051 goto free_msg;
10052 }
10053
Johannes Berg683b6d32012-11-08 21:25:48 +010010054 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10055 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010056
10057 if (err)
10058 goto free_msg;
10059
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010060 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10061 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010062 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010063
10064 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010065
10066 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010067
10068 nla_put_failure:
10069 err = -ENOBUFS;
10070 free_msg:
10071 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010072 return err;
10073}
10074
10075static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10076 struct genl_info *info)
10077{
Johannes Berg4c476992010-10-04 21:36:35 +020010078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010079 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010080 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010081
10082 if (!info->attrs[NL80211_ATTR_COOKIE])
10083 return -EINVAL;
10084
Johannes Berg4c476992010-10-04 21:36:35 +020010085 if (!rdev->ops->cancel_remain_on_channel)
10086 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010087
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010088 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10089
Hila Gonene35e4d22012-06-27 17:19:42 +030010090 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010091}
10092
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010093static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10094 struct genl_info *info)
10095{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010096 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010098 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010099 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010100
Johannes Berg4c476992010-10-04 21:36:35 +020010101 if (!rdev->ops->set_bitrate_mask)
10102 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010103
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010104 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10105 if (err)
10106 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010107
Hila Gonene35e4d22012-06-27 17:19:42 +030010108 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010109}
10110
Johannes Berg2e161f782010-08-12 15:38:38 +020010111static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010112{
Johannes Berg4c476992010-10-04 21:36:35 +020010113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010114 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010115 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010116
10117 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10118 return -EINVAL;
10119
Johannes Berg2e161f782010-08-12 15:38:38 +020010120 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10121 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010122
Johannes Berg71bbc992012-06-15 15:30:18 +020010123 switch (wdev->iftype) {
10124 case NL80211_IFTYPE_STATION:
10125 case NL80211_IFTYPE_ADHOC:
10126 case NL80211_IFTYPE_P2P_CLIENT:
10127 case NL80211_IFTYPE_AP:
10128 case NL80211_IFTYPE_AP_VLAN:
10129 case NL80211_IFTYPE_MESH_POINT:
10130 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010131 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010132 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010133 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010134 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010135 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010136 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010137
10138 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010139 if (!rdev->ops->mgmt_tx)
10140 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010141
Eric W. Biederman15e47302012-09-07 20:12:54 +000010142 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010143 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10144 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010145}
10146
Johannes Berg2e161f782010-08-12 15:38:38 +020010147static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010148{
Johannes Berg4c476992010-10-04 21:36:35 +020010149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010150 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010151 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010152 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010153 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010154 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010155 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010156 struct cfg80211_mgmt_tx_params params = {
10157 .dont_wait_for_ack =
10158 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10159 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010160
Johannes Berg683b6d32012-11-08 21:25:48 +010010161 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010162 return -EINVAL;
10163
Johannes Berg4c476992010-10-04 21:36:35 +020010164 if (!rdev->ops->mgmt_tx)
10165 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010166
Johannes Berg71bbc992012-06-15 15:30:18 +020010167 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010168 case NL80211_IFTYPE_P2P_DEVICE:
10169 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10170 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010171 case NL80211_IFTYPE_STATION:
10172 case NL80211_IFTYPE_ADHOC:
10173 case NL80211_IFTYPE_P2P_CLIENT:
10174 case NL80211_IFTYPE_AP:
10175 case NL80211_IFTYPE_AP_VLAN:
10176 case NL80211_IFTYPE_MESH_POINT:
10177 case NL80211_IFTYPE_P2P_GO:
10178 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010179 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010180 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010181 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010182 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010183
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010184 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010185 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010186 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010187 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010188
10189 /*
10190 * We should wait on the channel for at least a minimum amount
10191 * of time (10ms) but no longer than the driver supports.
10192 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010193 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10194 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010195 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010196 }
10197
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010198 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010199
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010200 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010201 return -EINVAL;
10202
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010203 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010204
Antonio Quartulliea141b752013-06-11 14:20:03 +020010205 /* get the channel if any has been specified, otherwise pass NULL to
10206 * the driver. The latter will use the current one
10207 */
10208 chandef.chan = NULL;
10209 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10210 err = nl80211_parse_chandef(rdev, info, &chandef);
10211 if (err)
10212 return err;
10213 }
10214
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010215 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010216 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010217
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010218 wdev_lock(wdev);
10219 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10220 wdev_unlock(wdev);
10221 return -EBUSY;
10222 }
10223 wdev_unlock(wdev);
10224
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010225 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10226 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10227
10228 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10229 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10230 int i;
10231
10232 if (len % sizeof(u16))
10233 return -EINVAL;
10234
10235 params.n_csa_offsets = len / sizeof(u16);
10236 params.csa_offsets =
10237 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10238
10239 /* check that all the offsets fit the frame */
10240 for (i = 0; i < params.n_csa_offsets; i++) {
10241 if (params.csa_offsets[i] >= params.len)
10242 return -EINVAL;
10243 }
10244 }
10245
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010246 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10248 if (!msg)
10249 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010250
Eric W. Biederman15e47302012-09-07 20:12:54 +000010251 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010252 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010253 if (!hdr) {
10254 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010255 goto free_msg;
10256 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010257 }
Johannes Berge247bd902011-11-04 11:18:21 +010010258
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010259 params.chan = chandef.chan;
10260 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010261 if (err)
10262 goto free_msg;
10263
Johannes Berge247bd902011-11-04 11:18:21 +010010264 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010265 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10266 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010267 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010268
Johannes Berge247bd902011-11-04 11:18:21 +010010269 genlmsg_end(msg, hdr);
10270 return genlmsg_reply(msg, info);
10271 }
10272
10273 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010274
10275 nla_put_failure:
10276 err = -ENOBUFS;
10277 free_msg:
10278 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010279 return err;
10280}
10281
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010282static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10283{
10284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010285 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010286 u64 cookie;
10287
10288 if (!info->attrs[NL80211_ATTR_COOKIE])
10289 return -EINVAL;
10290
10291 if (!rdev->ops->mgmt_tx_cancel_wait)
10292 return -EOPNOTSUPP;
10293
Johannes Berg71bbc992012-06-15 15:30:18 +020010294 switch (wdev->iftype) {
10295 case NL80211_IFTYPE_STATION:
10296 case NL80211_IFTYPE_ADHOC:
10297 case NL80211_IFTYPE_P2P_CLIENT:
10298 case NL80211_IFTYPE_AP:
10299 case NL80211_IFTYPE_AP_VLAN:
10300 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010301 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010302 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010303 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010304 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010305 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010306 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010307
10308 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10309
Hila Gonene35e4d22012-06-27 17:19:42 +030010310 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010311}
10312
Kalle Valoffb9eb32010-02-17 17:58:10 +020010313static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10314{
Johannes Berg4c476992010-10-04 21:36:35 +020010315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010316 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010317 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010318 u8 ps_state;
10319 bool state;
10320 int err;
10321
Johannes Berg4c476992010-10-04 21:36:35 +020010322 if (!info->attrs[NL80211_ATTR_PS_STATE])
10323 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010324
10325 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10326
Kalle Valoffb9eb32010-02-17 17:58:10 +020010327 wdev = dev->ieee80211_ptr;
10328
Johannes Berg4c476992010-10-04 21:36:35 +020010329 if (!rdev->ops->set_power_mgmt)
10330 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010331
10332 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10333
10334 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010335 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010336
Hila Gonene35e4d22012-06-27 17:19:42 +030010337 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010338 if (!err)
10339 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010340 return err;
10341}
10342
10343static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10344{
Johannes Berg4c476992010-10-04 21:36:35 +020010345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010346 enum nl80211_ps_state ps_state;
10347 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010348 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010349 struct sk_buff *msg;
10350 void *hdr;
10351 int err;
10352
Kalle Valoffb9eb32010-02-17 17:58:10 +020010353 wdev = dev->ieee80211_ptr;
10354
Johannes Berg4c476992010-10-04 21:36:35 +020010355 if (!rdev->ops->set_power_mgmt)
10356 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010357
10358 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010359 if (!msg)
10360 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010361
Eric W. Biederman15e47302012-09-07 20:12:54 +000010362 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010363 NL80211_CMD_GET_POWER_SAVE);
10364 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010365 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010366 goto free_msg;
10367 }
10368
10369 if (wdev->ps)
10370 ps_state = NL80211_PS_ENABLED;
10371 else
10372 ps_state = NL80211_PS_DISABLED;
10373
David S. Miller9360ffd2012-03-29 04:41:26 -040010374 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10375 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010376
10377 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010378 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010379
Johannes Berg4c476992010-10-04 21:36:35 +020010380 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010381 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010382 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010383 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010384 return err;
10385}
10386
Johannes Berg94e860f2014-01-20 23:58:15 +010010387static const struct nla_policy
10388nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010389 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010390 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10391 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010392 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10393 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10394 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010395 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010396};
10397
Thomas Pedersen84f10702012-07-12 16:17:33 -070010398static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010399 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010400{
10401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010402 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010403 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010404
Johannes Bergd9d8b012012-11-26 12:51:52 +010010405 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010406 return -EINVAL;
10407
Thomas Pedersen84f10702012-07-12 16:17:33 -070010408 if (!rdev->ops->set_cqm_txe_config)
10409 return -EOPNOTSUPP;
10410
10411 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10412 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10413 return -EOPNOTSUPP;
10414
Hila Gonene35e4d22012-06-27 17:19:42 +030010415 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010416}
10417
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010418static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10419 struct net_device *dev)
10420{
10421 struct wireless_dev *wdev = dev->ieee80211_ptr;
10422 s32 last, low, high;
10423 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010424 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010425 int err;
10426
10427 /* RSSI reporting disabled? */
10428 if (!wdev->cqm_config)
10429 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10430
10431 /*
10432 * Obtain current RSSI value if possible, if not and no RSSI threshold
10433 * event has been received yet, we should receive an event after a
10434 * connection is established and enough beacons received to calculate
10435 * the average.
10436 */
10437 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10438 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010439 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010440 u8 *mac_addr;
10441
10442 mac_addr = wdev->current_bss->pub.bssid;
10443
Johannes Berg73887fd2018-05-18 09:57:55 +020010444 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10445 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010446 return err;
10447
Omer Efrat397c6572018-06-17 13:06:14 +030010448 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010449 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010450 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010451 }
10452
10453 last = wdev->cqm_config->last_rssi_event_value;
10454 hyst = wdev->cqm_config->rssi_hyst;
10455 n = wdev->cqm_config->n_rssi_thresholds;
10456
10457 for (i = 0; i < n; i++)
10458 if (last < wdev->cqm_config->rssi_thresholds[i])
10459 break;
10460
Masashi Honma1222a162018-09-25 11:15:01 +090010461 low_index = i - 1;
10462 if (low_index >= 0) {
10463 low_index = array_index_nospec(low_index, n);
10464 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10465 } else {
10466 low = S32_MIN;
10467 }
10468 if (i < n) {
10469 i = array_index_nospec(i, n);
10470 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10471 } else {
10472 high = S32_MAX;
10473 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010474
10475 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10476}
10477
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010478static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010479 const s32 *thresholds, int n_thresholds,
10480 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010481{
Johannes Berg4c476992010-10-04 21:36:35 +020010482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010483 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010484 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010485 int i, err;
10486 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010487
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010488 /* Check all values negative and sorted */
10489 for (i = 0; i < n_thresholds; i++) {
10490 if (thresholds[i] > 0 || thresholds[i] <= prev)
10491 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010492
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010493 prev = thresholds[i];
10494 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010495
Johannes Berg074ac8d2010-09-16 14:58:22 +020010496 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010497 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10498 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010499
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010500 wdev_lock(wdev);
10501 cfg80211_cqm_config_free(wdev);
10502 wdev_unlock(wdev);
10503
10504 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10505 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10506 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10507
10508 return rdev_set_cqm_rssi_config(rdev, dev,
10509 thresholds[0], hysteresis);
10510 }
10511
10512 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10513 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10514 return -EOPNOTSUPP;
10515
10516 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10517 n_thresholds = 0;
10518
10519 wdev_lock(wdev);
10520 if (n_thresholds) {
10521 struct cfg80211_cqm_config *cqm_config;
10522
10523 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10524 n_thresholds * sizeof(s32), GFP_KERNEL);
10525 if (!cqm_config) {
10526 err = -ENOMEM;
10527 goto unlock;
10528 }
10529
10530 cqm_config->rssi_hyst = hysteresis;
10531 cqm_config->n_rssi_thresholds = n_thresholds;
10532 memcpy(cqm_config->rssi_thresholds, thresholds,
10533 n_thresholds * sizeof(s32));
10534
10535 wdev->cqm_config = cqm_config;
10536 }
10537
10538 err = cfg80211_cqm_rssi_update(rdev, dev);
10539
10540unlock:
10541 wdev_unlock(wdev);
10542
10543 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010544}
10545
10546static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10547{
10548 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10549 struct nlattr *cqm;
10550 int err;
10551
10552 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010553 if (!cqm)
10554 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010555
10556 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +020010557 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010558 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010559 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010560
10561 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10562 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010563 const s32 *thresholds =
10564 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10565 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010566 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010567
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010568 if (len % 4)
10569 return -EINVAL;
10570
10571 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10572 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010573 }
10574
10575 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10576 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10577 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10578 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10579 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10580 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10581
10582 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10583 }
10584
10585 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010586}
10587
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010588static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10589{
10590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10591 struct net_device *dev = info->user_ptr[1];
10592 struct ocb_setup setup = {};
10593 int err;
10594
10595 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10596 if (err)
10597 return err;
10598
10599 return cfg80211_join_ocb(rdev, dev, &setup);
10600}
10601
10602static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10603{
10604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10605 struct net_device *dev = info->user_ptr[1];
10606
10607 return cfg80211_leave_ocb(rdev, dev);
10608}
10609
Johannes Berg29cbe682010-12-03 09:20:44 +010010610static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10611{
10612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10613 struct net_device *dev = info->user_ptr[1];
10614 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010615 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010616 int err;
10617
10618 /* start with default */
10619 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010620 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010621
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010622 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010623 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010624 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010625 if (err)
10626 return err;
10627 }
10628
10629 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10630 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10631 return -EINVAL;
10632
Javier Cardonac80d5452010-12-16 17:37:49 -080010633 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10634 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10635
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010636 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10637 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10638 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10639 return -EINVAL;
10640
Marco Porsch9bdbf042013-01-07 16:04:51 +010010641 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10642 setup.beacon_interval =
10643 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010644
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010645 err = cfg80211_validate_beacon_int(rdev,
10646 NL80211_IFTYPE_MESH_POINT,
10647 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010648 if (err)
10649 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010650 }
10651
10652 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10653 setup.dtim_period =
10654 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10655 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10656 return -EINVAL;
10657 }
10658
Javier Cardonac80d5452010-12-16 17:37:49 -080010659 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10660 /* parse additional setup parameters if given */
10661 err = nl80211_parse_mesh_setup(info, &setup);
10662 if (err)
10663 return err;
10664 }
10665
Thomas Pedersend37bb182013-03-04 13:06:13 -080010666 if (setup.user_mpm)
10667 cfg.auto_open_plinks = false;
10668
Johannes Bergcc1d2802012-05-16 23:50:20 +020010669 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010670 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10671 if (err)
10672 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010673 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010674 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010675 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010676 }
10677
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010678 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10679 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10680 int n_rates =
10681 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10682 struct ieee80211_supported_band *sband;
10683
10684 if (!setup.chandef.chan)
10685 return -EINVAL;
10686
10687 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10688
10689 err = ieee80211_get_ratemask(sband, rates, n_rates,
10690 &setup.basic_rates);
10691 if (err)
10692 return err;
10693 }
10694
Johannes Berg8564e382016-09-19 09:44:44 +020010695 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10696 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10697 if (err)
10698 return err;
10699
Johannes Berg265698d2017-09-18 22:46:36 +020010700 if (!setup.chandef.chan)
10701 return -EINVAL;
10702
Johannes Berg8564e382016-09-19 09:44:44 +020010703 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10704 &setup.beacon_rate);
10705 if (err)
10706 return err;
10707 }
10708
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010709 setup.userspace_handles_dfs =
10710 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10711
Denis Kenzior1224f582018-03-26 12:52:49 -050010712 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10713 int r = validate_pae_over_nl80211(rdev, info);
10714
10715 if (r < 0)
10716 return r;
10717
10718 setup.control_port_over_nl80211 = true;
10719 }
10720
Denis Kenzior188c1b32018-03-26 12:52:46 -050010721 wdev_lock(dev->ieee80211_ptr);
10722 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10723 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10724 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10725 wdev_unlock(dev->ieee80211_ptr);
10726
10727 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010728}
10729
10730static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10731{
10732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10733 struct net_device *dev = info->user_ptr[1];
10734
10735 return cfg80211_leave_mesh(rdev, dev);
10736}
10737
Johannes Bergdfb89c52012-06-27 09:23:48 +020010738#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010739static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10740 struct cfg80211_registered_device *rdev)
10741{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010742 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010743 struct nlattr *nl_pats, *nl_pat;
10744 int i, pat_len;
10745
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010746 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010747 return 0;
10748
10749 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10750 if (!nl_pats)
10751 return -ENOBUFS;
10752
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010753 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010754 nl_pat = nla_nest_start(msg, i + 1);
10755 if (!nl_pat)
10756 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010757 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010758 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010759 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010760 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10761 wowlan->patterns[i].pattern) ||
10762 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010763 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010764 return -ENOBUFS;
10765 nla_nest_end(msg, nl_pat);
10766 }
10767 nla_nest_end(msg, nl_pats);
10768
10769 return 0;
10770}
10771
Johannes Berg2a0e0472013-01-23 22:57:40 +010010772static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10773 struct cfg80211_wowlan_tcp *tcp)
10774{
10775 struct nlattr *nl_tcp;
10776
10777 if (!tcp)
10778 return 0;
10779
10780 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10781 if (!nl_tcp)
10782 return -ENOBUFS;
10783
Jiri Benc930345e2015-03-29 16:59:25 +020010784 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10785 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010786 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10787 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10788 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10789 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10790 tcp->payload_len, tcp->payload) ||
10791 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10792 tcp->data_interval) ||
10793 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10794 tcp->wake_len, tcp->wake_data) ||
10795 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10796 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10797 return -ENOBUFS;
10798
10799 if (tcp->payload_seq.len &&
10800 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10801 sizeof(tcp->payload_seq), &tcp->payload_seq))
10802 return -ENOBUFS;
10803
10804 if (tcp->payload_tok.len &&
10805 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10806 sizeof(tcp->payload_tok) + tcp->tokens_size,
10807 &tcp->payload_tok))
10808 return -ENOBUFS;
10809
Johannes Berge248ad32013-05-16 10:24:28 +020010810 nla_nest_end(msg, nl_tcp);
10811
Johannes Berg2a0e0472013-01-23 22:57:40 +010010812 return 0;
10813}
10814
Luciano Coelho75453cc2015-01-09 14:06:37 +020010815static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10816 struct cfg80211_sched_scan_request *req)
10817{
Avraham Stern3b06d272015-10-12 09:51:34 +030010818 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010819 int i;
10820
10821 if (!req)
10822 return 0;
10823
10824 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10825 if (!nd)
10826 return -ENOBUFS;
10827
Avraham Stern3b06d272015-10-12 09:51:34 +030010828 if (req->n_scan_plans == 1 &&
10829 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10830 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010831 return -ENOBUFS;
10832
Luciano Coelho21fea562015-03-17 16:36:01 +020010833 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10834 return -ENOBUFS;
10835
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010836 if (req->relative_rssi_set) {
10837 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10838
10839 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10840 req->relative_rssi))
10841 return -ENOBUFS;
10842
10843 rssi_adjust.band = req->rssi_adjust.band;
10844 rssi_adjust.delta = req->rssi_adjust.delta;
10845 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10846 sizeof(rssi_adjust), &rssi_adjust))
10847 return -ENOBUFS;
10848 }
10849
Luciano Coelho75453cc2015-01-09 14:06:37 +020010850 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10851 if (!freqs)
10852 return -ENOBUFS;
10853
Johannes Berg53b18982016-09-14 09:59:21 +020010854 for (i = 0; i < req->n_channels; i++) {
10855 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10856 return -ENOBUFS;
10857 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010858
10859 nla_nest_end(msg, freqs);
10860
10861 if (req->n_match_sets) {
10862 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010863 if (!matches)
10864 return -ENOBUFS;
10865
Luciano Coelho75453cc2015-01-09 14:06:37 +020010866 for (i = 0; i < req->n_match_sets; i++) {
10867 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010868 if (!match)
10869 return -ENOBUFS;
10870
Johannes Berg53b18982016-09-14 09:59:21 +020010871 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10872 req->match_sets[i].ssid.ssid_len,
10873 req->match_sets[i].ssid.ssid))
10874 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010875 nla_nest_end(msg, match);
10876 }
10877 nla_nest_end(msg, matches);
10878 }
10879
Avraham Stern3b06d272015-10-12 09:51:34 +030010880 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10881 if (!scan_plans)
10882 return -ENOBUFS;
10883
10884 for (i = 0; i < req->n_scan_plans; i++) {
10885 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010886 if (!scan_plan)
10887 return -ENOBUFS;
10888
Colin Ian King67626962018-09-06 10:58:44 +010010889 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030010890 req->scan_plans[i].interval) ||
10891 (req->scan_plans[i].iterations &&
10892 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10893 req->scan_plans[i].iterations)))
10894 return -ENOBUFS;
10895 nla_nest_end(msg, scan_plan);
10896 }
10897 nla_nest_end(msg, scan_plans);
10898
Luciano Coelho75453cc2015-01-09 14:06:37 +020010899 nla_nest_end(msg, nd);
10900
10901 return 0;
10902}
10903
Johannes Bergff1b6e62011-05-04 15:37:28 +020010904static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10905{
10906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10907 struct sk_buff *msg;
10908 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010909 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010910
Johannes Berg964dc9e2013-06-03 17:25:34 +020010911 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010912 return -EOPNOTSUPP;
10913
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010914 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010915 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010916 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10917 rdev->wiphy.wowlan_config->tcp->payload_len +
10918 rdev->wiphy.wowlan_config->tcp->wake_len +
10919 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010920 }
10921
10922 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010923 if (!msg)
10924 return -ENOMEM;
10925
Eric W. Biederman15e47302012-09-07 20:12:54 +000010926 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010927 NL80211_CMD_GET_WOWLAN);
10928 if (!hdr)
10929 goto nla_put_failure;
10930
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010931 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010932 struct nlattr *nl_wowlan;
10933
10934 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10935 if (!nl_wowlan)
10936 goto nla_put_failure;
10937
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010938 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010939 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010940 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010941 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010942 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010943 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010944 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010945 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010946 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010947 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010948 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010950 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10952 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010953
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010954 if (nl80211_send_wowlan_patterns(msg, rdev))
10955 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010956
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010957 if (nl80211_send_wowlan_tcp(msg,
10958 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010959 goto nla_put_failure;
10960
Luciano Coelho75453cc2015-01-09 14:06:37 +020010961 if (nl80211_send_wowlan_nd(
10962 msg,
10963 rdev->wiphy.wowlan_config->nd_config))
10964 goto nla_put_failure;
10965
Johannes Bergff1b6e62011-05-04 15:37:28 +020010966 nla_nest_end(msg, nl_wowlan);
10967 }
10968
10969 genlmsg_end(msg, hdr);
10970 return genlmsg_reply(msg, info);
10971
10972nla_put_failure:
10973 nlmsg_free(msg);
10974 return -ENOBUFS;
10975}
10976
Johannes Berg2a0e0472013-01-23 22:57:40 +010010977static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10978 struct nlattr *attr,
10979 struct cfg80211_wowlan *trig)
10980{
10981 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10982 struct cfg80211_wowlan_tcp *cfg;
10983 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10984 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10985 u32 size;
10986 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10987 int err, port;
10988
Johannes Berg964dc9e2013-06-03 17:25:34 +020010989 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010990 return -EINVAL;
10991
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010992 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010993 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010994 if (err)
10995 return err;
10996
10997 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10998 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10999 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11000 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11001 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11002 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11003 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11004 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11005 return -EINVAL;
11006
11007 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011008 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011009 return -EINVAL;
11010
11011 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011012 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011013 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011014 return -EINVAL;
11015
11016 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011017 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011018 return -EINVAL;
11019
11020 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11021 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11022 return -EINVAL;
11023
11024 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11025 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11026
11027 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11028 tokens_size = tokln - sizeof(*tok);
11029
11030 if (!tok->len || tokens_size % tok->len)
11031 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011032 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011033 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011034 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011035 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011036 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011037 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011038 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011039 return -EINVAL;
11040 if (tok->offset + tok->len > data_size)
11041 return -EINVAL;
11042 }
11043
11044 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11045 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011046 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011047 return -EINVAL;
11048 if (seq->len == 0 || seq->len > 4)
11049 return -EINVAL;
11050 if (seq->len + seq->offset > data_size)
11051 return -EINVAL;
11052 }
11053
11054 size = sizeof(*cfg);
11055 size += data_size;
11056 size += wake_size + wake_mask_size;
11057 size += tokens_size;
11058
11059 cfg = kzalloc(size, GFP_KERNEL);
11060 if (!cfg)
11061 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011062 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11063 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011064 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11065 ETH_ALEN);
11066 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11067 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11068 else
11069 port = 0;
11070#ifdef CONFIG_INET
11071 /* allocate a socket and port for it and use it */
11072 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11073 IPPROTO_TCP, &cfg->sock, 1);
11074 if (err) {
11075 kfree(cfg);
11076 return err;
11077 }
11078 if (inet_csk_get_port(cfg->sock->sk, port)) {
11079 sock_release(cfg->sock);
11080 kfree(cfg);
11081 return -EADDRINUSE;
11082 }
11083 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11084#else
11085 if (!port) {
11086 kfree(cfg);
11087 return -EINVAL;
11088 }
11089 cfg->src_port = port;
11090#endif
11091
11092 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11093 cfg->payload_len = data_size;
11094 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11095 memcpy((void *)cfg->payload,
11096 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11097 data_size);
11098 if (seq)
11099 cfg->payload_seq = *seq;
11100 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11101 cfg->wake_len = wake_size;
11102 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11103 memcpy((void *)cfg->wake_data,
11104 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11105 wake_size);
11106 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11107 data_size + wake_size;
11108 memcpy((void *)cfg->wake_mask,
11109 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11110 wake_mask_size);
11111 if (tok) {
11112 cfg->tokens_size = tokens_size;
11113 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11114 }
11115
11116 trig->tcp = cfg;
11117
11118 return 0;
11119}
11120
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011121static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11122 const struct wiphy_wowlan_support *wowlan,
11123 struct nlattr *attr,
11124 struct cfg80211_wowlan *trig)
11125{
11126 struct nlattr **tb;
11127 int err;
11128
Kees Cook6396bb22018-06-12 14:03:40 -070011129 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011130 if (!tb)
11131 return -ENOMEM;
11132
11133 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11134 err = -EOPNOTSUPP;
11135 goto out;
11136 }
11137
Johannes Bergfceb6432017-04-12 14:34:07 +020011138 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
11139 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011140 if (err)
11141 goto out;
11142
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011143 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11144 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011145 err = PTR_ERR_OR_ZERO(trig->nd_config);
11146 if (err)
11147 trig->nd_config = NULL;
11148
11149out:
11150 kfree(tb);
11151 return err;
11152}
11153
Johannes Bergff1b6e62011-05-04 15:37:28 +020011154static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11155{
11156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11157 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011158 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011159 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011160 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011161 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011162 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011163 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011164
Johannes Berg964dc9e2013-06-03 17:25:34 +020011165 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011166 return -EOPNOTSUPP;
11167
Johannes Bergae33bd82012-07-12 16:25:02 +020011168 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11169 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011170 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011171 goto set_wakeup;
11172 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011173
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011174 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
11175 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020011176 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011177 if (err)
11178 return err;
11179
11180 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11181 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11182 return -EINVAL;
11183 new_triggers.any = true;
11184 }
11185
11186 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11187 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11188 return -EINVAL;
11189 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011190 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011191 }
11192
11193 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11194 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11195 return -EINVAL;
11196 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011197 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011198 }
11199
Johannes Berg77dbbb12011-07-13 10:48:55 +020011200 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11201 return -EINVAL;
11202
11203 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11204 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11205 return -EINVAL;
11206 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011207 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011208 }
11209
11210 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11211 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11212 return -EINVAL;
11213 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011214 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011215 }
11216
11217 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11218 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11219 return -EINVAL;
11220 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011221 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011222 }
11223
11224 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11225 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11226 return -EINVAL;
11227 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011228 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011229 }
11230
Johannes Bergff1b6e62011-05-04 15:37:28 +020011231 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11232 struct nlattr *pat;
11233 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011234 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011235 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011236
Johannes Berg98fc4382015-03-01 09:10:13 +020011237 regular = true;
11238
Johannes Bergff1b6e62011-05-04 15:37:28 +020011239 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11240 rem)
11241 n_patterns++;
11242 if (n_patterns > wowlan->n_patterns)
11243 return -EINVAL;
11244
11245 new_triggers.patterns = kcalloc(n_patterns,
11246 sizeof(new_triggers.patterns[0]),
11247 GFP_KERNEL);
11248 if (!new_triggers.patterns)
11249 return -ENOMEM;
11250
11251 new_triggers.n_patterns = n_patterns;
11252 i = 0;
11253
11254 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11255 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011256 u8 *mask_pat;
11257
Johannes Berg95bca622018-06-29 09:33:39 +020011258 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11259 nl80211_packet_pattern_policy,
11260 info->extack);
11261 if (err)
11262 goto error;
11263
Johannes Bergff1b6e62011-05-04 15:37:28 +020011264 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011265 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11266 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011267 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011268 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011269 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011270 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011271 goto error;
11272 if (pat_len > wowlan->pattern_max_len ||
11273 pat_len < wowlan->pattern_min_len)
11274 goto error;
11275
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011276 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011277 pkt_offset = 0;
11278 else
11279 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011280 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011281 if (pkt_offset > wowlan->max_pkt_offset)
11282 goto error;
11283 new_triggers.patterns[i].pkt_offset = pkt_offset;
11284
Johannes Berg922bd802014-05-19 17:59:50 +020011285 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11286 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011287 err = -ENOMEM;
11288 goto error;
11289 }
Johannes Berg922bd802014-05-19 17:59:50 +020011290 new_triggers.patterns[i].mask = mask_pat;
11291 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011292 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011293 mask_pat += mask_len;
11294 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011295 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011296 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011297 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011298 pat_len);
11299 i++;
11300 }
11301 }
11302
Johannes Berg2a0e0472013-01-23 22:57:40 +010011303 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011304 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011305 err = nl80211_parse_wowlan_tcp(
11306 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11307 &new_triggers);
11308 if (err)
11309 goto error;
11310 }
11311
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011312 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011313 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011314 err = nl80211_parse_wowlan_nd(
11315 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11316 &new_triggers);
11317 if (err)
11318 goto error;
11319 }
11320
Johannes Berg98fc4382015-03-01 09:10:13 +020011321 /* The 'any' trigger means the device continues operating more or less
11322 * as in its normal operation mode and wakes up the host on most of the
11323 * normal interrupts (like packet RX, ...)
11324 * It therefore makes little sense to combine with the more constrained
11325 * wakeup trigger modes.
11326 */
11327 if (new_triggers.any && regular) {
11328 err = -EINVAL;
11329 goto error;
11330 }
11331
Johannes Bergae33bd82012-07-12 16:25:02 +020011332 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11333 if (!ntrig) {
11334 err = -ENOMEM;
11335 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011336 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011337 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011338 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011339
Johannes Bergae33bd82012-07-12 16:25:02 +020011340 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011341 if (rdev->ops->set_wakeup &&
11342 prev_enabled != !!rdev->wiphy.wowlan_config)
11343 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011344
Johannes Bergff1b6e62011-05-04 15:37:28 +020011345 return 0;
11346 error:
11347 for (i = 0; i < new_triggers.n_patterns; i++)
11348 kfree(new_triggers.patterns[i].mask);
11349 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011350 if (new_triggers.tcp && new_triggers.tcp->sock)
11351 sock_release(new_triggers.tcp->sock);
11352 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011353 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011354 return err;
11355}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011356#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011357
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011358static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11359 struct cfg80211_registered_device *rdev)
11360{
11361 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11362 int i, j, pat_len;
11363 struct cfg80211_coalesce_rules *rule;
11364
11365 if (!rdev->coalesce->n_rules)
11366 return 0;
11367
11368 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
11369 if (!nl_rules)
11370 return -ENOBUFS;
11371
11372 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11373 nl_rule = nla_nest_start(msg, i + 1);
11374 if (!nl_rule)
11375 return -ENOBUFS;
11376
11377 rule = &rdev->coalesce->rules[i];
11378 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11379 rule->delay))
11380 return -ENOBUFS;
11381
11382 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11383 rule->condition))
11384 return -ENOBUFS;
11385
11386 nl_pats = nla_nest_start(msg,
11387 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11388 if (!nl_pats)
11389 return -ENOBUFS;
11390
11391 for (j = 0; j < rule->n_patterns; j++) {
11392 nl_pat = nla_nest_start(msg, j + 1);
11393 if (!nl_pat)
11394 return -ENOBUFS;
11395 pat_len = rule->patterns[j].pattern_len;
11396 if (nla_put(msg, NL80211_PKTPAT_MASK,
11397 DIV_ROUND_UP(pat_len, 8),
11398 rule->patterns[j].mask) ||
11399 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11400 rule->patterns[j].pattern) ||
11401 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11402 rule->patterns[j].pkt_offset))
11403 return -ENOBUFS;
11404 nla_nest_end(msg, nl_pat);
11405 }
11406 nla_nest_end(msg, nl_pats);
11407 nla_nest_end(msg, nl_rule);
11408 }
11409 nla_nest_end(msg, nl_rules);
11410
11411 return 0;
11412}
11413
11414static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11415{
11416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11417 struct sk_buff *msg;
11418 void *hdr;
11419
11420 if (!rdev->wiphy.coalesce)
11421 return -EOPNOTSUPP;
11422
11423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11424 if (!msg)
11425 return -ENOMEM;
11426
11427 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11428 NL80211_CMD_GET_COALESCE);
11429 if (!hdr)
11430 goto nla_put_failure;
11431
11432 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11433 goto nla_put_failure;
11434
11435 genlmsg_end(msg, hdr);
11436 return genlmsg_reply(msg, info);
11437
11438nla_put_failure:
11439 nlmsg_free(msg);
11440 return -ENOBUFS;
11441}
11442
11443void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11444{
11445 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11446 int i, j;
11447 struct cfg80211_coalesce_rules *rule;
11448
11449 if (!coalesce)
11450 return;
11451
11452 for (i = 0; i < coalesce->n_rules; i++) {
11453 rule = &coalesce->rules[i];
11454 for (j = 0; j < rule->n_patterns; j++)
11455 kfree(rule->patterns[j].mask);
11456 kfree(rule->patterns);
11457 }
11458 kfree(coalesce->rules);
11459 kfree(coalesce);
11460 rdev->coalesce = NULL;
11461}
11462
11463static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11464 struct nlattr *rule,
11465 struct cfg80211_coalesce_rules *new_rule)
11466{
11467 int err, i;
11468 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11469 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11470 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11471 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11472
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011473 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020011474 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011475 if (err)
11476 return err;
11477
11478 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11479 new_rule->delay =
11480 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11481 if (new_rule->delay > coalesce->max_delay)
11482 return -EINVAL;
11483
11484 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11485 new_rule->condition =
11486 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011487
11488 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11489 return -EINVAL;
11490
11491 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11492 rem)
11493 n_patterns++;
11494 if (n_patterns > coalesce->n_patterns)
11495 return -EINVAL;
11496
11497 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11498 GFP_KERNEL);
11499 if (!new_rule->patterns)
11500 return -ENOMEM;
11501
11502 new_rule->n_patterns = n_patterns;
11503 i = 0;
11504
11505 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11506 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011507 u8 *mask_pat;
11508
Johannes Berg95bca622018-06-29 09:33:39 +020011509 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11510 nl80211_packet_pattern_policy, NULL);
11511 if (err)
11512 return err;
11513
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011514 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11515 !pat_tb[NL80211_PKTPAT_PATTERN])
11516 return -EINVAL;
11517 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11518 mask_len = DIV_ROUND_UP(pat_len, 8);
11519 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11520 return -EINVAL;
11521 if (pat_len > coalesce->pattern_max_len ||
11522 pat_len < coalesce->pattern_min_len)
11523 return -EINVAL;
11524
11525 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11526 pkt_offset = 0;
11527 else
11528 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11529 if (pkt_offset > coalesce->max_pkt_offset)
11530 return -EINVAL;
11531 new_rule->patterns[i].pkt_offset = pkt_offset;
11532
Johannes Berg922bd802014-05-19 17:59:50 +020011533 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11534 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011535 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011536
11537 new_rule->patterns[i].mask = mask_pat;
11538 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11539 mask_len);
11540
11541 mask_pat += mask_len;
11542 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011543 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011544 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11545 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011546 i++;
11547 }
11548
11549 return 0;
11550}
11551
11552static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11553{
11554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11555 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11556 struct cfg80211_coalesce new_coalesce = {};
11557 struct cfg80211_coalesce *n_coalesce;
11558 int err, rem_rule, n_rules = 0, i, j;
11559 struct nlattr *rule;
11560 struct cfg80211_coalesce_rules *tmp_rule;
11561
11562 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11563 return -EOPNOTSUPP;
11564
11565 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11566 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011567 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011568 return 0;
11569 }
11570
11571 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11572 rem_rule)
11573 n_rules++;
11574 if (n_rules > coalesce->n_rules)
11575 return -EINVAL;
11576
11577 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11578 GFP_KERNEL);
11579 if (!new_coalesce.rules)
11580 return -ENOMEM;
11581
11582 new_coalesce.n_rules = n_rules;
11583 i = 0;
11584
11585 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11586 rem_rule) {
11587 err = nl80211_parse_coalesce_rule(rdev, rule,
11588 &new_coalesce.rules[i]);
11589 if (err)
11590 goto error;
11591
11592 i++;
11593 }
11594
Ilan Peera1056b1b2015-10-22 22:27:46 +030011595 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011596 if (err)
11597 goto error;
11598
11599 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11600 if (!n_coalesce) {
11601 err = -ENOMEM;
11602 goto error;
11603 }
11604 cfg80211_rdev_free_coalesce(rdev);
11605 rdev->coalesce = n_coalesce;
11606
11607 return 0;
11608error:
11609 for (i = 0; i < new_coalesce.n_rules; i++) {
11610 tmp_rule = &new_coalesce.rules[i];
11611 for (j = 0; j < tmp_rule->n_patterns; j++)
11612 kfree(tmp_rule->patterns[j].mask);
11613 kfree(tmp_rule->patterns);
11614 }
11615 kfree(new_coalesce.rules);
11616
11617 return err;
11618}
11619
Johannes Berge5497d72011-07-05 16:35:40 +020011620static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11621{
11622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11623 struct net_device *dev = info->user_ptr[1];
11624 struct wireless_dev *wdev = dev->ieee80211_ptr;
11625 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11626 struct cfg80211_gtk_rekey_data rekey_data;
11627 int err;
11628
11629 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11630 return -EINVAL;
11631
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011632 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
11633 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020011634 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011635 if (err)
11636 return err;
11637
Vladis Dronove785fa02017-09-13 00:21:21 +020011638 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11639 !tb[NL80211_REKEY_DATA_KCK])
11640 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011641 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11642 return -ERANGE;
11643 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11644 return -ERANGE;
11645 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11646 return -ERANGE;
11647
Johannes Berg78f686c2014-09-10 22:28:06 +030011648 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11649 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11650 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011651
11652 wdev_lock(wdev);
11653 if (!wdev->current_bss) {
11654 err = -ENOTCONN;
11655 goto out;
11656 }
11657
11658 if (!rdev->ops->set_rekey_data) {
11659 err = -EOPNOTSUPP;
11660 goto out;
11661 }
11662
Hila Gonene35e4d22012-06-27 17:19:42 +030011663 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011664 out:
11665 wdev_unlock(wdev);
11666 return err;
11667}
11668
Johannes Berg28946da2011-11-04 11:18:12 +010011669static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11670 struct genl_info *info)
11671{
11672 struct net_device *dev = info->user_ptr[1];
11673 struct wireless_dev *wdev = dev->ieee80211_ptr;
11674
11675 if (wdev->iftype != NL80211_IFTYPE_AP &&
11676 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11677 return -EINVAL;
11678
Eric W. Biederman15e47302012-09-07 20:12:54 +000011679 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011680 return -EBUSY;
11681
Eric W. Biederman15e47302012-09-07 20:12:54 +000011682 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011683 return 0;
11684}
11685
Johannes Berg7f6cf312011-11-04 11:18:15 +010011686static int nl80211_probe_client(struct sk_buff *skb,
11687 struct genl_info *info)
11688{
11689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11690 struct net_device *dev = info->user_ptr[1];
11691 struct wireless_dev *wdev = dev->ieee80211_ptr;
11692 struct sk_buff *msg;
11693 void *hdr;
11694 const u8 *addr;
11695 u64 cookie;
11696 int err;
11697
11698 if (wdev->iftype != NL80211_IFTYPE_AP &&
11699 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11700 return -EOPNOTSUPP;
11701
11702 if (!info->attrs[NL80211_ATTR_MAC])
11703 return -EINVAL;
11704
11705 if (!rdev->ops->probe_client)
11706 return -EOPNOTSUPP;
11707
11708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11709 if (!msg)
11710 return -ENOMEM;
11711
Eric W. Biederman15e47302012-09-07 20:12:54 +000011712 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011713 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011714 if (!hdr) {
11715 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011716 goto free_msg;
11717 }
11718
11719 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11720
Hila Gonene35e4d22012-06-27 17:19:42 +030011721 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011722 if (err)
11723 goto free_msg;
11724
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011725 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11726 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011727 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011728
11729 genlmsg_end(msg, hdr);
11730
11731 return genlmsg_reply(msg, info);
11732
11733 nla_put_failure:
11734 err = -ENOBUFS;
11735 free_msg:
11736 nlmsg_free(msg);
11737 return err;
11738}
11739
Johannes Berg5e760232011-11-04 11:18:17 +010011740static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11741{
11742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011743 struct cfg80211_beacon_registration *reg, *nreg;
11744 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011745
11746 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11747 return -EOPNOTSUPP;
11748
Ben Greear37c73b52012-10-26 14:49:25 -070011749 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11750 if (!nreg)
11751 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011752
Ben Greear37c73b52012-10-26 14:49:25 -070011753 /* First, check if already registered. */
11754 spin_lock_bh(&rdev->beacon_registrations_lock);
11755 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11756 if (reg->nlportid == info->snd_portid) {
11757 rv = -EALREADY;
11758 goto out_err;
11759 }
11760 }
11761 /* Add it to the list */
11762 nreg->nlportid = info->snd_portid;
11763 list_add(&nreg->list, &rdev->beacon_registrations);
11764
11765 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011766
11767 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011768out_err:
11769 spin_unlock_bh(&rdev->beacon_registrations_lock);
11770 kfree(nreg);
11771 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011772}
11773
Johannes Berg98104fde2012-06-16 00:19:54 +020011774static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11775{
11776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11777 struct wireless_dev *wdev = info->user_ptr[1];
11778 int err;
11779
11780 if (!rdev->ops->start_p2p_device)
11781 return -EOPNOTSUPP;
11782
11783 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11784 return -EOPNOTSUPP;
11785
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011786 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011787 return 0;
11788
Luciano Coelhob6a55012014-02-27 11:07:21 +020011789 if (rfkill_blocked(rdev->rfkill))
11790 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011791
Johannes Bergeeb126e2012-10-23 15:16:50 +020011792 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011793 if (err)
11794 return err;
11795
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011796 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011797 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011798
11799 return 0;
11800}
11801
11802static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11803{
11804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11805 struct wireless_dev *wdev = info->user_ptr[1];
11806
11807 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11808 return -EOPNOTSUPP;
11809
11810 if (!rdev->ops->stop_p2p_device)
11811 return -EOPNOTSUPP;
11812
Johannes Bergf9f47522013-03-19 15:04:07 +010011813 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011814
11815 return 0;
11816}
11817
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011818static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11819{
11820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11821 struct wireless_dev *wdev = info->user_ptr[1];
11822 struct cfg80211_nan_conf conf = {};
11823 int err;
11824
11825 if (wdev->iftype != NL80211_IFTYPE_NAN)
11826 return -EOPNOTSUPP;
11827
Johannes Bergeeb04a92016-11-21 13:55:48 +010011828 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011829 return -EEXIST;
11830
11831 if (rfkill_blocked(rdev->rfkill))
11832 return -ERFKILL;
11833
11834 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11835 return -EINVAL;
11836
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011837 conf.master_pref =
11838 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011839
Luca Coelho85859892017-02-08 15:00:34 +020011840 if (info->attrs[NL80211_ATTR_BANDS]) {
11841 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11842
11843 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11844 return -EOPNOTSUPP;
11845
11846 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11847 return -EINVAL;
11848
11849 conf.bands = bands;
11850 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011851
11852 err = rdev_start_nan(rdev, wdev, &conf);
11853 if (err)
11854 return err;
11855
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011856 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011857 rdev->opencount++;
11858
11859 return 0;
11860}
11861
11862static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11863{
11864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11865 struct wireless_dev *wdev = info->user_ptr[1];
11866
11867 if (wdev->iftype != NL80211_IFTYPE_NAN)
11868 return -EOPNOTSUPP;
11869
11870 cfg80211_stop_nan(rdev, wdev);
11871
11872 return 0;
11873}
11874
Ayala Bekera442b762016-09-20 17:31:15 +030011875static int validate_nan_filter(struct nlattr *filter_attr)
11876{
11877 struct nlattr *attr;
11878 int len = 0, n_entries = 0, rem;
11879
11880 nla_for_each_nested(attr, filter_attr, rem) {
11881 len += nla_len(attr);
11882 n_entries++;
11883 }
11884
11885 if (len >= U8_MAX)
11886 return -EINVAL;
11887
11888 return n_entries;
11889}
11890
11891static int handle_nan_filter(struct nlattr *attr_filter,
11892 struct cfg80211_nan_func *func,
11893 bool tx)
11894{
11895 struct nlattr *attr;
11896 int n_entries, rem, i;
11897 struct cfg80211_nan_func_filter *filter;
11898
11899 n_entries = validate_nan_filter(attr_filter);
11900 if (n_entries < 0)
11901 return n_entries;
11902
11903 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11904
11905 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11906 if (!filter)
11907 return -ENOMEM;
11908
11909 i = 0;
11910 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011911 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011912 filter[i].len = nla_len(attr);
11913 i++;
11914 }
11915 if (tx) {
11916 func->num_tx_filters = n_entries;
11917 func->tx_filters = filter;
11918 } else {
11919 func->num_rx_filters = n_entries;
11920 func->rx_filters = filter;
11921 }
11922
11923 return 0;
11924}
11925
11926static int nl80211_nan_add_func(struct sk_buff *skb,
11927 struct genl_info *info)
11928{
11929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11930 struct wireless_dev *wdev = info->user_ptr[1];
11931 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11932 struct cfg80211_nan_func *func;
11933 struct sk_buff *msg = NULL;
11934 void *hdr = NULL;
11935 int err = 0;
11936
11937 if (wdev->iftype != NL80211_IFTYPE_NAN)
11938 return -EOPNOTSUPP;
11939
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011940 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011941 return -ENOTCONN;
11942
11943 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11944 return -EINVAL;
11945
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011946 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11947 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011948 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011949 if (err)
11950 return err;
11951
11952 func = kzalloc(sizeof(*func), GFP_KERNEL);
11953 if (!func)
11954 return -ENOMEM;
11955
Johannes Bergb60ad342018-10-01 11:52:07 +020011956 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030011957
11958 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11959 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11960 err = -EINVAL;
11961 goto out;
11962 }
11963
11964
11965 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11966
11967 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11968 err = -EINVAL;
11969 goto out;
11970 }
11971
11972 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11973 sizeof(func->service_id));
11974
11975 func->close_range =
11976 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11977
11978 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11979 func->serv_spec_info_len =
11980 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11981 func->serv_spec_info =
11982 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11983 func->serv_spec_info_len,
11984 GFP_KERNEL);
11985 if (!func->serv_spec_info) {
11986 err = -ENOMEM;
11987 goto out;
11988 }
11989 }
11990
11991 if (tb[NL80211_NAN_FUNC_TTL])
11992 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11993
11994 switch (func->type) {
11995 case NL80211_NAN_FUNC_PUBLISH:
11996 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11997 err = -EINVAL;
11998 goto out;
11999 }
12000
12001 func->publish_type =
12002 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12003 func->publish_bcast =
12004 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12005
12006 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12007 func->publish_bcast) {
12008 err = -EINVAL;
12009 goto out;
12010 }
12011 break;
12012 case NL80211_NAN_FUNC_SUBSCRIBE:
12013 func->subscribe_active =
12014 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12015 break;
12016 case NL80211_NAN_FUNC_FOLLOW_UP:
12017 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012018 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12019 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012020 err = -EINVAL;
12021 goto out;
12022 }
12023
12024 func->followup_id =
12025 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12026 func->followup_reqid =
12027 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12028 memcpy(func->followup_dest.addr,
12029 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12030 sizeof(func->followup_dest.addr));
12031 if (func->ttl) {
12032 err = -EINVAL;
12033 goto out;
12034 }
12035 break;
12036 default:
12037 err = -EINVAL;
12038 goto out;
12039 }
12040
12041 if (tb[NL80211_NAN_FUNC_SRF]) {
12042 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12043
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020012044 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
12045 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020012046 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012047 if (err)
12048 goto out;
12049
12050 func->srf_include =
12051 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12052
12053 if (srf_tb[NL80211_NAN_SRF_BF]) {
12054 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12055 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12056 err = -EINVAL;
12057 goto out;
12058 }
12059
12060 func->srf_bf_len =
12061 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12062 func->srf_bf =
12063 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12064 func->srf_bf_len, GFP_KERNEL);
12065 if (!func->srf_bf) {
12066 err = -ENOMEM;
12067 goto out;
12068 }
12069
12070 func->srf_bf_idx =
12071 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12072 } else {
12073 struct nlattr *attr, *mac_attr =
12074 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12075 int n_entries, rem, i = 0;
12076
12077 if (!mac_attr) {
12078 err = -EINVAL;
12079 goto out;
12080 }
12081
12082 n_entries = validate_acl_mac_addrs(mac_attr);
12083 if (n_entries <= 0) {
12084 err = -EINVAL;
12085 goto out;
12086 }
12087
12088 func->srf_num_macs = n_entries;
12089 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012090 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012091 GFP_KERNEL);
12092 if (!func->srf_macs) {
12093 err = -ENOMEM;
12094 goto out;
12095 }
12096
12097 nla_for_each_nested(attr, mac_attr, rem)
12098 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12099 sizeof(*func->srf_macs));
12100 }
12101 }
12102
12103 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12104 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12105 func, true);
12106 if (err)
12107 goto out;
12108 }
12109
12110 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12111 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12112 func, false);
12113 if (err)
12114 goto out;
12115 }
12116
12117 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12118 if (!msg) {
12119 err = -ENOMEM;
12120 goto out;
12121 }
12122
12123 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12124 NL80211_CMD_ADD_NAN_FUNCTION);
12125 /* This can't really happen - we just allocated 4KB */
12126 if (WARN_ON(!hdr)) {
12127 err = -ENOMEM;
12128 goto out;
12129 }
12130
12131 err = rdev_add_nan_func(rdev, wdev, func);
12132out:
12133 if (err < 0) {
12134 cfg80211_free_nan_func(func);
12135 nlmsg_free(msg);
12136 return err;
12137 }
12138
12139 /* propagate the instance id and cookie to userspace */
12140 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12141 NL80211_ATTR_PAD))
12142 goto nla_put_failure;
12143
12144 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
12145 if (!func_attr)
12146 goto nla_put_failure;
12147
12148 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12149 func->instance_id))
12150 goto nla_put_failure;
12151
12152 nla_nest_end(msg, func_attr);
12153
12154 genlmsg_end(msg, hdr);
12155 return genlmsg_reply(msg, info);
12156
12157nla_put_failure:
12158 nlmsg_free(msg);
12159 return -ENOBUFS;
12160}
12161
12162static int nl80211_nan_del_func(struct sk_buff *skb,
12163 struct genl_info *info)
12164{
12165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12166 struct wireless_dev *wdev = info->user_ptr[1];
12167 u64 cookie;
12168
12169 if (wdev->iftype != NL80211_IFTYPE_NAN)
12170 return -EOPNOTSUPP;
12171
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012172 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012173 return -ENOTCONN;
12174
12175 if (!info->attrs[NL80211_ATTR_COOKIE])
12176 return -EINVAL;
12177
Ayala Bekera442b762016-09-20 17:31:15 +030012178 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12179
12180 rdev_del_nan_func(rdev, wdev, cookie);
12181
12182 return 0;
12183}
12184
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012185static int nl80211_nan_change_config(struct sk_buff *skb,
12186 struct genl_info *info)
12187{
12188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12189 struct wireless_dev *wdev = info->user_ptr[1];
12190 struct cfg80211_nan_conf conf = {};
12191 u32 changed = 0;
12192
12193 if (wdev->iftype != NL80211_IFTYPE_NAN)
12194 return -EOPNOTSUPP;
12195
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012196 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012197 return -ENOTCONN;
12198
12199 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12200 conf.master_pref =
12201 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12202 if (conf.master_pref <= 1 || conf.master_pref == 255)
12203 return -EINVAL;
12204
12205 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12206 }
12207
Luca Coelho85859892017-02-08 15:00:34 +020012208 if (info->attrs[NL80211_ATTR_BANDS]) {
12209 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12210
12211 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12212 return -EOPNOTSUPP;
12213
12214 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12215 return -EINVAL;
12216
12217 conf.bands = bands;
12218 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012219 }
12220
12221 if (!changed)
12222 return -EINVAL;
12223
12224 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12225}
12226
Ayala Beker50bcd312016-09-20 17:31:17 +030012227void cfg80211_nan_match(struct wireless_dev *wdev,
12228 struct cfg80211_nan_match_params *match, gfp_t gfp)
12229{
12230 struct wiphy *wiphy = wdev->wiphy;
12231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12232 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12233 struct sk_buff *msg;
12234 void *hdr;
12235
12236 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12237 return;
12238
12239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12240 if (!msg)
12241 return;
12242
12243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12244 if (!hdr) {
12245 nlmsg_free(msg);
12246 return;
12247 }
12248
12249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12250 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12251 wdev->netdev->ifindex)) ||
12252 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12253 NL80211_ATTR_PAD))
12254 goto nla_put_failure;
12255
12256 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12257 NL80211_ATTR_PAD) ||
12258 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12259 goto nla_put_failure;
12260
12261 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
12262 if (!match_attr)
12263 goto nla_put_failure;
12264
12265 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
12266 if (!local_func_attr)
12267 goto nla_put_failure;
12268
12269 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12270 goto nla_put_failure;
12271
12272 nla_nest_end(msg, local_func_attr);
12273
12274 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
12275 if (!peer_func_attr)
12276 goto nla_put_failure;
12277
12278 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12279 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12280 goto nla_put_failure;
12281
12282 if (match->info && match->info_len &&
12283 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12284 match->info))
12285 goto nla_put_failure;
12286
12287 nla_nest_end(msg, peer_func_attr);
12288 nla_nest_end(msg, match_attr);
12289 genlmsg_end(msg, hdr);
12290
12291 if (!wdev->owner_nlportid)
12292 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12293 msg, 0, NL80211_MCGRP_NAN, gfp);
12294 else
12295 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12296 wdev->owner_nlportid);
12297
12298 return;
12299
12300nla_put_failure:
12301 nlmsg_free(msg);
12302}
12303EXPORT_SYMBOL(cfg80211_nan_match);
12304
Ayala Beker368e5a72016-09-20 17:31:18 +030012305void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12306 u8 inst_id,
12307 enum nl80211_nan_func_term_reason reason,
12308 u64 cookie, gfp_t gfp)
12309{
12310 struct wiphy *wiphy = wdev->wiphy;
12311 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12312 struct sk_buff *msg;
12313 struct nlattr *func_attr;
12314 void *hdr;
12315
12316 if (WARN_ON(!inst_id))
12317 return;
12318
12319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12320 if (!msg)
12321 return;
12322
12323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12324 if (!hdr) {
12325 nlmsg_free(msg);
12326 return;
12327 }
12328
12329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12330 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12331 wdev->netdev->ifindex)) ||
12332 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12333 NL80211_ATTR_PAD))
12334 goto nla_put_failure;
12335
12336 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12337 NL80211_ATTR_PAD))
12338 goto nla_put_failure;
12339
12340 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
12341 if (!func_attr)
12342 goto nla_put_failure;
12343
12344 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12345 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12346 goto nla_put_failure;
12347
12348 nla_nest_end(msg, func_attr);
12349 genlmsg_end(msg, hdr);
12350
12351 if (!wdev->owner_nlportid)
12352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12353 msg, 0, NL80211_MCGRP_NAN, gfp);
12354 else
12355 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12356 wdev->owner_nlportid);
12357
12358 return;
12359
12360nla_put_failure:
12361 nlmsg_free(msg);
12362}
12363EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12364
Johannes Berg3713b4e2013-02-14 16:19:38 +010012365static int nl80211_get_protocol_features(struct sk_buff *skb,
12366 struct genl_info *info)
12367{
12368 void *hdr;
12369 struct sk_buff *msg;
12370
12371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12372 if (!msg)
12373 return -ENOMEM;
12374
12375 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12376 NL80211_CMD_GET_PROTOCOL_FEATURES);
12377 if (!hdr)
12378 goto nla_put_failure;
12379
12380 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12381 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12382 goto nla_put_failure;
12383
12384 genlmsg_end(msg, hdr);
12385 return genlmsg_reply(msg, info);
12386
12387 nla_put_failure:
12388 kfree_skb(msg);
12389 return -ENOBUFS;
12390}
12391
Jouni Malinen355199e2013-02-27 17:14:27 +020012392static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12393{
12394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12395 struct cfg80211_update_ft_ies_params ft_params;
12396 struct net_device *dev = info->user_ptr[1];
12397
12398 if (!rdev->ops->update_ft_ies)
12399 return -EOPNOTSUPP;
12400
12401 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012402 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012403 return -EINVAL;
12404
12405 memset(&ft_params, 0, sizeof(ft_params));
12406 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12407 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12408 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12409
12410 return rdev_update_ft_ies(rdev, dev, &ft_params);
12411}
12412
Arend van Spriel5de17982013-04-18 15:49:00 +020012413static int nl80211_crit_protocol_start(struct sk_buff *skb,
12414 struct genl_info *info)
12415{
12416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12417 struct wireless_dev *wdev = info->user_ptr[1];
12418 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12419 u16 duration;
12420 int ret;
12421
12422 if (!rdev->ops->crit_proto_start)
12423 return -EOPNOTSUPP;
12424
12425 if (WARN_ON(!rdev->ops->crit_proto_stop))
12426 return -EINVAL;
12427
12428 if (rdev->crit_proto_nlportid)
12429 return -EBUSY;
12430
12431 /* determine protocol if provided */
12432 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12433 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12434
12435 if (proto >= NUM_NL80211_CRIT_PROTO)
12436 return -EINVAL;
12437
12438 /* timeout must be provided */
12439 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12440 return -EINVAL;
12441
12442 duration =
12443 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12444
12445 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12446 return -ERANGE;
12447
12448 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12449 if (!ret)
12450 rdev->crit_proto_nlportid = info->snd_portid;
12451
12452 return ret;
12453}
12454
12455static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12456 struct genl_info *info)
12457{
12458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12459 struct wireless_dev *wdev = info->user_ptr[1];
12460
12461 if (!rdev->ops->crit_proto_stop)
12462 return -EOPNOTSUPP;
12463
12464 if (rdev->crit_proto_nlportid) {
12465 rdev->crit_proto_nlportid = 0;
12466 rdev_crit_proto_stop(rdev, wdev);
12467 }
12468 return 0;
12469}
12470
Johannes Bergad7e7182013-11-13 13:37:47 +010012471static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12472{
12473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12474 struct wireless_dev *wdev =
12475 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12476 int i, err;
12477 u32 vid, subcmd;
12478
12479 if (!rdev->wiphy.vendor_commands)
12480 return -EOPNOTSUPP;
12481
12482 if (IS_ERR(wdev)) {
12483 err = PTR_ERR(wdev);
12484 if (err != -EINVAL)
12485 return err;
12486 wdev = NULL;
12487 } else if (wdev->wiphy != &rdev->wiphy) {
12488 return -EINVAL;
12489 }
12490
12491 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12492 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12493 return -EINVAL;
12494
12495 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12496 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12497 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12498 const struct wiphy_vendor_command *vcmd;
12499 void *data = NULL;
12500 int len = 0;
12501
12502 vcmd = &rdev->wiphy.vendor_commands[i];
12503
12504 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12505 continue;
12506
12507 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12508 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12509 if (!wdev)
12510 return -EINVAL;
12511 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12512 !wdev->netdev)
12513 return -EINVAL;
12514
12515 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012516 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012517 return -ENETDOWN;
12518 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012519
12520 if (!vcmd->doit)
12521 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012522 } else {
12523 wdev = NULL;
12524 }
12525
12526 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12527 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12528 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12529 }
12530
12531 rdev->cur_cmd_info = info;
12532 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
12533 data, len);
12534 rdev->cur_cmd_info = NULL;
12535 return err;
12536 }
12537
12538 return -EOPNOTSUPP;
12539}
12540
Johannes Berg7bdbe402015-08-15 22:39:49 +030012541static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12542 struct netlink_callback *cb,
12543 struct cfg80211_registered_device **rdev,
12544 struct wireless_dev **wdev)
12545{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012546 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012547 u32 vid, subcmd;
12548 unsigned int i;
12549 int vcmd_idx = -1;
12550 int err;
12551 void *data = NULL;
12552 unsigned int data_len = 0;
12553
Johannes Berg7bdbe402015-08-15 22:39:49 +030012554 if (cb->args[0]) {
12555 /* subtract the 1 again here */
12556 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12557 struct wireless_dev *tmp;
12558
Johannes Bergea90e0d2017-03-15 14:26:04 +010012559 if (!wiphy)
12560 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012561 *rdev = wiphy_to_rdev(wiphy);
12562 *wdev = NULL;
12563
12564 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012565 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012566 if (tmp->identifier == cb->args[1] - 1) {
12567 *wdev = tmp;
12568 break;
12569 }
12570 }
12571 }
12572
12573 /* keep rtnl locked in successful case */
12574 return 0;
12575 }
12576
Johannes Bergfceb6432017-04-12 14:34:07 +020012577 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
12578 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012579 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012580 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012581
Johannes Bergc90c39d2016-10-24 14:40:01 +020012582 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012583 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12584 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012585
Johannes Bergc90c39d2016-10-24 14:40:01 +020012586 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012587 if (IS_ERR(*wdev))
12588 *wdev = NULL;
12589
Johannes Bergc90c39d2016-10-24 14:40:01 +020012590 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012591 if (IS_ERR(*rdev))
12592 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012593
Johannes Bergc90c39d2016-10-24 14:40:01 +020012594 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12595 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012596
12597 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12598 const struct wiphy_vendor_command *vcmd;
12599
12600 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12601
12602 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12603 continue;
12604
Johannes Bergea90e0d2017-03-15 14:26:04 +010012605 if (!vcmd->dumpit)
12606 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012607
12608 vcmd_idx = i;
12609 break;
12610 }
12611
Johannes Bergea90e0d2017-03-15 14:26:04 +010012612 if (vcmd_idx < 0)
12613 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012614
Johannes Bergc90c39d2016-10-24 14:40:01 +020012615 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12616 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12617 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012618 }
12619
12620 /* 0 is the first index - add 1 to parse only once */
12621 cb->args[0] = (*rdev)->wiphy_idx + 1;
12622 /* add 1 to know if it was NULL */
12623 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12624 cb->args[2] = vcmd_idx;
12625 cb->args[3] = (unsigned long)data;
12626 cb->args[4] = data_len;
12627
12628 /* keep rtnl locked in successful case */
12629 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012630}
12631
12632static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12633 struct netlink_callback *cb)
12634{
12635 struct cfg80211_registered_device *rdev;
12636 struct wireless_dev *wdev;
12637 unsigned int vcmd_idx;
12638 const struct wiphy_vendor_command *vcmd;
12639 void *data;
12640 int data_len;
12641 int err;
12642 struct nlattr *vendor_data;
12643
Johannes Bergea90e0d2017-03-15 14:26:04 +010012644 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012645 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12646 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012647 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012648
12649 vcmd_idx = cb->args[2];
12650 data = (void *)cb->args[3];
12651 data_len = cb->args[4];
12652 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12653
12654 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12655 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012656 if (!wdev) {
12657 err = -EINVAL;
12658 goto out;
12659 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012660 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012661 !wdev->netdev) {
12662 err = -EINVAL;
12663 goto out;
12664 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012665
12666 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012667 if (!wdev_running(wdev)) {
12668 err = -ENETDOWN;
12669 goto out;
12670 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012671 }
12672 }
12673
12674 while (1) {
12675 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12676 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12677 NL80211_CMD_VENDOR);
12678 if (!hdr)
12679 break;
12680
12681 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012682 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12683 wdev_id(wdev),
12684 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012685 genlmsg_cancel(skb, hdr);
12686 break;
12687 }
12688
12689 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12690 if (!vendor_data) {
12691 genlmsg_cancel(skb, hdr);
12692 break;
12693 }
12694
12695 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12696 (unsigned long *)&cb->args[5]);
12697 nla_nest_end(skb, vendor_data);
12698
12699 if (err == -ENOBUFS || err == -ENOENT) {
12700 genlmsg_cancel(skb, hdr);
12701 break;
12702 } else if (err) {
12703 genlmsg_cancel(skb, hdr);
12704 goto out;
12705 }
12706
12707 genlmsg_end(skb, hdr);
12708 }
12709
12710 err = skb->len;
12711 out:
12712 rtnl_unlock();
12713 return err;
12714}
12715
Johannes Bergad7e7182013-11-13 13:37:47 +010012716struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12717 enum nl80211_commands cmd,
12718 enum nl80211_attrs attr,
12719 int approxlen)
12720{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012721 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012722
12723 if (WARN_ON(!rdev->cur_cmd_info))
12724 return NULL;
12725
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012726 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012727 rdev->cur_cmd_info->snd_portid,
12728 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012729 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012730}
12731EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12732
12733int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12734{
12735 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12736 void *hdr = ((void **)skb->cb)[1];
12737 struct nlattr *data = ((void **)skb->cb)[2];
12738
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012739 /* clear CB data for netlink core to own from now on */
12740 memset(skb->cb, 0, sizeof(skb->cb));
12741
Johannes Bergad7e7182013-11-13 13:37:47 +010012742 if (WARN_ON(!rdev->cur_cmd_info)) {
12743 kfree_skb(skb);
12744 return -EINVAL;
12745 }
12746
12747 nla_nest_end(skb, data);
12748 genlmsg_end(skb, hdr);
12749 return genlmsg_reply(skb, rdev->cur_cmd_info);
12750}
12751EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12752
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012753static int nl80211_set_qos_map(struct sk_buff *skb,
12754 struct genl_info *info)
12755{
12756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12757 struct cfg80211_qos_map *qos_map = NULL;
12758 struct net_device *dev = info->user_ptr[1];
12759 u8 *pos, len, num_des, des_len, des;
12760 int ret;
12761
12762 if (!rdev->ops->set_qos_map)
12763 return -EOPNOTSUPP;
12764
12765 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12766 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12767 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12768
12769 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12770 len > IEEE80211_QOS_MAP_LEN_MAX)
12771 return -EINVAL;
12772
12773 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12774 if (!qos_map)
12775 return -ENOMEM;
12776
12777 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12778 if (num_des) {
12779 des_len = num_des *
12780 sizeof(struct cfg80211_dscp_exception);
12781 memcpy(qos_map->dscp_exception, pos, des_len);
12782 qos_map->num_des = num_des;
12783 for (des = 0; des < num_des; des++) {
12784 if (qos_map->dscp_exception[des].up > 7) {
12785 kfree(qos_map);
12786 return -EINVAL;
12787 }
12788 }
12789 pos += des_len;
12790 }
12791 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12792 }
12793
12794 wdev_lock(dev->ieee80211_ptr);
12795 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12796 if (!ret)
12797 ret = rdev_set_qos_map(rdev, dev, qos_map);
12798 wdev_unlock(dev->ieee80211_ptr);
12799
12800 kfree(qos_map);
12801 return ret;
12802}
12803
Johannes Berg960d01a2014-09-09 22:55:35 +030012804static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12805{
12806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12807 struct net_device *dev = info->user_ptr[1];
12808 struct wireless_dev *wdev = dev->ieee80211_ptr;
12809 const u8 *peer;
12810 u8 tsid, up;
12811 u16 admitted_time = 0;
12812 int err;
12813
Johannes Berg723e73a2014-10-22 09:25:06 +020012814 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012815 return -EOPNOTSUPP;
12816
12817 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12818 !info->attrs[NL80211_ATTR_USER_PRIO])
12819 return -EINVAL;
12820
12821 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030012822 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030012823
12824 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012825 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012826 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012827 * need more attributes for that (e.g. BA session requirement);
12828 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012829 */
12830 return -EINVAL;
12831 }
12832
12833 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12834
12835 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12836 admitted_time =
12837 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12838 if (!admitted_time)
12839 return -EINVAL;
12840 }
12841
12842 wdev_lock(wdev);
12843 switch (wdev->iftype) {
12844 case NL80211_IFTYPE_STATION:
12845 case NL80211_IFTYPE_P2P_CLIENT:
12846 if (wdev->current_bss)
12847 break;
12848 err = -ENOTCONN;
12849 goto out;
12850 default:
12851 err = -EOPNOTSUPP;
12852 goto out;
12853 }
12854
12855 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12856
12857 out:
12858 wdev_unlock(wdev);
12859 return err;
12860}
12861
12862static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12863{
12864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12865 struct net_device *dev = info->user_ptr[1];
12866 struct wireless_dev *wdev = dev->ieee80211_ptr;
12867 const u8 *peer;
12868 u8 tsid;
12869 int err;
12870
12871 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12872 return -EINVAL;
12873
12874 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12875 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12876
12877 wdev_lock(wdev);
12878 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12879 wdev_unlock(wdev);
12880
12881 return err;
12882}
12883
Arik Nemtsov1057d352014-11-19 12:54:26 +020012884static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12885 struct genl_info *info)
12886{
12887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12888 struct net_device *dev = info->user_ptr[1];
12889 struct wireless_dev *wdev = dev->ieee80211_ptr;
12890 struct cfg80211_chan_def chandef = {};
12891 const u8 *addr;
12892 u8 oper_class;
12893 int err;
12894
12895 if (!rdev->ops->tdls_channel_switch ||
12896 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12897 return -EOPNOTSUPP;
12898
12899 switch (dev->ieee80211_ptr->iftype) {
12900 case NL80211_IFTYPE_STATION:
12901 case NL80211_IFTYPE_P2P_CLIENT:
12902 break;
12903 default:
12904 return -EOPNOTSUPP;
12905 }
12906
12907 if (!info->attrs[NL80211_ATTR_MAC] ||
12908 !info->attrs[NL80211_ATTR_OPER_CLASS])
12909 return -EINVAL;
12910
12911 err = nl80211_parse_chandef(rdev, info, &chandef);
12912 if (err)
12913 return err;
12914
12915 /*
12916 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12917 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12918 * specification is not defined for them.
12919 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012920 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012921 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12922 chandef.width != NL80211_CHAN_WIDTH_20)
12923 return -EINVAL;
12924
12925 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012926 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12927 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012928 return -EINVAL;
12929
12930 /* don't allow switching to DFS channels */
12931 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12932 return -EINVAL;
12933
12934 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12935 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12936
12937 wdev_lock(wdev);
12938 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12939 wdev_unlock(wdev);
12940
12941 return err;
12942}
12943
12944static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12945 struct genl_info *info)
12946{
12947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12948 struct net_device *dev = info->user_ptr[1];
12949 struct wireless_dev *wdev = dev->ieee80211_ptr;
12950 const u8 *addr;
12951
12952 if (!rdev->ops->tdls_channel_switch ||
12953 !rdev->ops->tdls_cancel_channel_switch ||
12954 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12955 return -EOPNOTSUPP;
12956
12957 switch (dev->ieee80211_ptr->iftype) {
12958 case NL80211_IFTYPE_STATION:
12959 case NL80211_IFTYPE_P2P_CLIENT:
12960 break;
12961 default:
12962 return -EOPNOTSUPP;
12963 }
12964
12965 if (!info->attrs[NL80211_ATTR_MAC])
12966 return -EINVAL;
12967
12968 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12969
12970 wdev_lock(wdev);
12971 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12972 wdev_unlock(wdev);
12973
12974 return 0;
12975}
12976
Michael Braunce0ce132016-10-10 19:12:22 +020012977static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12978 struct genl_info *info)
12979{
12980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12981 struct net_device *dev = info->user_ptr[1];
12982 struct wireless_dev *wdev = dev->ieee80211_ptr;
12983 const struct nlattr *nla;
12984 bool enabled;
12985
Michael Braunce0ce132016-10-10 19:12:22 +020012986 if (!rdev->ops->set_multicast_to_unicast)
12987 return -EOPNOTSUPP;
12988
12989 if (wdev->iftype != NL80211_IFTYPE_AP &&
12990 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12991 return -EOPNOTSUPP;
12992
12993 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12994 enabled = nla_get_flag(nla);
12995
12996 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12997}
12998
Avraham Stern3a00df52017-06-09 13:08:43 +010012999static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13000{
13001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13002 struct net_device *dev = info->user_ptr[1];
13003 struct wireless_dev *wdev = dev->ieee80211_ptr;
13004 struct cfg80211_pmk_conf pmk_conf = {};
13005 int ret;
13006
13007 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13008 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13009 return -EOPNOTSUPP;
13010
13011 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13012 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13013 return -EOPNOTSUPP;
13014
13015 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13016 return -EINVAL;
13017
13018 wdev_lock(wdev);
13019 if (!wdev->current_bss) {
13020 ret = -ENOTCONN;
13021 goto out;
13022 }
13023
13024 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13025 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13026 ret = -EINVAL;
13027 goto out;
13028 }
13029
13030 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13031 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13032 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13033 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13034 ret = -EINVAL;
13035 goto out;
13036 }
13037
13038 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13039 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13040
13041 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13042 ret = -EINVAL;
13043 goto out;
13044 }
13045
13046 pmk_conf.pmk_r0_name =
13047 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13048 }
13049
13050 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13051out:
13052 wdev_unlock(wdev);
13053 return ret;
13054}
13055
13056static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13057{
13058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13059 struct net_device *dev = info->user_ptr[1];
13060 struct wireless_dev *wdev = dev->ieee80211_ptr;
13061 const u8 *aa;
13062 int ret;
13063
13064 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13065 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13066 return -EOPNOTSUPP;
13067
13068 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13069 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13070 return -EOPNOTSUPP;
13071
13072 if (!info->attrs[NL80211_ATTR_MAC])
13073 return -EINVAL;
13074
13075 wdev_lock(wdev);
13076 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13077 ret = rdev_del_pmk(rdev, dev, aa);
13078 wdev_unlock(wdev);
13079
13080 return ret;
13081}
13082
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013083static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13084{
13085 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13086 struct net_device *dev = info->user_ptr[1];
13087 struct cfg80211_external_auth_params params;
13088
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013089 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013090 return -EOPNOTSUPP;
13091
Srinivas Dasarife494372019-01-23 18:06:56 +053013092 if (!info->attrs[NL80211_ATTR_SSID] &&
13093 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13094 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013095 return -EINVAL;
13096
13097 if (!info->attrs[NL80211_ATTR_BSSID])
13098 return -EINVAL;
13099
13100 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13101 return -EINVAL;
13102
13103 memset(&params, 0, sizeof(params));
13104
Srinivas Dasarife494372019-01-23 18:06:56 +053013105 if (info->attrs[NL80211_ATTR_SSID]) {
13106 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13107 if (params.ssid.ssid_len == 0 ||
13108 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13109 return -EINVAL;
13110 memcpy(params.ssid.ssid,
13111 nla_data(info->attrs[NL80211_ATTR_SSID]),
13112 params.ssid.ssid_len);
13113 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013114
13115 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13116 ETH_ALEN);
13117
13118 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13119
Srinivas Dasarife494372019-01-23 18:06:56 +053013120 if (info->attrs[NL80211_ATTR_PMKID])
13121 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13122
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013123 return rdev_external_auth(rdev, dev, &params);
13124}
13125
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013126static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13127{
13128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13129 struct net_device *dev = info->user_ptr[1];
13130 struct wireless_dev *wdev = dev->ieee80211_ptr;
13131 const u8 *buf;
13132 size_t len;
13133 u8 *dest;
13134 u16 proto;
13135 bool noencrypt;
13136 int err;
13137
13138 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13139 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13140 return -EOPNOTSUPP;
13141
13142 if (!rdev->ops->tx_control_port)
13143 return -EOPNOTSUPP;
13144
13145 if (!info->attrs[NL80211_ATTR_FRAME] ||
13146 !info->attrs[NL80211_ATTR_MAC] ||
13147 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13148 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13149 return -EINVAL;
13150 }
13151
13152 wdev_lock(wdev);
13153
13154 switch (wdev->iftype) {
13155 case NL80211_IFTYPE_AP:
13156 case NL80211_IFTYPE_P2P_GO:
13157 case NL80211_IFTYPE_MESH_POINT:
13158 break;
13159 case NL80211_IFTYPE_ADHOC:
13160 case NL80211_IFTYPE_STATION:
13161 case NL80211_IFTYPE_P2P_CLIENT:
13162 if (wdev->current_bss)
13163 break;
13164 err = -ENOTCONN;
13165 goto out;
13166 default:
13167 err = -EOPNOTSUPP;
13168 goto out;
13169 }
13170
13171 wdev_unlock(wdev);
13172
13173 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13174 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13175 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13176 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13177 noencrypt =
13178 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13179
13180 return rdev_tx_control_port(rdev, dev, buf, len,
13181 dest, cpu_to_be16(proto), noencrypt);
13182
13183 out:
13184 wdev_unlock(wdev);
13185 return err;
13186}
13187
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013188static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13189 struct genl_info *info)
13190{
13191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13192 struct net_device *dev = info->user_ptr[1];
13193 struct wireless_dev *wdev = dev->ieee80211_ptr;
13194 struct cfg80211_ftm_responder_stats ftm_stats = {};
13195 struct sk_buff *msg;
13196 void *hdr;
13197 struct nlattr *ftm_stats_attr;
13198 int err;
13199
13200 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13201 return -EOPNOTSUPP;
13202
13203 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13204 if (err)
13205 return err;
13206
13207 if (!ftm_stats.filled)
13208 return -ENODATA;
13209
13210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13211 if (!msg)
13212 return -ENOMEM;
13213
13214 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13215 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13216 if (!hdr)
13217 return -ENOBUFS;
13218
13219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13220 goto nla_put_failure;
13221
13222 ftm_stats_attr = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER_STATS);
13223 if (!ftm_stats_attr)
13224 goto nla_put_failure;
13225
13226#define SET_FTM(field, name, type) \
13227 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13228 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13229 ftm_stats.field)) \
13230 goto nla_put_failure; } while (0)
13231#define SET_FTM_U64(field, name) \
13232 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13233 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13234 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13235 goto nla_put_failure; } while (0)
13236
13237 SET_FTM(success_num, SUCCESS_NUM, u32);
13238 SET_FTM(partial_num, PARTIAL_NUM, u32);
13239 SET_FTM(failed_num, FAILED_NUM, u32);
13240 SET_FTM(asap_num, ASAP_NUM, u32);
13241 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13242 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13243 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13244 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13245 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13246#undef SET_FTM
13247
13248 nla_nest_end(msg, ftm_stats_attr);
13249
13250 genlmsg_end(msg, hdr);
13251 return genlmsg_reply(msg, info);
13252
13253nla_put_failure:
13254 nlmsg_free(msg);
13255 return -ENOBUFS;
13256}
13257
Johannes Berg4c476992010-10-04 21:36:35 +020013258#define NL80211_FLAG_NEED_WIPHY 0x01
13259#define NL80211_FLAG_NEED_NETDEV 0x02
13260#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013261#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13262#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13263 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013264#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013265/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013266#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13267 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013268#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013269
Johannes Bergf84f7712013-11-14 17:14:45 +010013270static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013271 struct genl_info *info)
13272{
13273 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013274 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013275 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013276 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13277
13278 if (rtnl)
13279 rtnl_lock();
13280
13281 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013282 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013283 if (IS_ERR(rdev)) {
13284 if (rtnl)
13285 rtnl_unlock();
13286 return PTR_ERR(rdev);
13287 }
13288 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013289 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13290 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013291 ASSERT_RTNL();
13292
Johannes Berg89a54e42012-06-15 14:33:17 +020013293 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13294 info->attrs);
13295 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013296 if (rtnl)
13297 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013298 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013299 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013300
Johannes Berg89a54e42012-06-15 14:33:17 +020013301 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013302 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013303
Johannes Berg1bf614e2012-06-15 15:23:36 +020013304 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13305 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013306 if (rtnl)
13307 rtnl_unlock();
13308 return -EINVAL;
13309 }
13310
13311 info->user_ptr[1] = dev;
13312 } else {
13313 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013314 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013315
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013316 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13317 !wdev_running(wdev)) {
13318 if (rtnl)
13319 rtnl_unlock();
13320 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013321 }
13322
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013323 if (dev)
13324 dev_hold(dev);
13325
Johannes Berg4c476992010-10-04 21:36:35 +020013326 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013327 }
13328
13329 return 0;
13330}
13331
Johannes Bergf84f7712013-11-14 17:14:45 +010013332static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013333 struct genl_info *info)
13334{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013335 if (info->user_ptr[1]) {
13336 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13337 struct wireless_dev *wdev = info->user_ptr[1];
13338
13339 if (wdev->netdev)
13340 dev_put(wdev->netdev);
13341 } else {
13342 dev_put(info->user_ptr[1]);
13343 }
13344 }
Johannes Berg5393b912014-09-10 15:00:16 +030013345
Johannes Berg4c476992010-10-04 21:36:35 +020013346 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13347 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013348
13349 /* If needed, clear the netlink message payload from the SKB
13350 * as it might contain key data that shouldn't stick around on
13351 * the heap after the SKB is freed. The netlink message header
13352 * is still needed for further processing, so leave it intact.
13353 */
13354 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13355 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13356
13357 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13358 }
Johannes Berg4c476992010-10-04 21:36:35 +020013359}
13360
Johannes Berg4534de82013-11-14 17:14:46 +010013361static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013362 {
13363 .cmd = NL80211_CMD_GET_WIPHY,
13364 .doit = nl80211_get_wiphy,
13365 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013366 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013367 .policy = nl80211_policy,
13368 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013369 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13370 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013371 },
13372 {
13373 .cmd = NL80211_CMD_SET_WIPHY,
13374 .doit = nl80211_set_wiphy,
13375 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013376 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013377 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013378 },
13379 {
13380 .cmd = NL80211_CMD_GET_INTERFACE,
13381 .doit = nl80211_get_interface,
13382 .dumpit = nl80211_dump_interface,
13383 .policy = nl80211_policy,
13384 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013385 .internal_flags = NL80211_FLAG_NEED_WDEV |
13386 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013387 },
13388 {
13389 .cmd = NL80211_CMD_SET_INTERFACE,
13390 .doit = nl80211_set_interface,
13391 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013392 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013393 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13394 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013395 },
13396 {
13397 .cmd = NL80211_CMD_NEW_INTERFACE,
13398 .doit = nl80211_new_interface,
13399 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013400 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013401 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13402 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013403 },
13404 {
13405 .cmd = NL80211_CMD_DEL_INTERFACE,
13406 .doit = nl80211_del_interface,
13407 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013408 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013409 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013410 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013411 },
Johannes Berg41ade002007-12-19 02:03:29 +010013412 {
13413 .cmd = NL80211_CMD_GET_KEY,
13414 .doit = nl80211_get_key,
13415 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013416 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013417 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013418 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013419 },
13420 {
13421 .cmd = NL80211_CMD_SET_KEY,
13422 .doit = nl80211_set_key,
13423 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013424 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013426 NL80211_FLAG_NEED_RTNL |
13427 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013428 },
13429 {
13430 .cmd = NL80211_CMD_NEW_KEY,
13431 .doit = nl80211_new_key,
13432 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013433 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013434 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013435 NL80211_FLAG_NEED_RTNL |
13436 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013437 },
13438 {
13439 .cmd = NL80211_CMD_DEL_KEY,
13440 .doit = nl80211_del_key,
13441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013444 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013445 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013446 {
13447 .cmd = NL80211_CMD_SET_BEACON,
13448 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013449 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013450 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013452 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013453 },
13454 {
Johannes Berg88600202012-02-13 15:17:18 +010013455 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013456 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013457 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013458 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013460 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013461 },
13462 {
Johannes Berg88600202012-02-13 15:17:18 +010013463 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013464 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013465 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013466 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013468 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013469 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013470 {
13471 .cmd = NL80211_CMD_GET_STATION,
13472 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013473 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010013474 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020013475 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13476 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013477 },
13478 {
13479 .cmd = NL80211_CMD_SET_STATION,
13480 .doit = nl80211_set_station,
13481 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013482 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013484 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013485 },
13486 {
13487 .cmd = NL80211_CMD_NEW_STATION,
13488 .doit = nl80211_new_station,
13489 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013490 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013492 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013493 },
13494 {
13495 .cmd = NL80211_CMD_DEL_STATION,
13496 .doit = nl80211_del_station,
13497 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013498 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013500 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013501 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013502 {
13503 .cmd = NL80211_CMD_GET_MPATH,
13504 .doit = nl80211_get_mpath,
13505 .dumpit = nl80211_dump_mpath,
13506 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013507 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013509 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013510 },
13511 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013512 .cmd = NL80211_CMD_GET_MPP,
13513 .doit = nl80211_get_mpp,
13514 .dumpit = nl80211_dump_mpp,
13515 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013516 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13518 NL80211_FLAG_NEED_RTNL,
13519 },
13520 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013521 .cmd = NL80211_CMD_SET_MPATH,
13522 .doit = nl80211_set_mpath,
13523 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013524 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013526 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013527 },
13528 {
13529 .cmd = NL80211_CMD_NEW_MPATH,
13530 .doit = nl80211_new_mpath,
13531 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013532 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013534 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013535 },
13536 {
13537 .cmd = NL80211_CMD_DEL_MPATH,
13538 .doit = nl80211_del_mpath,
13539 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013540 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013542 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013543 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013544 {
13545 .cmd = NL80211_CMD_SET_BSS,
13546 .doit = nl80211_set_bss,
13547 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013548 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013550 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013551 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013552 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013553 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013554 .doit = nl80211_get_reg_do,
13555 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013556 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013557 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013558 /* can be retrieved by unprivileged users */
13559 },
Johannes Bergb6863032015-10-15 09:25:18 +020013560#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013561 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013562 .cmd = NL80211_CMD_SET_REG,
13563 .doit = nl80211_set_reg,
13564 .policy = nl80211_policy,
13565 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013566 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013567 },
Johannes Bergb6863032015-10-15 09:25:18 +020013568#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013569 {
13570 .cmd = NL80211_CMD_REQ_SET_REG,
13571 .doit = nl80211_req_set_reg,
13572 .policy = nl80211_policy,
13573 .flags = GENL_ADMIN_PERM,
13574 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013575 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013576 .cmd = NL80211_CMD_RELOAD_REGDB,
13577 .doit = nl80211_reload_regdb,
13578 .policy = nl80211_policy,
13579 .flags = GENL_ADMIN_PERM,
13580 },
13581 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013582 .cmd = NL80211_CMD_GET_MESH_CONFIG,
13583 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013584 .policy = nl80211_policy,
13585 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013587 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013588 },
13589 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013590 .cmd = NL80211_CMD_SET_MESH_CONFIG,
13591 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013592 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013593 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013595 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013596 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013597 {
Johannes Berg2a519312009-02-10 21:25:55 +010013598 .cmd = NL80211_CMD_TRIGGER_SCAN,
13599 .doit = nl80211_trigger_scan,
13600 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013601 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013602 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013603 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013604 },
13605 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013606 .cmd = NL80211_CMD_ABORT_SCAN,
13607 .doit = nl80211_abort_scan,
13608 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013609 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013610 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13611 NL80211_FLAG_NEED_RTNL,
13612 },
13613 {
Johannes Berg2a519312009-02-10 21:25:55 +010013614 .cmd = NL80211_CMD_GET_SCAN,
13615 .policy = nl80211_policy,
13616 .dumpit = nl80211_dump_scan,
13617 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013618 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013619 .cmd = NL80211_CMD_START_SCHED_SCAN,
13620 .doit = nl80211_start_sched_scan,
13621 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013622 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013623 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13624 NL80211_FLAG_NEED_RTNL,
13625 },
13626 {
13627 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
13628 .doit = nl80211_stop_sched_scan,
13629 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013630 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13632 NL80211_FLAG_NEED_RTNL,
13633 },
13634 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013635 .cmd = NL80211_CMD_AUTHENTICATE,
13636 .doit = nl80211_authenticate,
13637 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013638 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013640 NL80211_FLAG_NEED_RTNL |
13641 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013642 },
13643 {
13644 .cmd = NL80211_CMD_ASSOCIATE,
13645 .doit = nl80211_associate,
13646 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013647 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013648 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013649 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013650 },
13651 {
13652 .cmd = NL80211_CMD_DEAUTHENTICATE,
13653 .doit = nl80211_deauthenticate,
13654 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013655 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013656 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013657 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013658 },
13659 {
13660 .cmd = NL80211_CMD_DISASSOCIATE,
13661 .doit = nl80211_disassociate,
13662 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013663 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013665 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013666 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013667 {
13668 .cmd = NL80211_CMD_JOIN_IBSS,
13669 .doit = nl80211_join_ibss,
13670 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013671 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013673 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013674 },
13675 {
13676 .cmd = NL80211_CMD_LEAVE_IBSS,
13677 .doit = nl80211_leave_ibss,
13678 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013679 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013681 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013682 },
Johannes Bergaff89a92009-07-01 21:26:51 +020013683#ifdef CONFIG_NL80211_TESTMODE
13684 {
13685 .cmd = NL80211_CMD_TESTMODE,
13686 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070013687 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020013688 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013689 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013690 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13691 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020013692 },
13693#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020013694 {
13695 .cmd = NL80211_CMD_CONNECT,
13696 .doit = nl80211_connect,
13697 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013698 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013700 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013701 },
13702 {
vamsi krishna088e8df2016-10-27 16:51:11 +030013703 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
13704 .doit = nl80211_update_connect_params,
13705 .policy = nl80211_policy,
13706 .flags = GENL_ADMIN_PERM,
13707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13708 NL80211_FLAG_NEED_RTNL,
13709 },
13710 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020013711 .cmd = NL80211_CMD_DISCONNECT,
13712 .doit = nl80211_disconnect,
13713 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013714 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013716 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013717 },
Johannes Berg463d0182009-07-14 00:33:35 +020013718 {
13719 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
13720 .doit = nl80211_wiphy_netns,
13721 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013722 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013723 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13724 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013725 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013726 {
13727 .cmd = NL80211_CMD_GET_SURVEY,
13728 .policy = nl80211_policy,
13729 .dumpit = nl80211_dump_survey,
13730 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013731 {
13732 .cmd = NL80211_CMD_SET_PMKSA,
13733 .doit = nl80211_setdel_pmksa,
13734 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013735 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013737 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013738 },
13739 {
13740 .cmd = NL80211_CMD_DEL_PMKSA,
13741 .doit = nl80211_setdel_pmksa,
13742 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013743 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013745 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013746 },
13747 {
13748 .cmd = NL80211_CMD_FLUSH_PMKSA,
13749 .doit = nl80211_flush_pmksa,
13750 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013751 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013753 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013754 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013755 {
13756 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13757 .doit = nl80211_remain_on_channel,
13758 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013759 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013760 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013761 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013762 },
13763 {
13764 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13765 .doit = nl80211_cancel_remain_on_channel,
13766 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013767 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013768 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013769 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013770 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013771 {
13772 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
13773 .doit = nl80211_set_tx_bitrate_mask,
13774 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013775 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13777 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013778 },
Jouni Malinen026331c2010-02-15 12:53:10 +020013779 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013780 .cmd = NL80211_CMD_REGISTER_FRAME,
13781 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013782 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013783 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013784 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013785 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013786 },
13787 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013788 .cmd = NL80211_CMD_FRAME,
13789 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013790 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013791 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013792 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013793 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013794 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020013795 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013796 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
13797 .doit = nl80211_tx_mgmt_cancel_wait,
13798 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013799 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013800 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013801 NL80211_FLAG_NEED_RTNL,
13802 },
13803 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020013804 .cmd = NL80211_CMD_SET_POWER_SAVE,
13805 .doit = nl80211_set_power_save,
13806 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013807 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013808 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13809 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013810 },
13811 {
13812 .cmd = NL80211_CMD_GET_POWER_SAVE,
13813 .doit = nl80211_get_power_save,
13814 .policy = nl80211_policy,
13815 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020013816 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13817 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013818 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013819 {
13820 .cmd = NL80211_CMD_SET_CQM,
13821 .doit = nl80211_set_cqm,
13822 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013823 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013824 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13825 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013826 },
Johannes Bergf444de02010-05-05 15:25:02 +020013827 {
13828 .cmd = NL80211_CMD_SET_CHANNEL,
13829 .doit = nl80211_set_channel,
13830 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013831 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013832 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13833 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013834 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013835 {
13836 .cmd = NL80211_CMD_SET_WDS_PEER,
13837 .doit = nl80211_set_wds_peer,
13838 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013839 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013840 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13841 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013842 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013843 {
13844 .cmd = NL80211_CMD_JOIN_MESH,
13845 .doit = nl80211_join_mesh,
13846 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013847 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13849 NL80211_FLAG_NEED_RTNL,
13850 },
13851 {
13852 .cmd = NL80211_CMD_LEAVE_MESH,
13853 .doit = nl80211_leave_mesh,
13854 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013855 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013856 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13857 NL80211_FLAG_NEED_RTNL,
13858 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013859 {
13860 .cmd = NL80211_CMD_JOIN_OCB,
13861 .doit = nl80211_join_ocb,
13862 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013863 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013864 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13865 NL80211_FLAG_NEED_RTNL,
13866 },
13867 {
13868 .cmd = NL80211_CMD_LEAVE_OCB,
13869 .doit = nl80211_leave_ocb,
13870 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013871 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013872 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13873 NL80211_FLAG_NEED_RTNL,
13874 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013875#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013876 {
13877 .cmd = NL80211_CMD_GET_WOWLAN,
13878 .doit = nl80211_get_wowlan,
13879 .policy = nl80211_policy,
13880 /* can be retrieved by unprivileged users */
13881 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13882 NL80211_FLAG_NEED_RTNL,
13883 },
13884 {
13885 .cmd = NL80211_CMD_SET_WOWLAN,
13886 .doit = nl80211_set_wowlan,
13887 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013888 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013889 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13890 NL80211_FLAG_NEED_RTNL,
13891 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013892#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013893 {
13894 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13895 .doit = nl80211_set_rekey_data,
13896 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013897 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013899 NL80211_FLAG_NEED_RTNL |
13900 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013901 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013902 {
13903 .cmd = NL80211_CMD_TDLS_MGMT,
13904 .doit = nl80211_tdls_mgmt,
13905 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013906 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13908 NL80211_FLAG_NEED_RTNL,
13909 },
13910 {
13911 .cmd = NL80211_CMD_TDLS_OPER,
13912 .doit = nl80211_tdls_oper,
13913 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013914 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13916 NL80211_FLAG_NEED_RTNL,
13917 },
Johannes Berg28946da2011-11-04 11:18:12 +010013918 {
13919 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13920 .doit = nl80211_register_unexpected_frame,
13921 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013922 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013923 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13924 NL80211_FLAG_NEED_RTNL,
13925 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013926 {
13927 .cmd = NL80211_CMD_PROBE_CLIENT,
13928 .doit = nl80211_probe_client,
13929 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013930 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013931 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013932 NL80211_FLAG_NEED_RTNL,
13933 },
Johannes Berg5e760232011-11-04 11:18:17 +010013934 {
13935 .cmd = NL80211_CMD_REGISTER_BEACONS,
13936 .doit = nl80211_register_beacons,
13937 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013938 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013939 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13940 NL80211_FLAG_NEED_RTNL,
13941 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013942 {
13943 .cmd = NL80211_CMD_SET_NOACK_MAP,
13944 .doit = nl80211_set_noack_map,
13945 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013946 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013947 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13948 NL80211_FLAG_NEED_RTNL,
13949 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013950 {
13951 .cmd = NL80211_CMD_START_P2P_DEVICE,
13952 .doit = nl80211_start_p2p_device,
13953 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013954 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013955 .internal_flags = NL80211_FLAG_NEED_WDEV |
13956 NL80211_FLAG_NEED_RTNL,
13957 },
13958 {
13959 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13960 .doit = nl80211_stop_p2p_device,
13961 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013962 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013963 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13964 NL80211_FLAG_NEED_RTNL,
13965 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013966 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013967 .cmd = NL80211_CMD_START_NAN,
13968 .doit = nl80211_start_nan,
13969 .policy = nl80211_policy,
13970 .flags = GENL_ADMIN_PERM,
13971 .internal_flags = NL80211_FLAG_NEED_WDEV |
13972 NL80211_FLAG_NEED_RTNL,
13973 },
13974 {
13975 .cmd = NL80211_CMD_STOP_NAN,
13976 .doit = nl80211_stop_nan,
13977 .policy = nl80211_policy,
13978 .flags = GENL_ADMIN_PERM,
13979 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13980 NL80211_FLAG_NEED_RTNL,
13981 },
13982 {
Ayala Bekera442b762016-09-20 17:31:15 +030013983 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13984 .doit = nl80211_nan_add_func,
13985 .policy = nl80211_policy,
13986 .flags = GENL_ADMIN_PERM,
13987 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13988 NL80211_FLAG_NEED_RTNL,
13989 },
13990 {
13991 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13992 .doit = nl80211_nan_del_func,
13993 .policy = nl80211_policy,
13994 .flags = GENL_ADMIN_PERM,
13995 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13996 NL80211_FLAG_NEED_RTNL,
13997 },
13998 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013999 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
14000 .doit = nl80211_nan_change_config,
14001 .policy = nl80211_policy,
14002 .flags = GENL_ADMIN_PERM,
14003 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14004 NL80211_FLAG_NEED_RTNL,
14005 },
14006 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014007 .cmd = NL80211_CMD_SET_MCAST_RATE,
14008 .doit = nl80211_set_mcast_rate,
14009 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014010 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014011 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14012 NL80211_FLAG_NEED_RTNL,
14013 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014014 {
14015 .cmd = NL80211_CMD_SET_MAC_ACL,
14016 .doit = nl80211_set_mac_acl,
14017 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014018 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014019 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14020 NL80211_FLAG_NEED_RTNL,
14021 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014022 {
14023 .cmd = NL80211_CMD_RADAR_DETECT,
14024 .doit = nl80211_start_radar_detection,
14025 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014026 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14028 NL80211_FLAG_NEED_RTNL,
14029 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014030 {
14031 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
14032 .doit = nl80211_get_protocol_features,
14033 .policy = nl80211_policy,
14034 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014035 {
14036 .cmd = NL80211_CMD_UPDATE_FT_IES,
14037 .doit = nl80211_update_ft_ies,
14038 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014039 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14041 NL80211_FLAG_NEED_RTNL,
14042 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014043 {
14044 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
14045 .doit = nl80211_crit_protocol_start,
14046 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014047 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014048 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14049 NL80211_FLAG_NEED_RTNL,
14050 },
14051 {
14052 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
14053 .doit = nl80211_crit_protocol_stop,
14054 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014055 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014056 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14057 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014058 },
14059 {
14060 .cmd = NL80211_CMD_GET_COALESCE,
14061 .doit = nl80211_get_coalesce,
14062 .policy = nl80211_policy,
14063 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14064 NL80211_FLAG_NEED_RTNL,
14065 },
14066 {
14067 .cmd = NL80211_CMD_SET_COALESCE,
14068 .doit = nl80211_set_coalesce,
14069 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014070 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014071 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14072 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014073 },
14074 {
14075 .cmd = NL80211_CMD_CHANNEL_SWITCH,
14076 .doit = nl80211_channel_switch,
14077 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014078 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14080 NL80211_FLAG_NEED_RTNL,
14081 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014082 {
14083 .cmd = NL80211_CMD_VENDOR,
14084 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014085 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010014086 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014087 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014088 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14089 NL80211_FLAG_NEED_RTNL,
14090 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014091 {
14092 .cmd = NL80211_CMD_SET_QOS_MAP,
14093 .doit = nl80211_set_qos_map,
14094 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014095 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14097 NL80211_FLAG_NEED_RTNL,
14098 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014099 {
14100 .cmd = NL80211_CMD_ADD_TX_TS,
14101 .doit = nl80211_add_tx_ts,
14102 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014103 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14105 NL80211_FLAG_NEED_RTNL,
14106 },
14107 {
14108 .cmd = NL80211_CMD_DEL_TX_TS,
14109 .doit = nl80211_del_tx_ts,
14110 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014111 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014112 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14113 NL80211_FLAG_NEED_RTNL,
14114 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014115 {
14116 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
14117 .doit = nl80211_tdls_channel_switch,
14118 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014119 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14121 NL80211_FLAG_NEED_RTNL,
14122 },
14123 {
14124 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
14125 .doit = nl80211_tdls_cancel_channel_switch,
14126 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014127 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14129 NL80211_FLAG_NEED_RTNL,
14130 },
Michael Braunce0ce132016-10-10 19:12:22 +020014131 {
14132 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
14133 .doit = nl80211_set_multicast_to_unicast,
14134 .policy = nl80211_policy,
14135 .flags = GENL_UNS_ADMIN_PERM,
14136 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14137 NL80211_FLAG_NEED_RTNL,
14138 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014139 {
14140 .cmd = NL80211_CMD_SET_PMK,
14141 .doit = nl80211_set_pmk,
14142 .policy = nl80211_policy,
14143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14144 NL80211_FLAG_NEED_RTNL,
14145 },
14146 {
14147 .cmd = NL80211_CMD_DEL_PMK,
14148 .doit = nl80211_del_pmk,
14149 .policy = nl80211_policy,
14150 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14151 NL80211_FLAG_NEED_RTNL,
14152 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014153 {
14154 .cmd = NL80211_CMD_EXTERNAL_AUTH,
14155 .doit = nl80211_external_auth,
14156 .policy = nl80211_policy,
14157 .flags = GENL_ADMIN_PERM,
14158 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14159 NL80211_FLAG_NEED_RTNL,
14160 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014161 {
14162 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
14163 .doit = nl80211_tx_control_port,
14164 .policy = nl80211_policy,
14165 .flags = GENL_UNS_ADMIN_PERM,
14166 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14167 NL80211_FLAG_NEED_RTNL,
14168 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014169 {
14170 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
14171 .doit = nl80211_get_ftm_responder_stats,
14172 .policy = nl80211_policy,
14173 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14174 NL80211_FLAG_NEED_RTNL,
14175 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014176 {
14177 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
14178 .doit = nl80211_pmsr_start,
14179 .policy = nl80211_policy,
14180 .flags = GENL_UNS_ADMIN_PERM,
14181 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14182 NL80211_FLAG_NEED_RTNL,
14183 },
Sriram R30c63112018-12-04 17:46:52 +053014184 {
14185 .cmd = NL80211_CMD_NOTIFY_RADAR,
14186 .doit = nl80211_notify_radar_detection,
14187 .policy = nl80211_policy,
14188 .flags = GENL_UNS_ADMIN_PERM,
14189 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14190 NL80211_FLAG_NEED_RTNL,
14191 },
Johannes Berg55682962007-09-20 13:09:35 -040014192};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014193
Johannes Berg56989f62016-10-24 14:40:05 +020014194static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014195 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14196 .hdrsize = 0, /* no private header */
14197 .version = 1, /* no particular meaning now */
14198 .maxattr = NL80211_ATTR_MAX,
14199 .netnsok = true,
14200 .pre_doit = nl80211_pre_doit,
14201 .post_doit = nl80211_post_doit,
14202 .module = THIS_MODULE,
14203 .ops = nl80211_ops,
14204 .n_ops = ARRAY_SIZE(nl80211_ops),
14205 .mcgrps = nl80211_mcgrps,
14206 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
14207};
14208
Johannes Berg55682962007-09-20 13:09:35 -040014209/* notification functions */
14210
Johannes Berg3bb20552014-05-26 13:52:25 +020014211void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14212 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014213{
14214 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014215 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014216
Johannes Berg3bb20552014-05-26 13:52:25 +020014217 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14218 cmd != NL80211_CMD_DEL_WIPHY);
14219
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014220 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014221 if (!msg)
14222 return;
14223
Johannes Berg3bb20552014-05-26 13:52:25 +020014224 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014225 nlmsg_free(msg);
14226 return;
14227 }
14228
Johannes Berg68eb5502013-11-19 15:19:38 +010014229 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014230 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014231}
14232
Denis Kenzior896ff062016-08-03 16:58:33 -050014233void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14234 struct wireless_dev *wdev,
14235 enum nl80211_commands cmd)
14236{
14237 struct sk_buff *msg;
14238
Denis Kenzior896ff062016-08-03 16:58:33 -050014239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14240 if (!msg)
14241 return;
14242
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014243 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014244 nlmsg_free(msg);
14245 return;
14246 }
14247
14248 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14249 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14250}
14251
Johannes Berg362a4152009-05-24 16:43:15 +020014252static int nl80211_add_scan_req(struct sk_buff *msg,
14253 struct cfg80211_registered_device *rdev)
14254{
14255 struct cfg80211_scan_request *req = rdev->scan_req;
14256 struct nlattr *nest;
14257 int i;
14258
14259 if (WARN_ON(!req))
14260 return 0;
14261
14262 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
14263 if (!nest)
14264 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014265 for (i = 0; i < req->n_ssids; i++) {
14266 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14267 goto nla_put_failure;
14268 }
Johannes Berg362a4152009-05-24 16:43:15 +020014269 nla_nest_end(msg, nest);
14270
14271 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
14272 if (!nest)
14273 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014274 for (i = 0; i < req->n_channels; i++) {
14275 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14276 goto nla_put_failure;
14277 }
Johannes Berg362a4152009-05-24 16:43:15 +020014278 nla_nest_end(msg, nest);
14279
David S. Miller9360ffd2012-03-29 04:41:26 -040014280 if (req->ie &&
14281 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14282 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014283
Johannes Bergae917c92013-10-25 11:05:22 +020014284 if (req->flags &&
14285 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14286 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014287
Avraham Stern1d762502016-07-05 17:10:13 +030014288 if (req->info.scan_start_tsf &&
14289 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14290 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14291 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14292 req->info.tsf_bssid)))
14293 goto nla_put_failure;
14294
Johannes Berg362a4152009-05-24 16:43:15 +020014295 return 0;
14296 nla_put_failure:
14297 return -ENOBUFS;
14298}
14299
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014300static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014301 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014302 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014303 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014304 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014305{
14306 void *hdr;
14307
Eric W. Biederman15e47302012-09-07 20:12:54 +000014308 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014309 if (!hdr)
14310 return -1;
14311
David S. Miller9360ffd2012-03-29 04:41:26 -040014312 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014313 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14314 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014315 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14316 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014317 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014318
Johannes Berg362a4152009-05-24 16:43:15 +020014319 /* ignore errors and send incomplete event anyway */
14320 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014321
Johannes Berg053c0952015-01-16 22:09:00 +010014322 genlmsg_end(msg, hdr);
14323 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014324
14325 nla_put_failure:
14326 genlmsg_cancel(msg, hdr);
14327 return -EMSGSIZE;
14328}
14329
Luciano Coelho807f8a82011-05-11 17:09:35 +030014330static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014331nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014332 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014333{
14334 void *hdr;
14335
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014336 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014337 if (!hdr)
14338 return -1;
14339
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14341 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14342 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14343 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14344 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014345 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014346
Johannes Berg053c0952015-01-16 22:09:00 +010014347 genlmsg_end(msg, hdr);
14348 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014349
14350 nla_put_failure:
14351 genlmsg_cancel(msg, hdr);
14352 return -EMSGSIZE;
14353}
14354
Johannes Berga538e2d2009-06-16 19:56:42 +020014355void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014356 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014357{
14358 struct sk_buff *msg;
14359
Thomas Graf58050fc2012-06-28 03:57:45 +000014360 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014361 if (!msg)
14362 return;
14363
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014364 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014365 NL80211_CMD_TRIGGER_SCAN) < 0) {
14366 nlmsg_free(msg);
14367 return;
14368 }
14369
Johannes Berg68eb5502013-11-19 15:19:38 +010014370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014371 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014372}
14373
Johannes Bergf9d15d12014-01-22 11:14:19 +020014374struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14375 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014376{
14377 struct sk_buff *msg;
14378
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014380 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014381 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014382
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014383 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014384 aborted ? NL80211_CMD_SCAN_ABORTED :
14385 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014386 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014387 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014388 }
14389
Johannes Bergf9d15d12014-01-22 11:14:19 +020014390 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014391}
14392
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014393/* send message created by nl80211_build_scan_msg() */
14394void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14395 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014396{
Johannes Berg2a519312009-02-10 21:25:55 +010014397 if (!msg)
14398 return;
14399
Johannes Berg68eb5502013-11-19 15:19:38 +010014400 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014401 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014402}
14403
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014404void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014405{
14406 struct sk_buff *msg;
14407
Thomas Graf58050fc2012-06-28 03:57:45 +000014408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014409 if (!msg)
14410 return;
14411
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014412 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014413 nlmsg_free(msg);
14414 return;
14415 }
14416
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014417 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014418 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014419}
14420
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014421static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14422 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014423{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014424 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014425 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14426 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014427
David S. Miller9360ffd2012-03-29 04:41:26 -040014428 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14429 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14430 NL80211_REGDOM_TYPE_WORLD))
14431 goto nla_put_failure;
14432 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14433 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14434 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14435 goto nla_put_failure;
14436 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14437 request->intersect) {
14438 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14439 NL80211_REGDOM_TYPE_INTERSECTION))
14440 goto nla_put_failure;
14441 } else {
14442 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14443 NL80211_REGDOM_TYPE_COUNTRY) ||
14444 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14445 request->alpha2))
14446 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014447 }
14448
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014449 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14450 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14451
14452 if (wiphy &&
14453 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14454 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014455
14456 if (wiphy &&
14457 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14458 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14459 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014460 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014461
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014462 return true;
14463
14464nla_put_failure:
14465 return false;
14466}
14467
14468/*
14469 * This can happen on global regulatory changes or device specific settings
14470 * based on custom regulatory domains.
14471 */
14472void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14473 struct regulatory_request *request)
14474{
14475 struct sk_buff *msg;
14476 void *hdr;
14477
14478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14479 if (!msg)
14480 return;
14481
14482 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14483 if (!hdr) {
14484 nlmsg_free(msg);
14485 return;
14486 }
14487
14488 if (nl80211_reg_change_event_fill(msg, request) == false)
14489 goto nla_put_failure;
14490
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014491 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014492
Johannes Bergbc43b282009-07-25 10:54:13 +020014493 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014494 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014495 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014496 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014497
14498 return;
14499
14500nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014501 nlmsg_free(msg);
14502}
14503
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014504static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14505 struct net_device *netdev,
14506 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014507 enum nl80211_commands cmd, gfp_t gfp,
14508 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014509{
14510 struct sk_buff *msg;
14511 void *hdr;
14512
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014513 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014514 if (!msg)
14515 return;
14516
14517 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14518 if (!hdr) {
14519 nlmsg_free(msg);
14520 return;
14521 }
14522
David S. Miller9360ffd2012-03-29 04:41:26 -040014523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14525 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
14526 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014527
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014528 if (uapsd_queues >= 0) {
14529 struct nlattr *nla_wmm =
14530 nla_nest_start(msg, NL80211_ATTR_STA_WME);
14531 if (!nla_wmm)
14532 goto nla_put_failure;
14533
14534 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14535 uapsd_queues))
14536 goto nla_put_failure;
14537
14538 nla_nest_end(msg, nla_wmm);
14539 }
14540
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014541 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014542
Johannes Berg68eb5502013-11-19 15:19:38 +010014543 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014544 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014545 return;
14546
14547 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014548 nlmsg_free(msg);
14549}
14550
14551void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014552 struct net_device *netdev, const u8 *buf,
14553 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014554{
14555 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014556 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014557}
14558
14559void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14560 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014561 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014562{
Johannes Berge6d6e342009-07-01 21:26:47 +020014563 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014564 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014565}
14566
Jouni Malinen53b46b82009-03-27 20:53:56 +020014567void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014568 struct net_device *netdev, const u8 *buf,
14569 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014570{
14571 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014572 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014573}
14574
Jouni Malinen53b46b82009-03-27 20:53:56 +020014575void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14576 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014577 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014578{
14579 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014580 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014581}
14582
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014583void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14584 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014585{
Johannes Berg947add32013-02-22 22:05:20 +010014586 struct wireless_dev *wdev = dev->ieee80211_ptr;
14587 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014588 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014589 const struct ieee80211_mgmt *mgmt = (void *)buf;
14590 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014591
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014592 if (WARN_ON(len < 2))
14593 return;
14594
14595 if (ieee80211_is_deauth(mgmt->frame_control))
14596 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14597 else
14598 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14599
14600 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014601 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014602}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014603EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014604
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014605static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14606 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014607 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014608{
14609 struct sk_buff *msg;
14610 void *hdr;
14611
Johannes Berge6d6e342009-07-01 21:26:47 +020014612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014613 if (!msg)
14614 return;
14615
14616 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14617 if (!hdr) {
14618 nlmsg_free(msg);
14619 return;
14620 }
14621
David S. Miller9360ffd2012-03-29 04:41:26 -040014622 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14623 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14624 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14625 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14626 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014627
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014628 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014629
Johannes Berg68eb5502013-11-19 15:19:38 +010014630 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014631 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014632 return;
14633
14634 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014635 nlmsg_free(msg);
14636}
14637
14638void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014639 struct net_device *netdev, const u8 *addr,
14640 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014641{
14642 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014643 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014644}
14645
14646void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014647 struct net_device *netdev, const u8 *addr,
14648 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014649{
Johannes Berge6d6e342009-07-01 21:26:47 +020014650 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14651 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014652}
14653
Samuel Ortizb23aa672009-07-01 21:26:54 +020014654void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014655 struct net_device *netdev,
14656 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014657 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014658{
14659 struct sk_buff *msg;
14660 void *hdr;
14661
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014662 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020014663 cr->fils.kek_len + cr->fils.pmk_len +
14664 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014665 if (!msg)
14666 return;
14667
14668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
14669 if (!hdr) {
14670 nlmsg_free(msg);
14671 return;
14672 }
14673
David S. Miller9360ffd2012-03-29 04:41:26 -040014674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014676 (cr->bssid &&
14677 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030014678 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014679 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
14680 cr->status) ||
14681 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014682 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014683 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
14684 cr->timeout_reason))) ||
14685 (cr->req_ie &&
14686 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
14687 (cr->resp_ie &&
14688 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014689 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020014690 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014691 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020014692 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014693 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020014694 ((cr->fils.kek &&
14695 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
14696 cr->fils.kek)) ||
14697 (cr->fils.pmk &&
14698 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
14699 (cr->fils.pmkid &&
14700 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040014701 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014702
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014703 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014704
Johannes Berg68eb5502013-11-19 15:19:38 +010014705 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014706 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014707 return;
14708
14709 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014710 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014711}
14712
14713void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014714 struct net_device *netdev,
14715 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014716{
14717 struct sk_buff *msg;
14718 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014719 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014720
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014721 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
14722 info->fils.kek_len + info->fils.pmk_len +
14723 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014724 if (!msg)
14725 return;
14726
14727 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
14728 if (!hdr) {
14729 nlmsg_free(msg);
14730 return;
14731 }
14732
David S. Miller9360ffd2012-03-29 04:41:26 -040014733 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14734 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14735 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014736 (info->req_ie &&
14737 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
14738 info->req_ie)) ||
14739 (info->resp_ie &&
14740 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014741 info->resp_ie)) ||
14742 (info->fils.update_erp_next_seq_num &&
14743 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
14744 info->fils.erp_next_seq_num)) ||
14745 (info->fils.kek &&
14746 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
14747 info->fils.kek)) ||
14748 (info->fils.pmk &&
14749 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
14750 (info->fils.pmkid &&
14751 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014752 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014753
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014754 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014755
Johannes Berg68eb5502013-11-19 15:19:38 +010014756 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014757 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014758 return;
14759
14760 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014761 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014762}
14763
Avraham Stern503c1fb2017-09-29 14:21:49 +020014764void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
14765 struct net_device *netdev, const u8 *bssid)
14766{
14767 struct sk_buff *msg;
14768 void *hdr;
14769
14770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14771 if (!msg)
14772 return;
14773
14774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
14775 if (!hdr) {
14776 nlmsg_free(msg);
14777 return;
14778 }
14779
14780 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14781 goto nla_put_failure;
14782
14783 genlmsg_end(msg, hdr);
14784
14785 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14786 NL80211_MCGRP_MLME, GFP_KERNEL);
14787 return;
14788
14789 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020014790 nlmsg_free(msg);
14791}
14792
Samuel Ortizb23aa672009-07-01 21:26:54 +020014793void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
14794 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020014795 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014796{
14797 struct sk_buff *msg;
14798 void *hdr;
14799
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014800 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014801 if (!msg)
14802 return;
14803
14804 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
14805 if (!hdr) {
14806 nlmsg_free(msg);
14807 return;
14808 }
14809
David S. Miller9360ffd2012-03-29 04:41:26 -040014810 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14811 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020014812 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040014813 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
14814 (from_ap &&
14815 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
14816 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
14817 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014818
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014819 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014820
Johannes Berg68eb5502013-11-19 15:19:38 +010014821 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014822 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014823 return;
14824
14825 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014826 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014827}
14828
Johannes Berg04a773a2009-04-19 21:24:32 +020014829void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
14830 struct net_device *netdev, const u8 *bssid,
14831 gfp_t gfp)
14832{
14833 struct sk_buff *msg;
14834 void *hdr;
14835
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014836 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014837 if (!msg)
14838 return;
14839
14840 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
14841 if (!hdr) {
14842 nlmsg_free(msg);
14843 return;
14844 }
14845
David S. Miller9360ffd2012-03-29 04:41:26 -040014846 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14847 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14848 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14849 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020014850
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014851 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020014852
Johannes Berg68eb5502013-11-19 15:19:38 +010014853 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014854 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014855 return;
14856
14857 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020014858 nlmsg_free(msg);
14859}
14860
Johannes Berg947add32013-02-22 22:05:20 +010014861void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040014862 const u8 *ie, u8 ie_len,
14863 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070014864{
Johannes Berg947add32013-02-22 22:05:20 +010014865 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014866 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014867 struct sk_buff *msg;
14868 void *hdr;
14869
Johannes Berg947add32013-02-22 22:05:20 +010014870 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14871 return;
14872
14873 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14874
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014875 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014876 if (!msg)
14877 return;
14878
14879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14880 if (!hdr) {
14881 nlmsg_free(msg);
14882 return;
14883 }
14884
David S. Miller9360ffd2012-03-29 04:41:26 -040014885 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014886 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14887 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014888 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040014889 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
14890 (sig_dbm &&
14891 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014892 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014893
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014894 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014895
Johannes Berg68eb5502013-11-19 15:19:38 +010014896 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014897 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014898 return;
14899
14900 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070014901 nlmsg_free(msg);
14902}
Johannes Berg947add32013-02-22 22:05:20 +010014903EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014904
Jouni Malinena3b8b052009-03-27 21:59:49 +020014905void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14906 struct net_device *netdev, const u8 *addr,
14907 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014908 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014909{
14910 struct sk_buff *msg;
14911 void *hdr;
14912
Johannes Berge6d6e342009-07-01 21:26:47 +020014913 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014914 if (!msg)
14915 return;
14916
14917 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14918 if (!hdr) {
14919 nlmsg_free(msg);
14920 return;
14921 }
14922
David S. Miller9360ffd2012-03-29 04:41:26 -040014923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14924 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14925 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14926 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14927 (key_id != -1 &&
14928 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14929 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14930 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014931
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014932 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014933
Johannes Berg68eb5502013-11-19 15:19:38 +010014934 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014935 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014936 return;
14937
14938 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020014939 nlmsg_free(msg);
14940}
14941
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014942void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14943 struct ieee80211_channel *channel_before,
14944 struct ieee80211_channel *channel_after)
14945{
14946 struct sk_buff *msg;
14947 void *hdr;
14948 struct nlattr *nl_freq;
14949
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014951 if (!msg)
14952 return;
14953
14954 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14955 if (!hdr) {
14956 nlmsg_free(msg);
14957 return;
14958 }
14959
14960 /*
14961 * Since we are applying the beacon hint to a wiphy we know its
14962 * wiphy_idx is valid
14963 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014964 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14965 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014966
14967 /* Before */
14968 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14969 if (!nl_freq)
14970 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014971
14972 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014973 goto nla_put_failure;
14974 nla_nest_end(msg, nl_freq);
14975
14976 /* After */
14977 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14978 if (!nl_freq)
14979 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014980
14981 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014982 goto nla_put_failure;
14983 nla_nest_end(msg, nl_freq);
14984
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014985 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014986
Johannes Berg463d0182009-07-14 00:33:35 +020014987 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014988 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014989 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014990 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014991
14992 return;
14993
14994nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014995 nlmsg_free(msg);
14996}
14997
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014998static void nl80211_send_remain_on_chan_event(
14999 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015000 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015001 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015002 unsigned int duration, gfp_t gfp)
15003{
15004 struct sk_buff *msg;
15005 void *hdr;
15006
15007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15008 if (!msg)
15009 return;
15010
15011 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15012 if (!hdr) {
15013 nlmsg_free(msg);
15014 return;
15015 }
15016
David S. Miller9360ffd2012-03-29 04:41:26 -040015017 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015018 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15019 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015020 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15021 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015022 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015023 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15024 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015025 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15026 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015027 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015028
David S. Miller9360ffd2012-03-29 04:41:26 -040015029 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15030 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15031 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015032
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015033 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015034
Johannes Berg68eb5502013-11-19 15:19:38 +010015035 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015036 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015037 return;
15038
15039 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015040 nlmsg_free(msg);
15041}
15042
Johannes Berg947add32013-02-22 22:05:20 +010015043void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15044 struct ieee80211_channel *chan,
15045 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015046{
Johannes Berg947add32013-02-22 22:05:20 +010015047 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015048 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015049
15050 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015051 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015052 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015053 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015054}
Johannes Berg947add32013-02-22 22:05:20 +010015055EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015056
Johannes Berg947add32013-02-22 22:05:20 +010015057void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15058 struct ieee80211_channel *chan,
15059 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015060{
Johannes Berg947add32013-02-22 22:05:20 +010015061 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015062 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015063
15064 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015065 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015066 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015067}
Johannes Berg947add32013-02-22 22:05:20 +010015068EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015069
Johannes Berg947add32013-02-22 22:05:20 +010015070void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15071 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015072{
Johannes Berg947add32013-02-22 22:05:20 +010015073 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015074 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015075 struct sk_buff *msg;
15076
Johannes Berg947add32013-02-22 22:05:20 +010015077 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15078
Thomas Graf58050fc2012-06-28 03:57:45 +000015079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015080 if (!msg)
15081 return;
15082
Johannes Bergcf5ead82014-11-14 17:14:00 +010015083 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015084 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015085 nlmsg_free(msg);
15086 return;
15087 }
15088
Johannes Berg68eb5502013-11-19 15:19:38 +010015089 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015090 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015091}
Johannes Berg947add32013-02-22 22:05:20 +010015092EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015093
Johannes Bergcf5ead82014-11-14 17:14:00 +010015094void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15095 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015096{
Johannes Berg947add32013-02-22 22:05:20 +010015097 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015098 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015099 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015100 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015101
Johannes Berg73887fd2018-05-18 09:57:55 +020015102 if (!sinfo)
15103 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015104
Johannes Berg947add32013-02-22 22:05:20 +010015105 trace_cfg80211_del_sta(dev, mac_addr);
15106
Thomas Graf58050fc2012-06-28 03:57:45 +000015107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015108 if (!msg) {
15109 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015110 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015111 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015112
Johannes Bergcf5ead82014-11-14 17:14:00 +010015113 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015114 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015115 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015116 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015117 }
15118
Johannes Berg68eb5502013-11-19 15:19:38 +010015119 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015120 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015121}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015122EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015123
Johannes Berg947add32013-02-22 22:05:20 +010015124void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15125 enum nl80211_connect_failed_reason reason,
15126 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015127{
Johannes Berg947add32013-02-22 22:05:20 +010015128 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015129 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015130 struct sk_buff *msg;
15131 void *hdr;
15132
15133 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15134 if (!msg)
15135 return;
15136
15137 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15138 if (!hdr) {
15139 nlmsg_free(msg);
15140 return;
15141 }
15142
15143 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15145 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15146 goto nla_put_failure;
15147
15148 genlmsg_end(msg, hdr);
15149
Johannes Berg68eb5502013-11-19 15:19:38 +010015150 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015151 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015152 return;
15153
15154 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015155 nlmsg_free(msg);
15156}
Johannes Berg947add32013-02-22 22:05:20 +010015157EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015158
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015159static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15160 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015161{
15162 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015163 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015164 struct sk_buff *msg;
15165 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015166 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015167
Eric W. Biederman15e47302012-09-07 20:12:54 +000015168 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015169 return false;
15170
15171 msg = nlmsg_new(100, gfp);
15172 if (!msg)
15173 return true;
15174
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015175 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015176 if (!hdr) {
15177 nlmsg_free(msg);
15178 return true;
15179 }
15180
David S. Miller9360ffd2012-03-29 04:41:26 -040015181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15182 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15183 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15184 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015185
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015186 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015187 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015188 return true;
15189
15190 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015191 nlmsg_free(msg);
15192 return true;
15193}
15194
Johannes Berg947add32013-02-22 22:05:20 +010015195bool cfg80211_rx_spurious_frame(struct net_device *dev,
15196 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015197{
Johannes Berg947add32013-02-22 22:05:20 +010015198 struct wireless_dev *wdev = dev->ieee80211_ptr;
15199 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015200
Johannes Berg947add32013-02-22 22:05:20 +010015201 trace_cfg80211_rx_spurious_frame(dev, addr);
15202
15203 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15204 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15205 trace_cfg80211_return_bool(false);
15206 return false;
15207 }
15208 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15209 addr, gfp);
15210 trace_cfg80211_return_bool(ret);
15211 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015212}
Johannes Berg947add32013-02-22 22:05:20 +010015213EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15214
15215bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15216 const u8 *addr, gfp_t gfp)
15217{
15218 struct wireless_dev *wdev = dev->ieee80211_ptr;
15219 bool ret;
15220
15221 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15222
15223 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15224 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15225 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15226 trace_cfg80211_return_bool(false);
15227 return false;
15228 }
15229 ret = __nl80211_unexpected_frame(dev,
15230 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15231 addr, gfp);
15232 trace_cfg80211_return_bool(ret);
15233 return ret;
15234}
15235EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015236
Johannes Berg2e161f782010-08-12 15:38:38 +020015237int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015238 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015239 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015240 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015241{
Johannes Berg71bbc992012-06-15 15:30:18 +020015242 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015243 struct sk_buff *msg;
15244 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015245
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015246 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015247 if (!msg)
15248 return -ENOMEM;
15249
Johannes Berg2e161f782010-08-12 15:38:38 +020015250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015251 if (!hdr) {
15252 nlmsg_free(msg);
15253 return -ENOMEM;
15254 }
15255
David S. Miller9360ffd2012-03-29 04:41:26 -040015256 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015257 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15258 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015259 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15260 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015261 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15262 (sig_dbm &&
15263 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015264 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15265 (flags &&
15266 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015267 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015268
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015269 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015270
Eric W. Biederman15e47302012-09-07 20:12:54 +000015271 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015272
15273 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015274 nlmsg_free(msg);
15275 return -ENOBUFS;
15276}
15277
Johannes Berg947add32013-02-22 22:05:20 +010015278void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15279 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015280{
Johannes Berg947add32013-02-22 22:05:20 +010015281 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015283 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015284 struct sk_buff *msg;
15285 void *hdr;
15286
Johannes Berg947add32013-02-22 22:05:20 +010015287 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15288
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015289 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015290 if (!msg)
15291 return;
15292
Johannes Berg2e161f782010-08-12 15:38:38 +020015293 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015294 if (!hdr) {
15295 nlmsg_free(msg);
15296 return;
15297 }
15298
David S. Miller9360ffd2012-03-29 04:41:26 -040015299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015300 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15301 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015302 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15303 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015304 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015305 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15306 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015307 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15308 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015309
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015310 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015311
Johannes Berg68eb5502013-11-19 15:19:38 +010015312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015313 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015314 return;
15315
15316 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015317 nlmsg_free(msg);
15318}
Johannes Berg947add32013-02-22 22:05:20 +010015319EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015320
Denis Kenzior6a671a52018-03-26 12:52:41 -050015321static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015322 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015323 bool unencrypted, gfp_t gfp)
15324{
15325 struct wireless_dev *wdev = dev->ieee80211_ptr;
15326 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015327 struct ethhdr *ehdr = eth_hdr(skb);
15328 const u8 *addr = ehdr->h_source;
15329 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015330 struct sk_buff *msg;
15331 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015332 struct nlattr *frame;
15333
Denis Kenzior6a671a52018-03-26 12:52:41 -050015334 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15335
15336 if (!nlportid)
15337 return -ENOENT;
15338
Denis Kenziora948f712018-07-03 15:05:48 -050015339 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015340 if (!msg)
15341 return -ENOMEM;
15342
15343 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15344 if (!hdr) {
15345 nlmsg_free(msg);
15346 return -ENOBUFS;
15347 }
15348
15349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15350 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15351 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15352 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015353 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15354 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15355 (unencrypted && nla_put_flag(msg,
15356 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15357 goto nla_put_failure;
15358
Denis Kenziora948f712018-07-03 15:05:48 -050015359 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15360 if (!frame)
15361 goto nla_put_failure;
15362
15363 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015364 genlmsg_end(msg, hdr);
15365
15366 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15367
15368 nla_put_failure:
15369 nlmsg_free(msg);
15370 return -ENOBUFS;
15371}
15372
15373bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015374 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015375{
15376 int ret;
15377
Denis Kenziora948f712018-07-03 15:05:48 -050015378 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15379 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015380 trace_cfg80211_return_bool(ret == 0);
15381 return ret == 0;
15382}
15383EXPORT_SYMBOL(cfg80211_rx_control_port);
15384
Johannes Berg5b97f492014-11-26 12:37:43 +010015385static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15386 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015387{
Johannes Berg947add32013-02-22 22:05:20 +010015388 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015389 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15390 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15391 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015392
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015393 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015394 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015395
Johannes Berg5b97f492014-11-26 12:37:43 +010015396 cb = (void **)msg->cb;
15397
15398 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15399 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015400 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015401 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015402 }
15403
David S. Miller9360ffd2012-03-29 04:41:26 -040015404 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015405 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015406 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015407
Johannes Berg5b97f492014-11-26 12:37:43 +010015408 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015409 goto nla_put_failure;
15410
Johannes Berg5b97f492014-11-26 12:37:43 +010015411 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
15412 if (!cb[1])
15413 goto nla_put_failure;
15414
15415 cb[2] = rdev;
15416
15417 return msg;
15418 nla_put_failure:
15419 nlmsg_free(msg);
15420 return NULL;
15421}
15422
15423static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15424{
15425 void **cb = (void **)msg->cb;
15426 struct cfg80211_registered_device *rdev = cb[2];
15427
15428 nla_nest_end(msg, cb[1]);
15429 genlmsg_end(msg, cb[0]);
15430
15431 memset(msg->cb, 0, sizeof(msg->cb));
15432
15433 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15434 NL80211_MCGRP_MLME, gfp);
15435}
15436
15437void cfg80211_cqm_rssi_notify(struct net_device *dev,
15438 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015439 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015440{
15441 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015442 struct wireless_dev *wdev = dev->ieee80211_ptr;
15443 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015444
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015445 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015446
Johannes Berg98f03342014-11-26 12:42:02 +010015447 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15448 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15449 return;
15450
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015451 if (wdev->cqm_config) {
15452 wdev->cqm_config->last_rssi_event_value = rssi_level;
15453
15454 cfg80211_cqm_rssi_update(rdev, dev);
15455
15456 if (rssi_level == 0)
15457 rssi_level = wdev->cqm_config->last_rssi_event_value;
15458 }
15459
Johannes Berg5b97f492014-11-26 12:37:43 +010015460 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15461 if (!msg)
15462 return;
15463
David S. Miller9360ffd2012-03-29 04:41:26 -040015464 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15465 rssi_event))
15466 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015467
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015468 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15469 rssi_level))
15470 goto nla_put_failure;
15471
Johannes Berg5b97f492014-11-26 12:37:43 +010015472 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015473
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015474 return;
15475
15476 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015477 nlmsg_free(msg);
15478}
Johannes Berg947add32013-02-22 22:05:20 +010015479EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015480
Johannes Berg5b97f492014-11-26 12:37:43 +010015481void cfg80211_cqm_txe_notify(struct net_device *dev,
15482 const u8 *peer, u32 num_packets,
15483 u32 rate, u32 intvl, gfp_t gfp)
15484{
15485 struct sk_buff *msg;
15486
15487 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15488 if (!msg)
15489 return;
15490
15491 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15492 goto nla_put_failure;
15493
15494 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15495 goto nla_put_failure;
15496
15497 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15498 goto nla_put_failure;
15499
15500 cfg80211_send_cqm(msg, gfp);
15501 return;
15502
15503 nla_put_failure:
15504 nlmsg_free(msg);
15505}
15506EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15507
15508void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15509 const u8 *peer, u32 num_packets, gfp_t gfp)
15510{
15511 struct sk_buff *msg;
15512
15513 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15514
15515 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15516 if (!msg)
15517 return;
15518
15519 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15520 goto nla_put_failure;
15521
15522 cfg80211_send_cqm(msg, gfp);
15523 return;
15524
15525 nla_put_failure:
15526 nlmsg_free(msg);
15527}
15528EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15529
Johannes Berg98f03342014-11-26 12:42:02 +010015530void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15531{
15532 struct sk_buff *msg;
15533
15534 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15535 if (!msg)
15536 return;
15537
15538 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15539 goto nla_put_failure;
15540
15541 cfg80211_send_cqm(msg, gfp);
15542 return;
15543
15544 nla_put_failure:
15545 nlmsg_free(msg);
15546}
15547EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15548
Johannes Berg947add32013-02-22 22:05:20 +010015549static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15550 struct net_device *netdev, const u8 *bssid,
15551 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015552{
15553 struct sk_buff *msg;
15554 struct nlattr *rekey_attr;
15555 void *hdr;
15556
Thomas Graf58050fc2012-06-28 03:57:45 +000015557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015558 if (!msg)
15559 return;
15560
15561 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15562 if (!hdr) {
15563 nlmsg_free(msg);
15564 return;
15565 }
15566
David S. Miller9360ffd2012-03-29 04:41:26 -040015567 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15568 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15569 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15570 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015571
15572 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
15573 if (!rekey_attr)
15574 goto nla_put_failure;
15575
David S. Miller9360ffd2012-03-29 04:41:26 -040015576 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15577 NL80211_REPLAY_CTR_LEN, replay_ctr))
15578 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015579
15580 nla_nest_end(msg, rekey_attr);
15581
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015582 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015583
Johannes Berg68eb5502013-11-19 15:19:38 +010015584 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015585 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015586 return;
15587
15588 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015589 nlmsg_free(msg);
15590}
15591
Johannes Berg947add32013-02-22 22:05:20 +010015592void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15593 const u8 *replay_ctr, gfp_t gfp)
15594{
15595 struct wireless_dev *wdev = dev->ieee80211_ptr;
15596 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015597 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015598
15599 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15600 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15601}
15602EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15603
15604static void
15605nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15606 struct net_device *netdev, int index,
15607 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015608{
15609 struct sk_buff *msg;
15610 struct nlattr *attr;
15611 void *hdr;
15612
Thomas Graf58050fc2012-06-28 03:57:45 +000015613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015614 if (!msg)
15615 return;
15616
15617 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15618 if (!hdr) {
15619 nlmsg_free(msg);
15620 return;
15621 }
15622
David S. Miller9360ffd2012-03-29 04:41:26 -040015623 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15624 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15625 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015626
15627 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
15628 if (!attr)
15629 goto nla_put_failure;
15630
David S. Miller9360ffd2012-03-29 04:41:26 -040015631 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15632 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15633 (preauth &&
15634 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15635 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015636
15637 nla_nest_end(msg, attr);
15638
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015639 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015640
Johannes Berg68eb5502013-11-19 15:19:38 +010015641 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015642 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015643 return;
15644
15645 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015646 nlmsg_free(msg);
15647}
15648
Johannes Berg947add32013-02-22 22:05:20 +010015649void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
15650 const u8 *bssid, bool preauth, gfp_t gfp)
15651{
15652 struct wireless_dev *wdev = dev->ieee80211_ptr;
15653 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015655
15656 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
15657 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
15658}
15659EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
15660
15661static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
15662 struct net_device *netdev,
15663 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020015664 gfp_t gfp,
15665 enum nl80211_commands notif,
15666 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070015667{
15668 struct sk_buff *msg;
15669 void *hdr;
15670
Thomas Graf58050fc2012-06-28 03:57:45 +000015671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015672 if (!msg)
15673 return;
15674
Luciano Coelhof8d75522014-11-07 14:31:35 +020015675 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070015676 if (!hdr) {
15677 nlmsg_free(msg);
15678 return;
15679 }
15680
Johannes Berg683b6d32012-11-08 21:25:48 +010015681 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15682 goto nla_put_failure;
15683
15684 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040015685 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070015686
Luciano Coelhof8d75522014-11-07 14:31:35 +020015687 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
15688 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
15689 goto nla_put_failure;
15690
Thomas Pedersen53145262012-04-06 13:35:47 -070015691 genlmsg_end(msg, hdr);
15692
Johannes Berg68eb5502013-11-19 15:19:38 +010015693 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015694 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015695 return;
15696
15697 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070015698 nlmsg_free(msg);
15699}
15700
Johannes Berg947add32013-02-22 22:05:20 +010015701void cfg80211_ch_switch_notify(struct net_device *dev,
15702 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070015703{
Johannes Berg947add32013-02-22 22:05:20 +010015704 struct wireless_dev *wdev = dev->ieee80211_ptr;
15705 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015706 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015707
Simon Wunderliche487eae2013-11-21 18:19:51 +010015708 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010015709
Simon Wunderliche487eae2013-11-21 18:19:51 +010015710 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010015711
Michal Kazior9e0e2962014-01-29 14:22:27 +010015712 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010015713 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020015714 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15715 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010015716}
15717EXPORT_SYMBOL(cfg80211_ch_switch_notify);
15718
Luciano Coelhof8d75522014-11-07 14:31:35 +020015719void cfg80211_ch_switch_started_notify(struct net_device *dev,
15720 struct cfg80211_chan_def *chandef,
15721 u8 count)
15722{
15723 struct wireless_dev *wdev = dev->ieee80211_ptr;
15724 struct wiphy *wiphy = wdev->wiphy;
15725 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15726
15727 trace_cfg80211_ch_switch_started_notify(dev, chandef);
15728
15729 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15730 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
15731}
15732EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
15733
Thomas Pedersen84f10702012-07-12 16:17:33 -070015734void
Simon Wunderlich04f39042013-02-08 18:16:19 +010015735nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010015736 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015737 enum nl80211_radar_event event,
15738 struct net_device *netdev, gfp_t gfp)
15739{
15740 struct sk_buff *msg;
15741 void *hdr;
15742
15743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15744 if (!msg)
15745 return;
15746
15747 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
15748 if (!hdr) {
15749 nlmsg_free(msg);
15750 return;
15751 }
15752
15753 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15754 goto nla_put_failure;
15755
15756 /* NOP and radar events don't need a netdev parameter */
15757 if (netdev) {
15758 struct wireless_dev *wdev = netdev->ieee80211_ptr;
15759
15760 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015761 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15762 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010015763 goto nla_put_failure;
15764 }
15765
15766 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
15767 goto nla_put_failure;
15768
15769 if (nl80211_send_chandef(msg, chandef))
15770 goto nla_put_failure;
15771
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015772 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015773
Johannes Berg68eb5502013-11-19 15:19:38 +010015774 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015775 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015776 return;
15777
15778 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010015779 nlmsg_free(msg);
15780}
15781
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053015782void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
15783 struct sta_opmode_info *sta_opmode,
15784 gfp_t gfp)
15785{
15786 struct sk_buff *msg;
15787 struct wireless_dev *wdev = dev->ieee80211_ptr;
15788 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15789 void *hdr;
15790
15791 if (WARN_ON(!mac))
15792 return;
15793
15794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15795 if (!msg)
15796 return;
15797
15798 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
15799 if (!hdr) {
15800 nlmsg_free(msg);
15801 return;
15802 }
15803
15804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15805 goto nla_put_failure;
15806
15807 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15808 goto nla_put_failure;
15809
15810 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15811 goto nla_put_failure;
15812
15813 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
15814 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
15815 goto nla_put_failure;
15816
15817 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
15818 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
15819 goto nla_put_failure;
15820
15821 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
15822 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
15823 goto nla_put_failure;
15824
15825 genlmsg_end(msg, hdr);
15826
15827 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15828 NL80211_MCGRP_MLME, gfp);
15829
15830 return;
15831
15832nla_put_failure:
15833 nlmsg_free(msg);
15834}
15835EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
15836
Johannes Berg7f6cf312011-11-04 11:18:15 +010015837void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015838 u64 cookie, bool acked, s32 ack_signal,
15839 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010015840{
15841 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015842 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015843 struct sk_buff *msg;
15844 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015845
Beni Lev4ee3e062012-08-27 12:49:39 +030015846 trace_cfg80211_probe_status(dev, addr, cookie, acked);
15847
Thomas Graf58050fc2012-06-28 03:57:45 +000015848 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030015849
Johannes Berg7f6cf312011-11-04 11:18:15 +010015850 if (!msg)
15851 return;
15852
15853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
15854 if (!hdr) {
15855 nlmsg_free(msg);
15856 return;
15857 }
15858
David S. Miller9360ffd2012-03-29 04:41:26 -040015859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015862 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15863 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015864 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
15865 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
15866 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015867 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015868
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015869 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015870
Johannes Berg68eb5502013-11-19 15:19:38 +010015871 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015872 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015873 return;
15874
15875 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010015876 nlmsg_free(msg);
15877}
15878EXPORT_SYMBOL(cfg80211_probe_status);
15879
Johannes Berg5e760232011-11-04 11:18:17 +010015880void cfg80211_report_obss_beacon(struct wiphy *wiphy,
15881 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070015882 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010015883{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015884 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010015885 struct sk_buff *msg;
15886 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070015887 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010015888
Beni Lev4ee3e062012-08-27 12:49:39 +030015889 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
15890
Ben Greear37c73b52012-10-26 14:49:25 -070015891 spin_lock_bh(&rdev->beacon_registrations_lock);
15892 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
15893 msg = nlmsg_new(len + 100, GFP_ATOMIC);
15894 if (!msg) {
15895 spin_unlock_bh(&rdev->beacon_registrations_lock);
15896 return;
15897 }
Johannes Berg5e760232011-11-04 11:18:17 +010015898
Ben Greear37c73b52012-10-26 14:49:25 -070015899 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15900 if (!hdr)
15901 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010015902
Ben Greear37c73b52012-10-26 14:49:25 -070015903 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15904 (freq &&
15905 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
15906 (sig_dbm &&
15907 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15908 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
15909 goto nla_put_failure;
15910
15911 genlmsg_end(msg, hdr);
15912
15913 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010015914 }
Ben Greear37c73b52012-10-26 14:49:25 -070015915 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015916 return;
15917
15918 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070015919 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015920 nlmsg_free(msg);
15921}
15922EXPORT_SYMBOL(cfg80211_report_obss_beacon);
15923
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015924#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015925static int cfg80211_net_detect_results(struct sk_buff *msg,
15926 struct cfg80211_wowlan_wakeup *wakeup)
15927{
15928 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
15929 struct nlattr *nl_results, *nl_match, *nl_freqs;
15930 int i, j;
15931
15932 nl_results = nla_nest_start(
15933 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15934 if (!nl_results)
15935 return -EMSGSIZE;
15936
15937 for (i = 0; i < nd->n_matches; i++) {
15938 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15939
15940 nl_match = nla_nest_start(msg, i);
15941 if (!nl_match)
15942 break;
15943
15944 /* The SSID attribute is optional in nl80211, but for
15945 * simplicity reasons it's always present in the
15946 * cfg80211 structure. If a driver can't pass the
15947 * SSID, that needs to be changed. A zero length SSID
15948 * is still a valid SSID (wildcard), so it cannot be
15949 * used for this purpose.
15950 */
15951 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
15952 match->ssid.ssid)) {
15953 nla_nest_cancel(msg, nl_match);
15954 goto out;
15955 }
15956
15957 if (match->n_channels) {
15958 nl_freqs = nla_nest_start(
15959 msg, NL80211_ATTR_SCAN_FREQUENCIES);
15960 if (!nl_freqs) {
15961 nla_nest_cancel(msg, nl_match);
15962 goto out;
15963 }
15964
15965 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020015966 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015967 nla_nest_cancel(msg, nl_freqs);
15968 nla_nest_cancel(msg, nl_match);
15969 goto out;
15970 }
15971 }
15972
15973 nla_nest_end(msg, nl_freqs);
15974 }
15975
15976 nla_nest_end(msg, nl_match);
15977 }
15978
15979out:
15980 nla_nest_end(msg, nl_results);
15981 return 0;
15982}
15983
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015984void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15985 struct cfg80211_wowlan_wakeup *wakeup,
15986 gfp_t gfp)
15987{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015988 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015989 struct sk_buff *msg;
15990 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015991 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015992
15993 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15994
15995 if (wakeup)
15996 size += wakeup->packet_present_len;
15997
15998 msg = nlmsg_new(size, gfp);
15999 if (!msg)
16000 return;
16001
16002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16003 if (!hdr)
16004 goto free_msg;
16005
16006 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016007 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16008 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016009 goto free_msg;
16010
16011 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16012 wdev->netdev->ifindex))
16013 goto free_msg;
16014
16015 if (wakeup) {
16016 struct nlattr *reasons;
16017
16018 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016019 if (!reasons)
16020 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016021
16022 if (wakeup->disconnect &&
16023 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16024 goto free_msg;
16025 if (wakeup->magic_pkt &&
16026 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16027 goto free_msg;
16028 if (wakeup->gtk_rekey_failure &&
16029 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16030 goto free_msg;
16031 if (wakeup->eap_identity_req &&
16032 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16033 goto free_msg;
16034 if (wakeup->four_way_handshake &&
16035 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16036 goto free_msg;
16037 if (wakeup->rfkill_release &&
16038 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16039 goto free_msg;
16040
16041 if (wakeup->pattern_idx >= 0 &&
16042 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16043 wakeup->pattern_idx))
16044 goto free_msg;
16045
Johannes Bergae917c92013-10-25 11:05:22 +020016046 if (wakeup->tcp_match &&
16047 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16048 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016049
Johannes Bergae917c92013-10-25 11:05:22 +020016050 if (wakeup->tcp_connlost &&
16051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16052 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016053
Johannes Bergae917c92013-10-25 11:05:22 +020016054 if (wakeup->tcp_nomoretokens &&
16055 nla_put_flag(msg,
16056 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16057 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016058
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016059 if (wakeup->packet) {
16060 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16061 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16062
16063 if (!wakeup->packet_80211) {
16064 pkt_attr =
16065 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16066 len_attr =
16067 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16068 }
16069
16070 if (wakeup->packet_len &&
16071 nla_put_u32(msg, len_attr, wakeup->packet_len))
16072 goto free_msg;
16073
16074 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16075 wakeup->packet))
16076 goto free_msg;
16077 }
16078
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016079 if (wakeup->net_detect &&
16080 cfg80211_net_detect_results(msg, wakeup))
16081 goto free_msg;
16082
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016083 nla_nest_end(msg, reasons);
16084 }
16085
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016086 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016087
Johannes Berg68eb5502013-11-19 15:19:38 +010016088 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016089 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016090 return;
16091
16092 free_msg:
16093 nlmsg_free(msg);
16094}
16095EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16096#endif
16097
Jouni Malinen3475b092012-11-16 22:49:57 +020016098void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16099 enum nl80211_tdls_operation oper,
16100 u16 reason_code, gfp_t gfp)
16101{
16102 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016103 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016104 struct sk_buff *msg;
16105 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016106
16107 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16108 reason_code);
16109
16110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16111 if (!msg)
16112 return;
16113
16114 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16115 if (!hdr) {
16116 nlmsg_free(msg);
16117 return;
16118 }
16119
16120 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16121 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16122 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16123 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16124 (reason_code > 0 &&
16125 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16126 goto nla_put_failure;
16127
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016128 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016129
Johannes Berg68eb5502013-11-19 15:19:38 +010016130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016131 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016132 return;
16133
16134 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016135 nlmsg_free(msg);
16136}
16137EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16138
Jouni Malinen026331c2010-02-15 12:53:10 +020016139static int nl80211_netlink_notify(struct notifier_block * nb,
16140 unsigned long state,
16141 void *_notify)
16142{
16143 struct netlink_notify *notify = _notify;
16144 struct cfg80211_registered_device *rdev;
16145 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016146 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016147
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016148 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016149 return NOTIFY_DONE;
16150
16151 rcu_read_lock();
16152
Johannes Berg5e760232011-11-04 11:18:17 +010016153 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016154 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016155
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016156 list_for_each_entry_rcu(sched_scan_req,
16157 &rdev->sched_scan_req_list,
16158 list) {
16159 if (sched_scan_req->owner_nlportid == notify->portid) {
16160 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010016161 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016162 }
Johannes Berg753aacf2017-01-05 10:57:14 +010016163 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016164
Johannes Berg53873f12016-05-03 16:52:04 +030016165 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016166 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016167
Johannes Bergab810072017-04-26 07:43:41 +020016168 if (wdev->owner_nlportid == notify->portid) {
16169 wdev->nl_owner_dead = true;
16170 schedule_work(&rdev->destroy_work);
16171 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016172 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016173 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016174
16175 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016176 }
16177
Ben Greear37c73b52012-10-26 14:49:25 -070016178 spin_lock_bh(&rdev->beacon_registrations_lock);
16179 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16180 list) {
16181 if (reg->nlportid == notify->portid) {
16182 list_del(&reg->list);
16183 kfree(reg);
16184 break;
16185 }
16186 }
16187 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016188 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016189
16190 rcu_read_unlock();
16191
Ilan peer05050752015-03-04 00:32:06 -050016192 /*
16193 * It is possible that the user space process that is controlling the
16194 * indoor setting disappeared, so notify the regulatory core.
16195 */
16196 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016197 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016198}
16199
16200static struct notifier_block nl80211_netlink_notifier = {
16201 .notifier_call = nl80211_netlink_notify,
16202};
16203
Jouni Malinen355199e2013-02-27 17:14:27 +020016204void cfg80211_ft_event(struct net_device *netdev,
16205 struct cfg80211_ft_event_params *ft_event)
16206{
16207 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016208 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016209 struct sk_buff *msg;
16210 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016211
16212 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16213
16214 if (!ft_event->target_ap)
16215 return;
16216
Dedy Lansky1039d082018-05-17 16:25:03 +030016217 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16218 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016219 if (!msg)
16220 return;
16221
16222 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016223 if (!hdr)
16224 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016225
Johannes Bergae917c92013-10-25 11:05:22 +020016226 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16227 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16228 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16229 goto out;
16230
16231 if (ft_event->ies &&
16232 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16233 goto out;
16234 if (ft_event->ric_ies &&
16235 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16236 ft_event->ric_ies))
16237 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016238
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016239 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016240
Johannes Berg68eb5502013-11-19 15:19:38 +010016241 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016242 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016243 return;
16244 out:
16245 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016246}
16247EXPORT_SYMBOL(cfg80211_ft_event);
16248
Arend van Spriel5de17982013-04-18 15:49:00 +020016249void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16250{
16251 struct cfg80211_registered_device *rdev;
16252 struct sk_buff *msg;
16253 void *hdr;
16254 u32 nlportid;
16255
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016256 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016257 if (!rdev->crit_proto_nlportid)
16258 return;
16259
16260 nlportid = rdev->crit_proto_nlportid;
16261 rdev->crit_proto_nlportid = 0;
16262
16263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16264 if (!msg)
16265 return;
16266
16267 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16268 if (!hdr)
16269 goto nla_put_failure;
16270
16271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016272 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16273 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016274 goto nla_put_failure;
16275
16276 genlmsg_end(msg, hdr);
16277
16278 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16279 return;
16280
16281 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016282 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016283}
16284EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16285
Johannes Berg348baf02014-01-24 14:06:29 +010016286void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16287{
16288 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016289 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016290 struct sk_buff *msg;
16291 void *hdr;
16292
16293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16294 if (!msg)
16295 return;
16296
16297 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16298 if (!hdr)
16299 goto out;
16300
16301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16302 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016303 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16304 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016305 goto out;
16306
16307 genlmsg_end(msg, hdr);
16308
16309 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16310 NL80211_MCGRP_MLME, GFP_KERNEL);
16311 return;
16312 out:
16313 nlmsg_free(msg);
16314}
16315
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016316int cfg80211_external_auth_request(struct net_device *dev,
16317 struct cfg80211_external_auth_params *params,
16318 gfp_t gfp)
16319{
16320 struct wireless_dev *wdev = dev->ieee80211_ptr;
16321 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16322 struct sk_buff *msg;
16323 void *hdr;
16324
16325 if (!wdev->conn_owner_nlportid)
16326 return -EINVAL;
16327
16328 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16329 if (!msg)
16330 return -ENOMEM;
16331
16332 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16333 if (!hdr)
16334 goto nla_put_failure;
16335
16336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16337 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16338 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16339 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16340 params->action) ||
16341 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16342 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16343 params->ssid.ssid))
16344 goto nla_put_failure;
16345
16346 genlmsg_end(msg, hdr);
16347 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16348 wdev->conn_owner_nlportid);
16349 return 0;
16350
16351 nla_put_failure:
16352 nlmsg_free(msg);
16353 return -ENOBUFS;
16354}
16355EXPORT_SYMBOL(cfg80211_external_auth_request);
16356
Johannes Berg55682962007-09-20 13:09:35 -040016357/* initialisation/exit functions */
16358
Johannes Berg56989f62016-10-24 14:40:05 +020016359int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016360{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016361 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016362
Johannes Berg489111e2016-10-24 14:40:03 +020016363 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016364 if (err)
16365 return err;
16366
Jouni Malinen026331c2010-02-15 12:53:10 +020016367 err = netlink_register_notifier(&nl80211_netlink_notifier);
16368 if (err)
16369 goto err_out;
16370
Johannes Berg55682962007-09-20 13:09:35 -040016371 return 0;
16372 err_out:
16373 genl_unregister_family(&nl80211_fam);
16374 return err;
16375}
16376
16377void nl80211_exit(void)
16378{
Jouni Malinen026331c2010-02-15 12:53:10 +020016379 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016380 genl_unregister_family(&nl80211_fam);
16381}