blob: 5e49492d5911d816c85bdec83af843e0a5235c1c [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),
Johannes Berg55682962007-09-20 13:09:35 -0400560};
561
Johannes Berge31b8212010-10-05 19:39:30 +0200562/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000563static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200564 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200565 [NL80211_KEY_IDX] = { .type = NLA_U8 },
566 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200567 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200568 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
569 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200570 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100571 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
572};
573
574/* policy for the key default flags */
575static const struct nla_policy
576nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
577 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
578 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200579};
580
Johannes Bergf83ace32016-10-17 08:04:07 +0200581#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200582/* policy for WoWLAN attributes */
583static const struct nla_policy
584nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
585 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
586 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
587 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
588 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200589 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
590 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
591 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
592 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100593 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300594 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100595};
596
597static const struct nla_policy
598nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
599 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
600 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
601 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
602 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
603 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
604 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
605 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
606 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
607 },
608 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
609 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
610 },
611 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
612 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
613 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200614};
Johannes Bergf83ace32016-10-17 08:04:07 +0200615#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200616
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700617/* policy for coalesce rule attributes */
618static const struct nla_policy
619nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
620 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200621 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
622 NLA_POLICY_RANGE(NLA_U32,
623 NL80211_COALESCE_CONDITION_MATCH,
624 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700625 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
626};
627
Johannes Berge5497d72011-07-05 16:35:40 +0200628/* policy for GTK rekey offload attributes */
629static const struct nla_policy
630nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
631 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
632 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
633 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
634};
635
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300636static const struct nla_policy
637nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200638 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300639 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100640 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700641 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300642};
643
Avraham Stern3b06d272015-10-12 09:51:34 +0300644static const struct nla_policy
645nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
646 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
647 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
648};
649
Arend van Spriel38de03d2016-03-02 20:37:18 +0100650static const struct nla_policy
651nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
652 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
653 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
654 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
655 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
656 },
657};
658
Ayala Bekera442b762016-09-20 17:31:15 +0300659/* policy for NAN function attributes */
660static const struct nla_policy
661nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
662 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300663 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300664 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
665 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
666 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
667 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
668 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
669 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
670 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
671 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
672 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
673 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
674 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
675 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
676 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
677 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
678 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
679 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
680};
681
682/* policy for Service Response Filter attributes */
683static const struct nla_policy
684nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
685 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
686 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
687 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
688 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
689 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
690};
691
Peng Xuad670232017-10-03 23:21:51 +0300692/* policy for packet pattern attributes */
693static const struct nla_policy
694nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
695 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
696 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
697 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
698};
699
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200700int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
701 struct cfg80211_registered_device **rdev,
702 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100703{
Johannes Berg67748892010-10-04 21:14:06 +0200704 int err;
705
Johannes Berg97990a02013-04-19 01:02:55 +0200706 if (!cb->args[0]) {
707 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200708 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200709 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200710 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100711 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200712
Johannes Bergc90c39d2016-10-24 14:40:01 +0200713 *wdev = __cfg80211_wdev_from_attrs(
Johannes Berg5297c652018-09-27 14:36:44 +0200714 sock_net(cb->skb->sk),
Johannes Bergc90c39d2016-10-24 14:40:01 +0200715 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100716 if (IS_ERR(*wdev))
717 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800718 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200719 /* 0 is the first index - add 1 to parse only once */
720 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200721 cb->args[1] = (*wdev)->identifier;
722 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200723 /* subtract the 1 again here */
724 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200725 struct wireless_dev *tmp;
726
Johannes Bergea90e0d2017-03-15 14:26:04 +0100727 if (!wiphy)
728 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800729 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200730 *wdev = NULL;
731
Johannes Berg53873f12016-05-03 16:52:04 +0300732 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200733 if (tmp->identifier == cb->args[1]) {
734 *wdev = tmp;
735 break;
736 }
737 }
Johannes Berg97990a02013-04-19 01:02:55 +0200738
Johannes Bergea90e0d2017-03-15 14:26:04 +0100739 if (!*wdev)
740 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200741 }
742
Johannes Berg67748892010-10-04 21:14:06 +0200743 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200744}
745
Johannes Berg55682962007-09-20 13:09:35 -0400746/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200747void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
748 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400749{
750 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000751 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400752}
753
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300754static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
755 const struct ieee80211_reg_rule *rule)
756{
757 int j;
758 struct nlattr *nl_wmm_rules =
759 nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM);
760
761 if (!nl_wmm_rules)
762 goto nla_put_failure;
763
764 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
765 struct nlattr *nl_wmm_rule = nla_nest_start(msg, j);
766
767 if (!nl_wmm_rule)
768 goto nla_put_failure;
769
770 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200771 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300772 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200773 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300774 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200775 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300776 nla_put_u16(msg, NL80211_WMMR_TXOP,
777 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300778 goto nla_put_failure;
779
780 nla_nest_end(msg, nl_wmm_rule);
781 }
782 nla_nest_end(msg, nl_wmm_rules);
783
784 return 0;
785
786nla_put_failure:
787 return -ENOBUFS;
788}
789
790static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100791 struct ieee80211_channel *chan,
792 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400793{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200794 /* Some channels must be completely excluded from the
795 * list to protect old user-space tools from breaking
796 */
797 if (!large && chan->flags &
798 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
799 return 0;
800
David S. Miller9360ffd2012-03-29 04:41:26 -0400801 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
802 chan->center_freq))
803 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400804
David S. Miller9360ffd2012-03-29 04:41:26 -0400805 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
806 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
807 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200808 if (chan->flags & IEEE80211_CHAN_NO_IR) {
809 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
810 goto nla_put_failure;
811 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
812 goto nla_put_failure;
813 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100814 if (chan->flags & IEEE80211_CHAN_RADAR) {
815 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
816 goto nla_put_failure;
817 if (large) {
818 u32 time;
819
820 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
821
822 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
823 chan->dfs_state))
824 goto nla_put_failure;
825 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
826 time))
827 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100828 if (nla_put_u32(msg,
829 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
830 chan->dfs_cac_ms))
831 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100832 }
833 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400834
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100835 if (large) {
836 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
837 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
838 goto nla_put_failure;
839 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
840 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
841 goto nla_put_failure;
842 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
843 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
844 goto nla_put_failure;
845 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
846 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
847 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200848 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
849 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
850 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300851 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
852 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200853 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200854 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
855 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
856 goto nla_put_failure;
857 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
858 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
859 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100860 }
861
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
863 DBM_TO_MBM(chan->max_power)))
864 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400865
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300866 if (large) {
867 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300868 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300869
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200870 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300871 if (nl80211_msg_put_wmm_rules(msg, rule))
872 goto nla_put_failure;
873 }
874 }
875
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400876 return 0;
877
878 nla_put_failure:
879 return -ENOBUFS;
880}
881
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200882static bool nl80211_put_txq_stats(struct sk_buff *msg,
883 struct cfg80211_txq_stats *txqstats,
884 int attrtype)
885{
886 struct nlattr *txqattr;
887
888#define PUT_TXQVAL_U32(attr, memb) do { \
889 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
890 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
891 return false; \
892 } while (0)
893
894 txqattr = nla_nest_start(msg, attrtype);
895 if (!txqattr)
896 return false;
897
898 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
899 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
900 PUT_TXQVAL_U32(FLOWS, flows);
901 PUT_TXQVAL_U32(DROPS, drops);
902 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
903 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
904 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
905 PUT_TXQVAL_U32(COLLISIONS, collisions);
906 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
907 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
908 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
909 nla_nest_end(msg, txqattr);
910
911#undef PUT_TXQVAL_U32
912 return true;
913}
914
Johannes Berg55682962007-09-20 13:09:35 -0400915/* netlink command implementations */
916
Johannes Bergb9454e82009-07-08 13:29:08 +0200917struct key_parse {
918 struct key_params p;
919 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200920 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200921 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100922 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200923};
924
Johannes Berg768075e2017-11-13 15:35:06 +0100925static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
926 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200927{
928 struct nlattr *tb[NL80211_KEY_MAX + 1];
929 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Berg768075e2017-11-13 15:35:06 +0100930 nl80211_key_policy, info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200931 if (err)
932 return err;
933
934 k->def = !!tb[NL80211_KEY_DEFAULT];
935 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
936
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100937 if (k->def) {
938 k->def_uni = true;
939 k->def_multi = true;
940 }
941 if (k->defmgmt)
942 k->def_multi = true;
943
Johannes Bergb9454e82009-07-08 13:29:08 +0200944 if (tb[NL80211_KEY_IDX])
945 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
946
947 if (tb[NL80211_KEY_DATA]) {
948 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
949 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
950 }
951
952 if (tb[NL80211_KEY_SEQ]) {
953 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
954 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
955 }
956
957 if (tb[NL80211_KEY_CIPHER])
958 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
959
Johannes Bergab0d76f2018-10-02 10:00:07 +0200960 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +0200961 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +0200962
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100963 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
964 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700965
Johannes Berg2da8f412012-01-20 13:52:37 +0100966 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
967 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Berg768075e2017-11-13 15:35:06 +0100968 nl80211_key_default_policy,
969 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100970 if (err)
971 return err;
972
973 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
974 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
975 }
976
Johannes Bergb9454e82009-07-08 13:29:08 +0200977 return 0;
978}
979
980static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
981{
982 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
983 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
984 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
985 }
986
987 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
988 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
989 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
990 }
991
992 if (info->attrs[NL80211_ATTR_KEY_IDX])
993 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
994
995 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
996 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
997
998 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
999 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1000
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001001 if (k->def) {
1002 k->def_uni = true;
1003 k->def_multi = true;
1004 }
1005 if (k->defmgmt)
1006 k->def_multi = true;
1007
Johannes Bergab0d76f2018-10-02 10:00:07 +02001008 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001009 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001010
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001011 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1012 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +02001013 int err = nla_parse_nested(kdt,
1014 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1015 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +02001016 nl80211_key_default_policy,
1017 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001018 if (err)
1019 return err;
1020
1021 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1022 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1023 }
1024
Johannes Bergb9454e82009-07-08 13:29:08 +02001025 return 0;
1026}
1027
1028static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1029{
1030 int err;
1031
1032 memset(k, 0, sizeof(*k));
1033 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001034 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001035
1036 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001037 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001038 else
1039 err = nl80211_parse_key_old(info, k);
1040
1041 if (err)
1042 return err;
1043
Johannes Berg768075e2017-11-13 15:35:06 +01001044 if (k->def && k->defmgmt) {
1045 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001046 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001047 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001048
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001049 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001050 if (k->def_uni || !k->def_multi) {
1051 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001052 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001053 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001054 }
1055
Johannes Bergb9454e82009-07-08 13:29:08 +02001056 if (k->idx != -1) {
1057 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001058 if (k->idx < 4 || k->idx > 5) {
1059 GENL_SET_ERR_MSG(info,
1060 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001061 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001062 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001063 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001064 if (k->idx < 0 || k->idx > 3) {
1065 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001066 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001067 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001068 } else {
Johannes Berg768075e2017-11-13 15:35:06 +01001069 if (k->idx < 0 || k->idx > 5) {
1070 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001071 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001072 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001073 }
1074 }
1075
1076 return 0;
1077}
1078
Johannes Bergfffd0932009-07-08 14:22:54 +02001079static struct cfg80211_cached_keys *
1080nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001081 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001082{
Johannes Berg768075e2017-11-13 15:35:06 +01001083 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001084 struct key_parse parse;
1085 struct nlattr *key;
1086 struct cfg80211_cached_keys *result;
1087 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001088 bool have_key = false;
1089
1090 nla_for_each_nested(key, keys, rem) {
1091 have_key = true;
1092 break;
1093 }
1094
1095 if (!have_key)
1096 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001097
1098 result = kzalloc(sizeof(*result), GFP_KERNEL);
1099 if (!result)
1100 return ERR_PTR(-ENOMEM);
1101
1102 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001103
1104 nla_for_each_nested(key, keys, rem) {
1105 memset(&parse, 0, sizeof(parse));
1106 parse.idx = -1;
1107
Johannes Berg768075e2017-11-13 15:35:06 +01001108 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001109 if (err)
1110 goto error;
1111 err = -EINVAL;
1112 if (!parse.p.key)
1113 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001114 if (parse.idx < 0 || parse.idx > 3) {
1115 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001116 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001117 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001118 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001119 if (def) {
1120 GENL_SET_ERR_MSG(info,
1121 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001122 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001123 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001124 def = 1;
1125 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001126 if (!parse.def_uni || !parse.def_multi)
1127 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001128 } else if (parse.defmgmt)
1129 goto error;
1130 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001131 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001132 if (err)
1133 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001134 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1135 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001136 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001137 err = -EINVAL;
1138 goto error;
1139 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001140 result->params[parse.idx].cipher = parse.p.cipher;
1141 result->params[parse.idx].key_len = parse.p.key_len;
1142 result->params[parse.idx].key = result->data[parse.idx];
1143 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301144
Johannes Berg386b1f22016-09-13 16:10:02 +02001145 /* must be WEP key if we got here */
1146 if (no_ht)
1147 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001148 }
1149
Johannes Bergf1c1f172016-09-13 17:08:23 +02001150 if (result->def < 0) {
1151 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001152 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001153 goto error;
1154 }
1155
Johannes Bergfffd0932009-07-08 14:22:54 +02001156 return result;
1157 error:
1158 kfree(result);
1159 return ERR_PTR(err);
1160}
1161
1162static int nl80211_key_allowed(struct wireless_dev *wdev)
1163{
1164 ASSERT_WDEV_LOCK(wdev);
1165
Johannes Bergfffd0932009-07-08 14:22:54 +02001166 switch (wdev->iftype) {
1167 case NL80211_IFTYPE_AP:
1168 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001169 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001170 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001171 break;
1172 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001173 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001174 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001175 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001176 return -ENOLINK;
1177 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001178 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001179 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001180 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001181 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001182 case NL80211_IFTYPE_P2P_DEVICE:
1183 case NL80211_IFTYPE_WDS:
1184 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001185 return -EINVAL;
1186 }
1187
1188 return 0;
1189}
1190
Jouni Malinen664834d2014-01-15 00:01:44 +02001191static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1192 struct nlattr *tb)
1193{
1194 struct ieee80211_channel *chan;
1195
1196 if (tb == NULL)
1197 return NULL;
1198 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1199 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1200 return NULL;
1201 return chan;
1202}
1203
Johannes Berg7527a782011-05-13 10:58:57 +02001204static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1205{
1206 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1207 int i;
1208
1209 if (!nl_modes)
1210 goto nla_put_failure;
1211
1212 i = 0;
1213 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001214 if ((ifmodes & 1) && nla_put_flag(msg, i))
1215 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001216 ifmodes >>= 1;
1217 i++;
1218 }
1219
1220 nla_nest_end(msg, nl_modes);
1221 return 0;
1222
1223nla_put_failure:
1224 return -ENOBUFS;
1225}
1226
1227static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001228 struct sk_buff *msg,
1229 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001230{
1231 struct nlattr *nl_combis;
1232 int i, j;
1233
1234 nl_combis = nla_nest_start(msg,
1235 NL80211_ATTR_INTERFACE_COMBINATIONS);
1236 if (!nl_combis)
1237 goto nla_put_failure;
1238
1239 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1240 const struct ieee80211_iface_combination *c;
1241 struct nlattr *nl_combi, *nl_limits;
1242
1243 c = &wiphy->iface_combinations[i];
1244
1245 nl_combi = nla_nest_start(msg, i + 1);
1246 if (!nl_combi)
1247 goto nla_put_failure;
1248
1249 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1250 if (!nl_limits)
1251 goto nla_put_failure;
1252
1253 for (j = 0; j < c->n_limits; j++) {
1254 struct nlattr *nl_limit;
1255
1256 nl_limit = nla_nest_start(msg, j + 1);
1257 if (!nl_limit)
1258 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001259 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1260 c->limits[j].max))
1261 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001262 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1263 c->limits[j].types))
1264 goto nla_put_failure;
1265 nla_nest_end(msg, nl_limit);
1266 }
1267
1268 nla_nest_end(msg, nl_limits);
1269
David S. Miller9360ffd2012-03-29 04:41:26 -04001270 if (c->beacon_int_infra_match &&
1271 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1272 goto nla_put_failure;
1273 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1274 c->num_different_channels) ||
1275 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1276 c->max_interfaces))
1277 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001278 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001279 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1280 c->radar_detect_widths) ||
1281 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1282 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001283 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301284 if (c->beacon_int_min_gcd &&
1285 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1286 c->beacon_int_min_gcd))
1287 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001288
1289 nla_nest_end(msg, nl_combi);
1290 }
1291
1292 nla_nest_end(msg, nl_combis);
1293
1294 return 0;
1295nla_put_failure:
1296 return -ENOBUFS;
1297}
1298
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001300static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1301 struct sk_buff *msg)
1302{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001303 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001304 struct nlattr *nl_tcp;
1305
1306 if (!tcp)
1307 return 0;
1308
1309 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1310 if (!nl_tcp)
1311 return -ENOBUFS;
1312
1313 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1314 tcp->data_payload_max))
1315 return -ENOBUFS;
1316
1317 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1318 tcp->data_payload_max))
1319 return -ENOBUFS;
1320
1321 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1322 return -ENOBUFS;
1323
1324 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1325 sizeof(*tcp->tok), tcp->tok))
1326 return -ENOBUFS;
1327
1328 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1329 tcp->data_interval_max))
1330 return -ENOBUFS;
1331
1332 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1333 tcp->wake_payload_max))
1334 return -ENOBUFS;
1335
1336 nla_nest_end(msg, nl_tcp);
1337 return 0;
1338}
1339
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001342 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343{
1344 struct nlattr *nl_wowlan;
1345
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 return 0;
1348
1349 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1350 if (!nl_wowlan)
1351 return -ENOBUFS;
1352
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001359 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001367 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1369 return -ENOBUFS;
1370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001372 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001373 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1374 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1375 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1376 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 };
1378
1379 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1380 sizeof(pat), &pat))
1381 return -ENOBUFS;
1382 }
1383
Luciano Coelho75453cc2015-01-09 14:06:37 +02001384 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1385 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1386 rdev->wiphy.wowlan->max_nd_match_sets))
1387 return -ENOBUFS;
1388
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001389 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001390 return -ENOBUFS;
1391
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 nla_nest_end(msg, nl_wowlan);
1393
1394 return 0;
1395}
1396#endif
1397
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001398static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001399 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001400{
1401 struct nl80211_coalesce_rule_support rule;
1402
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001403 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001404 return 0;
1405
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001406 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1407 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1408 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1409 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1410 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1411 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001412
1413 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1414 return -ENOBUFS;
1415
1416 return 0;
1417}
1418
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001419static int
1420nl80211_send_iftype_data(struct sk_buff *msg,
1421 const struct ieee80211_sband_iftype_data *iftdata)
1422{
1423 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1424
1425 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1426 iftdata->types_mask))
1427 return -ENOBUFS;
1428
1429 if (he_cap->has_he) {
1430 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1431 sizeof(he_cap->he_cap_elem.mac_cap_info),
1432 he_cap->he_cap_elem.mac_cap_info) ||
1433 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1434 sizeof(he_cap->he_cap_elem.phy_cap_info),
1435 he_cap->he_cap_elem.phy_cap_info) ||
1436 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1437 sizeof(he_cap->he_mcs_nss_supp),
1438 &he_cap->he_mcs_nss_supp) ||
1439 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1440 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1441 return -ENOBUFS;
1442 }
1443
1444 return 0;
1445}
1446
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1448 struct ieee80211_supported_band *sband)
1449{
1450 struct nlattr *nl_rates, *nl_rate;
1451 struct ieee80211_rate *rate;
1452 int i;
1453
1454 /* add HT info */
1455 if (sband->ht_cap.ht_supported &&
1456 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1457 sizeof(sband->ht_cap.mcs),
1458 &sband->ht_cap.mcs) ||
1459 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1460 sband->ht_cap.cap) ||
1461 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1462 sband->ht_cap.ampdu_factor) ||
1463 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1464 sband->ht_cap.ampdu_density)))
1465 return -ENOBUFS;
1466
1467 /* add VHT info */
1468 if (sband->vht_cap.vht_supported &&
1469 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1470 sizeof(sband->vht_cap.vht_mcs),
1471 &sband->vht_cap.vht_mcs) ||
1472 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1473 sband->vht_cap.cap)))
1474 return -ENOBUFS;
1475
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001476 if (sband->n_iftype_data) {
1477 struct nlattr *nl_iftype_data =
1478 nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA);
1479 int err;
1480
1481 if (!nl_iftype_data)
1482 return -ENOBUFS;
1483
1484 for (i = 0; i < sband->n_iftype_data; i++) {
1485 struct nlattr *iftdata;
1486
1487 iftdata = nla_nest_start(msg, i + 1);
1488 if (!iftdata)
1489 return -ENOBUFS;
1490
1491 err = nl80211_send_iftype_data(msg,
1492 &sband->iftype_data[i]);
1493 if (err)
1494 return err;
1495
1496 nla_nest_end(msg, iftdata);
1497 }
1498
1499 nla_nest_end(msg, nl_iftype_data);
1500 }
1501
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 /* add bitrates */
1503 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1504 if (!nl_rates)
1505 return -ENOBUFS;
1506
1507 for (i = 0; i < sband->n_bitrates; i++) {
1508 nl_rate = nla_nest_start(msg, i);
1509 if (!nl_rate)
1510 return -ENOBUFS;
1511
1512 rate = &sband->bitrates[i];
1513 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1514 rate->bitrate))
1515 return -ENOBUFS;
1516 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1517 nla_put_flag(msg,
1518 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1519 return -ENOBUFS;
1520
1521 nla_nest_end(msg, nl_rate);
1522 }
1523
1524 nla_nest_end(msg, nl_rates);
1525
1526 return 0;
1527}
1528
1529static int
1530nl80211_send_mgmt_stypes(struct sk_buff *msg,
1531 const struct ieee80211_txrx_stypes *mgmt_stypes)
1532{
1533 u16 stypes;
1534 struct nlattr *nl_ftypes, *nl_ifs;
1535 enum nl80211_iftype ift;
1536 int i;
1537
1538 if (!mgmt_stypes)
1539 return 0;
1540
1541 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1542 if (!nl_ifs)
1543 return -ENOBUFS;
1544
1545 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1546 nl_ftypes = nla_nest_start(msg, ift);
1547 if (!nl_ftypes)
1548 return -ENOBUFS;
1549 i = 0;
1550 stypes = mgmt_stypes[ift].tx;
1551 while (stypes) {
1552 if ((stypes & 1) &&
1553 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1554 (i << 4) | IEEE80211_FTYPE_MGMT))
1555 return -ENOBUFS;
1556 stypes >>= 1;
1557 i++;
1558 }
1559 nla_nest_end(msg, nl_ftypes);
1560 }
1561
1562 nla_nest_end(msg, nl_ifs);
1563
1564 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1565 if (!nl_ifs)
1566 return -ENOBUFS;
1567
1568 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1569 nl_ftypes = nla_nest_start(msg, ift);
1570 if (!nl_ftypes)
1571 return -ENOBUFS;
1572 i = 0;
1573 stypes = mgmt_stypes[ift].rx;
1574 while (stypes) {
1575 if ((stypes & 1) &&
1576 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1577 (i << 4) | IEEE80211_FTYPE_MGMT))
1578 return -ENOBUFS;
1579 stypes >>= 1;
1580 i++;
1581 }
1582 nla_nest_end(msg, nl_ftypes);
1583 }
1584 nla_nest_end(msg, nl_ifs);
1585
1586 return 0;
1587}
1588
Johannes Berg17948992016-10-26 11:42:04 +02001589#define CMD(op, n) \
1590 do { \
1591 if (rdev->ops->op) { \
1592 i++; \
1593 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1594 goto nla_put_failure; \
1595 } \
1596 } while (0)
1597
1598static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1599 struct sk_buff *msg)
1600{
1601 int i = 0;
1602
1603 /*
1604 * do *NOT* add anything into this function, new things need to be
1605 * advertised only to new versions of userspace that can deal with
1606 * the split (and they can't possibly care about new features...
1607 */
1608 CMD(add_virtual_intf, NEW_INTERFACE);
1609 CMD(change_virtual_intf, SET_INTERFACE);
1610 CMD(add_key, NEW_KEY);
1611 CMD(start_ap, START_AP);
1612 CMD(add_station, NEW_STATION);
1613 CMD(add_mpath, NEW_MPATH);
1614 CMD(update_mesh_config, SET_MESH_CONFIG);
1615 CMD(change_bss, SET_BSS);
1616 CMD(auth, AUTHENTICATE);
1617 CMD(assoc, ASSOCIATE);
1618 CMD(deauth, DEAUTHENTICATE);
1619 CMD(disassoc, DISASSOCIATE);
1620 CMD(join_ibss, JOIN_IBSS);
1621 CMD(join_mesh, JOIN_MESH);
1622 CMD(set_pmksa, SET_PMKSA);
1623 CMD(del_pmksa, DEL_PMKSA);
1624 CMD(flush_pmksa, FLUSH_PMKSA);
1625 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1626 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1627 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1628 CMD(mgmt_tx, FRAME);
1629 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1630 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1631 i++;
1632 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1633 goto nla_put_failure;
1634 }
1635 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1636 rdev->ops->join_mesh) {
1637 i++;
1638 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1639 goto nla_put_failure;
1640 }
1641 CMD(set_wds_peer, SET_WDS_PEER);
1642 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1643 CMD(tdls_mgmt, TDLS_MGMT);
1644 CMD(tdls_oper, TDLS_OPER);
1645 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001646 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001647 CMD(sched_scan_start, START_SCHED_SCAN);
1648 CMD(probe_client, PROBE_CLIENT);
1649 CMD(set_noack_map, SET_NOACK_MAP);
1650 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1651 i++;
1652 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1653 goto nla_put_failure;
1654 }
1655 CMD(start_p2p_device, START_P2P_DEVICE);
1656 CMD(set_mcast_rate, SET_MCAST_RATE);
1657#ifdef CONFIG_NL80211_TESTMODE
1658 CMD(testmode_cmd, TESTMODE);
1659#endif
1660
1661 if (rdev->ops->connect || rdev->ops->auth) {
1662 i++;
1663 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1664 goto nla_put_failure;
1665 }
1666
1667 if (rdev->ops->disconnect || rdev->ops->deauth) {
1668 i++;
1669 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1670 goto nla_put_failure;
1671 }
1672
1673 return i;
1674 nla_put_failure:
1675 return -ENOBUFS;
1676}
1677
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001678static int
1679nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1680 struct sk_buff *msg)
1681{
1682 struct nlattr *ftm;
1683
1684 if (!cap->ftm.supported)
1685 return 0;
1686
1687 ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM);
1688 if (!ftm)
1689 return -ENOBUFS;
1690
1691 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1692 return -ENOBUFS;
1693 if (cap->ftm.non_asap &&
1694 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1695 return -ENOBUFS;
1696 if (cap->ftm.request_lci &&
1697 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1698 return -ENOBUFS;
1699 if (cap->ftm.request_civicloc &&
1700 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1701 return -ENOBUFS;
1702 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1703 cap->ftm.preambles))
1704 return -ENOBUFS;
1705 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1706 cap->ftm.bandwidths))
1707 return -ENOBUFS;
1708 if (cap->ftm.max_bursts_exponent >= 0 &&
1709 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1710 cap->ftm.max_bursts_exponent))
1711 return -ENOBUFS;
1712 if (cap->ftm.max_ftms_per_burst &&
1713 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1714 cap->ftm.max_ftms_per_burst))
1715 return -ENOBUFS;
1716
1717 nla_nest_end(msg, ftm);
1718 return 0;
1719}
1720
1721static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1722 struct sk_buff *msg)
1723{
1724 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1725 struct nlattr *pmsr, *caps;
1726
1727 if (!cap)
1728 return 0;
1729
1730 /*
1731 * we don't need to clean up anything here since the caller
1732 * will genlmsg_cancel() if we fail
1733 */
1734
1735 pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1736 if (!pmsr)
1737 return -ENOBUFS;
1738
1739 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1740 return -ENOBUFS;
1741
1742 if (cap->report_ap_tsf &&
1743 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1744 return -ENOBUFS;
1745
1746 if (cap->randomize_mac_addr &&
1747 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1748 return -ENOBUFS;
1749
1750 caps = nla_nest_start(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
1751 if (!caps)
1752 return -ENOBUFS;
1753
1754 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1755 return -ENOBUFS;
1756
1757 nla_nest_end(msg, caps);
1758 nla_nest_end(msg, pmsr);
1759
1760 return 0;
1761}
1762
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763struct nl80211_dump_wiphy_state {
1764 s64 filter_wiphy;
1765 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301766 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001767 bool split;
1768};
1769
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001770static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001771 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001772 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001774{
1775 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001776 struct nlattr *nl_bands, *nl_band;
1777 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001778 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001779 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001780 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001781 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001782 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001783 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001784 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001785
Johannes Berg3bb20552014-05-26 13:52:25 +02001786 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001787 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 return -ENOBUFS;
1789
Johannes Berg86e8cf92013-06-19 10:57:22 +02001790 if (WARN_ON(!state))
1791 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001792
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001794 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001795 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001796 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001797 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001798 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001799
Johannes Berg3bb20552014-05-26 13:52:25 +02001800 if (cmd != NL80211_CMD_NEW_WIPHY)
1801 goto finish;
1802
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001804 case 0:
1805 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001806 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001807 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001808 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001809 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001810 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001811 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001812 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001813 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001814 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001815 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001816 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001817 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001818 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001819 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001820 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001821 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001822 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001824 rdev->wiphy.max_match_sets) ||
1825 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1826 rdev->wiphy.max_sched_scan_plans) ||
1827 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1828 rdev->wiphy.max_sched_scan_plan_interval) ||
1829 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1830 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001831 goto nla_put_failure;
1832
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001833 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001834 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1835 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001836 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001837 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1838 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001839 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001840 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1841 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001842 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001843 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1844 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001845 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001846 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1847 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001848 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001849 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001850 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 state->split_start++;
1852 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001853 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001854 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001855 case 1:
1856 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001857 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1858 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001859 goto nla_put_failure;
1860
Johannes Berg3713b4e2013-02-14 16:19:38 +01001861 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001862 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001863 goto nla_put_failure;
1864
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001865 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001866 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1867 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001868
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001870 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001872 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001873 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001874
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001875 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001876 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001877 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001878 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001879
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001880 if ((rdev->wiphy.available_antennas_tx ||
1881 rdev->wiphy.available_antennas_rx) &&
1882 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001883 u32 tx_ant = 0, rx_ant = 0;
1884 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001885
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001886 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 if (!res) {
1888 if (nla_put_u32(msg,
1889 NL80211_ATTR_WIPHY_ANTENNA_TX,
1890 tx_ant) ||
1891 nla_put_u32(msg,
1892 NL80211_ATTR_WIPHY_ANTENNA_RX,
1893 rx_ant))
1894 goto nla_put_failure;
1895 }
Johannes Bergee688b002008-01-24 19:38:39 +01001896 }
1897
Johannes Berg86e8cf92013-06-19 10:57:22 +02001898 state->split_start++;
1899 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001900 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001901 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 case 2:
1903 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001904 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001905 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001906 state->split_start++;
1907 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001908 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001909 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001910 case 3:
1911 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1912 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001913 goto nla_put_failure;
1914
Johannes Berg86e8cf92013-06-19 10:57:22 +02001915 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001916 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001917 struct ieee80211_supported_band *sband;
1918
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001919 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001920
1921 if (!sband)
1922 continue;
1923
1924 nl_band = nla_nest_start(msg, band);
1925 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001926 goto nla_put_failure;
1927
Johannes Berg86e8cf92013-06-19 10:57:22 +02001928 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001929 case 0:
1930 if (nl80211_send_band_rateinfo(msg, sband))
1931 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932 state->chan_start++;
1933 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001934 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001935 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001936 default:
1937 /* add frequencies */
1938 nl_freqs = nla_nest_start(
1939 msg, NL80211_BAND_ATTR_FREQS);
1940 if (!nl_freqs)
1941 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001942
Johannes Berg86e8cf92013-06-19 10:57:22 +02001943 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001944 i < sband->n_channels;
1945 i++) {
1946 nl_freq = nla_nest_start(msg, i);
1947 if (!nl_freq)
1948 goto nla_put_failure;
1949
1950 chan = &sband->channels[i];
1951
Johannes Berg86e8cf92013-06-19 10:57:22 +02001952 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001953 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001954 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001955 goto nla_put_failure;
1956
1957 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001958 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001959 break;
1960 }
1961 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001962 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001963 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001964 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001965 nla_nest_end(msg, nl_freqs);
1966 }
1967
1968 nla_nest_end(msg, nl_band);
1969
Johannes Berg86e8cf92013-06-19 10:57:22 +02001970 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001971 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001972 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001973 band--;
1974 break;
1975 }
Johannes Bergee688b002008-01-24 19:38:39 +01001976 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001977 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001978
Johannes Berg57fbcce2016-04-12 15:56:15 +02001979 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001980 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001981 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001982 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001983
Johannes Berg3713b4e2013-02-14 16:19:38 +01001984 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001985 if (state->band_start == 0 && state->chan_start == 0)
1986 state->split_start++;
1987 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001988 break;
Luca Coelho925b5972018-12-15 11:03:21 +02001989 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01001990 case 4:
1991 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1992 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001993 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001994
Johannes Berg17948992016-10-26 11:42:04 +02001995 i = nl80211_add_commands_unsplit(rdev, msg);
1996 if (i < 0)
1997 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001998 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001999 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2000 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002001 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002002 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002003 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002004 if (rdev->wiphy.features &
2005 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002006 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002007 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002008 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02002009 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002010#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002011
Johannes Berg3713b4e2013-02-14 16:19:38 +01002012 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002013 state->split_start++;
2014 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002015 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002016 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002017 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002018 if (rdev->ops->remain_on_channel &&
2019 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002020 nla_put_u32(msg,
2021 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002022 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002023 goto nla_put_failure;
2024
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002025 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002026 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2027 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002028
Johannes Berg3713b4e2013-02-14 16:19:38 +01002029 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2030 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002031 state->split_start++;
2032 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002033 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002034 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002035 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002036#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002037 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002038 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002039 state->split_start++;
2040 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002041 break;
2042#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002043 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002044#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002045 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002046 case 7:
2047 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002048 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002049 goto nla_put_failure;
2050
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002051 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002052 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002053 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002054
Johannes Berg86e8cf92013-06-19 10:57:22 +02002055 state->split_start++;
2056 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002057 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002058 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002059 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002060 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002061 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002062 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002063 goto nla_put_failure;
2064
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002065 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002066 /*
2067 * We can only add the per-channel limit information if the
2068 * dump is split, otherwise it makes it too big. Therefore
2069 * only advertise it in that case.
2070 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002071 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002072 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2073 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002074 goto nla_put_failure;
2075
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002076 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002077 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002078 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2079 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002080 goto nla_put_failure;
2081
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002082 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2083 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002084 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002085 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002086 goto nla_put_failure;
2087
2088 /*
2089 * Any information below this point is only available to
2090 * applications that can deal with it being split. This
2091 * helps ensure that newly added capabilities don't break
2092 * older tools by overrunning their buffers.
2093 *
2094 * We still increment split_start so that in the split
2095 * case we'll continue with more data in the next round,
2096 * but break unconditionally so unsplit data stops here.
2097 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002098 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002099 break;
2100 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002101 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002102 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002103 rdev->wiphy.extended_capabilities_len,
2104 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002105 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002106 rdev->wiphy.extended_capabilities_len,
2107 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002108 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002109
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002110 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002111 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002112 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2113 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002114 goto nla_put_failure;
2115
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002116 state->split_start++;
2117 break;
2118 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002119 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002120 goto nla_put_failure;
2121
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002122 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002123 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2124 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2125 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002126
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002127 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002128 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002129 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002130 goto nla_put_failure;
2131
Johannes Bergad7e7182013-11-13 13:37:47 +01002132 state->split_start++;
2133 break;
2134 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002135 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002136 const struct nl80211_vendor_cmd_info *info;
2137 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002138
Johannes Berg567ffc32013-12-18 14:43:31 +01002139 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
2140 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002141 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002142
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002143 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2144 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002145 if (nla_put(msg, i + 1, sizeof(*info), info))
2146 goto nla_put_failure;
2147 }
2148 nla_nest_end(msg, nested);
2149 }
2150
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002151 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002152 const struct nl80211_vendor_cmd_info *info;
2153 struct nlattr *nested;
2154
2155 nested = nla_nest_start(msg,
2156 NL80211_ATTR_VENDOR_EVENTS);
2157 if (!nested)
2158 goto nla_put_failure;
2159
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002160 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2161 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002162 if (nla_put(msg, i + 1, sizeof(*info), info))
2163 goto nla_put_failure;
2164 }
2165 nla_nest_end(msg, nested);
2166 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002167 state->split_start++;
2168 break;
2169 case 12:
2170 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2171 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2172 rdev->wiphy.max_num_csa_counters))
2173 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002174
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002175 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2176 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2177 goto nla_put_failure;
2178
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002179 if (rdev->wiphy.max_sched_scan_reqs &&
2180 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2181 rdev->wiphy.max_sched_scan_reqs))
2182 goto nla_put_failure;
2183
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002184 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2185 sizeof(rdev->wiphy.ext_features),
2186 rdev->wiphy.ext_features))
2187 goto nla_put_failure;
2188
Arend van Spriel38de03d2016-03-02 20:37:18 +01002189 if (rdev->wiphy.bss_select_support) {
2190 struct nlattr *nested;
2191 u32 bss_select_support = rdev->wiphy.bss_select_support;
2192
2193 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
2194 if (!nested)
2195 goto nla_put_failure;
2196
2197 i = 0;
2198 while (bss_select_support) {
2199 if ((bss_select_support & 1) &&
2200 nla_put_flag(msg, i))
2201 goto nla_put_failure;
2202 i++;
2203 bss_select_support >>= 1;
2204 }
2205 nla_nest_end(msg, nested);
2206 }
2207
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302208 state->split_start++;
2209 break;
2210 case 13:
2211 if (rdev->wiphy.num_iftype_ext_capab &&
2212 rdev->wiphy.iftype_ext_capab) {
2213 struct nlattr *nested_ext_capab, *nested;
2214
2215 nested = nla_nest_start(msg,
2216 NL80211_ATTR_IFTYPE_EXT_CAPA);
2217 if (!nested)
2218 goto nla_put_failure;
2219
2220 for (i = state->capa_start;
2221 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2222 const struct wiphy_iftype_ext_capab *capab;
2223
2224 capab = &rdev->wiphy.iftype_ext_capab[i];
2225
2226 nested_ext_capab = nla_nest_start(msg, i);
2227 if (!nested_ext_capab ||
2228 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2229 capab->iftype) ||
2230 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2231 capab->extended_capabilities_len,
2232 capab->extended_capabilities) ||
2233 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2234 capab->extended_capabilities_len,
2235 capab->extended_capabilities_mask))
2236 goto nla_put_failure;
2237
2238 nla_nest_end(msg, nested_ext_capab);
2239 if (state->split)
2240 break;
2241 }
2242 nla_nest_end(msg, nested);
2243 if (i < rdev->wiphy.num_iftype_ext_capab) {
2244 state->capa_start = i + 1;
2245 break;
2246 }
2247 }
2248
Luca Coelho85859892017-02-08 15:00:34 +02002249 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2250 rdev->wiphy.nan_supported_bands))
2251 goto nla_put_failure;
2252
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002253 if (wiphy_ext_feature_isset(&rdev->wiphy,
2254 NL80211_EXT_FEATURE_TXQS)) {
2255 struct cfg80211_txq_stats txqstats = {};
2256 int res;
2257
2258 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2259 if (!res &&
2260 !nl80211_put_txq_stats(msg, &txqstats,
2261 NL80211_ATTR_TXQ_STATS))
2262 goto nla_put_failure;
2263
2264 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2265 rdev->wiphy.txq_limit))
2266 goto nla_put_failure;
2267 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2268 rdev->wiphy.txq_memory_limit))
2269 goto nla_put_failure;
2270 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2271 rdev->wiphy.txq_quantum))
2272 goto nla_put_failure;
2273 }
2274
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002275 state->split_start++;
2276 break;
2277 case 14:
2278 if (nl80211_send_pmsr_capa(rdev, msg))
2279 goto nla_put_failure;
2280
Johannes Berg3713b4e2013-02-14 16:19:38 +01002281 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002282 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002283 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002284 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002285 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002286 genlmsg_end(msg, hdr);
2287 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002288
2289 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002290 genlmsg_cancel(msg, hdr);
2291 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002292}
2293
Johannes Berg86e8cf92013-06-19 10:57:22 +02002294static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2295 struct netlink_callback *cb,
2296 struct nl80211_dump_wiphy_state *state)
2297{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002298 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02002299 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
2300 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002301 /* ignore parse errors for backward compatibility */
2302 if (ret)
2303 return 0;
2304
2305 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2306 if (tb[NL80211_ATTR_WIPHY])
2307 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2308 if (tb[NL80211_ATTR_WDEV])
2309 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2310 if (tb[NL80211_ATTR_IFINDEX]) {
2311 struct net_device *netdev;
2312 struct cfg80211_registered_device *rdev;
2313 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2314
Ying Xue7f2b8562014-01-15 10:23:45 +08002315 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002316 if (!netdev)
2317 return -ENODEV;
2318 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002319 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002320 netdev->ieee80211_ptr->wiphy);
2321 state->filter_wiphy = rdev->wiphy_idx;
2322 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002323 }
2324
2325 return 0;
2326}
2327
Johannes Berg55682962007-09-20 13:09:35 -04002328static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2329{
Johannes Berg645e77d2013-03-01 14:03:49 +01002330 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002331 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002332 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002333
Johannes Berg5fe231e2013-05-08 21:45:15 +02002334 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002335 if (!state) {
2336 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002337 if (!state) {
2338 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002339 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002340 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002341 state->filter_wiphy = -1;
2342 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2343 if (ret) {
2344 kfree(state);
2345 rtnl_unlock();
2346 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002347 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002348 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002349 }
2350
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002351 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2352 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002353 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002354 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002355 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002356 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002357 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002358 continue;
2359 /* attempt to fit multiple wiphy data chunks into the skb */
2360 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002361 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2362 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002363 NETLINK_CB(cb->skb).portid,
2364 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002365 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002366 if (ret < 0) {
2367 /*
2368 * If sending the wiphy data didn't fit (ENOBUFS
2369 * or EMSGSIZE returned), this SKB is still
2370 * empty (so it's not too big because another
2371 * wiphy dataset is already in the skb) and
2372 * we've not tried to adjust the dump allocation
2373 * yet ... then adjust the alloc size to be
2374 * bigger, and return 1 but with the empty skb.
2375 * This results in an empty message being RX'ed
2376 * in userspace, but that is ignored.
2377 *
2378 * We can then retry with the larger buffer.
2379 */
2380 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002381 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002382 cb->min_dump_alloc < 4096) {
2383 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002384 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002385 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002386 return 1;
2387 }
2388 idx--;
2389 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002390 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002391 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002392 break;
Johannes Berg55682962007-09-20 13:09:35 -04002393 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002394 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002395
Johannes Berg86e8cf92013-06-19 10:57:22 +02002396 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002397
2398 return skb->len;
2399}
2400
Johannes Berg86e8cf92013-06-19 10:57:22 +02002401static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2402{
2403 kfree((void *)cb->args[0]);
2404 return 0;
2405}
2406
Johannes Berg55682962007-09-20 13:09:35 -04002407static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2408{
2409 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002411 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002412
Johannes Berg645e77d2013-03-01 14:03:49 +01002413 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002414 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002415 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002416
Johannes Berg3bb20552014-05-26 13:52:25 +02002417 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2418 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002419 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002420 nlmsg_free(msg);
2421 return -ENOBUFS;
2422 }
Johannes Berg55682962007-09-20 13:09:35 -04002423
Johannes Berg134e6372009-07-10 09:51:34 +00002424 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002425}
2426
Jouni Malinen31888482008-10-30 16:59:24 +02002427static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2428 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2429 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2430 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2431 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2432 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2433};
2434
2435static int parse_txq_params(struct nlattr *tb[],
2436 struct ieee80211_txq_params *txq_params)
2437{
Dan Williams259d8c12018-01-29 17:03:15 -08002438 u8 ac;
2439
Johannes Berga3304b02012-03-28 11:04:24 +02002440 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002441 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2442 !tb[NL80211_TXQ_ATTR_AIFS])
2443 return -EINVAL;
2444
Dan Williams259d8c12018-01-29 17:03:15 -08002445 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002446 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2447 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2448 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2449 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2450
Dan Williams259d8c12018-01-29 17:03:15 -08002451 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002452 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002453 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002454 return 0;
2455}
2456
Johannes Bergf444de02010-05-05 15:25:02 +02002457static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2458{
2459 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002460 * You can only set the channel explicitly for WDS interfaces,
2461 * all others have their channel managed via their respective
2462 * "establish a connection" command (connect, join, ...)
2463 *
2464 * For AP/GO and mesh mode, the channel can be set with the
2465 * channel userspace API, but is only stored and passed to the
2466 * low-level driver when the AP starts or the mesh is joined.
2467 * This is for backward compatibility, userspace can also give
2468 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002469 *
2470 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002471 * whatever else is going on, so they have their own special
2472 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002473 */
2474 return !wdev ||
2475 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002476 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002477 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2478 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002479}
2480
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002481int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2482 struct genl_info *info,
2483 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002484{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002485 struct netlink_ext_ack *extack = info->extack;
2486 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302487 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002488
Johannes Berg49f9cf02018-10-01 11:55:09 +02002489 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002490 return -EINVAL;
2491
Johannes Berg49f9cf02018-10-01 11:55:09 +02002492 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002493
2494 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002495 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2496 chandef->center_freq1 = control_freq;
2497 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002498
2499 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002500 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2501 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2502 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002503 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002504 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002505
Johannes Berg49f9cf02018-10-01 11:55:09 +02002506 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002507 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002508
Johannes Berg49f9cf02018-10-01 11:55:09 +02002509 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002510
2511 switch (chantype) {
2512 case NL80211_CHAN_NO_HT:
2513 case NL80211_CHAN_HT20:
2514 case NL80211_CHAN_HT40PLUS:
2515 case NL80211_CHAN_HT40MINUS:
2516 cfg80211_chandef_create(chandef, chandef->chan,
2517 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002518 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002519 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2520 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2521 NL_SET_ERR_MSG_ATTR(extack,
2522 attrs[NL80211_ATTR_CENTER_FREQ1],
2523 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002524 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002525 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002526 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002527 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2528 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2529 NL_SET_ERR_MSG_ATTR(extack,
2530 attrs[NL80211_ATTR_CENTER_FREQ2],
2531 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002532 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002533 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002534 break;
2535 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002536 NL_SET_ERR_MSG_ATTR(extack,
2537 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2538 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002539 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002540 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002541 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002542 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002543 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2544 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002545 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002546 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2547 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002548 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002549 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002550 }
2551
Johannes Berg49f9cf02018-10-01 11:55:09 +02002552 if (!cfg80211_chandef_valid(chandef)) {
2553 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002554 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002555 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002556
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002557 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002558 IEEE80211_CHAN_DISABLED)) {
2559 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002560 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002561 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002562
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002563 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2564 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002565 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2566 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002567 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002568 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002569
Johannes Berg683b6d32012-11-08 21:25:48 +01002570 return 0;
2571}
2572
Johannes Bergf444de02010-05-05 15:25:02 +02002573static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002574 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002575 struct genl_info *info)
2576{
Johannes Berg683b6d32012-11-08 21:25:48 +01002577 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002578 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002579 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002580 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002581
Jouni Malinene16821b2014-04-28 11:22:08 +03002582 if (dev)
2583 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002584 if (!nl80211_can_set_dev_channel(wdev))
2585 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002586 if (wdev)
2587 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002588
Johannes Berg683b6d32012-11-08 21:25:48 +01002589 result = nl80211_parse_chandef(rdev, info, &chandef);
2590 if (result)
2591 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002592
Johannes Berge8c9bd52012-06-06 08:18:22 +02002593 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002594 case NL80211_IFTYPE_AP:
2595 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002596 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2597 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002598 result = -EINVAL;
2599 break;
2600 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002601 if (wdev->beacon_interval) {
2602 if (!dev || !rdev->ops->set_ap_chanwidth ||
2603 !(rdev->wiphy.features &
2604 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2605 result = -EBUSY;
2606 break;
2607 }
2608
2609 /* Only allow dynamic channel width changes */
2610 if (chandef.chan != wdev->preset_chandef.chan) {
2611 result = -EBUSY;
2612 break;
2613 }
2614 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2615 if (result)
2616 break;
2617 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002618 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002619 result = 0;
2620 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002621 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002622 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002623 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002624 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002625 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002626 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002627 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002628 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002629 }
Johannes Bergf444de02010-05-05 15:25:02 +02002630
2631 return result;
2632}
2633
2634static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2635{
Johannes Berg4c476992010-10-04 21:36:35 +02002636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2637 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002638
Jouni Malinene16821b2014-04-28 11:22:08 +03002639 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002640}
2641
Bill Jordane8347eb2010-10-01 13:54:28 -04002642static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2643{
Johannes Berg43b19952010-10-07 13:10:30 +02002644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2645 struct net_device *dev = info->user_ptr[1];
2646 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002647 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002648
2649 if (!info->attrs[NL80211_ATTR_MAC])
2650 return -EINVAL;
2651
Johannes Berg43b19952010-10-07 13:10:30 +02002652 if (netif_running(dev))
2653 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002654
Johannes Berg43b19952010-10-07 13:10:30 +02002655 if (!rdev->ops->set_wds_peer)
2656 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002657
Johannes Berg43b19952010-10-07 13:10:30 +02002658 if (wdev->iftype != NL80211_IFTYPE_WDS)
2659 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002660
2661 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002662 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002663}
2664
Johannes Berg55682962007-09-20 13:09:35 -04002665static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2666{
2667 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002668 struct net_device *netdev = NULL;
2669 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002670 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002671 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002672 u32 changed;
2673 u8 retry_short = 0, retry_long = 0;
2674 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002675 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002676 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002677
Johannes Berg5fe231e2013-05-08 21:45:15 +02002678 ASSERT_RTNL();
2679
Johannes Bergf444de02010-05-05 15:25:02 +02002680 /*
2681 * Try to find the wiphy and netdev. Normally this
2682 * function shouldn't need the netdev, but this is
2683 * done for backward compatibility -- previously
2684 * setting the channel was done per wiphy, but now
2685 * it is per netdev. Previous userland like hostapd
2686 * also passed a netdev to set_wiphy, so that it is
2687 * possible to let that go to the right netdev!
2688 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002689
Johannes Bergf444de02010-05-05 15:25:02 +02002690 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2691 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2692
Ying Xue7f2b8562014-01-15 10:23:45 +08002693 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002694 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002695 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002696 else
Johannes Bergf444de02010-05-05 15:25:02 +02002697 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002698 }
2699
Johannes Bergf444de02010-05-05 15:25:02 +02002700 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002701 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2702 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002703 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002704 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002705 wdev = NULL;
2706 netdev = NULL;
2707 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002708 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002709 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002710
2711 /*
2712 * end workaround code, by now the rdev is available
2713 * and locked, and wdev may or may not be NULL.
2714 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002715
2716 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002717 result = cfg80211_dev_rename(
2718 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002719
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002720 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002721 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002722
Jouni Malinen31888482008-10-30 16:59:24 +02002723 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2724 struct ieee80211_txq_params txq_params;
2725 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2726
Ying Xue7f2b8562014-01-15 10:23:45 +08002727 if (!rdev->ops->set_txq_params)
2728 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002729
Ying Xue7f2b8562014-01-15 10:23:45 +08002730 if (!netdev)
2731 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002732
Johannes Berg133a3ff2011-11-03 14:50:13 +01002733 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002734 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2735 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002736
Ying Xue7f2b8562014-01-15 10:23:45 +08002737 if (!netif_running(netdev))
2738 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002739
Jouni Malinen31888482008-10-30 16:59:24 +02002740 nla_for_each_nested(nl_txq_params,
2741 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2742 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002743 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2744 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002745 txq_params_policy,
2746 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002747 if (result)
2748 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002749 result = parse_txq_params(tb, &txq_params);
2750 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002751 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002752
Hila Gonene35e4d22012-06-27 17:19:42 +03002753 result = rdev_set_txq_params(rdev, netdev,
2754 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002755 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002756 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002757 }
2758 }
2759
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002760 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002761 result = __nl80211_set_channel(
2762 rdev,
2763 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2764 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002765 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002766 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002767 }
2768
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002769 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002770 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002771 enum nl80211_tx_power_setting type;
2772 int idx, mbm = 0;
2773
Johannes Bergc8442112012-10-24 10:17:18 +02002774 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2775 txp_wdev = NULL;
2776
Ying Xue7f2b8562014-01-15 10:23:45 +08002777 if (!rdev->ops->set_tx_power)
2778 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002779
2780 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2781 type = nla_get_u32(info->attrs[idx]);
2782
2783 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002784 (type != NL80211_TX_POWER_AUTOMATIC))
2785 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002786
2787 if (type != NL80211_TX_POWER_AUTOMATIC) {
2788 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2789 mbm = nla_get_u32(info->attrs[idx]);
2790 }
2791
Johannes Bergc8442112012-10-24 10:17:18 +02002792 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002793 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002794 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002795 }
2796
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002797 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2798 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2799 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002800
Bruno Randolf7f531e02010-12-16 11:30:22 +09002801 if ((!rdev->wiphy.available_antennas_tx &&
2802 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002803 !rdev->ops->set_antenna)
2804 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002805
2806 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2807 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2808
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002809 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002810 * available antenna masks, except for the "all" mask */
2811 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002812 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2813 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002814
Bruno Randolf7f531e02010-12-16 11:30:22 +09002815 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2816 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002817
Hila Gonene35e4d22012-06-27 17:19:42 +03002818 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002819 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002820 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002821 }
2822
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002823 changed = 0;
2824
2825 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2826 retry_short = nla_get_u8(
2827 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002828
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002829 changed |= WIPHY_PARAM_RETRY_SHORT;
2830 }
2831
2832 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2833 retry_long = nla_get_u8(
2834 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002835
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002836 changed |= WIPHY_PARAM_RETRY_LONG;
2837 }
2838
2839 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2840 frag_threshold = nla_get_u32(
2841 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002842 if (frag_threshold < 256)
2843 return -EINVAL;
2844
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002845 if (frag_threshold != (u32) -1) {
2846 /*
2847 * Fragments (apart from the last one) are required to
2848 * have even length. Make the fragmentation code
2849 * simpler by stripping LSB should someone try to use
2850 * odd threshold value.
2851 */
2852 frag_threshold &= ~0x1;
2853 }
2854 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2855 }
2856
2857 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2858 rts_threshold = nla_get_u32(
2859 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2860 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2861 }
2862
Lukáš Turek81077e82009-12-21 22:50:47 +01002863 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002864 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2865 return -EINVAL;
2866
Lukáš Turek81077e82009-12-21 22:50:47 +01002867 coverage_class = nla_get_u8(
2868 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2869 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2870 }
2871
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002872 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2873 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2874 return -EOPNOTSUPP;
2875
2876 changed |= WIPHY_PARAM_DYN_ACK;
2877 }
2878
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002879 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2880 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2881 NL80211_EXT_FEATURE_TXQS))
2882 return -EOPNOTSUPP;
2883 txq_limit = nla_get_u32(
2884 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2885 changed |= WIPHY_PARAM_TXQ_LIMIT;
2886 }
2887
2888 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2889 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2890 NL80211_EXT_FEATURE_TXQS))
2891 return -EOPNOTSUPP;
2892 txq_memory_limit = nla_get_u32(
2893 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2894 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2895 }
2896
2897 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2898 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2899 NL80211_EXT_FEATURE_TXQS))
2900 return -EOPNOTSUPP;
2901 txq_quantum = nla_get_u32(
2902 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2903 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2904 }
2905
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002906 if (changed) {
2907 u8 old_retry_short, old_retry_long;
2908 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002909 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002910 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002911
Ying Xue7f2b8562014-01-15 10:23:45 +08002912 if (!rdev->ops->set_wiphy_params)
2913 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002914
2915 old_retry_short = rdev->wiphy.retry_short;
2916 old_retry_long = rdev->wiphy.retry_long;
2917 old_frag_threshold = rdev->wiphy.frag_threshold;
2918 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002919 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002920 old_txq_limit = rdev->wiphy.txq_limit;
2921 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2922 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002923
2924 if (changed & WIPHY_PARAM_RETRY_SHORT)
2925 rdev->wiphy.retry_short = retry_short;
2926 if (changed & WIPHY_PARAM_RETRY_LONG)
2927 rdev->wiphy.retry_long = retry_long;
2928 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2929 rdev->wiphy.frag_threshold = frag_threshold;
2930 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2931 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002932 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2933 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002934 if (changed & WIPHY_PARAM_TXQ_LIMIT)
2935 rdev->wiphy.txq_limit = txq_limit;
2936 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
2937 rdev->wiphy.txq_memory_limit = txq_memory_limit;
2938 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
2939 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002940
Hila Gonene35e4d22012-06-27 17:19:42 +03002941 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002942 if (result) {
2943 rdev->wiphy.retry_short = old_retry_short;
2944 rdev->wiphy.retry_long = old_retry_long;
2945 rdev->wiphy.frag_threshold = old_frag_threshold;
2946 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002947 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002948 rdev->wiphy.txq_limit = old_txq_limit;
2949 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
2950 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02002951 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002952 }
2953 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002954 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002955}
2956
Johannes Berg683b6d32012-11-08 21:25:48 +01002957static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002958 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002959{
Johannes Berg601555c2014-11-27 17:26:56 +01002960 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2961 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002962
Johannes Berg683b6d32012-11-08 21:25:48 +01002963 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2964 chandef->chan->center_freq))
2965 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002966 switch (chandef->width) {
2967 case NL80211_CHAN_WIDTH_20_NOHT:
2968 case NL80211_CHAN_WIDTH_20:
2969 case NL80211_CHAN_WIDTH_40:
2970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2971 cfg80211_get_chandef_type(chandef)))
2972 return -ENOBUFS;
2973 break;
2974 default:
2975 break;
2976 }
2977 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2978 return -ENOBUFS;
2979 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2980 return -ENOBUFS;
2981 if (chandef->center_freq2 &&
2982 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002983 return -ENOBUFS;
2984 return 0;
2985}
2986
Eric W. Biederman15e47302012-09-07 20:12:54 +00002987static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002988 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02002989 struct wireless_dev *wdev,
2990 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04002991{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002992 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002993 void *hdr;
2994
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02002995 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
2996 cmd != NL80211_CMD_DEL_INTERFACE &&
2997 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002998
2999 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003000 if (!hdr)
3001 return -1;
3002
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003003 if (dev &&
3004 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003005 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003006 goto nla_put_failure;
3007
3008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3009 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003010 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3011 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003012 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003013 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3014 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003015 (cfg80211_rdev_list_generation << 2)) ||
3016 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003017 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003018
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003019 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003020 int ret;
3021 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003022
Johannes Berg683b6d32012-11-08 21:25:48 +01003023 ret = rdev_get_channel(rdev, wdev, &chandef);
3024 if (ret == 0) {
3025 if (nl80211_send_chandef(msg, &chandef))
3026 goto nla_put_failure;
3027 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003028 }
3029
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003030 if (rdev->ops->get_tx_power) {
3031 int dbm, ret;
3032
3033 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3034 if (ret == 0 &&
3035 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3036 DBM_TO_MBM(dbm)))
3037 goto nla_put_failure;
3038 }
3039
Johannes Berg44905262017-10-17 21:56:01 +02003040 wdev_lock(wdev);
3041 switch (wdev->iftype) {
3042 case NL80211_IFTYPE_AP:
3043 if (wdev->ssid_len &&
3044 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003045 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003046 break;
3047 case NL80211_IFTYPE_STATION:
3048 case NL80211_IFTYPE_P2P_CLIENT:
3049 case NL80211_IFTYPE_ADHOC: {
3050 const u8 *ssid_ie;
3051 if (!wdev->current_bss)
3052 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003053 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003054 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3055 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003056 if (ssid_ie &&
3057 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3058 goto nla_put_failure_rcu_locked;
3059 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003060 break;
3061 }
3062 default:
3063 /* nothing */
3064 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003065 }
Johannes Berg44905262017-10-17 21:56:01 +02003066 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003067
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003068 if (rdev->ops->get_txq_stats) {
3069 struct cfg80211_txq_stats txqstats = {};
3070 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3071
3072 if (ret == 0 &&
3073 !nl80211_put_txq_stats(msg, &txqstats,
3074 NL80211_ATTR_TXQ_STATS))
3075 goto nla_put_failure;
3076 }
3077
Johannes Berg053c0952015-01-16 22:09:00 +01003078 genlmsg_end(msg, hdr);
3079 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003080
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003081 nla_put_failure_rcu_locked:
3082 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003083 nla_put_failure_locked:
3084 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003085 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003086 genlmsg_cancel(msg, hdr);
3087 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003088}
3089
3090static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3091{
3092 int wp_idx = 0;
3093 int if_idx = 0;
3094 int wp_start = cb->args[0];
3095 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003096 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003097 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003098 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003099 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003100
Johannes Berg5fe231e2013-05-08 21:45:15 +02003101 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003102 if (!cb->args[2]) {
3103 struct nl80211_dump_wiphy_state state = {
3104 .filter_wiphy = -1,
3105 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003106
3107 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3108 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003109 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003110
3111 filter_wiphy = state.filter_wiphy;
3112
3113 /*
3114 * if filtering, set cb->args[2] to +1 since 0 is the default
3115 * value needed to determine that parsing is necessary.
3116 */
3117 if (filter_wiphy >= 0)
3118 cb->args[2] = filter_wiphy + 1;
3119 else
3120 cb->args[2] = -1;
3121 } else if (cb->args[2] > 0) {
3122 filter_wiphy = cb->args[2] - 1;
3123 }
3124
Johannes Bergf5ea9122009-08-07 16:17:38 +02003125 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3126 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003127 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003128 if (wp_idx < wp_start) {
3129 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003130 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003131 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003132
3133 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3134 continue;
3135
Johannes Berg55682962007-09-20 13:09:35 -04003136 if_idx = 0;
3137
Johannes Berg53873f12016-05-03 16:52:04 +03003138 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003139 if (if_idx < if_start) {
3140 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003141 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003142 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003143 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003144 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003145 rdev, wdev,
3146 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003147 goto out;
3148 }
3149 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003150 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003151
3152 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003153 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003154 out:
Johannes Berg55682962007-09-20 13:09:35 -04003155 cb->args[0] = wp_idx;
3156 cb->args[1] = if_idx;
3157
Johannes Bergea90e0d2017-03-15 14:26:04 +01003158 ret = skb->len;
3159 out_unlock:
3160 rtnl_unlock();
3161
3162 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003163}
3164
3165static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3166{
3167 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003169 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003170
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003172 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003173 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003174
Eric W. Biederman15e47302012-09-07 20:12:54 +00003175 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003176 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003177 nlmsg_free(msg);
3178 return -ENOBUFS;
3179 }
Johannes Berg55682962007-09-20 13:09:35 -04003180
Johannes Berg134e6372009-07-10 09:51:34 +00003181 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003182}
3183
Michael Wu66f7ac52008-01-31 19:48:22 +01003184static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3185 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3186 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3187 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3188 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3189 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003190 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003191};
3192
3193static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3194{
3195 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3196 int flag;
3197
3198 *mntrflags = 0;
3199
3200 if (!nla)
3201 return -EINVAL;
3202
Johannes Bergfceb6432017-04-12 14:34:07 +02003203 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
3204 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003205 return -EINVAL;
3206
3207 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3208 if (flags[flag])
3209 *mntrflags |= (1<<flag);
3210
Johannes Berg818a9862017-04-12 11:23:28 +02003211 *mntrflags |= MONITOR_FLAG_CHANGED;
3212
Michael Wu66f7ac52008-01-31 19:48:22 +01003213 return 0;
3214}
3215
Johannes Berg1db77592017-04-12 11:36:31 +02003216static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3217 enum nl80211_iftype type,
3218 struct genl_info *info,
3219 struct vif_params *params)
3220{
3221 bool change = false;
3222 int err;
3223
3224 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3225 if (type != NL80211_IFTYPE_MONITOR)
3226 return -EINVAL;
3227
3228 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3229 &params->flags);
3230 if (err)
3231 return err;
3232
3233 change = true;
3234 }
3235
3236 if (params->flags & MONITOR_FLAG_ACTIVE &&
3237 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3238 return -EOPNOTSUPP;
3239
3240 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3241 const u8 *mumimo_groups;
3242 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3243
3244 if (type != NL80211_IFTYPE_MONITOR)
3245 return -EINVAL;
3246
3247 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3248 return -EOPNOTSUPP;
3249
3250 mumimo_groups =
3251 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3252
3253 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003254 if ((mumimo_groups[0] & BIT(0)) ||
3255 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003256 return -EINVAL;
3257
3258 params->vht_mumimo_groups = mumimo_groups;
3259 change = true;
3260 }
3261
3262 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3263 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3264
3265 if (type != NL80211_IFTYPE_MONITOR)
3266 return -EINVAL;
3267
3268 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3269 return -EOPNOTSUPP;
3270
3271 params->vht_mumimo_follow_addr =
3272 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3273 change = true;
3274 }
3275
3276 return change ? 1 : 0;
3277}
3278
Johannes Berg9bc383d2009-11-19 11:55:19 +01003279static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003280 struct net_device *netdev, u8 use_4addr,
3281 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003282{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003283 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003284 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003285 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003286 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003287 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003288
3289 switch (iftype) {
3290 case NL80211_IFTYPE_AP_VLAN:
3291 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3292 return 0;
3293 break;
3294 case NL80211_IFTYPE_STATION:
3295 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3296 return 0;
3297 break;
3298 default:
3299 break;
3300 }
3301
3302 return -EOPNOTSUPP;
3303}
3304
Johannes Berg55682962007-09-20 13:09:35 -04003305static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3306{
Johannes Berg4c476992010-10-04 21:36:35 +02003307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003308 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003309 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003310 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003311 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003312 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003313
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003314 memset(&params, 0, sizeof(params));
3315
Johannes Berg04a773a2009-04-19 21:24:32 +02003316 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003317
Johannes Berg723b0382008-09-16 20:22:09 +02003318 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003319 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003320 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003321 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003322 }
3323
Johannes Berg92ffe052008-09-16 20:39:36 +02003324 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003325 struct wireless_dev *wdev = dev->ieee80211_ptr;
3326
Johannes Berg4c476992010-10-04 21:36:35 +02003327 if (ntype != NL80211_IFTYPE_MESH_POINT)
3328 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003329 if (netif_running(dev))
3330 return -EBUSY;
3331
3332 wdev_lock(wdev);
3333 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3334 IEEE80211_MAX_MESH_ID_LEN);
3335 wdev->mesh_id_up_len =
3336 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3337 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3338 wdev->mesh_id_up_len);
3339 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003340 }
3341
Felix Fietkau8b787642009-11-10 18:53:10 +01003342 if (info->attrs[NL80211_ATTR_4ADDR]) {
3343 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3344 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003345 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003346 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003347 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003348 } else {
3349 params.use_4addr = -1;
3350 }
3351
Johannes Berg1db77592017-04-12 11:36:31 +02003352 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3353 if (err < 0)
3354 return err;
3355 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003356 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003357
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003358 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003359 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003360 else
3361 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003362
Johannes Berg9bc383d2009-11-19 11:55:19 +01003363 if (!err && params.use_4addr != -1)
3364 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3365
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003366 if (change && !err) {
3367 struct wireless_dev *wdev = dev->ieee80211_ptr;
3368
3369 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3370 }
3371
Johannes Berg55682962007-09-20 13:09:35 -04003372 return err;
3373}
3374
3375static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3376{
Johannes Berg4c476992010-10-04 21:36:35 +02003377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003378 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003379 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003380 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003381 int err;
3382 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3383
Johannes Berg78f22b62014-03-24 17:57:27 +01003384 /* to avoid failing a new interface creation due to pending removal */
3385 cfg80211_destroy_ifaces(rdev);
3386
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003387 memset(&params, 0, sizeof(params));
3388
Johannes Berg55682962007-09-20 13:09:35 -04003389 if (!info->attrs[NL80211_ATTR_IFNAME])
3390 return -EINVAL;
3391
Johannes Bergab0d76f2018-10-02 10:00:07 +02003392 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003393 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003394
Johannes Berg79c97e92009-07-07 03:56:12 +02003395 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003396 !(rdev->wiphy.interface_modes & (1 << type)))
3397 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003398
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003399 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003400 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3401 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003402 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3403 ETH_ALEN);
3404 if (!is_valid_ether_addr(params.macaddr))
3405 return -EADDRNOTAVAIL;
3406 }
3407
Johannes Berg9bc383d2009-11-19 11:55:19 +01003408 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003409 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003410 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003411 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003412 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003413 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003414
Johannes Berg1db77592017-04-12 11:36:31 +02003415 err = nl80211_parse_mon_options(rdev, type, info, &params);
3416 if (err < 0)
3417 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003418
Johannes Berga18c7192015-02-24 10:56:42 +01003419 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3420 if (!msg)
3421 return -ENOMEM;
3422
Hila Gonene35e4d22012-06-27 17:19:42 +03003423 wdev = rdev_add_virtual_intf(rdev,
3424 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003425 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003426 if (WARN_ON(!wdev)) {
3427 nlmsg_free(msg);
3428 return -EPROTO;
3429 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003430 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003431 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003432 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003433
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003434 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003435 wdev->owner_nlportid = info->snd_portid;
3436
Johannes Berg98104fde2012-06-16 00:19:54 +02003437 switch (type) {
3438 case NL80211_IFTYPE_MESH_POINT:
3439 if (!info->attrs[NL80211_ATTR_MESH_ID])
3440 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003441 wdev_lock(wdev);
3442 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3443 IEEE80211_MAX_MESH_ID_LEN);
3444 wdev->mesh_id_up_len =
3445 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3446 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3447 wdev->mesh_id_up_len);
3448 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003449 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003450 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003451 case NL80211_IFTYPE_P2P_DEVICE:
3452 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003453 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003454 * through the netdev notifier and must be added here
3455 */
Johannes Berge4d42162018-09-13 14:12:03 +02003456 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003457 break;
3458 default:
3459 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003460 }
3461
Eric W. Biederman15e47302012-09-07 20:12:54 +00003462 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003463 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003464 nlmsg_free(msg);
3465 return -ENOBUFS;
3466 }
3467
3468 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003469}
3470
3471static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3472{
Johannes Berg4c476992010-10-04 21:36:35 +02003473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003474 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003475
Johannes Berg4c476992010-10-04 21:36:35 +02003476 if (!rdev->ops->del_virtual_intf)
3477 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003478
Johannes Berg84efbb82012-06-16 00:00:26 +02003479 /*
3480 * If we remove a wireless device without a netdev then clear
3481 * user_ptr[1] so that nl80211_post_doit won't dereference it
3482 * to check if it needs to do dev_put(). Otherwise it crashes
3483 * since the wdev has been freed, unlike with a netdev where
3484 * we need the dev_put() for the netdev to really be freed.
3485 */
3486 if (!wdev->netdev)
3487 info->user_ptr[1] = NULL;
3488
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003489 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003490}
3491
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003492static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3493{
3494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3495 struct net_device *dev = info->user_ptr[1];
3496 u16 noack_map;
3497
3498 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3499 return -EINVAL;
3500
3501 if (!rdev->ops->set_noack_map)
3502 return -EOPNOTSUPP;
3503
3504 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3505
Hila Gonene35e4d22012-06-27 17:19:42 +03003506 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003507}
3508
Johannes Berg41ade002007-12-19 02:03:29 +01003509struct get_key_cookie {
3510 struct sk_buff *msg;
3511 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003512 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003513};
3514
3515static void get_key_callback(void *c, struct key_params *params)
3516{
Johannes Bergb9454e82009-07-08 13:29:08 +02003517 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003518 struct get_key_cookie *cookie = c;
3519
David S. Miller9360ffd2012-03-29 04:41:26 -04003520 if ((params->key &&
3521 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3522 params->key_len, params->key)) ||
3523 (params->seq &&
3524 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3525 params->seq_len, params->seq)) ||
3526 (params->cipher &&
3527 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3528 params->cipher)))
3529 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003530
Johannes Bergb9454e82009-07-08 13:29:08 +02003531 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3532 if (!key)
3533 goto nla_put_failure;
3534
David S. Miller9360ffd2012-03-29 04:41:26 -04003535 if ((params->key &&
3536 nla_put(cookie->msg, NL80211_KEY_DATA,
3537 params->key_len, params->key)) ||
3538 (params->seq &&
3539 nla_put(cookie->msg, NL80211_KEY_SEQ,
3540 params->seq_len, params->seq)) ||
3541 (params->cipher &&
3542 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3543 params->cipher)))
3544 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003545
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003546 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003547 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003548
3549 nla_nest_end(cookie->msg, key);
3550
Johannes Berg41ade002007-12-19 02:03:29 +01003551 return;
3552 nla_put_failure:
3553 cookie->error = 1;
3554}
3555
3556static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3557{
Johannes Berg4c476992010-10-04 21:36:35 +02003558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003559 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003560 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003561 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003562 const u8 *mac_addr = NULL;
3563 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003564 struct get_key_cookie cookie = {
3565 .error = 0,
3566 };
3567 void *hdr;
3568 struct sk_buff *msg;
3569
3570 if (info->attrs[NL80211_ATTR_KEY_IDX])
3571 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3572
Johannes Berg41ade002007-12-19 02:03:29 +01003573 if (info->attrs[NL80211_ATTR_MAC])
3574 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3575
Johannes Berge31b8212010-10-05 19:39:30 +02003576 pairwise = !!mac_addr;
3577 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3578 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003579
Johannes Berge31b8212010-10-05 19:39:30 +02003580 if (kt != NL80211_KEYTYPE_GROUP &&
3581 kt != NL80211_KEYTYPE_PAIRWISE)
3582 return -EINVAL;
3583 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3584 }
3585
Johannes Berg4c476992010-10-04 21:36:35 +02003586 if (!rdev->ops->get_key)
3587 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003588
Johannes Berg0fa7b392015-01-23 11:10:12 +01003589 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3590 return -ENOENT;
3591
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003593 if (!msg)
3594 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003595
Eric W. Biederman15e47302012-09-07 20:12:54 +00003596 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003597 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003598 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003599 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003600
3601 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003602 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003603
David S. Miller9360ffd2012-03-29 04:41:26 -04003604 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3605 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3606 goto nla_put_failure;
3607 if (mac_addr &&
3608 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3609 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003610
Hila Gonene35e4d22012-06-27 17:19:42 +03003611 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3612 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003613
3614 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003615 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003616
3617 if (cookie.error)
3618 goto nla_put_failure;
3619
3620 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003621 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003622
3623 nla_put_failure:
3624 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003625 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003626 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003627 return err;
3628}
3629
3630static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3631{
Johannes Berg4c476992010-10-04 21:36:35 +02003632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003633 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003634 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003635 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003636
Johannes Bergb9454e82009-07-08 13:29:08 +02003637 err = nl80211_parse_key(info, &key);
3638 if (err)
3639 return err;
3640
3641 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003642 return -EINVAL;
3643
Johannes Bergb9454e82009-07-08 13:29:08 +02003644 /* only support setting default key */
3645 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003646 return -EINVAL;
3647
Johannes Bergfffd0932009-07-08 14:22:54 +02003648 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003649
3650 if (key.def) {
3651 if (!rdev->ops->set_default_key) {
3652 err = -EOPNOTSUPP;
3653 goto out;
3654 }
3655
3656 err = nl80211_key_allowed(dev->ieee80211_ptr);
3657 if (err)
3658 goto out;
3659
Hila Gonene35e4d22012-06-27 17:19:42 +03003660 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003661 key.def_uni, key.def_multi);
3662
3663 if (err)
3664 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003665
Johannes Berg3d23e342009-09-29 23:27:28 +02003666#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003667 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003668#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003669 } else {
3670 if (key.def_uni || !key.def_multi) {
3671 err = -EINVAL;
3672 goto out;
3673 }
3674
3675 if (!rdev->ops->set_default_mgmt_key) {
3676 err = -EOPNOTSUPP;
3677 goto out;
3678 }
3679
3680 err = nl80211_key_allowed(dev->ieee80211_ptr);
3681 if (err)
3682 goto out;
3683
Hila Gonene35e4d22012-06-27 17:19:42 +03003684 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003685 if (err)
3686 goto out;
3687
3688#ifdef CONFIG_CFG80211_WEXT
3689 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3690#endif
3691 }
3692
3693 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003694 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003695
Johannes Berg41ade002007-12-19 02:03:29 +01003696 return err;
3697}
3698
3699static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3700{
Johannes Berg4c476992010-10-04 21:36:35 +02003701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003702 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003703 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003704 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003705 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003706
Johannes Bergb9454e82009-07-08 13:29:08 +02003707 err = nl80211_parse_key(info, &key);
3708 if (err)
3709 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003710
Johannes Bergb9454e82009-07-08 13:29:08 +02003711 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003712 return -EINVAL;
3713
Johannes Berg41ade002007-12-19 02:03:29 +01003714 if (info->attrs[NL80211_ATTR_MAC])
3715 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3716
Johannes Berge31b8212010-10-05 19:39:30 +02003717 if (key.type == -1) {
3718 if (mac_addr)
3719 key.type = NL80211_KEYTYPE_PAIRWISE;
3720 else
3721 key.type = NL80211_KEYTYPE_GROUP;
3722 }
3723
3724 /* for now */
3725 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3726 key.type != NL80211_KEYTYPE_GROUP)
3727 return -EINVAL;
3728
Johannes Berg4c476992010-10-04 21:36:35 +02003729 if (!rdev->ops->add_key)
3730 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003731
Johannes Berge31b8212010-10-05 19:39:30 +02003732 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3733 key.type == NL80211_KEYTYPE_PAIRWISE,
3734 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003735 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003736
3737 wdev_lock(dev->ieee80211_ptr);
3738 err = nl80211_key_allowed(dev->ieee80211_ptr);
3739 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003740 err = rdev_add_key(rdev, dev, key.idx,
3741 key.type == NL80211_KEYTYPE_PAIRWISE,
3742 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003743 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003744
Johannes Berg41ade002007-12-19 02:03:29 +01003745 return err;
3746}
3747
3748static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3749{
Johannes Berg4c476992010-10-04 21:36:35 +02003750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003751 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003752 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003753 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003754 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003755
Johannes Bergb9454e82009-07-08 13:29:08 +02003756 err = nl80211_parse_key(info, &key);
3757 if (err)
3758 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003759
3760 if (info->attrs[NL80211_ATTR_MAC])
3761 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3762
Johannes Berge31b8212010-10-05 19:39:30 +02003763 if (key.type == -1) {
3764 if (mac_addr)
3765 key.type = NL80211_KEYTYPE_PAIRWISE;
3766 else
3767 key.type = NL80211_KEYTYPE_GROUP;
3768 }
3769
3770 /* for now */
3771 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3772 key.type != NL80211_KEYTYPE_GROUP)
3773 return -EINVAL;
3774
Johannes Berg4c476992010-10-04 21:36:35 +02003775 if (!rdev->ops->del_key)
3776 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003777
Johannes Bergfffd0932009-07-08 14:22:54 +02003778 wdev_lock(dev->ieee80211_ptr);
3779 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003780
Johannes Berg0fa7b392015-01-23 11:10:12 +01003781 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003782 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3783 err = -ENOENT;
3784
Johannes Bergfffd0932009-07-08 14:22:54 +02003785 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003786 err = rdev_del_key(rdev, dev, key.idx,
3787 key.type == NL80211_KEYTYPE_PAIRWISE,
3788 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003789
Johannes Berg3d23e342009-09-29 23:27:28 +02003790#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003791 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003792 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003793 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003794 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003795 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3796 }
3797#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003798 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003799
Johannes Berg41ade002007-12-19 02:03:29 +01003800 return err;
3801}
3802
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303803/* This function returns an error or the number of nested attributes */
3804static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3805{
3806 struct nlattr *attr;
3807 int n_entries = 0, tmp;
3808
3809 nla_for_each_nested(attr, nl_attr, tmp) {
3810 if (nla_len(attr) != ETH_ALEN)
3811 return -EINVAL;
3812
3813 n_entries++;
3814 }
3815
3816 return n_entries;
3817}
3818
3819/*
3820 * This function parses ACL information and allocates memory for ACL data.
3821 * On successful return, the calling function is responsible to free the
3822 * ACL buffer returned by this function.
3823 */
3824static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3825 struct genl_info *info)
3826{
3827 enum nl80211_acl_policy acl_policy;
3828 struct nlattr *attr;
3829 struct cfg80211_acl_data *acl;
3830 int i = 0, n_entries, tmp;
3831
3832 if (!wiphy->max_acl_mac_addrs)
3833 return ERR_PTR(-EOPNOTSUPP);
3834
3835 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3836 return ERR_PTR(-EINVAL);
3837
3838 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3839 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3840 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3841 return ERR_PTR(-EINVAL);
3842
3843 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3844 return ERR_PTR(-EINVAL);
3845
3846 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3847 if (n_entries < 0)
3848 return ERR_PTR(n_entries);
3849
3850 if (n_entries > wiphy->max_acl_mac_addrs)
3851 return ERR_PTR(-ENOTSUPP);
3852
3853 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3854 GFP_KERNEL);
3855 if (!acl)
3856 return ERR_PTR(-ENOMEM);
3857
3858 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3859 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3860 i++;
3861 }
3862
3863 acl->n_acl_entries = n_entries;
3864 acl->acl_policy = acl_policy;
3865
3866 return acl;
3867}
3868
3869static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3870{
3871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3872 struct net_device *dev = info->user_ptr[1];
3873 struct cfg80211_acl_data *acl;
3874 int err;
3875
3876 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3877 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3878 return -EOPNOTSUPP;
3879
3880 if (!dev->ieee80211_ptr->beacon_interval)
3881 return -EINVAL;
3882
3883 acl = parse_acl_data(&rdev->wiphy, info);
3884 if (IS_ERR(acl))
3885 return PTR_ERR(acl);
3886
3887 err = rdev_set_mac_acl(rdev, dev, acl);
3888
3889 kfree(acl);
3890
3891 return err;
3892}
3893
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303894static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3895 u8 *rates, u8 rates_len)
3896{
3897 u8 i;
3898 u32 mask = 0;
3899
3900 for (i = 0; i < rates_len; i++) {
3901 int rate = (rates[i] & 0x7f) * 5;
3902 int ridx;
3903
3904 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3905 struct ieee80211_rate *srate =
3906 &sband->bitrates[ridx];
3907 if (rate == srate->bitrate) {
3908 mask |= 1 << ridx;
3909 break;
3910 }
3911 }
3912 if (ridx == sband->n_bitrates)
3913 return 0; /* rate not found */
3914 }
3915
3916 return mask;
3917}
3918
3919static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3920 u8 *rates, u8 rates_len,
3921 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3922{
3923 u8 i;
3924
3925 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3926
3927 for (i = 0; i < rates_len; i++) {
3928 int ridx, rbit;
3929
3930 ridx = rates[i] / 8;
3931 rbit = BIT(rates[i] % 8);
3932
3933 /* check validity */
3934 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3935 return false;
3936
3937 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09003938 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303939 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3940 mcs[ridx] |= rbit;
3941 else
3942 return false;
3943 }
3944
3945 return true;
3946}
3947
3948static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3949{
3950 u16 mcs_mask = 0;
3951
3952 switch (vht_mcs_map) {
3953 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3954 break;
3955 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3956 mcs_mask = 0x00FF;
3957 break;
3958 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3959 mcs_mask = 0x01FF;
3960 break;
3961 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3962 mcs_mask = 0x03FF;
3963 break;
3964 default:
3965 break;
3966 }
3967
3968 return mcs_mask;
3969}
3970
3971static void vht_build_mcs_mask(u16 vht_mcs_map,
3972 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3973{
3974 u8 nss;
3975
3976 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3977 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3978 vht_mcs_map >>= 2;
3979 }
3980}
3981
3982static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3983 struct nl80211_txrate_vht *txrate,
3984 u16 mcs[NL80211_VHT_NSS_MAX])
3985{
3986 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3987 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3988 u8 i;
3989
3990 if (!sband->vht_cap.vht_supported)
3991 return false;
3992
3993 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3994
3995 /* Build vht_mcs_mask from VHT capabilities */
3996 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3997
3998 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3999 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4000 mcs[i] = txrate->mcs[i];
4001 else
4002 return false;
4003 }
4004
4005 return true;
4006}
4007
4008static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4009 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4010 .len = NL80211_MAX_SUPP_RATES },
4011 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4012 .len = NL80211_MAX_SUPP_HT_RATES },
4013 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
4014 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4015};
4016
4017static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4018 struct cfg80211_bitrate_mask *mask)
4019{
4020 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4021 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4022 int rem, i;
4023 struct nlattr *tx_rates;
4024 struct ieee80211_supported_band *sband;
4025 u16 vht_tx_mcs_map;
4026
4027 memset(mask, 0, sizeof(*mask));
4028 /* Default to all rates enabled */
4029 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4030 sband = rdev->wiphy.bands[i];
4031
4032 if (!sband)
4033 continue;
4034
4035 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4036 memcpy(mask->control[i].ht_mcs,
4037 sband->ht_cap.mcs.rx_mask,
4038 sizeof(mask->control[i].ht_mcs));
4039
4040 if (!sband->vht_cap.vht_supported)
4041 continue;
4042
4043 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4044 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4045 }
4046
4047 /* if no rates are given set it back to the defaults */
4048 if (!info->attrs[NL80211_ATTR_TX_RATES])
4049 goto out;
4050
4051 /* The nested attribute uses enum nl80211_band as the index. This maps
4052 * directly to the enum nl80211_band values used in cfg80211.
4053 */
4054 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4055 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4056 enum nl80211_band band = nla_type(tx_rates);
4057 int err;
4058
4059 if (band < 0 || band >= NUM_NL80211_BANDS)
4060 return -EINVAL;
4061 sband = rdev->wiphy.bands[band];
4062 if (sband == NULL)
4063 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02004064 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02004065 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304066 if (err)
4067 return err;
4068 if (tb[NL80211_TXRATE_LEGACY]) {
4069 mask->control[band].legacy = rateset_to_mask(
4070 sband,
4071 nla_data(tb[NL80211_TXRATE_LEGACY]),
4072 nla_len(tb[NL80211_TXRATE_LEGACY]));
4073 if ((mask->control[band].legacy == 0) &&
4074 nla_len(tb[NL80211_TXRATE_LEGACY]))
4075 return -EINVAL;
4076 }
4077 if (tb[NL80211_TXRATE_HT]) {
4078 if (!ht_rateset_to_mask(
4079 sband,
4080 nla_data(tb[NL80211_TXRATE_HT]),
4081 nla_len(tb[NL80211_TXRATE_HT]),
4082 mask->control[band].ht_mcs))
4083 return -EINVAL;
4084 }
4085 if (tb[NL80211_TXRATE_VHT]) {
4086 if (!vht_set_mcs_mask(
4087 sband,
4088 nla_data(tb[NL80211_TXRATE_VHT]),
4089 mask->control[band].vht_mcs))
4090 return -EINVAL;
4091 }
4092 if (tb[NL80211_TXRATE_GI]) {
4093 mask->control[band].gi =
4094 nla_get_u8(tb[NL80211_TXRATE_GI]);
4095 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4096 return -EINVAL;
4097 }
4098
4099 if (mask->control[band].legacy == 0) {
4100 /* don't allow empty legacy rates if HT or VHT
4101 * are not even supported.
4102 */
4103 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4104 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4105 return -EINVAL;
4106
4107 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4108 if (mask->control[band].ht_mcs[i])
4109 goto out;
4110
4111 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4112 if (mask->control[band].vht_mcs[i])
4113 goto out;
4114
4115 /* legacy and mcs rates may not be both empty */
4116 return -EINVAL;
4117 }
4118 }
4119
4120out:
4121 return 0;
4122}
4123
Johannes Berg8564e382016-09-19 09:44:44 +02004124static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4125 enum nl80211_band band,
4126 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304127{
Johannes Berg8564e382016-09-19 09:44:44 +02004128 u32 count_ht, count_vht, i;
4129 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304130
4131 /* Allow only one rate */
4132 if (hweight32(rate) > 1)
4133 return -EINVAL;
4134
4135 count_ht = 0;
4136 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004137 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304138 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004139 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304140 count_ht++;
4141 if (count_ht > 1)
4142 return -EINVAL;
4143 }
4144 if (count_ht && rate)
4145 return -EINVAL;
4146 }
4147
4148 count_vht = 0;
4149 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004150 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304151 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004152 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304153 count_vht++;
4154 if (count_vht > 1)
4155 return -EINVAL;
4156 }
4157 if (count_vht && rate)
4158 return -EINVAL;
4159 }
4160
4161 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4162 return -EINVAL;
4163
Johannes Berg8564e382016-09-19 09:44:44 +02004164 if (rate &&
4165 !wiphy_ext_feature_isset(&rdev->wiphy,
4166 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4167 return -EINVAL;
4168 if (count_ht &&
4169 !wiphy_ext_feature_isset(&rdev->wiphy,
4170 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4171 return -EINVAL;
4172 if (count_vht &&
4173 !wiphy_ext_feature_isset(&rdev->wiphy,
4174 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4175 return -EINVAL;
4176
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304177 return 0;
4178}
4179
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004180static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4181 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004182 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004183{
Johannes Berg88600202012-02-13 15:17:18 +01004184 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004185 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004186
Johannes Berg88600202012-02-13 15:17:18 +01004187 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004188
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004189 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4190 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4191 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004192 if (!bcn->head_len)
4193 return -EINVAL;
4194 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004195 }
4196
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004197 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4198 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4199 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004200 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004201 }
4202
Johannes Berg4c476992010-10-04 21:36:35 +02004203 if (!haveinfo)
4204 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004205
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004206 if (attrs[NL80211_ATTR_IE]) {
4207 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4208 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004209 }
4210
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004211 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004212 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004213 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004214 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004215 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004216 }
4217
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004218 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004219 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004220 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004221 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004222 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004223 }
4224
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004225 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4226 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4227 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004228 }
4229
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004230 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4231 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4232
4233 err = nla_parse_nested(tb, NL80211_FTM_RESP_ATTR_MAX,
4234 attrs[NL80211_ATTR_FTM_RESPONDER],
4235 NULL, NULL);
4236 if (err)
4237 return err;
4238
4239 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4240 wiphy_ext_feature_isset(&rdev->wiphy,
4241 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4242 bcn->ftm_responder = 1;
4243 else
4244 return -EOPNOTSUPP;
4245
4246 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4247 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4248 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4249 }
4250
4251 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4252 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4253 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4254 }
4255 } else {
4256 bcn->ftm_responder = -1;
4257 }
4258
Johannes Berg88600202012-02-13 15:17:18 +01004259 return 0;
4260}
4261
Johannes Berg66cd7942017-02-07 22:40:44 +02004262static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4263 const u8 *rates)
4264{
4265 int i;
4266
4267 if (!rates)
4268 return;
4269
4270 for (i = 0; i < rates[1]; i++) {
4271 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4272 params->ht_required = true;
4273 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4274 params->vht_required = true;
4275 }
4276}
4277
4278/*
4279 * Since the nl80211 API didn't include, from the beginning, attributes about
4280 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4281 * benefit of drivers that rebuild IEs in the firmware.
4282 */
4283static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4284{
4285 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004286 size_t ies_len = bcn->tail_len;
4287 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004288 const u8 *rates;
4289 const u8 *cap;
4290
4291 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4292 nl80211_check_ap_rate_selectors(params, rates);
4293
4294 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4295 nl80211_check_ap_rate_selectors(params, rates);
4296
4297 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4298 if (cap && cap[1] >= sizeof(*params->ht_cap))
4299 params->ht_cap = (void *)(cap + 2);
4300 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4301 if (cap && cap[1] >= sizeof(*params->vht_cap))
4302 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004303 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4304 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4305 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004306}
4307
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004308static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4309 struct cfg80211_ap_settings *params)
4310{
4311 struct wireless_dev *wdev;
4312 bool ret = false;
4313
Johannes Berg53873f12016-05-03 16:52:04 +03004314 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004315 if (wdev->iftype != NL80211_IFTYPE_AP &&
4316 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4317 continue;
4318
Johannes Berg683b6d32012-11-08 21:25:48 +01004319 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004320 continue;
4321
Johannes Berg683b6d32012-11-08 21:25:48 +01004322 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004323 ret = true;
4324 break;
4325 }
4326
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004327 return ret;
4328}
4329
Jouni Malinene39e5b52012-09-30 19:29:39 +03004330static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4331 enum nl80211_auth_type auth_type,
4332 enum nl80211_commands cmd)
4333{
4334 if (auth_type > NL80211_AUTHTYPE_MAX)
4335 return false;
4336
4337 switch (cmd) {
4338 case NL80211_CMD_AUTHENTICATE:
4339 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4340 auth_type == NL80211_AUTHTYPE_SAE)
4341 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004342 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4343 NL80211_EXT_FEATURE_FILS_STA) &&
4344 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4345 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4346 auth_type == NL80211_AUTHTYPE_FILS_PK))
4347 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004348 return true;
4349 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004350 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4351 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004352 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004353
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004354 /* FILS with SK PFS or PK not supported yet */
4355 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4356 auth_type == NL80211_AUTHTYPE_FILS_PK)
4357 return false;
4358 if (!wiphy_ext_feature_isset(
4359 &rdev->wiphy,
4360 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4361 auth_type == NL80211_AUTHTYPE_FILS_SK)
4362 return false;
4363 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004364 case NL80211_CMD_START_AP:
4365 /* SAE not supported yet */
4366 if (auth_type == NL80211_AUTHTYPE_SAE)
4367 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004368 /* FILS not supported yet */
4369 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4370 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4371 auth_type == NL80211_AUTHTYPE_FILS_PK)
4372 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004373 return true;
4374 default:
4375 return false;
4376 }
4377}
4378
Johannes Berg88600202012-02-13 15:17:18 +01004379static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4380{
4381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4382 struct net_device *dev = info->user_ptr[1];
4383 struct wireless_dev *wdev = dev->ieee80211_ptr;
4384 struct cfg80211_ap_settings params;
4385 int err;
4386
4387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4388 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4389 return -EOPNOTSUPP;
4390
4391 if (!rdev->ops->start_ap)
4392 return -EOPNOTSUPP;
4393
4394 if (wdev->beacon_interval)
4395 return -EALREADY;
4396
4397 memset(&params, 0, sizeof(params));
4398
4399 /* these are required for START_AP */
4400 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4401 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4402 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4403 return -EINVAL;
4404
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004405 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004406 if (err)
4407 return err;
4408
4409 params.beacon_interval =
4410 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4411 params.dtim_period =
4412 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4413
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304414 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4415 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004416 if (err)
4417 return err;
4418
4419 /*
4420 * In theory, some of these attributes should be required here
4421 * but since they were not used when the command was originally
4422 * added, keep them optional for old user space programs to let
4423 * them continue to work with drivers that do not need the
4424 * additional information -- drivers must check!
4425 */
4426 if (info->attrs[NL80211_ATTR_SSID]) {
4427 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4428 params.ssid_len =
4429 nla_len(info->attrs[NL80211_ATTR_SSID]);
4430 if (params.ssid_len == 0 ||
4431 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4432 return -EINVAL;
4433 }
4434
Johannes Bergab0d76f2018-10-02 10:00:07 +02004435 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004436 params.hidden_ssid = nla_get_u32(
4437 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004438
4439 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4440
4441 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4442 params.auth_type = nla_get_u32(
4443 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004444 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4445 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004446 return -EINVAL;
4447 } else
4448 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4449
4450 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4451 NL80211_MAX_NR_CIPHER_SUITES);
4452 if (err)
4453 return err;
4454
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304455 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4456 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4457 return -EOPNOTSUPP;
4458 params.inactivity_timeout = nla_get_u16(
4459 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4460 }
4461
Johannes Berg53cabad2012-11-14 15:17:28 +01004462 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4464 return -EINVAL;
4465 params.p2p_ctwindow =
4466 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004467 if (params.p2p_ctwindow != 0 &&
4468 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4469 return -EINVAL;
4470 }
4471
4472 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4473 u8 tmp;
4474
4475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4476 return -EINVAL;
4477 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004478 params.p2p_opp_ps = tmp;
4479 if (params.p2p_opp_ps != 0 &&
4480 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4481 return -EINVAL;
4482 }
4483
Johannes Bergaa430da2012-05-16 23:50:18 +02004484 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004485 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4486 if (err)
4487 return err;
4488 } else if (wdev->preset_chandef.chan) {
4489 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004490 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004491 return -EINVAL;
4492
Arik Nemtsov923b3522015-07-08 15:41:44 +03004493 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4494 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004495 return -EINVAL;
4496
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304497 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4498 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4499 if (err)
4500 return err;
4501
Johannes Berg8564e382016-09-19 09:44:44 +02004502 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4503 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304504 if (err)
4505 return err;
4506 }
4507
Eliad Peller18998c32014-09-10 14:07:34 +03004508 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4509 params.smps_mode =
4510 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4511 switch (params.smps_mode) {
4512 case NL80211_SMPS_OFF:
4513 break;
4514 case NL80211_SMPS_STATIC:
4515 if (!(rdev->wiphy.features &
4516 NL80211_FEATURE_STATIC_SMPS))
4517 return -EINVAL;
4518 break;
4519 case NL80211_SMPS_DYNAMIC:
4520 if (!(rdev->wiphy.features &
4521 NL80211_FEATURE_DYNAMIC_SMPS))
4522 return -EINVAL;
4523 break;
4524 default:
4525 return -EINVAL;
4526 }
4527 } else {
4528 params.smps_mode = NL80211_SMPS_OFF;
4529 }
4530
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304531 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4532 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4533 return -EOPNOTSUPP;
4534
Ola Olsson4baf6be2015-10-29 07:04:58 +01004535 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4536 params.acl = parse_acl_data(&rdev->wiphy, info);
4537 if (IS_ERR(params.acl))
4538 return PTR_ERR(params.acl);
4539 }
4540
Johannes Berg66cd7942017-02-07 22:40:44 +02004541 nl80211_calculate_ap_params(&params);
4542
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004543 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004544 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004545 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004546 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004547 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004548 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004549 wdev->ssid_len = params.ssid_len;
4550 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004551
4552 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4553 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004554 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004555 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304556
4557 kfree(params.acl);
4558
Johannes Berg56d18932011-05-09 18:41:15 +02004559 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004560}
4561
Johannes Berg88600202012-02-13 15:17:18 +01004562static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4563{
4564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4565 struct net_device *dev = info->user_ptr[1];
4566 struct wireless_dev *wdev = dev->ieee80211_ptr;
4567 struct cfg80211_beacon_data params;
4568 int err;
4569
4570 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4572 return -EOPNOTSUPP;
4573
4574 if (!rdev->ops->change_beacon)
4575 return -EOPNOTSUPP;
4576
4577 if (!wdev->beacon_interval)
4578 return -EINVAL;
4579
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004580 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004581 if (err)
4582 return err;
4583
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004584 wdev_lock(wdev);
4585 err = rdev_change_beacon(rdev, dev, &params);
4586 wdev_unlock(wdev);
4587
4588 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004589}
4590
4591static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004592{
Johannes Berg4c476992010-10-04 21:36:35 +02004593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4594 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004595
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004596 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004597}
4598
Johannes Berg5727ef12007-12-19 02:03:34 +01004599static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4600 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4601 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4602 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004603 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004604 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004605 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004606};
4607
Johannes Bergeccb8e82009-05-11 21:57:56 +03004608static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004609 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004610 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004611{
4612 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004613 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004614 int flag;
4615
Johannes Bergeccb8e82009-05-11 21:57:56 +03004616 /*
4617 * Try parsing the new attribute first so userspace
4618 * can specify both for older kernels.
4619 */
4620 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4621 if (nla) {
4622 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004623
Johannes Bergeccb8e82009-05-11 21:57:56 +03004624 sta_flags = nla_data(nla);
4625 params->sta_flags_mask = sta_flags->mask;
4626 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004627 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004628 if ((params->sta_flags_mask |
4629 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4630 return -EINVAL;
4631 return 0;
4632 }
4633
4634 /* if present, parse the old attribute */
4635
4636 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004637 if (!nla)
4638 return 0;
4639
Johannes Bergfceb6432017-04-12 14:34:07 +02004640 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004641 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004642 return -EINVAL;
4643
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004644 /*
4645 * Only allow certain flags for interface types so that
4646 * other attributes are silently ignored. Remember that
4647 * this is backward compatibility code with old userspace
4648 * and shouldn't be hit in other cases anyway.
4649 */
4650 switch (iftype) {
4651 case NL80211_IFTYPE_AP:
4652 case NL80211_IFTYPE_AP_VLAN:
4653 case NL80211_IFTYPE_P2P_GO:
4654 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4655 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4656 BIT(NL80211_STA_FLAG_WME) |
4657 BIT(NL80211_STA_FLAG_MFP);
4658 break;
4659 case NL80211_IFTYPE_P2P_CLIENT:
4660 case NL80211_IFTYPE_STATION:
4661 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4662 BIT(NL80211_STA_FLAG_TDLS_PEER);
4663 break;
4664 case NL80211_IFTYPE_MESH_POINT:
4665 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4666 BIT(NL80211_STA_FLAG_MFP) |
4667 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00004668 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004669 default:
4670 return -EINVAL;
4671 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004672
Johannes Berg3383b5a2012-05-10 20:14:43 +02004673 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4674 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004675 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004676
Johannes Berg3383b5a2012-05-10 20:14:43 +02004677 /* no longer support new API additions in old API */
4678 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4679 return -EINVAL;
4680 }
4681 }
4682
Johannes Berg5727ef12007-12-19 02:03:34 +01004683 return 0;
4684}
4685
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02004686bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004687{
4688 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004689 u32 bitrate;
4690 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004691 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004692
4693 rate = nla_nest_start(msg, attr);
4694 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004695 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004696
4697 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4698 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004699 /* report 16-bit bitrate only if we can */
4700 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004701 if (bitrate > 0 &&
4702 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4703 return false;
4704 if (bitrate_compat > 0 &&
4705 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4706 return false;
4707
Johannes Bergb51f3be2015-01-15 16:14:02 +01004708 switch (info->bw) {
4709 case RATE_INFO_BW_5:
4710 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4711 break;
4712 case RATE_INFO_BW_10:
4713 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4714 break;
4715 default:
4716 WARN_ON(1);
4717 /* fall through */
4718 case RATE_INFO_BW_20:
4719 rate_flg = 0;
4720 break;
4721 case RATE_INFO_BW_40:
4722 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4723 break;
4724 case RATE_INFO_BW_80:
4725 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4726 break;
4727 case RATE_INFO_BW_160:
4728 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4729 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004730 case RATE_INFO_BW_HE_RU:
4731 rate_flg = 0;
4732 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004733 }
4734
4735 if (rate_flg && nla_put_flag(msg, rate_flg))
4736 return false;
4737
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004738 if (info->flags & RATE_INFO_FLAGS_MCS) {
4739 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4740 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004741 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4742 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4743 return false;
4744 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4745 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4746 return false;
4747 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4748 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004749 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4750 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4751 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004752 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4753 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4754 return false;
4755 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4756 return false;
4757 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4758 return false;
4759 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4760 return false;
4761 if (info->bw == RATE_INFO_BW_HE_RU &&
4762 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4763 info->he_ru_alloc))
4764 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004765 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004766
4767 nla_nest_end(msg, rate);
4768 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004769}
4770
Felix Fietkau119363c2013-04-22 16:29:30 +02004771static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4772 int id)
4773{
4774 void *attr;
4775 int i = 0;
4776
4777 if (!mask)
4778 return true;
4779
4780 attr = nla_nest_start(msg, id);
4781 if (!attr)
4782 return false;
4783
4784 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4785 if (!(mask & BIT(i)))
4786 continue;
4787
4788 if (nla_put_u8(msg, i, signal[i]))
4789 return false;
4790 }
4791
4792 nla_nest_end(msg, attr);
4793
4794 return true;
4795}
4796
Johannes Bergcf5ead82014-11-14 17:14:00 +01004797static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4798 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004799 struct cfg80211_registered_device *rdev,
4800 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004801 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004802{
4803 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004804 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004805
Johannes Bergcf5ead82014-11-14 17:14:00 +01004806 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004807 if (!hdr)
4808 return -1;
4809
David S. Miller9360ffd2012-03-29 04:41:26 -04004810 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4811 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4812 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4813 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004814
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004815 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4816 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004817 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004818
4819#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004820 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03004821 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004822 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4823 sinfo->memb)) \
4824 goto nla_put_failure; \
4825 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004826#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03004827 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004828 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4829 sinfo->memb, NL80211_STA_INFO_PAD)) \
4830 goto nla_put_failure; \
4831 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004832
4833 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4834 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4835
Omer Efrat397c6572018-06-17 13:06:14 +03004836 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4837 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004838 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004839 (u32)sinfo->rx_bytes))
4840 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004841
Omer Efrat397c6572018-06-17 13:06:14 +03004842 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4843 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004844 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4845 (u32)sinfo->tx_bytes))
4846 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004847
Johannes Bergd686b922016-04-26 09:54:11 +02004848 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4849 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004850 PUT_SINFO(LLID, llid, u16);
4851 PUT_SINFO(PLID, plid, u16);
4852 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004853 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004854
John W. Linville66266b32012-03-15 13:25:41 -04004855 switch (rdev->wiphy.signal_type) {
4856 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004857 PUT_SINFO(SIGNAL, signal, u8);
4858 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004859 break;
4860 default:
4861 break;
4862 }
Omer Efrat397c6572018-06-17 13:06:14 +03004863 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004864 if (!nl80211_put_signal(msg, sinfo->chains,
4865 sinfo->chain_signal,
4866 NL80211_STA_INFO_CHAIN_SIGNAL))
4867 goto nla_put_failure;
4868 }
Omer Efrat397c6572018-06-17 13:06:14 +03004869 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004870 if (!nl80211_put_signal(msg, sinfo->chains,
4871 sinfo->chain_signal_avg,
4872 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4873 goto nla_put_failure;
4874 }
Omer Efrat397c6572018-06-17 13:06:14 +03004875 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004876 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4877 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004878 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004879 }
Omer Efrat397c6572018-06-17 13:06:14 +03004880 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004881 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4882 NL80211_STA_INFO_RX_BITRATE))
4883 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004884 }
Johannes Berg319090b2014-11-17 14:08:11 +01004885
4886 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4887 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4888 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4889 PUT_SINFO(TX_FAILED, tx_failed, u32);
4890 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4891 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4892 PUT_SINFO(LOCAL_PM, local_pm, u32);
4893 PUT_SINFO(PEER_PM, peer_pm, u32);
4894 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04004895 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004896
Omer Efrat397c6572018-06-17 13:06:14 +03004897 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004898 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4899 if (!bss_param)
4900 goto nla_put_failure;
4901
David S. Miller9360ffd2012-03-29 04:41:26 -04004902 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4903 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4904 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4905 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4906 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4907 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4908 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4909 sinfo->bss_param.dtim_period) ||
4910 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4911 sinfo->bss_param.beacon_interval))
4912 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004913
4914 nla_nest_end(msg, bss_param);
4915 }
Omer Efrat397c6572018-06-17 13:06:14 +03004916 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004917 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4918 sizeof(struct nl80211_sta_flag_update),
4919 &sinfo->sta_flags))
4920 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004921
Johannes Bergd686b922016-04-26 09:54:11 +02004922 PUT_SINFO_U64(T_OFFSET, t_offset);
4923 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4924 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004925 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03004926 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
4927 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05304928 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05304929 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
4930 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
4931 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
4932 }
Johannes Berg319090b2014-11-17 14:08:11 +01004933
4934#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004935#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004936
Arend van Spriel8689c052018-05-10 13:50:12 +02004937 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01004938 struct nlattr *tidsattr;
4939 int tid;
4940
4941 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4942 if (!tidsattr)
4943 goto nla_put_failure;
4944
4945 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4946 struct cfg80211_tid_stats *tidstats;
4947 struct nlattr *tidattr;
4948
4949 tidstats = &sinfo->pertid[tid];
4950
4951 if (!tidstats->filled)
4952 continue;
4953
4954 tidattr = nla_nest_start(msg, tid + 1);
4955 if (!tidattr)
4956 goto nla_put_failure;
4957
Johannes Bergd686b922016-04-26 09:54:11 +02004958#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004959 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004960 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4961 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004962 goto nla_put_failure; \
4963 } while (0)
4964
Johannes Bergd686b922016-04-26 09:54:11 +02004965 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4966 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4967 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4968 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004969
Johannes Bergd686b922016-04-26 09:54:11 +02004970#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02004971 if ((tidstats->filled &
4972 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
4973 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
4974 NL80211_TID_STATS_TXQ_STATS))
4975 goto nla_put_failure;
4976
Johannes Berg6de39802014-12-19 12:34:00 +01004977 nla_nest_end(msg, tidattr);
4978 }
4979
4980 nla_nest_end(msg, tidsattr);
4981 }
4982
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004983 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004984
Johannes Berg319090b2014-11-17 14:08:11 +01004985 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004986 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4987 sinfo->assoc_req_ies))
4988 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004989
Johannes Berg7ea3e112018-05-18 11:40:44 +02004990 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01004991 genlmsg_end(msg, hdr);
4992 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004993
4994 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02004995 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07004996 genlmsg_cancel(msg, hdr);
4997 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004998}
4999
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005000static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005001 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005002{
Johannes Berg73887fd2018-05-18 09:57:55 +02005003 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005004 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005005 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005006 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005007 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005008 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005009
Johannes Bergea90e0d2017-03-15 14:26:04 +01005010 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005011 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005012 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005013 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005014
Johannes Berg97990a02013-04-19 01:02:55 +02005015 if (!wdev->netdev) {
5016 err = -EINVAL;
5017 goto out_err;
5018 }
5019
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005020 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005021 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005022 goto out_err;
5023 }
5024
Johannes Bergbba95fe2008-07-29 13:22:51 +02005025 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005026 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005027 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005028 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005029 if (err == -ENOENT)
5030 break;
5031 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005032 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005033
Johannes Bergcf5ead82014-11-14 17:14:00 +01005034 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005035 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005036 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005037 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005038 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005039 goto out;
5040
5041 sta_idx++;
5042 }
5043
Johannes Bergbba95fe2008-07-29 13:22:51 +02005044 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005045 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005046 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005047 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005048 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005049
5050 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005051}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005052
Johannes Berg5727ef12007-12-19 02:03:34 +01005053static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5054{
Johannes Berg4c476992010-10-04 21:36:35 +02005055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5056 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005057 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005058 struct sk_buff *msg;
5059 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005060 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005061
Johannes Berg73887fd2018-05-18 09:57:55 +02005062 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005063
Johannes Berg73887fd2018-05-18 09:57:55 +02005064 if (!info->attrs[NL80211_ATTR_MAC])
5065 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005066
5067 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5068
Johannes Berg73887fd2018-05-18 09:57:55 +02005069 if (!rdev->ops->get_station)
5070 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005071
Johannes Berg73887fd2018-05-18 09:57:55 +02005072 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005073 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005074 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005075
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005076 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005077 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005078 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005079 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005080 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005081
Johannes Bergcf5ead82014-11-14 17:14:00 +01005082 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5083 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005084 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005085 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005086 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005087 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005088
Johannes Berg73887fd2018-05-18 09:57:55 +02005089 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005090}
5091
Johannes Berg77ee7c82013-02-15 00:48:33 +01005092int cfg80211_check_station_change(struct wiphy *wiphy,
5093 struct station_parameters *params,
5094 enum cfg80211_station_type statype)
5095{
Ayala Bekere4208422015-10-23 11:20:06 +03005096 if (params->listen_interval != -1 &&
5097 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005098 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005099
Ayala Beker17b94242016-03-17 15:41:38 +02005100 if (params->support_p2p_ps != -1 &&
5101 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5102 return -EINVAL;
5103
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005104 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005105 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5106 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005107 return -EINVAL;
5108
5109 /* When you run into this, adjust the code below for the new flag */
5110 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5111
5112 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005113 case CFG80211_STA_MESH_PEER_KERNEL:
5114 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005115 /*
5116 * No ignoring the TDLS flag here -- the userspace mesh
5117 * code doesn't have the bug of including TDLS in the
5118 * mask everywhere.
5119 */
5120 if (params->sta_flags_mask &
5121 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5122 BIT(NL80211_STA_FLAG_MFP) |
5123 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5124 return -EINVAL;
5125 break;
5126 case CFG80211_STA_TDLS_PEER_SETUP:
5127 case CFG80211_STA_TDLS_PEER_ACTIVE:
5128 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5129 return -EINVAL;
5130 /* ignore since it can't change */
5131 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5132 break;
5133 default:
5134 /* disallow mesh-specific things */
5135 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5136 return -EINVAL;
5137 if (params->local_pm)
5138 return -EINVAL;
5139 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5140 return -EINVAL;
5141 }
5142
5143 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5144 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5145 /* TDLS can't be set, ... */
5146 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5147 return -EINVAL;
5148 /*
5149 * ... but don't bother the driver with it. This works around
5150 * a hostapd/wpa_supplicant issue -- it always includes the
5151 * TLDS_PEER flag in the mask even for AP mode.
5152 */
5153 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5154 }
5155
Ayala Beker47edb112015-09-21 15:49:53 +03005156 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5157 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005158 /* reject other things that can't change */
5159 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5160 return -EINVAL;
5161 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5162 return -EINVAL;
5163 if (params->supported_rates)
5164 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005165 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5166 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005167 return -EINVAL;
5168 }
5169
Ayala Beker47edb112015-09-21 15:49:53 +03005170 if (statype != CFG80211_STA_AP_CLIENT &&
5171 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005172 if (params->vlan)
5173 return -EINVAL;
5174 }
5175
5176 switch (statype) {
5177 case CFG80211_STA_AP_MLME_CLIENT:
5178 /* Use this only for authorizing/unauthorizing a station */
5179 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5180 return -EOPNOTSUPP;
5181 break;
5182 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005183 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005184 /* accept only the listed bits */
5185 if (params->sta_flags_mask &
5186 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5187 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5188 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5189 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5190 BIT(NL80211_STA_FLAG_WME) |
5191 BIT(NL80211_STA_FLAG_MFP)))
5192 return -EINVAL;
5193
5194 /* but authenticated/associated only if driver handles it */
5195 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5196 params->sta_flags_mask &
5197 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5198 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5199 return -EINVAL;
5200 break;
5201 case CFG80211_STA_IBSS:
5202 case CFG80211_STA_AP_STA:
5203 /* reject any changes other than AUTHORIZED */
5204 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5205 return -EINVAL;
5206 break;
5207 case CFG80211_STA_TDLS_PEER_SETUP:
5208 /* reject any changes other than AUTHORIZED or WME */
5209 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5210 BIT(NL80211_STA_FLAG_WME)))
5211 return -EINVAL;
5212 /* force (at least) rates when authorizing */
5213 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5214 !params->supported_rates)
5215 return -EINVAL;
5216 break;
5217 case CFG80211_STA_TDLS_PEER_ACTIVE:
5218 /* reject any changes */
5219 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005220 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005221 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5222 return -EINVAL;
5223 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005224 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005225 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5226 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005227 return -EINVAL;
5228 break;
5229 }
5230
Beni Lev06f7c882016-07-19 19:28:56 +03005231 /*
5232 * Older kernel versions ignored this attribute entirely, so don't
5233 * reject attempts to update it but mark it as unused instead so the
5234 * driver won't look at the data.
5235 */
5236 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5237 statype != CFG80211_STA_TDLS_PEER_SETUP)
5238 params->opmode_notif_used = false;
5239
Johannes Berg77ee7c82013-02-15 00:48:33 +01005240 return 0;
5241}
5242EXPORT_SYMBOL(cfg80211_check_station_change);
5243
Johannes Berg5727ef12007-12-19 02:03:34 +01005244/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005245 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005246 */
Johannes Berg80b99892011-11-18 16:23:01 +01005247static struct net_device *get_vlan(struct genl_info *info,
5248 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005249{
Johannes Berg463d0182009-07-14 00:33:35 +02005250 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005251 struct net_device *v;
5252 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005253
Johannes Berg80b99892011-11-18 16:23:01 +01005254 if (!vlanattr)
5255 return NULL;
5256
5257 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5258 if (!v)
5259 return ERR_PTR(-ENODEV);
5260
5261 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5262 ret = -EINVAL;
5263 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005264 }
Johannes Berg80b99892011-11-18 16:23:01 +01005265
Johannes Berg77ee7c82013-02-15 00:48:33 +01005266 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5267 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5268 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5269 ret = -EINVAL;
5270 goto error;
5271 }
5272
Johannes Berg80b99892011-11-18 16:23:01 +01005273 if (!netif_running(v)) {
5274 ret = -ENETDOWN;
5275 goto error;
5276 }
5277
5278 return v;
5279 error:
5280 dev_put(v);
5281 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005282}
5283
Johannes Berg94e860f2014-01-20 23:58:15 +01005284static const struct nla_policy
5285nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005286 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5287 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5288};
5289
Johannes Bergff276692013-02-15 00:09:01 +01005290static int nl80211_parse_sta_wme(struct genl_info *info,
5291 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005292{
Jouni Malinendf881292013-02-14 21:10:54 +02005293 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5294 struct nlattr *nla;
5295 int err;
5296
Jouni Malinendf881292013-02-14 21:10:54 +02005297 /* parse WME attributes if present */
5298 if (!info->attrs[NL80211_ATTR_STA_WME])
5299 return 0;
5300
5301 nla = info->attrs[NL80211_ATTR_STA_WME];
5302 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02005303 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005304 if (err)
5305 return err;
5306
5307 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5308 params->uapsd_queues = nla_get_u8(
5309 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5310 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5311 return -EINVAL;
5312
5313 if (tb[NL80211_STA_WME_MAX_SP])
5314 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5315
5316 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5317 return -EINVAL;
5318
5319 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5320
5321 return 0;
5322}
5323
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305324static int nl80211_parse_sta_channel_info(struct genl_info *info,
5325 struct station_parameters *params)
5326{
5327 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5328 params->supported_channels =
5329 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5330 params->supported_channels_len =
5331 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5332 /*
5333 * Need to include at least one (first channel, number of
5334 * channels) tuple for each subband, and must have proper
5335 * tuples for the rest of the data as well.
5336 */
5337 if (params->supported_channels_len < 2)
5338 return -EINVAL;
5339 if (params->supported_channels_len % 2)
5340 return -EINVAL;
5341 }
5342
5343 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5344 params->supported_oper_classes =
5345 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5346 params->supported_oper_classes_len =
5347 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5348 /*
5349 * The value of the Length field of the Supported Operating
5350 * Classes element is between 2 and 253.
5351 */
5352 if (params->supported_oper_classes_len < 2 ||
5353 params->supported_oper_classes_len > 253)
5354 return -EINVAL;
5355 }
5356 return 0;
5357}
5358
Johannes Bergff276692013-02-15 00:09:01 +01005359static int nl80211_set_station_tdls(struct genl_info *info,
5360 struct station_parameters *params)
5361{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305362 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005363 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005364 if (info->attrs[NL80211_ATTR_PEER_AID])
5365 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005366 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5367 params->ht_capa =
5368 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5369 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5370 params->vht_capa =
5371 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005372 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5373 params->he_capa =
5374 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5375 params->he_capa_len =
5376 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5377
5378 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5379 return -EINVAL;
5380 }
Johannes Bergff276692013-02-15 00:09:01 +01005381
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305382 err = nl80211_parse_sta_channel_info(info, params);
5383 if (err)
5384 return err;
5385
Johannes Bergff276692013-02-15 00:09:01 +01005386 return nl80211_parse_sta_wme(info, params);
5387}
5388
Johannes Berg5727ef12007-12-19 02:03:34 +01005389static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5390{
Johannes Berg4c476992010-10-04 21:36:35 +02005391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005392 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005393 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005394 u8 *mac_addr;
5395 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005396
5397 memset(&params, 0, sizeof(params));
5398
Johannes Berg77ee7c82013-02-15 00:48:33 +01005399 if (!rdev->ops->change_station)
5400 return -EOPNOTSUPP;
5401
Ayala Bekere4208422015-10-23 11:20:06 +03005402 /*
5403 * AID and listen_interval properties can be set only for unassociated
5404 * station. Include these parameters here and will check them in
5405 * cfg80211_check_station_change().
5406 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005407 if (info->attrs[NL80211_ATTR_STA_AID])
5408 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005409
5410 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5411 params.listen_interval =
5412 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5413 else
5414 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005415
Johannes Bergab0d76f2018-10-02 10:00:07 +02005416 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5417 params.support_p2p_ps =
5418 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5419 else
Ayala Beker17b94242016-03-17 15:41:38 +02005420 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005421
Johannes Berg5727ef12007-12-19 02:03:34 +01005422 if (!info->attrs[NL80211_ATTR_MAC])
5423 return -EINVAL;
5424
5425 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5426
5427 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5428 params.supported_rates =
5429 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5430 params.supported_rates_len =
5431 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5432 }
5433
Jouni Malinen9d62a982013-02-14 21:10:13 +02005434 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5435 params.capability =
5436 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5437 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5438 }
5439
5440 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5441 params.ext_capab =
5442 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5443 params.ext_capab_len =
5444 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5445 }
5446
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005447 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005448 return -EINVAL;
5449
Johannes Bergab0d76f2018-10-02 10:00:07 +02005450 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005451 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005452 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005453
Johannes Bergf8bacc22013-02-14 23:27:01 +01005454 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005455 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005456 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005457 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005458 params.peer_aid = nla_get_u16(
5459 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005460 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5461 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005462
Johannes Bergab0d76f2018-10-02 10:00:07 +02005463 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5464 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005465 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5466
Beni Lev06f7c882016-07-19 19:28:56 +03005467 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5468 params.opmode_notif_used = true;
5469 params.opmode_notif =
5470 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5471 }
5472
Johannes Berg77ee7c82013-02-15 00:48:33 +01005473 /* Include parameters for TDLS peer (will check later) */
5474 err = nl80211_set_station_tdls(info, &params);
5475 if (err)
5476 return err;
5477
5478 params.vlan = get_vlan(info, rdev);
5479 if (IS_ERR(params.vlan))
5480 return PTR_ERR(params.vlan);
5481
Johannes Berga97f4422009-06-18 17:23:43 +02005482 switch (dev->ieee80211_ptr->iftype) {
5483 case NL80211_IFTYPE_AP:
5484 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005485 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005486 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005487 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005488 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005489 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005490 break;
5491 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005492 err = -EOPNOTSUPP;
5493 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005494 }
5495
Johannes Berg77ee7c82013-02-15 00:48:33 +01005496 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005497 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005498
Johannes Berg77ee7c82013-02-15 00:48:33 +01005499 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005500 if (params.vlan)
5501 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005502
Johannes Berg5727ef12007-12-19 02:03:34 +01005503 return err;
5504}
5505
5506static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5507{
Johannes Berg4c476992010-10-04 21:36:35 +02005508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005509 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005510 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005511 struct station_parameters params;
5512 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005513 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5514 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005515
5516 memset(&params, 0, sizeof(params));
5517
Johannes Berg984c3112013-02-14 23:43:25 +01005518 if (!rdev->ops->add_station)
5519 return -EOPNOTSUPP;
5520
Johannes Berg5727ef12007-12-19 02:03:34 +01005521 if (!info->attrs[NL80211_ATTR_MAC])
5522 return -EINVAL;
5523
Johannes Berg5727ef12007-12-19 02:03:34 +01005524 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5525 return -EINVAL;
5526
5527 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5528 return -EINVAL;
5529
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005530 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5531 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005532 return -EINVAL;
5533
Johannes Berg5727ef12007-12-19 02:03:34 +01005534 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5535 params.supported_rates =
5536 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5537 params.supported_rates_len =
5538 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5539 params.listen_interval =
5540 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005541
Ayala Beker17b94242016-03-17 15:41:38 +02005542 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02005543 params.support_p2p_ps =
5544 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02005545 } else {
5546 /*
5547 * if not specified, assume it's supported for P2P GO interface,
5548 * and is NOT supported for AP interface
5549 */
5550 params.support_p2p_ps =
5551 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5552 }
5553
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005554 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005555 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005556 else
5557 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005558
Jouni Malinen9d62a982013-02-14 21:10:13 +02005559 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5560 params.capability =
5561 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5562 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5563 }
5564
5565 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5566 params.ext_capab =
5567 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5568 params.ext_capab_len =
5569 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5570 }
5571
Jouni Malinen36aedc92008-08-25 11:58:58 +03005572 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5573 params.ht_capa =
5574 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005575
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005576 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5577 params.vht_capa =
5578 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5579
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005580 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5581 params.he_capa =
5582 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5583 params.he_capa_len =
5584 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5585
5586 /* max len is validated in nla policy */
5587 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5588 return -EINVAL;
5589 }
5590
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005591 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5592 params.opmode_notif_used = true;
5593 params.opmode_notif =
5594 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5595 }
5596
Johannes Bergab0d76f2018-10-02 10:00:07 +02005597 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07005598 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005599 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07005600
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305601 err = nl80211_parse_sta_channel_info(info, &params);
5602 if (err)
5603 return err;
5604
Johannes Bergff276692013-02-15 00:09:01 +01005605 err = nl80211_parse_sta_wme(info, &params);
5606 if (err)
5607 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005608
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005609 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005610 return -EINVAL;
5611
Johannes Berg496fcc22015-03-12 08:53:27 +02005612 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5613 * as userspace might just pass through the capabilities from the IEs
5614 * directly, rather than enforcing this restriction and returning an
5615 * error in this case.
5616 */
5617 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5618 params.ht_capa = NULL;
5619 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005620
5621 /* HE requires WME */
5622 if (params.he_capa_len)
5623 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005624 }
5625
Johannes Berg77ee7c82013-02-15 00:48:33 +01005626 /* When you run into this, adjust the code below for the new flag */
5627 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5628
Johannes Bergbdd90d52011-12-14 12:20:27 +01005629 switch (dev->ieee80211_ptr->iftype) {
5630 case NL80211_IFTYPE_AP:
5631 case NL80211_IFTYPE_AP_VLAN:
5632 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005633 /* ignore WME attributes if iface/sta is not capable */
5634 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5635 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5636 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005637
Johannes Bergbdd90d52011-12-14 12:20:27 +01005638 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005639 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5640 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005641 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005642 /* but don't bother the driver with it */
5643 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005644
Johannes Bergd582cff2012-10-26 17:53:44 +02005645 /* allow authenticated/associated only if driver handles it */
5646 if (!(rdev->wiphy.features &
5647 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005648 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005649 return -EINVAL;
5650
Johannes Bergbda95eb2015-11-26 16:26:13 +01005651 /* Older userspace, or userspace wanting to be compatible with
5652 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5653 * and assoc flags in the mask, but assumes the station will be
5654 * added as associated anyway since this was the required driver
5655 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5656 * introduced.
5657 * In order to not bother drivers with this quirk in the API
5658 * set the flags in both the mask and set for new stations in
5659 * this case.
5660 */
5661 if (!(params.sta_flags_mask & auth_assoc)) {
5662 params.sta_flags_mask |= auth_assoc;
5663 params.sta_flags_set |= auth_assoc;
5664 }
5665
Johannes Bergbdd90d52011-12-14 12:20:27 +01005666 /* must be last in here for error handling */
5667 params.vlan = get_vlan(info, rdev);
5668 if (IS_ERR(params.vlan))
5669 return PTR_ERR(params.vlan);
5670 break;
5671 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005672 /* ignore uAPSD data */
5673 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5674
Johannes Bergd582cff2012-10-26 17:53:44 +02005675 /* associated is disallowed */
5676 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5677 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005678 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005679 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5680 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005681 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005682 break;
5683 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005684 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005685 /* ignore uAPSD data */
5686 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5687
Johannes Berg77ee7c82013-02-15 00:48:33 +01005688 /* these are disallowed */
5689 if (params.sta_flags_mask &
5690 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5691 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005692 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005693 /* Only TDLS peers can be added */
5694 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5695 return -EINVAL;
5696 /* Can only add if TDLS ... */
5697 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5698 return -EOPNOTSUPP;
5699 /* ... with external setup is supported */
5700 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5701 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005702 /*
5703 * Older wpa_supplicant versions always mark the TDLS peer
5704 * as authorized, but it shouldn't yet be.
5705 */
5706 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005707 break;
5708 default:
5709 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005710 }
5711
Johannes Bergbdd90d52011-12-14 12:20:27 +01005712 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005713
Hila Gonene35e4d22012-06-27 17:19:42 +03005714 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005715
Johannes Berg5727ef12007-12-19 02:03:34 +01005716 if (params.vlan)
5717 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005718 return err;
5719}
5720
5721static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5722{
Johannes Berg4c476992010-10-04 21:36:35 +02005723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5724 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005725 struct station_del_parameters params;
5726
5727 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005728
5729 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005730 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005731
Johannes Berge80cf852009-05-11 14:43:13 +02005732 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005733 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005734 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005735 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5736 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005737
Johannes Berg4c476992010-10-04 21:36:35 +02005738 if (!rdev->ops->del_station)
5739 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005740
Jouni Malinen98856862014-10-20 13:20:45 +03005741 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5742 params.subtype =
5743 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5744 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5745 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5746 return -EINVAL;
5747 } else {
5748 /* Default to Deauthentication frame */
5749 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5750 }
5751
5752 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5753 params.reason_code =
5754 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5755 if (params.reason_code == 0)
5756 return -EINVAL; /* 0 is reserved */
5757 } else {
5758 /* Default to reason code 2 */
5759 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5760 }
5761
Jouni Malinen89c771e2014-10-10 20:52:40 +03005762 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005763}
5764
Eric W. Biederman15e47302012-09-07 20:12:54 +00005765static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005766 int flags, struct net_device *dev,
5767 u8 *dst, u8 *next_hop,
5768 struct mpath_info *pinfo)
5769{
5770 void *hdr;
5771 struct nlattr *pinfoattr;
5772
Henning Rogge1ef4c852014-11-04 16:14:58 +01005773 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005774 if (!hdr)
5775 return -1;
5776
David S. Miller9360ffd2012-03-29 04:41:26 -04005777 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5778 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5779 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5780 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5781 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005782
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005783 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5784 if (!pinfoattr)
5785 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005786 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5787 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5788 pinfo->frame_qlen))
5789 goto nla_put_failure;
5790 if (((pinfo->filled & MPATH_INFO_SN) &&
5791 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5792 ((pinfo->filled & MPATH_INFO_METRIC) &&
5793 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5794 pinfo->metric)) ||
5795 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5796 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5797 pinfo->exptime)) ||
5798 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5799 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5800 pinfo->flags)) ||
5801 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5802 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5803 pinfo->discovery_timeout)) ||
5804 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5805 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5806 pinfo->discovery_retries)))
5807 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005808
5809 nla_nest_end(msg, pinfoattr);
5810
Johannes Berg053c0952015-01-16 22:09:00 +01005811 genlmsg_end(msg, hdr);
5812 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005813
5814 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005815 genlmsg_cancel(msg, hdr);
5816 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005817}
5818
5819static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005820 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005821{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005822 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005823 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005824 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005825 u8 dst[ETH_ALEN];
5826 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005827 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005828 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005829
Johannes Bergea90e0d2017-03-15 14:26:04 +01005830 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005831 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005832 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005833 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005834
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005835 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005836 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005837 goto out_err;
5838 }
5839
Johannes Berg97990a02013-04-19 01:02:55 +02005840 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005841 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005842 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005843 }
5844
Johannes Bergbba95fe2008-07-29 13:22:51 +02005845 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005846 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005847 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005848 if (err == -ENOENT)
5849 break;
5850 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005851 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005852
Eric W. Biederman15e47302012-09-07 20:12:54 +00005853 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005854 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005855 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005856 &pinfo) < 0)
5857 goto out;
5858
5859 path_idx++;
5860 }
5861
Johannes Bergbba95fe2008-07-29 13:22:51 +02005862 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005863 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005864 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005865 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005866 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005867 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005868}
5869
5870static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5871{
Johannes Berg4c476992010-10-04 21:36:35 +02005872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005873 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005874 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005875 struct mpath_info pinfo;
5876 struct sk_buff *msg;
5877 u8 *dst = NULL;
5878 u8 next_hop[ETH_ALEN];
5879
5880 memset(&pinfo, 0, sizeof(pinfo));
5881
5882 if (!info->attrs[NL80211_ATTR_MAC])
5883 return -EINVAL;
5884
5885 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5886
Johannes Berg4c476992010-10-04 21:36:35 +02005887 if (!rdev->ops->get_mpath)
5888 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005889
Johannes Berg4c476992010-10-04 21:36:35 +02005890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5891 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005892
Hila Gonene35e4d22012-06-27 17:19:42 +03005893 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005894 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005895 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005896
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005897 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005898 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005899 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005900
Eric W. Biederman15e47302012-09-07 20:12:54 +00005901 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005902 dev, dst, next_hop, &pinfo) < 0) {
5903 nlmsg_free(msg);
5904 return -ENOBUFS;
5905 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005906
Johannes Berg4c476992010-10-04 21:36:35 +02005907 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005908}
5909
5910static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5911{
Johannes Berg4c476992010-10-04 21:36:35 +02005912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5913 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005914 u8 *dst = NULL;
5915 u8 *next_hop = NULL;
5916
5917 if (!info->attrs[NL80211_ATTR_MAC])
5918 return -EINVAL;
5919
5920 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5921 return -EINVAL;
5922
5923 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5924 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5925
Johannes Berg4c476992010-10-04 21:36:35 +02005926 if (!rdev->ops->change_mpath)
5927 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005928
Johannes Berg4c476992010-10-04 21:36:35 +02005929 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5930 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005931
Hila Gonene35e4d22012-06-27 17:19:42 +03005932 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005933}
Johannes Berg4c476992010-10-04 21:36:35 +02005934
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005935static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5936{
Johannes Berg4c476992010-10-04 21:36:35 +02005937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5938 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005939 u8 *dst = NULL;
5940 u8 *next_hop = NULL;
5941
5942 if (!info->attrs[NL80211_ATTR_MAC])
5943 return -EINVAL;
5944
5945 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5946 return -EINVAL;
5947
5948 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5949 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5950
Johannes Berg4c476992010-10-04 21:36:35 +02005951 if (!rdev->ops->add_mpath)
5952 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005953
Johannes Berg4c476992010-10-04 21:36:35 +02005954 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5955 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005956
Hila Gonene35e4d22012-06-27 17:19:42 +03005957 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005958}
5959
5960static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5961{
Johannes Berg4c476992010-10-04 21:36:35 +02005962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5963 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005964 u8 *dst = NULL;
5965
5966 if (info->attrs[NL80211_ATTR_MAC])
5967 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5968
Johannes Berg4c476992010-10-04 21:36:35 +02005969 if (!rdev->ops->del_mpath)
5970 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005971
Hila Gonene35e4d22012-06-27 17:19:42 +03005972 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005973}
5974
Henning Rogge66be7d22014-09-12 08:58:49 +02005975static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5976{
5977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5978 int err;
5979 struct net_device *dev = info->user_ptr[1];
5980 struct mpath_info pinfo;
5981 struct sk_buff *msg;
5982 u8 *dst = NULL;
5983 u8 mpp[ETH_ALEN];
5984
5985 memset(&pinfo, 0, sizeof(pinfo));
5986
5987 if (!info->attrs[NL80211_ATTR_MAC])
5988 return -EINVAL;
5989
5990 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5991
5992 if (!rdev->ops->get_mpp)
5993 return -EOPNOTSUPP;
5994
5995 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5996 return -EOPNOTSUPP;
5997
5998 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5999 if (err)
6000 return err;
6001
6002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6003 if (!msg)
6004 return -ENOMEM;
6005
6006 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6007 dev, dst, mpp, &pinfo) < 0) {
6008 nlmsg_free(msg);
6009 return -ENOBUFS;
6010 }
6011
6012 return genlmsg_reply(msg, info);
6013}
6014
6015static int nl80211_dump_mpp(struct sk_buff *skb,
6016 struct netlink_callback *cb)
6017{
6018 struct mpath_info pinfo;
6019 struct cfg80211_registered_device *rdev;
6020 struct wireless_dev *wdev;
6021 u8 dst[ETH_ALEN];
6022 u8 mpp[ETH_ALEN];
6023 int path_idx = cb->args[2];
6024 int err;
6025
Johannes Bergea90e0d2017-03-15 14:26:04 +01006026 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006027 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006028 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006029 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006030
6031 if (!rdev->ops->dump_mpp) {
6032 err = -EOPNOTSUPP;
6033 goto out_err;
6034 }
6035
6036 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6037 err = -EOPNOTSUPP;
6038 goto out_err;
6039 }
6040
6041 while (1) {
6042 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6043 mpp, &pinfo);
6044 if (err == -ENOENT)
6045 break;
6046 if (err)
6047 goto out_err;
6048
6049 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6050 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6051 wdev->netdev, dst, mpp,
6052 &pinfo) < 0)
6053 goto out;
6054
6055 path_idx++;
6056 }
6057
6058 out:
6059 cb->args[2] = path_idx;
6060 err = skb->len;
6061 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006062 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006063 return err;
6064}
6065
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006066static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6067{
Johannes Berg4c476992010-10-04 21:36:35 +02006068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6069 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006070 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006071 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006072 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006073
6074 memset(&params, 0, sizeof(params));
6075 /* default to not changing parameters */
6076 params.use_cts_prot = -1;
6077 params.use_short_preamble = -1;
6078 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006079 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006080 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006081 params.p2p_ctwindow = -1;
6082 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006083
6084 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6085 params.use_cts_prot =
6086 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6087 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6088 params.use_short_preamble =
6089 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6090 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6091 params.use_short_slot_time =
6092 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006093 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6094 params.basic_rates =
6095 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6096 params.basic_rates_len =
6097 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6098 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006099 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6100 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006101 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6102 params.ht_opmode =
6103 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006104
Johannes Berg53cabad2012-11-14 15:17:28 +01006105 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6107 return -EINVAL;
6108 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006109 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006110 if (params.p2p_ctwindow != 0 &&
6111 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6112 return -EINVAL;
6113 }
6114
6115 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6116 u8 tmp;
6117
6118 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6119 return -EINVAL;
6120 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006121 params.p2p_opp_ps = tmp;
6122 if (params.p2p_opp_ps &&
6123 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6124 return -EINVAL;
6125 }
6126
Johannes Berg4c476992010-10-04 21:36:35 +02006127 if (!rdev->ops->change_bss)
6128 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006129
Johannes Berg074ac8d2010-09-16 14:58:22 +02006130 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006131 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6132 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006133
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006134 wdev_lock(wdev);
6135 err = rdev_change_bss(rdev, dev, &params);
6136 wdev_unlock(wdev);
6137
6138 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006139}
6140
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006141static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6142{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006143 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006144 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006145 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006146 u32 owner_nlportid;
6147
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006148 /*
6149 * You should only get this when cfg80211 hasn't yet initialized
6150 * completely when built-in to the kernel right between the time
6151 * window between nl80211_init() and regulatory_init(), if that is
6152 * even possible.
6153 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006154 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006155 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006156
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006157 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6158 user_reg_hint_type =
6159 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6160 else
6161 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6162
6163 switch (user_reg_hint_type) {
6164 case NL80211_USER_REG_HINT_USER:
6165 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006166 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6167 return -EINVAL;
6168
6169 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6170 return regulatory_hint_user(data, user_reg_hint_type);
6171 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006172 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6173 owner_nlportid = info->snd_portid;
6174 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6175 } else {
6176 owner_nlportid = 0;
6177 is_indoor = true;
6178 }
6179
6180 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006181 default:
6182 return -EINVAL;
6183 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006184}
6185
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006186static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6187{
6188 return reg_reload_regdb();
6189}
6190
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006191static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006192 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006193{
Johannes Berg4c476992010-10-04 21:36:35 +02006194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006195 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006196 struct wireless_dev *wdev = dev->ieee80211_ptr;
6197 struct mesh_config cur_params;
6198 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006199 void *hdr;
6200 struct nlattr *pinfoattr;
6201 struct sk_buff *msg;
6202
Johannes Berg29cbe682010-12-03 09:20:44 +01006203 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6204 return -EOPNOTSUPP;
6205
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006206 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006207 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006208
Johannes Berg29cbe682010-12-03 09:20:44 +01006209 wdev_lock(wdev);
6210 /* If not connected, get default parameters */
6211 if (!wdev->mesh_id_len)
6212 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6213 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006214 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006215 wdev_unlock(wdev);
6216
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006217 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006218 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006219
6220 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006221 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006222 if (!msg)
6223 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006224 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006225 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006226 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006227 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006228 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006229 if (!pinfoattr)
6230 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006231 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6232 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6233 cur_params.dot11MeshRetryTimeout) ||
6234 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6235 cur_params.dot11MeshConfirmTimeout) ||
6236 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6237 cur_params.dot11MeshHoldingTimeout) ||
6238 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6239 cur_params.dot11MeshMaxPeerLinks) ||
6240 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6241 cur_params.dot11MeshMaxRetries) ||
6242 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6243 cur_params.dot11MeshTTL) ||
6244 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6245 cur_params.element_ttl) ||
6246 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6247 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006248 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6249 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006250 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6251 cur_params.dot11MeshHWMPmaxPREQretries) ||
6252 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6253 cur_params.path_refresh_time) ||
6254 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6255 cur_params.min_discovery_timeout) ||
6256 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6257 cur_params.dot11MeshHWMPactivePathTimeout) ||
6258 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6259 cur_params.dot11MeshHWMPpreqMinInterval) ||
6260 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6261 cur_params.dot11MeshHWMPperrMinInterval) ||
6262 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6263 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6264 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6265 cur_params.dot11MeshHWMPRootMode) ||
6266 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6267 cur_params.dot11MeshHWMPRannInterval) ||
6268 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6269 cur_params.dot11MeshGateAnnouncementProtocol) ||
6270 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6271 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006272 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006273 cur_params.rssi_threshold) ||
6274 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006275 cur_params.ht_opmode) ||
6276 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6277 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6278 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006279 cur_params.dot11MeshHWMProotInterval) ||
6280 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006281 cur_params.dot11MeshHWMPconfirmationInterval) ||
6282 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6283 cur_params.power_mode) ||
6284 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006285 cur_params.dot11MeshAwakeWindowDuration) ||
6286 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006287 cur_params.plink_timeout) ||
6288 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6289 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006290 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006291 nla_nest_end(msg, pinfoattr);
6292 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006293 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006294
Johannes Berg3b858752009-03-12 09:55:09 +01006295 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006296 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006297 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006298 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006299}
6300
Johannes Bergab0d76f2018-10-02 10:00:07 +02006301static const struct nla_policy
6302nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6303 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6304 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6305 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6306 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6307 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6308 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6309 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6310 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6311 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6312 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6313 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6314 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6315 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6316 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006317 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6318 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006319 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006320 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006321 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6322 NLA_POLICY_MIN(NLA_U16, 1),
6323 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6324 NLA_POLICY_MIN(NLA_U16, 1),
6325 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6326 NLA_POLICY_MIN(NLA_U16, 1),
6327 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6328 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6329 NLA_POLICY_MIN(NLA_U16, 1),
6330 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6331 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6332 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6333 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006334 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006335 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006336 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6337 NLA_POLICY_MIN(NLA_U16, 1),
6338 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6339 NLA_POLICY_MIN(NLA_U16, 1),
6340 [NL80211_MESHCONF_POWER_MODE] =
6341 NLA_POLICY_RANGE(NLA_U32,
6342 NL80211_MESH_POWER_ACTIVE,
6343 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006344 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006345 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006346 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006347};
6348
Javier Cardonac80d5452010-12-16 17:37:49 -08006349static const struct nla_policy
6350 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006351 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006352 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6353 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006354 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006355 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006356 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006357 [NL80211_MESH_SETUP_IE] =
6358 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6359 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006360 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006361};
6362
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006363static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006364 struct mesh_config *cfg,
6365 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006366{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006367 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006368 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006369 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006370
Johannes Bergab0d76f2018-10-02 10:00:07 +02006371#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6372do { \
6373 if (tb[attr]) { \
6374 cfg->param = fn(tb[attr]); \
6375 mask |= BIT((attr) - 1); \
6376 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006377} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006378
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006379 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006380 return -EINVAL;
6381 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006382 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02006383 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006384 return -EINVAL;
6385
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006386 /* This makes sure that there aren't more than 32 mesh config
6387 * parameters (otherwise our bitfield scheme would not work.) */
6388 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6389
6390 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006391 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6392 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6393 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6394 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6395 nla_get_u16);
6396 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6397 NL80211_MESHCONF_HOLDING_TIMEOUT,
6398 nla_get_u16);
6399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6400 NL80211_MESHCONF_MAX_PEER_LINKS,
6401 nla_get_u16);
6402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6403 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6404 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6405 NL80211_MESHCONF_TTL, nla_get_u8);
6406 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6407 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6408 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6409 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6410 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006412 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006413 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006414 nla_get_u32);
6415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6416 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6417 nla_get_u8);
6418 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6419 NL80211_MESHCONF_PATH_REFRESH_TIME,
6420 nla_get_u32);
6421 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6422 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6423 return -EINVAL;
6424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6425 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6426 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006427 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006428 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006429 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006430 nla_get_u32);
6431 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6432 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6433 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6434 return -EINVAL;
6435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006436 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006437 nla_get_u16);
6438 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006439 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006440 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006441 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006442 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006443 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006444 nla_get_u16);
6445 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6446 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6447 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6448 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6449 nla_get_u16);
6450 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006451 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006452 nla_get_u8);
6453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6454 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6455 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6456 NL80211_MESHCONF_RSSI_THRESHOLD,
6457 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006458 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6459 NL80211_MESHCONF_CONNECTED_TO_GATE,
6460 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006461 /*
6462 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006463 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006464 */
6465 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6466 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6467
6468 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6469 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6470 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6471 return -EINVAL;
6472
Bob Copeland188f60a2018-06-24 21:10:49 -04006473 /* NON_HT_STA bit is reserved, but some programs set it */
6474 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09006475
Masashi Honma97572352016-08-03 10:07:44 +09006476 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006477 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006478 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006479 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006480 dot11MeshHWMPactivePathToRootTimeout, mask,
6481 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6482 nla_get_u32);
6483 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6484 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6485 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6486 return -EINVAL;
6487 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6488 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6489 nla_get_u16);
6490 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6491 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006492 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006493 nla_get_u16);
6494 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6495 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6496 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6497 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6498 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6499 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006500 if (mask_out)
6501 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006502
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006503 return 0;
6504
6505#undef FILL_IN_MESH_PARAM_IF_SET
6506}
6507
Javier Cardonac80d5452010-12-16 17:37:49 -08006508static int nl80211_parse_mesh_setup(struct genl_info *info,
6509 struct mesh_setup *setup)
6510{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006512 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6513
6514 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6515 return -EINVAL;
6516 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6517 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006518 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006519 return -EINVAL;
6520
Javier Cardonad299a1f2012-03-31 11:31:33 -07006521 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6522 setup->sync_method =
6523 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6524 IEEE80211_SYNC_METHOD_VENDOR :
6525 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6526
Javier Cardonac80d5452010-12-16 17:37:49 -08006527 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6528 setup->path_sel_proto =
6529 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6530 IEEE80211_PATH_PROTOCOL_VENDOR :
6531 IEEE80211_PATH_PROTOCOL_HWMP;
6532
6533 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6534 setup->path_metric =
6535 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6536 IEEE80211_PATH_METRIC_VENDOR :
6537 IEEE80211_PATH_METRIC_AIRTIME;
6538
Javier Cardona581a8b02011-04-07 15:08:27 -07006539 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006540 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006541 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07006542 setup->ie = nla_data(ieattr);
6543 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006544 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006545 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6546 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6547 return -EINVAL;
6548 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006549 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6550 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006551 if (setup->is_secure)
6552 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006553
Colleen Twitty6e16d902013-05-08 11:45:59 -07006554 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6555 if (!setup->user_mpm)
6556 return -EINVAL;
6557 setup->auth_id =
6558 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6559 }
6560
Javier Cardonac80d5452010-12-16 17:37:49 -08006561 return 0;
6562}
6563
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006564static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006565 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006566{
6567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6568 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006570 struct mesh_config cfg;
6571 u32 mask;
6572 int err;
6573
Johannes Berg29cbe682010-12-03 09:20:44 +01006574 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6575 return -EOPNOTSUPP;
6576
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006577 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006578 return -EOPNOTSUPP;
6579
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006580 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006581 if (err)
6582 return err;
6583
Johannes Berg29cbe682010-12-03 09:20:44 +01006584 wdev_lock(wdev);
6585 if (!wdev->mesh_id_len)
6586 err = -ENOLINK;
6587
6588 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006589 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006590
6591 wdev_unlock(wdev);
6592
6593 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006594}
6595
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006596static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6597 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006598{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006599 struct nlattr *nl_reg_rules;
6600 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006601
Johannes Berg458f4f92012-12-06 15:47:38 +01006602 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6603 (regdom->dfs_region &&
6604 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006605 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006606
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006607 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6608 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006609 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006610
Johannes Berg458f4f92012-12-06 15:47:38 +01006611 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006612 struct nlattr *nl_reg_rule;
6613 const struct ieee80211_reg_rule *reg_rule;
6614 const struct ieee80211_freq_range *freq_range;
6615 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006616 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006617
Johannes Berg458f4f92012-12-06 15:47:38 +01006618 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006619 freq_range = &reg_rule->freq_range;
6620 power_rule = &reg_rule->power_rule;
6621
6622 nl_reg_rule = nla_nest_start(msg, i);
6623 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006624 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006625
Janusz Dziedzic97524822014-01-30 09:52:20 +01006626 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6627 if (!max_bandwidth_khz)
6628 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6629 reg_rule);
6630
David S. Miller9360ffd2012-03-29 04:41:26 -04006631 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6632 reg_rule->flags) ||
6633 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6634 freq_range->start_freq_khz) ||
6635 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6636 freq_range->end_freq_khz) ||
6637 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006638 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006639 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6640 power_rule->max_antenna_gain) ||
6641 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006642 power_rule->max_eirp) ||
6643 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6644 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006645 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006646
6647 nla_nest_end(msg, nl_reg_rule);
6648 }
6649
6650 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006651 return 0;
6652
6653nla_put_failure:
6654 return -EMSGSIZE;
6655}
6656
6657static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6658{
6659 const struct ieee80211_regdomain *regdom = NULL;
6660 struct cfg80211_registered_device *rdev;
6661 struct wiphy *wiphy = NULL;
6662 struct sk_buff *msg;
6663 void *hdr;
6664
6665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6666 if (!msg)
6667 return -ENOBUFS;
6668
6669 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6670 NL80211_CMD_GET_REG);
6671 if (!hdr)
6672 goto put_failure;
6673
6674 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006675 bool self_managed;
6676
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006677 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6678 if (IS_ERR(rdev)) {
6679 nlmsg_free(msg);
6680 return PTR_ERR(rdev);
6681 }
6682
6683 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006684 self_managed = wiphy->regulatory_flags &
6685 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006686 regdom = get_wiphy_regdom(wiphy);
6687
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006688 /* a self-managed-reg device must have a private regdom */
6689 if (WARN_ON(!regdom && self_managed)) {
6690 nlmsg_free(msg);
6691 return -EINVAL;
6692 }
6693
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006694 if (regdom &&
6695 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6696 goto nla_put_failure;
6697 }
6698
6699 if (!wiphy && reg_last_request_cell_base() &&
6700 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6701 NL80211_USER_REG_HINT_CELL_BASE))
6702 goto nla_put_failure;
6703
6704 rcu_read_lock();
6705
6706 if (!regdom)
6707 regdom = rcu_dereference(cfg80211_regdomain);
6708
6709 if (nl80211_put_regdom(regdom, msg))
6710 goto nla_put_failure_rcu;
6711
6712 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006713
6714 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006715 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006716
Johannes Berg458f4f92012-12-06 15:47:38 +01006717nla_put_failure_rcu:
6718 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006719nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006720put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006721 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006722 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006723}
6724
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006725static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6726 u32 seq, int flags, struct wiphy *wiphy,
6727 const struct ieee80211_regdomain *regdom)
6728{
6729 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6730 NL80211_CMD_GET_REG);
6731
6732 if (!hdr)
6733 return -1;
6734
Michal Kubecek0a833c22017-11-15 13:09:32 +01006735 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006736
6737 if (nl80211_put_regdom(regdom, msg))
6738 goto nla_put_failure;
6739
6740 if (!wiphy && reg_last_request_cell_base() &&
6741 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6742 NL80211_USER_REG_HINT_CELL_BASE))
6743 goto nla_put_failure;
6744
6745 if (wiphy &&
6746 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6747 goto nla_put_failure;
6748
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006749 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6750 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6751 goto nla_put_failure;
6752
Johannes Berg053c0952015-01-16 22:09:00 +01006753 genlmsg_end(msg, hdr);
6754 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006755
6756nla_put_failure:
6757 genlmsg_cancel(msg, hdr);
6758 return -EMSGSIZE;
6759}
6760
6761static int nl80211_get_reg_dump(struct sk_buff *skb,
6762 struct netlink_callback *cb)
6763{
6764 const struct ieee80211_regdomain *regdom = NULL;
6765 struct cfg80211_registered_device *rdev;
6766 int err, reg_idx, start = cb->args[2];
6767
6768 rtnl_lock();
6769
6770 if (cfg80211_regdomain && start == 0) {
6771 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6772 NLM_F_MULTI, NULL,
6773 rtnl_dereference(cfg80211_regdomain));
6774 if (err < 0)
6775 goto out_err;
6776 }
6777
6778 /* the global regdom is idx 0 */
6779 reg_idx = 1;
6780 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6781 regdom = get_wiphy_regdom(&rdev->wiphy);
6782 if (!regdom)
6783 continue;
6784
6785 if (++reg_idx <= start)
6786 continue;
6787
6788 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6789 NLM_F_MULTI, &rdev->wiphy, regdom);
6790 if (err < 0) {
6791 reg_idx--;
6792 break;
6793 }
6794 }
6795
6796 cb->args[2] = reg_idx;
6797 err = skb->len;
6798out_err:
6799 rtnl_unlock();
6800 return err;
6801}
6802
Johannes Bergb6863032015-10-15 09:25:18 +02006803#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6804static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6805 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6806 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6807 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6808 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6809 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6810 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6811 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6812};
6813
6814static int parse_reg_rule(struct nlattr *tb[],
6815 struct ieee80211_reg_rule *reg_rule)
6816{
6817 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6818 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6819
6820 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6821 return -EINVAL;
6822 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6823 return -EINVAL;
6824 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6825 return -EINVAL;
6826 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6827 return -EINVAL;
6828 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6829 return -EINVAL;
6830
6831 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6832
6833 freq_range->start_freq_khz =
6834 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6835 freq_range->end_freq_khz =
6836 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6837 freq_range->max_bandwidth_khz =
6838 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6839
6840 power_rule->max_eirp =
6841 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6842
6843 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6844 power_rule->max_antenna_gain =
6845 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6846
6847 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6848 reg_rule->dfs_cac_ms =
6849 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6850
6851 return 0;
6852}
6853
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006854static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6855{
6856 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6857 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006858 char *alpha2;
6859 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006860 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006861 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006862 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006863
6864 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6865 return -EINVAL;
6866
6867 if (!info->attrs[NL80211_ATTR_REG_RULES])
6868 return -EINVAL;
6869
6870 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6871
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006872 if (info->attrs[NL80211_ATTR_DFS_REGION])
6873 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6874
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006875 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006876 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006877 num_rules++;
6878 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006879 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006880 }
6881
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006882 if (!reg_is_valid_request(alpha2))
6883 return -EINVAL;
6884
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006885 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006886 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006887
6888 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006889 if (!rd)
6890 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006891
6892 rd->n_reg_rules = num_rules;
6893 rd->alpha2[0] = alpha2[0];
6894 rd->alpha2[1] = alpha2[1];
6895
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006896 /*
6897 * Disable DFS master mode if the DFS region was
6898 * not supported or known on this kernel.
6899 */
6900 if (reg_supported_dfs_region(dfs_region))
6901 rd->dfs_region = dfs_region;
6902
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006903 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006904 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006905 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006906 nl_reg_rule, reg_rule_policy,
6907 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006908 if (r)
6909 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006910 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6911 if (r)
6912 goto bad_reg;
6913
6914 rule_idx++;
6915
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006916 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6917 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006918 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006919 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006920 }
6921
Johannes Berg06627992016-06-09 10:40:09 +02006922 /* set_regdom takes ownership of rd */
6923 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006924 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006925 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006926 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006927}
Johannes Bergb6863032015-10-15 09:25:18 +02006928#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006929
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006930static int validate_scan_freqs(struct nlattr *freqs)
6931{
6932 struct nlattr *attr1, *attr2;
6933 int n_channels = 0, tmp1, tmp2;
6934
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006935 nla_for_each_nested(attr1, freqs, tmp1)
6936 if (nla_len(attr1) != sizeof(u32))
6937 return 0;
6938
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006939 nla_for_each_nested(attr1, freqs, tmp1) {
6940 n_channels++;
6941 /*
6942 * Some hardware has a limited channel list for
6943 * scanning, and it is pretty much nonsensical
6944 * to scan for a channel twice, so disallow that
6945 * and don't require drivers to check that the
6946 * channel list they get isn't longer than what
6947 * they can scan, as long as they can scan all
6948 * the channels they registered at once.
6949 */
6950 nla_for_each_nested(attr2, freqs, tmp2)
6951 if (attr1 != attr2 &&
6952 nla_get_u32(attr1) == nla_get_u32(attr2))
6953 return 0;
6954 }
6955
6956 return n_channels;
6957}
6958
Johannes Berg57fbcce2016-04-12 15:56:15 +02006959static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006960{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006961 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006962}
6963
6964static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6965 struct cfg80211_bss_selection *bss_select)
6966{
6967 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6968 struct nlattr *nest;
6969 int err;
6970 bool found = false;
6971 int i;
6972
6973 /* only process one nested attribute */
6974 nest = nla_data(nla);
6975 if (!nla_ok(nest, nla_len(nest)))
6976 return -EINVAL;
6977
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006978 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006979 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006980 if (err)
6981 return err;
6982
6983 /* only one attribute may be given */
6984 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6985 if (attr[i]) {
6986 if (found)
6987 return -EINVAL;
6988 found = true;
6989 }
6990 }
6991
6992 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6993
6994 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6995 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6996
6997 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6998 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6999 bss_select->param.band_pref =
7000 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7001 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7002 return -EINVAL;
7003 }
7004
7005 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7006 struct nl80211_bss_select_rssi_adjust *adj_param;
7007
7008 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7009 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7010 bss_select->param.adjust.band = adj_param->band;
7011 bss_select->param.adjust.delta = adj_param->delta;
7012 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7013 return -EINVAL;
7014 }
7015
7016 /* user-space did not provide behaviour attribute */
7017 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7018 return -EINVAL;
7019
7020 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7021 return -EINVAL;
7022
7023 return 0;
7024}
7025
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007026int nl80211_parse_random_mac(struct nlattr **attrs,
7027 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007028{
7029 int i;
7030
7031 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007032 eth_zero_addr(mac_addr);
7033 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007034 mac_addr[0] = 0x2;
7035 mac_addr_mask[0] = 0x3;
7036
7037 return 0;
7038 }
7039
7040 /* need both or none */
7041 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7042 return -EINVAL;
7043
7044 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7045 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7046
7047 /* don't allow or configure an mcast address */
7048 if (!is_multicast_ether_addr(mac_addr_mask) ||
7049 is_multicast_ether_addr(mac_addr))
7050 return -EINVAL;
7051
7052 /*
7053 * allow users to pass a MAC address that has bits set outside
7054 * of the mask, but don't bother drivers with having to deal
7055 * with such bits
7056 */
7057 for (i = 0; i < ETH_ALEN; i++)
7058 mac_addr[i] &= mac_addr_mask[i];
7059
7060 return 0;
7061}
7062
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307063static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7064{
7065 ASSERT_WDEV_LOCK(wdev);
7066
7067 if (!cfg80211_beaconing_iface_active(wdev))
7068 return true;
7069
7070 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7071 return true;
7072
7073 return regulatory_pre_cac_allowed(wdev->wiphy);
7074}
7075
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007076static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7077 enum nl80211_ext_feature_index feat)
7078{
7079 if (!(flags & flag))
7080 return true;
7081 if (wiphy_ext_feature_isset(wiphy, feat))
7082 return true;
7083 return false;
7084}
7085
Roee Zamir2d23d072017-08-06 11:38:22 +03007086static int
7087nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7088 void *request, struct nlattr **attrs,
7089 bool is_sched_scan)
7090{
7091 u8 *mac_addr, *mac_addr_mask;
7092 u32 *flags;
7093 enum nl80211_feature_flags randomness_flag;
7094
7095 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7096 return 0;
7097
7098 if (is_sched_scan) {
7099 struct cfg80211_sched_scan_request *req = request;
7100
7101 randomness_flag = wdev ?
7102 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7103 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7104 flags = &req->flags;
7105 mac_addr = req->mac_addr;
7106 mac_addr_mask = req->mac_addr_mask;
7107 } else {
7108 struct cfg80211_scan_request *req = request;
7109
7110 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7111 flags = &req->flags;
7112 mac_addr = req->mac_addr;
7113 mac_addr_mask = req->mac_addr_mask;
7114 }
7115
7116 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7117
Sunil Dutt5037a002018-01-25 17:13:37 +02007118 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7119 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007120 !nl80211_check_scan_feat(wiphy, *flags,
7121 NL80211_SCAN_FLAG_LOW_SPAN,
7122 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7123 !nl80211_check_scan_feat(wiphy, *flags,
7124 NL80211_SCAN_FLAG_LOW_POWER,
7125 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7126 !nl80211_check_scan_feat(wiphy, *flags,
7127 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7128 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7129 !nl80211_check_scan_feat(wiphy, *flags,
7130 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7131 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7132 !nl80211_check_scan_feat(wiphy, *flags,
7133 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7134 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7135 !nl80211_check_scan_feat(wiphy, *flags,
7136 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7137 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7138 !nl80211_check_scan_feat(wiphy, *flags,
7139 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007140 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7141 !nl80211_check_scan_feat(wiphy, *flags,
7142 NL80211_SCAN_FLAG_RANDOM_SN,
7143 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7144 !nl80211_check_scan_feat(wiphy, *flags,
7145 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7146 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007147 return -EOPNOTSUPP;
7148
7149 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7150 int err;
7151
7152 if (!(wiphy->features & randomness_flag) ||
7153 (wdev && wdev->current_bss))
7154 return -EOPNOTSUPP;
7155
7156 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7157 if (err)
7158 return err;
7159 }
7160
Roee Zamir2d23d072017-08-06 11:38:22 +03007161 return 0;
7162}
7163
Johannes Berg2a519312009-02-10 21:25:55 +01007164static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7165{
Johannes Berg4c476992010-10-04 21:36:35 +02007166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007167 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007168 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007169 struct nlattr *attr;
7170 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007171 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007172 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007173
Johannes Berg79c97e92009-07-07 03:56:12 +02007174 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007175
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007176 if (wdev->iftype == NL80211_IFTYPE_NAN)
7177 return -EOPNOTSUPP;
7178
Johannes Berg4c476992010-10-04 21:36:35 +02007179 if (!rdev->ops->scan)
7180 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007181
Johannes Bergf9d15d12014-01-22 11:14:19 +02007182 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007183 err = -EBUSY;
7184 goto unlock;
7185 }
Johannes Berg2a519312009-02-10 21:25:55 +01007186
7187 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007188 n_channels = validate_scan_freqs(
7189 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007190 if (!n_channels) {
7191 err = -EINVAL;
7192 goto unlock;
7193 }
Johannes Berg2a519312009-02-10 21:25:55 +01007194 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007195 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007196 }
7197
7198 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7199 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7200 n_ssids++;
7201
Johannes Bergf9f47522013-03-19 15:04:07 +01007202 if (n_ssids > wiphy->max_scan_ssids) {
7203 err = -EINVAL;
7204 goto unlock;
7205 }
Johannes Berg2a519312009-02-10 21:25:55 +01007206
Jouni Malinen70692ad2009-02-16 19:39:13 +02007207 if (info->attrs[NL80211_ATTR_IE])
7208 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7209 else
7210 ie_len = 0;
7211
Johannes Bergf9f47522013-03-19 15:04:07 +01007212 if (ie_len > wiphy->max_scan_ie_len) {
7213 err = -EINVAL;
7214 goto unlock;
7215 }
Johannes Berg18a83652009-03-31 12:12:05 +02007216
Johannes Berg2a519312009-02-10 21:25:55 +01007217 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007218 + sizeof(*request->ssids) * n_ssids
7219 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007220 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007221 if (!request) {
7222 err = -ENOMEM;
7223 goto unlock;
7224 }
Johannes Berg2a519312009-02-10 21:25:55 +01007225
Johannes Berg2a519312009-02-10 21:25:55 +01007226 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007227 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007228 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007229 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007230 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007231 request->ie = (void *)(request->ssids + n_ssids);
7232 else
7233 request->ie = (void *)(request->channels + n_channels);
7234 }
Johannes Berg2a519312009-02-10 21:25:55 +01007235
Johannes Berg584991d2009-11-02 13:32:03 +01007236 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007237 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7238 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007239 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007240 struct ieee80211_channel *chan;
7241
7242 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7243
7244 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007245 err = -EINVAL;
7246 goto out_free;
7247 }
Johannes Berg584991d2009-11-02 13:32:03 +01007248
7249 /* ignore disabled channels */
7250 if (chan->flags & IEEE80211_CHAN_DISABLED)
7251 continue;
7252
7253 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007254 i++;
7255 }
7256 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007257 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007258
Johannes Berg2a519312009-02-10 21:25:55 +01007259 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007260 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007261 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007262
Johannes Berg2a519312009-02-10 21:25:55 +01007263 if (!wiphy->bands[band])
7264 continue;
7265 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007266 struct ieee80211_channel *chan;
7267
7268 chan = &wiphy->bands[band]->channels[j];
7269
7270 if (chan->flags & IEEE80211_CHAN_DISABLED)
7271 continue;
7272
7273 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007274 i++;
7275 }
7276 }
7277 }
7278
Johannes Berg584991d2009-11-02 13:32:03 +01007279 if (!i) {
7280 err = -EINVAL;
7281 goto out_free;
7282 }
7283
7284 request->n_channels = i;
7285
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307286 wdev_lock(wdev);
7287 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7288 struct ieee80211_channel *chan;
7289
7290 if (request->n_channels != 1) {
7291 wdev_unlock(wdev);
7292 err = -EBUSY;
7293 goto out_free;
7294 }
7295
7296 chan = request->channels[0];
7297 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7298 wdev_unlock(wdev);
7299 err = -EBUSY;
7300 goto out_free;
7301 }
7302 }
7303 wdev_unlock(wdev);
7304
Johannes Berg2a519312009-02-10 21:25:55 +01007305 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007306 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007307 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007308 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007309 err = -EINVAL;
7310 goto out_free;
7311 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007312 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007313 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007314 i++;
7315 }
7316 }
7317
Jouni Malinen70692ad2009-02-16 19:39:13 +02007318 if (info->attrs[NL80211_ATTR_IE]) {
7319 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007320 memcpy((void *)request->ie,
7321 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007322 request->ie_len);
7323 }
7324
Johannes Berg57fbcce2016-04-12 15:56:15 +02007325 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007326 if (wiphy->bands[i])
7327 request->rates[i] =
7328 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007329
7330 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7331 nla_for_each_nested(attr,
7332 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7333 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007334 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007335
Johannes Berg57fbcce2016-04-12 15:56:15 +02007336 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007337 err = -EINVAL;
7338 goto out_free;
7339 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007340
7341 if (!wiphy->bands[band])
7342 continue;
7343
Johannes Berg34850ab2011-07-18 18:08:35 +02007344 err = ieee80211_get_ratemask(wiphy->bands[band],
7345 nla_data(attr),
7346 nla_len(attr),
7347 &request->rates[band]);
7348 if (err)
7349 goto out_free;
7350 }
7351 }
7352
Avraham Stern1d762502016-07-05 17:10:13 +03007353 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7354 if (!wiphy_ext_feature_isset(wiphy,
7355 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7356 err = -EOPNOTSUPP;
7357 goto out_free;
7358 }
7359
7360 request->duration =
7361 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7362 request->duration_mandatory =
7363 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7364 }
7365
Roee Zamir2d23d072017-08-06 11:38:22 +03007366 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7367 false);
7368 if (err)
7369 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007370
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307371 request->no_cck =
7372 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7373
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007374 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7375 * BSSID to scan for. This was problematic because that same attribute
7376 * was already used for another purpose (local random MAC address). The
7377 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7378 * compatibility with older userspace components, also use the
7379 * NL80211_ATTR_MAC value here if it can be determined to be used for
7380 * the specific BSSID use case instead of the random MAC address
7381 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7382 */
7383 if (info->attrs[NL80211_ATTR_BSSID])
7384 memcpy(request->bssid,
7385 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7386 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7387 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007388 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7389 ETH_ALEN);
7390 else
7391 eth_broadcast_addr(request->bssid);
7392
Johannes Bergfd014282012-06-18 19:17:03 +02007393 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007394 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007395 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007396
Johannes Berg79c97e92009-07-07 03:56:12 +02007397 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007398 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007399
Johannes Berg463d0182009-07-14 00:33:35 +02007400 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007401 nl80211_send_scan_start(rdev, wdev);
7402 if (wdev->netdev)
7403 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007404 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007405 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007406 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007407 kfree(request);
7408 }
Johannes Berg3b858752009-03-12 09:55:09 +01007409
Johannes Bergf9f47522013-03-19 15:04:07 +01007410 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007411 return err;
7412}
7413
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307414static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7415{
7416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7417 struct wireless_dev *wdev = info->user_ptr[1];
7418
7419 if (!rdev->ops->abort_scan)
7420 return -EOPNOTSUPP;
7421
7422 if (rdev->scan_msg)
7423 return 0;
7424
7425 if (!rdev->scan_req)
7426 return -ENOENT;
7427
7428 rdev_abort_scan(rdev, wdev);
7429 return 0;
7430}
7431
Avraham Stern3b06d272015-10-12 09:51:34 +03007432static int
7433nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7434 struct cfg80211_sched_scan_request *request,
7435 struct nlattr **attrs)
7436{
7437 int tmp, err, i = 0;
7438 struct nlattr *attr;
7439
7440 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7441 u32 interval;
7442
7443 /*
7444 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007445 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007446 * case one scan plan will be set with the specified scan
7447 * interval and infinite number of iterations.
7448 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007449 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7450 if (!interval)
7451 return -EINVAL;
7452
7453 request->scan_plans[0].interval =
7454 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7455 if (!request->scan_plans[0].interval)
7456 return -EINVAL;
7457
7458 if (request->scan_plans[0].interval >
7459 wiphy->max_sched_scan_plan_interval)
7460 request->scan_plans[0].interval =
7461 wiphy->max_sched_scan_plan_interval;
7462
7463 return 0;
7464 }
7465
7466 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7467 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7468
7469 if (WARN_ON(i >= n_plans))
7470 return -EINVAL;
7471
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007472 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007473 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007474 if (err)
7475 return err;
7476
7477 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7478 return -EINVAL;
7479
7480 request->scan_plans[i].interval =
7481 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7482 if (!request->scan_plans[i].interval ||
7483 request->scan_plans[i].interval >
7484 wiphy->max_sched_scan_plan_interval)
7485 return -EINVAL;
7486
7487 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7488 request->scan_plans[i].iterations =
7489 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7490 if (!request->scan_plans[i].iterations ||
7491 (request->scan_plans[i].iterations >
7492 wiphy->max_sched_scan_plan_iterations))
7493 return -EINVAL;
7494 } else if (i < n_plans - 1) {
7495 /*
7496 * All scan plans but the last one must specify
7497 * a finite number of iterations
7498 */
7499 return -EINVAL;
7500 }
7501
7502 i++;
7503 }
7504
7505 /*
7506 * The last scan plan must not specify the number of
7507 * iterations, it is supposed to run infinitely
7508 */
7509 if (request->scan_plans[n_plans - 1].iterations)
7510 return -EINVAL;
7511
7512 return 0;
7513}
7514
Luciano Coelho256da022014-11-10 16:13:46 +02007515static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007516nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007517 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007518{
7519 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007520 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007521 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007522 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007523 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007524 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007525 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007526
Luciano Coelho256da022014-11-10 16:13:46 +02007527 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007528 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007529 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007530 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007531 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007532 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007533 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007534 }
7535
Luciano Coelho256da022014-11-10 16:13:46 +02007536 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7537 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007538 tmp)
7539 n_ssids++;
7540
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007541 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007542 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007543
Johannes Bergea73cbc2014-01-24 10:53:53 +01007544 /*
7545 * First, count the number of 'real' matchsets. Due to an issue with
7546 * the old implementation, matchsets containing only the RSSI attribute
7547 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7548 * RSSI for all matchsets, rather than their own matchset for reporting
7549 * all APs with a strong RSSI. This is needed to be compatible with
7550 * older userspace that treated a matchset with only the RSSI as the
7551 * global RSSI for all other matchsets - if there are other matchsets.
7552 */
Luciano Coelho256da022014-11-10 16:13:46 +02007553 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007554 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007555 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007556 tmp) {
7557 struct nlattr *rssi;
7558
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007559 err = nla_parse_nested(tb,
7560 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007561 attr, nl80211_match_policy,
7562 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007563 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007564 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007565
7566 /* SSID and BSSID are mutually exclusive */
7567 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7568 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7569 return ERR_PTR(-EINVAL);
7570
Johannes Bergea73cbc2014-01-24 10:53:53 +01007571 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007572 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7573 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007574 n_match_sets++;
7575 continue;
7576 }
7577 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7578 if (rssi)
7579 default_match_rssi = nla_get_s32(rssi);
7580 }
7581 }
7582
7583 /* However, if there's no other matchset, add the RSSI one */
7584 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7585 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007586
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007587 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007588 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007589
Luciano Coelho256da022014-11-10 16:13:46 +02007590 if (attrs[NL80211_ATTR_IE])
7591 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007592 else
7593 ie_len = 0;
7594
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007595 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007596 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007597
Avraham Stern3b06d272015-10-12 09:51:34 +03007598 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7599 /*
7600 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7601 * each scan plan already specifies its own interval
7602 */
7603 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7604 return ERR_PTR(-EINVAL);
7605
7606 nla_for_each_nested(attr,
7607 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7608 n_plans++;
7609 } else {
7610 /*
7611 * The scan interval attribute is kept for backward
7612 * compatibility. If no scan plans are specified and sched scan
7613 * interval is specified, one scan plan will be set with this
7614 * scan interval and infinite number of iterations.
7615 */
7616 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7617 return ERR_PTR(-EINVAL);
7618
7619 n_plans = 1;
7620 }
7621
7622 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7623 return ERR_PTR(-EINVAL);
7624
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007625 if (!wiphy_ext_feature_isset(
7626 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7627 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7628 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7629 return ERR_PTR(-EINVAL);
7630
Luciano Coelho807f8a82011-05-11 17:09:35 +03007631 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007632 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007633 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007634 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007635 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007636 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007637 if (!request)
7638 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007639
7640 if (n_ssids)
7641 request->ssids = (void *)&request->channels[n_channels];
7642 request->n_ssids = n_ssids;
7643 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007644 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007645 request->ie = (void *)(request->ssids + n_ssids);
7646 else
7647 request->ie = (void *)(request->channels + n_channels);
7648 }
7649
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007650 if (n_match_sets) {
7651 if (request->ie)
7652 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007653 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007654 request->match_sets =
7655 (void *)(request->ssids + n_ssids);
7656 else
7657 request->match_sets =
7658 (void *)(request->channels + n_channels);
7659 }
7660 request->n_match_sets = n_match_sets;
7661
Avraham Stern3b06d272015-10-12 09:51:34 +03007662 if (n_match_sets)
7663 request->scan_plans = (void *)(request->match_sets +
7664 n_match_sets);
7665 else if (request->ie)
7666 request->scan_plans = (void *)(request->ie + ie_len);
7667 else if (n_ssids)
7668 request->scan_plans = (void *)(request->ssids + n_ssids);
7669 else
7670 request->scan_plans = (void *)(request->channels + n_channels);
7671
7672 request->n_scan_plans = n_plans;
7673
Luciano Coelho807f8a82011-05-11 17:09:35 +03007674 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007675 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007676 /* user specified, bail out if channel not found */
7677 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007678 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007679 tmp) {
7680 struct ieee80211_channel *chan;
7681
7682 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7683
7684 if (!chan) {
7685 err = -EINVAL;
7686 goto out_free;
7687 }
7688
7689 /* ignore disabled channels */
7690 if (chan->flags & IEEE80211_CHAN_DISABLED)
7691 continue;
7692
7693 request->channels[i] = chan;
7694 i++;
7695 }
7696 } else {
7697 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007698 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007699 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007700
Luciano Coelho807f8a82011-05-11 17:09:35 +03007701 if (!wiphy->bands[band])
7702 continue;
7703 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7704 struct ieee80211_channel *chan;
7705
7706 chan = &wiphy->bands[band]->channels[j];
7707
7708 if (chan->flags & IEEE80211_CHAN_DISABLED)
7709 continue;
7710
7711 request->channels[i] = chan;
7712 i++;
7713 }
7714 }
7715 }
7716
7717 if (!i) {
7718 err = -EINVAL;
7719 goto out_free;
7720 }
7721
7722 request->n_channels = i;
7723
7724 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007725 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007726 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007727 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007728 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007729 err = -EINVAL;
7730 goto out_free;
7731 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007732 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007733 memcpy(request->ssids[i].ssid, nla_data(attr),
7734 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007735 i++;
7736 }
7737 }
7738
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007739 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007740 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007741 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007742 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007743 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007744 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007745
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007746 err = nla_parse_nested(tb,
7747 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007748 attr, nl80211_match_policy,
7749 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007750 if (err)
7751 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007752 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007753 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7754 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007755 if (WARN_ON(i >= n_match_sets)) {
7756 /* this indicates a programming error,
7757 * the loop above should have verified
7758 * things properly
7759 */
7760 err = -EINVAL;
7761 goto out_free;
7762 }
7763
Arend Van Spriel3007e352017-04-21 13:05:01 +01007764 if (ssid) {
7765 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7766 err = -EINVAL;
7767 goto out_free;
7768 }
7769 memcpy(request->match_sets[i].ssid.ssid,
7770 nla_data(ssid), nla_len(ssid));
7771 request->match_sets[i].ssid.ssid_len =
7772 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007773 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007774 if (bssid) {
7775 if (nla_len(bssid) != ETH_ALEN) {
7776 err = -EINVAL;
7777 goto out_free;
7778 }
7779 memcpy(request->match_sets[i].bssid,
7780 nla_data(bssid), ETH_ALEN);
7781 }
7782
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007783 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007784 request->match_sets[i].rssi_thold =
7785 default_match_rssi;
7786 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7787 if (rssi)
7788 request->match_sets[i].rssi_thold =
7789 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007790 }
7791 i++;
7792 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007793
7794 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007795 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007796 request->match_sets[0].rssi_thold = default_match_rssi;
7797
7798 request->min_rssi_thold = INT_MAX;
7799 for (i = 0; i < n_match_sets; i++)
7800 request->min_rssi_thold =
7801 min(request->match_sets[i].rssi_thold,
7802 request->min_rssi_thold);
7803 } else {
7804 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007805 }
7806
Johannes Berg9900e482014-02-04 21:01:25 +01007807 if (ie_len) {
7808 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007809 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007810 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007811 request->ie_len);
7812 }
7813
Roee Zamir2d23d072017-08-06 11:38:22 +03007814 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7815 if (err)
7816 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007817
Luciano Coelho9c748932015-01-16 16:04:09 +02007818 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7819 request->delay =
7820 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7821
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007822 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7823 request->relative_rssi = nla_get_s8(
7824 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7825 request->relative_rssi_set = true;
7826 }
7827
7828 if (request->relative_rssi_set &&
7829 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7830 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7831
7832 rssi_adjust = nla_data(
7833 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7834 request->rssi_adjust.band = rssi_adjust->band;
7835 request->rssi_adjust.delta = rssi_adjust->delta;
7836 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7837 err = -EINVAL;
7838 goto out_free;
7839 }
7840 }
7841
Avraham Stern3b06d272015-10-12 09:51:34 +03007842 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7843 if (err)
7844 goto out_free;
7845
Sam Leffler15d60302012-10-11 21:03:34 -07007846 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007847
Luciano Coelho256da022014-11-10 16:13:46 +02007848 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007849
7850out_free:
7851 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007852 return ERR_PTR(err);
7853}
7854
7855static int nl80211_start_sched_scan(struct sk_buff *skb,
7856 struct genl_info *info)
7857{
7858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7859 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007860 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007861 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007862 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007863 int err;
7864
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007865 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007866 return -EOPNOTSUPP;
7867
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007868 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7869 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7870 if (err)
7871 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007872
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007873 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007874 info->attrs,
7875 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007876
7877 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007878 if (err)
7879 goto out_err;
7880
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007881 /* leave request id zero for legacy request
7882 * or if driver does not support multi-scheduled scan
7883 */
7884 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7885 while (!sched_scan_req->reqid)
Johannes Bergb60ad342018-10-01 11:52:07 +02007886 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007887 }
7888
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007889 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007890 if (err)
7891 goto out_free;
7892
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007893 sched_scan_req->dev = dev;
7894 sched_scan_req->wiphy = &rdev->wiphy;
7895
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007896 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7897 sched_scan_req->owner_nlportid = info->snd_portid;
7898
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007899 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007900
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007901 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007902 return 0;
7903
7904out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007905 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007906out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007907 return err;
7908}
7909
7910static int nl80211_stop_sched_scan(struct sk_buff *skb,
7911 struct genl_info *info)
7912{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007913 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007915 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007916
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007917 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007918 return -EOPNOTSUPP;
7919
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007920 if (info->attrs[NL80211_ATTR_COOKIE]) {
7921 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7922 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7923 }
7924
7925 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7926 struct cfg80211_sched_scan_request,
7927 list);
7928 if (!req || req->reqid ||
7929 (req->owner_nlportid &&
7930 req->owner_nlportid != info->snd_portid))
7931 return -ENOENT;
7932
7933 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007934}
7935
Simon Wunderlich04f39042013-02-08 18:16:19 +01007936static int nl80211_start_radar_detection(struct sk_buff *skb,
7937 struct genl_info *info)
7938{
7939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7940 struct net_device *dev = info->user_ptr[1];
7941 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007942 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007943 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007944 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007945 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007946 int err;
7947
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007948 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007949 if (dfs_region == NL80211_DFS_UNSET)
7950 return -EINVAL;
7951
Simon Wunderlich04f39042013-02-08 18:16:19 +01007952 err = nl80211_parse_chandef(rdev, info, &chandef);
7953 if (err)
7954 return err;
7955
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007956 if (netif_carrier_ok(dev))
7957 return -EBUSY;
7958
Simon Wunderlich04f39042013-02-08 18:16:19 +01007959 if (wdev->cac_started)
7960 return -EBUSY;
7961
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007962 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007963 if (err < 0)
7964 return err;
7965
7966 if (err == 0)
7967 return -EINVAL;
7968
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007969 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007970 return -EINVAL;
7971
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007972 /* CAC start is offloaded to HW and can't be started manually */
7973 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
7974 return -EOPNOTSUPP;
7975
Simon Wunderlich04f39042013-02-08 18:16:19 +01007976 if (!rdev->ops->start_radar_detection)
7977 return -EOPNOTSUPP;
7978
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007979 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7980 if (WARN_ON(!cac_time_ms))
7981 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7982
Ilan Peera1056b1b2015-10-22 22:27:46 +03007983 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007984 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007985 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007986 wdev->cac_started = true;
7987 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007988 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007989 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007990 return err;
7991}
7992
Sriram R30c63112018-12-04 17:46:52 +05307993static int nl80211_notify_radar_detection(struct sk_buff *skb,
7994 struct genl_info *info)
7995{
7996 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7997 struct net_device *dev = info->user_ptr[1];
7998 struct wireless_dev *wdev = dev->ieee80211_ptr;
7999 struct wiphy *wiphy = wdev->wiphy;
8000 struct cfg80211_chan_def chandef;
8001 enum nl80211_dfs_regions dfs_region;
8002 int err;
8003
8004 dfs_region = reg_get_dfs_region(wiphy);
8005 if (dfs_region == NL80211_DFS_UNSET) {
8006 GENL_SET_ERR_MSG(info,
8007 "DFS Region is not set. Unexpected Radar indication");
8008 return -EINVAL;
8009 }
8010
8011 err = nl80211_parse_chandef(rdev, info, &chandef);
8012 if (err) {
8013 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8014 return err;
8015 }
8016
8017 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8018 if (err < 0) {
8019 GENL_SET_ERR_MSG(info, "chandef is invalid");
8020 return err;
8021 }
8022
8023 if (err == 0) {
8024 GENL_SET_ERR_MSG(info,
8025 "Unexpected Radar indication for chandef/iftype");
8026 return -EINVAL;
8027 }
8028
8029 /* Do not process this notification if radar is already detected
8030 * by kernel on this channel, and return success.
8031 */
8032 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8033 return 0;
8034
8035 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8036
8037 cfg80211_sched_dfs_chan_update(rdev);
8038
8039 memcpy(&rdev->radar_chandef, &chandef, sizeof(chandef));
8040
8041 /* Propagate this notification to other radios as well */
8042 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8043
8044 return 0;
8045}
8046
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008047static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8048{
8049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8050 struct net_device *dev = info->user_ptr[1];
8051 struct wireless_dev *wdev = dev->ieee80211_ptr;
8052 struct cfg80211_csa_settings params;
8053 /* csa_attrs is defined static to avoid waste of stack size - this
8054 * function is called under RTNL lock, so this should not be a problem.
8055 */
8056 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008057 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008058 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008059 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008060 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008061 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008062
8063 if (!rdev->ops->channel_switch ||
8064 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8065 return -EOPNOTSUPP;
8066
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008067 switch (dev->ieee80211_ptr->iftype) {
8068 case NL80211_IFTYPE_AP:
8069 case NL80211_IFTYPE_P2P_GO:
8070 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008071 /* For all modes except AP the handle_dfs flag needs to be
8072 * supplied to tell the kernel that userspace will handle radar
8073 * events when they happen. Otherwise a switch to a channel
8074 * requiring DFS will be rejected.
8075 */
8076 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008077
8078 /* useless if AP is not running */
8079 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008080 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008081 break;
8082 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008083 if (!wdev->ssid_len)
8084 return -ENOTCONN;
8085 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008086 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008087 if (!wdev->mesh_id_len)
8088 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008089 break;
8090 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008091 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008092 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008093
8094 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008095 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008096
8097 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8098 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8099 return -EINVAL;
8100
8101 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008102 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008103 return -EINVAL;
8104
Luciano Coelho252e07c2014-10-08 09:48:34 +03008105 /* Even though the attribute is u32, the specification says
8106 * u8, so let's make sure we don't overflow.
8107 */
8108 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8109 if (cs_count > 255)
8110 return -EINVAL;
8111
8112 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008113
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008114 if (!need_new_beacon)
8115 goto skip_beacons;
8116
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008117 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008118 if (err)
8119 return err;
8120
8121 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
8122 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02008123 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008124 if (err)
8125 return err;
8126
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008127 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008128 if (err)
8129 return err;
8130
8131 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8132 return -EINVAL;
8133
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008134 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8135 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008136 return -EINVAL;
8137
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008138 params.n_counter_offsets_beacon = len / sizeof(u16);
8139 if (rdev->wiphy.max_num_csa_counters &&
8140 (params.n_counter_offsets_beacon >
8141 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008142 return -EINVAL;
8143
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008144 params.counter_offsets_beacon =
8145 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8146
8147 /* sanity checks - counters should fit and be the same */
8148 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8149 u16 offset = params.counter_offsets_beacon[i];
8150
8151 if (offset >= params.beacon_csa.tail_len)
8152 return -EINVAL;
8153
8154 if (params.beacon_csa.tail[offset] != params.count)
8155 return -EINVAL;
8156 }
8157
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008158 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008159 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8160 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008161 return -EINVAL;
8162
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008163 params.n_counter_offsets_presp = len / sizeof(u16);
8164 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008165 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008166 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008167 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008168
8169 params.counter_offsets_presp =
8170 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8171
8172 /* sanity checks - counters should fit and be the same */
8173 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8174 u16 offset = params.counter_offsets_presp[i];
8175
8176 if (offset >= params.beacon_csa.probe_resp_len)
8177 return -EINVAL;
8178
8179 if (params.beacon_csa.probe_resp[offset] !=
8180 params.count)
8181 return -EINVAL;
8182 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008183 }
8184
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008185skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008186 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8187 if (err)
8188 return err;
8189
Arik Nemtsov923b3522015-07-08 15:41:44 +03008190 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8191 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008192 return -EINVAL;
8193
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008194 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8195 &params.chandef,
8196 wdev->iftype);
8197 if (err < 0)
8198 return err;
8199
Benjamin Berg8d9de162017-05-16 11:23:12 +02008200 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008201 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008202 if (need_handle_dfs_flag &&
8203 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8204 return -EINVAL;
8205 }
8206 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008207
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008208 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8209 params.block_tx = true;
8210
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008211 wdev_lock(wdev);
8212 err = rdev_channel_switch(rdev, dev, &params);
8213 wdev_unlock(wdev);
8214
8215 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008216}
8217
Johannes Berg9720bb32011-06-21 09:45:33 +02008218static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8219 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008220 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008221 struct wireless_dev *wdev,
8222 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008223{
Johannes Berg48ab9052009-07-10 18:42:31 +02008224 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008225 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008226 void *hdr;
8227 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008228
8229 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008230
Eric W. Biederman15e47302012-09-07 20:12:54 +00008231 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008232 NL80211_CMD_NEW_SCAN_RESULTS);
8233 if (!hdr)
8234 return -1;
8235
Michal Kubecek0a833c22017-11-15 13:09:32 +01008236 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008237
Johannes Berg97990a02013-04-19 01:02:55 +02008238 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8239 goto nla_put_failure;
8240 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8242 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008243 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8244 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008245 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008246
8247 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
8248 if (!bss)
8249 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008250 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008251 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008252 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008253
8254 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008255 /* indicate whether we have probe response data or not */
8256 if (rcu_access_pointer(res->proberesp_ies) &&
8257 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8258 goto fail_unlock_rcu;
8259
8260 /* this pointer prefers to be pointed to probe response data
8261 * but is always valid
8262 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008263 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008264 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008265 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8266 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008267 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008268 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8269 ies->len, ies->data))
8270 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008271 }
Johannes Berg0e227082014-08-12 20:34:30 +02008272
8273 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008274 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008275 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008276 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8277 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008278 goto fail_unlock_rcu;
8279 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8280 ies->len, ies->data))
8281 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008282 }
8283 rcu_read_unlock();
8284
David S. Miller9360ffd2012-03-29 04:41:26 -04008285 if (res->beacon_interval &&
8286 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8287 goto nla_put_failure;
8288 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8289 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008290 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008291 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8292 jiffies_to_msecs(jiffies - intbss->ts)))
8293 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008294
Avraham Stern1d762502016-07-05 17:10:13 +03008295 if (intbss->parent_tsf &&
8296 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8297 intbss->parent_tsf, NL80211_BSS_PAD) ||
8298 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8299 intbss->parent_bssid)))
8300 goto nla_put_failure;
8301
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008302 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008303 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8304 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008305 goto nla_put_failure;
8306
Sunil Dutt983dafa2017-12-13 19:51:36 +02008307 if (!nl80211_put_signal(msg, intbss->pub.chains,
8308 intbss->pub.chain_signal,
8309 NL80211_BSS_CHAIN_SIGNAL))
8310 goto nla_put_failure;
8311
Johannes Berg77965c972009-02-18 18:45:06 +01008312 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008313 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008314 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8315 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008316 break;
8317 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008318 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8319 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008320 break;
8321 default:
8322 break;
8323 }
8324
Johannes Berg48ab9052009-07-10 18:42:31 +02008325 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008326 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008327 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008328 if (intbss == wdev->current_bss &&
8329 nla_put_u32(msg, NL80211_BSS_STATUS,
8330 NL80211_BSS_STATUS_ASSOCIATED))
8331 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008332 break;
8333 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008334 if (intbss == wdev->current_bss &&
8335 nla_put_u32(msg, NL80211_BSS_STATUS,
8336 NL80211_BSS_STATUS_IBSS_JOINED))
8337 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008338 break;
8339 default:
8340 break;
8341 }
8342
Johannes Berg2a519312009-02-10 21:25:55 +01008343 nla_nest_end(msg, bss);
8344
Johannes Berg053c0952015-01-16 22:09:00 +01008345 genlmsg_end(msg, hdr);
8346 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008347
Johannes Berg8cef2c92013-02-05 16:54:31 +01008348 fail_unlock_rcu:
8349 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008350 nla_put_failure:
8351 genlmsg_cancel(msg, hdr);
8352 return -EMSGSIZE;
8353}
8354
Johannes Berg97990a02013-04-19 01:02:55 +02008355static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008356{
Johannes Berg48ab9052009-07-10 18:42:31 +02008357 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008358 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008359 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008360 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008361 int err;
8362
Johannes Bergea90e0d2017-03-15 14:26:04 +01008363 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008364 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008365 if (err) {
8366 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008367 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008368 }
Johannes Berg2a519312009-02-10 21:25:55 +01008369
Johannes Berg48ab9052009-07-10 18:42:31 +02008370 wdev_lock(wdev);
8371 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008372
8373 /*
8374 * dump_scan will be called multiple times to break up the scan results
8375 * into multiple messages. It is unlikely that any more bss-es will be
8376 * expired after the first call, so only call only call this on the
8377 * first dump_scan invocation.
8378 */
8379 if (start == 0)
8380 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008381
Johannes Berg9720bb32011-06-21 09:45:33 +02008382 cb->seq = rdev->bss_generation;
8383
Johannes Berg48ab9052009-07-10 18:42:31 +02008384 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008385 if (++idx <= start)
8386 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008387 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008388 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008389 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008390 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008391 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008392 }
8393 }
8394
Johannes Berg48ab9052009-07-10 18:42:31 +02008395 spin_unlock_bh(&rdev->bss_lock);
8396 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008397
Johannes Berg97990a02013-04-19 01:02:55 +02008398 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008399 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008400
Johannes Berg67748892010-10-04 21:14:06 +02008401 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008402}
8403
Eric W. Biederman15e47302012-09-07 20:12:54 +00008404static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008405 int flags, struct net_device *dev,
8406 bool allow_radio_stats,
8407 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008408{
8409 void *hdr;
8410 struct nlattr *infoattr;
8411
Johannes Berg11f78ac2014-11-14 16:43:50 +01008412 /* skip radio stats if userspace didn't request them */
8413 if (!survey->channel && !allow_radio_stats)
8414 return 0;
8415
Eric W. Biederman15e47302012-09-07 20:12:54 +00008416 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008417 NL80211_CMD_NEW_SURVEY_RESULTS);
8418 if (!hdr)
8419 return -ENOMEM;
8420
David S. Miller9360ffd2012-03-29 04:41:26 -04008421 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8422 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008423
8424 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
8425 if (!infoattr)
8426 goto nla_put_failure;
8427
Johannes Berg11f78ac2014-11-14 16:43:50 +01008428 if (survey->channel &&
8429 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008430 survey->channel->center_freq))
8431 goto nla_put_failure;
8432
8433 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8434 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8435 goto nla_put_failure;
8436 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8437 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8438 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008439 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008440 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8441 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008442 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008443 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008444 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8445 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008446 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008447 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008448 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8449 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008450 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008451 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008452 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8453 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008454 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008455 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008456 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8457 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008458 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008459 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008460 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8461 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008462 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008463
8464 nla_nest_end(msg, infoattr);
8465
Johannes Berg053c0952015-01-16 22:09:00 +01008466 genlmsg_end(msg, hdr);
8467 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008468
8469 nla_put_failure:
8470 genlmsg_cancel(msg, hdr);
8471 return -EMSGSIZE;
8472}
8473
Johannes Berg11f78ac2014-11-14 16:43:50 +01008474static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008475{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008476 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008477 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008478 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008479 struct wireless_dev *wdev;
8480 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008481 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008482 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008483
Johannes Bergea90e0d2017-03-15 14:26:04 +01008484 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008485 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008486 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008487 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008488
Johannes Berg11f78ac2014-11-14 16:43:50 +01008489 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008490 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008491
Johannes Berg97990a02013-04-19 01:02:55 +02008492 if (!wdev->netdev) {
8493 res = -EINVAL;
8494 goto out_err;
8495 }
8496
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008497 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008498 res = -EOPNOTSUPP;
8499 goto out_err;
8500 }
8501
8502 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008503 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008504 if (res == -ENOENT)
8505 break;
8506 if (res)
8507 goto out_err;
8508
Johannes Berg11f78ac2014-11-14 16:43:50 +01008509 /* don't send disabled channels, but do send non-channel data */
8510 if (survey.channel &&
8511 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008512 survey_idx++;
8513 continue;
8514 }
8515
Holger Schurig61fa7132009-11-11 12:25:40 +01008516 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008517 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008518 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008519 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008520 goto out;
8521 survey_idx++;
8522 }
8523
8524 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008525 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008526 res = skb->len;
8527 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008528 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008529 return res;
8530}
8531
Samuel Ortizb23aa672009-07-01 21:26:54 +02008532static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8533{
8534 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8535 NL80211_WPA_VERSION_2));
8536}
8537
Jouni Malinen636a5d32009-03-19 13:39:22 +02008538static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8539{
Johannes Berg4c476992010-10-04 21:36:35 +02008540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8541 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008542 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008543 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8544 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008545 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008546 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008547 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008548
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008549 if (!info->attrs[NL80211_ATTR_MAC])
8550 return -EINVAL;
8551
Jouni Malinen17780922009-03-27 20:52:47 +02008552 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8553 return -EINVAL;
8554
Johannes Berg19957bb2009-07-02 17:20:43 +02008555 if (!info->attrs[NL80211_ATTR_SSID])
8556 return -EINVAL;
8557
8558 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8559 return -EINVAL;
8560
Johannes Bergfffd0932009-07-08 14:22:54 +02008561 err = nl80211_parse_key(info, &key);
8562 if (err)
8563 return err;
8564
8565 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008566 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8567 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008568 if (!key.p.key || !key.p.key_len)
8569 return -EINVAL;
8570 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8571 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8572 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8573 key.p.key_len != WLAN_KEY_LEN_WEP104))
8574 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008575 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008576 return -EINVAL;
8577 } else {
8578 key.p.key_len = 0;
8579 key.p.key = NULL;
8580 }
8581
Johannes Bergafea0b72010-08-10 09:46:42 +02008582 if (key.idx >= 0) {
8583 int i;
8584 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008585
Johannes Bergafea0b72010-08-10 09:46:42 +02008586 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8587 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8588 ok = true;
8589 break;
8590 }
8591 }
Johannes Berg4c476992010-10-04 21:36:35 +02008592 if (!ok)
8593 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008594 }
8595
Johannes Berg4c476992010-10-04 21:36:35 +02008596 if (!rdev->ops->auth)
8597 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008598
Johannes Berg074ac8d2010-09-16 14:58:22 +02008599 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008600 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8601 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008602
Johannes Berg19957bb2009-07-02 17:20:43 +02008603 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008604 chan = nl80211_get_valid_chan(&rdev->wiphy,
8605 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8606 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008607 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008608
Johannes Berg19957bb2009-07-02 17:20:43 +02008609 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8610 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8611
8612 if (info->attrs[NL80211_ATTR_IE]) {
8613 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8614 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8615 }
8616
8617 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008618 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008619 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008620
Jouni Malinen63181062016-10-27 00:42:02 +03008621 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8622 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8623 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8624 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008625 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008626 return -EINVAL;
8627
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008628 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008629 if (auth_type != NL80211_AUTHTYPE_SAE &&
8630 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8631 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8632 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008633 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008634 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8635 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008636 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008637 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008638 return -EINVAL;
8639 }
8640
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008641 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8642
Johannes Berg95de8172012-01-20 13:55:25 +01008643 /*
8644 * Since we no longer track auth state, ignore
8645 * requests to only change local state.
8646 */
8647 if (local_state_change)
8648 return 0;
8649
Johannes Berg91bf9b22013-05-15 17:44:01 +02008650 wdev_lock(dev->ieee80211_ptr);
8651 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8652 ssid, ssid_len, ie, ie_len,
8653 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008654 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008655 wdev_unlock(dev->ieee80211_ptr);
8656 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008657}
8658
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008659static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8660 struct genl_info *info)
8661{
8662 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8663 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8664 return -EINVAL;
8665 }
8666
8667 if (!rdev->ops->tx_control_port ||
8668 !wiphy_ext_feature_isset(&rdev->wiphy,
8669 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8670 return -EOPNOTSUPP;
8671
8672 return 0;
8673}
8674
Johannes Bergc0692b82010-08-27 14:26:53 +03008675static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8676 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008677 struct cfg80211_crypto_settings *settings,
8678 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008679{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008680 memset(settings, 0, sizeof(*settings));
8681
Samuel Ortizb23aa672009-07-01 21:26:54 +02008682 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8683
Johannes Bergc0692b82010-08-27 14:26:53 +03008684 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8685 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008686
Johannes Bergc0692b82010-08-27 14:26:53 +03008687 proto = nla_get_u16(
8688 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8689 settings->control_port_ethertype = cpu_to_be16(proto);
8690 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8691 proto != ETH_P_PAE)
8692 return -EINVAL;
8693 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8694 settings->control_port_no_encrypt = true;
8695 } else
8696 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8697
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008698 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8699 int r = validate_pae_over_nl80211(rdev, info);
8700
8701 if (r < 0)
8702 return r;
8703
8704 settings->control_port_over_nl80211 = true;
8705 }
8706
Samuel Ortizb23aa672009-07-01 21:26:54 +02008707 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8708 void *data;
8709 int len, i;
8710
8711 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8712 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8713 settings->n_ciphers_pairwise = len / sizeof(u32);
8714
8715 if (len % sizeof(u32))
8716 return -EINVAL;
8717
Johannes Berg3dc27d22009-07-02 21:36:37 +02008718 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008719 return -EINVAL;
8720
8721 memcpy(settings->ciphers_pairwise, data, len);
8722
8723 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008724 if (!cfg80211_supported_cipher_suite(
8725 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008726 settings->ciphers_pairwise[i]))
8727 return -EINVAL;
8728 }
8729
8730 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8731 settings->cipher_group =
8732 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008733 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8734 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008735 return -EINVAL;
8736 }
8737
8738 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8739 settings->wpa_versions =
8740 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8741 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8742 return -EINVAL;
8743 }
8744
8745 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8746 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008747 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008748
8749 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8750 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8751 settings->n_akm_suites = len / sizeof(u32);
8752
8753 if (len % sizeof(u32))
8754 return -EINVAL;
8755
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008756 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8757 return -EINVAL;
8758
Samuel Ortizb23aa672009-07-01 21:26:54 +02008759 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008760 }
8761
Eliad Peller91b5ab62017-06-09 13:08:42 +01008762 if (info->attrs[NL80211_ATTR_PMK]) {
8763 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8764 return -EINVAL;
8765 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8766 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8767 return -EINVAL;
8768 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8769 }
8770
Samuel Ortizb23aa672009-07-01 21:26:54 +02008771 return 0;
8772}
8773
Jouni Malinen636a5d32009-03-19 13:39:22 +02008774static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8775{
Johannes Berg4c476992010-10-04 21:36:35 +02008776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8777 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008778 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008779 struct cfg80211_assoc_request req = {};
8780 const u8 *bssid, *ssid;
8781 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008782
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008783 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8784 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8785 return -EPERM;
8786
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008787 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008788 !info->attrs[NL80211_ATTR_SSID] ||
8789 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008790 return -EINVAL;
8791
Johannes Berg4c476992010-10-04 21:36:35 +02008792 if (!rdev->ops->assoc)
8793 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008794
Johannes Berg074ac8d2010-09-16 14:58:22 +02008795 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008796 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8797 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008798
Johannes Berg19957bb2009-07-02 17:20:43 +02008799 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008800
Jouni Malinen664834d2014-01-15 00:01:44 +02008801 chan = nl80211_get_valid_chan(&rdev->wiphy,
8802 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8803 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008804 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008805
Johannes Berg19957bb2009-07-02 17:20:43 +02008806 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8807 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008808
8809 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008810 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8811 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008812 }
8813
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008814 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008815 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008816 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008817 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008818 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008819 else if (mfp != NL80211_MFP_NO)
8820 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008821 }
8822
Johannes Berg3e5d7642009-07-07 14:37:26 +02008823 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008824 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008825
Ben Greear7e7c8922011-11-18 11:31:59 -08008826 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008827 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008828
8829 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008830 memcpy(&req.ht_capa_mask,
8831 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8832 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008833
8834 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008835 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008836 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008837 memcpy(&req.ht_capa,
8838 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8839 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008840 }
8841
Johannes Bergee2aca32013-02-21 17:36:01 +01008842 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008843 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008844
8845 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008846 memcpy(&req.vht_capa_mask,
8847 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8848 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008849
8850 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008851 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008852 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008853 memcpy(&req.vht_capa,
8854 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8855 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008856 }
8857
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008858 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008859 if (!((rdev->wiphy.features &
8860 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8861 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8862 !wiphy_ext_feature_isset(&rdev->wiphy,
8863 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008864 return -EINVAL;
8865 req.flags |= ASSOC_REQ_USE_RRM;
8866 }
8867
Jouni Malinen348bd452016-10-27 00:42:03 +03008868 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8869 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8870 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8871 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8872 return -EINVAL;
8873 req.fils_nonces =
8874 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8875 }
8876
Johannes Bergf62fab72013-02-21 20:09:09 +01008877 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008878 if (!err) {
8879 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008880
Johannes Bergf62fab72013-02-21 20:09:09 +01008881 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8882 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008883
8884 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8885 dev->ieee80211_ptr->conn_owner_nlportid =
8886 info->snd_portid;
8887 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8888 bssid, ETH_ALEN);
8889 }
8890
Johannes Berg91bf9b22013-05-15 17:44:01 +02008891 wdev_unlock(dev->ieee80211_ptr);
8892 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008893
Jouni Malinen636a5d32009-03-19 13:39:22 +02008894 return err;
8895}
8896
8897static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8898{
Johannes Berg4c476992010-10-04 21:36:35 +02008899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8900 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008901 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008902 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008903 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008904 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008905
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008906 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8907 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8908 return -EPERM;
8909
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008910 if (!info->attrs[NL80211_ATTR_MAC])
8911 return -EINVAL;
8912
8913 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8914 return -EINVAL;
8915
Johannes Berg4c476992010-10-04 21:36:35 +02008916 if (!rdev->ops->deauth)
8917 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008918
Johannes Berg074ac8d2010-09-16 14:58:22 +02008919 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008920 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8921 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008922
Johannes Berg19957bb2009-07-02 17:20:43 +02008923 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008924
Johannes Berg19957bb2009-07-02 17:20:43 +02008925 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8926 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008927 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008928 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008929 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008930
8931 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008932 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8933 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008934 }
8935
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008936 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8937
Johannes Berg91bf9b22013-05-15 17:44:01 +02008938 wdev_lock(dev->ieee80211_ptr);
8939 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8940 local_state_change);
8941 wdev_unlock(dev->ieee80211_ptr);
8942 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008943}
8944
8945static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8946{
Johannes Berg4c476992010-10-04 21:36:35 +02008947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8948 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008949 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008950 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008951 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008952 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008953
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008954 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8955 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8956 return -EPERM;
8957
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008958 if (!info->attrs[NL80211_ATTR_MAC])
8959 return -EINVAL;
8960
8961 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8962 return -EINVAL;
8963
Johannes Berg4c476992010-10-04 21:36:35 +02008964 if (!rdev->ops->disassoc)
8965 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008966
Johannes Berg074ac8d2010-09-16 14:58:22 +02008967 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8969 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008970
Johannes Berg19957bb2009-07-02 17:20:43 +02008971 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008972
Johannes Berg19957bb2009-07-02 17:20:43 +02008973 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8974 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008975 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008976 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008977 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008978
8979 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008980 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8981 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008982 }
8983
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008984 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8985
Johannes Berg91bf9b22013-05-15 17:44:01 +02008986 wdev_lock(dev->ieee80211_ptr);
8987 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8988 local_state_change);
8989 wdev_unlock(dev->ieee80211_ptr);
8990 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008991}
8992
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008993static bool
8994nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008995 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008996 int rateval)
8997{
8998 struct wiphy *wiphy = &rdev->wiphy;
8999 bool found = false;
9000 int band, i;
9001
Johannes Berg57fbcce2016-04-12 15:56:15 +02009002 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009003 struct ieee80211_supported_band *sband;
9004
9005 sband = wiphy->bands[band];
9006 if (!sband)
9007 continue;
9008
9009 for (i = 0; i < sband->n_bitrates; i++) {
9010 if (sband->bitrates[i].bitrate == rateval) {
9011 mcast_rate[band] = i + 1;
9012 found = true;
9013 break;
9014 }
9015 }
9016 }
9017
9018 return found;
9019}
9020
Johannes Berg04a773a2009-04-19 21:24:32 +02009021static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9022{
Johannes Berg4c476992010-10-04 21:36:35 +02009023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9024 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009025 struct cfg80211_ibss_params ibss;
9026 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009027 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009028 int err;
9029
Johannes Berg8e30bc52009-04-22 17:45:38 +02009030 memset(&ibss, 0, sizeof(ibss));
9031
Johannes Berg683b6d32012-11-08 21:25:48 +01009032 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009033 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9034 return -EINVAL;
9035
Johannes Berg8e30bc52009-04-22 17:45:38 +02009036 ibss.beacon_interval = 100;
9037
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309038 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009039 ibss.beacon_interval =
9040 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309041
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309042 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9043 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309044 if (err)
9045 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009046
Johannes Berg4c476992010-10-04 21:36:35 +02009047 if (!rdev->ops->join_ibss)
9048 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009049
Johannes Berg4c476992010-10-04 21:36:35 +02009050 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9051 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009052
Johannes Berg79c97e92009-07-07 03:56:12 +02009053 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009054
Johannes Berg39193492011-09-16 13:45:25 +02009055 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009056 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009057
9058 if (!is_valid_ether_addr(ibss.bssid))
9059 return -EINVAL;
9060 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009061 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9062 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9063
9064 if (info->attrs[NL80211_ATTR_IE]) {
9065 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9066 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9067 }
9068
Johannes Berg683b6d32012-11-08 21:25:48 +01009069 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9070 if (err)
9071 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009072
Ilan Peer174e0cd2014-02-23 09:13:01 +02009073 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9074 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009075 return -EINVAL;
9076
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009077 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009078 case NL80211_CHAN_WIDTH_5:
9079 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009080 case NL80211_CHAN_WIDTH_20_NOHT:
9081 break;
9082 case NL80211_CHAN_WIDTH_20:
9083 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009084 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9085 return -EINVAL;
9086 break;
9087 case NL80211_CHAN_WIDTH_80:
9088 case NL80211_CHAN_WIDTH_80P80:
9089 case NL80211_CHAN_WIDTH_160:
9090 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9091 return -EINVAL;
9092 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9093 NL80211_EXT_FEATURE_VHT_IBSS))
9094 return -EINVAL;
9095 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009096 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009097 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009098 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009099
Johannes Berg04a773a2009-04-19 21:24:32 +02009100 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009101 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009102
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009103 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9104 u8 *rates =
9105 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9106 int n_rates =
9107 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9108 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009109 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009110
Johannes Berg34850ab2011-07-18 18:08:35 +02009111 err = ieee80211_get_ratemask(sband, rates, n_rates,
9112 &ibss.basic_rates);
9113 if (err)
9114 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009115 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009116
Simon Wunderlich803768f2013-06-28 10:39:58 +02009117 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9118 memcpy(&ibss.ht_capa_mask,
9119 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9120 sizeof(ibss.ht_capa_mask));
9121
9122 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9123 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9124 return -EINVAL;
9125 memcpy(&ibss.ht_capa,
9126 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9127 sizeof(ibss.ht_capa));
9128 }
9129
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009130 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9131 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9132 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9133 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009134
Johannes Berg4c476992010-10-04 21:36:35 +02009135 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309136 bool no_ht = false;
9137
Johannes Berg768075e2017-11-13 15:35:06 +01009138 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009139 if (IS_ERR(connkeys))
9140 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309141
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009142 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9143 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009144 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309145 return -EINVAL;
9146 }
Johannes Berg4c476992010-10-04 21:36:35 +02009147 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009148
Antonio Quartulli267335d2012-01-31 20:25:47 +01009149 ibss.control_port =
9150 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9151
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009152 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9153 int r = validate_pae_over_nl80211(rdev, info);
9154
Johannes Bergd350a0f2018-12-15 11:03:22 +02009155 if (r < 0) {
9156 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009157 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009158 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009159
9160 ibss.control_port_over_nl80211 = true;
9161 }
9162
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009163 ibss.userspace_handles_dfs =
9164 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9165
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009166 wdev_lock(dev->ieee80211_ptr);
9167 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009168 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009169 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009170 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9171 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9172 wdev_unlock(dev->ieee80211_ptr);
9173
Johannes Berg04a773a2009-04-19 21:24:32 +02009174 return err;
9175}
9176
9177static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9178{
Johannes Berg4c476992010-10-04 21:36:35 +02009179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9180 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009181
Johannes Berg4c476992010-10-04 21:36:35 +02009182 if (!rdev->ops->leave_ibss)
9183 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009184
Johannes Berg4c476992010-10-04 21:36:35 +02009185 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9186 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009187
Johannes Berg4c476992010-10-04 21:36:35 +02009188 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009189}
9190
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009191static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9192{
9193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9194 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009195 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009196 u32 nla_rate;
9197 int err;
9198
9199 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009200 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009202 return -EOPNOTSUPP;
9203
9204 if (!rdev->ops->set_mcast_rate)
9205 return -EOPNOTSUPP;
9206
9207 memset(mcast_rate, 0, sizeof(mcast_rate));
9208
9209 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9210 return -EINVAL;
9211
9212 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9213 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9214 return -EINVAL;
9215
Ilan Peera1056b1b2015-10-22 22:27:46 +03009216 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009217
9218 return err;
9219}
9220
Johannes Bergad7e7182013-11-13 13:37:47 +01009221static struct sk_buff *
9222__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009223 struct wireless_dev *wdev, int approxlen,
9224 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009225 enum nl80211_attrs attr,
9226 const struct nl80211_vendor_cmd_info *info,
9227 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009228{
9229 struct sk_buff *skb;
9230 void *hdr;
9231 struct nlattr *data;
9232
9233 skb = nlmsg_new(approxlen + 100, gfp);
9234 if (!skb)
9235 return NULL;
9236
9237 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9238 if (!hdr) {
9239 kfree_skb(skb);
9240 return NULL;
9241 }
9242
9243 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9244 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009245
9246 if (info) {
9247 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9248 info->vendor_id))
9249 goto nla_put_failure;
9250 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9251 info->subcmd))
9252 goto nla_put_failure;
9253 }
9254
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009255 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009256 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9257 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009258 goto nla_put_failure;
9259 if (wdev->netdev &&
9260 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9261 wdev->netdev->ifindex))
9262 goto nla_put_failure;
9263 }
9264
Johannes Bergad7e7182013-11-13 13:37:47 +01009265 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009266 if (!data)
9267 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009268
9269 ((void **)skb->cb)[0] = rdev;
9270 ((void **)skb->cb)[1] = hdr;
9271 ((void **)skb->cb)[2] = data;
9272
9273 return skb;
9274
9275 nla_put_failure:
9276 kfree_skb(skb);
9277 return NULL;
9278}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009279
Johannes Berge03ad6e2014-01-01 17:22:30 +01009280struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009281 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009282 enum nl80211_commands cmd,
9283 enum nl80211_attrs attr,
9284 int vendor_event_idx,
9285 int approxlen, gfp_t gfp)
9286{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009287 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009288 const struct nl80211_vendor_cmd_info *info;
9289
9290 switch (cmd) {
9291 case NL80211_CMD_TESTMODE:
9292 if (WARN_ON(vendor_event_idx != -1))
9293 return NULL;
9294 info = NULL;
9295 break;
9296 case NL80211_CMD_VENDOR:
9297 if (WARN_ON(vendor_event_idx < 0 ||
9298 vendor_event_idx >= wiphy->n_vendor_events))
9299 return NULL;
9300 info = &wiphy->vendor_events[vendor_event_idx];
9301 break;
9302 default:
9303 WARN_ON(1);
9304 return NULL;
9305 }
9306
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009307 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009308 cmd, attr, info, gfp);
9309}
9310EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9311
9312void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9313{
9314 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9315 void *hdr = ((void **)skb->cb)[1];
9316 struct nlattr *data = ((void **)skb->cb)[2];
9317 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9318
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009319 /* clear CB data for netlink core to own from now on */
9320 memset(skb->cb, 0, sizeof(skb->cb));
9321
Johannes Berge03ad6e2014-01-01 17:22:30 +01009322 nla_nest_end(skb, data);
9323 genlmsg_end(skb, hdr);
9324
9325 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9326 mcgrp = NL80211_MCGRP_VENDOR;
9327
9328 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
9329 mcgrp, gfp);
9330}
9331EXPORT_SYMBOL(__cfg80211_send_event_skb);
9332
Johannes Bergaff89a92009-07-01 21:26:51 +02009333#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009334static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9335{
Johannes Berg4c476992010-10-04 21:36:35 +02009336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009337 struct wireless_dev *wdev =
9338 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009339 int err;
9340
David Spinadelfc73f112013-07-31 18:04:15 +03009341 if (!rdev->ops->testmode_cmd)
9342 return -EOPNOTSUPP;
9343
9344 if (IS_ERR(wdev)) {
9345 err = PTR_ERR(wdev);
9346 if (err != -EINVAL)
9347 return err;
9348 wdev = NULL;
9349 } else if (wdev->wiphy != &rdev->wiphy) {
9350 return -EINVAL;
9351 }
9352
Johannes Bergaff89a92009-07-01 21:26:51 +02009353 if (!info->attrs[NL80211_ATTR_TESTDATA])
9354 return -EINVAL;
9355
Johannes Bergad7e7182013-11-13 13:37:47 +01009356 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009357 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009358 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9359 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009360 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009361
Johannes Bergaff89a92009-07-01 21:26:51 +02009362 return err;
9363}
9364
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009365static int nl80211_testmode_dump(struct sk_buff *skb,
9366 struct netlink_callback *cb)
9367{
Johannes Berg00918d32011-12-13 17:22:05 +01009368 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009369 int err;
9370 long phy_idx;
9371 void *data = NULL;
9372 int data_len = 0;
9373
Johannes Berg5fe231e2013-05-08 21:45:15 +02009374 rtnl_lock();
9375
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009376 if (cb->args[0]) {
9377 /*
9378 * 0 is a valid index, but not valid for args[0],
9379 * so we need to offset by 1.
9380 */
9381 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009382
9383 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9384 if (!rdev) {
9385 err = -ENOENT;
9386 goto out_err;
9387 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009388 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009389 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9390
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009391 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02009392 attrbuf, nl80211_fam.maxattr,
9393 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009394 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009395 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009396
Johannes Bergc90c39d2016-10-24 14:40:01 +02009397 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009398 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009399 err = PTR_ERR(rdev);
9400 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009401 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009402 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009403
Johannes Bergc90c39d2016-10-24 14:40:01 +02009404 if (attrbuf[NL80211_ATTR_TESTDATA])
9405 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009406 }
9407
9408 if (cb->args[1]) {
9409 data = nla_data((void *)cb->args[1]);
9410 data_len = nla_len((void *)cb->args[1]);
9411 }
9412
Johannes Berg00918d32011-12-13 17:22:05 +01009413 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009414 err = -EOPNOTSUPP;
9415 goto out_err;
9416 }
9417
9418 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009419 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009420 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9421 NL80211_CMD_TESTMODE);
9422 struct nlattr *tmdata;
9423
Dan Carpentercb35fba2013-08-14 14:50:01 +03009424 if (!hdr)
9425 break;
9426
David S. Miller9360ffd2012-03-29 04:41:26 -04009427 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009428 genlmsg_cancel(skb, hdr);
9429 break;
9430 }
9431
9432 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
9433 if (!tmdata) {
9434 genlmsg_cancel(skb, hdr);
9435 break;
9436 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009437 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009438 nla_nest_end(skb, tmdata);
9439
9440 if (err == -ENOBUFS || err == -ENOENT) {
9441 genlmsg_cancel(skb, hdr);
9442 break;
9443 } else if (err) {
9444 genlmsg_cancel(skb, hdr);
9445 goto out_err;
9446 }
9447
9448 genlmsg_end(skb, hdr);
9449 }
9450
9451 err = skb->len;
9452 /* see above */
9453 cb->args[0] = phy_idx + 1;
9454 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009455 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009456 return err;
9457}
Johannes Bergaff89a92009-07-01 21:26:51 +02009458#endif
9459
Samuel Ortizb23aa672009-07-01 21:26:54 +02009460static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9461{
Johannes Berg4c476992010-10-04 21:36:35 +02009462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9463 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009464 struct cfg80211_connect_params connect;
9465 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009466 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009467 int err;
9468
9469 memset(&connect, 0, sizeof(connect));
9470
Samuel Ortizb23aa672009-07-01 21:26:54 +02009471 if (!info->attrs[NL80211_ATTR_SSID] ||
9472 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9473 return -EINVAL;
9474
9475 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9476 connect.auth_type =
9477 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009478 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9479 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009480 return -EINVAL;
9481 } else
9482 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9483
9484 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9485
Avraham Stern3a00df52017-06-09 13:08:43 +01009486 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9487 !wiphy_ext_feature_isset(&rdev->wiphy,
9488 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9489 return -EINVAL;
9490 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9491
Johannes Bergc0692b82010-08-27 14:26:53 +03009492 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009493 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009494 if (err)
9495 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009496
Johannes Berg074ac8d2010-09-16 14:58:22 +02009497 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009498 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9499 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009500
Johannes Berg79c97e92009-07-07 03:56:12 +02009501 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009502
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309503 connect.bg_scan_period = -1;
9504 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9505 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9506 connect.bg_scan_period =
9507 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9508 }
9509
Samuel Ortizb23aa672009-07-01 21:26:54 +02009510 if (info->attrs[NL80211_ATTR_MAC])
9511 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009512 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9513 connect.bssid_hint =
9514 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009515 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9516 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9517
9518 if (info->attrs[NL80211_ATTR_IE]) {
9519 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9520 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9521 }
9522
Jouni Malinencee00a92013-01-15 17:15:57 +02009523 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9524 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009525 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9526 !wiphy_ext_feature_isset(&rdev->wiphy,
9527 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9528 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +02009529 } else {
9530 connect.mfp = NL80211_MFP_NO;
9531 }
9532
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009533 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9534 connect.prev_bssid =
9535 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9536
Samuel Ortizb23aa672009-07-01 21:26:54 +02009537 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009538 connect.channel = nl80211_get_valid_chan(
9539 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9540 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009541 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009542 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009543 connect.channel_hint = nl80211_get_valid_chan(
9544 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9545 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009546 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009547 }
9548
Johannes Bergfffd0932009-07-08 14:22:54 +02009549 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009550 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009551 if (IS_ERR(connkeys))
9552 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009553 }
9554
Ben Greear7e7c8922011-11-18 11:31:59 -08009555 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9556 connect.flags |= ASSOC_REQ_DISABLE_HT;
9557
9558 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9559 memcpy(&connect.ht_capa_mask,
9560 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9561 sizeof(connect.ht_capa_mask));
9562
9563 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009564 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009565 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009566 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009567 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009568 memcpy(&connect.ht_capa,
9569 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9570 sizeof(connect.ht_capa));
9571 }
9572
Johannes Bergee2aca32013-02-21 17:36:01 +01009573 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9574 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9575
9576 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9577 memcpy(&connect.vht_capa_mask,
9578 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9579 sizeof(connect.vht_capa_mask));
9580
9581 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9582 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009583 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009584 return -EINVAL;
9585 }
9586 memcpy(&connect.vht_capa,
9587 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9588 sizeof(connect.vht_capa));
9589 }
9590
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009591 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009592 if (!((rdev->wiphy.features &
9593 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9594 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9595 !wiphy_ext_feature_isset(&rdev->wiphy,
9596 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009597 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009598 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009599 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009600 connect.flags |= ASSOC_REQ_USE_RRM;
9601 }
9602
Lior David34d50512016-01-28 10:58:25 +02009603 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009604 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009605 kzfree(connkeys);
9606 return -EOPNOTSUPP;
9607 }
9608
Arend van Spriel38de03d2016-03-02 20:37:18 +01009609 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9610 /* bss selection makes no sense if bssid is set */
9611 if (connect.bssid) {
9612 kzfree(connkeys);
9613 return -EINVAL;
9614 }
9615
9616 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9617 wiphy, &connect.bss_select);
9618 if (err) {
9619 kzfree(connkeys);
9620 return err;
9621 }
9622 }
9623
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009624 if (wiphy_ext_feature_isset(&rdev->wiphy,
9625 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9626 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9627 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9628 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9629 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9630 connect.fils_erp_username =
9631 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9632 connect.fils_erp_username_len =
9633 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9634 connect.fils_erp_realm =
9635 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9636 connect.fils_erp_realm_len =
9637 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9638 connect.fils_erp_next_seq_num =
9639 nla_get_u16(
9640 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9641 connect.fils_erp_rrk =
9642 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9643 connect.fils_erp_rrk_len =
9644 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9645 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9646 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9647 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9648 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9649 kzfree(connkeys);
9650 return -EINVAL;
9651 }
9652
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009653 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9654 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309655 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009656 GENL_SET_ERR_MSG(info,
9657 "external auth requires connection ownership");
9658 return -EINVAL;
9659 }
9660 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9661 }
9662
Johannes Berg83739b02013-05-15 17:44:01 +02009663 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009664
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009665 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9666 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009667 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009668 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009669
9670 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9671 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9672 if (connect.bssid)
9673 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9674 connect.bssid, ETH_ALEN);
9675 else
9676 memset(dev->ieee80211_ptr->disconnect_bssid,
9677 0, ETH_ALEN);
9678 }
9679
9680 wdev_unlock(dev->ieee80211_ptr);
9681
Samuel Ortizb23aa672009-07-01 21:26:54 +02009682 return err;
9683}
9684
vamsi krishna088e8df2016-10-27 16:51:11 +03009685static int nl80211_update_connect_params(struct sk_buff *skb,
9686 struct genl_info *info)
9687{
9688 struct cfg80211_connect_params connect = {};
9689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9690 struct net_device *dev = info->user_ptr[1];
9691 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009692 bool fils_sk_offload;
9693 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +03009694 u32 changed = 0;
9695 int ret;
9696
9697 if (!rdev->ops->update_connect_params)
9698 return -EOPNOTSUPP;
9699
9700 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +03009701 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9702 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9703 changed |= UPDATE_ASSOC_IES;
9704 }
9705
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009706 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
9707 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
9708
9709 /*
9710 * when driver supports fils-sk offload all attributes must be
9711 * provided. So the else covers "fils-sk-not-all" and
9712 * "no-fils-sk-any".
9713 */
9714 if (fils_sk_offload &&
9715 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9716 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9717 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9718 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9719 connect.fils_erp_username =
9720 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9721 connect.fils_erp_username_len =
9722 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9723 connect.fils_erp_realm =
9724 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9725 connect.fils_erp_realm_len =
9726 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9727 connect.fils_erp_next_seq_num =
9728 nla_get_u16(
9729 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9730 connect.fils_erp_rrk =
9731 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9732 connect.fils_erp_rrk_len =
9733 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9734 changed |= UPDATE_FILS_ERP_INFO;
9735 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9736 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9737 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9738 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9739 return -EINVAL;
9740 }
9741
9742 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9743 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9744 if (!nl80211_valid_auth_type(rdev, auth_type,
9745 NL80211_CMD_CONNECT))
9746 return -EINVAL;
9747
9748 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
9749 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
9750 return -EINVAL;
9751
9752 connect.auth_type = auth_type;
9753 changed |= UPDATE_AUTH_TYPE;
9754 }
9755
vamsi krishna088e8df2016-10-27 16:51:11 +03009756 wdev_lock(dev->ieee80211_ptr);
9757 if (!wdev->current_bss)
9758 ret = -ENOLINK;
9759 else
9760 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9761 wdev_unlock(dev->ieee80211_ptr);
9762
9763 return ret;
9764}
9765
Samuel Ortizb23aa672009-07-01 21:26:54 +02009766static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9767{
Johannes Berg4c476992010-10-04 21:36:35 +02009768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9769 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009770 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009771 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009772
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009773 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9774 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9775 return -EPERM;
9776
Samuel Ortizb23aa672009-07-01 21:26:54 +02009777 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9778 reason = WLAN_REASON_DEAUTH_LEAVING;
9779 else
9780 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9781
9782 if (reason == 0)
9783 return -EINVAL;
9784
Johannes Berg074ac8d2010-09-16 14:58:22 +02009785 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009786 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9787 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009788
Johannes Berg83739b02013-05-15 17:44:01 +02009789 wdev_lock(dev->ieee80211_ptr);
9790 ret = cfg80211_disconnect(rdev, dev, reason, true);
9791 wdev_unlock(dev->ieee80211_ptr);
9792 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009793}
9794
Johannes Berg463d0182009-07-14 00:33:35 +02009795static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9796{
Johannes Berg4c476992010-10-04 21:36:35 +02009797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009798 struct net *net;
9799 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009800
Vadim Kochan4b681c82015-01-12 16:34:05 +02009801 if (info->attrs[NL80211_ATTR_PID]) {
9802 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9803
9804 net = get_net_ns_by_pid(pid);
9805 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9806 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9807
9808 net = get_net_ns_by_fd(fd);
9809 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009810 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009811 }
Johannes Berg463d0182009-07-14 00:33:35 +02009812
Johannes Berg4c476992010-10-04 21:36:35 +02009813 if (IS_ERR(net))
9814 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009815
9816 err = 0;
9817
9818 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009819 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9820 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009821
Johannes Berg463d0182009-07-14 00:33:35 +02009822 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009823 return err;
9824}
9825
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009826static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9827{
Johannes Berg4c476992010-10-04 21:36:35 +02009828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009829 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9830 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009831 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009832 struct cfg80211_pmksa pmksa;
9833
9834 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9835
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009836 if (!info->attrs[NL80211_ATTR_PMKID])
9837 return -EINVAL;
9838
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009839 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009840
9841 if (info->attrs[NL80211_ATTR_MAC]) {
9842 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9843 } else if (info->attrs[NL80211_ATTR_SSID] &&
9844 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9845 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9846 info->attrs[NL80211_ATTR_PMK])) {
9847 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9848 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9849 pmksa.cache_id =
9850 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9851 } else {
9852 return -EINVAL;
9853 }
9854 if (info->attrs[NL80211_ATTR_PMK]) {
9855 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9856 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9857 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009858
Johannes Berg074ac8d2010-09-16 14:58:22 +02009859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009860 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9861 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009862
9863 switch (info->genlhdr->cmd) {
9864 case NL80211_CMD_SET_PMKSA:
9865 rdev_ops = rdev->ops->set_pmksa;
9866 break;
9867 case NL80211_CMD_DEL_PMKSA:
9868 rdev_ops = rdev->ops->del_pmksa;
9869 break;
9870 default:
9871 WARN_ON(1);
9872 break;
9873 }
9874
Johannes Berg4c476992010-10-04 21:36:35 +02009875 if (!rdev_ops)
9876 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009877
Johannes Berg4c476992010-10-04 21:36:35 +02009878 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009879}
9880
9881static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9882{
Johannes Berg4c476992010-10-04 21:36:35 +02009883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9884 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009885
Johannes Berg074ac8d2010-09-16 14:58:22 +02009886 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009887 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9888 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009889
Johannes Berg4c476992010-10-04 21:36:35 +02009890 if (!rdev->ops->flush_pmksa)
9891 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009892
Hila Gonene35e4d22012-06-27 17:19:42 +03009893 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009894}
9895
Arik Nemtsov109086c2011-09-28 14:12:50 +03009896static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9897{
9898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9899 struct net_device *dev = info->user_ptr[1];
9900 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309901 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009902 u16 status_code;
9903 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009904 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009905
9906 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9907 !rdev->ops->tdls_mgmt)
9908 return -EOPNOTSUPP;
9909
9910 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9911 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9912 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9913 !info->attrs[NL80211_ATTR_IE] ||
9914 !info->attrs[NL80211_ATTR_MAC])
9915 return -EINVAL;
9916
9917 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9918 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9919 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9920 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009921 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309922 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9923 peer_capability =
9924 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009925
Hila Gonene35e4d22012-06-27 17:19:42 +03009926 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309927 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009928 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009929 nla_data(info->attrs[NL80211_ATTR_IE]),
9930 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009931}
9932
9933static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9934{
9935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9936 struct net_device *dev = info->user_ptr[1];
9937 enum nl80211_tdls_operation operation;
9938 u8 *peer;
9939
9940 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9941 !rdev->ops->tdls_oper)
9942 return -EOPNOTSUPP;
9943
9944 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9945 !info->attrs[NL80211_ATTR_MAC])
9946 return -EINVAL;
9947
9948 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9949 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9950
Hila Gonene35e4d22012-06-27 17:19:42 +03009951 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009952}
9953
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009954static int nl80211_remain_on_channel(struct sk_buff *skb,
9955 struct genl_info *info)
9956{
Johannes Berg4c476992010-10-04 21:36:35 +02009957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009958 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009959 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309960 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009961 struct sk_buff *msg;
9962 void *hdr;
9963 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009964 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009965 int err;
9966
9967 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9968 !info->attrs[NL80211_ATTR_DURATION])
9969 return -EINVAL;
9970
9971 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9972
Johannes Berg7c4ef712011-11-18 15:33:48 +01009973 if (!rdev->ops->remain_on_channel ||
9974 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009975 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009976
Johannes Bergebf348f2012-06-01 12:50:54 +02009977 /*
9978 * We should be on that channel for at least a minimum amount of
9979 * time (10ms) but no longer than the driver supports.
9980 */
9981 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9982 duration > rdev->wiphy.max_remain_on_channel_duration)
9983 return -EINVAL;
9984
Johannes Berg683b6d32012-11-08 21:25:48 +01009985 err = nl80211_parse_chandef(rdev, info, &chandef);
9986 if (err)
9987 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009988
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309989 wdev_lock(wdev);
9990 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9991 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9992 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9993 &chandef);
9994 if (compat_chandef != &chandef) {
9995 wdev_unlock(wdev);
9996 return -EBUSY;
9997 }
9998 }
9999 wdev_unlock(wdev);
10000
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010001 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010002 if (!msg)
10003 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010004
Eric W. Biederman15e47302012-09-07 20:12:54 +000010005 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010006 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010007 if (!hdr) {
10008 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010009 goto free_msg;
10010 }
10011
Johannes Berg683b6d32012-11-08 21:25:48 +010010012 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10013 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010014
10015 if (err)
10016 goto free_msg;
10017
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010018 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10019 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010020 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010021
10022 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010023
10024 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010025
10026 nla_put_failure:
10027 err = -ENOBUFS;
10028 free_msg:
10029 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010030 return err;
10031}
10032
10033static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10034 struct genl_info *info)
10035{
Johannes Berg4c476992010-10-04 21:36:35 +020010036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010037 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010038 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010039
10040 if (!info->attrs[NL80211_ATTR_COOKIE])
10041 return -EINVAL;
10042
Johannes Berg4c476992010-10-04 21:36:35 +020010043 if (!rdev->ops->cancel_remain_on_channel)
10044 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010045
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010046 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10047
Hila Gonene35e4d22012-06-27 17:19:42 +030010048 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010049}
10050
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010051static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10052 struct genl_info *info)
10053{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010054 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010056 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010057 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010058
Johannes Berg4c476992010-10-04 21:36:35 +020010059 if (!rdev->ops->set_bitrate_mask)
10060 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010061
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010062 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10063 if (err)
10064 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010065
Hila Gonene35e4d22012-06-27 17:19:42 +030010066 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010067}
10068
Johannes Berg2e161f782010-08-12 15:38:38 +020010069static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010070{
Johannes Berg4c476992010-10-04 21:36:35 +020010071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010072 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010073 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010074
10075 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10076 return -EINVAL;
10077
Johannes Berg2e161f782010-08-12 15:38:38 +020010078 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10079 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010080
Johannes Berg71bbc992012-06-15 15:30:18 +020010081 switch (wdev->iftype) {
10082 case NL80211_IFTYPE_STATION:
10083 case NL80211_IFTYPE_ADHOC:
10084 case NL80211_IFTYPE_P2P_CLIENT:
10085 case NL80211_IFTYPE_AP:
10086 case NL80211_IFTYPE_AP_VLAN:
10087 case NL80211_IFTYPE_MESH_POINT:
10088 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010089 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010090 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010091 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010092 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010093 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010094 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010095
10096 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010097 if (!rdev->ops->mgmt_tx)
10098 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010099
Eric W. Biederman15e47302012-09-07 20:12:54 +000010100 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +020010101 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10102 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +020010103}
10104
Johannes Berg2e161f782010-08-12 15:38:38 +020010105static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010106{
Johannes Berg4c476992010-10-04 21:36:35 +020010107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010108 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010109 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010110 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010111 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010112 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010113 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010114 struct cfg80211_mgmt_tx_params params = {
10115 .dont_wait_for_ack =
10116 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10117 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010118
Johannes Berg683b6d32012-11-08 21:25:48 +010010119 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010120 return -EINVAL;
10121
Johannes Berg4c476992010-10-04 21:36:35 +020010122 if (!rdev->ops->mgmt_tx)
10123 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010124
Johannes Berg71bbc992012-06-15 15:30:18 +020010125 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010126 case NL80211_IFTYPE_P2P_DEVICE:
10127 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10128 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010129 case NL80211_IFTYPE_STATION:
10130 case NL80211_IFTYPE_ADHOC:
10131 case NL80211_IFTYPE_P2P_CLIENT:
10132 case NL80211_IFTYPE_AP:
10133 case NL80211_IFTYPE_AP_VLAN:
10134 case NL80211_IFTYPE_MESH_POINT:
10135 case NL80211_IFTYPE_P2P_GO:
10136 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010137 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010138 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010139 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010140 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010141
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010142 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010143 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010144 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010145 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010146
10147 /*
10148 * We should wait on the channel for at least a minimum amount
10149 * of time (10ms) but no longer than the driver supports.
10150 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010151 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10152 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010153 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010154 }
10155
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010156 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010157
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010158 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010159 return -EINVAL;
10160
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010161 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010162
Antonio Quartulliea141b752013-06-11 14:20:03 +020010163 /* get the channel if any has been specified, otherwise pass NULL to
10164 * the driver. The latter will use the current one
10165 */
10166 chandef.chan = NULL;
10167 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10168 err = nl80211_parse_chandef(rdev, info, &chandef);
10169 if (err)
10170 return err;
10171 }
10172
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010173 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010174 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010175
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010176 wdev_lock(wdev);
10177 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10178 wdev_unlock(wdev);
10179 return -EBUSY;
10180 }
10181 wdev_unlock(wdev);
10182
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010183 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10184 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10185
10186 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10187 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10188 int i;
10189
10190 if (len % sizeof(u16))
10191 return -EINVAL;
10192
10193 params.n_csa_offsets = len / sizeof(u16);
10194 params.csa_offsets =
10195 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10196
10197 /* check that all the offsets fit the frame */
10198 for (i = 0; i < params.n_csa_offsets; i++) {
10199 if (params.csa_offsets[i] >= params.len)
10200 return -EINVAL;
10201 }
10202 }
10203
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010204 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010205 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10206 if (!msg)
10207 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010208
Eric W. Biederman15e47302012-09-07 20:12:54 +000010209 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010210 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010211 if (!hdr) {
10212 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010213 goto free_msg;
10214 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010215 }
Johannes Berge247bd902011-11-04 11:18:21 +010010216
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010217 params.chan = chandef.chan;
10218 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010219 if (err)
10220 goto free_msg;
10221
Johannes Berge247bd902011-11-04 11:18:21 +010010222 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010223 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10224 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010225 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010226
Johannes Berge247bd902011-11-04 11:18:21 +010010227 genlmsg_end(msg, hdr);
10228 return genlmsg_reply(msg, info);
10229 }
10230
10231 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010232
10233 nla_put_failure:
10234 err = -ENOBUFS;
10235 free_msg:
10236 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010237 return err;
10238}
10239
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010240static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10241{
10242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010243 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010244 u64 cookie;
10245
10246 if (!info->attrs[NL80211_ATTR_COOKIE])
10247 return -EINVAL;
10248
10249 if (!rdev->ops->mgmt_tx_cancel_wait)
10250 return -EOPNOTSUPP;
10251
Johannes Berg71bbc992012-06-15 15:30:18 +020010252 switch (wdev->iftype) {
10253 case NL80211_IFTYPE_STATION:
10254 case NL80211_IFTYPE_ADHOC:
10255 case NL80211_IFTYPE_P2P_CLIENT:
10256 case NL80211_IFTYPE_AP:
10257 case NL80211_IFTYPE_AP_VLAN:
10258 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010259 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010260 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010261 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010262 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010263 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010264 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010265
10266 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10267
Hila Gonene35e4d22012-06-27 17:19:42 +030010268 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010269}
10270
Kalle Valoffb9eb32010-02-17 17:58:10 +020010271static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10272{
Johannes Berg4c476992010-10-04 21:36:35 +020010273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010274 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010275 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010276 u8 ps_state;
10277 bool state;
10278 int err;
10279
Johannes Berg4c476992010-10-04 21:36:35 +020010280 if (!info->attrs[NL80211_ATTR_PS_STATE])
10281 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010282
10283 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10284
Kalle Valoffb9eb32010-02-17 17:58:10 +020010285 wdev = dev->ieee80211_ptr;
10286
Johannes Berg4c476992010-10-04 21:36:35 +020010287 if (!rdev->ops->set_power_mgmt)
10288 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010289
10290 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10291
10292 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010293 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010294
Hila Gonene35e4d22012-06-27 17:19:42 +030010295 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010296 if (!err)
10297 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010298 return err;
10299}
10300
10301static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10302{
Johannes Berg4c476992010-10-04 21:36:35 +020010303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010304 enum nl80211_ps_state ps_state;
10305 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010306 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010307 struct sk_buff *msg;
10308 void *hdr;
10309 int err;
10310
Kalle Valoffb9eb32010-02-17 17:58:10 +020010311 wdev = dev->ieee80211_ptr;
10312
Johannes Berg4c476992010-10-04 21:36:35 +020010313 if (!rdev->ops->set_power_mgmt)
10314 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010315
10316 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010317 if (!msg)
10318 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010319
Eric W. Biederman15e47302012-09-07 20:12:54 +000010320 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010321 NL80211_CMD_GET_POWER_SAVE);
10322 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010323 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010324 goto free_msg;
10325 }
10326
10327 if (wdev->ps)
10328 ps_state = NL80211_PS_ENABLED;
10329 else
10330 ps_state = NL80211_PS_DISABLED;
10331
David S. Miller9360ffd2012-03-29 04:41:26 -040010332 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10333 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010334
10335 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010336 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010337
Johannes Berg4c476992010-10-04 21:36:35 +020010338 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010339 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010340 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010341 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010342 return err;
10343}
10344
Johannes Berg94e860f2014-01-20 23:58:15 +010010345static const struct nla_policy
10346nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010347 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010348 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10349 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010350 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10351 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10352 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010353 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010354};
10355
Thomas Pedersen84f10702012-07-12 16:17:33 -070010356static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010357 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010358{
10359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010360 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010361 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010362
Johannes Bergd9d8b012012-11-26 12:51:52 +010010363 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010364 return -EINVAL;
10365
Thomas Pedersen84f10702012-07-12 16:17:33 -070010366 if (!rdev->ops->set_cqm_txe_config)
10367 return -EOPNOTSUPP;
10368
10369 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10370 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10371 return -EOPNOTSUPP;
10372
Hila Gonene35e4d22012-06-27 17:19:42 +030010373 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010374}
10375
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010376static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10377 struct net_device *dev)
10378{
10379 struct wireless_dev *wdev = dev->ieee80211_ptr;
10380 s32 last, low, high;
10381 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090010382 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010383 int err;
10384
10385 /* RSSI reporting disabled? */
10386 if (!wdev->cqm_config)
10387 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10388
10389 /*
10390 * Obtain current RSSI value if possible, if not and no RSSI threshold
10391 * event has been received yet, we should receive an event after a
10392 * connection is established and enough beacons received to calculate
10393 * the average.
10394 */
10395 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10396 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010397 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010398 u8 *mac_addr;
10399
10400 mac_addr = wdev->current_bss->pub.bssid;
10401
Johannes Berg73887fd2018-05-18 09:57:55 +020010402 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10403 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010404 return err;
10405
Omer Efrat397c6572018-06-17 13:06:14 +030010406 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010407 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010408 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010409 }
10410
10411 last = wdev->cqm_config->last_rssi_event_value;
10412 hyst = wdev->cqm_config->rssi_hyst;
10413 n = wdev->cqm_config->n_rssi_thresholds;
10414
10415 for (i = 0; i < n; i++)
10416 if (last < wdev->cqm_config->rssi_thresholds[i])
10417 break;
10418
Masashi Honma1222a162018-09-25 11:15:01 +090010419 low_index = i - 1;
10420 if (low_index >= 0) {
10421 low_index = array_index_nospec(low_index, n);
10422 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10423 } else {
10424 low = S32_MIN;
10425 }
10426 if (i < n) {
10427 i = array_index_nospec(i, n);
10428 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10429 } else {
10430 high = S32_MAX;
10431 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010432
10433 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10434}
10435
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010436static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010437 const s32 *thresholds, int n_thresholds,
10438 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010439{
Johannes Berg4c476992010-10-04 21:36:35 +020010440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010441 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010442 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010443 int i, err;
10444 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010445
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010446 /* Check all values negative and sorted */
10447 for (i = 0; i < n_thresholds; i++) {
10448 if (thresholds[i] > 0 || thresholds[i] <= prev)
10449 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010450
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010451 prev = thresholds[i];
10452 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010453
Johannes Berg074ac8d2010-09-16 14:58:22 +020010454 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010455 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10456 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010457
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010458 wdev_lock(wdev);
10459 cfg80211_cqm_config_free(wdev);
10460 wdev_unlock(wdev);
10461
10462 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10463 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10464 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10465
10466 return rdev_set_cqm_rssi_config(rdev, dev,
10467 thresholds[0], hysteresis);
10468 }
10469
10470 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10471 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10472 return -EOPNOTSUPP;
10473
10474 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10475 n_thresholds = 0;
10476
10477 wdev_lock(wdev);
10478 if (n_thresholds) {
10479 struct cfg80211_cqm_config *cqm_config;
10480
10481 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10482 n_thresholds * sizeof(s32), GFP_KERNEL);
10483 if (!cqm_config) {
10484 err = -ENOMEM;
10485 goto unlock;
10486 }
10487
10488 cqm_config->rssi_hyst = hysteresis;
10489 cqm_config->n_rssi_thresholds = n_thresholds;
10490 memcpy(cqm_config->rssi_thresholds, thresholds,
10491 n_thresholds * sizeof(s32));
10492
10493 wdev->cqm_config = cqm_config;
10494 }
10495
10496 err = cfg80211_cqm_rssi_update(rdev, dev);
10497
10498unlock:
10499 wdev_unlock(wdev);
10500
10501 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010502}
10503
10504static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10505{
10506 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10507 struct nlattr *cqm;
10508 int err;
10509
10510 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010511 if (!cqm)
10512 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010513
10514 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +020010515 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010516 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010517 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010518
10519 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10520 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010521 const s32 *thresholds =
10522 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10523 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010524 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010525
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010526 if (len % 4)
10527 return -EINVAL;
10528
10529 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10530 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010531 }
10532
10533 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10534 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10535 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10536 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10537 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10538 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10539
10540 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10541 }
10542
10543 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010544}
10545
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010546static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10547{
10548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10549 struct net_device *dev = info->user_ptr[1];
10550 struct ocb_setup setup = {};
10551 int err;
10552
10553 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10554 if (err)
10555 return err;
10556
10557 return cfg80211_join_ocb(rdev, dev, &setup);
10558}
10559
10560static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10561{
10562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10563 struct net_device *dev = info->user_ptr[1];
10564
10565 return cfg80211_leave_ocb(rdev, dev);
10566}
10567
Johannes Berg29cbe682010-12-03 09:20:44 +010010568static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10569{
10570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10571 struct net_device *dev = info->user_ptr[1];
10572 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010573 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010574 int err;
10575
10576 /* start with default */
10577 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010578 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010579
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010580 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010581 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010582 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010583 if (err)
10584 return err;
10585 }
10586
10587 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10588 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10589 return -EINVAL;
10590
Javier Cardonac80d5452010-12-16 17:37:49 -080010591 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10592 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10593
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010594 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10595 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10596 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10597 return -EINVAL;
10598
Marco Porsch9bdbf042013-01-07 16:04:51 +010010599 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10600 setup.beacon_interval =
10601 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010602
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010603 err = cfg80211_validate_beacon_int(rdev,
10604 NL80211_IFTYPE_MESH_POINT,
10605 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010606 if (err)
10607 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010608 }
10609
10610 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10611 setup.dtim_period =
10612 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10613 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10614 return -EINVAL;
10615 }
10616
Javier Cardonac80d5452010-12-16 17:37:49 -080010617 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10618 /* parse additional setup parameters if given */
10619 err = nl80211_parse_mesh_setup(info, &setup);
10620 if (err)
10621 return err;
10622 }
10623
Thomas Pedersend37bb182013-03-04 13:06:13 -080010624 if (setup.user_mpm)
10625 cfg.auto_open_plinks = false;
10626
Johannes Bergcc1d2802012-05-16 23:50:20 +020010627 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010628 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10629 if (err)
10630 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010631 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010632 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010633 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010634 }
10635
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010636 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10637 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10638 int n_rates =
10639 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10640 struct ieee80211_supported_band *sband;
10641
10642 if (!setup.chandef.chan)
10643 return -EINVAL;
10644
10645 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10646
10647 err = ieee80211_get_ratemask(sband, rates, n_rates,
10648 &setup.basic_rates);
10649 if (err)
10650 return err;
10651 }
10652
Johannes Berg8564e382016-09-19 09:44:44 +020010653 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10654 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10655 if (err)
10656 return err;
10657
Johannes Berg265698d2017-09-18 22:46:36 +020010658 if (!setup.chandef.chan)
10659 return -EINVAL;
10660
Johannes Berg8564e382016-09-19 09:44:44 +020010661 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10662 &setup.beacon_rate);
10663 if (err)
10664 return err;
10665 }
10666
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010667 setup.userspace_handles_dfs =
10668 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10669
Denis Kenzior1224f582018-03-26 12:52:49 -050010670 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10671 int r = validate_pae_over_nl80211(rdev, info);
10672
10673 if (r < 0)
10674 return r;
10675
10676 setup.control_port_over_nl80211 = true;
10677 }
10678
Denis Kenzior188c1b32018-03-26 12:52:46 -050010679 wdev_lock(dev->ieee80211_ptr);
10680 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10681 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10682 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10683 wdev_unlock(dev->ieee80211_ptr);
10684
10685 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010686}
10687
10688static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10689{
10690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10691 struct net_device *dev = info->user_ptr[1];
10692
10693 return cfg80211_leave_mesh(rdev, dev);
10694}
10695
Johannes Bergdfb89c52012-06-27 09:23:48 +020010696#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010697static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10698 struct cfg80211_registered_device *rdev)
10699{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010700 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010701 struct nlattr *nl_pats, *nl_pat;
10702 int i, pat_len;
10703
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010704 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010705 return 0;
10706
10707 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10708 if (!nl_pats)
10709 return -ENOBUFS;
10710
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010711 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010712 nl_pat = nla_nest_start(msg, i + 1);
10713 if (!nl_pat)
10714 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010715 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010716 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010717 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010718 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10719 wowlan->patterns[i].pattern) ||
10720 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010721 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010722 return -ENOBUFS;
10723 nla_nest_end(msg, nl_pat);
10724 }
10725 nla_nest_end(msg, nl_pats);
10726
10727 return 0;
10728}
10729
Johannes Berg2a0e0472013-01-23 22:57:40 +010010730static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10731 struct cfg80211_wowlan_tcp *tcp)
10732{
10733 struct nlattr *nl_tcp;
10734
10735 if (!tcp)
10736 return 0;
10737
10738 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10739 if (!nl_tcp)
10740 return -ENOBUFS;
10741
Jiri Benc930345e2015-03-29 16:59:25 +020010742 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10743 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010744 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10745 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10746 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10747 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10748 tcp->payload_len, tcp->payload) ||
10749 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10750 tcp->data_interval) ||
10751 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10752 tcp->wake_len, tcp->wake_data) ||
10753 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10754 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10755 return -ENOBUFS;
10756
10757 if (tcp->payload_seq.len &&
10758 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10759 sizeof(tcp->payload_seq), &tcp->payload_seq))
10760 return -ENOBUFS;
10761
10762 if (tcp->payload_tok.len &&
10763 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10764 sizeof(tcp->payload_tok) + tcp->tokens_size,
10765 &tcp->payload_tok))
10766 return -ENOBUFS;
10767
Johannes Berge248ad32013-05-16 10:24:28 +020010768 nla_nest_end(msg, nl_tcp);
10769
Johannes Berg2a0e0472013-01-23 22:57:40 +010010770 return 0;
10771}
10772
Luciano Coelho75453cc2015-01-09 14:06:37 +020010773static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10774 struct cfg80211_sched_scan_request *req)
10775{
Avraham Stern3b06d272015-10-12 09:51:34 +030010776 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010777 int i;
10778
10779 if (!req)
10780 return 0;
10781
10782 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10783 if (!nd)
10784 return -ENOBUFS;
10785
Avraham Stern3b06d272015-10-12 09:51:34 +030010786 if (req->n_scan_plans == 1 &&
10787 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10788 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010789 return -ENOBUFS;
10790
Luciano Coelho21fea562015-03-17 16:36:01 +020010791 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10792 return -ENOBUFS;
10793
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010794 if (req->relative_rssi_set) {
10795 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10796
10797 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10798 req->relative_rssi))
10799 return -ENOBUFS;
10800
10801 rssi_adjust.band = req->rssi_adjust.band;
10802 rssi_adjust.delta = req->rssi_adjust.delta;
10803 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10804 sizeof(rssi_adjust), &rssi_adjust))
10805 return -ENOBUFS;
10806 }
10807
Luciano Coelho75453cc2015-01-09 14:06:37 +020010808 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10809 if (!freqs)
10810 return -ENOBUFS;
10811
Johannes Berg53b18982016-09-14 09:59:21 +020010812 for (i = 0; i < req->n_channels; i++) {
10813 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10814 return -ENOBUFS;
10815 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010816
10817 nla_nest_end(msg, freqs);
10818
10819 if (req->n_match_sets) {
10820 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010821 if (!matches)
10822 return -ENOBUFS;
10823
Luciano Coelho75453cc2015-01-09 14:06:37 +020010824 for (i = 0; i < req->n_match_sets; i++) {
10825 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010826 if (!match)
10827 return -ENOBUFS;
10828
Johannes Berg53b18982016-09-14 09:59:21 +020010829 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10830 req->match_sets[i].ssid.ssid_len,
10831 req->match_sets[i].ssid.ssid))
10832 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010833 nla_nest_end(msg, match);
10834 }
10835 nla_nest_end(msg, matches);
10836 }
10837
Avraham Stern3b06d272015-10-12 09:51:34 +030010838 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10839 if (!scan_plans)
10840 return -ENOBUFS;
10841
10842 for (i = 0; i < req->n_scan_plans; i++) {
10843 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010844 if (!scan_plan)
10845 return -ENOBUFS;
10846
Colin Ian King67626962018-09-06 10:58:44 +010010847 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030010848 req->scan_plans[i].interval) ||
10849 (req->scan_plans[i].iterations &&
10850 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10851 req->scan_plans[i].iterations)))
10852 return -ENOBUFS;
10853 nla_nest_end(msg, scan_plan);
10854 }
10855 nla_nest_end(msg, scan_plans);
10856
Luciano Coelho75453cc2015-01-09 14:06:37 +020010857 nla_nest_end(msg, nd);
10858
10859 return 0;
10860}
10861
Johannes Bergff1b6e62011-05-04 15:37:28 +020010862static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10863{
10864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10865 struct sk_buff *msg;
10866 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010867 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010868
Johannes Berg964dc9e2013-06-03 17:25:34 +020010869 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010870 return -EOPNOTSUPP;
10871
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010872 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010873 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010874 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10875 rdev->wiphy.wowlan_config->tcp->payload_len +
10876 rdev->wiphy.wowlan_config->tcp->wake_len +
10877 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010878 }
10879
10880 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010881 if (!msg)
10882 return -ENOMEM;
10883
Eric W. Biederman15e47302012-09-07 20:12:54 +000010884 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010885 NL80211_CMD_GET_WOWLAN);
10886 if (!hdr)
10887 goto nla_put_failure;
10888
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010889 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010890 struct nlattr *nl_wowlan;
10891
10892 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10893 if (!nl_wowlan)
10894 goto nla_put_failure;
10895
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010896 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010898 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010899 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010900 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010901 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010902 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010903 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010904 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010905 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010906 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010907 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010908 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010909 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10910 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010911
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010912 if (nl80211_send_wowlan_patterns(msg, rdev))
10913 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010914
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010915 if (nl80211_send_wowlan_tcp(msg,
10916 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010917 goto nla_put_failure;
10918
Luciano Coelho75453cc2015-01-09 14:06:37 +020010919 if (nl80211_send_wowlan_nd(
10920 msg,
10921 rdev->wiphy.wowlan_config->nd_config))
10922 goto nla_put_failure;
10923
Johannes Bergff1b6e62011-05-04 15:37:28 +020010924 nla_nest_end(msg, nl_wowlan);
10925 }
10926
10927 genlmsg_end(msg, hdr);
10928 return genlmsg_reply(msg, info);
10929
10930nla_put_failure:
10931 nlmsg_free(msg);
10932 return -ENOBUFS;
10933}
10934
Johannes Berg2a0e0472013-01-23 22:57:40 +010010935static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10936 struct nlattr *attr,
10937 struct cfg80211_wowlan *trig)
10938{
10939 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10940 struct cfg80211_wowlan_tcp *cfg;
10941 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10942 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10943 u32 size;
10944 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10945 int err, port;
10946
Johannes Berg964dc9e2013-06-03 17:25:34 +020010947 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010948 return -EINVAL;
10949
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010950 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010951 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010952 if (err)
10953 return err;
10954
10955 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10956 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10957 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10958 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10959 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10960 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10961 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10962 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10963 return -EINVAL;
10964
10965 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010966 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010967 return -EINVAL;
10968
10969 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010970 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010971 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010972 return -EINVAL;
10973
10974 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010975 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010976 return -EINVAL;
10977
10978 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10979 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10980 return -EINVAL;
10981
10982 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10983 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10984
10985 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10986 tokens_size = tokln - sizeof(*tok);
10987
10988 if (!tok->len || tokens_size % tok->len)
10989 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010990 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010991 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010992 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010993 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010994 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010995 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010996 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010997 return -EINVAL;
10998 if (tok->offset + tok->len > data_size)
10999 return -EINVAL;
11000 }
11001
11002 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11003 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011004 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011005 return -EINVAL;
11006 if (seq->len == 0 || seq->len > 4)
11007 return -EINVAL;
11008 if (seq->len + seq->offset > data_size)
11009 return -EINVAL;
11010 }
11011
11012 size = sizeof(*cfg);
11013 size += data_size;
11014 size += wake_size + wake_mask_size;
11015 size += tokens_size;
11016
11017 cfg = kzalloc(size, GFP_KERNEL);
11018 if (!cfg)
11019 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011020 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11021 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011022 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11023 ETH_ALEN);
11024 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11025 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11026 else
11027 port = 0;
11028#ifdef CONFIG_INET
11029 /* allocate a socket and port for it and use it */
11030 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11031 IPPROTO_TCP, &cfg->sock, 1);
11032 if (err) {
11033 kfree(cfg);
11034 return err;
11035 }
11036 if (inet_csk_get_port(cfg->sock->sk, port)) {
11037 sock_release(cfg->sock);
11038 kfree(cfg);
11039 return -EADDRINUSE;
11040 }
11041 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11042#else
11043 if (!port) {
11044 kfree(cfg);
11045 return -EINVAL;
11046 }
11047 cfg->src_port = port;
11048#endif
11049
11050 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11051 cfg->payload_len = data_size;
11052 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11053 memcpy((void *)cfg->payload,
11054 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11055 data_size);
11056 if (seq)
11057 cfg->payload_seq = *seq;
11058 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11059 cfg->wake_len = wake_size;
11060 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11061 memcpy((void *)cfg->wake_data,
11062 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11063 wake_size);
11064 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11065 data_size + wake_size;
11066 memcpy((void *)cfg->wake_mask,
11067 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11068 wake_mask_size);
11069 if (tok) {
11070 cfg->tokens_size = tokens_size;
11071 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11072 }
11073
11074 trig->tcp = cfg;
11075
11076 return 0;
11077}
11078
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011079static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11080 const struct wiphy_wowlan_support *wowlan,
11081 struct nlattr *attr,
11082 struct cfg80211_wowlan *trig)
11083{
11084 struct nlattr **tb;
11085 int err;
11086
Kees Cook6396bb22018-06-12 14:03:40 -070011087 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011088 if (!tb)
11089 return -ENOMEM;
11090
11091 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11092 err = -EOPNOTSUPP;
11093 goto out;
11094 }
11095
Johannes Bergfceb6432017-04-12 14:34:07 +020011096 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
11097 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011098 if (err)
11099 goto out;
11100
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011101 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11102 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011103 err = PTR_ERR_OR_ZERO(trig->nd_config);
11104 if (err)
11105 trig->nd_config = NULL;
11106
11107out:
11108 kfree(tb);
11109 return err;
11110}
11111
Johannes Bergff1b6e62011-05-04 15:37:28 +020011112static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11113{
11114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11115 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011116 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011117 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011118 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011119 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011120 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011121 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011122
Johannes Berg964dc9e2013-06-03 17:25:34 +020011123 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011124 return -EOPNOTSUPP;
11125
Johannes Bergae33bd82012-07-12 16:25:02 +020011126 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11127 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011128 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011129 goto set_wakeup;
11130 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011131
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011132 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
11133 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020011134 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011135 if (err)
11136 return err;
11137
11138 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11139 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11140 return -EINVAL;
11141 new_triggers.any = true;
11142 }
11143
11144 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11145 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11146 return -EINVAL;
11147 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011148 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011149 }
11150
11151 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11152 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11153 return -EINVAL;
11154 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011155 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011156 }
11157
Johannes Berg77dbbb12011-07-13 10:48:55 +020011158 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11159 return -EINVAL;
11160
11161 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11162 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11163 return -EINVAL;
11164 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011165 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011166 }
11167
11168 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11169 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11170 return -EINVAL;
11171 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011172 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011173 }
11174
11175 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11176 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11177 return -EINVAL;
11178 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011179 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011180 }
11181
11182 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11183 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11184 return -EINVAL;
11185 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011186 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011187 }
11188
Johannes Bergff1b6e62011-05-04 15:37:28 +020011189 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11190 struct nlattr *pat;
11191 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011192 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011193 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011194
Johannes Berg98fc4382015-03-01 09:10:13 +020011195 regular = true;
11196
Johannes Bergff1b6e62011-05-04 15:37:28 +020011197 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11198 rem)
11199 n_patterns++;
11200 if (n_patterns > wowlan->n_patterns)
11201 return -EINVAL;
11202
11203 new_triggers.patterns = kcalloc(n_patterns,
11204 sizeof(new_triggers.patterns[0]),
11205 GFP_KERNEL);
11206 if (!new_triggers.patterns)
11207 return -ENOMEM;
11208
11209 new_triggers.n_patterns = n_patterns;
11210 i = 0;
11211
11212 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11213 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011214 u8 *mask_pat;
11215
Johannes Berg95bca622018-06-29 09:33:39 +020011216 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11217 nl80211_packet_pattern_policy,
11218 info->extack);
11219 if (err)
11220 goto error;
11221
Johannes Bergff1b6e62011-05-04 15:37:28 +020011222 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011223 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11224 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011225 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011226 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011227 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011228 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011229 goto error;
11230 if (pat_len > wowlan->pattern_max_len ||
11231 pat_len < wowlan->pattern_min_len)
11232 goto error;
11233
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011234 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011235 pkt_offset = 0;
11236 else
11237 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011238 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011239 if (pkt_offset > wowlan->max_pkt_offset)
11240 goto error;
11241 new_triggers.patterns[i].pkt_offset = pkt_offset;
11242
Johannes Berg922bd802014-05-19 17:59:50 +020011243 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11244 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011245 err = -ENOMEM;
11246 goto error;
11247 }
Johannes Berg922bd802014-05-19 17:59:50 +020011248 new_triggers.patterns[i].mask = mask_pat;
11249 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011250 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011251 mask_pat += mask_len;
11252 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011253 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011254 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011255 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011256 pat_len);
11257 i++;
11258 }
11259 }
11260
Johannes Berg2a0e0472013-01-23 22:57:40 +010011261 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011262 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011263 err = nl80211_parse_wowlan_tcp(
11264 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11265 &new_triggers);
11266 if (err)
11267 goto error;
11268 }
11269
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011270 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011271 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011272 err = nl80211_parse_wowlan_nd(
11273 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11274 &new_triggers);
11275 if (err)
11276 goto error;
11277 }
11278
Johannes Berg98fc4382015-03-01 09:10:13 +020011279 /* The 'any' trigger means the device continues operating more or less
11280 * as in its normal operation mode and wakes up the host on most of the
11281 * normal interrupts (like packet RX, ...)
11282 * It therefore makes little sense to combine with the more constrained
11283 * wakeup trigger modes.
11284 */
11285 if (new_triggers.any && regular) {
11286 err = -EINVAL;
11287 goto error;
11288 }
11289
Johannes Bergae33bd82012-07-12 16:25:02 +020011290 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11291 if (!ntrig) {
11292 err = -ENOMEM;
11293 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011294 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011295 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011296 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011297
Johannes Bergae33bd82012-07-12 16:25:02 +020011298 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011299 if (rdev->ops->set_wakeup &&
11300 prev_enabled != !!rdev->wiphy.wowlan_config)
11301 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011302
Johannes Bergff1b6e62011-05-04 15:37:28 +020011303 return 0;
11304 error:
11305 for (i = 0; i < new_triggers.n_patterns; i++)
11306 kfree(new_triggers.patterns[i].mask);
11307 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011308 if (new_triggers.tcp && new_triggers.tcp->sock)
11309 sock_release(new_triggers.tcp->sock);
11310 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011311 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011312 return err;
11313}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011314#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011315
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011316static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11317 struct cfg80211_registered_device *rdev)
11318{
11319 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11320 int i, j, pat_len;
11321 struct cfg80211_coalesce_rules *rule;
11322
11323 if (!rdev->coalesce->n_rules)
11324 return 0;
11325
11326 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
11327 if (!nl_rules)
11328 return -ENOBUFS;
11329
11330 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11331 nl_rule = nla_nest_start(msg, i + 1);
11332 if (!nl_rule)
11333 return -ENOBUFS;
11334
11335 rule = &rdev->coalesce->rules[i];
11336 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11337 rule->delay))
11338 return -ENOBUFS;
11339
11340 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11341 rule->condition))
11342 return -ENOBUFS;
11343
11344 nl_pats = nla_nest_start(msg,
11345 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11346 if (!nl_pats)
11347 return -ENOBUFS;
11348
11349 for (j = 0; j < rule->n_patterns; j++) {
11350 nl_pat = nla_nest_start(msg, j + 1);
11351 if (!nl_pat)
11352 return -ENOBUFS;
11353 pat_len = rule->patterns[j].pattern_len;
11354 if (nla_put(msg, NL80211_PKTPAT_MASK,
11355 DIV_ROUND_UP(pat_len, 8),
11356 rule->patterns[j].mask) ||
11357 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11358 rule->patterns[j].pattern) ||
11359 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11360 rule->patterns[j].pkt_offset))
11361 return -ENOBUFS;
11362 nla_nest_end(msg, nl_pat);
11363 }
11364 nla_nest_end(msg, nl_pats);
11365 nla_nest_end(msg, nl_rule);
11366 }
11367 nla_nest_end(msg, nl_rules);
11368
11369 return 0;
11370}
11371
11372static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11373{
11374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11375 struct sk_buff *msg;
11376 void *hdr;
11377
11378 if (!rdev->wiphy.coalesce)
11379 return -EOPNOTSUPP;
11380
11381 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11382 if (!msg)
11383 return -ENOMEM;
11384
11385 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11386 NL80211_CMD_GET_COALESCE);
11387 if (!hdr)
11388 goto nla_put_failure;
11389
11390 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11391 goto nla_put_failure;
11392
11393 genlmsg_end(msg, hdr);
11394 return genlmsg_reply(msg, info);
11395
11396nla_put_failure:
11397 nlmsg_free(msg);
11398 return -ENOBUFS;
11399}
11400
11401void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11402{
11403 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11404 int i, j;
11405 struct cfg80211_coalesce_rules *rule;
11406
11407 if (!coalesce)
11408 return;
11409
11410 for (i = 0; i < coalesce->n_rules; i++) {
11411 rule = &coalesce->rules[i];
11412 for (j = 0; j < rule->n_patterns; j++)
11413 kfree(rule->patterns[j].mask);
11414 kfree(rule->patterns);
11415 }
11416 kfree(coalesce->rules);
11417 kfree(coalesce);
11418 rdev->coalesce = NULL;
11419}
11420
11421static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11422 struct nlattr *rule,
11423 struct cfg80211_coalesce_rules *new_rule)
11424{
11425 int err, i;
11426 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11427 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11428 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11429 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11430
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011431 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020011432 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011433 if (err)
11434 return err;
11435
11436 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11437 new_rule->delay =
11438 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11439 if (new_rule->delay > coalesce->max_delay)
11440 return -EINVAL;
11441
11442 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11443 new_rule->condition =
11444 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011445
11446 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11447 return -EINVAL;
11448
11449 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11450 rem)
11451 n_patterns++;
11452 if (n_patterns > coalesce->n_patterns)
11453 return -EINVAL;
11454
11455 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11456 GFP_KERNEL);
11457 if (!new_rule->patterns)
11458 return -ENOMEM;
11459
11460 new_rule->n_patterns = n_patterns;
11461 i = 0;
11462
11463 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11464 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011465 u8 *mask_pat;
11466
Johannes Berg95bca622018-06-29 09:33:39 +020011467 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11468 nl80211_packet_pattern_policy, NULL);
11469 if (err)
11470 return err;
11471
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011472 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11473 !pat_tb[NL80211_PKTPAT_PATTERN])
11474 return -EINVAL;
11475 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11476 mask_len = DIV_ROUND_UP(pat_len, 8);
11477 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11478 return -EINVAL;
11479 if (pat_len > coalesce->pattern_max_len ||
11480 pat_len < coalesce->pattern_min_len)
11481 return -EINVAL;
11482
11483 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11484 pkt_offset = 0;
11485 else
11486 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11487 if (pkt_offset > coalesce->max_pkt_offset)
11488 return -EINVAL;
11489 new_rule->patterns[i].pkt_offset = pkt_offset;
11490
Johannes Berg922bd802014-05-19 17:59:50 +020011491 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11492 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011493 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011494
11495 new_rule->patterns[i].mask = mask_pat;
11496 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11497 mask_len);
11498
11499 mask_pat += mask_len;
11500 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011501 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011502 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11503 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011504 i++;
11505 }
11506
11507 return 0;
11508}
11509
11510static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11511{
11512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11513 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11514 struct cfg80211_coalesce new_coalesce = {};
11515 struct cfg80211_coalesce *n_coalesce;
11516 int err, rem_rule, n_rules = 0, i, j;
11517 struct nlattr *rule;
11518 struct cfg80211_coalesce_rules *tmp_rule;
11519
11520 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11521 return -EOPNOTSUPP;
11522
11523 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11524 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011525 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011526 return 0;
11527 }
11528
11529 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11530 rem_rule)
11531 n_rules++;
11532 if (n_rules > coalesce->n_rules)
11533 return -EINVAL;
11534
11535 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11536 GFP_KERNEL);
11537 if (!new_coalesce.rules)
11538 return -ENOMEM;
11539
11540 new_coalesce.n_rules = n_rules;
11541 i = 0;
11542
11543 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11544 rem_rule) {
11545 err = nl80211_parse_coalesce_rule(rdev, rule,
11546 &new_coalesce.rules[i]);
11547 if (err)
11548 goto error;
11549
11550 i++;
11551 }
11552
Ilan Peera1056b1b2015-10-22 22:27:46 +030011553 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011554 if (err)
11555 goto error;
11556
11557 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11558 if (!n_coalesce) {
11559 err = -ENOMEM;
11560 goto error;
11561 }
11562 cfg80211_rdev_free_coalesce(rdev);
11563 rdev->coalesce = n_coalesce;
11564
11565 return 0;
11566error:
11567 for (i = 0; i < new_coalesce.n_rules; i++) {
11568 tmp_rule = &new_coalesce.rules[i];
11569 for (j = 0; j < tmp_rule->n_patterns; j++)
11570 kfree(tmp_rule->patterns[j].mask);
11571 kfree(tmp_rule->patterns);
11572 }
11573 kfree(new_coalesce.rules);
11574
11575 return err;
11576}
11577
Johannes Berge5497d72011-07-05 16:35:40 +020011578static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11579{
11580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11581 struct net_device *dev = info->user_ptr[1];
11582 struct wireless_dev *wdev = dev->ieee80211_ptr;
11583 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11584 struct cfg80211_gtk_rekey_data rekey_data;
11585 int err;
11586
11587 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11588 return -EINVAL;
11589
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011590 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
11591 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020011592 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011593 if (err)
11594 return err;
11595
Vladis Dronove785fa02017-09-13 00:21:21 +020011596 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11597 !tb[NL80211_REKEY_DATA_KCK])
11598 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011599 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11600 return -ERANGE;
11601 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11602 return -ERANGE;
11603 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11604 return -ERANGE;
11605
Johannes Berg78f686c2014-09-10 22:28:06 +030011606 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11607 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11608 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011609
11610 wdev_lock(wdev);
11611 if (!wdev->current_bss) {
11612 err = -ENOTCONN;
11613 goto out;
11614 }
11615
11616 if (!rdev->ops->set_rekey_data) {
11617 err = -EOPNOTSUPP;
11618 goto out;
11619 }
11620
Hila Gonene35e4d22012-06-27 17:19:42 +030011621 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011622 out:
11623 wdev_unlock(wdev);
11624 return err;
11625}
11626
Johannes Berg28946da2011-11-04 11:18:12 +010011627static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11628 struct genl_info *info)
11629{
11630 struct net_device *dev = info->user_ptr[1];
11631 struct wireless_dev *wdev = dev->ieee80211_ptr;
11632
11633 if (wdev->iftype != NL80211_IFTYPE_AP &&
11634 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11635 return -EINVAL;
11636
Eric W. Biederman15e47302012-09-07 20:12:54 +000011637 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011638 return -EBUSY;
11639
Eric W. Biederman15e47302012-09-07 20:12:54 +000011640 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011641 return 0;
11642}
11643
Johannes Berg7f6cf312011-11-04 11:18:15 +010011644static int nl80211_probe_client(struct sk_buff *skb,
11645 struct genl_info *info)
11646{
11647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11648 struct net_device *dev = info->user_ptr[1];
11649 struct wireless_dev *wdev = dev->ieee80211_ptr;
11650 struct sk_buff *msg;
11651 void *hdr;
11652 const u8 *addr;
11653 u64 cookie;
11654 int err;
11655
11656 if (wdev->iftype != NL80211_IFTYPE_AP &&
11657 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11658 return -EOPNOTSUPP;
11659
11660 if (!info->attrs[NL80211_ATTR_MAC])
11661 return -EINVAL;
11662
11663 if (!rdev->ops->probe_client)
11664 return -EOPNOTSUPP;
11665
11666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11667 if (!msg)
11668 return -ENOMEM;
11669
Eric W. Biederman15e47302012-09-07 20:12:54 +000011670 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011671 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011672 if (!hdr) {
11673 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011674 goto free_msg;
11675 }
11676
11677 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11678
Hila Gonene35e4d22012-06-27 17:19:42 +030011679 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011680 if (err)
11681 goto free_msg;
11682
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011683 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11684 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011685 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011686
11687 genlmsg_end(msg, hdr);
11688
11689 return genlmsg_reply(msg, info);
11690
11691 nla_put_failure:
11692 err = -ENOBUFS;
11693 free_msg:
11694 nlmsg_free(msg);
11695 return err;
11696}
11697
Johannes Berg5e760232011-11-04 11:18:17 +010011698static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11699{
11700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011701 struct cfg80211_beacon_registration *reg, *nreg;
11702 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011703
11704 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11705 return -EOPNOTSUPP;
11706
Ben Greear37c73b52012-10-26 14:49:25 -070011707 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11708 if (!nreg)
11709 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011710
Ben Greear37c73b52012-10-26 14:49:25 -070011711 /* First, check if already registered. */
11712 spin_lock_bh(&rdev->beacon_registrations_lock);
11713 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11714 if (reg->nlportid == info->snd_portid) {
11715 rv = -EALREADY;
11716 goto out_err;
11717 }
11718 }
11719 /* Add it to the list */
11720 nreg->nlportid = info->snd_portid;
11721 list_add(&nreg->list, &rdev->beacon_registrations);
11722
11723 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011724
11725 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011726out_err:
11727 spin_unlock_bh(&rdev->beacon_registrations_lock);
11728 kfree(nreg);
11729 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011730}
11731
Johannes Berg98104fde2012-06-16 00:19:54 +020011732static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11733{
11734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11735 struct wireless_dev *wdev = info->user_ptr[1];
11736 int err;
11737
11738 if (!rdev->ops->start_p2p_device)
11739 return -EOPNOTSUPP;
11740
11741 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11742 return -EOPNOTSUPP;
11743
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011744 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011745 return 0;
11746
Luciano Coelhob6a55012014-02-27 11:07:21 +020011747 if (rfkill_blocked(rdev->rfkill))
11748 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011749
Johannes Bergeeb126e2012-10-23 15:16:50 +020011750 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011751 if (err)
11752 return err;
11753
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011754 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011755 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011756
11757 return 0;
11758}
11759
11760static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11761{
11762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11763 struct wireless_dev *wdev = info->user_ptr[1];
11764
11765 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11766 return -EOPNOTSUPP;
11767
11768 if (!rdev->ops->stop_p2p_device)
11769 return -EOPNOTSUPP;
11770
Johannes Bergf9f47522013-03-19 15:04:07 +010011771 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011772
11773 return 0;
11774}
11775
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011776static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11777{
11778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11779 struct wireless_dev *wdev = info->user_ptr[1];
11780 struct cfg80211_nan_conf conf = {};
11781 int err;
11782
11783 if (wdev->iftype != NL80211_IFTYPE_NAN)
11784 return -EOPNOTSUPP;
11785
Johannes Bergeeb04a92016-11-21 13:55:48 +010011786 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011787 return -EEXIST;
11788
11789 if (rfkill_blocked(rdev->rfkill))
11790 return -ERFKILL;
11791
11792 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11793 return -EINVAL;
11794
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011795 conf.master_pref =
11796 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011797
Luca Coelho85859892017-02-08 15:00:34 +020011798 if (info->attrs[NL80211_ATTR_BANDS]) {
11799 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11800
11801 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11802 return -EOPNOTSUPP;
11803
11804 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11805 return -EINVAL;
11806
11807 conf.bands = bands;
11808 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011809
11810 err = rdev_start_nan(rdev, wdev, &conf);
11811 if (err)
11812 return err;
11813
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011814 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011815 rdev->opencount++;
11816
11817 return 0;
11818}
11819
11820static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11821{
11822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11823 struct wireless_dev *wdev = info->user_ptr[1];
11824
11825 if (wdev->iftype != NL80211_IFTYPE_NAN)
11826 return -EOPNOTSUPP;
11827
11828 cfg80211_stop_nan(rdev, wdev);
11829
11830 return 0;
11831}
11832
Ayala Bekera442b762016-09-20 17:31:15 +030011833static int validate_nan_filter(struct nlattr *filter_attr)
11834{
11835 struct nlattr *attr;
11836 int len = 0, n_entries = 0, rem;
11837
11838 nla_for_each_nested(attr, filter_attr, rem) {
11839 len += nla_len(attr);
11840 n_entries++;
11841 }
11842
11843 if (len >= U8_MAX)
11844 return -EINVAL;
11845
11846 return n_entries;
11847}
11848
11849static int handle_nan_filter(struct nlattr *attr_filter,
11850 struct cfg80211_nan_func *func,
11851 bool tx)
11852{
11853 struct nlattr *attr;
11854 int n_entries, rem, i;
11855 struct cfg80211_nan_func_filter *filter;
11856
11857 n_entries = validate_nan_filter(attr_filter);
11858 if (n_entries < 0)
11859 return n_entries;
11860
11861 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11862
11863 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11864 if (!filter)
11865 return -ENOMEM;
11866
11867 i = 0;
11868 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011869 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011870 filter[i].len = nla_len(attr);
11871 i++;
11872 }
11873 if (tx) {
11874 func->num_tx_filters = n_entries;
11875 func->tx_filters = filter;
11876 } else {
11877 func->num_rx_filters = n_entries;
11878 func->rx_filters = filter;
11879 }
11880
11881 return 0;
11882}
11883
11884static int nl80211_nan_add_func(struct sk_buff *skb,
11885 struct genl_info *info)
11886{
11887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11888 struct wireless_dev *wdev = info->user_ptr[1];
11889 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11890 struct cfg80211_nan_func *func;
11891 struct sk_buff *msg = NULL;
11892 void *hdr = NULL;
11893 int err = 0;
11894
11895 if (wdev->iftype != NL80211_IFTYPE_NAN)
11896 return -EOPNOTSUPP;
11897
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011898 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011899 return -ENOTCONN;
11900
11901 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11902 return -EINVAL;
11903
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011904 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11905 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011906 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011907 if (err)
11908 return err;
11909
11910 func = kzalloc(sizeof(*func), GFP_KERNEL);
11911 if (!func)
11912 return -ENOMEM;
11913
Johannes Bergb60ad342018-10-01 11:52:07 +020011914 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030011915
11916 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11917 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11918 err = -EINVAL;
11919 goto out;
11920 }
11921
11922
11923 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11924
11925 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11926 err = -EINVAL;
11927 goto out;
11928 }
11929
11930 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11931 sizeof(func->service_id));
11932
11933 func->close_range =
11934 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11935
11936 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11937 func->serv_spec_info_len =
11938 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11939 func->serv_spec_info =
11940 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11941 func->serv_spec_info_len,
11942 GFP_KERNEL);
11943 if (!func->serv_spec_info) {
11944 err = -ENOMEM;
11945 goto out;
11946 }
11947 }
11948
11949 if (tb[NL80211_NAN_FUNC_TTL])
11950 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11951
11952 switch (func->type) {
11953 case NL80211_NAN_FUNC_PUBLISH:
11954 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11955 err = -EINVAL;
11956 goto out;
11957 }
11958
11959 func->publish_type =
11960 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11961 func->publish_bcast =
11962 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11963
11964 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11965 func->publish_bcast) {
11966 err = -EINVAL;
11967 goto out;
11968 }
11969 break;
11970 case NL80211_NAN_FUNC_SUBSCRIBE:
11971 func->subscribe_active =
11972 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11973 break;
11974 case NL80211_NAN_FUNC_FOLLOW_UP:
11975 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080011976 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11977 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030011978 err = -EINVAL;
11979 goto out;
11980 }
11981
11982 func->followup_id =
11983 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11984 func->followup_reqid =
11985 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11986 memcpy(func->followup_dest.addr,
11987 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11988 sizeof(func->followup_dest.addr));
11989 if (func->ttl) {
11990 err = -EINVAL;
11991 goto out;
11992 }
11993 break;
11994 default:
11995 err = -EINVAL;
11996 goto out;
11997 }
11998
11999 if (tb[NL80211_NAN_FUNC_SRF]) {
12000 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12001
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020012002 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
12003 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020012004 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012005 if (err)
12006 goto out;
12007
12008 func->srf_include =
12009 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12010
12011 if (srf_tb[NL80211_NAN_SRF_BF]) {
12012 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12013 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12014 err = -EINVAL;
12015 goto out;
12016 }
12017
12018 func->srf_bf_len =
12019 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12020 func->srf_bf =
12021 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12022 func->srf_bf_len, GFP_KERNEL);
12023 if (!func->srf_bf) {
12024 err = -ENOMEM;
12025 goto out;
12026 }
12027
12028 func->srf_bf_idx =
12029 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12030 } else {
12031 struct nlattr *attr, *mac_attr =
12032 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12033 int n_entries, rem, i = 0;
12034
12035 if (!mac_attr) {
12036 err = -EINVAL;
12037 goto out;
12038 }
12039
12040 n_entries = validate_acl_mac_addrs(mac_attr);
12041 if (n_entries <= 0) {
12042 err = -EINVAL;
12043 goto out;
12044 }
12045
12046 func->srf_num_macs = n_entries;
12047 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012048 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012049 GFP_KERNEL);
12050 if (!func->srf_macs) {
12051 err = -ENOMEM;
12052 goto out;
12053 }
12054
12055 nla_for_each_nested(attr, mac_attr, rem)
12056 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12057 sizeof(*func->srf_macs));
12058 }
12059 }
12060
12061 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12062 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12063 func, true);
12064 if (err)
12065 goto out;
12066 }
12067
12068 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12069 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12070 func, false);
12071 if (err)
12072 goto out;
12073 }
12074
12075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12076 if (!msg) {
12077 err = -ENOMEM;
12078 goto out;
12079 }
12080
12081 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12082 NL80211_CMD_ADD_NAN_FUNCTION);
12083 /* This can't really happen - we just allocated 4KB */
12084 if (WARN_ON(!hdr)) {
12085 err = -ENOMEM;
12086 goto out;
12087 }
12088
12089 err = rdev_add_nan_func(rdev, wdev, func);
12090out:
12091 if (err < 0) {
12092 cfg80211_free_nan_func(func);
12093 nlmsg_free(msg);
12094 return err;
12095 }
12096
12097 /* propagate the instance id and cookie to userspace */
12098 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12099 NL80211_ATTR_PAD))
12100 goto nla_put_failure;
12101
12102 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
12103 if (!func_attr)
12104 goto nla_put_failure;
12105
12106 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12107 func->instance_id))
12108 goto nla_put_failure;
12109
12110 nla_nest_end(msg, func_attr);
12111
12112 genlmsg_end(msg, hdr);
12113 return genlmsg_reply(msg, info);
12114
12115nla_put_failure:
12116 nlmsg_free(msg);
12117 return -ENOBUFS;
12118}
12119
12120static int nl80211_nan_del_func(struct sk_buff *skb,
12121 struct genl_info *info)
12122{
12123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12124 struct wireless_dev *wdev = info->user_ptr[1];
12125 u64 cookie;
12126
12127 if (wdev->iftype != NL80211_IFTYPE_NAN)
12128 return -EOPNOTSUPP;
12129
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012130 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012131 return -ENOTCONN;
12132
12133 if (!info->attrs[NL80211_ATTR_COOKIE])
12134 return -EINVAL;
12135
Ayala Bekera442b762016-09-20 17:31:15 +030012136 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12137
12138 rdev_del_nan_func(rdev, wdev, cookie);
12139
12140 return 0;
12141}
12142
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012143static int nl80211_nan_change_config(struct sk_buff *skb,
12144 struct genl_info *info)
12145{
12146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12147 struct wireless_dev *wdev = info->user_ptr[1];
12148 struct cfg80211_nan_conf conf = {};
12149 u32 changed = 0;
12150
12151 if (wdev->iftype != NL80211_IFTYPE_NAN)
12152 return -EOPNOTSUPP;
12153
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012154 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012155 return -ENOTCONN;
12156
12157 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12158 conf.master_pref =
12159 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12160 if (conf.master_pref <= 1 || conf.master_pref == 255)
12161 return -EINVAL;
12162
12163 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12164 }
12165
Luca Coelho85859892017-02-08 15:00:34 +020012166 if (info->attrs[NL80211_ATTR_BANDS]) {
12167 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12168
12169 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12170 return -EOPNOTSUPP;
12171
12172 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12173 return -EINVAL;
12174
12175 conf.bands = bands;
12176 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012177 }
12178
12179 if (!changed)
12180 return -EINVAL;
12181
12182 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12183}
12184
Ayala Beker50bcd312016-09-20 17:31:17 +030012185void cfg80211_nan_match(struct wireless_dev *wdev,
12186 struct cfg80211_nan_match_params *match, gfp_t gfp)
12187{
12188 struct wiphy *wiphy = wdev->wiphy;
12189 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12190 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12191 struct sk_buff *msg;
12192 void *hdr;
12193
12194 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12195 return;
12196
12197 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12198 if (!msg)
12199 return;
12200
12201 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12202 if (!hdr) {
12203 nlmsg_free(msg);
12204 return;
12205 }
12206
12207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12208 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12209 wdev->netdev->ifindex)) ||
12210 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12211 NL80211_ATTR_PAD))
12212 goto nla_put_failure;
12213
12214 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12215 NL80211_ATTR_PAD) ||
12216 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12217 goto nla_put_failure;
12218
12219 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
12220 if (!match_attr)
12221 goto nla_put_failure;
12222
12223 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
12224 if (!local_func_attr)
12225 goto nla_put_failure;
12226
12227 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12228 goto nla_put_failure;
12229
12230 nla_nest_end(msg, local_func_attr);
12231
12232 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
12233 if (!peer_func_attr)
12234 goto nla_put_failure;
12235
12236 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12237 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12238 goto nla_put_failure;
12239
12240 if (match->info && match->info_len &&
12241 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12242 match->info))
12243 goto nla_put_failure;
12244
12245 nla_nest_end(msg, peer_func_attr);
12246 nla_nest_end(msg, match_attr);
12247 genlmsg_end(msg, hdr);
12248
12249 if (!wdev->owner_nlportid)
12250 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12251 msg, 0, NL80211_MCGRP_NAN, gfp);
12252 else
12253 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12254 wdev->owner_nlportid);
12255
12256 return;
12257
12258nla_put_failure:
12259 nlmsg_free(msg);
12260}
12261EXPORT_SYMBOL(cfg80211_nan_match);
12262
Ayala Beker368e5a72016-09-20 17:31:18 +030012263void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12264 u8 inst_id,
12265 enum nl80211_nan_func_term_reason reason,
12266 u64 cookie, gfp_t gfp)
12267{
12268 struct wiphy *wiphy = wdev->wiphy;
12269 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12270 struct sk_buff *msg;
12271 struct nlattr *func_attr;
12272 void *hdr;
12273
12274 if (WARN_ON(!inst_id))
12275 return;
12276
12277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12278 if (!msg)
12279 return;
12280
12281 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12282 if (!hdr) {
12283 nlmsg_free(msg);
12284 return;
12285 }
12286
12287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12288 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12289 wdev->netdev->ifindex)) ||
12290 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12291 NL80211_ATTR_PAD))
12292 goto nla_put_failure;
12293
12294 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12295 NL80211_ATTR_PAD))
12296 goto nla_put_failure;
12297
12298 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
12299 if (!func_attr)
12300 goto nla_put_failure;
12301
12302 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12303 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12304 goto nla_put_failure;
12305
12306 nla_nest_end(msg, func_attr);
12307 genlmsg_end(msg, hdr);
12308
12309 if (!wdev->owner_nlportid)
12310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12311 msg, 0, NL80211_MCGRP_NAN, gfp);
12312 else
12313 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12314 wdev->owner_nlportid);
12315
12316 return;
12317
12318nla_put_failure:
12319 nlmsg_free(msg);
12320}
12321EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12322
Johannes Berg3713b4e2013-02-14 16:19:38 +010012323static int nl80211_get_protocol_features(struct sk_buff *skb,
12324 struct genl_info *info)
12325{
12326 void *hdr;
12327 struct sk_buff *msg;
12328
12329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12330 if (!msg)
12331 return -ENOMEM;
12332
12333 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12334 NL80211_CMD_GET_PROTOCOL_FEATURES);
12335 if (!hdr)
12336 goto nla_put_failure;
12337
12338 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12339 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12340 goto nla_put_failure;
12341
12342 genlmsg_end(msg, hdr);
12343 return genlmsg_reply(msg, info);
12344
12345 nla_put_failure:
12346 kfree_skb(msg);
12347 return -ENOBUFS;
12348}
12349
Jouni Malinen355199e2013-02-27 17:14:27 +020012350static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12351{
12352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12353 struct cfg80211_update_ft_ies_params ft_params;
12354 struct net_device *dev = info->user_ptr[1];
12355
12356 if (!rdev->ops->update_ft_ies)
12357 return -EOPNOTSUPP;
12358
12359 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012360 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012361 return -EINVAL;
12362
12363 memset(&ft_params, 0, sizeof(ft_params));
12364 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12365 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12366 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12367
12368 return rdev_update_ft_ies(rdev, dev, &ft_params);
12369}
12370
Arend van Spriel5de17982013-04-18 15:49:00 +020012371static int nl80211_crit_protocol_start(struct sk_buff *skb,
12372 struct genl_info *info)
12373{
12374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12375 struct wireless_dev *wdev = info->user_ptr[1];
12376 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12377 u16 duration;
12378 int ret;
12379
12380 if (!rdev->ops->crit_proto_start)
12381 return -EOPNOTSUPP;
12382
12383 if (WARN_ON(!rdev->ops->crit_proto_stop))
12384 return -EINVAL;
12385
12386 if (rdev->crit_proto_nlportid)
12387 return -EBUSY;
12388
12389 /* determine protocol if provided */
12390 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12391 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12392
12393 if (proto >= NUM_NL80211_CRIT_PROTO)
12394 return -EINVAL;
12395
12396 /* timeout must be provided */
12397 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12398 return -EINVAL;
12399
12400 duration =
12401 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12402
12403 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12404 return -ERANGE;
12405
12406 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12407 if (!ret)
12408 rdev->crit_proto_nlportid = info->snd_portid;
12409
12410 return ret;
12411}
12412
12413static int nl80211_crit_protocol_stop(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
12419 if (!rdev->ops->crit_proto_stop)
12420 return -EOPNOTSUPP;
12421
12422 if (rdev->crit_proto_nlportid) {
12423 rdev->crit_proto_nlportid = 0;
12424 rdev_crit_proto_stop(rdev, wdev);
12425 }
12426 return 0;
12427}
12428
Johannes Bergad7e7182013-11-13 13:37:47 +010012429static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12430{
12431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12432 struct wireless_dev *wdev =
12433 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12434 int i, err;
12435 u32 vid, subcmd;
12436
12437 if (!rdev->wiphy.vendor_commands)
12438 return -EOPNOTSUPP;
12439
12440 if (IS_ERR(wdev)) {
12441 err = PTR_ERR(wdev);
12442 if (err != -EINVAL)
12443 return err;
12444 wdev = NULL;
12445 } else if (wdev->wiphy != &rdev->wiphy) {
12446 return -EINVAL;
12447 }
12448
12449 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12450 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12451 return -EINVAL;
12452
12453 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12454 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12455 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12456 const struct wiphy_vendor_command *vcmd;
12457 void *data = NULL;
12458 int len = 0;
12459
12460 vcmd = &rdev->wiphy.vendor_commands[i];
12461
12462 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12463 continue;
12464
12465 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12466 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12467 if (!wdev)
12468 return -EINVAL;
12469 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12470 !wdev->netdev)
12471 return -EINVAL;
12472
12473 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012474 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012475 return -ENETDOWN;
12476 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012477
12478 if (!vcmd->doit)
12479 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012480 } else {
12481 wdev = NULL;
12482 }
12483
12484 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12485 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12486 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12487 }
12488
12489 rdev->cur_cmd_info = info;
12490 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
12491 data, len);
12492 rdev->cur_cmd_info = NULL;
12493 return err;
12494 }
12495
12496 return -EOPNOTSUPP;
12497}
12498
Johannes Berg7bdbe402015-08-15 22:39:49 +030012499static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12500 struct netlink_callback *cb,
12501 struct cfg80211_registered_device **rdev,
12502 struct wireless_dev **wdev)
12503{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012504 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012505 u32 vid, subcmd;
12506 unsigned int i;
12507 int vcmd_idx = -1;
12508 int err;
12509 void *data = NULL;
12510 unsigned int data_len = 0;
12511
Johannes Berg7bdbe402015-08-15 22:39:49 +030012512 if (cb->args[0]) {
12513 /* subtract the 1 again here */
12514 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12515 struct wireless_dev *tmp;
12516
Johannes Bergea90e0d2017-03-15 14:26:04 +010012517 if (!wiphy)
12518 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012519 *rdev = wiphy_to_rdev(wiphy);
12520 *wdev = NULL;
12521
12522 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012523 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012524 if (tmp->identifier == cb->args[1] - 1) {
12525 *wdev = tmp;
12526 break;
12527 }
12528 }
12529 }
12530
12531 /* keep rtnl locked in successful case */
12532 return 0;
12533 }
12534
Johannes Bergfceb6432017-04-12 14:34:07 +020012535 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
12536 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012537 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012538 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012539
Johannes Bergc90c39d2016-10-24 14:40:01 +020012540 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012541 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12542 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012543
Johannes Bergc90c39d2016-10-24 14:40:01 +020012544 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012545 if (IS_ERR(*wdev))
12546 *wdev = NULL;
12547
Johannes Bergc90c39d2016-10-24 14:40:01 +020012548 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012549 if (IS_ERR(*rdev))
12550 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012551
Johannes Bergc90c39d2016-10-24 14:40:01 +020012552 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12553 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012554
12555 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12556 const struct wiphy_vendor_command *vcmd;
12557
12558 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12559
12560 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12561 continue;
12562
Johannes Bergea90e0d2017-03-15 14:26:04 +010012563 if (!vcmd->dumpit)
12564 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012565
12566 vcmd_idx = i;
12567 break;
12568 }
12569
Johannes Bergea90e0d2017-03-15 14:26:04 +010012570 if (vcmd_idx < 0)
12571 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012572
Johannes Bergc90c39d2016-10-24 14:40:01 +020012573 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12574 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12575 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012576 }
12577
12578 /* 0 is the first index - add 1 to parse only once */
12579 cb->args[0] = (*rdev)->wiphy_idx + 1;
12580 /* add 1 to know if it was NULL */
12581 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12582 cb->args[2] = vcmd_idx;
12583 cb->args[3] = (unsigned long)data;
12584 cb->args[4] = data_len;
12585
12586 /* keep rtnl locked in successful case */
12587 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012588}
12589
12590static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12591 struct netlink_callback *cb)
12592{
12593 struct cfg80211_registered_device *rdev;
12594 struct wireless_dev *wdev;
12595 unsigned int vcmd_idx;
12596 const struct wiphy_vendor_command *vcmd;
12597 void *data;
12598 int data_len;
12599 int err;
12600 struct nlattr *vendor_data;
12601
Johannes Bergea90e0d2017-03-15 14:26:04 +010012602 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012603 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12604 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012605 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012606
12607 vcmd_idx = cb->args[2];
12608 data = (void *)cb->args[3];
12609 data_len = cb->args[4];
12610 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12611
12612 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12613 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012614 if (!wdev) {
12615 err = -EINVAL;
12616 goto out;
12617 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012618 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012619 !wdev->netdev) {
12620 err = -EINVAL;
12621 goto out;
12622 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012623
12624 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012625 if (!wdev_running(wdev)) {
12626 err = -ENETDOWN;
12627 goto out;
12628 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012629 }
12630 }
12631
12632 while (1) {
12633 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12634 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12635 NL80211_CMD_VENDOR);
12636 if (!hdr)
12637 break;
12638
12639 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012640 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12641 wdev_id(wdev),
12642 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012643 genlmsg_cancel(skb, hdr);
12644 break;
12645 }
12646
12647 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12648 if (!vendor_data) {
12649 genlmsg_cancel(skb, hdr);
12650 break;
12651 }
12652
12653 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12654 (unsigned long *)&cb->args[5]);
12655 nla_nest_end(skb, vendor_data);
12656
12657 if (err == -ENOBUFS || err == -ENOENT) {
12658 genlmsg_cancel(skb, hdr);
12659 break;
12660 } else if (err) {
12661 genlmsg_cancel(skb, hdr);
12662 goto out;
12663 }
12664
12665 genlmsg_end(skb, hdr);
12666 }
12667
12668 err = skb->len;
12669 out:
12670 rtnl_unlock();
12671 return err;
12672}
12673
Johannes Bergad7e7182013-11-13 13:37:47 +010012674struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12675 enum nl80211_commands cmd,
12676 enum nl80211_attrs attr,
12677 int approxlen)
12678{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012679 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012680
12681 if (WARN_ON(!rdev->cur_cmd_info))
12682 return NULL;
12683
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012684 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012685 rdev->cur_cmd_info->snd_portid,
12686 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012687 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012688}
12689EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12690
12691int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12692{
12693 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12694 void *hdr = ((void **)skb->cb)[1];
12695 struct nlattr *data = ((void **)skb->cb)[2];
12696
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012697 /* clear CB data for netlink core to own from now on */
12698 memset(skb->cb, 0, sizeof(skb->cb));
12699
Johannes Bergad7e7182013-11-13 13:37:47 +010012700 if (WARN_ON(!rdev->cur_cmd_info)) {
12701 kfree_skb(skb);
12702 return -EINVAL;
12703 }
12704
12705 nla_nest_end(skb, data);
12706 genlmsg_end(skb, hdr);
12707 return genlmsg_reply(skb, rdev->cur_cmd_info);
12708}
12709EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12710
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012711static int nl80211_set_qos_map(struct sk_buff *skb,
12712 struct genl_info *info)
12713{
12714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12715 struct cfg80211_qos_map *qos_map = NULL;
12716 struct net_device *dev = info->user_ptr[1];
12717 u8 *pos, len, num_des, des_len, des;
12718 int ret;
12719
12720 if (!rdev->ops->set_qos_map)
12721 return -EOPNOTSUPP;
12722
12723 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12724 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12725 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12726
12727 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12728 len > IEEE80211_QOS_MAP_LEN_MAX)
12729 return -EINVAL;
12730
12731 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12732 if (!qos_map)
12733 return -ENOMEM;
12734
12735 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12736 if (num_des) {
12737 des_len = num_des *
12738 sizeof(struct cfg80211_dscp_exception);
12739 memcpy(qos_map->dscp_exception, pos, des_len);
12740 qos_map->num_des = num_des;
12741 for (des = 0; des < num_des; des++) {
12742 if (qos_map->dscp_exception[des].up > 7) {
12743 kfree(qos_map);
12744 return -EINVAL;
12745 }
12746 }
12747 pos += des_len;
12748 }
12749 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12750 }
12751
12752 wdev_lock(dev->ieee80211_ptr);
12753 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12754 if (!ret)
12755 ret = rdev_set_qos_map(rdev, dev, qos_map);
12756 wdev_unlock(dev->ieee80211_ptr);
12757
12758 kfree(qos_map);
12759 return ret;
12760}
12761
Johannes Berg960d01a2014-09-09 22:55:35 +030012762static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12763{
12764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12765 struct net_device *dev = info->user_ptr[1];
12766 struct wireless_dev *wdev = dev->ieee80211_ptr;
12767 const u8 *peer;
12768 u8 tsid, up;
12769 u16 admitted_time = 0;
12770 int err;
12771
Johannes Berg723e73a2014-10-22 09:25:06 +020012772 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012773 return -EOPNOTSUPP;
12774
12775 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12776 !info->attrs[NL80211_ATTR_USER_PRIO])
12777 return -EINVAL;
12778
12779 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030012780 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030012781
12782 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012783 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012784 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012785 * need more attributes for that (e.g. BA session requirement);
12786 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012787 */
12788 return -EINVAL;
12789 }
12790
12791 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12792
12793 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12794 admitted_time =
12795 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12796 if (!admitted_time)
12797 return -EINVAL;
12798 }
12799
12800 wdev_lock(wdev);
12801 switch (wdev->iftype) {
12802 case NL80211_IFTYPE_STATION:
12803 case NL80211_IFTYPE_P2P_CLIENT:
12804 if (wdev->current_bss)
12805 break;
12806 err = -ENOTCONN;
12807 goto out;
12808 default:
12809 err = -EOPNOTSUPP;
12810 goto out;
12811 }
12812
12813 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12814
12815 out:
12816 wdev_unlock(wdev);
12817 return err;
12818}
12819
12820static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12821{
12822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12823 struct net_device *dev = info->user_ptr[1];
12824 struct wireless_dev *wdev = dev->ieee80211_ptr;
12825 const u8 *peer;
12826 u8 tsid;
12827 int err;
12828
12829 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12830 return -EINVAL;
12831
12832 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12833 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12834
12835 wdev_lock(wdev);
12836 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12837 wdev_unlock(wdev);
12838
12839 return err;
12840}
12841
Arik Nemtsov1057d352014-11-19 12:54:26 +020012842static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12843 struct genl_info *info)
12844{
12845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12846 struct net_device *dev = info->user_ptr[1];
12847 struct wireless_dev *wdev = dev->ieee80211_ptr;
12848 struct cfg80211_chan_def chandef = {};
12849 const u8 *addr;
12850 u8 oper_class;
12851 int err;
12852
12853 if (!rdev->ops->tdls_channel_switch ||
12854 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12855 return -EOPNOTSUPP;
12856
12857 switch (dev->ieee80211_ptr->iftype) {
12858 case NL80211_IFTYPE_STATION:
12859 case NL80211_IFTYPE_P2P_CLIENT:
12860 break;
12861 default:
12862 return -EOPNOTSUPP;
12863 }
12864
12865 if (!info->attrs[NL80211_ATTR_MAC] ||
12866 !info->attrs[NL80211_ATTR_OPER_CLASS])
12867 return -EINVAL;
12868
12869 err = nl80211_parse_chandef(rdev, info, &chandef);
12870 if (err)
12871 return err;
12872
12873 /*
12874 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12875 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12876 * specification is not defined for them.
12877 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012878 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012879 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12880 chandef.width != NL80211_CHAN_WIDTH_20)
12881 return -EINVAL;
12882
12883 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012884 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12885 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012886 return -EINVAL;
12887
12888 /* don't allow switching to DFS channels */
12889 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12890 return -EINVAL;
12891
12892 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12893 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12894
12895 wdev_lock(wdev);
12896 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12897 wdev_unlock(wdev);
12898
12899 return err;
12900}
12901
12902static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12903 struct genl_info *info)
12904{
12905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12906 struct net_device *dev = info->user_ptr[1];
12907 struct wireless_dev *wdev = dev->ieee80211_ptr;
12908 const u8 *addr;
12909
12910 if (!rdev->ops->tdls_channel_switch ||
12911 !rdev->ops->tdls_cancel_channel_switch ||
12912 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12913 return -EOPNOTSUPP;
12914
12915 switch (dev->ieee80211_ptr->iftype) {
12916 case NL80211_IFTYPE_STATION:
12917 case NL80211_IFTYPE_P2P_CLIENT:
12918 break;
12919 default:
12920 return -EOPNOTSUPP;
12921 }
12922
12923 if (!info->attrs[NL80211_ATTR_MAC])
12924 return -EINVAL;
12925
12926 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12927
12928 wdev_lock(wdev);
12929 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12930 wdev_unlock(wdev);
12931
12932 return 0;
12933}
12934
Michael Braunce0ce132016-10-10 19:12:22 +020012935static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12936 struct genl_info *info)
12937{
12938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12939 struct net_device *dev = info->user_ptr[1];
12940 struct wireless_dev *wdev = dev->ieee80211_ptr;
12941 const struct nlattr *nla;
12942 bool enabled;
12943
Michael Braunce0ce132016-10-10 19:12:22 +020012944 if (!rdev->ops->set_multicast_to_unicast)
12945 return -EOPNOTSUPP;
12946
12947 if (wdev->iftype != NL80211_IFTYPE_AP &&
12948 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12949 return -EOPNOTSUPP;
12950
12951 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12952 enabled = nla_get_flag(nla);
12953
12954 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12955}
12956
Avraham Stern3a00df52017-06-09 13:08:43 +010012957static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12958{
12959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12960 struct net_device *dev = info->user_ptr[1];
12961 struct wireless_dev *wdev = dev->ieee80211_ptr;
12962 struct cfg80211_pmk_conf pmk_conf = {};
12963 int ret;
12964
12965 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12966 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12967 return -EOPNOTSUPP;
12968
12969 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12970 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12971 return -EOPNOTSUPP;
12972
12973 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12974 return -EINVAL;
12975
12976 wdev_lock(wdev);
12977 if (!wdev->current_bss) {
12978 ret = -ENOTCONN;
12979 goto out;
12980 }
12981
12982 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12983 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12984 ret = -EINVAL;
12985 goto out;
12986 }
12987
12988 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12989 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12990 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12991 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12992 ret = -EINVAL;
12993 goto out;
12994 }
12995
12996 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12997 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12998
12999 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13000 ret = -EINVAL;
13001 goto out;
13002 }
13003
13004 pmk_conf.pmk_r0_name =
13005 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13006 }
13007
13008 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13009out:
13010 wdev_unlock(wdev);
13011 return ret;
13012}
13013
13014static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13015{
13016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13017 struct net_device *dev = info->user_ptr[1];
13018 struct wireless_dev *wdev = dev->ieee80211_ptr;
13019 const u8 *aa;
13020 int ret;
13021
13022 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13023 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13024 return -EOPNOTSUPP;
13025
13026 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13027 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13028 return -EOPNOTSUPP;
13029
13030 if (!info->attrs[NL80211_ATTR_MAC])
13031 return -EINVAL;
13032
13033 wdev_lock(wdev);
13034 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13035 ret = rdev_del_pmk(rdev, dev, aa);
13036 wdev_unlock(wdev);
13037
13038 return ret;
13039}
13040
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013041static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13042{
13043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13044 struct net_device *dev = info->user_ptr[1];
13045 struct cfg80211_external_auth_params params;
13046
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013047 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013048 return -EOPNOTSUPP;
13049
13050 if (!info->attrs[NL80211_ATTR_SSID])
13051 return -EINVAL;
13052
13053 if (!info->attrs[NL80211_ATTR_BSSID])
13054 return -EINVAL;
13055
13056 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13057 return -EINVAL;
13058
13059 memset(&params, 0, sizeof(params));
13060
13061 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13062 if (params.ssid.ssid_len == 0 ||
13063 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13064 return -EINVAL;
13065 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
13066 params.ssid.ssid_len);
13067
13068 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13069 ETH_ALEN);
13070
13071 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13072
13073 return rdev_external_auth(rdev, dev, &params);
13074}
13075
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013076static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13077{
13078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13079 struct net_device *dev = info->user_ptr[1];
13080 struct wireless_dev *wdev = dev->ieee80211_ptr;
13081 const u8 *buf;
13082 size_t len;
13083 u8 *dest;
13084 u16 proto;
13085 bool noencrypt;
13086 int err;
13087
13088 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13089 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13090 return -EOPNOTSUPP;
13091
13092 if (!rdev->ops->tx_control_port)
13093 return -EOPNOTSUPP;
13094
13095 if (!info->attrs[NL80211_ATTR_FRAME] ||
13096 !info->attrs[NL80211_ATTR_MAC] ||
13097 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13098 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13099 return -EINVAL;
13100 }
13101
13102 wdev_lock(wdev);
13103
13104 switch (wdev->iftype) {
13105 case NL80211_IFTYPE_AP:
13106 case NL80211_IFTYPE_P2P_GO:
13107 case NL80211_IFTYPE_MESH_POINT:
13108 break;
13109 case NL80211_IFTYPE_ADHOC:
13110 case NL80211_IFTYPE_STATION:
13111 case NL80211_IFTYPE_P2P_CLIENT:
13112 if (wdev->current_bss)
13113 break;
13114 err = -ENOTCONN;
13115 goto out;
13116 default:
13117 err = -EOPNOTSUPP;
13118 goto out;
13119 }
13120
13121 wdev_unlock(wdev);
13122
13123 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13124 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13125 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13126 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13127 noencrypt =
13128 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13129
13130 return rdev_tx_control_port(rdev, dev, buf, len,
13131 dest, cpu_to_be16(proto), noencrypt);
13132
13133 out:
13134 wdev_unlock(wdev);
13135 return err;
13136}
13137
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013138static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13139 struct genl_info *info)
13140{
13141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13142 struct net_device *dev = info->user_ptr[1];
13143 struct wireless_dev *wdev = dev->ieee80211_ptr;
13144 struct cfg80211_ftm_responder_stats ftm_stats = {};
13145 struct sk_buff *msg;
13146 void *hdr;
13147 struct nlattr *ftm_stats_attr;
13148 int err;
13149
13150 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13151 return -EOPNOTSUPP;
13152
13153 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13154 if (err)
13155 return err;
13156
13157 if (!ftm_stats.filled)
13158 return -ENODATA;
13159
13160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13161 if (!msg)
13162 return -ENOMEM;
13163
13164 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13165 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13166 if (!hdr)
13167 return -ENOBUFS;
13168
13169 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13170 goto nla_put_failure;
13171
13172 ftm_stats_attr = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER_STATS);
13173 if (!ftm_stats_attr)
13174 goto nla_put_failure;
13175
13176#define SET_FTM(field, name, type) \
13177 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13178 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13179 ftm_stats.field)) \
13180 goto nla_put_failure; } while (0)
13181#define SET_FTM_U64(field, name) \
13182 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13183 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13184 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13185 goto nla_put_failure; } while (0)
13186
13187 SET_FTM(success_num, SUCCESS_NUM, u32);
13188 SET_FTM(partial_num, PARTIAL_NUM, u32);
13189 SET_FTM(failed_num, FAILED_NUM, u32);
13190 SET_FTM(asap_num, ASAP_NUM, u32);
13191 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13192 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13193 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13194 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13195 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13196#undef SET_FTM
13197
13198 nla_nest_end(msg, ftm_stats_attr);
13199
13200 genlmsg_end(msg, hdr);
13201 return genlmsg_reply(msg, info);
13202
13203nla_put_failure:
13204 nlmsg_free(msg);
13205 return -ENOBUFS;
13206}
13207
Johannes Berg4c476992010-10-04 21:36:35 +020013208#define NL80211_FLAG_NEED_WIPHY 0x01
13209#define NL80211_FLAG_NEED_NETDEV 0x02
13210#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013211#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13212#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13213 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013214#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013215/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013216#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13217 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013218#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013219
Johannes Bergf84f7712013-11-14 17:14:45 +010013220static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013221 struct genl_info *info)
13222{
13223 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013224 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013225 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013226 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13227
13228 if (rtnl)
13229 rtnl_lock();
13230
13231 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013232 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013233 if (IS_ERR(rdev)) {
13234 if (rtnl)
13235 rtnl_unlock();
13236 return PTR_ERR(rdev);
13237 }
13238 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013239 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13240 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013241 ASSERT_RTNL();
13242
Johannes Berg89a54e42012-06-15 14:33:17 +020013243 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13244 info->attrs);
13245 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013246 if (rtnl)
13247 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013248 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013249 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013250
Johannes Berg89a54e42012-06-15 14:33:17 +020013251 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013252 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013253
Johannes Berg1bf614e2012-06-15 15:23:36 +020013254 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13255 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013256 if (rtnl)
13257 rtnl_unlock();
13258 return -EINVAL;
13259 }
13260
13261 info->user_ptr[1] = dev;
13262 } else {
13263 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013264 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013265
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013266 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13267 !wdev_running(wdev)) {
13268 if (rtnl)
13269 rtnl_unlock();
13270 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013271 }
13272
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013273 if (dev)
13274 dev_hold(dev);
13275
Johannes Berg4c476992010-10-04 21:36:35 +020013276 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013277 }
13278
13279 return 0;
13280}
13281
Johannes Bergf84f7712013-11-14 17:14:45 +010013282static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013283 struct genl_info *info)
13284{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013285 if (info->user_ptr[1]) {
13286 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13287 struct wireless_dev *wdev = info->user_ptr[1];
13288
13289 if (wdev->netdev)
13290 dev_put(wdev->netdev);
13291 } else {
13292 dev_put(info->user_ptr[1]);
13293 }
13294 }
Johannes Berg5393b912014-09-10 15:00:16 +030013295
Johannes Berg4c476992010-10-04 21:36:35 +020013296 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13297 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013298
13299 /* If needed, clear the netlink message payload from the SKB
13300 * as it might contain key data that shouldn't stick around on
13301 * the heap after the SKB is freed. The netlink message header
13302 * is still needed for further processing, so leave it intact.
13303 */
13304 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13305 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13306
13307 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13308 }
Johannes Berg4c476992010-10-04 21:36:35 +020013309}
13310
Johannes Berg4534de82013-11-14 17:14:46 +010013311static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013312 {
13313 .cmd = NL80211_CMD_GET_WIPHY,
13314 .doit = nl80211_get_wiphy,
13315 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013316 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013317 .policy = nl80211_policy,
13318 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013319 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13320 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013321 },
13322 {
13323 .cmd = NL80211_CMD_SET_WIPHY,
13324 .doit = nl80211_set_wiphy,
13325 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013326 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013327 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013328 },
13329 {
13330 .cmd = NL80211_CMD_GET_INTERFACE,
13331 .doit = nl80211_get_interface,
13332 .dumpit = nl80211_dump_interface,
13333 .policy = nl80211_policy,
13334 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013335 .internal_flags = NL80211_FLAG_NEED_WDEV |
13336 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013337 },
13338 {
13339 .cmd = NL80211_CMD_SET_INTERFACE,
13340 .doit = nl80211_set_interface,
13341 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013342 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013343 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13344 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013345 },
13346 {
13347 .cmd = NL80211_CMD_NEW_INTERFACE,
13348 .doit = nl80211_new_interface,
13349 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013350 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013351 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13352 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013353 },
13354 {
13355 .cmd = NL80211_CMD_DEL_INTERFACE,
13356 .doit = nl80211_del_interface,
13357 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013358 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013359 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013360 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013361 },
Johannes Berg41ade002007-12-19 02:03:29 +010013362 {
13363 .cmd = NL80211_CMD_GET_KEY,
13364 .doit = nl80211_get_key,
13365 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013366 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013367 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013368 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013369 },
13370 {
13371 .cmd = NL80211_CMD_SET_KEY,
13372 .doit = nl80211_set_key,
13373 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013374 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013375 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013376 NL80211_FLAG_NEED_RTNL |
13377 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013378 },
13379 {
13380 .cmd = NL80211_CMD_NEW_KEY,
13381 .doit = nl80211_new_key,
13382 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013383 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013385 NL80211_FLAG_NEED_RTNL |
13386 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013387 },
13388 {
13389 .cmd = NL80211_CMD_DEL_KEY,
13390 .doit = nl80211_del_key,
13391 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013392 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013394 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013395 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013396 {
13397 .cmd = NL80211_CMD_SET_BEACON,
13398 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013399 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013400 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013401 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013402 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013403 },
13404 {
Johannes Berg88600202012-02-13 15:17:18 +010013405 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013406 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013407 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013408 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013409 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013410 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013411 },
13412 {
Johannes Berg88600202012-02-13 15:17:18 +010013413 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013414 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013415 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013416 .doit = nl80211_stop_ap,
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 Berged1b6cc2007-12-19 02:03:32 +010013419 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013420 {
13421 .cmd = NL80211_CMD_GET_STATION,
13422 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013423 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010013424 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020013425 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13426 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013427 },
13428 {
13429 .cmd = NL80211_CMD_SET_STATION,
13430 .doit = nl80211_set_station,
13431 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013432 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013433 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013434 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013435 },
13436 {
13437 .cmd = NL80211_CMD_NEW_STATION,
13438 .doit = nl80211_new_station,
13439 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013440 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013442 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013443 },
13444 {
13445 .cmd = NL80211_CMD_DEL_STATION,
13446 .doit = nl80211_del_station,
13447 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013448 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013450 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013451 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013452 {
13453 .cmd = NL80211_CMD_GET_MPATH,
13454 .doit = nl80211_get_mpath,
13455 .dumpit = nl80211_dump_mpath,
13456 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013457 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013459 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013460 },
13461 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013462 .cmd = NL80211_CMD_GET_MPP,
13463 .doit = nl80211_get_mpp,
13464 .dumpit = nl80211_dump_mpp,
13465 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013466 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13468 NL80211_FLAG_NEED_RTNL,
13469 },
13470 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013471 .cmd = NL80211_CMD_SET_MPATH,
13472 .doit = nl80211_set_mpath,
13473 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013474 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013475 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013476 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013477 },
13478 {
13479 .cmd = NL80211_CMD_NEW_MPATH,
13480 .doit = nl80211_new_mpath,
13481 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013482 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013484 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013485 },
13486 {
13487 .cmd = NL80211_CMD_DEL_MPATH,
13488 .doit = nl80211_del_mpath,
13489 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013490 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013492 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013493 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013494 {
13495 .cmd = NL80211_CMD_SET_BSS,
13496 .doit = nl80211_set_bss,
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,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013501 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013502 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013503 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013504 .doit = nl80211_get_reg_do,
13505 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013506 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013507 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013508 /* can be retrieved by unprivileged users */
13509 },
Johannes Bergb6863032015-10-15 09:25:18 +020013510#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013511 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013512 .cmd = NL80211_CMD_SET_REG,
13513 .doit = nl80211_set_reg,
13514 .policy = nl80211_policy,
13515 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013516 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013517 },
Johannes Bergb6863032015-10-15 09:25:18 +020013518#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013519 {
13520 .cmd = NL80211_CMD_REQ_SET_REG,
13521 .doit = nl80211_req_set_reg,
13522 .policy = nl80211_policy,
13523 .flags = GENL_ADMIN_PERM,
13524 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013525 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013526 .cmd = NL80211_CMD_RELOAD_REGDB,
13527 .doit = nl80211_reload_regdb,
13528 .policy = nl80211_policy,
13529 .flags = GENL_ADMIN_PERM,
13530 },
13531 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013532 .cmd = NL80211_CMD_GET_MESH_CONFIG,
13533 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013534 .policy = nl80211_policy,
13535 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013537 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013538 },
13539 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013540 .cmd = NL80211_CMD_SET_MESH_CONFIG,
13541 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013542 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013543 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013545 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013546 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013547 {
Johannes Berg2a519312009-02-10 21:25:55 +010013548 .cmd = NL80211_CMD_TRIGGER_SCAN,
13549 .doit = nl80211_trigger_scan,
13550 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013551 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013552 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013553 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013554 },
13555 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013556 .cmd = NL80211_CMD_ABORT_SCAN,
13557 .doit = nl80211_abort_scan,
13558 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013559 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013560 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13561 NL80211_FLAG_NEED_RTNL,
13562 },
13563 {
Johannes Berg2a519312009-02-10 21:25:55 +010013564 .cmd = NL80211_CMD_GET_SCAN,
13565 .policy = nl80211_policy,
13566 .dumpit = nl80211_dump_scan,
13567 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013568 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013569 .cmd = NL80211_CMD_START_SCHED_SCAN,
13570 .doit = nl80211_start_sched_scan,
13571 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013572 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013573 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13574 NL80211_FLAG_NEED_RTNL,
13575 },
13576 {
13577 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
13578 .doit = nl80211_stop_sched_scan,
13579 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013580 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13582 NL80211_FLAG_NEED_RTNL,
13583 },
13584 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013585 .cmd = NL80211_CMD_AUTHENTICATE,
13586 .doit = nl80211_authenticate,
13587 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013590 NL80211_FLAG_NEED_RTNL |
13591 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013592 },
13593 {
13594 .cmd = NL80211_CMD_ASSOCIATE,
13595 .doit = nl80211_associate,
13596 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013597 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013599 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013600 },
13601 {
13602 .cmd = NL80211_CMD_DEAUTHENTICATE,
13603 .doit = nl80211_deauthenticate,
13604 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013605 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013607 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013608 },
13609 {
13610 .cmd = NL80211_CMD_DISASSOCIATE,
13611 .doit = nl80211_disassociate,
13612 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013613 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013615 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013616 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013617 {
13618 .cmd = NL80211_CMD_JOIN_IBSS,
13619 .doit = nl80211_join_ibss,
13620 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013621 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013623 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013624 },
13625 {
13626 .cmd = NL80211_CMD_LEAVE_IBSS,
13627 .doit = nl80211_leave_ibss,
13628 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013629 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013631 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013632 },
Johannes Bergaff89a92009-07-01 21:26:51 +020013633#ifdef CONFIG_NL80211_TESTMODE
13634 {
13635 .cmd = NL80211_CMD_TESTMODE,
13636 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070013637 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020013638 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013639 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013640 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13641 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020013642 },
13643#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020013644 {
13645 .cmd = NL80211_CMD_CONNECT,
13646 .doit = nl80211_connect,
13647 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013648 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013649 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013650 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013651 },
13652 {
vamsi krishna088e8df2016-10-27 16:51:11 +030013653 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
13654 .doit = nl80211_update_connect_params,
13655 .policy = nl80211_policy,
13656 .flags = GENL_ADMIN_PERM,
13657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13658 NL80211_FLAG_NEED_RTNL,
13659 },
13660 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020013661 .cmd = NL80211_CMD_DISCONNECT,
13662 .doit = nl80211_disconnect,
13663 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013664 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013665 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013666 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013667 },
Johannes Berg463d0182009-07-14 00:33:35 +020013668 {
13669 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
13670 .doit = nl80211_wiphy_netns,
13671 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013672 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013673 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13674 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013675 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013676 {
13677 .cmd = NL80211_CMD_GET_SURVEY,
13678 .policy = nl80211_policy,
13679 .dumpit = nl80211_dump_survey,
13680 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013681 {
13682 .cmd = NL80211_CMD_SET_PMKSA,
13683 .doit = nl80211_setdel_pmksa,
13684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013685 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013687 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013688 },
13689 {
13690 .cmd = NL80211_CMD_DEL_PMKSA,
13691 .doit = nl80211_setdel_pmksa,
13692 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013693 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013694 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013695 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013696 },
13697 {
13698 .cmd = NL80211_CMD_FLUSH_PMKSA,
13699 .doit = nl80211_flush_pmksa,
13700 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013701 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013703 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013704 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013705 {
13706 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13707 .doit = nl80211_remain_on_channel,
13708 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013709 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013710 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013711 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013712 },
13713 {
13714 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13715 .doit = nl80211_cancel_remain_on_channel,
13716 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013717 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013718 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013719 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013720 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013721 {
13722 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
13723 .doit = nl80211_set_tx_bitrate_mask,
13724 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013725 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013726 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13727 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013728 },
Jouni Malinen026331c2010-02-15 12:53:10 +020013729 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013730 .cmd = NL80211_CMD_REGISTER_FRAME,
13731 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013732 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013733 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013734 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013735 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013736 },
13737 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013738 .cmd = NL80211_CMD_FRAME,
13739 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013740 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013741 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013742 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013743 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013744 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020013745 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013746 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
13747 .doit = nl80211_tx_mgmt_cancel_wait,
13748 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013749 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013750 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013751 NL80211_FLAG_NEED_RTNL,
13752 },
13753 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020013754 .cmd = NL80211_CMD_SET_POWER_SAVE,
13755 .doit = nl80211_set_power_save,
13756 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013757 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013758 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13759 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013760 },
13761 {
13762 .cmd = NL80211_CMD_GET_POWER_SAVE,
13763 .doit = nl80211_get_power_save,
13764 .policy = nl80211_policy,
13765 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020013766 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13767 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013768 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013769 {
13770 .cmd = NL80211_CMD_SET_CQM,
13771 .doit = nl80211_set_cqm,
13772 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013773 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013774 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13775 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013776 },
Johannes Bergf444de02010-05-05 15:25:02 +020013777 {
13778 .cmd = NL80211_CMD_SET_CHANNEL,
13779 .doit = nl80211_set_channel,
13780 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013781 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013782 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13783 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013784 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013785 {
13786 .cmd = NL80211_CMD_SET_WDS_PEER,
13787 .doit = nl80211_set_wds_peer,
13788 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013789 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013790 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13791 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013792 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013793 {
13794 .cmd = NL80211_CMD_JOIN_MESH,
13795 .doit = nl80211_join_mesh,
13796 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013797 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013798 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13799 NL80211_FLAG_NEED_RTNL,
13800 },
13801 {
13802 .cmd = NL80211_CMD_LEAVE_MESH,
13803 .doit = nl80211_leave_mesh,
13804 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013805 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013806 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13807 NL80211_FLAG_NEED_RTNL,
13808 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013809 {
13810 .cmd = NL80211_CMD_JOIN_OCB,
13811 .doit = nl80211_join_ocb,
13812 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013813 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013814 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13815 NL80211_FLAG_NEED_RTNL,
13816 },
13817 {
13818 .cmd = NL80211_CMD_LEAVE_OCB,
13819 .doit = nl80211_leave_ocb,
13820 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013821 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013822 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13823 NL80211_FLAG_NEED_RTNL,
13824 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013825#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013826 {
13827 .cmd = NL80211_CMD_GET_WOWLAN,
13828 .doit = nl80211_get_wowlan,
13829 .policy = nl80211_policy,
13830 /* can be retrieved by unprivileged users */
13831 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13832 NL80211_FLAG_NEED_RTNL,
13833 },
13834 {
13835 .cmd = NL80211_CMD_SET_WOWLAN,
13836 .doit = nl80211_set_wowlan,
13837 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013838 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013839 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13840 NL80211_FLAG_NEED_RTNL,
13841 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013842#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013843 {
13844 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13845 .doit = nl80211_set_rekey_data,
13846 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013847 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013849 NL80211_FLAG_NEED_RTNL |
13850 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013851 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013852 {
13853 .cmd = NL80211_CMD_TDLS_MGMT,
13854 .doit = nl80211_tdls_mgmt,
13855 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013856 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13858 NL80211_FLAG_NEED_RTNL,
13859 },
13860 {
13861 .cmd = NL80211_CMD_TDLS_OPER,
13862 .doit = nl80211_tdls_oper,
13863 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013864 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13866 NL80211_FLAG_NEED_RTNL,
13867 },
Johannes Berg28946da2011-11-04 11:18:12 +010013868 {
13869 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13870 .doit = nl80211_register_unexpected_frame,
13871 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013872 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013873 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13874 NL80211_FLAG_NEED_RTNL,
13875 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013876 {
13877 .cmd = NL80211_CMD_PROBE_CLIENT,
13878 .doit = nl80211_probe_client,
13879 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013880 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013882 NL80211_FLAG_NEED_RTNL,
13883 },
Johannes Berg5e760232011-11-04 11:18:17 +010013884 {
13885 .cmd = NL80211_CMD_REGISTER_BEACONS,
13886 .doit = nl80211_register_beacons,
13887 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013888 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013889 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13890 NL80211_FLAG_NEED_RTNL,
13891 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013892 {
13893 .cmd = NL80211_CMD_SET_NOACK_MAP,
13894 .doit = nl80211_set_noack_map,
13895 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013896 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13898 NL80211_FLAG_NEED_RTNL,
13899 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013900 {
13901 .cmd = NL80211_CMD_START_P2P_DEVICE,
13902 .doit = nl80211_start_p2p_device,
13903 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013904 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013905 .internal_flags = NL80211_FLAG_NEED_WDEV |
13906 NL80211_FLAG_NEED_RTNL,
13907 },
13908 {
13909 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13910 .doit = nl80211_stop_p2p_device,
13911 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013912 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013913 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13914 NL80211_FLAG_NEED_RTNL,
13915 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013916 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013917 .cmd = NL80211_CMD_START_NAN,
13918 .doit = nl80211_start_nan,
13919 .policy = nl80211_policy,
13920 .flags = GENL_ADMIN_PERM,
13921 .internal_flags = NL80211_FLAG_NEED_WDEV |
13922 NL80211_FLAG_NEED_RTNL,
13923 },
13924 {
13925 .cmd = NL80211_CMD_STOP_NAN,
13926 .doit = nl80211_stop_nan,
13927 .policy = nl80211_policy,
13928 .flags = GENL_ADMIN_PERM,
13929 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13930 NL80211_FLAG_NEED_RTNL,
13931 },
13932 {
Ayala Bekera442b762016-09-20 17:31:15 +030013933 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13934 .doit = nl80211_nan_add_func,
13935 .policy = nl80211_policy,
13936 .flags = GENL_ADMIN_PERM,
13937 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13938 NL80211_FLAG_NEED_RTNL,
13939 },
13940 {
13941 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13942 .doit = nl80211_nan_del_func,
13943 .policy = nl80211_policy,
13944 .flags = GENL_ADMIN_PERM,
13945 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13946 NL80211_FLAG_NEED_RTNL,
13947 },
13948 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013949 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13950 .doit = nl80211_nan_change_config,
13951 .policy = nl80211_policy,
13952 .flags = GENL_ADMIN_PERM,
13953 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13954 NL80211_FLAG_NEED_RTNL,
13955 },
13956 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013957 .cmd = NL80211_CMD_SET_MCAST_RATE,
13958 .doit = nl80211_set_mcast_rate,
13959 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013960 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013961 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13962 NL80211_FLAG_NEED_RTNL,
13963 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013964 {
13965 .cmd = NL80211_CMD_SET_MAC_ACL,
13966 .doit = nl80211_set_mac_acl,
13967 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013968 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013969 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13970 NL80211_FLAG_NEED_RTNL,
13971 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013972 {
13973 .cmd = NL80211_CMD_RADAR_DETECT,
13974 .doit = nl80211_start_radar_detection,
13975 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013976 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013977 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13978 NL80211_FLAG_NEED_RTNL,
13979 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013980 {
13981 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13982 .doit = nl80211_get_protocol_features,
13983 .policy = nl80211_policy,
13984 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013985 {
13986 .cmd = NL80211_CMD_UPDATE_FT_IES,
13987 .doit = nl80211_update_ft_ies,
13988 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013989 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013990 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13991 NL80211_FLAG_NEED_RTNL,
13992 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013993 {
13994 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13995 .doit = nl80211_crit_protocol_start,
13996 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013997 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013998 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13999 NL80211_FLAG_NEED_RTNL,
14000 },
14001 {
14002 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
14003 .doit = nl80211_crit_protocol_stop,
14004 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014005 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014006 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14007 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014008 },
14009 {
14010 .cmd = NL80211_CMD_GET_COALESCE,
14011 .doit = nl80211_get_coalesce,
14012 .policy = nl80211_policy,
14013 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14014 NL80211_FLAG_NEED_RTNL,
14015 },
14016 {
14017 .cmd = NL80211_CMD_SET_COALESCE,
14018 .doit = nl80211_set_coalesce,
14019 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014020 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014021 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14022 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014023 },
14024 {
14025 .cmd = NL80211_CMD_CHANNEL_SWITCH,
14026 .doit = nl80211_channel_switch,
14027 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014028 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14030 NL80211_FLAG_NEED_RTNL,
14031 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014032 {
14033 .cmd = NL80211_CMD_VENDOR,
14034 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014035 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010014036 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014037 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014038 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14039 NL80211_FLAG_NEED_RTNL,
14040 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014041 {
14042 .cmd = NL80211_CMD_SET_QOS_MAP,
14043 .doit = nl80211_set_qos_map,
14044 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014045 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014046 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14047 NL80211_FLAG_NEED_RTNL,
14048 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014049 {
14050 .cmd = NL80211_CMD_ADD_TX_TS,
14051 .doit = nl80211_add_tx_ts,
14052 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014053 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014054 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14055 NL80211_FLAG_NEED_RTNL,
14056 },
14057 {
14058 .cmd = NL80211_CMD_DEL_TX_TS,
14059 .doit = nl80211_del_tx_ts,
14060 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014061 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014062 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14063 NL80211_FLAG_NEED_RTNL,
14064 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014065 {
14066 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
14067 .doit = nl80211_tdls_channel_switch,
14068 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014069 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014070 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14071 NL80211_FLAG_NEED_RTNL,
14072 },
14073 {
14074 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
14075 .doit = nl80211_tdls_cancel_channel_switch,
14076 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014077 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014078 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14079 NL80211_FLAG_NEED_RTNL,
14080 },
Michael Braunce0ce132016-10-10 19:12:22 +020014081 {
14082 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
14083 .doit = nl80211_set_multicast_to_unicast,
14084 .policy = nl80211_policy,
14085 .flags = GENL_UNS_ADMIN_PERM,
14086 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14087 NL80211_FLAG_NEED_RTNL,
14088 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014089 {
14090 .cmd = NL80211_CMD_SET_PMK,
14091 .doit = nl80211_set_pmk,
14092 .policy = nl80211_policy,
14093 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14094 NL80211_FLAG_NEED_RTNL,
14095 },
14096 {
14097 .cmd = NL80211_CMD_DEL_PMK,
14098 .doit = nl80211_del_pmk,
14099 .policy = nl80211_policy,
14100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14101 NL80211_FLAG_NEED_RTNL,
14102 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014103 {
14104 .cmd = NL80211_CMD_EXTERNAL_AUTH,
14105 .doit = nl80211_external_auth,
14106 .policy = nl80211_policy,
14107 .flags = GENL_ADMIN_PERM,
14108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14109 NL80211_FLAG_NEED_RTNL,
14110 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014111 {
14112 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
14113 .doit = nl80211_tx_control_port,
14114 .policy = nl80211_policy,
14115 .flags = GENL_UNS_ADMIN_PERM,
14116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14117 NL80211_FLAG_NEED_RTNL,
14118 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014119 {
14120 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
14121 .doit = nl80211_get_ftm_responder_stats,
14122 .policy = nl80211_policy,
14123 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14124 NL80211_FLAG_NEED_RTNL,
14125 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020014126 {
14127 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
14128 .doit = nl80211_pmsr_start,
14129 .policy = nl80211_policy,
14130 .flags = GENL_UNS_ADMIN_PERM,
14131 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14132 NL80211_FLAG_NEED_RTNL,
14133 },
Sriram R30c63112018-12-04 17:46:52 +053014134 {
14135 .cmd = NL80211_CMD_NOTIFY_RADAR,
14136 .doit = nl80211_notify_radar_detection,
14137 .policy = nl80211_policy,
14138 .flags = GENL_UNS_ADMIN_PERM,
14139 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14140 NL80211_FLAG_NEED_RTNL,
14141 },
Johannes Berg55682962007-09-20 13:09:35 -040014142};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014143
Johannes Berg56989f62016-10-24 14:40:05 +020014144static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020014145 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14146 .hdrsize = 0, /* no private header */
14147 .version = 1, /* no particular meaning now */
14148 .maxattr = NL80211_ATTR_MAX,
14149 .netnsok = true,
14150 .pre_doit = nl80211_pre_doit,
14151 .post_doit = nl80211_post_doit,
14152 .module = THIS_MODULE,
14153 .ops = nl80211_ops,
14154 .n_ops = ARRAY_SIZE(nl80211_ops),
14155 .mcgrps = nl80211_mcgrps,
14156 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
14157};
14158
Johannes Berg55682962007-09-20 13:09:35 -040014159/* notification functions */
14160
Johannes Berg3bb20552014-05-26 13:52:25 +020014161void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14162 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040014163{
14164 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020014165 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040014166
Johannes Berg3bb20552014-05-26 13:52:25 +020014167 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14168 cmd != NL80211_CMD_DEL_WIPHY);
14169
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014171 if (!msg)
14172 return;
14173
Johannes Berg3bb20552014-05-26 13:52:25 +020014174 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040014175 nlmsg_free(msg);
14176 return;
14177 }
14178
Johannes Berg68eb5502013-11-19 15:19:38 +010014179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014180 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040014181}
14182
Denis Kenzior896ff062016-08-03 16:58:33 -050014183void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14184 struct wireless_dev *wdev,
14185 enum nl80211_commands cmd)
14186{
14187 struct sk_buff *msg;
14188
Denis Kenzior896ff062016-08-03 16:58:33 -050014189 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14190 if (!msg)
14191 return;
14192
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020014193 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050014194 nlmsg_free(msg);
14195 return;
14196 }
14197
14198 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14199 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14200}
14201
Johannes Berg362a4152009-05-24 16:43:15 +020014202static int nl80211_add_scan_req(struct sk_buff *msg,
14203 struct cfg80211_registered_device *rdev)
14204{
14205 struct cfg80211_scan_request *req = rdev->scan_req;
14206 struct nlattr *nest;
14207 int i;
14208
14209 if (WARN_ON(!req))
14210 return 0;
14211
14212 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
14213 if (!nest)
14214 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014215 for (i = 0; i < req->n_ssids; i++) {
14216 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14217 goto nla_put_failure;
14218 }
Johannes Berg362a4152009-05-24 16:43:15 +020014219 nla_nest_end(msg, nest);
14220
14221 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
14222 if (!nest)
14223 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040014224 for (i = 0; i < req->n_channels; i++) {
14225 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14226 goto nla_put_failure;
14227 }
Johannes Berg362a4152009-05-24 16:43:15 +020014228 nla_nest_end(msg, nest);
14229
David S. Miller9360ffd2012-03-29 04:41:26 -040014230 if (req->ie &&
14231 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14232 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014233
Johannes Bergae917c92013-10-25 11:05:22 +020014234 if (req->flags &&
14235 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14236 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014237
Avraham Stern1d762502016-07-05 17:10:13 +030014238 if (req->info.scan_start_tsf &&
14239 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14240 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14241 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14242 req->info.tsf_bssid)))
14243 goto nla_put_failure;
14244
Johannes Berg362a4152009-05-24 16:43:15 +020014245 return 0;
14246 nla_put_failure:
14247 return -ENOBUFS;
14248}
14249
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014250static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014251 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014252 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014253 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014254 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014255{
14256 void *hdr;
14257
Eric W. Biederman15e47302012-09-07 20:12:54 +000014258 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014259 if (!hdr)
14260 return -1;
14261
David S. Miller9360ffd2012-03-29 04:41:26 -040014262 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014263 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14264 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014265 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14266 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014267 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014268
Johannes Berg362a4152009-05-24 16:43:15 +020014269 /* ignore errors and send incomplete event anyway */
14270 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014271
Johannes Berg053c0952015-01-16 22:09:00 +010014272 genlmsg_end(msg, hdr);
14273 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014274
14275 nla_put_failure:
14276 genlmsg_cancel(msg, hdr);
14277 return -EMSGSIZE;
14278}
14279
Luciano Coelho807f8a82011-05-11 17:09:35 +030014280static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014281nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014282 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014283{
14284 void *hdr;
14285
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014286 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014287 if (!hdr)
14288 return -1;
14289
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14291 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14292 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14293 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14294 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014295 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014296
Johannes Berg053c0952015-01-16 22:09:00 +010014297 genlmsg_end(msg, hdr);
14298 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014299
14300 nla_put_failure:
14301 genlmsg_cancel(msg, hdr);
14302 return -EMSGSIZE;
14303}
14304
Johannes Berga538e2d2009-06-16 19:56:42 +020014305void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014306 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014307{
14308 struct sk_buff *msg;
14309
Thomas Graf58050fc2012-06-28 03:57:45 +000014310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014311 if (!msg)
14312 return;
14313
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014314 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014315 NL80211_CMD_TRIGGER_SCAN) < 0) {
14316 nlmsg_free(msg);
14317 return;
14318 }
14319
Johannes Berg68eb5502013-11-19 15:19:38 +010014320 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014321 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014322}
14323
Johannes Bergf9d15d12014-01-22 11:14:19 +020014324struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14325 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014326{
14327 struct sk_buff *msg;
14328
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014330 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014331 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014332
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014333 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014334 aborted ? NL80211_CMD_SCAN_ABORTED :
14335 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014336 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014337 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014338 }
14339
Johannes Bergf9d15d12014-01-22 11:14:19 +020014340 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014341}
14342
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014343/* send message created by nl80211_build_scan_msg() */
14344void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14345 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014346{
Johannes Berg2a519312009-02-10 21:25:55 +010014347 if (!msg)
14348 return;
14349
Johannes Berg68eb5502013-11-19 15:19:38 +010014350 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014351 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014352}
14353
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014354void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014355{
14356 struct sk_buff *msg;
14357
Thomas Graf58050fc2012-06-28 03:57:45 +000014358 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014359 if (!msg)
14360 return;
14361
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014362 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014363 nlmsg_free(msg);
14364 return;
14365 }
14366
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014367 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014368 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014369}
14370
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014371static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14372 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014373{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014374 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014375 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14376 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014377
David S. Miller9360ffd2012-03-29 04:41:26 -040014378 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14379 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14380 NL80211_REGDOM_TYPE_WORLD))
14381 goto nla_put_failure;
14382 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14383 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14384 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14385 goto nla_put_failure;
14386 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14387 request->intersect) {
14388 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14389 NL80211_REGDOM_TYPE_INTERSECTION))
14390 goto nla_put_failure;
14391 } else {
14392 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14393 NL80211_REGDOM_TYPE_COUNTRY) ||
14394 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14395 request->alpha2))
14396 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014397 }
14398
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014399 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14400 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14401
14402 if (wiphy &&
14403 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14404 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014405
14406 if (wiphy &&
14407 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14408 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14409 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014410 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014411
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014412 return true;
14413
14414nla_put_failure:
14415 return false;
14416}
14417
14418/*
14419 * This can happen on global regulatory changes or device specific settings
14420 * based on custom regulatory domains.
14421 */
14422void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14423 struct regulatory_request *request)
14424{
14425 struct sk_buff *msg;
14426 void *hdr;
14427
14428 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14429 if (!msg)
14430 return;
14431
14432 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14433 if (!hdr) {
14434 nlmsg_free(msg);
14435 return;
14436 }
14437
14438 if (nl80211_reg_change_event_fill(msg, request) == false)
14439 goto nla_put_failure;
14440
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014441 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014442
Johannes Bergbc43b282009-07-25 10:54:13 +020014443 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014444 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014445 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014446 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014447
14448 return;
14449
14450nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014451 nlmsg_free(msg);
14452}
14453
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014454static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14455 struct net_device *netdev,
14456 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014457 enum nl80211_commands cmd, gfp_t gfp,
14458 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014459{
14460 struct sk_buff *msg;
14461 void *hdr;
14462
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014463 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014464 if (!msg)
14465 return;
14466
14467 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14468 if (!hdr) {
14469 nlmsg_free(msg);
14470 return;
14471 }
14472
David S. Miller9360ffd2012-03-29 04:41:26 -040014473 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14475 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
14476 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014477
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014478 if (uapsd_queues >= 0) {
14479 struct nlattr *nla_wmm =
14480 nla_nest_start(msg, NL80211_ATTR_STA_WME);
14481 if (!nla_wmm)
14482 goto nla_put_failure;
14483
14484 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14485 uapsd_queues))
14486 goto nla_put_failure;
14487
14488 nla_nest_end(msg, nla_wmm);
14489 }
14490
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014491 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014492
Johannes Berg68eb5502013-11-19 15:19:38 +010014493 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014494 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014495 return;
14496
14497 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014498 nlmsg_free(msg);
14499}
14500
14501void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014502 struct net_device *netdev, const u8 *buf,
14503 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014504{
14505 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014506 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014507}
14508
14509void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14510 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014511 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014512{
Johannes Berge6d6e342009-07-01 21:26:47 +020014513 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014514 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014515}
14516
Jouni Malinen53b46b82009-03-27 20:53:56 +020014517void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014518 struct net_device *netdev, const u8 *buf,
14519 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014520{
14521 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014522 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014523}
14524
Jouni Malinen53b46b82009-03-27 20:53:56 +020014525void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14526 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014527 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014528{
14529 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014530 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014531}
14532
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014533void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14534 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014535{
Johannes Berg947add32013-02-22 22:05:20 +010014536 struct wireless_dev *wdev = dev->ieee80211_ptr;
14537 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014538 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014539 const struct ieee80211_mgmt *mgmt = (void *)buf;
14540 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014541
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014542 if (WARN_ON(len < 2))
14543 return;
14544
14545 if (ieee80211_is_deauth(mgmt->frame_control))
14546 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14547 else
14548 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14549
14550 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014551 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014552}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014553EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014554
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014555static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14556 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014557 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014558{
14559 struct sk_buff *msg;
14560 void *hdr;
14561
Johannes Berge6d6e342009-07-01 21:26:47 +020014562 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014563 if (!msg)
14564 return;
14565
14566 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14567 if (!hdr) {
14568 nlmsg_free(msg);
14569 return;
14570 }
14571
David S. Miller9360ffd2012-03-29 04:41:26 -040014572 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14573 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14574 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14575 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14576 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014577
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014578 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014579
Johannes Berg68eb5502013-11-19 15:19:38 +010014580 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014581 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014582 return;
14583
14584 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014585 nlmsg_free(msg);
14586}
14587
14588void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014589 struct net_device *netdev, const u8 *addr,
14590 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014591{
14592 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014593 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014594}
14595
14596void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014597 struct net_device *netdev, const u8 *addr,
14598 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014599{
Johannes Berge6d6e342009-07-01 21:26:47 +020014600 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14601 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014602}
14603
Samuel Ortizb23aa672009-07-01 21:26:54 +020014604void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014605 struct net_device *netdev,
14606 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014607 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014608{
14609 struct sk_buff *msg;
14610 void *hdr;
14611
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014612 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020014613 cr->fils.kek_len + cr->fils.pmk_len +
14614 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014615 if (!msg)
14616 return;
14617
14618 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
14619 if (!hdr) {
14620 nlmsg_free(msg);
14621 return;
14622 }
14623
David S. Miller9360ffd2012-03-29 04:41:26 -040014624 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14625 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014626 (cr->bssid &&
14627 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030014628 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014629 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
14630 cr->status) ||
14631 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014632 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014633 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
14634 cr->timeout_reason))) ||
14635 (cr->req_ie &&
14636 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
14637 (cr->resp_ie &&
14638 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014639 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020014640 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014641 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020014642 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014643 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020014644 ((cr->fils.kek &&
14645 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
14646 cr->fils.kek)) ||
14647 (cr->fils.pmk &&
14648 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
14649 (cr->fils.pmkid &&
14650 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040014651 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014652
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014653 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014654
Johannes Berg68eb5502013-11-19 15:19:38 +010014655 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014656 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014657 return;
14658
14659 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014660 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014661}
14662
14663void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014664 struct net_device *netdev,
14665 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014666{
14667 struct sk_buff *msg;
14668 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014669 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014670
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014671 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
14672 info->fils.kek_len + info->fils.pmk_len +
14673 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014674 if (!msg)
14675 return;
14676
14677 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
14678 if (!hdr) {
14679 nlmsg_free(msg);
14680 return;
14681 }
14682
David S. Miller9360ffd2012-03-29 04:41:26 -040014683 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14684 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14685 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014686 (info->req_ie &&
14687 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
14688 info->req_ie)) ||
14689 (info->resp_ie &&
14690 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014691 info->resp_ie)) ||
14692 (info->fils.update_erp_next_seq_num &&
14693 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
14694 info->fils.erp_next_seq_num)) ||
14695 (info->fils.kek &&
14696 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
14697 info->fils.kek)) ||
14698 (info->fils.pmk &&
14699 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
14700 (info->fils.pmkid &&
14701 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014702 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014703
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014704 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014705
Johannes Berg68eb5502013-11-19 15:19:38 +010014706 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014707 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014708 return;
14709
14710 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014711 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014712}
14713
Avraham Stern503c1fb2017-09-29 14:21:49 +020014714void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
14715 struct net_device *netdev, const u8 *bssid)
14716{
14717 struct sk_buff *msg;
14718 void *hdr;
14719
14720 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14721 if (!msg)
14722 return;
14723
14724 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
14725 if (!hdr) {
14726 nlmsg_free(msg);
14727 return;
14728 }
14729
14730 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14731 goto nla_put_failure;
14732
14733 genlmsg_end(msg, hdr);
14734
14735 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14736 NL80211_MCGRP_MLME, GFP_KERNEL);
14737 return;
14738
14739 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020014740 nlmsg_free(msg);
14741}
14742
Samuel Ortizb23aa672009-07-01 21:26:54 +020014743void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
14744 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020014745 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014746{
14747 struct sk_buff *msg;
14748 void *hdr;
14749
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014750 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014751 if (!msg)
14752 return;
14753
14754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
14755 if (!hdr) {
14756 nlmsg_free(msg);
14757 return;
14758 }
14759
David S. Miller9360ffd2012-03-29 04:41:26 -040014760 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020014762 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040014763 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
14764 (from_ap &&
14765 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
14766 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
14767 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014768
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014769 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014770
Johannes Berg68eb5502013-11-19 15:19:38 +010014771 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014772 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014773 return;
14774
14775 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014776 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014777}
14778
Johannes Berg04a773a2009-04-19 21:24:32 +020014779void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
14780 struct net_device *netdev, const u8 *bssid,
14781 gfp_t gfp)
14782{
14783 struct sk_buff *msg;
14784 void *hdr;
14785
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014786 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014787 if (!msg)
14788 return;
14789
14790 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
14791 if (!hdr) {
14792 nlmsg_free(msg);
14793 return;
14794 }
14795
David S. Miller9360ffd2012-03-29 04:41:26 -040014796 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14797 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14798 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14799 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020014800
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014801 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020014802
Johannes Berg68eb5502013-11-19 15:19:38 +010014803 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014804 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014805 return;
14806
14807 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020014808 nlmsg_free(msg);
14809}
14810
Johannes Berg947add32013-02-22 22:05:20 +010014811void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040014812 const u8 *ie, u8 ie_len,
14813 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070014814{
Johannes Berg947add32013-02-22 22:05:20 +010014815 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014816 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014817 struct sk_buff *msg;
14818 void *hdr;
14819
Johannes Berg947add32013-02-22 22:05:20 +010014820 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14821 return;
14822
14823 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14824
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014825 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014826 if (!msg)
14827 return;
14828
14829 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14830 if (!hdr) {
14831 nlmsg_free(msg);
14832 return;
14833 }
14834
David S. Miller9360ffd2012-03-29 04:41:26 -040014835 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014836 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14837 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014838 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040014839 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
14840 (sig_dbm &&
14841 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014842 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014843
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014844 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014845
Johannes Berg68eb5502013-11-19 15:19:38 +010014846 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014847 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014848 return;
14849
14850 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070014851 nlmsg_free(msg);
14852}
Johannes Berg947add32013-02-22 22:05:20 +010014853EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014854
Jouni Malinena3b8b052009-03-27 21:59:49 +020014855void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14856 struct net_device *netdev, const u8 *addr,
14857 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014858 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014859{
14860 struct sk_buff *msg;
14861 void *hdr;
14862
Johannes Berge6d6e342009-07-01 21:26:47 +020014863 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014864 if (!msg)
14865 return;
14866
14867 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14868 if (!hdr) {
14869 nlmsg_free(msg);
14870 return;
14871 }
14872
David S. Miller9360ffd2012-03-29 04:41:26 -040014873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14875 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14876 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14877 (key_id != -1 &&
14878 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14879 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14880 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014881
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014882 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014883
Johannes Berg68eb5502013-11-19 15:19:38 +010014884 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014885 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014886 return;
14887
14888 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020014889 nlmsg_free(msg);
14890}
14891
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014892void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14893 struct ieee80211_channel *channel_before,
14894 struct ieee80211_channel *channel_after)
14895{
14896 struct sk_buff *msg;
14897 void *hdr;
14898 struct nlattr *nl_freq;
14899
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014901 if (!msg)
14902 return;
14903
14904 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14905 if (!hdr) {
14906 nlmsg_free(msg);
14907 return;
14908 }
14909
14910 /*
14911 * Since we are applying the beacon hint to a wiphy we know its
14912 * wiphy_idx is valid
14913 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14915 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014916
14917 /* Before */
14918 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14919 if (!nl_freq)
14920 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014921
14922 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014923 goto nla_put_failure;
14924 nla_nest_end(msg, nl_freq);
14925
14926 /* After */
14927 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14928 if (!nl_freq)
14929 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014930
14931 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014932 goto nla_put_failure;
14933 nla_nest_end(msg, nl_freq);
14934
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014935 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014936
Johannes Berg463d0182009-07-14 00:33:35 +020014937 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014938 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014939 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014940 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014941
14942 return;
14943
14944nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014945 nlmsg_free(msg);
14946}
14947
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014948static void nl80211_send_remain_on_chan_event(
14949 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014950 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014951 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014952 unsigned int duration, gfp_t gfp)
14953{
14954 struct sk_buff *msg;
14955 void *hdr;
14956
14957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14958 if (!msg)
14959 return;
14960
14961 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14962 if (!hdr) {
14963 nlmsg_free(msg);
14964 return;
14965 }
14966
David S. Miller9360ffd2012-03-29 04:41:26 -040014967 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014968 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14969 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014970 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14971 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014972 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014973 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14974 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014975 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14976 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014977 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014978
David S. Miller9360ffd2012-03-29 04:41:26 -040014979 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14980 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14981 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014982
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014983 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014984
Johannes Berg68eb5502013-11-19 15:19:38 +010014985 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014986 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014987 return;
14988
14989 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014990 nlmsg_free(msg);
14991}
14992
Johannes Berg947add32013-02-22 22:05:20 +010014993void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14994 struct ieee80211_channel *chan,
14995 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014996{
Johannes Berg947add32013-02-22 22:05:20 +010014997 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014998 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014999
15000 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015001 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015002 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015003 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015004}
Johannes Berg947add32013-02-22 22:05:20 +010015005EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015006
Johannes Berg947add32013-02-22 22:05:20 +010015007void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15008 struct ieee80211_channel *chan,
15009 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015010{
Johannes Berg947add32013-02-22 22:05:20 +010015011 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015012 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015013
15014 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015015 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015016 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015017}
Johannes Berg947add32013-02-22 22:05:20 +010015018EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015019
Johannes Berg947add32013-02-22 22:05:20 +010015020void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15021 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015022{
Johannes Berg947add32013-02-22 22:05:20 +010015023 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015024 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015025 struct sk_buff *msg;
15026
Johannes Berg947add32013-02-22 22:05:20 +010015027 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15028
Thomas Graf58050fc2012-06-28 03:57:45 +000015029 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015030 if (!msg)
15031 return;
15032
Johannes Bergcf5ead82014-11-14 17:14:00 +010015033 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015034 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015035 nlmsg_free(msg);
15036 return;
15037 }
15038
Johannes Berg68eb5502013-11-19 15:19:38 +010015039 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015040 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015041}
Johannes Berg947add32013-02-22 22:05:20 +010015042EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015043
Johannes Bergcf5ead82014-11-14 17:14:00 +010015044void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15045 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015046{
Johannes Berg947add32013-02-22 22:05:20 +010015047 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015048 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015049 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015050 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015051
Johannes Berg73887fd2018-05-18 09:57:55 +020015052 if (!sinfo)
15053 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015054
Johannes Berg947add32013-02-22 22:05:20 +010015055 trace_cfg80211_del_sta(dev, mac_addr);
15056
Thomas Graf58050fc2012-06-28 03:57:45 +000015057 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015058 if (!msg) {
15059 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015060 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015061 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015062
Johannes Bergcf5ead82014-11-14 17:14:00 +010015063 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015064 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015065 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015066 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015067 }
15068
Johannes Berg68eb5502013-11-19 15:19:38 +010015069 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015070 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020015071}
Johannes Bergcf5ead82014-11-14 17:14:00 +010015072EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020015073
Johannes Berg947add32013-02-22 22:05:20 +010015074void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15075 enum nl80211_connect_failed_reason reason,
15076 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015077{
Johannes Berg947add32013-02-22 22:05:20 +010015078 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015079 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015080 struct sk_buff *msg;
15081 void *hdr;
15082
15083 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15084 if (!msg)
15085 return;
15086
15087 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15088 if (!hdr) {
15089 nlmsg_free(msg);
15090 return;
15091 }
15092
15093 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15094 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15095 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15096 goto nla_put_failure;
15097
15098 genlmsg_end(msg, hdr);
15099
Johannes Berg68eb5502013-11-19 15:19:38 +010015100 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015101 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015102 return;
15103
15104 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015105 nlmsg_free(msg);
15106}
Johannes Berg947add32013-02-22 22:05:20 +010015107EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053015108
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015109static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15110 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010015111{
15112 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015113 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010015114 struct sk_buff *msg;
15115 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070015116 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015117
Eric W. Biederman15e47302012-09-07 20:12:54 +000015118 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010015119 return false;
15120
15121 msg = nlmsg_new(100, gfp);
15122 if (!msg)
15123 return true;
15124
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015125 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010015126 if (!hdr) {
15127 nlmsg_free(msg);
15128 return true;
15129 }
15130
David S. Miller9360ffd2012-03-29 04:41:26 -040015131 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15132 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15133 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15134 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010015135
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015136 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000015137 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010015138 return true;
15139
15140 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010015141 nlmsg_free(msg);
15142 return true;
15143}
15144
Johannes Berg947add32013-02-22 22:05:20 +010015145bool cfg80211_rx_spurious_frame(struct net_device *dev,
15146 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015147{
Johannes Berg947add32013-02-22 22:05:20 +010015148 struct wireless_dev *wdev = dev->ieee80211_ptr;
15149 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015150
Johannes Berg947add32013-02-22 22:05:20 +010015151 trace_cfg80211_rx_spurious_frame(dev, addr);
15152
15153 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15154 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15155 trace_cfg80211_return_bool(false);
15156 return false;
15157 }
15158 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15159 addr, gfp);
15160 trace_cfg80211_return_bool(ret);
15161 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015162}
Johannes Berg947add32013-02-22 22:05:20 +010015163EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15164
15165bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15166 const u8 *addr, gfp_t gfp)
15167{
15168 struct wireless_dev *wdev = dev->ieee80211_ptr;
15169 bool ret;
15170
15171 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15172
15173 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15174 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15175 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15176 trace_cfg80211_return_bool(false);
15177 return false;
15178 }
15179 ret = __nl80211_unexpected_frame(dev,
15180 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15181 addr, gfp);
15182 trace_cfg80211_return_bool(ret);
15183 return ret;
15184}
15185EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010015186
Johannes Berg2e161f782010-08-12 15:38:38 +020015187int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015188 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010015189 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015190 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015191{
Johannes Berg71bbc992012-06-15 15:30:18 +020015192 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015193 struct sk_buff *msg;
15194 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020015195
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015196 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015197 if (!msg)
15198 return -ENOMEM;
15199
Johannes Berg2e161f782010-08-12 15:38:38 +020015200 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020015201 if (!hdr) {
15202 nlmsg_free(msg);
15203 return -ENOMEM;
15204 }
15205
David S. Miller9360ffd2012-03-29 04:41:26 -040015206 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015207 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15208 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015209 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15210 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015211 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15212 (sig_dbm &&
15213 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030015214 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15215 (flags &&
15216 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015217 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015218
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015219 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015220
Eric W. Biederman15e47302012-09-07 20:12:54 +000015221 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020015222
15223 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015224 nlmsg_free(msg);
15225 return -ENOBUFS;
15226}
15227
Johannes Berg947add32013-02-22 22:05:20 +010015228void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15229 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020015230{
Johannes Berg947add32013-02-22 22:05:20 +010015231 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015233 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015234 struct sk_buff *msg;
15235 void *hdr;
15236
Johannes Berg947add32013-02-22 22:05:20 +010015237 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15238
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015239 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015240 if (!msg)
15241 return;
15242
Johannes Berg2e161f782010-08-12 15:38:38 +020015243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015244 if (!hdr) {
15245 nlmsg_free(msg);
15246 return;
15247 }
15248
David S. Miller9360ffd2012-03-29 04:41:26 -040015249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015250 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15251 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015252 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15253 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015254 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015255 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15256 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015257 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15258 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015259
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015260 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015261
Johannes Berg68eb5502013-11-19 15:19:38 +010015262 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015263 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015264 return;
15265
15266 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015267 nlmsg_free(msg);
15268}
Johannes Berg947add32013-02-22 22:05:20 +010015269EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015270
Denis Kenzior6a671a52018-03-26 12:52:41 -050015271static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015272 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050015273 bool unencrypted, gfp_t gfp)
15274{
15275 struct wireless_dev *wdev = dev->ieee80211_ptr;
15276 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050015277 struct ethhdr *ehdr = eth_hdr(skb);
15278 const u8 *addr = ehdr->h_source;
15279 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015280 struct sk_buff *msg;
15281 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050015282 struct nlattr *frame;
15283
Denis Kenzior6a671a52018-03-26 12:52:41 -050015284 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15285
15286 if (!nlportid)
15287 return -ENOENT;
15288
Denis Kenziora948f712018-07-03 15:05:48 -050015289 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015290 if (!msg)
15291 return -ENOMEM;
15292
15293 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15294 if (!hdr) {
15295 nlmsg_free(msg);
15296 return -ENOBUFS;
15297 }
15298
15299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15300 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15301 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15302 NL80211_ATTR_PAD) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050015303 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15304 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15305 (unencrypted && nla_put_flag(msg,
15306 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15307 goto nla_put_failure;
15308
Denis Kenziora948f712018-07-03 15:05:48 -050015309 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15310 if (!frame)
15311 goto nla_put_failure;
15312
15313 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015314 genlmsg_end(msg, hdr);
15315
15316 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15317
15318 nla_put_failure:
15319 nlmsg_free(msg);
15320 return -ENOBUFS;
15321}
15322
15323bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050015324 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050015325{
15326 int ret;
15327
Denis Kenziora948f712018-07-03 15:05:48 -050015328 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15329 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050015330 trace_cfg80211_return_bool(ret == 0);
15331 return ret == 0;
15332}
15333EXPORT_SYMBOL(cfg80211_rx_control_port);
15334
Johannes Berg5b97f492014-11-26 12:37:43 +010015335static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15336 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015337{
Johannes Berg947add32013-02-22 22:05:20 +010015338 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015339 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15340 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15341 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015342
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015343 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015344 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015345
Johannes Berg5b97f492014-11-26 12:37:43 +010015346 cb = (void **)msg->cb;
15347
15348 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15349 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015350 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015351 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015352 }
15353
David S. Miller9360ffd2012-03-29 04:41:26 -040015354 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015355 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015356 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015357
Johannes Berg5b97f492014-11-26 12:37:43 +010015358 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015359 goto nla_put_failure;
15360
Johannes Berg5b97f492014-11-26 12:37:43 +010015361 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
15362 if (!cb[1])
15363 goto nla_put_failure;
15364
15365 cb[2] = rdev;
15366
15367 return msg;
15368 nla_put_failure:
15369 nlmsg_free(msg);
15370 return NULL;
15371}
15372
15373static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15374{
15375 void **cb = (void **)msg->cb;
15376 struct cfg80211_registered_device *rdev = cb[2];
15377
15378 nla_nest_end(msg, cb[1]);
15379 genlmsg_end(msg, cb[0]);
15380
15381 memset(msg->cb, 0, sizeof(msg->cb));
15382
15383 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15384 NL80211_MCGRP_MLME, gfp);
15385}
15386
15387void cfg80211_cqm_rssi_notify(struct net_device *dev,
15388 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015389 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015390{
15391 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015392 struct wireless_dev *wdev = dev->ieee80211_ptr;
15393 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015394
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015395 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015396
Johannes Berg98f03342014-11-26 12:42:02 +010015397 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15398 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15399 return;
15400
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015401 if (wdev->cqm_config) {
15402 wdev->cqm_config->last_rssi_event_value = rssi_level;
15403
15404 cfg80211_cqm_rssi_update(rdev, dev);
15405
15406 if (rssi_level == 0)
15407 rssi_level = wdev->cqm_config->last_rssi_event_value;
15408 }
15409
Johannes Berg5b97f492014-11-26 12:37:43 +010015410 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15411 if (!msg)
15412 return;
15413
David S. Miller9360ffd2012-03-29 04:41:26 -040015414 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15415 rssi_event))
15416 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015417
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015418 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15419 rssi_level))
15420 goto nla_put_failure;
15421
Johannes Berg5b97f492014-11-26 12:37:43 +010015422 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015423
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015424 return;
15425
15426 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015427 nlmsg_free(msg);
15428}
Johannes Berg947add32013-02-22 22:05:20 +010015429EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015430
Johannes Berg5b97f492014-11-26 12:37:43 +010015431void cfg80211_cqm_txe_notify(struct net_device *dev,
15432 const u8 *peer, u32 num_packets,
15433 u32 rate, u32 intvl, gfp_t gfp)
15434{
15435 struct sk_buff *msg;
15436
15437 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15438 if (!msg)
15439 return;
15440
15441 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15442 goto nla_put_failure;
15443
15444 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15445 goto nla_put_failure;
15446
15447 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15448 goto nla_put_failure;
15449
15450 cfg80211_send_cqm(msg, gfp);
15451 return;
15452
15453 nla_put_failure:
15454 nlmsg_free(msg);
15455}
15456EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15457
15458void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15459 const u8 *peer, u32 num_packets, gfp_t gfp)
15460{
15461 struct sk_buff *msg;
15462
15463 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15464
15465 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15466 if (!msg)
15467 return;
15468
15469 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15470 goto nla_put_failure;
15471
15472 cfg80211_send_cqm(msg, gfp);
15473 return;
15474
15475 nla_put_failure:
15476 nlmsg_free(msg);
15477}
15478EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15479
Johannes Berg98f03342014-11-26 12:42:02 +010015480void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15481{
15482 struct sk_buff *msg;
15483
15484 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15485 if (!msg)
15486 return;
15487
15488 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15489 goto nla_put_failure;
15490
15491 cfg80211_send_cqm(msg, gfp);
15492 return;
15493
15494 nla_put_failure:
15495 nlmsg_free(msg);
15496}
15497EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15498
Johannes Berg947add32013-02-22 22:05:20 +010015499static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15500 struct net_device *netdev, const u8 *bssid,
15501 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015502{
15503 struct sk_buff *msg;
15504 struct nlattr *rekey_attr;
15505 void *hdr;
15506
Thomas Graf58050fc2012-06-28 03:57:45 +000015507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015508 if (!msg)
15509 return;
15510
15511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15512 if (!hdr) {
15513 nlmsg_free(msg);
15514 return;
15515 }
15516
David S. Miller9360ffd2012-03-29 04:41:26 -040015517 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15518 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15519 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15520 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015521
15522 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
15523 if (!rekey_attr)
15524 goto nla_put_failure;
15525
David S. Miller9360ffd2012-03-29 04:41:26 -040015526 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15527 NL80211_REPLAY_CTR_LEN, replay_ctr))
15528 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015529
15530 nla_nest_end(msg, rekey_attr);
15531
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015532 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015533
Johannes Berg68eb5502013-11-19 15:19:38 +010015534 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015535 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015536 return;
15537
15538 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015539 nlmsg_free(msg);
15540}
15541
Johannes Berg947add32013-02-22 22:05:20 +010015542void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15543 const u8 *replay_ctr, gfp_t gfp)
15544{
15545 struct wireless_dev *wdev = dev->ieee80211_ptr;
15546 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015547 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015548
15549 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15550 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15551}
15552EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15553
15554static void
15555nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15556 struct net_device *netdev, int index,
15557 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015558{
15559 struct sk_buff *msg;
15560 struct nlattr *attr;
15561 void *hdr;
15562
Thomas Graf58050fc2012-06-28 03:57:45 +000015563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015564 if (!msg)
15565 return;
15566
15567 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15568 if (!hdr) {
15569 nlmsg_free(msg);
15570 return;
15571 }
15572
David S. Miller9360ffd2012-03-29 04:41:26 -040015573 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15574 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15575 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015576
15577 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
15578 if (!attr)
15579 goto nla_put_failure;
15580
David S. Miller9360ffd2012-03-29 04:41:26 -040015581 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15582 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15583 (preauth &&
15584 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15585 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015586
15587 nla_nest_end(msg, attr);
15588
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015589 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015590
Johannes Berg68eb5502013-11-19 15:19:38 +010015591 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015592 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015593 return;
15594
15595 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015596 nlmsg_free(msg);
15597}
15598
Johannes Berg947add32013-02-22 22:05:20 +010015599void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
15600 const u8 *bssid, bool preauth, gfp_t gfp)
15601{
15602 struct wireless_dev *wdev = dev->ieee80211_ptr;
15603 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015604 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015605
15606 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
15607 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
15608}
15609EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
15610
15611static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
15612 struct net_device *netdev,
15613 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020015614 gfp_t gfp,
15615 enum nl80211_commands notif,
15616 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070015617{
15618 struct sk_buff *msg;
15619 void *hdr;
15620
Thomas Graf58050fc2012-06-28 03:57:45 +000015621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015622 if (!msg)
15623 return;
15624
Luciano Coelhof8d75522014-11-07 14:31:35 +020015625 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070015626 if (!hdr) {
15627 nlmsg_free(msg);
15628 return;
15629 }
15630
Johannes Berg683b6d32012-11-08 21:25:48 +010015631 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15632 goto nla_put_failure;
15633
15634 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040015635 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070015636
Luciano Coelhof8d75522014-11-07 14:31:35 +020015637 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
15638 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
15639 goto nla_put_failure;
15640
Thomas Pedersen53145262012-04-06 13:35:47 -070015641 genlmsg_end(msg, hdr);
15642
Johannes Berg68eb5502013-11-19 15:19:38 +010015643 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015644 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015645 return;
15646
15647 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070015648 nlmsg_free(msg);
15649}
15650
Johannes Berg947add32013-02-22 22:05:20 +010015651void cfg80211_ch_switch_notify(struct net_device *dev,
15652 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070015653{
Johannes Berg947add32013-02-22 22:05:20 +010015654 struct wireless_dev *wdev = dev->ieee80211_ptr;
15655 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015656 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015657
Simon Wunderliche487eae2013-11-21 18:19:51 +010015658 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010015659
Simon Wunderliche487eae2013-11-21 18:19:51 +010015660 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010015661
Michal Kazior9e0e2962014-01-29 14:22:27 +010015662 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010015663 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020015664 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15665 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010015666}
15667EXPORT_SYMBOL(cfg80211_ch_switch_notify);
15668
Luciano Coelhof8d75522014-11-07 14:31:35 +020015669void cfg80211_ch_switch_started_notify(struct net_device *dev,
15670 struct cfg80211_chan_def *chandef,
15671 u8 count)
15672{
15673 struct wireless_dev *wdev = dev->ieee80211_ptr;
15674 struct wiphy *wiphy = wdev->wiphy;
15675 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15676
15677 trace_cfg80211_ch_switch_started_notify(dev, chandef);
15678
15679 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15680 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
15681}
15682EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
15683
Thomas Pedersen84f10702012-07-12 16:17:33 -070015684void
Simon Wunderlich04f39042013-02-08 18:16:19 +010015685nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010015686 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015687 enum nl80211_radar_event event,
15688 struct net_device *netdev, gfp_t gfp)
15689{
15690 struct sk_buff *msg;
15691 void *hdr;
15692
15693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15694 if (!msg)
15695 return;
15696
15697 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
15698 if (!hdr) {
15699 nlmsg_free(msg);
15700 return;
15701 }
15702
15703 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15704 goto nla_put_failure;
15705
15706 /* NOP and radar events don't need a netdev parameter */
15707 if (netdev) {
15708 struct wireless_dev *wdev = netdev->ieee80211_ptr;
15709
15710 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015711 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15712 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010015713 goto nla_put_failure;
15714 }
15715
15716 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
15717 goto nla_put_failure;
15718
15719 if (nl80211_send_chandef(msg, chandef))
15720 goto nla_put_failure;
15721
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015722 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015723
Johannes Berg68eb5502013-11-19 15:19:38 +010015724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015725 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015726 return;
15727
15728 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010015729 nlmsg_free(msg);
15730}
15731
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053015732void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
15733 struct sta_opmode_info *sta_opmode,
15734 gfp_t gfp)
15735{
15736 struct sk_buff *msg;
15737 struct wireless_dev *wdev = dev->ieee80211_ptr;
15738 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15739 void *hdr;
15740
15741 if (WARN_ON(!mac))
15742 return;
15743
15744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15745 if (!msg)
15746 return;
15747
15748 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
15749 if (!hdr) {
15750 nlmsg_free(msg);
15751 return;
15752 }
15753
15754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15755 goto nla_put_failure;
15756
15757 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15758 goto nla_put_failure;
15759
15760 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15761 goto nla_put_failure;
15762
15763 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
15764 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
15765 goto nla_put_failure;
15766
15767 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
15768 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
15769 goto nla_put_failure;
15770
15771 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
15772 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
15773 goto nla_put_failure;
15774
15775 genlmsg_end(msg, hdr);
15776
15777 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15778 NL80211_MCGRP_MLME, gfp);
15779
15780 return;
15781
15782nla_put_failure:
15783 nlmsg_free(msg);
15784}
15785EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
15786
Johannes Berg7f6cf312011-11-04 11:18:15 +010015787void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015788 u64 cookie, bool acked, s32 ack_signal,
15789 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010015790{
15791 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015792 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015793 struct sk_buff *msg;
15794 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015795
Beni Lev4ee3e062012-08-27 12:49:39 +030015796 trace_cfg80211_probe_status(dev, addr, cookie, acked);
15797
Thomas Graf58050fc2012-06-28 03:57:45 +000015798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030015799
Johannes Berg7f6cf312011-11-04 11:18:15 +010015800 if (!msg)
15801 return;
15802
15803 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
15804 if (!hdr) {
15805 nlmsg_free(msg);
15806 return;
15807 }
15808
David S. Miller9360ffd2012-03-29 04:41:26 -040015809 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15810 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15811 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015812 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15813 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015814 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
15815 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
15816 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015817 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015818
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015819 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015820
Johannes Berg68eb5502013-11-19 15:19:38 +010015821 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015822 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015823 return;
15824
15825 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010015826 nlmsg_free(msg);
15827}
15828EXPORT_SYMBOL(cfg80211_probe_status);
15829
Johannes Berg5e760232011-11-04 11:18:17 +010015830void cfg80211_report_obss_beacon(struct wiphy *wiphy,
15831 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070015832 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010015833{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015834 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010015835 struct sk_buff *msg;
15836 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070015837 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010015838
Beni Lev4ee3e062012-08-27 12:49:39 +030015839 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
15840
Ben Greear37c73b52012-10-26 14:49:25 -070015841 spin_lock_bh(&rdev->beacon_registrations_lock);
15842 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
15843 msg = nlmsg_new(len + 100, GFP_ATOMIC);
15844 if (!msg) {
15845 spin_unlock_bh(&rdev->beacon_registrations_lock);
15846 return;
15847 }
Johannes Berg5e760232011-11-04 11:18:17 +010015848
Ben Greear37c73b52012-10-26 14:49:25 -070015849 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15850 if (!hdr)
15851 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010015852
Ben Greear37c73b52012-10-26 14:49:25 -070015853 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15854 (freq &&
15855 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
15856 (sig_dbm &&
15857 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15858 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
15859 goto nla_put_failure;
15860
15861 genlmsg_end(msg, hdr);
15862
15863 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010015864 }
Ben Greear37c73b52012-10-26 14:49:25 -070015865 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015866 return;
15867
15868 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070015869 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015870 nlmsg_free(msg);
15871}
15872EXPORT_SYMBOL(cfg80211_report_obss_beacon);
15873
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015874#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015875static int cfg80211_net_detect_results(struct sk_buff *msg,
15876 struct cfg80211_wowlan_wakeup *wakeup)
15877{
15878 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
15879 struct nlattr *nl_results, *nl_match, *nl_freqs;
15880 int i, j;
15881
15882 nl_results = nla_nest_start(
15883 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15884 if (!nl_results)
15885 return -EMSGSIZE;
15886
15887 for (i = 0; i < nd->n_matches; i++) {
15888 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15889
15890 nl_match = nla_nest_start(msg, i);
15891 if (!nl_match)
15892 break;
15893
15894 /* The SSID attribute is optional in nl80211, but for
15895 * simplicity reasons it's always present in the
15896 * cfg80211 structure. If a driver can't pass the
15897 * SSID, that needs to be changed. A zero length SSID
15898 * is still a valid SSID (wildcard), so it cannot be
15899 * used for this purpose.
15900 */
15901 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
15902 match->ssid.ssid)) {
15903 nla_nest_cancel(msg, nl_match);
15904 goto out;
15905 }
15906
15907 if (match->n_channels) {
15908 nl_freqs = nla_nest_start(
15909 msg, NL80211_ATTR_SCAN_FREQUENCIES);
15910 if (!nl_freqs) {
15911 nla_nest_cancel(msg, nl_match);
15912 goto out;
15913 }
15914
15915 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020015916 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015917 nla_nest_cancel(msg, nl_freqs);
15918 nla_nest_cancel(msg, nl_match);
15919 goto out;
15920 }
15921 }
15922
15923 nla_nest_end(msg, nl_freqs);
15924 }
15925
15926 nla_nest_end(msg, nl_match);
15927 }
15928
15929out:
15930 nla_nest_end(msg, nl_results);
15931 return 0;
15932}
15933
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015934void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15935 struct cfg80211_wowlan_wakeup *wakeup,
15936 gfp_t gfp)
15937{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015939 struct sk_buff *msg;
15940 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015941 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015942
15943 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15944
15945 if (wakeup)
15946 size += wakeup->packet_present_len;
15947
15948 msg = nlmsg_new(size, gfp);
15949 if (!msg)
15950 return;
15951
15952 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15953 if (!hdr)
15954 goto free_msg;
15955
15956 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015957 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15958 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015959 goto free_msg;
15960
15961 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15962 wdev->netdev->ifindex))
15963 goto free_msg;
15964
15965 if (wakeup) {
15966 struct nlattr *reasons;
15967
15968 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015969 if (!reasons)
15970 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015971
15972 if (wakeup->disconnect &&
15973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15974 goto free_msg;
15975 if (wakeup->magic_pkt &&
15976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15977 goto free_msg;
15978 if (wakeup->gtk_rekey_failure &&
15979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15980 goto free_msg;
15981 if (wakeup->eap_identity_req &&
15982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15983 goto free_msg;
15984 if (wakeup->four_way_handshake &&
15985 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15986 goto free_msg;
15987 if (wakeup->rfkill_release &&
15988 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15989 goto free_msg;
15990
15991 if (wakeup->pattern_idx >= 0 &&
15992 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15993 wakeup->pattern_idx))
15994 goto free_msg;
15995
Johannes Bergae917c92013-10-25 11:05:22 +020015996 if (wakeup->tcp_match &&
15997 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15998 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015999
Johannes Bergae917c92013-10-25 11:05:22 +020016000 if (wakeup->tcp_connlost &&
16001 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16002 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016003
Johannes Bergae917c92013-10-25 11:05:22 +020016004 if (wakeup->tcp_nomoretokens &&
16005 nla_put_flag(msg,
16006 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16007 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016008
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016009 if (wakeup->packet) {
16010 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16011 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16012
16013 if (!wakeup->packet_80211) {
16014 pkt_attr =
16015 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16016 len_attr =
16017 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16018 }
16019
16020 if (wakeup->packet_len &&
16021 nla_put_u32(msg, len_attr, wakeup->packet_len))
16022 goto free_msg;
16023
16024 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16025 wakeup->packet))
16026 goto free_msg;
16027 }
16028
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016029 if (wakeup->net_detect &&
16030 cfg80211_net_detect_results(msg, wakeup))
16031 goto free_msg;
16032
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016033 nla_nest_end(msg, reasons);
16034 }
16035
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016036 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016037
Johannes Berg68eb5502013-11-19 15:19:38 +010016038 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016039 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016040 return;
16041
16042 free_msg:
16043 nlmsg_free(msg);
16044}
16045EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16046#endif
16047
Jouni Malinen3475b092012-11-16 22:49:57 +020016048void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16049 enum nl80211_tdls_operation oper,
16050 u16 reason_code, gfp_t gfp)
16051{
16052 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016053 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016054 struct sk_buff *msg;
16055 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016056
16057 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16058 reason_code);
16059
16060 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16061 if (!msg)
16062 return;
16063
16064 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16065 if (!hdr) {
16066 nlmsg_free(msg);
16067 return;
16068 }
16069
16070 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16071 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16072 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16073 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16074 (reason_code > 0 &&
16075 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16076 goto nla_put_failure;
16077
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016078 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020016079
Johannes Berg68eb5502013-11-19 15:19:38 +010016080 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016081 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020016082 return;
16083
16084 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020016085 nlmsg_free(msg);
16086}
16087EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16088
Jouni Malinen026331c2010-02-15 12:53:10 +020016089static int nl80211_netlink_notify(struct notifier_block * nb,
16090 unsigned long state,
16091 void *_notify)
16092{
16093 struct netlink_notify *notify = _notify;
16094 struct cfg80211_registered_device *rdev;
16095 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070016096 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020016097
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030016098 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020016099 return NOTIFY_DONE;
16100
16101 rcu_read_lock();
16102
Johannes Berg5e760232011-11-04 11:18:17 +010016103 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016104 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020016105
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016106 list_for_each_entry_rcu(sched_scan_req,
16107 &rdev->sched_scan_req_list,
16108 list) {
16109 if (sched_scan_req->owner_nlportid == notify->portid) {
16110 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010016111 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010016112 }
Johannes Berg753aacf2017-01-05 10:57:14 +010016113 }
Johannes Berg78f22b62014-03-24 17:57:27 +010016114
Johannes Berg53873f12016-05-03 16:52:04 +030016115 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000016116 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070016117
Johannes Bergab810072017-04-26 07:43:41 +020016118 if (wdev->owner_nlportid == notify->portid) {
16119 wdev->nl_owner_dead = true;
16120 schedule_work(&rdev->destroy_work);
16121 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050016122 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020016123 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020016124
16125 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010016126 }
16127
Ben Greear37c73b52012-10-26 14:49:25 -070016128 spin_lock_bh(&rdev->beacon_registrations_lock);
16129 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16130 list) {
16131 if (reg->nlportid == notify->portid) {
16132 list_del(&reg->list);
16133 kfree(reg);
16134 break;
16135 }
16136 }
16137 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016138 }
Jouni Malinen026331c2010-02-15 12:53:10 +020016139
16140 rcu_read_unlock();
16141
Ilan peer05050752015-03-04 00:32:06 -050016142 /*
16143 * It is possible that the user space process that is controlling the
16144 * indoor setting disappeared, so notify the regulatory core.
16145 */
16146 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080016147 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020016148}
16149
16150static struct notifier_block nl80211_netlink_notifier = {
16151 .notifier_call = nl80211_netlink_notify,
16152};
16153
Jouni Malinen355199e2013-02-27 17:14:27 +020016154void cfg80211_ft_event(struct net_device *netdev,
16155 struct cfg80211_ft_event_params *ft_event)
16156{
16157 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016158 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020016159 struct sk_buff *msg;
16160 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020016161
16162 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16163
16164 if (!ft_event->target_ap)
16165 return;
16166
Dedy Lansky1039d082018-05-17 16:25:03 +030016167 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16168 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020016169 if (!msg)
16170 return;
16171
16172 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020016173 if (!hdr)
16174 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016175
Johannes Bergae917c92013-10-25 11:05:22 +020016176 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16177 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16178 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16179 goto out;
16180
16181 if (ft_event->ies &&
16182 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16183 goto out;
16184 if (ft_event->ric_ies &&
16185 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16186 ft_event->ric_ies))
16187 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020016188
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016189 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020016190
Johannes Berg68eb5502013-11-19 15:19:38 +010016191 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016192 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020016193 return;
16194 out:
16195 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020016196}
16197EXPORT_SYMBOL(cfg80211_ft_event);
16198
Arend van Spriel5de17982013-04-18 15:49:00 +020016199void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16200{
16201 struct cfg80211_registered_device *rdev;
16202 struct sk_buff *msg;
16203 void *hdr;
16204 u32 nlportid;
16205
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016206 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020016207 if (!rdev->crit_proto_nlportid)
16208 return;
16209
16210 nlportid = rdev->crit_proto_nlportid;
16211 rdev->crit_proto_nlportid = 0;
16212
16213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16214 if (!msg)
16215 return;
16216
16217 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16218 if (!hdr)
16219 goto nla_put_failure;
16220
16221 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016222 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16223 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020016224 goto nla_put_failure;
16225
16226 genlmsg_end(msg, hdr);
16227
16228 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16229 return;
16230
16231 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020016232 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020016233}
16234EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16235
Johannes Berg348baf02014-01-24 14:06:29 +010016236void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16237{
16238 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016239 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010016240 struct sk_buff *msg;
16241 void *hdr;
16242
16243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16244 if (!msg)
16245 return;
16246
16247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16248 if (!hdr)
16249 goto out;
16250
16251 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16252 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016253 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16254 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016255 goto out;
16256
16257 genlmsg_end(msg, hdr);
16258
16259 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16260 NL80211_MCGRP_MLME, GFP_KERNEL);
16261 return;
16262 out:
16263 nlmsg_free(msg);
16264}
16265
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016266int cfg80211_external_auth_request(struct net_device *dev,
16267 struct cfg80211_external_auth_params *params,
16268 gfp_t gfp)
16269{
16270 struct wireless_dev *wdev = dev->ieee80211_ptr;
16271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16272 struct sk_buff *msg;
16273 void *hdr;
16274
16275 if (!wdev->conn_owner_nlportid)
16276 return -EINVAL;
16277
16278 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16279 if (!msg)
16280 return -ENOMEM;
16281
16282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16283 if (!hdr)
16284 goto nla_put_failure;
16285
16286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16288 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16289 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16290 params->action) ||
16291 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16292 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16293 params->ssid.ssid))
16294 goto nla_put_failure;
16295
16296 genlmsg_end(msg, hdr);
16297 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16298 wdev->conn_owner_nlportid);
16299 return 0;
16300
16301 nla_put_failure:
16302 nlmsg_free(msg);
16303 return -ENOBUFS;
16304}
16305EXPORT_SYMBOL(cfg80211_external_auth_request);
16306
Johannes Berg55682962007-09-20 13:09:35 -040016307/* initialisation/exit functions */
16308
Johannes Berg56989f62016-10-24 14:40:05 +020016309int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016310{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016311 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016312
Johannes Berg489111e2016-10-24 14:40:03 +020016313 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016314 if (err)
16315 return err;
16316
Jouni Malinen026331c2010-02-15 12:53:10 +020016317 err = netlink_register_notifier(&nl80211_netlink_notifier);
16318 if (err)
16319 goto err_out;
16320
Johannes Berg55682962007-09-20 13:09:35 -040016321 return 0;
16322 err_out:
16323 genl_unregister_family(&nl80211_fam);
16324 return err;
16325}
16326
16327void nl80211_exit(void)
16328{
Jouni Malinen026331c2010-02-15 12:53:10 +020016329 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016330 genl_unregister_family(&nl80211_fam);
16331}