blob: 350d2962524c6039040459e50368375975a905d4 [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 Berg55682962007-09-20 13:09:35 -0400203/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300204static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400205 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
206 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700207 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200208 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100209
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200210 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530211 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100212 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
213 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
214 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
215
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200216 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
217 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
218 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
219 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100220 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200221 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400222
223 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
224 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
225 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100226
Eliad Pellere007b852011-11-24 18:13:56 +0200227 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
228 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100229
Johannes Bergb9454e82009-07-08 13:29:08 +0200230 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100231 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
232 .len = WLAN_MAX_KEY_LEN },
233 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
234 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
235 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200236 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200237 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100238
239 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
240 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
241 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
243 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
244 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100245 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
247 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
248 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
249 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100250 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200252 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800254 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100255 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300256
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700257 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
258 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
259
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300260 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
261 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
262 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200263 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
264 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100265 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300266
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800267 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700268 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700269
Johannes Berg6c739412011-11-03 09:27:01 +0100270 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200271
272 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
273 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
274 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100275 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
276 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200277
278 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
279 .len = IEEE80211_MAX_SSID_LEN },
280 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
281 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200282 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300283 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300284 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300285 [NL80211_ATTR_STA_FLAGS2] = {
286 .len = sizeof(struct nl80211_sta_flag_update),
287 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300288 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300289 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
290 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500291 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200292 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
293 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
294 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200295 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100296 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300297 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100298 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
299 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200300 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200301 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
302 .len = IEEE80211_MAX_DATA_LEN },
303 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200304 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200305 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300306 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200307 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300308 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
309 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200310 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900311 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
312 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100313 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100314 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100315 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200316 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700317 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300318 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200319 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200320 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300321 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300322 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
324 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
325 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530326 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300327 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530328 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300329 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
330 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
331 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
332 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
333 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300334 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100335 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200336 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
337 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700338 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800339 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
340 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
341 .len = NL80211_HT_CAPABILITY_LEN
342 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100343 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530344 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530345 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200346 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700347 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300348 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000349 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700350 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100351 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
352 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasari8feb69c2017-07-07 01:43:41 +0300353 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530354 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
355 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200356 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
357 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100358 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100359 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
360 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
361 .len = NL80211_VHT_CAPABILITY_LEN,
362 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200363 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
364 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
365 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300366 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200367 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
368 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
369 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300370 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
371 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530372 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
373 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200374 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100375 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100376 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
377 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
378 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800379 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
380 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200381 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
382 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530383 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200384 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300385 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300386 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300387 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
388 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
389 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300390 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200391 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200392 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200393 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200394 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500395 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200396 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100397 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200398 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300399 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
400 .len = VHT_MUMIMO_GROUPS_DATA_LEN
401 },
402 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300403 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200404 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300405 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300406 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
407 .len = FILS_MAX_KEK_LEN },
408 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200409 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200410 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200411 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
412 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
413 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
414 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200415 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300416 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
417 .len = FILS_ERP_MAX_USERNAME_LEN },
418 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
419 .len = FILS_ERP_MAX_REALM_LEN },
420 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
421 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
422 .len = FILS_ERP_MAX_RRK_LEN },
423 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
424 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100425 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200426 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200427
428 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
429 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
430 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300431 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
432 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Johannes Berg55682962007-09-20 13:09:35 -0400433};
434
Johannes Berge31b8212010-10-05 19:39:30 +0200435/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000436static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200437 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200438 [NL80211_KEY_IDX] = { .type = NLA_U8 },
439 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200440 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200441 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
442 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200443 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100444 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
445};
446
447/* policy for the key default flags */
448static const struct nla_policy
449nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
450 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
451 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200452};
453
Johannes Bergf83ace32016-10-17 08:04:07 +0200454#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200455/* policy for WoWLAN attributes */
456static const struct nla_policy
457nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
458 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
459 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
460 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
461 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200462 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
463 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
464 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
465 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100466 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300467 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100468};
469
470static const struct nla_policy
471nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
472 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
473 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
474 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
475 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
476 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
477 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
478 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
479 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
480 },
481 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
482 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
483 },
484 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
485 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
486 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200487};
Johannes Bergf83ace32016-10-17 08:04:07 +0200488#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200489
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700490/* policy for coalesce rule attributes */
491static const struct nla_policy
492nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
493 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
494 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
495 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
496};
497
Johannes Berge5497d72011-07-05 16:35:40 +0200498/* policy for GTK rekey offload attributes */
499static const struct nla_policy
500nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
501 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
502 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
503 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
504};
505
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300506static const struct nla_policy
507nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200508 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300509 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100510 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700511 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300512};
513
Avraham Stern3b06d272015-10-12 09:51:34 +0300514static const struct nla_policy
515nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
516 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
517 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
518};
519
Arend van Spriel38de03d2016-03-02 20:37:18 +0100520static const struct nla_policy
521nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
522 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
523 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
524 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
525 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
526 },
527};
528
Ayala Bekera442b762016-09-20 17:31:15 +0300529/* policy for NAN function attributes */
530static const struct nla_policy
531nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
532 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300533 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300534 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
535 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
536 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
537 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
538 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
539 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
540 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
541 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
542 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
543 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
544 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
545 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
546 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
547 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
548 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
549 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
550};
551
552/* policy for Service Response Filter attributes */
553static const struct nla_policy
554nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
555 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
556 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
557 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
558 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
559 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
560};
561
Peng Xuad670232017-10-03 23:21:51 +0300562/* policy for packet pattern attributes */
563static const struct nla_policy
564nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
565 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
566 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
567 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
568};
569
Johannes Berg97990a02013-04-19 01:02:55 +0200570static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
571 struct netlink_callback *cb,
572 struct cfg80211_registered_device **rdev,
573 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100574{
Johannes Berg67748892010-10-04 21:14:06 +0200575 int err;
576
Johannes Berg97990a02013-04-19 01:02:55 +0200577 if (!cb->args[0]) {
578 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200579 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200580 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200581 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100582 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200583
Johannes Bergc90c39d2016-10-24 14:40:01 +0200584 *wdev = __cfg80211_wdev_from_attrs(
585 sock_net(skb->sk),
586 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100587 if (IS_ERR(*wdev))
588 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800589 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200590 /* 0 is the first index - add 1 to parse only once */
591 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200592 cb->args[1] = (*wdev)->identifier;
593 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200594 /* subtract the 1 again here */
595 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200596 struct wireless_dev *tmp;
597
Johannes Bergea90e0d2017-03-15 14:26:04 +0100598 if (!wiphy)
599 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800600 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200601 *wdev = NULL;
602
Johannes Berg53873f12016-05-03 16:52:04 +0300603 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200604 if (tmp->identifier == cb->args[1]) {
605 *wdev = tmp;
606 break;
607 }
608 }
Johannes Berg97990a02013-04-19 01:02:55 +0200609
Johannes Bergea90e0d2017-03-15 14:26:04 +0100610 if (!*wdev)
611 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200612 }
613
Johannes Berg67748892010-10-04 21:14:06 +0200614 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200615}
616
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100617/* IE validation */
618static bool is_valid_ie_attr(const struct nlattr *attr)
619{
620 const u8 *pos;
621 int len;
622
623 if (!attr)
624 return true;
625
626 pos = nla_data(attr);
627 len = nla_len(attr);
628
629 while (len) {
630 u8 elemlen;
631
632 if (len < 2)
633 return false;
634 len -= 2;
635
636 elemlen = pos[1];
637 if (elemlen > len)
638 return false;
639
640 len -= elemlen;
641 pos += 2 + elemlen;
642 }
643
644 return true;
645}
646
Johannes Berg55682962007-09-20 13:09:35 -0400647/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000648static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400649 int flags, u8 cmd)
650{
651 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000652 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400653}
654
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300655static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
656 const struct ieee80211_reg_rule *rule)
657{
658 int j;
659 struct nlattr *nl_wmm_rules =
660 nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM);
661
662 if (!nl_wmm_rules)
663 goto nla_put_failure;
664
665 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
666 struct nlattr *nl_wmm_rule = nla_nest_start(msg, j);
667
668 if (!nl_wmm_rule)
669 goto nla_put_failure;
670
671 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
672 rule->wmm_rule->client[j].cw_min) ||
673 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
674 rule->wmm_rule->client[j].cw_max) ||
675 nla_put_u8(msg, NL80211_WMMR_AIFSN,
676 rule->wmm_rule->client[j].aifsn) ||
677 nla_put_u8(msg, NL80211_WMMR_TXOP,
678 rule->wmm_rule->client[j].cot))
679 goto nla_put_failure;
680
681 nla_nest_end(msg, nl_wmm_rule);
682 }
683 nla_nest_end(msg, nl_wmm_rules);
684
685 return 0;
686
687nla_put_failure:
688 return -ENOBUFS;
689}
690
691static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100692 struct ieee80211_channel *chan,
693 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400694{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200695 /* Some channels must be completely excluded from the
696 * list to protect old user-space tools from breaking
697 */
698 if (!large && chan->flags &
699 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
700 return 0;
701
David S. Miller9360ffd2012-03-29 04:41:26 -0400702 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
703 chan->center_freq))
704 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400705
David S. Miller9360ffd2012-03-29 04:41:26 -0400706 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
708 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200709 if (chan->flags & IEEE80211_CHAN_NO_IR) {
710 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
711 goto nla_put_failure;
712 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
713 goto nla_put_failure;
714 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100715 if (chan->flags & IEEE80211_CHAN_RADAR) {
716 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
717 goto nla_put_failure;
718 if (large) {
719 u32 time;
720
721 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
722
723 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
724 chan->dfs_state))
725 goto nla_put_failure;
726 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
727 time))
728 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100729 if (nla_put_u32(msg,
730 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
731 chan->dfs_cac_ms))
732 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100733 }
734 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400735
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100736 if (large) {
737 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
738 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
739 goto nla_put_failure;
740 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
741 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
742 goto nla_put_failure;
743 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
744 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
745 goto nla_put_failure;
746 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
747 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
748 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200749 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
750 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
751 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300752 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
753 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200754 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200755 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
756 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
757 goto nla_put_failure;
758 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
759 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
760 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100761 }
762
David S. Miller9360ffd2012-03-29 04:41:26 -0400763 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
764 DBM_TO_MBM(chan->max_power)))
765 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400766
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300767 if (large) {
768 const struct ieee80211_reg_rule *rule =
769 freq_reg_info(wiphy, chan->center_freq);
770
771 if (!IS_ERR(rule) && rule->wmm_rule) {
772 if (nl80211_msg_put_wmm_rules(msg, rule))
773 goto nla_put_failure;
774 }
775 }
776
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400777 return 0;
778
779 nla_put_failure:
780 return -ENOBUFS;
781}
782
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200783static bool nl80211_put_txq_stats(struct sk_buff *msg,
784 struct cfg80211_txq_stats *txqstats,
785 int attrtype)
786{
787 struct nlattr *txqattr;
788
789#define PUT_TXQVAL_U32(attr, memb) do { \
790 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
791 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
792 return false; \
793 } while (0)
794
795 txqattr = nla_nest_start(msg, attrtype);
796 if (!txqattr)
797 return false;
798
799 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
800 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
801 PUT_TXQVAL_U32(FLOWS, flows);
802 PUT_TXQVAL_U32(DROPS, drops);
803 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
804 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
805 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
806 PUT_TXQVAL_U32(COLLISIONS, collisions);
807 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
808 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
809 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
810 nla_nest_end(msg, txqattr);
811
812#undef PUT_TXQVAL_U32
813 return true;
814}
815
Johannes Berg55682962007-09-20 13:09:35 -0400816/* netlink command implementations */
817
Johannes Bergb9454e82009-07-08 13:29:08 +0200818struct key_parse {
819 struct key_params p;
820 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200821 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200822 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100823 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200824};
825
Johannes Berg768075e2017-11-13 15:35:06 +0100826static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
827 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200828{
829 struct nlattr *tb[NL80211_KEY_MAX + 1];
830 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Berg768075e2017-11-13 15:35:06 +0100831 nl80211_key_policy, info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200832 if (err)
833 return err;
834
835 k->def = !!tb[NL80211_KEY_DEFAULT];
836 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
837
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100838 if (k->def) {
839 k->def_uni = true;
840 k->def_multi = true;
841 }
842 if (k->defmgmt)
843 k->def_multi = true;
844
Johannes Bergb9454e82009-07-08 13:29:08 +0200845 if (tb[NL80211_KEY_IDX])
846 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
847
848 if (tb[NL80211_KEY_DATA]) {
849 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
850 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
851 }
852
853 if (tb[NL80211_KEY_SEQ]) {
854 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
855 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
856 }
857
858 if (tb[NL80211_KEY_CIPHER])
859 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
860
Johannes Berge31b8212010-10-05 19:39:30 +0200861 if (tb[NL80211_KEY_TYPE]) {
862 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
863 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
Johannes Berg768075e2017-11-13 15:35:06 +0100864 return genl_err_attr(info, -EINVAL,
865 tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +0200866 }
867
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100868 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
869 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700870
Johannes Berg2da8f412012-01-20 13:52:37 +0100871 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
872 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Berg768075e2017-11-13 15:35:06 +0100873 nl80211_key_default_policy,
874 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100875 if (err)
876 return err;
877
878 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
879 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
880 }
881
Johannes Bergb9454e82009-07-08 13:29:08 +0200882 return 0;
883}
884
885static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
886{
887 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
888 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
889 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
890 }
891
892 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
893 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
894 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
895 }
896
897 if (info->attrs[NL80211_ATTR_KEY_IDX])
898 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
899
900 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
901 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
902
903 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
904 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
905
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100906 if (k->def) {
907 k->def_uni = true;
908 k->def_multi = true;
909 }
910 if (k->defmgmt)
911 k->def_multi = true;
912
Johannes Berge31b8212010-10-05 19:39:30 +0200913 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
914 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berg768075e2017-11-13 15:35:06 +0100915 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) {
916 GENL_SET_ERR_MSG(info, "key type out of range");
Johannes Berge31b8212010-10-05 19:39:30 +0200917 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100918 }
Johannes Berge31b8212010-10-05 19:39:30 +0200919 }
920
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100921 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
922 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200923 int err = nla_parse_nested(kdt,
924 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
925 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200926 nl80211_key_default_policy,
927 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100928 if (err)
929 return err;
930
931 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
932 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
933 }
934
Johannes Bergb9454e82009-07-08 13:29:08 +0200935 return 0;
936}
937
938static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
939{
940 int err;
941
942 memset(k, 0, sizeof(*k));
943 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200944 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200945
946 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +0100947 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +0200948 else
949 err = nl80211_parse_key_old(info, k);
950
951 if (err)
952 return err;
953
Johannes Berg768075e2017-11-13 15:35:06 +0100954 if (k->def && k->defmgmt) {
955 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +0200956 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100957 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200958
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100959 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100960 if (k->def_uni || !k->def_multi) {
961 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100962 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100963 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100964 }
965
Johannes Bergb9454e82009-07-08 13:29:08 +0200966 if (k->idx != -1) {
967 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100968 if (k->idx < 4 || k->idx > 5) {
969 GENL_SET_ERR_MSG(info,
970 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200971 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100972 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200973 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +0100974 if (k->idx < 0 || k->idx > 3) {
975 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +0200976 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100977 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200978 } else {
Johannes Berg768075e2017-11-13 15:35:06 +0100979 if (k->idx < 0 || k->idx > 5) {
980 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200981 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100982 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200983 }
984 }
985
986 return 0;
987}
988
Johannes Bergfffd0932009-07-08 14:22:54 +0200989static struct cfg80211_cached_keys *
990nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +0100991 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200992{
Johannes Berg768075e2017-11-13 15:35:06 +0100993 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +0200994 struct key_parse parse;
995 struct nlattr *key;
996 struct cfg80211_cached_keys *result;
997 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200998 bool have_key = false;
999
1000 nla_for_each_nested(key, keys, rem) {
1001 have_key = true;
1002 break;
1003 }
1004
1005 if (!have_key)
1006 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001007
1008 result = kzalloc(sizeof(*result), GFP_KERNEL);
1009 if (!result)
1010 return ERR_PTR(-ENOMEM);
1011
1012 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001013
1014 nla_for_each_nested(key, keys, rem) {
1015 memset(&parse, 0, sizeof(parse));
1016 parse.idx = -1;
1017
Johannes Berg768075e2017-11-13 15:35:06 +01001018 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001019 if (err)
1020 goto error;
1021 err = -EINVAL;
1022 if (!parse.p.key)
1023 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001024 if (parse.idx < 0 || parse.idx > 3) {
1025 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001026 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001027 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001028 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001029 if (def) {
1030 GENL_SET_ERR_MSG(info,
1031 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001032 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001033 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001034 def = 1;
1035 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001036 if (!parse.def_uni || !parse.def_multi)
1037 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001038 } else if (parse.defmgmt)
1039 goto error;
1040 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001041 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001042 if (err)
1043 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001044 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1045 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001046 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001047 err = -EINVAL;
1048 goto error;
1049 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001050 result->params[parse.idx].cipher = parse.p.cipher;
1051 result->params[parse.idx].key_len = parse.p.key_len;
1052 result->params[parse.idx].key = result->data[parse.idx];
1053 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301054
Johannes Berg386b1f22016-09-13 16:10:02 +02001055 /* must be WEP key if we got here */
1056 if (no_ht)
1057 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001058 }
1059
Johannes Bergf1c1f172016-09-13 17:08:23 +02001060 if (result->def < 0) {
1061 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001062 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001063 goto error;
1064 }
1065
Johannes Bergfffd0932009-07-08 14:22:54 +02001066 return result;
1067 error:
1068 kfree(result);
1069 return ERR_PTR(err);
1070}
1071
1072static int nl80211_key_allowed(struct wireless_dev *wdev)
1073{
1074 ASSERT_WDEV_LOCK(wdev);
1075
Johannes Bergfffd0932009-07-08 14:22:54 +02001076 switch (wdev->iftype) {
1077 case NL80211_IFTYPE_AP:
1078 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001079 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001080 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001081 break;
1082 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001083 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001084 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001085 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001086 return -ENOLINK;
1087 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001088 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001089 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001090 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001091 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001092 case NL80211_IFTYPE_P2P_DEVICE:
1093 case NL80211_IFTYPE_WDS:
1094 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001095 return -EINVAL;
1096 }
1097
1098 return 0;
1099}
1100
Jouni Malinen664834d2014-01-15 00:01:44 +02001101static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1102 struct nlattr *tb)
1103{
1104 struct ieee80211_channel *chan;
1105
1106 if (tb == NULL)
1107 return NULL;
1108 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1109 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1110 return NULL;
1111 return chan;
1112}
1113
Johannes Berg7527a782011-05-13 10:58:57 +02001114static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1115{
1116 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1117 int i;
1118
1119 if (!nl_modes)
1120 goto nla_put_failure;
1121
1122 i = 0;
1123 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001124 if ((ifmodes & 1) && nla_put_flag(msg, i))
1125 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001126 ifmodes >>= 1;
1127 i++;
1128 }
1129
1130 nla_nest_end(msg, nl_modes);
1131 return 0;
1132
1133nla_put_failure:
1134 return -ENOBUFS;
1135}
1136
1137static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001138 struct sk_buff *msg,
1139 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001140{
1141 struct nlattr *nl_combis;
1142 int i, j;
1143
1144 nl_combis = nla_nest_start(msg,
1145 NL80211_ATTR_INTERFACE_COMBINATIONS);
1146 if (!nl_combis)
1147 goto nla_put_failure;
1148
1149 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1150 const struct ieee80211_iface_combination *c;
1151 struct nlattr *nl_combi, *nl_limits;
1152
1153 c = &wiphy->iface_combinations[i];
1154
1155 nl_combi = nla_nest_start(msg, i + 1);
1156 if (!nl_combi)
1157 goto nla_put_failure;
1158
1159 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1160 if (!nl_limits)
1161 goto nla_put_failure;
1162
1163 for (j = 0; j < c->n_limits; j++) {
1164 struct nlattr *nl_limit;
1165
1166 nl_limit = nla_nest_start(msg, j + 1);
1167 if (!nl_limit)
1168 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001169 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1170 c->limits[j].max))
1171 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001172 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1173 c->limits[j].types))
1174 goto nla_put_failure;
1175 nla_nest_end(msg, nl_limit);
1176 }
1177
1178 nla_nest_end(msg, nl_limits);
1179
David S. Miller9360ffd2012-03-29 04:41:26 -04001180 if (c->beacon_int_infra_match &&
1181 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1182 goto nla_put_failure;
1183 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1184 c->num_different_channels) ||
1185 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1186 c->max_interfaces))
1187 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001188 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001189 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1190 c->radar_detect_widths) ||
1191 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1192 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001193 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301194 if (c->beacon_int_min_gcd &&
1195 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1196 c->beacon_int_min_gcd))
1197 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001198
1199 nla_nest_end(msg, nl_combi);
1200 }
1201
1202 nla_nest_end(msg, nl_combis);
1203
1204 return 0;
1205nla_put_failure:
1206 return -ENOBUFS;
1207}
1208
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001210static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1211 struct sk_buff *msg)
1212{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001213 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001214 struct nlattr *nl_tcp;
1215
1216 if (!tcp)
1217 return 0;
1218
1219 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1220 if (!nl_tcp)
1221 return -ENOBUFS;
1222
1223 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1224 tcp->data_payload_max))
1225 return -ENOBUFS;
1226
1227 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1228 tcp->data_payload_max))
1229 return -ENOBUFS;
1230
1231 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1232 return -ENOBUFS;
1233
1234 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1235 sizeof(*tcp->tok), tcp->tok))
1236 return -ENOBUFS;
1237
1238 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1239 tcp->data_interval_max))
1240 return -ENOBUFS;
1241
1242 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1243 tcp->wake_payload_max))
1244 return -ENOBUFS;
1245
1246 nla_nest_end(msg, nl_tcp);
1247 return 0;
1248}
1249
Johannes Berg3713b4e2013-02-14 16:19:38 +01001250static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001251 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001252 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253{
1254 struct nlattr *nl_wowlan;
1255
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001256 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001257 return 0;
1258
1259 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1260 if (!nl_wowlan)
1261 return -ENOBUFS;
1262
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001263 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1279 return -ENOBUFS;
1280
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001282 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1284 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1285 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1286 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 };
1288
1289 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1290 sizeof(pat), &pat))
1291 return -ENOBUFS;
1292 }
1293
Luciano Coelho75453cc2015-01-09 14:06:37 +02001294 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1295 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1296 rdev->wiphy.wowlan->max_nd_match_sets))
1297 return -ENOBUFS;
1298
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001300 return -ENOBUFS;
1301
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_nest_end(msg, nl_wowlan);
1303
1304 return 0;
1305}
1306#endif
1307
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001308static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001310{
1311 struct nl80211_coalesce_rule_support rule;
1312
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001314 return 0;
1315
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1317 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1318 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1319 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1320 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1321 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001322
1323 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1324 return -ENOBUFS;
1325
1326 return 0;
1327}
1328
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001329static int
1330nl80211_send_iftype_data(struct sk_buff *msg,
1331 const struct ieee80211_sband_iftype_data *iftdata)
1332{
1333 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1334
1335 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1336 iftdata->types_mask))
1337 return -ENOBUFS;
1338
1339 if (he_cap->has_he) {
1340 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1341 sizeof(he_cap->he_cap_elem.mac_cap_info),
1342 he_cap->he_cap_elem.mac_cap_info) ||
1343 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1344 sizeof(he_cap->he_cap_elem.phy_cap_info),
1345 he_cap->he_cap_elem.phy_cap_info) ||
1346 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1347 sizeof(he_cap->he_mcs_nss_supp),
1348 &he_cap->he_mcs_nss_supp) ||
1349 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1350 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1351 return -ENOBUFS;
1352 }
1353
1354 return 0;
1355}
1356
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1358 struct ieee80211_supported_band *sband)
1359{
1360 struct nlattr *nl_rates, *nl_rate;
1361 struct ieee80211_rate *rate;
1362 int i;
1363
1364 /* add HT info */
1365 if (sband->ht_cap.ht_supported &&
1366 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1367 sizeof(sband->ht_cap.mcs),
1368 &sband->ht_cap.mcs) ||
1369 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1370 sband->ht_cap.cap) ||
1371 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1372 sband->ht_cap.ampdu_factor) ||
1373 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1374 sband->ht_cap.ampdu_density)))
1375 return -ENOBUFS;
1376
1377 /* add VHT info */
1378 if (sband->vht_cap.vht_supported &&
1379 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1380 sizeof(sband->vht_cap.vht_mcs),
1381 &sband->vht_cap.vht_mcs) ||
1382 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1383 sband->vht_cap.cap)))
1384 return -ENOBUFS;
1385
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001386 if (sband->n_iftype_data) {
1387 struct nlattr *nl_iftype_data =
1388 nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA);
1389 int err;
1390
1391 if (!nl_iftype_data)
1392 return -ENOBUFS;
1393
1394 for (i = 0; i < sband->n_iftype_data; i++) {
1395 struct nlattr *iftdata;
1396
1397 iftdata = nla_nest_start(msg, i + 1);
1398 if (!iftdata)
1399 return -ENOBUFS;
1400
1401 err = nl80211_send_iftype_data(msg,
1402 &sband->iftype_data[i]);
1403 if (err)
1404 return err;
1405
1406 nla_nest_end(msg, iftdata);
1407 }
1408
1409 nla_nest_end(msg, nl_iftype_data);
1410 }
1411
Johannes Berg3713b4e2013-02-14 16:19:38 +01001412 /* add bitrates */
1413 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1414 if (!nl_rates)
1415 return -ENOBUFS;
1416
1417 for (i = 0; i < sband->n_bitrates; i++) {
1418 nl_rate = nla_nest_start(msg, i);
1419 if (!nl_rate)
1420 return -ENOBUFS;
1421
1422 rate = &sband->bitrates[i];
1423 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1424 rate->bitrate))
1425 return -ENOBUFS;
1426 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1427 nla_put_flag(msg,
1428 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1429 return -ENOBUFS;
1430
1431 nla_nest_end(msg, nl_rate);
1432 }
1433
1434 nla_nest_end(msg, nl_rates);
1435
1436 return 0;
1437}
1438
1439static int
1440nl80211_send_mgmt_stypes(struct sk_buff *msg,
1441 const struct ieee80211_txrx_stypes *mgmt_stypes)
1442{
1443 u16 stypes;
1444 struct nlattr *nl_ftypes, *nl_ifs;
1445 enum nl80211_iftype ift;
1446 int i;
1447
1448 if (!mgmt_stypes)
1449 return 0;
1450
1451 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1452 if (!nl_ifs)
1453 return -ENOBUFS;
1454
1455 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1456 nl_ftypes = nla_nest_start(msg, ift);
1457 if (!nl_ftypes)
1458 return -ENOBUFS;
1459 i = 0;
1460 stypes = mgmt_stypes[ift].tx;
1461 while (stypes) {
1462 if ((stypes & 1) &&
1463 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1464 (i << 4) | IEEE80211_FTYPE_MGMT))
1465 return -ENOBUFS;
1466 stypes >>= 1;
1467 i++;
1468 }
1469 nla_nest_end(msg, nl_ftypes);
1470 }
1471
1472 nla_nest_end(msg, nl_ifs);
1473
1474 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1475 if (!nl_ifs)
1476 return -ENOBUFS;
1477
1478 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1479 nl_ftypes = nla_nest_start(msg, ift);
1480 if (!nl_ftypes)
1481 return -ENOBUFS;
1482 i = 0;
1483 stypes = mgmt_stypes[ift].rx;
1484 while (stypes) {
1485 if ((stypes & 1) &&
1486 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1487 (i << 4) | IEEE80211_FTYPE_MGMT))
1488 return -ENOBUFS;
1489 stypes >>= 1;
1490 i++;
1491 }
1492 nla_nest_end(msg, nl_ftypes);
1493 }
1494 nla_nest_end(msg, nl_ifs);
1495
1496 return 0;
1497}
1498
Johannes Berg17948992016-10-26 11:42:04 +02001499#define CMD(op, n) \
1500 do { \
1501 if (rdev->ops->op) { \
1502 i++; \
1503 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1504 goto nla_put_failure; \
1505 } \
1506 } while (0)
1507
1508static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1509 struct sk_buff *msg)
1510{
1511 int i = 0;
1512
1513 /*
1514 * do *NOT* add anything into this function, new things need to be
1515 * advertised only to new versions of userspace that can deal with
1516 * the split (and they can't possibly care about new features...
1517 */
1518 CMD(add_virtual_intf, NEW_INTERFACE);
1519 CMD(change_virtual_intf, SET_INTERFACE);
1520 CMD(add_key, NEW_KEY);
1521 CMD(start_ap, START_AP);
1522 CMD(add_station, NEW_STATION);
1523 CMD(add_mpath, NEW_MPATH);
1524 CMD(update_mesh_config, SET_MESH_CONFIG);
1525 CMD(change_bss, SET_BSS);
1526 CMD(auth, AUTHENTICATE);
1527 CMD(assoc, ASSOCIATE);
1528 CMD(deauth, DEAUTHENTICATE);
1529 CMD(disassoc, DISASSOCIATE);
1530 CMD(join_ibss, JOIN_IBSS);
1531 CMD(join_mesh, JOIN_MESH);
1532 CMD(set_pmksa, SET_PMKSA);
1533 CMD(del_pmksa, DEL_PMKSA);
1534 CMD(flush_pmksa, FLUSH_PMKSA);
1535 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1536 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1537 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1538 CMD(mgmt_tx, FRAME);
1539 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1540 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1543 goto nla_put_failure;
1544 }
1545 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1546 rdev->ops->join_mesh) {
1547 i++;
1548 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1549 goto nla_put_failure;
1550 }
1551 CMD(set_wds_peer, SET_WDS_PEER);
1552 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1553 CMD(tdls_mgmt, TDLS_MGMT);
1554 CMD(tdls_oper, TDLS_OPER);
1555 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001556 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001557 CMD(sched_scan_start, START_SCHED_SCAN);
1558 CMD(probe_client, PROBE_CLIENT);
1559 CMD(set_noack_map, SET_NOACK_MAP);
1560 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1561 i++;
1562 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1563 goto nla_put_failure;
1564 }
1565 CMD(start_p2p_device, START_P2P_DEVICE);
1566 CMD(set_mcast_rate, SET_MCAST_RATE);
1567#ifdef CONFIG_NL80211_TESTMODE
1568 CMD(testmode_cmd, TESTMODE);
1569#endif
1570
1571 if (rdev->ops->connect || rdev->ops->auth) {
1572 i++;
1573 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1574 goto nla_put_failure;
1575 }
1576
1577 if (rdev->ops->disconnect || rdev->ops->deauth) {
1578 i++;
1579 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1580 goto nla_put_failure;
1581 }
1582
1583 return i;
1584 nla_put_failure:
1585 return -ENOBUFS;
1586}
1587
Johannes Berg86e8cf92013-06-19 10:57:22 +02001588struct nl80211_dump_wiphy_state {
1589 s64 filter_wiphy;
1590 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301591 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001592 bool split;
1593};
1594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001596 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001598 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001599{
1600 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001601 struct nlattr *nl_bands, *nl_band;
1602 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001603 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001604 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001605 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001606 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001607 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001608 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001609 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001610
Johannes Berg3bb20552014-05-26 13:52:25 +02001611 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001612 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 return -ENOBUFS;
1614
Johannes Berg86e8cf92013-06-19 10:57:22 +02001615 if (WARN_ON(!state))
1616 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001617
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001621 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001623 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001624
Johannes Berg3bb20552014-05-26 13:52:25 +02001625 if (cmd != NL80211_CMD_NEW_WIPHY)
1626 goto finish;
1627
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 case 0:
1630 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001632 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001636 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001640 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001641 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001644 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001649 rdev->wiphy.max_match_sets) ||
1650 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1651 rdev->wiphy.max_sched_scan_plans) ||
1652 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1653 rdev->wiphy.max_sched_scan_plan_interval) ||
1654 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1655 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001656 goto nla_put_failure;
1657
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1660 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001662 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1663 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1666 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1669 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001671 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1672 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001674 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001675 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001676 state->split_start++;
1677 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001678 break;
1679 case 1:
1680 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1682 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001683 goto nla_put_failure;
1684
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001686 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001687 goto nla_put_failure;
1688
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001690 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1691 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001692
Johannes Berg3713b4e2013-02-14 16:19:38 +01001693 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001694 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001697 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001698
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001699 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001700 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001701 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001702 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001703
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001704 if ((rdev->wiphy.available_antennas_tx ||
1705 rdev->wiphy.available_antennas_rx) &&
1706 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 u32 tx_ant = 0, rx_ant = 0;
1708 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001709
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001710 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001711 if (!res) {
1712 if (nla_put_u32(msg,
1713 NL80211_ATTR_WIPHY_ANTENNA_TX,
1714 tx_ant) ||
1715 nla_put_u32(msg,
1716 NL80211_ATTR_WIPHY_ANTENNA_RX,
1717 rx_ant))
1718 goto nla_put_failure;
1719 }
Johannes Bergee688b002008-01-24 19:38:39 +01001720 }
1721
Johannes Berg86e8cf92013-06-19 10:57:22 +02001722 state->split_start++;
1723 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001724 break;
1725 case 2:
1726 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 state->split_start++;
1730 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001731 break;
1732 case 3:
1733 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1734 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001735 goto nla_put_failure;
1736
Johannes Berg86e8cf92013-06-19 10:57:22 +02001737 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001738 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001739 struct ieee80211_supported_band *sband;
1740
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001741 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001742
1743 if (!sband)
1744 continue;
1745
1746 nl_band = nla_nest_start(msg, band);
1747 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001748 goto nla_put_failure;
1749
Johannes Berg86e8cf92013-06-19 10:57:22 +02001750 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001751 case 0:
1752 if (nl80211_send_band_rateinfo(msg, sband))
1753 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001754 state->chan_start++;
1755 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001756 break;
1757 default:
1758 /* add frequencies */
1759 nl_freqs = nla_nest_start(
1760 msg, NL80211_BAND_ATTR_FREQS);
1761 if (!nl_freqs)
1762 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001763
Johannes Berg86e8cf92013-06-19 10:57:22 +02001764 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001765 i < sband->n_channels;
1766 i++) {
1767 nl_freq = nla_nest_start(msg, i);
1768 if (!nl_freq)
1769 goto nla_put_failure;
1770
1771 chan = &sband->channels[i];
1772
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001774 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001775 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 goto nla_put_failure;
1777
1778 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001779 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001780 break;
1781 }
1782 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001784 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001785 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 nla_nest_end(msg, nl_freqs);
1787 }
1788
1789 nla_nest_end(msg, nl_band);
1790
Johannes Berg86e8cf92013-06-19 10:57:22 +02001791 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001792 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001794 band--;
1795 break;
1796 }
Johannes Bergee688b002008-01-24 19:38:39 +01001797 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001798 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001799
Johannes Berg57fbcce2016-04-12 15:56:15 +02001800 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001801 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001802 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001804
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 if (state->band_start == 0 && state->chan_start == 0)
1807 state->split_start++;
1808 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001809 break;
1810 case 4:
1811 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1812 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001813 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814
Johannes Berg17948992016-10-26 11:42:04 +02001815 i = nl80211_add_commands_unsplit(rdev, msg);
1816 if (i < 0)
1817 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001819 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1820 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001821 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001822 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001823 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001824 if (rdev->wiphy.features &
1825 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001826 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001827 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001828 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001829 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001830#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001831
Johannes Berg3713b4e2013-02-14 16:19:38 +01001832 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001833 state->split_start++;
1834 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001835 break;
1836 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001837 if (rdev->ops->remain_on_channel &&
1838 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001839 nla_put_u32(msg,
1840 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001841 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001842 goto nla_put_failure;
1843
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001844 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001845 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1846 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001847
Johannes Berg3713b4e2013-02-14 16:19:38 +01001848 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1849 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 state->split_start++;
1851 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001852 break;
1853 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001854#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001855 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001856 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001857 state->split_start++;
1858 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001859 break;
1860#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001861 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001862#endif
1863 case 7:
1864 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001865 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001866 goto nla_put_failure;
1867
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001868 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001869 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001870 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001871
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 state->split_start++;
1873 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001874 break;
1875 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001876 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001877 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001878 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001879 goto nla_put_failure;
1880
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001881 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001882 /*
1883 * We can only add the per-channel limit information if the
1884 * dump is split, otherwise it makes it too big. Therefore
1885 * only advertise it in that case.
1886 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001887 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001888 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1889 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 goto nla_put_failure;
1891
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001892 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001893 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001894 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1895 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 goto nla_put_failure;
1897
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001898 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1899 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001900 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001901 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 goto nla_put_failure;
1903
1904 /*
1905 * Any information below this point is only available to
1906 * applications that can deal with it being split. This
1907 * helps ensure that newly added capabilities don't break
1908 * older tools by overrunning their buffers.
1909 *
1910 * We still increment split_start so that in the split
1911 * case we'll continue with more data in the next round,
1912 * but break unconditionally so unsplit data stops here.
1913 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001914 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001915 break;
1916 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001917 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001918 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001919 rdev->wiphy.extended_capabilities_len,
1920 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001921 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001922 rdev->wiphy.extended_capabilities_len,
1923 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001924 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001925
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001926 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001927 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001928 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1929 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001930 goto nla_put_failure;
1931
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001932 state->split_start++;
1933 break;
1934 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001935 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001936 goto nla_put_failure;
1937
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001938 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001939 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1940 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1941 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001942
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001943 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001944 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001945 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001946 goto nla_put_failure;
1947
Johannes Bergad7e7182013-11-13 13:37:47 +01001948 state->split_start++;
1949 break;
1950 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001951 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001952 const struct nl80211_vendor_cmd_info *info;
1953 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001954
Johannes Berg567ffc32013-12-18 14:43:31 +01001955 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1956 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001957 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001958
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001959 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1960 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001961 if (nla_put(msg, i + 1, sizeof(*info), info))
1962 goto nla_put_failure;
1963 }
1964 nla_nest_end(msg, nested);
1965 }
1966
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001967 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001968 const struct nl80211_vendor_cmd_info *info;
1969 struct nlattr *nested;
1970
1971 nested = nla_nest_start(msg,
1972 NL80211_ATTR_VENDOR_EVENTS);
1973 if (!nested)
1974 goto nla_put_failure;
1975
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001976 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1977 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001978 if (nla_put(msg, i + 1, sizeof(*info), info))
1979 goto nla_put_failure;
1980 }
1981 nla_nest_end(msg, nested);
1982 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001983 state->split_start++;
1984 break;
1985 case 12:
1986 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1987 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1988 rdev->wiphy.max_num_csa_counters))
1989 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001990
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001991 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1992 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1993 goto nla_put_failure;
1994
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001995 if (rdev->wiphy.max_sched_scan_reqs &&
1996 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1997 rdev->wiphy.max_sched_scan_reqs))
1998 goto nla_put_failure;
1999
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002000 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2001 sizeof(rdev->wiphy.ext_features),
2002 rdev->wiphy.ext_features))
2003 goto nla_put_failure;
2004
Arend van Spriel38de03d2016-03-02 20:37:18 +01002005 if (rdev->wiphy.bss_select_support) {
2006 struct nlattr *nested;
2007 u32 bss_select_support = rdev->wiphy.bss_select_support;
2008
2009 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
2010 if (!nested)
2011 goto nla_put_failure;
2012
2013 i = 0;
2014 while (bss_select_support) {
2015 if ((bss_select_support & 1) &&
2016 nla_put_flag(msg, i))
2017 goto nla_put_failure;
2018 i++;
2019 bss_select_support >>= 1;
2020 }
2021 nla_nest_end(msg, nested);
2022 }
2023
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302024 state->split_start++;
2025 break;
2026 case 13:
2027 if (rdev->wiphy.num_iftype_ext_capab &&
2028 rdev->wiphy.iftype_ext_capab) {
2029 struct nlattr *nested_ext_capab, *nested;
2030
2031 nested = nla_nest_start(msg,
2032 NL80211_ATTR_IFTYPE_EXT_CAPA);
2033 if (!nested)
2034 goto nla_put_failure;
2035
2036 for (i = state->capa_start;
2037 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2038 const struct wiphy_iftype_ext_capab *capab;
2039
2040 capab = &rdev->wiphy.iftype_ext_capab[i];
2041
2042 nested_ext_capab = nla_nest_start(msg, i);
2043 if (!nested_ext_capab ||
2044 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2045 capab->iftype) ||
2046 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2047 capab->extended_capabilities_len,
2048 capab->extended_capabilities) ||
2049 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2050 capab->extended_capabilities_len,
2051 capab->extended_capabilities_mask))
2052 goto nla_put_failure;
2053
2054 nla_nest_end(msg, nested_ext_capab);
2055 if (state->split)
2056 break;
2057 }
2058 nla_nest_end(msg, nested);
2059 if (i < rdev->wiphy.num_iftype_ext_capab) {
2060 state->capa_start = i + 1;
2061 break;
2062 }
2063 }
2064
Luca Coelho85859892017-02-08 15:00:34 +02002065 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2066 rdev->wiphy.nan_supported_bands))
2067 goto nla_put_failure;
2068
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002069 if (wiphy_ext_feature_isset(&rdev->wiphy,
2070 NL80211_EXT_FEATURE_TXQS)) {
2071 struct cfg80211_txq_stats txqstats = {};
2072 int res;
2073
2074 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2075 if (!res &&
2076 !nl80211_put_txq_stats(msg, &txqstats,
2077 NL80211_ATTR_TXQ_STATS))
2078 goto nla_put_failure;
2079
2080 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2081 rdev->wiphy.txq_limit))
2082 goto nla_put_failure;
2083 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2084 rdev->wiphy.txq_memory_limit))
2085 goto nla_put_failure;
2086 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2087 rdev->wiphy.txq_quantum))
2088 goto nla_put_failure;
2089 }
2090
Johannes Berg3713b4e2013-02-14 16:19:38 +01002091 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002092 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002093 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002094 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002095 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002096 genlmsg_end(msg, hdr);
2097 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002098
2099 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002100 genlmsg_cancel(msg, hdr);
2101 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002102}
2103
Johannes Berg86e8cf92013-06-19 10:57:22 +02002104static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2105 struct netlink_callback *cb,
2106 struct nl80211_dump_wiphy_state *state)
2107{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002108 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02002109 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
2110 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002111 /* ignore parse errors for backward compatibility */
2112 if (ret)
2113 return 0;
2114
2115 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2116 if (tb[NL80211_ATTR_WIPHY])
2117 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2118 if (tb[NL80211_ATTR_WDEV])
2119 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2120 if (tb[NL80211_ATTR_IFINDEX]) {
2121 struct net_device *netdev;
2122 struct cfg80211_registered_device *rdev;
2123 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2124
Ying Xue7f2b8562014-01-15 10:23:45 +08002125 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002126 if (!netdev)
2127 return -ENODEV;
2128 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002129 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002130 netdev->ieee80211_ptr->wiphy);
2131 state->filter_wiphy = rdev->wiphy_idx;
2132 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002133 }
2134
2135 return 0;
2136}
2137
Johannes Berg55682962007-09-20 13:09:35 -04002138static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2139{
Johannes Berg645e77d2013-03-01 14:03:49 +01002140 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002141 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002142 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002143
Johannes Berg5fe231e2013-05-08 21:45:15 +02002144 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002145 if (!state) {
2146 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002147 if (!state) {
2148 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002149 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002150 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002151 state->filter_wiphy = -1;
2152 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2153 if (ret) {
2154 kfree(state);
2155 rtnl_unlock();
2156 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002157 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002158 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002159 }
2160
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002161 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2162 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002163 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002164 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002165 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002166 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002167 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002168 continue;
2169 /* attempt to fit multiple wiphy data chunks into the skb */
2170 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002171 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2172 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002173 NETLINK_CB(cb->skb).portid,
2174 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002175 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002176 if (ret < 0) {
2177 /*
2178 * If sending the wiphy data didn't fit (ENOBUFS
2179 * or EMSGSIZE returned), this SKB is still
2180 * empty (so it's not too big because another
2181 * wiphy dataset is already in the skb) and
2182 * we've not tried to adjust the dump allocation
2183 * yet ... then adjust the alloc size to be
2184 * bigger, and return 1 but with the empty skb.
2185 * This results in an empty message being RX'ed
2186 * in userspace, but that is ignored.
2187 *
2188 * We can then retry with the larger buffer.
2189 */
2190 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002191 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002192 cb->min_dump_alloc < 4096) {
2193 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002194 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002195 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002196 return 1;
2197 }
2198 idx--;
2199 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002200 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002201 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002202 break;
Johannes Berg55682962007-09-20 13:09:35 -04002203 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002204 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002205
Johannes Berg86e8cf92013-06-19 10:57:22 +02002206 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002207
2208 return skb->len;
2209}
2210
Johannes Berg86e8cf92013-06-19 10:57:22 +02002211static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2212{
2213 kfree((void *)cb->args[0]);
2214 return 0;
2215}
2216
Johannes Berg55682962007-09-20 13:09:35 -04002217static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2218{
2219 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002221 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002222
Johannes Berg645e77d2013-03-01 14:03:49 +01002223 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002224 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002225 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002226
Johannes Berg3bb20552014-05-26 13:52:25 +02002227 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2228 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002229 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002230 nlmsg_free(msg);
2231 return -ENOBUFS;
2232 }
Johannes Berg55682962007-09-20 13:09:35 -04002233
Johannes Berg134e6372009-07-10 09:51:34 +00002234 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002235}
2236
Jouni Malinen31888482008-10-30 16:59:24 +02002237static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2238 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2239 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2240 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2241 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2242 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2243};
2244
2245static int parse_txq_params(struct nlattr *tb[],
2246 struct ieee80211_txq_params *txq_params)
2247{
Dan Williams259d8c12018-01-29 17:03:15 -08002248 u8 ac;
2249
Johannes Berga3304b02012-03-28 11:04:24 +02002250 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002251 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2252 !tb[NL80211_TXQ_ATTR_AIFS])
2253 return -EINVAL;
2254
Dan Williams259d8c12018-01-29 17:03:15 -08002255 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002256 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2257 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2258 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2259 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2260
Dan Williams259d8c12018-01-29 17:03:15 -08002261 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002262 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002263 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002264 return 0;
2265}
2266
Johannes Bergf444de02010-05-05 15:25:02 +02002267static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2268{
2269 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002270 * You can only set the channel explicitly for WDS interfaces,
2271 * all others have their channel managed via their respective
2272 * "establish a connection" command (connect, join, ...)
2273 *
2274 * For AP/GO and mesh mode, the channel can be set with the
2275 * channel userspace API, but is only stored and passed to the
2276 * low-level driver when the AP starts or the mesh is joined.
2277 * This is for backward compatibility, userspace can also give
2278 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002279 *
2280 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002281 * whatever else is going on, so they have their own special
2282 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002283 */
2284 return !wdev ||
2285 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002286 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002287 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2288 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002289}
2290
Johannes Berg683b6d32012-11-08 21:25:48 +01002291static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2292 struct genl_info *info,
2293 struct cfg80211_chan_def *chandef)
2294{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302295 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002296
2297 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2298 return -EINVAL;
2299
2300 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2301
2302 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002303 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2304 chandef->center_freq1 = control_freq;
2305 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002306
2307 /* Primary channel not allowed */
2308 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2309 return -EINVAL;
2310
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002311 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2312 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002313
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002314 chantype = nla_get_u32(
2315 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2316
2317 switch (chantype) {
2318 case NL80211_CHAN_NO_HT:
2319 case NL80211_CHAN_HT20:
2320 case NL80211_CHAN_HT40PLUS:
2321 case NL80211_CHAN_HT40MINUS:
2322 cfg80211_chandef_create(chandef, chandef->chan,
2323 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002324 /* user input for center_freq is incorrect */
2325 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2326 chandef->center_freq1 != nla_get_u32(
2327 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2328 return -EINVAL;
2329 /* center_freq2 must be zero */
2330 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2331 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2332 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002333 break;
2334 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002335 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002336 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002337 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2338 chandef->width =
2339 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2340 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2341 chandef->center_freq1 =
2342 nla_get_u32(
2343 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2344 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2345 chandef->center_freq2 =
2346 nla_get_u32(
2347 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2348 }
2349
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002350 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002351 return -EINVAL;
2352
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002353 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2354 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002355 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002356
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002357 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2358 chandef->width == NL80211_CHAN_WIDTH_10) &&
2359 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2360 return -EINVAL;
2361
Johannes Berg683b6d32012-11-08 21:25:48 +01002362 return 0;
2363}
2364
Johannes Bergf444de02010-05-05 15:25:02 +02002365static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002366 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002367 struct genl_info *info)
2368{
Johannes Berg683b6d32012-11-08 21:25:48 +01002369 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002370 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002371 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002372 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002373
Jouni Malinene16821b2014-04-28 11:22:08 +03002374 if (dev)
2375 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002376 if (!nl80211_can_set_dev_channel(wdev))
2377 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002378 if (wdev)
2379 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002380
Johannes Berg683b6d32012-11-08 21:25:48 +01002381 result = nl80211_parse_chandef(rdev, info, &chandef);
2382 if (result)
2383 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002384
Johannes Berge8c9bd52012-06-06 08:18:22 +02002385 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002386 case NL80211_IFTYPE_AP:
2387 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002388 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2389 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002390 result = -EINVAL;
2391 break;
2392 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002393 if (wdev->beacon_interval) {
2394 if (!dev || !rdev->ops->set_ap_chanwidth ||
2395 !(rdev->wiphy.features &
2396 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2397 result = -EBUSY;
2398 break;
2399 }
2400
2401 /* Only allow dynamic channel width changes */
2402 if (chandef.chan != wdev->preset_chandef.chan) {
2403 result = -EBUSY;
2404 break;
2405 }
2406 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2407 if (result)
2408 break;
2409 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002410 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002411 result = 0;
2412 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002413 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002414 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002415 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002416 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002417 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002418 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002419 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002420 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002421 }
Johannes Bergf444de02010-05-05 15:25:02 +02002422
2423 return result;
2424}
2425
2426static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2427{
Johannes Berg4c476992010-10-04 21:36:35 +02002428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2429 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002430
Jouni Malinene16821b2014-04-28 11:22:08 +03002431 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002432}
2433
Bill Jordane8347eb2010-10-01 13:54:28 -04002434static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2435{
Johannes Berg43b19952010-10-07 13:10:30 +02002436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2437 struct net_device *dev = info->user_ptr[1];
2438 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002439 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002440
2441 if (!info->attrs[NL80211_ATTR_MAC])
2442 return -EINVAL;
2443
Johannes Berg43b19952010-10-07 13:10:30 +02002444 if (netif_running(dev))
2445 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002446
Johannes Berg43b19952010-10-07 13:10:30 +02002447 if (!rdev->ops->set_wds_peer)
2448 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002449
Johannes Berg43b19952010-10-07 13:10:30 +02002450 if (wdev->iftype != NL80211_IFTYPE_WDS)
2451 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002452
2453 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002454 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002455}
2456
Johannes Berg55682962007-09-20 13:09:35 -04002457static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2458{
2459 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002460 struct net_device *netdev = NULL;
2461 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002462 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002463 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002464 u32 changed;
2465 u8 retry_short = 0, retry_long = 0;
2466 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002467 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002468 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002469
Johannes Berg5fe231e2013-05-08 21:45:15 +02002470 ASSERT_RTNL();
2471
Johannes Bergf444de02010-05-05 15:25:02 +02002472 /*
2473 * Try to find the wiphy and netdev. Normally this
2474 * function shouldn't need the netdev, but this is
2475 * done for backward compatibility -- previously
2476 * setting the channel was done per wiphy, but now
2477 * it is per netdev. Previous userland like hostapd
2478 * also passed a netdev to set_wiphy, so that it is
2479 * possible to let that go to the right netdev!
2480 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002481
Johannes Bergf444de02010-05-05 15:25:02 +02002482 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2483 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2484
Ying Xue7f2b8562014-01-15 10:23:45 +08002485 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002486 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002487 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002488 else
Johannes Bergf444de02010-05-05 15:25:02 +02002489 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002490 }
2491
Johannes Bergf444de02010-05-05 15:25:02 +02002492 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002493 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2494 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002495 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002496 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002497 wdev = NULL;
2498 netdev = NULL;
2499 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002500 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002501 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002502
2503 /*
2504 * end workaround code, by now the rdev is available
2505 * and locked, and wdev may or may not be NULL.
2506 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002507
2508 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002509 result = cfg80211_dev_rename(
2510 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002511
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002512 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002513 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002514
Jouni Malinen31888482008-10-30 16:59:24 +02002515 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2516 struct ieee80211_txq_params txq_params;
2517 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2518
Ying Xue7f2b8562014-01-15 10:23:45 +08002519 if (!rdev->ops->set_txq_params)
2520 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002521
Ying Xue7f2b8562014-01-15 10:23:45 +08002522 if (!netdev)
2523 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002524
Johannes Berg133a3ff2011-11-03 14:50:13 +01002525 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002526 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2527 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002528
Ying Xue7f2b8562014-01-15 10:23:45 +08002529 if (!netif_running(netdev))
2530 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002531
Jouni Malinen31888482008-10-30 16:59:24 +02002532 nla_for_each_nested(nl_txq_params,
2533 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2534 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002535 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2536 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002537 txq_params_policy,
2538 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002539 if (result)
2540 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002541 result = parse_txq_params(tb, &txq_params);
2542 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002543 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002544
Hila Gonene35e4d22012-06-27 17:19:42 +03002545 result = rdev_set_txq_params(rdev, netdev,
2546 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002547 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002548 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002549 }
2550 }
2551
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002552 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002553 result = __nl80211_set_channel(
2554 rdev,
2555 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2556 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002557 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002558 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002559 }
2560
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002561 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002562 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002563 enum nl80211_tx_power_setting type;
2564 int idx, mbm = 0;
2565
Johannes Bergc8442112012-10-24 10:17:18 +02002566 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2567 txp_wdev = NULL;
2568
Ying Xue7f2b8562014-01-15 10:23:45 +08002569 if (!rdev->ops->set_tx_power)
2570 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002571
2572 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2573 type = nla_get_u32(info->attrs[idx]);
2574
2575 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002576 (type != NL80211_TX_POWER_AUTOMATIC))
2577 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002578
2579 if (type != NL80211_TX_POWER_AUTOMATIC) {
2580 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2581 mbm = nla_get_u32(info->attrs[idx]);
2582 }
2583
Johannes Bergc8442112012-10-24 10:17:18 +02002584 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002585 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002586 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002587 }
2588
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002589 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2590 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2591 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002592
Bruno Randolf7f531e02010-12-16 11:30:22 +09002593 if ((!rdev->wiphy.available_antennas_tx &&
2594 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002595 !rdev->ops->set_antenna)
2596 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002597
2598 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2599 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2600
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002601 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002602 * available antenna masks, except for the "all" mask */
2603 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002604 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2605 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002606
Bruno Randolf7f531e02010-12-16 11:30:22 +09002607 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2608 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002609
Hila Gonene35e4d22012-06-27 17:19:42 +03002610 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002611 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002612 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002613 }
2614
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002615 changed = 0;
2616
2617 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2618 retry_short = nla_get_u8(
2619 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002620 if (retry_short == 0)
2621 return -EINVAL;
2622
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002623 changed |= WIPHY_PARAM_RETRY_SHORT;
2624 }
2625
2626 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2627 retry_long = nla_get_u8(
2628 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002629 if (retry_long == 0)
2630 return -EINVAL;
2631
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002632 changed |= WIPHY_PARAM_RETRY_LONG;
2633 }
2634
2635 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2636 frag_threshold = nla_get_u32(
2637 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002638 if (frag_threshold < 256)
2639 return -EINVAL;
2640
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002641 if (frag_threshold != (u32) -1) {
2642 /*
2643 * Fragments (apart from the last one) are required to
2644 * have even length. Make the fragmentation code
2645 * simpler by stripping LSB should someone try to use
2646 * odd threshold value.
2647 */
2648 frag_threshold &= ~0x1;
2649 }
2650 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2651 }
2652
2653 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2654 rts_threshold = nla_get_u32(
2655 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2656 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2657 }
2658
Lukáš Turek81077e82009-12-21 22:50:47 +01002659 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002660 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2661 return -EINVAL;
2662
Lukáš Turek81077e82009-12-21 22:50:47 +01002663 coverage_class = nla_get_u8(
2664 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2665 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2666 }
2667
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002668 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2669 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2670 return -EOPNOTSUPP;
2671
2672 changed |= WIPHY_PARAM_DYN_ACK;
2673 }
2674
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002675 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2676 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2677 NL80211_EXT_FEATURE_TXQS))
2678 return -EOPNOTSUPP;
2679 txq_limit = nla_get_u32(
2680 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2681 changed |= WIPHY_PARAM_TXQ_LIMIT;
2682 }
2683
2684 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2685 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2686 NL80211_EXT_FEATURE_TXQS))
2687 return -EOPNOTSUPP;
2688 txq_memory_limit = nla_get_u32(
2689 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2690 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2691 }
2692
2693 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2694 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2695 NL80211_EXT_FEATURE_TXQS))
2696 return -EOPNOTSUPP;
2697 txq_quantum = nla_get_u32(
2698 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2699 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2700 }
2701
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002702 if (changed) {
2703 u8 old_retry_short, old_retry_long;
2704 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002705 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002706 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002707
Ying Xue7f2b8562014-01-15 10:23:45 +08002708 if (!rdev->ops->set_wiphy_params)
2709 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002710
2711 old_retry_short = rdev->wiphy.retry_short;
2712 old_retry_long = rdev->wiphy.retry_long;
2713 old_frag_threshold = rdev->wiphy.frag_threshold;
2714 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002715 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002716 old_txq_limit = rdev->wiphy.txq_limit;
2717 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2718 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002719
2720 if (changed & WIPHY_PARAM_RETRY_SHORT)
2721 rdev->wiphy.retry_short = retry_short;
2722 if (changed & WIPHY_PARAM_RETRY_LONG)
2723 rdev->wiphy.retry_long = retry_long;
2724 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2725 rdev->wiphy.frag_threshold = frag_threshold;
2726 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2727 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002728 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2729 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002730 if (changed & WIPHY_PARAM_TXQ_LIMIT)
2731 rdev->wiphy.txq_limit = txq_limit;
2732 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
2733 rdev->wiphy.txq_memory_limit = txq_memory_limit;
2734 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
2735 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002736
Hila Gonene35e4d22012-06-27 17:19:42 +03002737 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002738 if (result) {
2739 rdev->wiphy.retry_short = old_retry_short;
2740 rdev->wiphy.retry_long = old_retry_long;
2741 rdev->wiphy.frag_threshold = old_frag_threshold;
2742 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002743 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002744 rdev->wiphy.txq_limit = old_txq_limit;
2745 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
2746 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02002747 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002748 }
2749 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002750 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002751}
2752
Johannes Berg71bbc992012-06-15 15:30:18 +02002753static inline u64 wdev_id(struct wireless_dev *wdev)
2754{
2755 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002756 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002757}
Johannes Berg55682962007-09-20 13:09:35 -04002758
Johannes Berg683b6d32012-11-08 21:25:48 +01002759static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002760 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002761{
Johannes Berg601555c2014-11-27 17:26:56 +01002762 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2763 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002764
Johannes Berg683b6d32012-11-08 21:25:48 +01002765 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2766 chandef->chan->center_freq))
2767 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002768 switch (chandef->width) {
2769 case NL80211_CHAN_WIDTH_20_NOHT:
2770 case NL80211_CHAN_WIDTH_20:
2771 case NL80211_CHAN_WIDTH_40:
2772 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2773 cfg80211_get_chandef_type(chandef)))
2774 return -ENOBUFS;
2775 break;
2776 default:
2777 break;
2778 }
2779 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2780 return -ENOBUFS;
2781 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2782 return -ENOBUFS;
2783 if (chandef->center_freq2 &&
2784 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002785 return -ENOBUFS;
2786 return 0;
2787}
2788
Eric W. Biederman15e47302012-09-07 20:12:54 +00002789static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002790 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002791 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002792{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002793 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002794 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002795 void *hdr;
2796
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002797 if (removal)
2798 cmd = NL80211_CMD_DEL_INTERFACE;
2799
2800 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002801 if (!hdr)
2802 return -1;
2803
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002804 if (dev &&
2805 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002806 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002807 goto nla_put_failure;
2808
2809 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2810 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002811 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2812 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002813 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002814 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2815 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08002816 (cfg80211_rdev_list_generation << 2)) ||
2817 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04002818 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002819
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002820 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002821 int ret;
2822 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002823
Johannes Berg683b6d32012-11-08 21:25:48 +01002824 ret = rdev_get_channel(rdev, wdev, &chandef);
2825 if (ret == 0) {
2826 if (nl80211_send_chandef(msg, &chandef))
2827 goto nla_put_failure;
2828 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002829 }
2830
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002831 if (rdev->ops->get_tx_power) {
2832 int dbm, ret;
2833
2834 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2835 if (ret == 0 &&
2836 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2837 DBM_TO_MBM(dbm)))
2838 goto nla_put_failure;
2839 }
2840
Johannes Berg44905262017-10-17 21:56:01 +02002841 wdev_lock(wdev);
2842 switch (wdev->iftype) {
2843 case NL80211_IFTYPE_AP:
2844 if (wdev->ssid_len &&
2845 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01002846 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02002847 break;
2848 case NL80211_IFTYPE_STATION:
2849 case NL80211_IFTYPE_P2P_CLIENT:
2850 case NL80211_IFTYPE_ADHOC: {
2851 const u8 *ssid_ie;
2852 if (!wdev->current_bss)
2853 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002854 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02002855 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
2856 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002857 if (ssid_ie &&
2858 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
2859 goto nla_put_failure_rcu_locked;
2860 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02002861 break;
2862 }
2863 default:
2864 /* nothing */
2865 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002866 }
Johannes Berg44905262017-10-17 21:56:01 +02002867 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002868
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002869 if (rdev->ops->get_txq_stats) {
2870 struct cfg80211_txq_stats txqstats = {};
2871 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
2872
2873 if (ret == 0 &&
2874 !nl80211_put_txq_stats(msg, &txqstats,
2875 NL80211_ATTR_TXQ_STATS))
2876 goto nla_put_failure;
2877 }
2878
Johannes Berg053c0952015-01-16 22:09:00 +01002879 genlmsg_end(msg, hdr);
2880 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002881
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002882 nla_put_failure_rcu_locked:
2883 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01002884 nla_put_failure_locked:
2885 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002886 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002887 genlmsg_cancel(msg, hdr);
2888 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002889}
2890
2891static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2892{
2893 int wp_idx = 0;
2894 int if_idx = 0;
2895 int wp_start = cb->args[0];
2896 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002897 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002898 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002899 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002900 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002901
Johannes Berg5fe231e2013-05-08 21:45:15 +02002902 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002903 if (!cb->args[2]) {
2904 struct nl80211_dump_wiphy_state state = {
2905 .filter_wiphy = -1,
2906 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002907
2908 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2909 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002910 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002911
2912 filter_wiphy = state.filter_wiphy;
2913
2914 /*
2915 * if filtering, set cb->args[2] to +1 since 0 is the default
2916 * value needed to determine that parsing is necessary.
2917 */
2918 if (filter_wiphy >= 0)
2919 cb->args[2] = filter_wiphy + 1;
2920 else
2921 cb->args[2] = -1;
2922 } else if (cb->args[2] > 0) {
2923 filter_wiphy = cb->args[2] - 1;
2924 }
2925
Johannes Bergf5ea9122009-08-07 16:17:38 +02002926 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2927 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002928 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002929 if (wp_idx < wp_start) {
2930 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002931 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002932 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002933
2934 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2935 continue;
2936
Johannes Berg55682962007-09-20 13:09:35 -04002937 if_idx = 0;
2938
Johannes Berg53873f12016-05-03 16:52:04 +03002939 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002940 if (if_idx < if_start) {
2941 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002942 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002943 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002944 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002945 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002946 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002947 goto out;
2948 }
2949 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002950 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002951
2952 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002953 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002954 out:
Johannes Berg55682962007-09-20 13:09:35 -04002955 cb->args[0] = wp_idx;
2956 cb->args[1] = if_idx;
2957
Johannes Bergea90e0d2017-03-15 14:26:04 +01002958 ret = skb->len;
2959 out_unlock:
2960 rtnl_unlock();
2961
2962 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002963}
2964
2965static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2966{
2967 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002969 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002970
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002972 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002973 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002974
Eric W. Biederman15e47302012-09-07 20:12:54 +00002975 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002976 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002977 nlmsg_free(msg);
2978 return -ENOBUFS;
2979 }
Johannes Berg55682962007-09-20 13:09:35 -04002980
Johannes Berg134e6372009-07-10 09:51:34 +00002981 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002982}
2983
Michael Wu66f7ac52008-01-31 19:48:22 +01002984static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2985 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2986 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2987 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2988 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2989 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002990 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002991};
2992
2993static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2994{
2995 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2996 int flag;
2997
2998 *mntrflags = 0;
2999
3000 if (!nla)
3001 return -EINVAL;
3002
Johannes Bergfceb6432017-04-12 14:34:07 +02003003 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
3004 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003005 return -EINVAL;
3006
3007 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3008 if (flags[flag])
3009 *mntrflags |= (1<<flag);
3010
Johannes Berg818a9862017-04-12 11:23:28 +02003011 *mntrflags |= MONITOR_FLAG_CHANGED;
3012
Michael Wu66f7ac52008-01-31 19:48:22 +01003013 return 0;
3014}
3015
Johannes Berg1db77592017-04-12 11:36:31 +02003016static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3017 enum nl80211_iftype type,
3018 struct genl_info *info,
3019 struct vif_params *params)
3020{
3021 bool change = false;
3022 int err;
3023
3024 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3025 if (type != NL80211_IFTYPE_MONITOR)
3026 return -EINVAL;
3027
3028 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3029 &params->flags);
3030 if (err)
3031 return err;
3032
3033 change = true;
3034 }
3035
3036 if (params->flags & MONITOR_FLAG_ACTIVE &&
3037 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3038 return -EOPNOTSUPP;
3039
3040 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3041 const u8 *mumimo_groups;
3042 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3043
3044 if (type != NL80211_IFTYPE_MONITOR)
3045 return -EINVAL;
3046
3047 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3048 return -EOPNOTSUPP;
3049
3050 mumimo_groups =
3051 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3052
3053 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003054 if ((mumimo_groups[0] & BIT(0)) ||
3055 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003056 return -EINVAL;
3057
3058 params->vht_mumimo_groups = mumimo_groups;
3059 change = true;
3060 }
3061
3062 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3063 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3064
3065 if (type != NL80211_IFTYPE_MONITOR)
3066 return -EINVAL;
3067
3068 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3069 return -EOPNOTSUPP;
3070
3071 params->vht_mumimo_follow_addr =
3072 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3073 change = true;
3074 }
3075
3076 return change ? 1 : 0;
3077}
3078
Johannes Berg9bc383d2009-11-19 11:55:19 +01003079static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003080 struct net_device *netdev, u8 use_4addr,
3081 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003082{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003083 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003084 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003085 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003086 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003087 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003088
3089 switch (iftype) {
3090 case NL80211_IFTYPE_AP_VLAN:
3091 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3092 return 0;
3093 break;
3094 case NL80211_IFTYPE_STATION:
3095 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3096 return 0;
3097 break;
3098 default:
3099 break;
3100 }
3101
3102 return -EOPNOTSUPP;
3103}
3104
Johannes Berg55682962007-09-20 13:09:35 -04003105static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3106{
Johannes Berg4c476992010-10-04 21:36:35 +02003107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003108 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003109 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003110 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003111 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003112 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003113
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003114 memset(&params, 0, sizeof(params));
3115
Johannes Berg04a773a2009-04-19 21:24:32 +02003116 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003117
Johannes Berg723b0382008-09-16 20:22:09 +02003118 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003119 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003120 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003121 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02003122 if (ntype > NL80211_IFTYPE_MAX)
3123 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02003124 }
3125
Johannes Berg92ffe052008-09-16 20:39:36 +02003126 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003127 struct wireless_dev *wdev = dev->ieee80211_ptr;
3128
Johannes Berg4c476992010-10-04 21:36:35 +02003129 if (ntype != NL80211_IFTYPE_MESH_POINT)
3130 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003131 if (netif_running(dev))
3132 return -EBUSY;
3133
3134 wdev_lock(wdev);
3135 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3136 IEEE80211_MAX_MESH_ID_LEN);
3137 wdev->mesh_id_up_len =
3138 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3139 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3140 wdev->mesh_id_up_len);
3141 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003142 }
3143
Felix Fietkau8b787642009-11-10 18:53:10 +01003144 if (info->attrs[NL80211_ATTR_4ADDR]) {
3145 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3146 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003147 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003148 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003149 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003150 } else {
3151 params.use_4addr = -1;
3152 }
3153
Johannes Berg1db77592017-04-12 11:36:31 +02003154 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3155 if (err < 0)
3156 return err;
3157 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003158 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003159
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003160 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003161 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003162 else
3163 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003164
Johannes Berg9bc383d2009-11-19 11:55:19 +01003165 if (!err && params.use_4addr != -1)
3166 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3167
Johannes Berg55682962007-09-20 13:09:35 -04003168 return err;
3169}
3170
3171static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3172{
Johannes Berg4c476992010-10-04 21:36:35 +02003173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003174 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003175 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003176 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003177 int err;
3178 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3179
Johannes Berg78f22b62014-03-24 17:57:27 +01003180 /* to avoid failing a new interface creation due to pending removal */
3181 cfg80211_destroy_ifaces(rdev);
3182
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003183 memset(&params, 0, sizeof(params));
3184
Johannes Berg55682962007-09-20 13:09:35 -04003185 if (!info->attrs[NL80211_ATTR_IFNAME])
3186 return -EINVAL;
3187
3188 if (info->attrs[NL80211_ATTR_IFTYPE]) {
3189 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3190 if (type > NL80211_IFTYPE_MAX)
3191 return -EINVAL;
3192 }
3193
Johannes Berg79c97e92009-07-07 03:56:12 +02003194 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003195 !(rdev->wiphy.interface_modes & (1 << type)))
3196 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003197
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003198 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003199 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3200 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003201 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3202 ETH_ALEN);
3203 if (!is_valid_ether_addr(params.macaddr))
3204 return -EADDRNOTAVAIL;
3205 }
3206
Johannes Berg9bc383d2009-11-19 11:55:19 +01003207 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003208 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003209 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003210 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003211 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003212 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003213
Johannes Berg1db77592017-04-12 11:36:31 +02003214 err = nl80211_parse_mon_options(rdev, type, info, &params);
3215 if (err < 0)
3216 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003217
Johannes Berga18c7192015-02-24 10:56:42 +01003218 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3219 if (!msg)
3220 return -ENOMEM;
3221
Hila Gonene35e4d22012-06-27 17:19:42 +03003222 wdev = rdev_add_virtual_intf(rdev,
3223 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003224 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003225 if (WARN_ON(!wdev)) {
3226 nlmsg_free(msg);
3227 return -EPROTO;
3228 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003229 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003230 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003231 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003232
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003233 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003234 wdev->owner_nlportid = info->snd_portid;
3235
Johannes Berg98104fde2012-06-16 00:19:54 +02003236 switch (type) {
3237 case NL80211_IFTYPE_MESH_POINT:
3238 if (!info->attrs[NL80211_ATTR_MESH_ID])
3239 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003240 wdev_lock(wdev);
3241 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3242 IEEE80211_MAX_MESH_ID_LEN);
3243 wdev->mesh_id_up_len =
3244 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3245 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3246 wdev->mesh_id_up_len);
3247 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003248 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003249 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003250 case NL80211_IFTYPE_P2P_DEVICE:
3251 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003252 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003253 * through the netdev notifier and must be added here
3254 */
3255 mutex_init(&wdev->mtx);
3256 INIT_LIST_HEAD(&wdev->event_list);
3257 spin_lock_init(&wdev->event_lock);
3258 INIT_LIST_HEAD(&wdev->mgmt_registrations);
3259 spin_lock_init(&wdev->mgmt_registrations_lock);
3260
Johannes Berg98104fde2012-06-16 00:19:54 +02003261 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03003262 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02003263 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02003264 break;
3265 default:
3266 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003267 }
3268
Eric W. Biederman15e47302012-09-07 20:12:54 +00003269 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003270 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003271 nlmsg_free(msg);
3272 return -ENOBUFS;
3273 }
3274
Denis Kenzior896ff062016-08-03 16:58:33 -05003275 /*
3276 * For wdevs which have no associated netdev object (e.g. of type
3277 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3278 * For all other types, the event will be generated from the
3279 * netdev notifier
3280 */
3281 if (!wdev->netdev)
3282 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003283
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003284 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003285}
3286
3287static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3288{
Johannes Berg4c476992010-10-04 21:36:35 +02003289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003290 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003291
Johannes Berg4c476992010-10-04 21:36:35 +02003292 if (!rdev->ops->del_virtual_intf)
3293 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003294
Johannes Berg84efbb82012-06-16 00:00:26 +02003295 /*
3296 * If we remove a wireless device without a netdev then clear
3297 * user_ptr[1] so that nl80211_post_doit won't dereference it
3298 * to check if it needs to do dev_put(). Otherwise it crashes
3299 * since the wdev has been freed, unlike with a netdev where
3300 * we need the dev_put() for the netdev to really be freed.
3301 */
3302 if (!wdev->netdev)
3303 info->user_ptr[1] = NULL;
3304
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003305 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003306}
3307
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003308static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3309{
3310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3311 struct net_device *dev = info->user_ptr[1];
3312 u16 noack_map;
3313
3314 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3315 return -EINVAL;
3316
3317 if (!rdev->ops->set_noack_map)
3318 return -EOPNOTSUPP;
3319
3320 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3321
Hila Gonene35e4d22012-06-27 17:19:42 +03003322 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003323}
3324
Johannes Berg41ade002007-12-19 02:03:29 +01003325struct get_key_cookie {
3326 struct sk_buff *msg;
3327 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003328 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003329};
3330
3331static void get_key_callback(void *c, struct key_params *params)
3332{
Johannes Bergb9454e82009-07-08 13:29:08 +02003333 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003334 struct get_key_cookie *cookie = c;
3335
David S. Miller9360ffd2012-03-29 04:41:26 -04003336 if ((params->key &&
3337 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3338 params->key_len, params->key)) ||
3339 (params->seq &&
3340 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3341 params->seq_len, params->seq)) ||
3342 (params->cipher &&
3343 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3344 params->cipher)))
3345 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003346
Johannes Bergb9454e82009-07-08 13:29:08 +02003347 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3348 if (!key)
3349 goto nla_put_failure;
3350
David S. Miller9360ffd2012-03-29 04:41:26 -04003351 if ((params->key &&
3352 nla_put(cookie->msg, NL80211_KEY_DATA,
3353 params->key_len, params->key)) ||
3354 (params->seq &&
3355 nla_put(cookie->msg, NL80211_KEY_SEQ,
3356 params->seq_len, params->seq)) ||
3357 (params->cipher &&
3358 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3359 params->cipher)))
3360 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003361
David S. Miller9360ffd2012-03-29 04:41:26 -04003362 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3363 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003364
3365 nla_nest_end(cookie->msg, key);
3366
Johannes Berg41ade002007-12-19 02:03:29 +01003367 return;
3368 nla_put_failure:
3369 cookie->error = 1;
3370}
3371
3372static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3373{
Johannes Berg4c476992010-10-04 21:36:35 +02003374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003375 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003376 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003377 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003378 const u8 *mac_addr = NULL;
3379 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003380 struct get_key_cookie cookie = {
3381 .error = 0,
3382 };
3383 void *hdr;
3384 struct sk_buff *msg;
3385
3386 if (info->attrs[NL80211_ATTR_KEY_IDX])
3387 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3388
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003389 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003390 return -EINVAL;
3391
3392 if (info->attrs[NL80211_ATTR_MAC])
3393 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3394
Johannes Berge31b8212010-10-05 19:39:30 +02003395 pairwise = !!mac_addr;
3396 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3397 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003398
Johannes Berge31b8212010-10-05 19:39:30 +02003399 if (kt >= NUM_NL80211_KEYTYPES)
3400 return -EINVAL;
3401 if (kt != NL80211_KEYTYPE_GROUP &&
3402 kt != NL80211_KEYTYPE_PAIRWISE)
3403 return -EINVAL;
3404 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3405 }
3406
Johannes Berg4c476992010-10-04 21:36:35 +02003407 if (!rdev->ops->get_key)
3408 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003409
Johannes Berg0fa7b392015-01-23 11:10:12 +01003410 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3411 return -ENOENT;
3412
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003413 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003414 if (!msg)
3415 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003416
Eric W. Biederman15e47302012-09-07 20:12:54 +00003417 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003418 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003419 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003420 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003421
3422 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003423 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003424
David S. Miller9360ffd2012-03-29 04:41:26 -04003425 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3426 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3427 goto nla_put_failure;
3428 if (mac_addr &&
3429 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3430 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003431
Hila Gonene35e4d22012-06-27 17:19:42 +03003432 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3433 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003434
3435 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003436 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003437
3438 if (cookie.error)
3439 goto nla_put_failure;
3440
3441 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003442 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003443
3444 nla_put_failure:
3445 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003446 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003447 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003448 return err;
3449}
3450
3451static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3452{
Johannes Berg4c476992010-10-04 21:36:35 +02003453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003454 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003455 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003456 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003457
Johannes Bergb9454e82009-07-08 13:29:08 +02003458 err = nl80211_parse_key(info, &key);
3459 if (err)
3460 return err;
3461
3462 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003463 return -EINVAL;
3464
Johannes Bergb9454e82009-07-08 13:29:08 +02003465 /* only support setting default key */
3466 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003467 return -EINVAL;
3468
Johannes Bergfffd0932009-07-08 14:22:54 +02003469 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003470
3471 if (key.def) {
3472 if (!rdev->ops->set_default_key) {
3473 err = -EOPNOTSUPP;
3474 goto out;
3475 }
3476
3477 err = nl80211_key_allowed(dev->ieee80211_ptr);
3478 if (err)
3479 goto out;
3480
Hila Gonene35e4d22012-06-27 17:19:42 +03003481 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003482 key.def_uni, key.def_multi);
3483
3484 if (err)
3485 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003486
Johannes Berg3d23e342009-09-29 23:27:28 +02003487#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003488 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003489#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003490 } else {
3491 if (key.def_uni || !key.def_multi) {
3492 err = -EINVAL;
3493 goto out;
3494 }
3495
3496 if (!rdev->ops->set_default_mgmt_key) {
3497 err = -EOPNOTSUPP;
3498 goto out;
3499 }
3500
3501 err = nl80211_key_allowed(dev->ieee80211_ptr);
3502 if (err)
3503 goto out;
3504
Hila Gonene35e4d22012-06-27 17:19:42 +03003505 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003506 if (err)
3507 goto out;
3508
3509#ifdef CONFIG_CFG80211_WEXT
3510 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3511#endif
3512 }
3513
3514 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003515 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003516
Johannes Berg41ade002007-12-19 02:03:29 +01003517 return err;
3518}
3519
3520static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3521{
Johannes Berg4c476992010-10-04 21:36:35 +02003522 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003523 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003524 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003525 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003526 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003527
Johannes Bergb9454e82009-07-08 13:29:08 +02003528 err = nl80211_parse_key(info, &key);
3529 if (err)
3530 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003531
Johannes Bergb9454e82009-07-08 13:29:08 +02003532 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003533 return -EINVAL;
3534
Johannes Berg41ade002007-12-19 02:03:29 +01003535 if (info->attrs[NL80211_ATTR_MAC])
3536 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3537
Johannes Berge31b8212010-10-05 19:39:30 +02003538 if (key.type == -1) {
3539 if (mac_addr)
3540 key.type = NL80211_KEYTYPE_PAIRWISE;
3541 else
3542 key.type = NL80211_KEYTYPE_GROUP;
3543 }
3544
3545 /* for now */
3546 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3547 key.type != NL80211_KEYTYPE_GROUP)
3548 return -EINVAL;
3549
Johannes Berg4c476992010-10-04 21:36:35 +02003550 if (!rdev->ops->add_key)
3551 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003552
Johannes Berge31b8212010-10-05 19:39:30 +02003553 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3554 key.type == NL80211_KEYTYPE_PAIRWISE,
3555 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003556 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003557
3558 wdev_lock(dev->ieee80211_ptr);
3559 err = nl80211_key_allowed(dev->ieee80211_ptr);
3560 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003561 err = rdev_add_key(rdev, dev, key.idx,
3562 key.type == NL80211_KEYTYPE_PAIRWISE,
3563 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003564 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003565
Johannes Berg41ade002007-12-19 02:03:29 +01003566 return err;
3567}
3568
3569static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3570{
Johannes Berg4c476992010-10-04 21:36:35 +02003571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003572 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003574 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003575 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003576
Johannes Bergb9454e82009-07-08 13:29:08 +02003577 err = nl80211_parse_key(info, &key);
3578 if (err)
3579 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003580
3581 if (info->attrs[NL80211_ATTR_MAC])
3582 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3583
Johannes Berge31b8212010-10-05 19:39:30 +02003584 if (key.type == -1) {
3585 if (mac_addr)
3586 key.type = NL80211_KEYTYPE_PAIRWISE;
3587 else
3588 key.type = NL80211_KEYTYPE_GROUP;
3589 }
3590
3591 /* for now */
3592 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3593 key.type != NL80211_KEYTYPE_GROUP)
3594 return -EINVAL;
3595
Johannes Berg4c476992010-10-04 21:36:35 +02003596 if (!rdev->ops->del_key)
3597 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003598
Johannes Bergfffd0932009-07-08 14:22:54 +02003599 wdev_lock(dev->ieee80211_ptr);
3600 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003601
Johannes Berg0fa7b392015-01-23 11:10:12 +01003602 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003603 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3604 err = -ENOENT;
3605
Johannes Bergfffd0932009-07-08 14:22:54 +02003606 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003607 err = rdev_del_key(rdev, dev, key.idx,
3608 key.type == NL80211_KEYTYPE_PAIRWISE,
3609 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003610
Johannes Berg3d23e342009-09-29 23:27:28 +02003611#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003612 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003613 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003614 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003615 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003616 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3617 }
3618#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003619 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003620
Johannes Berg41ade002007-12-19 02:03:29 +01003621 return err;
3622}
3623
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303624/* This function returns an error or the number of nested attributes */
3625static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3626{
3627 struct nlattr *attr;
3628 int n_entries = 0, tmp;
3629
3630 nla_for_each_nested(attr, nl_attr, tmp) {
3631 if (nla_len(attr) != ETH_ALEN)
3632 return -EINVAL;
3633
3634 n_entries++;
3635 }
3636
3637 return n_entries;
3638}
3639
3640/*
3641 * This function parses ACL information and allocates memory for ACL data.
3642 * On successful return, the calling function is responsible to free the
3643 * ACL buffer returned by this function.
3644 */
3645static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3646 struct genl_info *info)
3647{
3648 enum nl80211_acl_policy acl_policy;
3649 struct nlattr *attr;
3650 struct cfg80211_acl_data *acl;
3651 int i = 0, n_entries, tmp;
3652
3653 if (!wiphy->max_acl_mac_addrs)
3654 return ERR_PTR(-EOPNOTSUPP);
3655
3656 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3657 return ERR_PTR(-EINVAL);
3658
3659 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3660 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3661 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3662 return ERR_PTR(-EINVAL);
3663
3664 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3665 return ERR_PTR(-EINVAL);
3666
3667 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3668 if (n_entries < 0)
3669 return ERR_PTR(n_entries);
3670
3671 if (n_entries > wiphy->max_acl_mac_addrs)
3672 return ERR_PTR(-ENOTSUPP);
3673
3674 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3675 GFP_KERNEL);
3676 if (!acl)
3677 return ERR_PTR(-ENOMEM);
3678
3679 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3680 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3681 i++;
3682 }
3683
3684 acl->n_acl_entries = n_entries;
3685 acl->acl_policy = acl_policy;
3686
3687 return acl;
3688}
3689
3690static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3691{
3692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3693 struct net_device *dev = info->user_ptr[1];
3694 struct cfg80211_acl_data *acl;
3695 int err;
3696
3697 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3698 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3699 return -EOPNOTSUPP;
3700
3701 if (!dev->ieee80211_ptr->beacon_interval)
3702 return -EINVAL;
3703
3704 acl = parse_acl_data(&rdev->wiphy, info);
3705 if (IS_ERR(acl))
3706 return PTR_ERR(acl);
3707
3708 err = rdev_set_mac_acl(rdev, dev, acl);
3709
3710 kfree(acl);
3711
3712 return err;
3713}
3714
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303715static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3716 u8 *rates, u8 rates_len)
3717{
3718 u8 i;
3719 u32 mask = 0;
3720
3721 for (i = 0; i < rates_len; i++) {
3722 int rate = (rates[i] & 0x7f) * 5;
3723 int ridx;
3724
3725 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3726 struct ieee80211_rate *srate =
3727 &sband->bitrates[ridx];
3728 if (rate == srate->bitrate) {
3729 mask |= 1 << ridx;
3730 break;
3731 }
3732 }
3733 if (ridx == sband->n_bitrates)
3734 return 0; /* rate not found */
3735 }
3736
3737 return mask;
3738}
3739
3740static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3741 u8 *rates, u8 rates_len,
3742 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3743{
3744 u8 i;
3745
3746 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3747
3748 for (i = 0; i < rates_len; i++) {
3749 int ridx, rbit;
3750
3751 ridx = rates[i] / 8;
3752 rbit = BIT(rates[i] % 8);
3753
3754 /* check validity */
3755 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3756 return false;
3757
3758 /* check availability */
3759 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3760 mcs[ridx] |= rbit;
3761 else
3762 return false;
3763 }
3764
3765 return true;
3766}
3767
3768static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3769{
3770 u16 mcs_mask = 0;
3771
3772 switch (vht_mcs_map) {
3773 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3774 break;
3775 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3776 mcs_mask = 0x00FF;
3777 break;
3778 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3779 mcs_mask = 0x01FF;
3780 break;
3781 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3782 mcs_mask = 0x03FF;
3783 break;
3784 default:
3785 break;
3786 }
3787
3788 return mcs_mask;
3789}
3790
3791static void vht_build_mcs_mask(u16 vht_mcs_map,
3792 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3793{
3794 u8 nss;
3795
3796 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3797 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3798 vht_mcs_map >>= 2;
3799 }
3800}
3801
3802static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3803 struct nl80211_txrate_vht *txrate,
3804 u16 mcs[NL80211_VHT_NSS_MAX])
3805{
3806 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3807 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3808 u8 i;
3809
3810 if (!sband->vht_cap.vht_supported)
3811 return false;
3812
3813 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3814
3815 /* Build vht_mcs_mask from VHT capabilities */
3816 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3817
3818 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3819 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3820 mcs[i] = txrate->mcs[i];
3821 else
3822 return false;
3823 }
3824
3825 return true;
3826}
3827
3828static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3829 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3830 .len = NL80211_MAX_SUPP_RATES },
3831 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3832 .len = NL80211_MAX_SUPP_HT_RATES },
3833 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3834 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3835};
3836
3837static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3838 struct cfg80211_bitrate_mask *mask)
3839{
3840 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3842 int rem, i;
3843 struct nlattr *tx_rates;
3844 struct ieee80211_supported_band *sband;
3845 u16 vht_tx_mcs_map;
3846
3847 memset(mask, 0, sizeof(*mask));
3848 /* Default to all rates enabled */
3849 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3850 sband = rdev->wiphy.bands[i];
3851
3852 if (!sband)
3853 continue;
3854
3855 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3856 memcpy(mask->control[i].ht_mcs,
3857 sband->ht_cap.mcs.rx_mask,
3858 sizeof(mask->control[i].ht_mcs));
3859
3860 if (!sband->vht_cap.vht_supported)
3861 continue;
3862
3863 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3864 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3865 }
3866
3867 /* if no rates are given set it back to the defaults */
3868 if (!info->attrs[NL80211_ATTR_TX_RATES])
3869 goto out;
3870
3871 /* The nested attribute uses enum nl80211_band as the index. This maps
3872 * directly to the enum nl80211_band values used in cfg80211.
3873 */
3874 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3875 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3876 enum nl80211_band band = nla_type(tx_rates);
3877 int err;
3878
3879 if (band < 0 || band >= NUM_NL80211_BANDS)
3880 return -EINVAL;
3881 sband = rdev->wiphy.bands[band];
3882 if (sband == NULL)
3883 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003884 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003885 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303886 if (err)
3887 return err;
3888 if (tb[NL80211_TXRATE_LEGACY]) {
3889 mask->control[band].legacy = rateset_to_mask(
3890 sband,
3891 nla_data(tb[NL80211_TXRATE_LEGACY]),
3892 nla_len(tb[NL80211_TXRATE_LEGACY]));
3893 if ((mask->control[band].legacy == 0) &&
3894 nla_len(tb[NL80211_TXRATE_LEGACY]))
3895 return -EINVAL;
3896 }
3897 if (tb[NL80211_TXRATE_HT]) {
3898 if (!ht_rateset_to_mask(
3899 sband,
3900 nla_data(tb[NL80211_TXRATE_HT]),
3901 nla_len(tb[NL80211_TXRATE_HT]),
3902 mask->control[band].ht_mcs))
3903 return -EINVAL;
3904 }
3905 if (tb[NL80211_TXRATE_VHT]) {
3906 if (!vht_set_mcs_mask(
3907 sband,
3908 nla_data(tb[NL80211_TXRATE_VHT]),
3909 mask->control[band].vht_mcs))
3910 return -EINVAL;
3911 }
3912 if (tb[NL80211_TXRATE_GI]) {
3913 mask->control[band].gi =
3914 nla_get_u8(tb[NL80211_TXRATE_GI]);
3915 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3916 return -EINVAL;
3917 }
3918
3919 if (mask->control[band].legacy == 0) {
3920 /* don't allow empty legacy rates if HT or VHT
3921 * are not even supported.
3922 */
3923 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3924 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3925 return -EINVAL;
3926
3927 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3928 if (mask->control[band].ht_mcs[i])
3929 goto out;
3930
3931 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3932 if (mask->control[band].vht_mcs[i])
3933 goto out;
3934
3935 /* legacy and mcs rates may not be both empty */
3936 return -EINVAL;
3937 }
3938 }
3939
3940out:
3941 return 0;
3942}
3943
Johannes Berg8564e382016-09-19 09:44:44 +02003944static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3945 enum nl80211_band band,
3946 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303947{
Johannes Berg8564e382016-09-19 09:44:44 +02003948 u32 count_ht, count_vht, i;
3949 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303950
3951 /* Allow only one rate */
3952 if (hweight32(rate) > 1)
3953 return -EINVAL;
3954
3955 count_ht = 0;
3956 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003957 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303958 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003959 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303960 count_ht++;
3961 if (count_ht > 1)
3962 return -EINVAL;
3963 }
3964 if (count_ht && rate)
3965 return -EINVAL;
3966 }
3967
3968 count_vht = 0;
3969 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003970 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303971 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003972 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303973 count_vht++;
3974 if (count_vht > 1)
3975 return -EINVAL;
3976 }
3977 if (count_vht && rate)
3978 return -EINVAL;
3979 }
3980
3981 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3982 return -EINVAL;
3983
Johannes Berg8564e382016-09-19 09:44:44 +02003984 if (rate &&
3985 !wiphy_ext_feature_isset(&rdev->wiphy,
3986 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3987 return -EINVAL;
3988 if (count_ht &&
3989 !wiphy_ext_feature_isset(&rdev->wiphy,
3990 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3991 return -EINVAL;
3992 if (count_vht &&
3993 !wiphy_ext_feature_isset(&rdev->wiphy,
3994 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3995 return -EINVAL;
3996
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303997 return 0;
3998}
3999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004000static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004001 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004002{
Johannes Berg88600202012-02-13 15:17:18 +01004003 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004004
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004005 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
4006 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
4007 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
4008 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004009 return -EINVAL;
4010
Johannes Berg88600202012-02-13 15:17:18 +01004011 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004012
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004013 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4014 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4015 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004016 if (!bcn->head_len)
4017 return -EINVAL;
4018 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004019 }
4020
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004021 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4022 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4023 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004024 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004025 }
4026
Johannes Berg4c476992010-10-04 21:36:35 +02004027 if (!haveinfo)
4028 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004029
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004030 if (attrs[NL80211_ATTR_IE]) {
4031 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4032 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004033 }
4034
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004035 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004036 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004037 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004038 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004039 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004040 }
4041
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004042 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004043 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004044 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004045 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004046 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004047 }
4048
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004049 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4050 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4051 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004052 }
4053
Johannes Berg88600202012-02-13 15:17:18 +01004054 return 0;
4055}
4056
Johannes Berg66cd7942017-02-07 22:40:44 +02004057static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4058 const u8 *rates)
4059{
4060 int i;
4061
4062 if (!rates)
4063 return;
4064
4065 for (i = 0; i < rates[1]; i++) {
4066 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4067 params->ht_required = true;
4068 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4069 params->vht_required = true;
4070 }
4071}
4072
4073/*
4074 * Since the nl80211 API didn't include, from the beginning, attributes about
4075 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4076 * benefit of drivers that rebuild IEs in the firmware.
4077 */
4078static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4079{
4080 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004081 size_t ies_len = bcn->tail_len;
4082 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004083 const u8 *rates;
4084 const u8 *cap;
4085
4086 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4087 nl80211_check_ap_rate_selectors(params, rates);
4088
4089 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4090 nl80211_check_ap_rate_selectors(params, rates);
4091
4092 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4093 if (cap && cap[1] >= sizeof(*params->ht_cap))
4094 params->ht_cap = (void *)(cap + 2);
4095 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4096 if (cap && cap[1] >= sizeof(*params->vht_cap))
4097 params->vht_cap = (void *)(cap + 2);
4098}
4099
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004100static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4101 struct cfg80211_ap_settings *params)
4102{
4103 struct wireless_dev *wdev;
4104 bool ret = false;
4105
Johannes Berg53873f12016-05-03 16:52:04 +03004106 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004107 if (wdev->iftype != NL80211_IFTYPE_AP &&
4108 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4109 continue;
4110
Johannes Berg683b6d32012-11-08 21:25:48 +01004111 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004112 continue;
4113
Johannes Berg683b6d32012-11-08 21:25:48 +01004114 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004115 ret = true;
4116 break;
4117 }
4118
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004119 return ret;
4120}
4121
Jouni Malinene39e5b52012-09-30 19:29:39 +03004122static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4123 enum nl80211_auth_type auth_type,
4124 enum nl80211_commands cmd)
4125{
4126 if (auth_type > NL80211_AUTHTYPE_MAX)
4127 return false;
4128
4129 switch (cmd) {
4130 case NL80211_CMD_AUTHENTICATE:
4131 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4132 auth_type == NL80211_AUTHTYPE_SAE)
4133 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004134 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4135 NL80211_EXT_FEATURE_FILS_STA) &&
4136 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4137 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4138 auth_type == NL80211_AUTHTYPE_FILS_PK))
4139 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004140 return true;
4141 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004142 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4143 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004144 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004145
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004146 /* FILS with SK PFS or PK not supported yet */
4147 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4148 auth_type == NL80211_AUTHTYPE_FILS_PK)
4149 return false;
4150 if (!wiphy_ext_feature_isset(
4151 &rdev->wiphy,
4152 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4153 auth_type == NL80211_AUTHTYPE_FILS_SK)
4154 return false;
4155 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004156 case NL80211_CMD_START_AP:
4157 /* SAE not supported yet */
4158 if (auth_type == NL80211_AUTHTYPE_SAE)
4159 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004160 /* FILS not supported yet */
4161 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4162 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4163 auth_type == NL80211_AUTHTYPE_FILS_PK)
4164 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004165 return true;
4166 default:
4167 return false;
4168 }
4169}
4170
Johannes Berg88600202012-02-13 15:17:18 +01004171static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4172{
4173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4174 struct net_device *dev = info->user_ptr[1];
4175 struct wireless_dev *wdev = dev->ieee80211_ptr;
4176 struct cfg80211_ap_settings params;
4177 int err;
4178
4179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4180 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4181 return -EOPNOTSUPP;
4182
4183 if (!rdev->ops->start_ap)
4184 return -EOPNOTSUPP;
4185
4186 if (wdev->beacon_interval)
4187 return -EALREADY;
4188
4189 memset(&params, 0, sizeof(params));
4190
4191 /* these are required for START_AP */
4192 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4193 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4194 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4195 return -EINVAL;
4196
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004197 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004198 if (err)
4199 return err;
4200
4201 params.beacon_interval =
4202 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4203 params.dtim_period =
4204 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4205
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304206 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4207 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004208 if (err)
4209 return err;
4210
4211 /*
4212 * In theory, some of these attributes should be required here
4213 * but since they were not used when the command was originally
4214 * added, keep them optional for old user space programs to let
4215 * them continue to work with drivers that do not need the
4216 * additional information -- drivers must check!
4217 */
4218 if (info->attrs[NL80211_ATTR_SSID]) {
4219 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4220 params.ssid_len =
4221 nla_len(info->attrs[NL80211_ATTR_SSID]);
4222 if (params.ssid_len == 0 ||
4223 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4224 return -EINVAL;
4225 }
4226
4227 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
4228 params.hidden_ssid = nla_get_u32(
4229 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4230 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
4231 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
4232 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
4233 return -EINVAL;
4234 }
4235
4236 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4237
4238 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4239 params.auth_type = nla_get_u32(
4240 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004241 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4242 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004243 return -EINVAL;
4244 } else
4245 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4246
4247 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4248 NL80211_MAX_NR_CIPHER_SUITES);
4249 if (err)
4250 return err;
4251
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304252 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4253 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4254 return -EOPNOTSUPP;
4255 params.inactivity_timeout = nla_get_u16(
4256 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4257 }
4258
Johannes Berg53cabad2012-11-14 15:17:28 +01004259 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4260 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4261 return -EINVAL;
4262 params.p2p_ctwindow =
4263 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4264 if (params.p2p_ctwindow > 127)
4265 return -EINVAL;
4266 if (params.p2p_ctwindow != 0 &&
4267 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4268 return -EINVAL;
4269 }
4270
4271 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4272 u8 tmp;
4273
4274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4275 return -EINVAL;
4276 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4277 if (tmp > 1)
4278 return -EINVAL;
4279 params.p2p_opp_ps = tmp;
4280 if (params.p2p_opp_ps != 0 &&
4281 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4282 return -EINVAL;
4283 }
4284
Johannes Bergaa430da2012-05-16 23:50:18 +02004285 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004286 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4287 if (err)
4288 return err;
4289 } else if (wdev->preset_chandef.chan) {
4290 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004291 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004292 return -EINVAL;
4293
Arik Nemtsov923b3522015-07-08 15:41:44 +03004294 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4295 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004296 return -EINVAL;
4297
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304298 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4299 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4300 if (err)
4301 return err;
4302
Johannes Berg8564e382016-09-19 09:44:44 +02004303 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4304 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304305 if (err)
4306 return err;
4307 }
4308
Eliad Peller18998c32014-09-10 14:07:34 +03004309 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4310 params.smps_mode =
4311 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4312 switch (params.smps_mode) {
4313 case NL80211_SMPS_OFF:
4314 break;
4315 case NL80211_SMPS_STATIC:
4316 if (!(rdev->wiphy.features &
4317 NL80211_FEATURE_STATIC_SMPS))
4318 return -EINVAL;
4319 break;
4320 case NL80211_SMPS_DYNAMIC:
4321 if (!(rdev->wiphy.features &
4322 NL80211_FEATURE_DYNAMIC_SMPS))
4323 return -EINVAL;
4324 break;
4325 default:
4326 return -EINVAL;
4327 }
4328 } else {
4329 params.smps_mode = NL80211_SMPS_OFF;
4330 }
4331
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304332 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4333 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4334 return -EOPNOTSUPP;
4335
Ola Olsson4baf6be2015-10-29 07:04:58 +01004336 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4337 params.acl = parse_acl_data(&rdev->wiphy, info);
4338 if (IS_ERR(params.acl))
4339 return PTR_ERR(params.acl);
4340 }
4341
Johannes Berg66cd7942017-02-07 22:40:44 +02004342 nl80211_calculate_ap_params(&params);
4343
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004344 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004345 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004346 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004347 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004348 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004349 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004350 wdev->ssid_len = params.ssid_len;
4351 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004352
4353 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4354 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004355 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004356 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304357
4358 kfree(params.acl);
4359
Johannes Berg56d18932011-05-09 18:41:15 +02004360 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004361}
4362
Johannes Berg88600202012-02-13 15:17:18 +01004363static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4364{
4365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4366 struct net_device *dev = info->user_ptr[1];
4367 struct wireless_dev *wdev = dev->ieee80211_ptr;
4368 struct cfg80211_beacon_data params;
4369 int err;
4370
4371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4373 return -EOPNOTSUPP;
4374
4375 if (!rdev->ops->change_beacon)
4376 return -EOPNOTSUPP;
4377
4378 if (!wdev->beacon_interval)
4379 return -EINVAL;
4380
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004381 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004382 if (err)
4383 return err;
4384
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004385 wdev_lock(wdev);
4386 err = rdev_change_beacon(rdev, dev, &params);
4387 wdev_unlock(wdev);
4388
4389 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004390}
4391
4392static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004393{
Johannes Berg4c476992010-10-04 21:36:35 +02004394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4395 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004396
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004397 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004398}
4399
Johannes Berg5727ef12007-12-19 02:03:34 +01004400static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4401 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4402 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4403 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004404 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004405 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004406 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004407};
4408
Johannes Bergeccb8e82009-05-11 21:57:56 +03004409static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004410 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004411 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004412{
4413 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004414 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004415 int flag;
4416
Johannes Bergeccb8e82009-05-11 21:57:56 +03004417 /*
4418 * Try parsing the new attribute first so userspace
4419 * can specify both for older kernels.
4420 */
4421 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4422 if (nla) {
4423 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004424
Johannes Bergeccb8e82009-05-11 21:57:56 +03004425 sta_flags = nla_data(nla);
4426 params->sta_flags_mask = sta_flags->mask;
4427 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004428 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004429 if ((params->sta_flags_mask |
4430 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4431 return -EINVAL;
4432 return 0;
4433 }
4434
4435 /* if present, parse the old attribute */
4436
4437 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004438 if (!nla)
4439 return 0;
4440
Johannes Bergfceb6432017-04-12 14:34:07 +02004441 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004442 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004443 return -EINVAL;
4444
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004445 /*
4446 * Only allow certain flags for interface types so that
4447 * other attributes are silently ignored. Remember that
4448 * this is backward compatibility code with old userspace
4449 * and shouldn't be hit in other cases anyway.
4450 */
4451 switch (iftype) {
4452 case NL80211_IFTYPE_AP:
4453 case NL80211_IFTYPE_AP_VLAN:
4454 case NL80211_IFTYPE_P2P_GO:
4455 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4456 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4457 BIT(NL80211_STA_FLAG_WME) |
4458 BIT(NL80211_STA_FLAG_MFP);
4459 break;
4460 case NL80211_IFTYPE_P2P_CLIENT:
4461 case NL80211_IFTYPE_STATION:
4462 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4463 BIT(NL80211_STA_FLAG_TDLS_PEER);
4464 break;
4465 case NL80211_IFTYPE_MESH_POINT:
4466 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4467 BIT(NL80211_STA_FLAG_MFP) |
4468 BIT(NL80211_STA_FLAG_AUTHORIZED);
4469 default:
4470 return -EINVAL;
4471 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004472
Johannes Berg3383b5a2012-05-10 20:14:43 +02004473 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4474 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004475 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004476
Johannes Berg3383b5a2012-05-10 20:14:43 +02004477 /* no longer support new API additions in old API */
4478 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4479 return -EINVAL;
4480 }
4481 }
4482
Johannes Berg5727ef12007-12-19 02:03:34 +01004483 return 0;
4484}
4485
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004486static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4487 int attr)
4488{
4489 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004490 u32 bitrate;
4491 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004492 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004493
4494 rate = nla_nest_start(msg, attr);
4495 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004496 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004497
4498 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4499 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004500 /* report 16-bit bitrate only if we can */
4501 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004502 if (bitrate > 0 &&
4503 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4504 return false;
4505 if (bitrate_compat > 0 &&
4506 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4507 return false;
4508
Johannes Bergb51f3be2015-01-15 16:14:02 +01004509 switch (info->bw) {
4510 case RATE_INFO_BW_5:
4511 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4512 break;
4513 case RATE_INFO_BW_10:
4514 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4515 break;
4516 default:
4517 WARN_ON(1);
4518 /* fall through */
4519 case RATE_INFO_BW_20:
4520 rate_flg = 0;
4521 break;
4522 case RATE_INFO_BW_40:
4523 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4524 break;
4525 case RATE_INFO_BW_80:
4526 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4527 break;
4528 case RATE_INFO_BW_160:
4529 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4530 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004531 case RATE_INFO_BW_HE_RU:
4532 rate_flg = 0;
4533 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01004534 }
4535
4536 if (rate_flg && nla_put_flag(msg, rate_flg))
4537 return false;
4538
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004539 if (info->flags & RATE_INFO_FLAGS_MCS) {
4540 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4541 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004542 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4543 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4544 return false;
4545 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4546 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4547 return false;
4548 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4549 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004550 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4551 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4552 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004553 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
4554 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
4555 return false;
4556 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
4557 return false;
4558 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
4559 return false;
4560 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
4561 return false;
4562 if (info->bw == RATE_INFO_BW_HE_RU &&
4563 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
4564 info->he_ru_alloc))
4565 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004566 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004567
4568 nla_nest_end(msg, rate);
4569 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004570}
4571
Felix Fietkau119363c2013-04-22 16:29:30 +02004572static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4573 int id)
4574{
4575 void *attr;
4576 int i = 0;
4577
4578 if (!mask)
4579 return true;
4580
4581 attr = nla_nest_start(msg, id);
4582 if (!attr)
4583 return false;
4584
4585 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4586 if (!(mask & BIT(i)))
4587 continue;
4588
4589 if (nla_put_u8(msg, i, signal[i]))
4590 return false;
4591 }
4592
4593 nla_nest_end(msg, attr);
4594
4595 return true;
4596}
4597
Johannes Bergcf5ead82014-11-14 17:14:00 +01004598static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4599 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004600 struct cfg80211_registered_device *rdev,
4601 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004602 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004603{
4604 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004605 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004606
Johannes Bergcf5ead82014-11-14 17:14:00 +01004607 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004608 if (!hdr)
4609 return -1;
4610
David S. Miller9360ffd2012-03-29 04:41:26 -04004611 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4612 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4613 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4614 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004615
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4617 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004618 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004619
4620#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004621 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03004622 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004623 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4624 sinfo->memb)) \
4625 goto nla_put_failure; \
4626 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004627#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03004628 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004629 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4630 sinfo->memb, NL80211_STA_INFO_PAD)) \
4631 goto nla_put_failure; \
4632 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004633
4634 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4635 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4636
Omer Efrat397c6572018-06-17 13:06:14 +03004637 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4638 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004639 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004640 (u32)sinfo->rx_bytes))
4641 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004642
Omer Efrat397c6572018-06-17 13:06:14 +03004643 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4644 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004645 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4646 (u32)sinfo->tx_bytes))
4647 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004648
Johannes Bergd686b922016-04-26 09:54:11 +02004649 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4650 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004651 PUT_SINFO(LLID, llid, u16);
4652 PUT_SINFO(PLID, plid, u16);
4653 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004654 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004655
John W. Linville66266b32012-03-15 13:25:41 -04004656 switch (rdev->wiphy.signal_type) {
4657 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004658 PUT_SINFO(SIGNAL, signal, u8);
4659 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004660 break;
4661 default:
4662 break;
4663 }
Omer Efrat397c6572018-06-17 13:06:14 +03004664 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004665 if (!nl80211_put_signal(msg, sinfo->chains,
4666 sinfo->chain_signal,
4667 NL80211_STA_INFO_CHAIN_SIGNAL))
4668 goto nla_put_failure;
4669 }
Omer Efrat397c6572018-06-17 13:06:14 +03004670 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004671 if (!nl80211_put_signal(msg, sinfo->chains,
4672 sinfo->chain_signal_avg,
4673 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4674 goto nla_put_failure;
4675 }
Omer Efrat397c6572018-06-17 13:06:14 +03004676 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004677 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4678 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004679 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004680 }
Omer Efrat397c6572018-06-17 13:06:14 +03004681 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004682 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4683 NL80211_STA_INFO_RX_BITRATE))
4684 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004685 }
Johannes Berg319090b2014-11-17 14:08:11 +01004686
4687 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4688 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4689 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4690 PUT_SINFO(TX_FAILED, tx_failed, u32);
4691 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4692 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4693 PUT_SINFO(LOCAL_PM, local_pm, u32);
4694 PUT_SINFO(PEER_PM, peer_pm, u32);
4695 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4696
Omer Efrat397c6572018-06-17 13:06:14 +03004697 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004698 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4699 if (!bss_param)
4700 goto nla_put_failure;
4701
David S. Miller9360ffd2012-03-29 04:41:26 -04004702 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4703 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4704 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4705 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4706 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4707 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4708 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4709 sinfo->bss_param.dtim_period) ||
4710 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4711 sinfo->bss_param.beacon_interval))
4712 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004713
4714 nla_nest_end(msg, bss_param);
4715 }
Omer Efrat397c6572018-06-17 13:06:14 +03004716 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004717 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4718 sizeof(struct nl80211_sta_flag_update),
4719 &sinfo->sta_flags))
4720 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004721
Johannes Bergd686b922016-04-26 09:54:11 +02004722 PUT_SINFO_U64(T_OFFSET, t_offset);
4723 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4724 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004725 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +05304726 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05304727 if (wiphy_ext_feature_isset(&rdev->wiphy,
4728 NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT))
4729 PUT_SINFO(DATA_ACK_SIGNAL_AVG, avg_ack_signal, s8);
Johannes Berg319090b2014-11-17 14:08:11 +01004730
4731#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004732#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004733
Arend van Spriel8689c052018-05-10 13:50:12 +02004734 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01004735 struct nlattr *tidsattr;
4736 int tid;
4737
4738 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4739 if (!tidsattr)
4740 goto nla_put_failure;
4741
4742 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4743 struct cfg80211_tid_stats *tidstats;
4744 struct nlattr *tidattr;
4745
4746 tidstats = &sinfo->pertid[tid];
4747
4748 if (!tidstats->filled)
4749 continue;
4750
4751 tidattr = nla_nest_start(msg, tid + 1);
4752 if (!tidattr)
4753 goto nla_put_failure;
4754
Johannes Bergd686b922016-04-26 09:54:11 +02004755#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004756 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004757 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4758 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004759 goto nla_put_failure; \
4760 } while (0)
4761
Johannes Bergd686b922016-04-26 09:54:11 +02004762 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4763 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4764 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4765 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004766
Johannes Bergd686b922016-04-26 09:54:11 +02004767#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02004768 if ((tidstats->filled &
4769 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
4770 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
4771 NL80211_TID_STATS_TXQ_STATS))
4772 goto nla_put_failure;
4773
Johannes Berg6de39802014-12-19 12:34:00 +01004774 nla_nest_end(msg, tidattr);
4775 }
4776
4777 nla_nest_end(msg, tidsattr);
4778 }
4779
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004780 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004781
Johannes Berg319090b2014-11-17 14:08:11 +01004782 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004783 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4784 sinfo->assoc_req_ies))
4785 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004786
Johannes Berg7ea3e112018-05-18 11:40:44 +02004787 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01004788 genlmsg_end(msg, hdr);
4789 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004790
4791 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02004792 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07004793 genlmsg_cancel(msg, hdr);
4794 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004795}
4796
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004797static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004798 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004799{
Johannes Berg73887fd2018-05-18 09:57:55 +02004800 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004801 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004802 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004803 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004804 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004805 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004806
Johannes Bergea90e0d2017-03-15 14:26:04 +01004807 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004808 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004809 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004810 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004811
Johannes Berg97990a02013-04-19 01:02:55 +02004812 if (!wdev->netdev) {
4813 err = -EINVAL;
4814 goto out_err;
4815 }
4816
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004817 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004818 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004819 goto out_err;
4820 }
4821
Johannes Bergbba95fe2008-07-29 13:22:51 +02004822 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02004823 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004824 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02004825 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004826 if (err == -ENOENT)
4827 break;
4828 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004829 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004830
Johannes Bergcf5ead82014-11-14 17:14:00 +01004831 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004832 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004833 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004834 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02004835 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02004836 goto out;
4837
4838 sta_idx++;
4839 }
4840
Johannes Bergbba95fe2008-07-29 13:22:51 +02004841 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004842 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004843 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004844 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004845 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004846
4847 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004848}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004849
Johannes Berg5727ef12007-12-19 02:03:34 +01004850static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4851{
Johannes Berg4c476992010-10-04 21:36:35 +02004852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4853 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02004854 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004855 struct sk_buff *msg;
4856 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004857 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004858
Johannes Berg73887fd2018-05-18 09:57:55 +02004859 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004860
Johannes Berg73887fd2018-05-18 09:57:55 +02004861 if (!info->attrs[NL80211_ATTR_MAC])
4862 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004863
4864 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4865
Johannes Berg73887fd2018-05-18 09:57:55 +02004866 if (!rdev->ops->get_station)
4867 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004868
Johannes Berg73887fd2018-05-18 09:57:55 +02004869 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004870 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02004871 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004872
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004873 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02004874 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05004875 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02004876 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02004877 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004878
Johannes Bergcf5ead82014-11-14 17:14:00 +01004879 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4880 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02004881 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004882 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02004883 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02004884 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004885
Johannes Berg73887fd2018-05-18 09:57:55 +02004886 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004887}
4888
Johannes Berg77ee7c82013-02-15 00:48:33 +01004889int cfg80211_check_station_change(struct wiphy *wiphy,
4890 struct station_parameters *params,
4891 enum cfg80211_station_type statype)
4892{
Ayala Bekere4208422015-10-23 11:20:06 +03004893 if (params->listen_interval != -1 &&
4894 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004895 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004896
Ayala Beker17b94242016-03-17 15:41:38 +02004897 if (params->support_p2p_ps != -1 &&
4898 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4899 return -EINVAL;
4900
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004901 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004902 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4903 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004904 return -EINVAL;
4905
4906 /* When you run into this, adjust the code below for the new flag */
4907 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4908
4909 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004910 case CFG80211_STA_MESH_PEER_KERNEL:
4911 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004912 /*
4913 * No ignoring the TDLS flag here -- the userspace mesh
4914 * code doesn't have the bug of including TDLS in the
4915 * mask everywhere.
4916 */
4917 if (params->sta_flags_mask &
4918 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4919 BIT(NL80211_STA_FLAG_MFP) |
4920 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4921 return -EINVAL;
4922 break;
4923 case CFG80211_STA_TDLS_PEER_SETUP:
4924 case CFG80211_STA_TDLS_PEER_ACTIVE:
4925 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4926 return -EINVAL;
4927 /* ignore since it can't change */
4928 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4929 break;
4930 default:
4931 /* disallow mesh-specific things */
4932 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4933 return -EINVAL;
4934 if (params->local_pm)
4935 return -EINVAL;
4936 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4937 return -EINVAL;
4938 }
4939
4940 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4941 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4942 /* TDLS can't be set, ... */
4943 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4944 return -EINVAL;
4945 /*
4946 * ... but don't bother the driver with it. This works around
4947 * a hostapd/wpa_supplicant issue -- it always includes the
4948 * TLDS_PEER flag in the mask even for AP mode.
4949 */
4950 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4951 }
4952
Ayala Beker47edb112015-09-21 15:49:53 +03004953 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4954 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004955 /* reject other things that can't change */
4956 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4957 return -EINVAL;
4958 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4959 return -EINVAL;
4960 if (params->supported_rates)
4961 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03004962 if (params->ext_capab || params->ht_capa || params->vht_capa ||
4963 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004964 return -EINVAL;
4965 }
4966
Ayala Beker47edb112015-09-21 15:49:53 +03004967 if (statype != CFG80211_STA_AP_CLIENT &&
4968 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004969 if (params->vlan)
4970 return -EINVAL;
4971 }
4972
4973 switch (statype) {
4974 case CFG80211_STA_AP_MLME_CLIENT:
4975 /* Use this only for authorizing/unauthorizing a station */
4976 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4977 return -EOPNOTSUPP;
4978 break;
4979 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004980 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004981 /* accept only the listed bits */
4982 if (params->sta_flags_mask &
4983 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4984 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4985 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4986 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4987 BIT(NL80211_STA_FLAG_WME) |
4988 BIT(NL80211_STA_FLAG_MFP)))
4989 return -EINVAL;
4990
4991 /* but authenticated/associated only if driver handles it */
4992 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4993 params->sta_flags_mask &
4994 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4995 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4996 return -EINVAL;
4997 break;
4998 case CFG80211_STA_IBSS:
4999 case CFG80211_STA_AP_STA:
5000 /* reject any changes other than AUTHORIZED */
5001 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5002 return -EINVAL;
5003 break;
5004 case CFG80211_STA_TDLS_PEER_SETUP:
5005 /* reject any changes other than AUTHORIZED or WME */
5006 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5007 BIT(NL80211_STA_FLAG_WME)))
5008 return -EINVAL;
5009 /* force (at least) rates when authorizing */
5010 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5011 !params->supported_rates)
5012 return -EINVAL;
5013 break;
5014 case CFG80211_STA_TDLS_PEER_ACTIVE:
5015 /* reject any changes */
5016 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005017 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005018 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5019 return -EINVAL;
5020 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005021 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005022 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5023 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005024 return -EINVAL;
5025 break;
5026 }
5027
Beni Lev06f7c882016-07-19 19:28:56 +03005028 /*
5029 * Older kernel versions ignored this attribute entirely, so don't
5030 * reject attempts to update it but mark it as unused instead so the
5031 * driver won't look at the data.
5032 */
5033 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5034 statype != CFG80211_STA_TDLS_PEER_SETUP)
5035 params->opmode_notif_used = false;
5036
Johannes Berg77ee7c82013-02-15 00:48:33 +01005037 return 0;
5038}
5039EXPORT_SYMBOL(cfg80211_check_station_change);
5040
Johannes Berg5727ef12007-12-19 02:03:34 +01005041/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005042 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005043 */
Johannes Berg80b99892011-11-18 16:23:01 +01005044static struct net_device *get_vlan(struct genl_info *info,
5045 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005046{
Johannes Berg463d0182009-07-14 00:33:35 +02005047 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005048 struct net_device *v;
5049 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005050
Johannes Berg80b99892011-11-18 16:23:01 +01005051 if (!vlanattr)
5052 return NULL;
5053
5054 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5055 if (!v)
5056 return ERR_PTR(-ENODEV);
5057
5058 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5059 ret = -EINVAL;
5060 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005061 }
Johannes Berg80b99892011-11-18 16:23:01 +01005062
Johannes Berg77ee7c82013-02-15 00:48:33 +01005063 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5064 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5065 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5066 ret = -EINVAL;
5067 goto error;
5068 }
5069
Johannes Berg80b99892011-11-18 16:23:01 +01005070 if (!netif_running(v)) {
5071 ret = -ENETDOWN;
5072 goto error;
5073 }
5074
5075 return v;
5076 error:
5077 dev_put(v);
5078 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005079}
5080
Johannes Berg94e860f2014-01-20 23:58:15 +01005081static const struct nla_policy
5082nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005083 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5084 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5085};
5086
Johannes Bergff276692013-02-15 00:09:01 +01005087static int nl80211_parse_sta_wme(struct genl_info *info,
5088 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005089{
Jouni Malinendf881292013-02-14 21:10:54 +02005090 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5091 struct nlattr *nla;
5092 int err;
5093
Jouni Malinendf881292013-02-14 21:10:54 +02005094 /* parse WME attributes if present */
5095 if (!info->attrs[NL80211_ATTR_STA_WME])
5096 return 0;
5097
5098 nla = info->attrs[NL80211_ATTR_STA_WME];
5099 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02005100 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005101 if (err)
5102 return err;
5103
5104 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5105 params->uapsd_queues = nla_get_u8(
5106 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5107 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5108 return -EINVAL;
5109
5110 if (tb[NL80211_STA_WME_MAX_SP])
5111 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5112
5113 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5114 return -EINVAL;
5115
5116 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5117
5118 return 0;
5119}
5120
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305121static int nl80211_parse_sta_channel_info(struct genl_info *info,
5122 struct station_parameters *params)
5123{
5124 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5125 params->supported_channels =
5126 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5127 params->supported_channels_len =
5128 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5129 /*
5130 * Need to include at least one (first channel, number of
5131 * channels) tuple for each subband, and must have proper
5132 * tuples for the rest of the data as well.
5133 */
5134 if (params->supported_channels_len < 2)
5135 return -EINVAL;
5136 if (params->supported_channels_len % 2)
5137 return -EINVAL;
5138 }
5139
5140 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5141 params->supported_oper_classes =
5142 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5143 params->supported_oper_classes_len =
5144 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5145 /*
5146 * The value of the Length field of the Supported Operating
5147 * Classes element is between 2 and 253.
5148 */
5149 if (params->supported_oper_classes_len < 2 ||
5150 params->supported_oper_classes_len > 253)
5151 return -EINVAL;
5152 }
5153 return 0;
5154}
5155
Johannes Bergff276692013-02-15 00:09:01 +01005156static int nl80211_set_station_tdls(struct genl_info *info,
5157 struct station_parameters *params)
5158{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305159 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005160 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005161 if (info->attrs[NL80211_ATTR_PEER_AID])
5162 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005163 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5164 params->ht_capa =
5165 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5166 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5167 params->vht_capa =
5168 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005169 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5170 params->he_capa =
5171 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5172 params->he_capa_len =
5173 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5174
5175 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5176 return -EINVAL;
5177 }
Johannes Bergff276692013-02-15 00:09:01 +01005178
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305179 err = nl80211_parse_sta_channel_info(info, params);
5180 if (err)
5181 return err;
5182
Johannes Bergff276692013-02-15 00:09:01 +01005183 return nl80211_parse_sta_wme(info, params);
5184}
5185
Johannes Berg5727ef12007-12-19 02:03:34 +01005186static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5187{
Johannes Berg4c476992010-10-04 21:36:35 +02005188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005189 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005190 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005191 u8 *mac_addr;
5192 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005193
5194 memset(&params, 0, sizeof(params));
5195
Johannes Berg77ee7c82013-02-15 00:48:33 +01005196 if (!rdev->ops->change_station)
5197 return -EOPNOTSUPP;
5198
Ayala Bekere4208422015-10-23 11:20:06 +03005199 /*
5200 * AID and listen_interval properties can be set only for unassociated
5201 * station. Include these parameters here and will check them in
5202 * cfg80211_check_station_change().
5203 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005204 if (info->attrs[NL80211_ATTR_STA_AID])
5205 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005206
5207 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5208 params.listen_interval =
5209 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5210 else
5211 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005212
Ayala Beker17b94242016-03-17 15:41:38 +02005213 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5214 u8 tmp;
5215
5216 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5217 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5218 return -EINVAL;
5219
5220 params.support_p2p_ps = tmp;
5221 } else {
5222 params.support_p2p_ps = -1;
5223 }
5224
Johannes Berg5727ef12007-12-19 02:03:34 +01005225 if (!info->attrs[NL80211_ATTR_MAC])
5226 return -EINVAL;
5227
5228 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5229
5230 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5231 params.supported_rates =
5232 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5233 params.supported_rates_len =
5234 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5235 }
5236
Jouni Malinen9d62a982013-02-14 21:10:13 +02005237 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5238 params.capability =
5239 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5240 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5241 }
5242
5243 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5244 params.ext_capab =
5245 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5246 params.ext_capab_len =
5247 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5248 }
5249
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005250 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005251 return -EINVAL;
5252
Johannes Bergf8bacc22013-02-14 23:27:01 +01005253 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005254 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005255 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5256 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5257 return -EINVAL;
5258 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005259
Johannes Bergf8bacc22013-02-14 23:27:01 +01005260 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005261 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005262 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
5263 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
5264 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005265 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
5266 params.peer_aid = nla_get_u16(
5267 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
5268 if (params.peer_aid > IEEE80211_MAX_AID)
5269 return -EINVAL;
5270 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01005271 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5272 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005273
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005274 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
5275 enum nl80211_mesh_power_mode pm = nla_get_u32(
5276 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5277
5278 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
5279 pm > NL80211_MESH_POWER_MAX)
5280 return -EINVAL;
5281
5282 params.local_pm = pm;
5283 }
5284
Beni Lev06f7c882016-07-19 19:28:56 +03005285 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5286 params.opmode_notif_used = true;
5287 params.opmode_notif =
5288 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5289 }
5290
Johannes Berg77ee7c82013-02-15 00:48:33 +01005291 /* Include parameters for TDLS peer (will check later) */
5292 err = nl80211_set_station_tdls(info, &params);
5293 if (err)
5294 return err;
5295
5296 params.vlan = get_vlan(info, rdev);
5297 if (IS_ERR(params.vlan))
5298 return PTR_ERR(params.vlan);
5299
Johannes Berga97f4422009-06-18 17:23:43 +02005300 switch (dev->ieee80211_ptr->iftype) {
5301 case NL80211_IFTYPE_AP:
5302 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005303 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005304 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005305 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005306 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005307 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005308 break;
5309 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005310 err = -EOPNOTSUPP;
5311 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005312 }
5313
Johannes Berg77ee7c82013-02-15 00:48:33 +01005314 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005315 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005316
Johannes Berg77ee7c82013-02-15 00:48:33 +01005317 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005318 if (params.vlan)
5319 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005320
Johannes Berg5727ef12007-12-19 02:03:34 +01005321 return err;
5322}
5323
5324static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5325{
Johannes Berg4c476992010-10-04 21:36:35 +02005326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005327 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005328 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005329 struct station_parameters params;
5330 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005331 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5332 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005333
5334 memset(&params, 0, sizeof(params));
5335
Johannes Berg984c3112013-02-14 23:43:25 +01005336 if (!rdev->ops->add_station)
5337 return -EOPNOTSUPP;
5338
Johannes Berg5727ef12007-12-19 02:03:34 +01005339 if (!info->attrs[NL80211_ATTR_MAC])
5340 return -EINVAL;
5341
Johannes Berg5727ef12007-12-19 02:03:34 +01005342 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5343 return -EINVAL;
5344
5345 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5346 return -EINVAL;
5347
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005348 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5349 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005350 return -EINVAL;
5351
Johannes Berg5727ef12007-12-19 02:03:34 +01005352 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5353 params.supported_rates =
5354 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5355 params.supported_rates_len =
5356 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5357 params.listen_interval =
5358 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005359
Ayala Beker17b94242016-03-17 15:41:38 +02005360 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5361 u8 tmp;
5362
5363 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5364 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5365 return -EINVAL;
5366
5367 params.support_p2p_ps = tmp;
5368 } else {
5369 /*
5370 * if not specified, assume it's supported for P2P GO interface,
5371 * and is NOT supported for AP interface
5372 */
5373 params.support_p2p_ps =
5374 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5375 }
5376
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005377 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005378 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005379 else
5380 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005381 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5382 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005383
Jouni Malinen9d62a982013-02-14 21:10:13 +02005384 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5385 params.capability =
5386 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5387 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5388 }
5389
5390 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5391 params.ext_capab =
5392 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5393 params.ext_capab_len =
5394 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5395 }
5396
Jouni Malinen36aedc92008-08-25 11:58:58 +03005397 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5398 params.ht_capa =
5399 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005400
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005401 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5402 params.vht_capa =
5403 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5404
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005405 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5406 params.he_capa =
5407 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5408 params.he_capa_len =
5409 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5410
5411 /* max len is validated in nla policy */
5412 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5413 return -EINVAL;
5414 }
5415
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005416 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5417 params.opmode_notif_used = true;
5418 params.opmode_notif =
5419 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5420 }
5421
Johannes Bergf8bacc22013-02-14 23:27:01 +01005422 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005423 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005424 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5425 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5426 return -EINVAL;
5427 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005428
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305429 err = nl80211_parse_sta_channel_info(info, &params);
5430 if (err)
5431 return err;
5432
Johannes Bergff276692013-02-15 00:09:01 +01005433 err = nl80211_parse_sta_wme(info, &params);
5434 if (err)
5435 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005436
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005437 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005438 return -EINVAL;
5439
Johannes Berg496fcc22015-03-12 08:53:27 +02005440 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5441 * as userspace might just pass through the capabilities from the IEs
5442 * directly, rather than enforcing this restriction and returning an
5443 * error in this case.
5444 */
5445 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5446 params.ht_capa = NULL;
5447 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005448
5449 /* HE requires WME */
5450 if (params.he_capa_len)
5451 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02005452 }
5453
Johannes Berg77ee7c82013-02-15 00:48:33 +01005454 /* When you run into this, adjust the code below for the new flag */
5455 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5456
Johannes Bergbdd90d52011-12-14 12:20:27 +01005457 switch (dev->ieee80211_ptr->iftype) {
5458 case NL80211_IFTYPE_AP:
5459 case NL80211_IFTYPE_AP_VLAN:
5460 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005461 /* ignore WME attributes if iface/sta is not capable */
5462 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5463 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5464 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005465
Johannes Bergbdd90d52011-12-14 12:20:27 +01005466 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005467 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5468 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005469 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005470 /* but don't bother the driver with it */
5471 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005472
Johannes Bergd582cff2012-10-26 17:53:44 +02005473 /* allow authenticated/associated only if driver handles it */
5474 if (!(rdev->wiphy.features &
5475 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005476 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005477 return -EINVAL;
5478
Johannes Bergbda95eb2015-11-26 16:26:13 +01005479 /* Older userspace, or userspace wanting to be compatible with
5480 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5481 * and assoc flags in the mask, but assumes the station will be
5482 * added as associated anyway since this was the required driver
5483 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5484 * introduced.
5485 * In order to not bother drivers with this quirk in the API
5486 * set the flags in both the mask and set for new stations in
5487 * this case.
5488 */
5489 if (!(params.sta_flags_mask & auth_assoc)) {
5490 params.sta_flags_mask |= auth_assoc;
5491 params.sta_flags_set |= auth_assoc;
5492 }
5493
Johannes Bergbdd90d52011-12-14 12:20:27 +01005494 /* must be last in here for error handling */
5495 params.vlan = get_vlan(info, rdev);
5496 if (IS_ERR(params.vlan))
5497 return PTR_ERR(params.vlan);
5498 break;
5499 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005500 /* ignore uAPSD data */
5501 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5502
Johannes Bergd582cff2012-10-26 17:53:44 +02005503 /* associated is disallowed */
5504 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5505 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005506 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005507 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5508 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005509 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005510 break;
5511 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005512 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005513 /* ignore uAPSD data */
5514 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5515
Johannes Berg77ee7c82013-02-15 00:48:33 +01005516 /* these are disallowed */
5517 if (params.sta_flags_mask &
5518 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5519 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005520 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005521 /* Only TDLS peers can be added */
5522 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5523 return -EINVAL;
5524 /* Can only add if TDLS ... */
5525 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5526 return -EOPNOTSUPP;
5527 /* ... with external setup is supported */
5528 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5529 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005530 /*
5531 * Older wpa_supplicant versions always mark the TDLS peer
5532 * as authorized, but it shouldn't yet be.
5533 */
5534 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005535 break;
5536 default:
5537 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005538 }
5539
Johannes Bergbdd90d52011-12-14 12:20:27 +01005540 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005541
Hila Gonene35e4d22012-06-27 17:19:42 +03005542 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005543
Johannes Berg5727ef12007-12-19 02:03:34 +01005544 if (params.vlan)
5545 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005546 return err;
5547}
5548
5549static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5550{
Johannes Berg4c476992010-10-04 21:36:35 +02005551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5552 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005553 struct station_del_parameters params;
5554
5555 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005556
5557 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005558 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005559
Johannes Berge80cf852009-05-11 14:43:13 +02005560 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005561 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005562 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005563 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5564 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005565
Johannes Berg4c476992010-10-04 21:36:35 +02005566 if (!rdev->ops->del_station)
5567 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005568
Jouni Malinen98856862014-10-20 13:20:45 +03005569 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5570 params.subtype =
5571 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5572 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5573 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5574 return -EINVAL;
5575 } else {
5576 /* Default to Deauthentication frame */
5577 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5578 }
5579
5580 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5581 params.reason_code =
5582 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5583 if (params.reason_code == 0)
5584 return -EINVAL; /* 0 is reserved */
5585 } else {
5586 /* Default to reason code 2 */
5587 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5588 }
5589
Jouni Malinen89c771e2014-10-10 20:52:40 +03005590 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005591}
5592
Eric W. Biederman15e47302012-09-07 20:12:54 +00005593static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005594 int flags, struct net_device *dev,
5595 u8 *dst, u8 *next_hop,
5596 struct mpath_info *pinfo)
5597{
5598 void *hdr;
5599 struct nlattr *pinfoattr;
5600
Henning Rogge1ef4c852014-11-04 16:14:58 +01005601 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005602 if (!hdr)
5603 return -1;
5604
David S. Miller9360ffd2012-03-29 04:41:26 -04005605 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5607 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5608 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5609 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005610
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005611 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5612 if (!pinfoattr)
5613 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005614 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5615 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5616 pinfo->frame_qlen))
5617 goto nla_put_failure;
5618 if (((pinfo->filled & MPATH_INFO_SN) &&
5619 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5620 ((pinfo->filled & MPATH_INFO_METRIC) &&
5621 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5622 pinfo->metric)) ||
5623 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5624 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5625 pinfo->exptime)) ||
5626 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5627 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5628 pinfo->flags)) ||
5629 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5630 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5631 pinfo->discovery_timeout)) ||
5632 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5633 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5634 pinfo->discovery_retries)))
5635 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005636
5637 nla_nest_end(msg, pinfoattr);
5638
Johannes Berg053c0952015-01-16 22:09:00 +01005639 genlmsg_end(msg, hdr);
5640 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005641
5642 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005643 genlmsg_cancel(msg, hdr);
5644 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005645}
5646
5647static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005648 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005649{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005650 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005651 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005652 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005653 u8 dst[ETH_ALEN];
5654 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005655 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005656 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005657
Johannes Bergea90e0d2017-03-15 14:26:04 +01005658 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005659 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005660 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005661 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005663 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005664 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005665 goto out_err;
5666 }
5667
Johannes Berg97990a02013-04-19 01:02:55 +02005668 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005669 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005670 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005671 }
5672
Johannes Bergbba95fe2008-07-29 13:22:51 +02005673 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005674 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005675 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005676 if (err == -ENOENT)
5677 break;
5678 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005679 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005680
Eric W. Biederman15e47302012-09-07 20:12:54 +00005681 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005682 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005683 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005684 &pinfo) < 0)
5685 goto out;
5686
5687 path_idx++;
5688 }
5689
Johannes Bergbba95fe2008-07-29 13:22:51 +02005690 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005691 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005692 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005693 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005694 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005695 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005696}
5697
5698static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5699{
Johannes Berg4c476992010-10-04 21:36:35 +02005700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005701 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005702 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005703 struct mpath_info pinfo;
5704 struct sk_buff *msg;
5705 u8 *dst = NULL;
5706 u8 next_hop[ETH_ALEN];
5707
5708 memset(&pinfo, 0, sizeof(pinfo));
5709
5710 if (!info->attrs[NL80211_ATTR_MAC])
5711 return -EINVAL;
5712
5713 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5714
Johannes Berg4c476992010-10-04 21:36:35 +02005715 if (!rdev->ops->get_mpath)
5716 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005717
Johannes Berg4c476992010-10-04 21:36:35 +02005718 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5719 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005720
Hila Gonene35e4d22012-06-27 17:19:42 +03005721 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005722 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005723 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005724
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005725 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005726 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005727 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005728
Eric W. Biederman15e47302012-09-07 20:12:54 +00005729 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005730 dev, dst, next_hop, &pinfo) < 0) {
5731 nlmsg_free(msg);
5732 return -ENOBUFS;
5733 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005734
Johannes Berg4c476992010-10-04 21:36:35 +02005735 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005736}
5737
5738static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5739{
Johannes Berg4c476992010-10-04 21:36:35 +02005740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5741 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005742 u8 *dst = NULL;
5743 u8 *next_hop = NULL;
5744
5745 if (!info->attrs[NL80211_ATTR_MAC])
5746 return -EINVAL;
5747
5748 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5749 return -EINVAL;
5750
5751 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5752 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5753
Johannes Berg4c476992010-10-04 21:36:35 +02005754 if (!rdev->ops->change_mpath)
5755 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005756
Johannes Berg4c476992010-10-04 21:36:35 +02005757 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5758 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005759
Hila Gonene35e4d22012-06-27 17:19:42 +03005760 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005761}
Johannes Berg4c476992010-10-04 21:36:35 +02005762
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005763static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5764{
Johannes Berg4c476992010-10-04 21:36:35 +02005765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5766 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005767 u8 *dst = NULL;
5768 u8 *next_hop = NULL;
5769
5770 if (!info->attrs[NL80211_ATTR_MAC])
5771 return -EINVAL;
5772
5773 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5774 return -EINVAL;
5775
5776 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5777 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5778
Johannes Berg4c476992010-10-04 21:36:35 +02005779 if (!rdev->ops->add_mpath)
5780 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005781
Johannes Berg4c476992010-10-04 21:36:35 +02005782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5783 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005784
Hila Gonene35e4d22012-06-27 17:19:42 +03005785 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005786}
5787
5788static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5789{
Johannes Berg4c476992010-10-04 21:36:35 +02005790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5791 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005792 u8 *dst = NULL;
5793
5794 if (info->attrs[NL80211_ATTR_MAC])
5795 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5796
Johannes Berg4c476992010-10-04 21:36:35 +02005797 if (!rdev->ops->del_mpath)
5798 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005799
Hila Gonene35e4d22012-06-27 17:19:42 +03005800 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005801}
5802
Henning Rogge66be7d22014-09-12 08:58:49 +02005803static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5804{
5805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5806 int err;
5807 struct net_device *dev = info->user_ptr[1];
5808 struct mpath_info pinfo;
5809 struct sk_buff *msg;
5810 u8 *dst = NULL;
5811 u8 mpp[ETH_ALEN];
5812
5813 memset(&pinfo, 0, sizeof(pinfo));
5814
5815 if (!info->attrs[NL80211_ATTR_MAC])
5816 return -EINVAL;
5817
5818 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5819
5820 if (!rdev->ops->get_mpp)
5821 return -EOPNOTSUPP;
5822
5823 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5824 return -EOPNOTSUPP;
5825
5826 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5827 if (err)
5828 return err;
5829
5830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5831 if (!msg)
5832 return -ENOMEM;
5833
5834 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5835 dev, dst, mpp, &pinfo) < 0) {
5836 nlmsg_free(msg);
5837 return -ENOBUFS;
5838 }
5839
5840 return genlmsg_reply(msg, info);
5841}
5842
5843static int nl80211_dump_mpp(struct sk_buff *skb,
5844 struct netlink_callback *cb)
5845{
5846 struct mpath_info pinfo;
5847 struct cfg80211_registered_device *rdev;
5848 struct wireless_dev *wdev;
5849 u8 dst[ETH_ALEN];
5850 u8 mpp[ETH_ALEN];
5851 int path_idx = cb->args[2];
5852 int err;
5853
Johannes Bergea90e0d2017-03-15 14:26:04 +01005854 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005855 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5856 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005857 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005858
5859 if (!rdev->ops->dump_mpp) {
5860 err = -EOPNOTSUPP;
5861 goto out_err;
5862 }
5863
5864 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5865 err = -EOPNOTSUPP;
5866 goto out_err;
5867 }
5868
5869 while (1) {
5870 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5871 mpp, &pinfo);
5872 if (err == -ENOENT)
5873 break;
5874 if (err)
5875 goto out_err;
5876
5877 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5878 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5879 wdev->netdev, dst, mpp,
5880 &pinfo) < 0)
5881 goto out;
5882
5883 path_idx++;
5884 }
5885
5886 out:
5887 cb->args[2] = path_idx;
5888 err = skb->len;
5889 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005890 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005891 return err;
5892}
5893
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005894static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5895{
Johannes Berg4c476992010-10-04 21:36:35 +02005896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5897 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005898 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005899 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005900 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005901
5902 memset(&params, 0, sizeof(params));
5903 /* default to not changing parameters */
5904 params.use_cts_prot = -1;
5905 params.use_short_preamble = -1;
5906 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005907 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005908 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005909 params.p2p_ctwindow = -1;
5910 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005911
5912 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5913 params.use_cts_prot =
5914 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5915 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5916 params.use_short_preamble =
5917 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5918 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5919 params.use_short_slot_time =
5920 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005921 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5922 params.basic_rates =
5923 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5924 params.basic_rates_len =
5925 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5926 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005927 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5928 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005929 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5930 params.ht_opmode =
5931 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005932
Johannes Berg53cabad2012-11-14 15:17:28 +01005933 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5934 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5935 return -EINVAL;
5936 params.p2p_ctwindow =
5937 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5938 if (params.p2p_ctwindow < 0)
5939 return -EINVAL;
5940 if (params.p2p_ctwindow != 0 &&
5941 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5942 return -EINVAL;
5943 }
5944
5945 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5946 u8 tmp;
5947
5948 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5949 return -EINVAL;
5950 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5951 if (tmp > 1)
5952 return -EINVAL;
5953 params.p2p_opp_ps = tmp;
5954 if (params.p2p_opp_ps &&
5955 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5956 return -EINVAL;
5957 }
5958
Johannes Berg4c476992010-10-04 21:36:35 +02005959 if (!rdev->ops->change_bss)
5960 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005961
Johannes Berg074ac8d2010-09-16 14:58:22 +02005962 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5964 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005965
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005966 wdev_lock(wdev);
5967 err = rdev_change_bss(rdev, dev, &params);
5968 wdev_unlock(wdev);
5969
5970 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005971}
5972
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005973static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5974{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005975 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005976 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005977 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005978 u32 owner_nlportid;
5979
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005980 /*
5981 * You should only get this when cfg80211 hasn't yet initialized
5982 * completely when built-in to the kernel right between the time
5983 * window between nl80211_init() and regulatory_init(), if that is
5984 * even possible.
5985 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005986 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005987 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005988
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005989 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5990 user_reg_hint_type =
5991 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5992 else
5993 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5994
5995 switch (user_reg_hint_type) {
5996 case NL80211_USER_REG_HINT_USER:
5997 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005998 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5999 return -EINVAL;
6000
6001 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6002 return regulatory_hint_user(data, user_reg_hint_type);
6003 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006004 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6005 owner_nlportid = info->snd_portid;
6006 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6007 } else {
6008 owner_nlportid = 0;
6009 is_indoor = true;
6010 }
6011
6012 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006013 default:
6014 return -EINVAL;
6015 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006016}
6017
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006018static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6019{
6020 return reg_reload_regdb();
6021}
6022
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006023static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006024 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006025{
Johannes Berg4c476992010-10-04 21:36:35 +02006026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006027 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006028 struct wireless_dev *wdev = dev->ieee80211_ptr;
6029 struct mesh_config cur_params;
6030 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006031 void *hdr;
6032 struct nlattr *pinfoattr;
6033 struct sk_buff *msg;
6034
Johannes Berg29cbe682010-12-03 09:20:44 +01006035 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6036 return -EOPNOTSUPP;
6037
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006038 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006039 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006040
Johannes Berg29cbe682010-12-03 09:20:44 +01006041 wdev_lock(wdev);
6042 /* If not connected, get default parameters */
6043 if (!wdev->mesh_id_len)
6044 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6045 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006046 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006047 wdev_unlock(wdev);
6048
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006049 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006050 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006051
6052 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006053 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006054 if (!msg)
6055 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006056 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006057 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006058 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006059 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006060 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006061 if (!pinfoattr)
6062 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006063 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6064 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6065 cur_params.dot11MeshRetryTimeout) ||
6066 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6067 cur_params.dot11MeshConfirmTimeout) ||
6068 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6069 cur_params.dot11MeshHoldingTimeout) ||
6070 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6071 cur_params.dot11MeshMaxPeerLinks) ||
6072 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6073 cur_params.dot11MeshMaxRetries) ||
6074 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6075 cur_params.dot11MeshTTL) ||
6076 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6077 cur_params.element_ttl) ||
6078 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6079 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006080 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6081 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006082 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6083 cur_params.dot11MeshHWMPmaxPREQretries) ||
6084 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6085 cur_params.path_refresh_time) ||
6086 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6087 cur_params.min_discovery_timeout) ||
6088 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6089 cur_params.dot11MeshHWMPactivePathTimeout) ||
6090 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6091 cur_params.dot11MeshHWMPpreqMinInterval) ||
6092 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6093 cur_params.dot11MeshHWMPperrMinInterval) ||
6094 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6095 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6096 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6097 cur_params.dot11MeshHWMPRootMode) ||
6098 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6099 cur_params.dot11MeshHWMPRannInterval) ||
6100 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6101 cur_params.dot11MeshGateAnnouncementProtocol) ||
6102 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6103 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006104 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006105 cur_params.rssi_threshold) ||
6106 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006107 cur_params.ht_opmode) ||
6108 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6109 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6110 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006111 cur_params.dot11MeshHWMProotInterval) ||
6112 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006113 cur_params.dot11MeshHWMPconfirmationInterval) ||
6114 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6115 cur_params.power_mode) ||
6116 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006117 cur_params.dot11MeshAwakeWindowDuration) ||
6118 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
6119 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04006120 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006121 nla_nest_end(msg, pinfoattr);
6122 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006123 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006124
Johannes Berg3b858752009-03-12 09:55:09 +01006125 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006126 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006127 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006128 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006129}
6130
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006131static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006132 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
6133 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
6134 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
6135 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
6136 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
6137 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01006138 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006139 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07006140 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006141 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6142 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
6143 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
6144 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
6145 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08006146 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006147 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07006148 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07006149 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07006150 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08006151 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006152 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
6153 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006154 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
6155 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006156 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006157 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
6158 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006159 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006160};
6161
Javier Cardonac80d5452010-12-16 17:37:49 -08006162static const struct nla_policy
6163 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006164 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006165 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6166 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006167 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006168 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006169 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07006170 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006171 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07006172 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006173};
6174
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006175static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
6176{
6177 u8 val = nla_get_u8(nla);
6178 if (val < min || val > max)
6179 return -EINVAL;
6180 *out = val;
6181 return 0;
6182}
6183
6184static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
6185{
6186 u8 val = nla_get_u8(nla);
6187 if (val < min || val > max)
6188 return -EINVAL;
6189 *out = val;
6190 return 0;
6191}
6192
6193static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
6194{
6195 u16 val = nla_get_u16(nla);
6196 if (val < min || val > max)
6197 return -EINVAL;
6198 *out = val;
6199 return 0;
6200}
6201
6202static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
6203{
6204 u32 val = nla_get_u32(nla);
6205 if (val < min || val > max)
6206 return -EINVAL;
6207 *out = val;
6208 return 0;
6209}
6210
6211static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
6212{
6213 s32 val = nla_get_s32(nla);
6214 if (val < min || val > max)
6215 return -EINVAL;
6216 *out = val;
6217 return 0;
6218}
6219
Johannes Bergff9a71a2016-08-11 14:59:53 +02006220static int nl80211_check_power_mode(const struct nlattr *nla,
6221 enum nl80211_mesh_power_mode min,
6222 enum nl80211_mesh_power_mode max,
6223 enum nl80211_mesh_power_mode *out)
6224{
6225 u32 val = nla_get_u32(nla);
6226 if (val < min || val > max)
6227 return -EINVAL;
6228 *out = val;
6229 return 0;
6230}
6231
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006232static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006233 struct mesh_config *cfg,
6234 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006235{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006236 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006237 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006238 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006239
Marco Porschea54fba2013-01-07 16:04:48 +01006240#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
6241do { \
6242 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006243 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01006244 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01006245 mask |= (1 << (attr - 1)); \
6246 } \
6247} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006248
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006249 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006250 return -EINVAL;
6251 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006252 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02006253 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006254 return -EINVAL;
6255
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006256 /* This makes sure that there aren't more than 32 mesh config
6257 * parameters (otherwise our bitfield scheme would not work.) */
6258 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6259
6260 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01006261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006262 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006263 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006265 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006266 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006267 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006268 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006269 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006271 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006272 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006273 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006274 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006275 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006276 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006277 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006278 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006279 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006280 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006282 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006283 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
6285 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006286 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006287 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006288 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006289 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006290 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006291 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006292 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006293 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006294 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006295 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006296 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006297 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
6298 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006299 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006300 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006301 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006302 1, 65535, mask,
6303 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006304 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08006305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006306 1, 65535, mask,
6307 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006308 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006309 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006310 dot11MeshHWMPnetDiameterTraversalTime,
6311 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006312 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006313 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006314 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
6315 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006316 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006317 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
6318 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006319 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00006320 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006321 dot11MeshGateAnnouncementProtocol, 0, 1,
6322 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006323 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006324 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006325 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006326 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08006327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006328 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006329 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09006330 /*
6331 * Check HT operation mode based on
6332 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6333 */
6334 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6335 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6336
6337 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6338 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6339 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6340 return -EINVAL;
6341
6342 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6343 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6344 return -EINVAL;
6345
6346 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6347 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6348 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6349 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6350 return -EINVAL;
6351 break;
6352 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6353 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6354 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6355 return -EINVAL;
6356 break;
6357 }
6358 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006359 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006360 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006361 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006362 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006363 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006364 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006365 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006366 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006367 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006368 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006369 dot11MeshHWMPconfirmationInterval,
6370 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006371 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006372 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006373 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6374 NL80211_MESH_POWER_ACTIVE,
6375 NL80211_MESH_POWER_MAX,
6376 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006377 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6379 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006380 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006381 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006382 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006383 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006384 if (mask_out)
6385 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006386
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006387 return 0;
6388
6389#undef FILL_IN_MESH_PARAM_IF_SET
6390}
6391
Javier Cardonac80d5452010-12-16 17:37:49 -08006392static int nl80211_parse_mesh_setup(struct genl_info *info,
6393 struct mesh_setup *setup)
6394{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006396 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6397
6398 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6399 return -EINVAL;
6400 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6401 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006402 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006403 return -EINVAL;
6404
Javier Cardonad299a1f2012-03-31 11:31:33 -07006405 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6406 setup->sync_method =
6407 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6408 IEEE80211_SYNC_METHOD_VENDOR :
6409 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6410
Javier Cardonac80d5452010-12-16 17:37:49 -08006411 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6412 setup->path_sel_proto =
6413 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6414 IEEE80211_PATH_PROTOCOL_VENDOR :
6415 IEEE80211_PATH_PROTOCOL_HWMP;
6416
6417 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6418 setup->path_metric =
6419 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6420 IEEE80211_PATH_METRIC_VENDOR :
6421 IEEE80211_PATH_METRIC_AIRTIME;
6422
Javier Cardona581a8b02011-04-07 15:08:27 -07006423 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006424 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006425 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006426 if (!is_valid_ie_attr(ieattr))
6427 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006428 setup->ie = nla_data(ieattr);
6429 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006430 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006431 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6432 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6433 return -EINVAL;
6434 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006435 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6436 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006437 if (setup->is_secure)
6438 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006439
Colleen Twitty6e16d902013-05-08 11:45:59 -07006440 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6441 if (!setup->user_mpm)
6442 return -EINVAL;
6443 setup->auth_id =
6444 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6445 }
6446
Javier Cardonac80d5452010-12-16 17:37:49 -08006447 return 0;
6448}
6449
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006450static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006451 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006452{
6453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6454 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006455 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006456 struct mesh_config cfg;
6457 u32 mask;
6458 int err;
6459
Johannes Berg29cbe682010-12-03 09:20:44 +01006460 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6461 return -EOPNOTSUPP;
6462
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006463 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006464 return -EOPNOTSUPP;
6465
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006466 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006467 if (err)
6468 return err;
6469
Johannes Berg29cbe682010-12-03 09:20:44 +01006470 wdev_lock(wdev);
6471 if (!wdev->mesh_id_len)
6472 err = -ENOLINK;
6473
6474 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006475 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006476
6477 wdev_unlock(wdev);
6478
6479 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006480}
6481
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006482static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6483 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006484{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006485 struct nlattr *nl_reg_rules;
6486 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006487
Johannes Berg458f4f92012-12-06 15:47:38 +01006488 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6489 (regdom->dfs_region &&
6490 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006491 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006492
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006493 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6494 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006495 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006496
Johannes Berg458f4f92012-12-06 15:47:38 +01006497 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006498 struct nlattr *nl_reg_rule;
6499 const struct ieee80211_reg_rule *reg_rule;
6500 const struct ieee80211_freq_range *freq_range;
6501 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006502 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006503
Johannes Berg458f4f92012-12-06 15:47:38 +01006504 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006505 freq_range = &reg_rule->freq_range;
6506 power_rule = &reg_rule->power_rule;
6507
6508 nl_reg_rule = nla_nest_start(msg, i);
6509 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006510 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006511
Janusz Dziedzic97524822014-01-30 09:52:20 +01006512 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6513 if (!max_bandwidth_khz)
6514 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6515 reg_rule);
6516
David S. Miller9360ffd2012-03-29 04:41:26 -04006517 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6518 reg_rule->flags) ||
6519 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6520 freq_range->start_freq_khz) ||
6521 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6522 freq_range->end_freq_khz) ||
6523 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006524 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006525 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6526 power_rule->max_antenna_gain) ||
6527 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006528 power_rule->max_eirp) ||
6529 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6530 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006531 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006532
6533 nla_nest_end(msg, nl_reg_rule);
6534 }
6535
6536 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006537 return 0;
6538
6539nla_put_failure:
6540 return -EMSGSIZE;
6541}
6542
6543static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6544{
6545 const struct ieee80211_regdomain *regdom = NULL;
6546 struct cfg80211_registered_device *rdev;
6547 struct wiphy *wiphy = NULL;
6548 struct sk_buff *msg;
6549 void *hdr;
6550
6551 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6552 if (!msg)
6553 return -ENOBUFS;
6554
6555 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6556 NL80211_CMD_GET_REG);
6557 if (!hdr)
6558 goto put_failure;
6559
6560 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006561 bool self_managed;
6562
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006563 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6564 if (IS_ERR(rdev)) {
6565 nlmsg_free(msg);
6566 return PTR_ERR(rdev);
6567 }
6568
6569 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006570 self_managed = wiphy->regulatory_flags &
6571 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006572 regdom = get_wiphy_regdom(wiphy);
6573
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006574 /* a self-managed-reg device must have a private regdom */
6575 if (WARN_ON(!regdom && self_managed)) {
6576 nlmsg_free(msg);
6577 return -EINVAL;
6578 }
6579
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006580 if (regdom &&
6581 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6582 goto nla_put_failure;
6583 }
6584
6585 if (!wiphy && reg_last_request_cell_base() &&
6586 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6587 NL80211_USER_REG_HINT_CELL_BASE))
6588 goto nla_put_failure;
6589
6590 rcu_read_lock();
6591
6592 if (!regdom)
6593 regdom = rcu_dereference(cfg80211_regdomain);
6594
6595 if (nl80211_put_regdom(regdom, msg))
6596 goto nla_put_failure_rcu;
6597
6598 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006599
6600 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006601 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006602
Johannes Berg458f4f92012-12-06 15:47:38 +01006603nla_put_failure_rcu:
6604 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006605nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006606put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006607 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006608 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006609}
6610
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006611static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6612 u32 seq, int flags, struct wiphy *wiphy,
6613 const struct ieee80211_regdomain *regdom)
6614{
6615 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6616 NL80211_CMD_GET_REG);
6617
6618 if (!hdr)
6619 return -1;
6620
Michal Kubecek0a833c22017-11-15 13:09:32 +01006621 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006622
6623 if (nl80211_put_regdom(regdom, msg))
6624 goto nla_put_failure;
6625
6626 if (!wiphy && reg_last_request_cell_base() &&
6627 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6628 NL80211_USER_REG_HINT_CELL_BASE))
6629 goto nla_put_failure;
6630
6631 if (wiphy &&
6632 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6633 goto nla_put_failure;
6634
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006635 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6636 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6637 goto nla_put_failure;
6638
Johannes Berg053c0952015-01-16 22:09:00 +01006639 genlmsg_end(msg, hdr);
6640 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006641
6642nla_put_failure:
6643 genlmsg_cancel(msg, hdr);
6644 return -EMSGSIZE;
6645}
6646
6647static int nl80211_get_reg_dump(struct sk_buff *skb,
6648 struct netlink_callback *cb)
6649{
6650 const struct ieee80211_regdomain *regdom = NULL;
6651 struct cfg80211_registered_device *rdev;
6652 int err, reg_idx, start = cb->args[2];
6653
6654 rtnl_lock();
6655
6656 if (cfg80211_regdomain && start == 0) {
6657 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6658 NLM_F_MULTI, NULL,
6659 rtnl_dereference(cfg80211_regdomain));
6660 if (err < 0)
6661 goto out_err;
6662 }
6663
6664 /* the global regdom is idx 0 */
6665 reg_idx = 1;
6666 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6667 regdom = get_wiphy_regdom(&rdev->wiphy);
6668 if (!regdom)
6669 continue;
6670
6671 if (++reg_idx <= start)
6672 continue;
6673
6674 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6675 NLM_F_MULTI, &rdev->wiphy, regdom);
6676 if (err < 0) {
6677 reg_idx--;
6678 break;
6679 }
6680 }
6681
6682 cb->args[2] = reg_idx;
6683 err = skb->len;
6684out_err:
6685 rtnl_unlock();
6686 return err;
6687}
6688
Johannes Bergb6863032015-10-15 09:25:18 +02006689#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6690static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6691 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6692 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6693 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6694 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6695 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6696 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6697 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6698};
6699
6700static int parse_reg_rule(struct nlattr *tb[],
6701 struct ieee80211_reg_rule *reg_rule)
6702{
6703 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6704 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6705
6706 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6707 return -EINVAL;
6708 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6709 return -EINVAL;
6710 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6711 return -EINVAL;
6712 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6713 return -EINVAL;
6714 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6715 return -EINVAL;
6716
6717 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6718
6719 freq_range->start_freq_khz =
6720 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6721 freq_range->end_freq_khz =
6722 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6723 freq_range->max_bandwidth_khz =
6724 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6725
6726 power_rule->max_eirp =
6727 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6728
6729 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6730 power_rule->max_antenna_gain =
6731 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6732
6733 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6734 reg_rule->dfs_cac_ms =
6735 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6736
6737 return 0;
6738}
6739
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006740static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6741{
6742 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6743 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006744 char *alpha2;
6745 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006746 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006747 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006748 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006749
6750 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6751 return -EINVAL;
6752
6753 if (!info->attrs[NL80211_ATTR_REG_RULES])
6754 return -EINVAL;
6755
6756 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6757
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006758 if (info->attrs[NL80211_ATTR_DFS_REGION])
6759 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6760
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006761 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006762 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006763 num_rules++;
6764 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006765 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006766 }
6767
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006768 if (!reg_is_valid_request(alpha2))
6769 return -EINVAL;
6770
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006771 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006772 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006773
6774 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006775 if (!rd)
6776 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006777
6778 rd->n_reg_rules = num_rules;
6779 rd->alpha2[0] = alpha2[0];
6780 rd->alpha2[1] = alpha2[1];
6781
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006782 /*
6783 * Disable DFS master mode if the DFS region was
6784 * not supported or known on this kernel.
6785 */
6786 if (reg_supported_dfs_region(dfs_region))
6787 rd->dfs_region = dfs_region;
6788
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006789 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006790 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006791 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006792 nl_reg_rule, reg_rule_policy,
6793 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006794 if (r)
6795 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006796 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6797 if (r)
6798 goto bad_reg;
6799
6800 rule_idx++;
6801
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006802 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6803 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006804 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006805 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006806 }
6807
Johannes Berg06627992016-06-09 10:40:09 +02006808 /* set_regdom takes ownership of rd */
6809 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006810 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006811 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006812 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006813}
Johannes Bergb6863032015-10-15 09:25:18 +02006814#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006815
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006816static int validate_scan_freqs(struct nlattr *freqs)
6817{
6818 struct nlattr *attr1, *attr2;
6819 int n_channels = 0, tmp1, tmp2;
6820
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006821 nla_for_each_nested(attr1, freqs, tmp1)
6822 if (nla_len(attr1) != sizeof(u32))
6823 return 0;
6824
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006825 nla_for_each_nested(attr1, freqs, tmp1) {
6826 n_channels++;
6827 /*
6828 * Some hardware has a limited channel list for
6829 * scanning, and it is pretty much nonsensical
6830 * to scan for a channel twice, so disallow that
6831 * and don't require drivers to check that the
6832 * channel list they get isn't longer than what
6833 * they can scan, as long as they can scan all
6834 * the channels they registered at once.
6835 */
6836 nla_for_each_nested(attr2, freqs, tmp2)
6837 if (attr1 != attr2 &&
6838 nla_get_u32(attr1) == nla_get_u32(attr2))
6839 return 0;
6840 }
6841
6842 return n_channels;
6843}
6844
Johannes Berg57fbcce2016-04-12 15:56:15 +02006845static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006846{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006847 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006848}
6849
6850static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6851 struct cfg80211_bss_selection *bss_select)
6852{
6853 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6854 struct nlattr *nest;
6855 int err;
6856 bool found = false;
6857 int i;
6858
6859 /* only process one nested attribute */
6860 nest = nla_data(nla);
6861 if (!nla_ok(nest, nla_len(nest)))
6862 return -EINVAL;
6863
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006864 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006865 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006866 if (err)
6867 return err;
6868
6869 /* only one attribute may be given */
6870 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6871 if (attr[i]) {
6872 if (found)
6873 return -EINVAL;
6874 found = true;
6875 }
6876 }
6877
6878 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6879
6880 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6881 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6882
6883 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6884 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6885 bss_select->param.band_pref =
6886 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6887 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6888 return -EINVAL;
6889 }
6890
6891 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6892 struct nl80211_bss_select_rssi_adjust *adj_param;
6893
6894 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6895 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6896 bss_select->param.adjust.band = adj_param->band;
6897 bss_select->param.adjust.delta = adj_param->delta;
6898 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6899 return -EINVAL;
6900 }
6901
6902 /* user-space did not provide behaviour attribute */
6903 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6904 return -EINVAL;
6905
6906 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6907 return -EINVAL;
6908
6909 return 0;
6910}
6911
Johannes Bergad2b26a2014-06-12 21:39:05 +02006912static int nl80211_parse_random_mac(struct nlattr **attrs,
6913 u8 *mac_addr, u8 *mac_addr_mask)
6914{
6915 int i;
6916
6917 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006918 eth_zero_addr(mac_addr);
6919 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006920 mac_addr[0] = 0x2;
6921 mac_addr_mask[0] = 0x3;
6922
6923 return 0;
6924 }
6925
6926 /* need both or none */
6927 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6928 return -EINVAL;
6929
6930 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6931 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6932
6933 /* don't allow or configure an mcast address */
6934 if (!is_multicast_ether_addr(mac_addr_mask) ||
6935 is_multicast_ether_addr(mac_addr))
6936 return -EINVAL;
6937
6938 /*
6939 * allow users to pass a MAC address that has bits set outside
6940 * of the mask, but don't bother drivers with having to deal
6941 * with such bits
6942 */
6943 for (i = 0; i < ETH_ALEN; i++)
6944 mac_addr[i] &= mac_addr_mask[i];
6945
6946 return 0;
6947}
6948
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306949static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6950{
6951 ASSERT_WDEV_LOCK(wdev);
6952
6953 if (!cfg80211_beaconing_iface_active(wdev))
6954 return true;
6955
6956 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6957 return true;
6958
6959 return regulatory_pre_cac_allowed(wdev->wiphy);
6960}
6961
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02006962static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
6963 enum nl80211_ext_feature_index feat)
6964{
6965 if (!(flags & flag))
6966 return true;
6967 if (wiphy_ext_feature_isset(wiphy, feat))
6968 return true;
6969 return false;
6970}
6971
Roee Zamir2d23d072017-08-06 11:38:22 +03006972static int
6973nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6974 void *request, struct nlattr **attrs,
6975 bool is_sched_scan)
6976{
6977 u8 *mac_addr, *mac_addr_mask;
6978 u32 *flags;
6979 enum nl80211_feature_flags randomness_flag;
6980
6981 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6982 return 0;
6983
6984 if (is_sched_scan) {
6985 struct cfg80211_sched_scan_request *req = request;
6986
6987 randomness_flag = wdev ?
6988 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6989 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6990 flags = &req->flags;
6991 mac_addr = req->mac_addr;
6992 mac_addr_mask = req->mac_addr_mask;
6993 } else {
6994 struct cfg80211_scan_request *req = request;
6995
6996 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6997 flags = &req->flags;
6998 mac_addr = req->mac_addr;
6999 mac_addr_mask = req->mac_addr_mask;
7000 }
7001
7002 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7003
Sunil Dutt5037a002018-01-25 17:13:37 +02007004 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7005 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007006 !nl80211_check_scan_feat(wiphy, *flags,
7007 NL80211_SCAN_FLAG_LOW_SPAN,
7008 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7009 !nl80211_check_scan_feat(wiphy, *flags,
7010 NL80211_SCAN_FLAG_LOW_POWER,
7011 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7012 !nl80211_check_scan_feat(wiphy, *flags,
7013 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7014 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7015 !nl80211_check_scan_feat(wiphy, *flags,
7016 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7017 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7018 !nl80211_check_scan_feat(wiphy, *flags,
7019 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7020 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7021 !nl80211_check_scan_feat(wiphy, *flags,
7022 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7023 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7024 !nl80211_check_scan_feat(wiphy, *flags,
7025 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007026 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7027 !nl80211_check_scan_feat(wiphy, *flags,
7028 NL80211_SCAN_FLAG_RANDOM_SN,
7029 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7030 !nl80211_check_scan_feat(wiphy, *flags,
7031 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7032 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007033 return -EOPNOTSUPP;
7034
7035 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7036 int err;
7037
7038 if (!(wiphy->features & randomness_flag) ||
7039 (wdev && wdev->current_bss))
7040 return -EOPNOTSUPP;
7041
7042 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7043 if (err)
7044 return err;
7045 }
7046
Roee Zamir2d23d072017-08-06 11:38:22 +03007047 return 0;
7048}
7049
Johannes Berg2a519312009-02-10 21:25:55 +01007050static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7051{
Johannes Berg4c476992010-10-04 21:36:35 +02007052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007053 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007054 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007055 struct nlattr *attr;
7056 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007057 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007058 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007059
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007060 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7061 return -EINVAL;
7062
Johannes Berg79c97e92009-07-07 03:56:12 +02007063 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007064
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007065 if (wdev->iftype == NL80211_IFTYPE_NAN)
7066 return -EOPNOTSUPP;
7067
Johannes Berg4c476992010-10-04 21:36:35 +02007068 if (!rdev->ops->scan)
7069 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007070
Johannes Bergf9d15d12014-01-22 11:14:19 +02007071 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007072 err = -EBUSY;
7073 goto unlock;
7074 }
Johannes Berg2a519312009-02-10 21:25:55 +01007075
7076 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007077 n_channels = validate_scan_freqs(
7078 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007079 if (!n_channels) {
7080 err = -EINVAL;
7081 goto unlock;
7082 }
Johannes Berg2a519312009-02-10 21:25:55 +01007083 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007084 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007085 }
7086
7087 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7088 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7089 n_ssids++;
7090
Johannes Bergf9f47522013-03-19 15:04:07 +01007091 if (n_ssids > wiphy->max_scan_ssids) {
7092 err = -EINVAL;
7093 goto unlock;
7094 }
Johannes Berg2a519312009-02-10 21:25:55 +01007095
Jouni Malinen70692ad2009-02-16 19:39:13 +02007096 if (info->attrs[NL80211_ATTR_IE])
7097 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7098 else
7099 ie_len = 0;
7100
Johannes Bergf9f47522013-03-19 15:04:07 +01007101 if (ie_len > wiphy->max_scan_ie_len) {
7102 err = -EINVAL;
7103 goto unlock;
7104 }
Johannes Berg18a83652009-03-31 12:12:05 +02007105
Johannes Berg2a519312009-02-10 21:25:55 +01007106 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007107 + sizeof(*request->ssids) * n_ssids
7108 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007109 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007110 if (!request) {
7111 err = -ENOMEM;
7112 goto unlock;
7113 }
Johannes Berg2a519312009-02-10 21:25:55 +01007114
Johannes Berg2a519312009-02-10 21:25:55 +01007115 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007116 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007117 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007118 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007119 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007120 request->ie = (void *)(request->ssids + n_ssids);
7121 else
7122 request->ie = (void *)(request->channels + n_channels);
7123 }
Johannes Berg2a519312009-02-10 21:25:55 +01007124
Johannes Berg584991d2009-11-02 13:32:03 +01007125 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007126 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7127 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007128 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007129 struct ieee80211_channel *chan;
7130
7131 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7132
7133 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007134 err = -EINVAL;
7135 goto out_free;
7136 }
Johannes Berg584991d2009-11-02 13:32:03 +01007137
7138 /* ignore disabled channels */
7139 if (chan->flags & IEEE80211_CHAN_DISABLED)
7140 continue;
7141
7142 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007143 i++;
7144 }
7145 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007146 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007147
Johannes Berg2a519312009-02-10 21:25:55 +01007148 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007149 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007150 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007151
Johannes Berg2a519312009-02-10 21:25:55 +01007152 if (!wiphy->bands[band])
7153 continue;
7154 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007155 struct ieee80211_channel *chan;
7156
7157 chan = &wiphy->bands[band]->channels[j];
7158
7159 if (chan->flags & IEEE80211_CHAN_DISABLED)
7160 continue;
7161
7162 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007163 i++;
7164 }
7165 }
7166 }
7167
Johannes Berg584991d2009-11-02 13:32:03 +01007168 if (!i) {
7169 err = -EINVAL;
7170 goto out_free;
7171 }
7172
7173 request->n_channels = i;
7174
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307175 wdev_lock(wdev);
7176 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7177 struct ieee80211_channel *chan;
7178
7179 if (request->n_channels != 1) {
7180 wdev_unlock(wdev);
7181 err = -EBUSY;
7182 goto out_free;
7183 }
7184
7185 chan = request->channels[0];
7186 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7187 wdev_unlock(wdev);
7188 err = -EBUSY;
7189 goto out_free;
7190 }
7191 }
7192 wdev_unlock(wdev);
7193
Johannes Berg2a519312009-02-10 21:25:55 +01007194 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007195 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007196 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007197 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007198 err = -EINVAL;
7199 goto out_free;
7200 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007201 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007202 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007203 i++;
7204 }
7205 }
7206
Jouni Malinen70692ad2009-02-16 19:39:13 +02007207 if (info->attrs[NL80211_ATTR_IE]) {
7208 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007209 memcpy((void *)request->ie,
7210 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007211 request->ie_len);
7212 }
7213
Johannes Berg57fbcce2016-04-12 15:56:15 +02007214 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007215 if (wiphy->bands[i])
7216 request->rates[i] =
7217 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007218
7219 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7220 nla_for_each_nested(attr,
7221 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7222 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007223 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007224
Johannes Berg57fbcce2016-04-12 15:56:15 +02007225 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007226 err = -EINVAL;
7227 goto out_free;
7228 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007229
7230 if (!wiphy->bands[band])
7231 continue;
7232
Johannes Berg34850ab2011-07-18 18:08:35 +02007233 err = ieee80211_get_ratemask(wiphy->bands[band],
7234 nla_data(attr),
7235 nla_len(attr),
7236 &request->rates[band]);
7237 if (err)
7238 goto out_free;
7239 }
7240 }
7241
Avraham Stern1d762502016-07-05 17:10:13 +03007242 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7243 if (!wiphy_ext_feature_isset(wiphy,
7244 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7245 err = -EOPNOTSUPP;
7246 goto out_free;
7247 }
7248
7249 request->duration =
7250 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7251 request->duration_mandatory =
7252 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7253 }
7254
Roee Zamir2d23d072017-08-06 11:38:22 +03007255 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7256 false);
7257 if (err)
7258 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007259
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307260 request->no_cck =
7261 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7262
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007263 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7264 * BSSID to scan for. This was problematic because that same attribute
7265 * was already used for another purpose (local random MAC address). The
7266 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7267 * compatibility with older userspace components, also use the
7268 * NL80211_ATTR_MAC value here if it can be determined to be used for
7269 * the specific BSSID use case instead of the random MAC address
7270 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7271 */
7272 if (info->attrs[NL80211_ATTR_BSSID])
7273 memcpy(request->bssid,
7274 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7275 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7276 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007277 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7278 ETH_ALEN);
7279 else
7280 eth_broadcast_addr(request->bssid);
7281
Johannes Bergfd014282012-06-18 19:17:03 +02007282 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007283 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007284 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007285
Johannes Berg79c97e92009-07-07 03:56:12 +02007286 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007287 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007288
Johannes Berg463d0182009-07-14 00:33:35 +02007289 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007290 nl80211_send_scan_start(rdev, wdev);
7291 if (wdev->netdev)
7292 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007293 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007294 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007295 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007296 kfree(request);
7297 }
Johannes Berg3b858752009-03-12 09:55:09 +01007298
Johannes Bergf9f47522013-03-19 15:04:07 +01007299 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007300 return err;
7301}
7302
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307303static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7304{
7305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7306 struct wireless_dev *wdev = info->user_ptr[1];
7307
7308 if (!rdev->ops->abort_scan)
7309 return -EOPNOTSUPP;
7310
7311 if (rdev->scan_msg)
7312 return 0;
7313
7314 if (!rdev->scan_req)
7315 return -ENOENT;
7316
7317 rdev_abort_scan(rdev, wdev);
7318 return 0;
7319}
7320
Avraham Stern3b06d272015-10-12 09:51:34 +03007321static int
7322nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7323 struct cfg80211_sched_scan_request *request,
7324 struct nlattr **attrs)
7325{
7326 int tmp, err, i = 0;
7327 struct nlattr *attr;
7328
7329 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7330 u32 interval;
7331
7332 /*
7333 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007334 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007335 * case one scan plan will be set with the specified scan
7336 * interval and infinite number of iterations.
7337 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007338 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7339 if (!interval)
7340 return -EINVAL;
7341
7342 request->scan_plans[0].interval =
7343 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7344 if (!request->scan_plans[0].interval)
7345 return -EINVAL;
7346
7347 if (request->scan_plans[0].interval >
7348 wiphy->max_sched_scan_plan_interval)
7349 request->scan_plans[0].interval =
7350 wiphy->max_sched_scan_plan_interval;
7351
7352 return 0;
7353 }
7354
7355 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7356 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7357
7358 if (WARN_ON(i >= n_plans))
7359 return -EINVAL;
7360
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007361 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007362 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007363 if (err)
7364 return err;
7365
7366 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7367 return -EINVAL;
7368
7369 request->scan_plans[i].interval =
7370 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7371 if (!request->scan_plans[i].interval ||
7372 request->scan_plans[i].interval >
7373 wiphy->max_sched_scan_plan_interval)
7374 return -EINVAL;
7375
7376 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7377 request->scan_plans[i].iterations =
7378 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7379 if (!request->scan_plans[i].iterations ||
7380 (request->scan_plans[i].iterations >
7381 wiphy->max_sched_scan_plan_iterations))
7382 return -EINVAL;
7383 } else if (i < n_plans - 1) {
7384 /*
7385 * All scan plans but the last one must specify
7386 * a finite number of iterations
7387 */
7388 return -EINVAL;
7389 }
7390
7391 i++;
7392 }
7393
7394 /*
7395 * The last scan plan must not specify the number of
7396 * iterations, it is supposed to run infinitely
7397 */
7398 if (request->scan_plans[n_plans - 1].iterations)
7399 return -EINVAL;
7400
7401 return 0;
7402}
7403
Luciano Coelho256da022014-11-10 16:13:46 +02007404static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007405nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007406 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007407{
7408 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007409 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007410 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007411 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007412 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007413 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007414 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007415
Luciano Coelho256da022014-11-10 16:13:46 +02007416 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7417 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007418
Luciano Coelho256da022014-11-10 16:13:46 +02007419 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007420 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007421 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007422 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007423 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007424 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007425 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007426 }
7427
Luciano Coelho256da022014-11-10 16:13:46 +02007428 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7429 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007430 tmp)
7431 n_ssids++;
7432
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007433 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007434 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007435
Johannes Bergea73cbc2014-01-24 10:53:53 +01007436 /*
7437 * First, count the number of 'real' matchsets. Due to an issue with
7438 * the old implementation, matchsets containing only the RSSI attribute
7439 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7440 * RSSI for all matchsets, rather than their own matchset for reporting
7441 * all APs with a strong RSSI. This is needed to be compatible with
7442 * older userspace that treated a matchset with only the RSSI as the
7443 * global RSSI for all other matchsets - if there are other matchsets.
7444 */
Luciano Coelho256da022014-11-10 16:13:46 +02007445 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007446 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007447 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007448 tmp) {
7449 struct nlattr *rssi;
7450
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007451 err = nla_parse_nested(tb,
7452 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007453 attr, nl80211_match_policy,
7454 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007455 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007456 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007457
7458 /* SSID and BSSID are mutually exclusive */
7459 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7460 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7461 return ERR_PTR(-EINVAL);
7462
Johannes Bergea73cbc2014-01-24 10:53:53 +01007463 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007464 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7465 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007466 n_match_sets++;
7467 continue;
7468 }
7469 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7470 if (rssi)
7471 default_match_rssi = nla_get_s32(rssi);
7472 }
7473 }
7474
7475 /* However, if there's no other matchset, add the RSSI one */
7476 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7477 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007478
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007479 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007480 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007481
Luciano Coelho256da022014-11-10 16:13:46 +02007482 if (attrs[NL80211_ATTR_IE])
7483 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007484 else
7485 ie_len = 0;
7486
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007487 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007488 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007489
Avraham Stern3b06d272015-10-12 09:51:34 +03007490 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7491 /*
7492 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7493 * each scan plan already specifies its own interval
7494 */
7495 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7496 return ERR_PTR(-EINVAL);
7497
7498 nla_for_each_nested(attr,
7499 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7500 n_plans++;
7501 } else {
7502 /*
7503 * The scan interval attribute is kept for backward
7504 * compatibility. If no scan plans are specified and sched scan
7505 * interval is specified, one scan plan will be set with this
7506 * scan interval and infinite number of iterations.
7507 */
7508 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7509 return ERR_PTR(-EINVAL);
7510
7511 n_plans = 1;
7512 }
7513
7514 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7515 return ERR_PTR(-EINVAL);
7516
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007517 if (!wiphy_ext_feature_isset(
7518 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7519 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7520 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7521 return ERR_PTR(-EINVAL);
7522
Luciano Coelho807f8a82011-05-11 17:09:35 +03007523 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007524 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007525 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007526 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007527 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007528 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007529 if (!request)
7530 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007531
7532 if (n_ssids)
7533 request->ssids = (void *)&request->channels[n_channels];
7534 request->n_ssids = n_ssids;
7535 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007536 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007537 request->ie = (void *)(request->ssids + n_ssids);
7538 else
7539 request->ie = (void *)(request->channels + n_channels);
7540 }
7541
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007542 if (n_match_sets) {
7543 if (request->ie)
7544 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007545 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007546 request->match_sets =
7547 (void *)(request->ssids + n_ssids);
7548 else
7549 request->match_sets =
7550 (void *)(request->channels + n_channels);
7551 }
7552 request->n_match_sets = n_match_sets;
7553
Avraham Stern3b06d272015-10-12 09:51:34 +03007554 if (n_match_sets)
7555 request->scan_plans = (void *)(request->match_sets +
7556 n_match_sets);
7557 else if (request->ie)
7558 request->scan_plans = (void *)(request->ie + ie_len);
7559 else if (n_ssids)
7560 request->scan_plans = (void *)(request->ssids + n_ssids);
7561 else
7562 request->scan_plans = (void *)(request->channels + n_channels);
7563
7564 request->n_scan_plans = n_plans;
7565
Luciano Coelho807f8a82011-05-11 17:09:35 +03007566 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007567 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007568 /* user specified, bail out if channel not found */
7569 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007570 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007571 tmp) {
7572 struct ieee80211_channel *chan;
7573
7574 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7575
7576 if (!chan) {
7577 err = -EINVAL;
7578 goto out_free;
7579 }
7580
7581 /* ignore disabled channels */
7582 if (chan->flags & IEEE80211_CHAN_DISABLED)
7583 continue;
7584
7585 request->channels[i] = chan;
7586 i++;
7587 }
7588 } else {
7589 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007590 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007591 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007592
Luciano Coelho807f8a82011-05-11 17:09:35 +03007593 if (!wiphy->bands[band])
7594 continue;
7595 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7596 struct ieee80211_channel *chan;
7597
7598 chan = &wiphy->bands[band]->channels[j];
7599
7600 if (chan->flags & IEEE80211_CHAN_DISABLED)
7601 continue;
7602
7603 request->channels[i] = chan;
7604 i++;
7605 }
7606 }
7607 }
7608
7609 if (!i) {
7610 err = -EINVAL;
7611 goto out_free;
7612 }
7613
7614 request->n_channels = i;
7615
7616 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007617 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007618 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007619 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007620 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007621 err = -EINVAL;
7622 goto out_free;
7623 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007624 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007625 memcpy(request->ssids[i].ssid, nla_data(attr),
7626 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007627 i++;
7628 }
7629 }
7630
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007631 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007632 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007633 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007634 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007635 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007636 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007637
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007638 err = nla_parse_nested(tb,
7639 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007640 attr, nl80211_match_policy,
7641 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007642 if (err)
7643 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007644 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007645 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7646 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007647 if (WARN_ON(i >= n_match_sets)) {
7648 /* this indicates a programming error,
7649 * the loop above should have verified
7650 * things properly
7651 */
7652 err = -EINVAL;
7653 goto out_free;
7654 }
7655
Arend Van Spriel3007e352017-04-21 13:05:01 +01007656 if (ssid) {
7657 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7658 err = -EINVAL;
7659 goto out_free;
7660 }
7661 memcpy(request->match_sets[i].ssid.ssid,
7662 nla_data(ssid), nla_len(ssid));
7663 request->match_sets[i].ssid.ssid_len =
7664 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007665 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007666 if (bssid) {
7667 if (nla_len(bssid) != ETH_ALEN) {
7668 err = -EINVAL;
7669 goto out_free;
7670 }
7671 memcpy(request->match_sets[i].bssid,
7672 nla_data(bssid), ETH_ALEN);
7673 }
7674
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007675 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007676 request->match_sets[i].rssi_thold =
7677 default_match_rssi;
7678 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7679 if (rssi)
7680 request->match_sets[i].rssi_thold =
7681 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007682 }
7683 i++;
7684 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007685
7686 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007687 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007688 request->match_sets[0].rssi_thold = default_match_rssi;
7689
7690 request->min_rssi_thold = INT_MAX;
7691 for (i = 0; i < n_match_sets; i++)
7692 request->min_rssi_thold =
7693 min(request->match_sets[i].rssi_thold,
7694 request->min_rssi_thold);
7695 } else {
7696 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007697 }
7698
Johannes Berg9900e482014-02-04 21:01:25 +01007699 if (ie_len) {
7700 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007701 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007702 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007703 request->ie_len);
7704 }
7705
Roee Zamir2d23d072017-08-06 11:38:22 +03007706 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7707 if (err)
7708 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007709
Luciano Coelho9c748932015-01-16 16:04:09 +02007710 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7711 request->delay =
7712 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7713
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007714 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7715 request->relative_rssi = nla_get_s8(
7716 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7717 request->relative_rssi_set = true;
7718 }
7719
7720 if (request->relative_rssi_set &&
7721 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7722 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7723
7724 rssi_adjust = nla_data(
7725 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7726 request->rssi_adjust.band = rssi_adjust->band;
7727 request->rssi_adjust.delta = rssi_adjust->delta;
7728 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7729 err = -EINVAL;
7730 goto out_free;
7731 }
7732 }
7733
Avraham Stern3b06d272015-10-12 09:51:34 +03007734 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7735 if (err)
7736 goto out_free;
7737
Sam Leffler15d60302012-10-11 21:03:34 -07007738 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007739
Luciano Coelho256da022014-11-10 16:13:46 +02007740 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007741
7742out_free:
7743 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007744 return ERR_PTR(err);
7745}
7746
7747static int nl80211_start_sched_scan(struct sk_buff *skb,
7748 struct genl_info *info)
7749{
7750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7751 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007752 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007753 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007754 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007755 int err;
7756
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007757 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007758 return -EOPNOTSUPP;
7759
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007760 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7761 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7762 if (err)
7763 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007764
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007765 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007766 info->attrs,
7767 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007768
7769 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007770 if (err)
7771 goto out_err;
7772
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007773 /* leave request id zero for legacy request
7774 * or if driver does not support multi-scheduled scan
7775 */
7776 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7777 while (!sched_scan_req->reqid)
7778 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7779 }
7780
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007781 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007782 if (err)
7783 goto out_free;
7784
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007785 sched_scan_req->dev = dev;
7786 sched_scan_req->wiphy = &rdev->wiphy;
7787
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007788 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7789 sched_scan_req->owner_nlportid = info->snd_portid;
7790
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007791 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007792
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007793 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007794 return 0;
7795
7796out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007797 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007798out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007799 return err;
7800}
7801
7802static int nl80211_stop_sched_scan(struct sk_buff *skb,
7803 struct genl_info *info)
7804{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007805 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007807 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007808
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007809 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007810 return -EOPNOTSUPP;
7811
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007812 if (info->attrs[NL80211_ATTR_COOKIE]) {
7813 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7814 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7815 }
7816
7817 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7818 struct cfg80211_sched_scan_request,
7819 list);
7820 if (!req || req->reqid ||
7821 (req->owner_nlportid &&
7822 req->owner_nlportid != info->snd_portid))
7823 return -ENOENT;
7824
7825 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007826}
7827
Simon Wunderlich04f39042013-02-08 18:16:19 +01007828static int nl80211_start_radar_detection(struct sk_buff *skb,
7829 struct genl_info *info)
7830{
7831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7832 struct net_device *dev = info->user_ptr[1];
7833 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007834 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007835 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007836 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007837 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007838 int err;
7839
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007840 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007841 if (dfs_region == NL80211_DFS_UNSET)
7842 return -EINVAL;
7843
Simon Wunderlich04f39042013-02-08 18:16:19 +01007844 err = nl80211_parse_chandef(rdev, info, &chandef);
7845 if (err)
7846 return err;
7847
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007848 if (netif_carrier_ok(dev))
7849 return -EBUSY;
7850
Simon Wunderlich04f39042013-02-08 18:16:19 +01007851 if (wdev->cac_started)
7852 return -EBUSY;
7853
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007854 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007855 if (err < 0)
7856 return err;
7857
7858 if (err == 0)
7859 return -EINVAL;
7860
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007861 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007862 return -EINVAL;
7863
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007864 /* CAC start is offloaded to HW and can't be started manually */
7865 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
7866 return -EOPNOTSUPP;
7867
Simon Wunderlich04f39042013-02-08 18:16:19 +01007868 if (!rdev->ops->start_radar_detection)
7869 return -EOPNOTSUPP;
7870
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007871 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7872 if (WARN_ON(!cac_time_ms))
7873 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7874
Ilan Peera1056b1b2015-10-22 22:27:46 +03007875 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007876 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007877 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007878 wdev->cac_started = true;
7879 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007880 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007881 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007882 return err;
7883}
7884
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007885static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7886{
7887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7888 struct net_device *dev = info->user_ptr[1];
7889 struct wireless_dev *wdev = dev->ieee80211_ptr;
7890 struct cfg80211_csa_settings params;
7891 /* csa_attrs is defined static to avoid waste of stack size - this
7892 * function is called under RTNL lock, so this should not be a problem.
7893 */
7894 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007895 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007896 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007897 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007898 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007899 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007900
7901 if (!rdev->ops->channel_switch ||
7902 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7903 return -EOPNOTSUPP;
7904
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007905 switch (dev->ieee80211_ptr->iftype) {
7906 case NL80211_IFTYPE_AP:
7907 case NL80211_IFTYPE_P2P_GO:
7908 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007909 /* For all modes except AP the handle_dfs flag needs to be
7910 * supplied to tell the kernel that userspace will handle radar
7911 * events when they happen. Otherwise a switch to a channel
7912 * requiring DFS will be rejected.
7913 */
7914 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007915
7916 /* useless if AP is not running */
7917 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007918 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007919 break;
7920 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007921 if (!wdev->ssid_len)
7922 return -ENOTCONN;
7923 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007924 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007925 if (!wdev->mesh_id_len)
7926 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007927 break;
7928 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007929 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007930 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007931
7932 memset(&params, 0, sizeof(params));
7933
7934 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7935 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7936 return -EINVAL;
7937
7938 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007939 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007940 return -EINVAL;
7941
Luciano Coelho252e07c2014-10-08 09:48:34 +03007942 /* Even though the attribute is u32, the specification says
7943 * u8, so let's make sure we don't overflow.
7944 */
7945 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7946 if (cs_count > 255)
7947 return -EINVAL;
7948
7949 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007950
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007951 if (!need_new_beacon)
7952 goto skip_beacons;
7953
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007954 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7955 if (err)
7956 return err;
7957
7958 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7959 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007960 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007961 if (err)
7962 return err;
7963
7964 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7965 if (err)
7966 return err;
7967
7968 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7969 return -EINVAL;
7970
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007971 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7972 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007973 return -EINVAL;
7974
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007975 params.n_counter_offsets_beacon = len / sizeof(u16);
7976 if (rdev->wiphy.max_num_csa_counters &&
7977 (params.n_counter_offsets_beacon >
7978 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007979 return -EINVAL;
7980
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007981 params.counter_offsets_beacon =
7982 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7983
7984 /* sanity checks - counters should fit and be the same */
7985 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7986 u16 offset = params.counter_offsets_beacon[i];
7987
7988 if (offset >= params.beacon_csa.tail_len)
7989 return -EINVAL;
7990
7991 if (params.beacon_csa.tail[offset] != params.count)
7992 return -EINVAL;
7993 }
7994
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007995 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007996 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7997 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007998 return -EINVAL;
7999
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008000 params.n_counter_offsets_presp = len / sizeof(u16);
8001 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008002 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008003 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008004 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008005
8006 params.counter_offsets_presp =
8007 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8008
8009 /* sanity checks - counters should fit and be the same */
8010 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8011 u16 offset = params.counter_offsets_presp[i];
8012
8013 if (offset >= params.beacon_csa.probe_resp_len)
8014 return -EINVAL;
8015
8016 if (params.beacon_csa.probe_resp[offset] !=
8017 params.count)
8018 return -EINVAL;
8019 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008020 }
8021
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008022skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008023 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8024 if (err)
8025 return err;
8026
Arik Nemtsov923b3522015-07-08 15:41:44 +03008027 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8028 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008029 return -EINVAL;
8030
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008031 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8032 &params.chandef,
8033 wdev->iftype);
8034 if (err < 0)
8035 return err;
8036
Benjamin Berg8d9de162017-05-16 11:23:12 +02008037 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008038 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008039 if (need_handle_dfs_flag &&
8040 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8041 return -EINVAL;
8042 }
8043 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008044
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008045 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8046 params.block_tx = true;
8047
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008048 wdev_lock(wdev);
8049 err = rdev_channel_switch(rdev, dev, &params);
8050 wdev_unlock(wdev);
8051
8052 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008053}
8054
Johannes Berg9720bb32011-06-21 09:45:33 +02008055static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8056 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008057 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008058 struct wireless_dev *wdev,
8059 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008060{
Johannes Berg48ab9052009-07-10 18:42:31 +02008061 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008062 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008063 void *hdr;
8064 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008065
8066 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008067
Eric W. Biederman15e47302012-09-07 20:12:54 +00008068 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008069 NL80211_CMD_NEW_SCAN_RESULTS);
8070 if (!hdr)
8071 return -1;
8072
Michal Kubecek0a833c22017-11-15 13:09:32 +01008073 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008074
Johannes Berg97990a02013-04-19 01:02:55 +02008075 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8076 goto nla_put_failure;
8077 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008078 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8079 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008080 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8081 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008082 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008083
8084 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
8085 if (!bss)
8086 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008087 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008088 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008089 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008090
8091 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008092 /* indicate whether we have probe response data or not */
8093 if (rcu_access_pointer(res->proberesp_ies) &&
8094 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8095 goto fail_unlock_rcu;
8096
8097 /* this pointer prefers to be pointed to probe response data
8098 * but is always valid
8099 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008100 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008101 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008102 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8103 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008104 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008105 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8106 ies->len, ies->data))
8107 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008108 }
Johannes Berg0e227082014-08-12 20:34:30 +02008109
8110 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008111 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008112 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008113 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8114 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008115 goto fail_unlock_rcu;
8116 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8117 ies->len, ies->data))
8118 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008119 }
8120 rcu_read_unlock();
8121
David S. Miller9360ffd2012-03-29 04:41:26 -04008122 if (res->beacon_interval &&
8123 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8124 goto nla_put_failure;
8125 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8126 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008127 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008128 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8129 jiffies_to_msecs(jiffies - intbss->ts)))
8130 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008131
Avraham Stern1d762502016-07-05 17:10:13 +03008132 if (intbss->parent_tsf &&
8133 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8134 intbss->parent_tsf, NL80211_BSS_PAD) ||
8135 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8136 intbss->parent_bssid)))
8137 goto nla_put_failure;
8138
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008139 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008140 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8141 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008142 goto nla_put_failure;
8143
Sunil Dutt983dafa2017-12-13 19:51:36 +02008144 if (!nl80211_put_signal(msg, intbss->pub.chains,
8145 intbss->pub.chain_signal,
8146 NL80211_BSS_CHAIN_SIGNAL))
8147 goto nla_put_failure;
8148
Johannes Berg77965c972009-02-18 18:45:06 +01008149 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008150 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008151 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8152 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008153 break;
8154 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008155 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8156 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008157 break;
8158 default:
8159 break;
8160 }
8161
Johannes Berg48ab9052009-07-10 18:42:31 +02008162 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008163 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008164 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008165 if (intbss == wdev->current_bss &&
8166 nla_put_u32(msg, NL80211_BSS_STATUS,
8167 NL80211_BSS_STATUS_ASSOCIATED))
8168 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008169 break;
8170 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008171 if (intbss == wdev->current_bss &&
8172 nla_put_u32(msg, NL80211_BSS_STATUS,
8173 NL80211_BSS_STATUS_IBSS_JOINED))
8174 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008175 break;
8176 default:
8177 break;
8178 }
8179
Johannes Berg2a519312009-02-10 21:25:55 +01008180 nla_nest_end(msg, bss);
8181
Johannes Berg053c0952015-01-16 22:09:00 +01008182 genlmsg_end(msg, hdr);
8183 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008184
Johannes Berg8cef2c92013-02-05 16:54:31 +01008185 fail_unlock_rcu:
8186 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008187 nla_put_failure:
8188 genlmsg_cancel(msg, hdr);
8189 return -EMSGSIZE;
8190}
8191
Johannes Berg97990a02013-04-19 01:02:55 +02008192static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008193{
Johannes Berg48ab9052009-07-10 18:42:31 +02008194 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008195 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008196 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008197 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008198 int err;
8199
Johannes Bergea90e0d2017-03-15 14:26:04 +01008200 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02008201 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008202 if (err) {
8203 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008204 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008205 }
Johannes Berg2a519312009-02-10 21:25:55 +01008206
Johannes Berg48ab9052009-07-10 18:42:31 +02008207 wdev_lock(wdev);
8208 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008209
8210 /*
8211 * dump_scan will be called multiple times to break up the scan results
8212 * into multiple messages. It is unlikely that any more bss-es will be
8213 * expired after the first call, so only call only call this on the
8214 * first dump_scan invocation.
8215 */
8216 if (start == 0)
8217 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008218
Johannes Berg9720bb32011-06-21 09:45:33 +02008219 cb->seq = rdev->bss_generation;
8220
Johannes Berg48ab9052009-07-10 18:42:31 +02008221 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008222 if (++idx <= start)
8223 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008224 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008225 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008226 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008227 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008228 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008229 }
8230 }
8231
Johannes Berg48ab9052009-07-10 18:42:31 +02008232 spin_unlock_bh(&rdev->bss_lock);
8233 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008234
Johannes Berg97990a02013-04-19 01:02:55 +02008235 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008236 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008237
Johannes Berg67748892010-10-04 21:14:06 +02008238 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008239}
8240
Eric W. Biederman15e47302012-09-07 20:12:54 +00008241static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008242 int flags, struct net_device *dev,
8243 bool allow_radio_stats,
8244 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008245{
8246 void *hdr;
8247 struct nlattr *infoattr;
8248
Johannes Berg11f78ac2014-11-14 16:43:50 +01008249 /* skip radio stats if userspace didn't request them */
8250 if (!survey->channel && !allow_radio_stats)
8251 return 0;
8252
Eric W. Biederman15e47302012-09-07 20:12:54 +00008253 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008254 NL80211_CMD_NEW_SURVEY_RESULTS);
8255 if (!hdr)
8256 return -ENOMEM;
8257
David S. Miller9360ffd2012-03-29 04:41:26 -04008258 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8259 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008260
8261 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
8262 if (!infoattr)
8263 goto nla_put_failure;
8264
Johannes Berg11f78ac2014-11-14 16:43:50 +01008265 if (survey->channel &&
8266 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008267 survey->channel->center_freq))
8268 goto nla_put_failure;
8269
8270 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8271 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8272 goto nla_put_failure;
8273 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8274 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8275 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008276 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008277 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8278 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008279 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008280 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008281 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8282 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008283 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008284 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008285 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8286 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008287 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008288 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008289 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8290 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008291 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008292 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008293 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8294 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008295 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008296 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008297 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8298 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008299 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008300
8301 nla_nest_end(msg, infoattr);
8302
Johannes Berg053c0952015-01-16 22:09:00 +01008303 genlmsg_end(msg, hdr);
8304 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008305
8306 nla_put_failure:
8307 genlmsg_cancel(msg, hdr);
8308 return -EMSGSIZE;
8309}
8310
Johannes Berg11f78ac2014-11-14 16:43:50 +01008311static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008312{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008313 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008314 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008315 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008316 struct wireless_dev *wdev;
8317 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008318 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008319 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008320
Johannes Bergea90e0d2017-03-15 14:26:04 +01008321 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008322 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008323 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008324 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008325
Johannes Berg11f78ac2014-11-14 16:43:50 +01008326 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008327 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008328
Johannes Berg97990a02013-04-19 01:02:55 +02008329 if (!wdev->netdev) {
8330 res = -EINVAL;
8331 goto out_err;
8332 }
8333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008334 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008335 res = -EOPNOTSUPP;
8336 goto out_err;
8337 }
8338
8339 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008340 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008341 if (res == -ENOENT)
8342 break;
8343 if (res)
8344 goto out_err;
8345
Johannes Berg11f78ac2014-11-14 16:43:50 +01008346 /* don't send disabled channels, but do send non-channel data */
8347 if (survey.channel &&
8348 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008349 survey_idx++;
8350 continue;
8351 }
8352
Holger Schurig61fa7132009-11-11 12:25:40 +01008353 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008354 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008355 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008356 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008357 goto out;
8358 survey_idx++;
8359 }
8360
8361 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008362 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008363 res = skb->len;
8364 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008365 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008366 return res;
8367}
8368
Samuel Ortizb23aa672009-07-01 21:26:54 +02008369static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8370{
8371 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8372 NL80211_WPA_VERSION_2));
8373}
8374
Jouni Malinen636a5d32009-03-19 13:39:22 +02008375static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8376{
Johannes Berg4c476992010-10-04 21:36:35 +02008377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8378 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008379 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008380 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8381 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008382 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008383 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008384 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008385
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008386 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8387 return -EINVAL;
8388
8389 if (!info->attrs[NL80211_ATTR_MAC])
8390 return -EINVAL;
8391
Jouni Malinen17780922009-03-27 20:52:47 +02008392 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8393 return -EINVAL;
8394
Johannes Berg19957bb2009-07-02 17:20:43 +02008395 if (!info->attrs[NL80211_ATTR_SSID])
8396 return -EINVAL;
8397
8398 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8399 return -EINVAL;
8400
Johannes Bergfffd0932009-07-08 14:22:54 +02008401 err = nl80211_parse_key(info, &key);
8402 if (err)
8403 return err;
8404
8405 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008406 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8407 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008408 if (!key.p.key || !key.p.key_len)
8409 return -EINVAL;
8410 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8411 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8412 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8413 key.p.key_len != WLAN_KEY_LEN_WEP104))
8414 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008415 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008416 return -EINVAL;
8417 } else {
8418 key.p.key_len = 0;
8419 key.p.key = NULL;
8420 }
8421
Johannes Bergafea0b72010-08-10 09:46:42 +02008422 if (key.idx >= 0) {
8423 int i;
8424 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008425
Johannes Bergafea0b72010-08-10 09:46:42 +02008426 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8427 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8428 ok = true;
8429 break;
8430 }
8431 }
Johannes Berg4c476992010-10-04 21:36:35 +02008432 if (!ok)
8433 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008434 }
8435
Johannes Berg4c476992010-10-04 21:36:35 +02008436 if (!rdev->ops->auth)
8437 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008438
Johannes Berg074ac8d2010-09-16 14:58:22 +02008439 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008440 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8441 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008442
Johannes Berg19957bb2009-07-02 17:20:43 +02008443 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008444 chan = nl80211_get_valid_chan(&rdev->wiphy,
8445 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8446 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008447 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008448
Johannes Berg19957bb2009-07-02 17:20:43 +02008449 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8450 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8451
8452 if (info->attrs[NL80211_ATTR_IE]) {
8453 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8454 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8455 }
8456
8457 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008458 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008459 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008460
Jouni Malinen63181062016-10-27 00:42:02 +03008461 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8462 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8463 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8464 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008465 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008466 return -EINVAL;
8467
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008468 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008469 if (auth_type != NL80211_AUTHTYPE_SAE &&
8470 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8471 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8472 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008473 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008474 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8475 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008476 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008477 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008478 return -EINVAL;
8479 }
8480
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008481 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8482
Johannes Berg95de8172012-01-20 13:55:25 +01008483 /*
8484 * Since we no longer track auth state, ignore
8485 * requests to only change local state.
8486 */
8487 if (local_state_change)
8488 return 0;
8489
Johannes Berg91bf9b22013-05-15 17:44:01 +02008490 wdev_lock(dev->ieee80211_ptr);
8491 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8492 ssid, ssid_len, ie, ie_len,
8493 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008494 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008495 wdev_unlock(dev->ieee80211_ptr);
8496 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008497}
8498
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008499static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8500 struct genl_info *info)
8501{
8502 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8503 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8504 return -EINVAL;
8505 }
8506
8507 if (!rdev->ops->tx_control_port ||
8508 !wiphy_ext_feature_isset(&rdev->wiphy,
8509 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8510 return -EOPNOTSUPP;
8511
8512 return 0;
8513}
8514
Johannes Bergc0692b82010-08-27 14:26:53 +03008515static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8516 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008517 struct cfg80211_crypto_settings *settings,
8518 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008519{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008520 memset(settings, 0, sizeof(*settings));
8521
Samuel Ortizb23aa672009-07-01 21:26:54 +02008522 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8523
Johannes Bergc0692b82010-08-27 14:26:53 +03008524 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8525 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008526
Johannes Bergc0692b82010-08-27 14:26:53 +03008527 proto = nla_get_u16(
8528 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8529 settings->control_port_ethertype = cpu_to_be16(proto);
8530 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8531 proto != ETH_P_PAE)
8532 return -EINVAL;
8533 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8534 settings->control_port_no_encrypt = true;
8535 } else
8536 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8537
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008538 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8539 int r = validate_pae_over_nl80211(rdev, info);
8540
8541 if (r < 0)
8542 return r;
8543
8544 settings->control_port_over_nl80211 = true;
8545 }
8546
Samuel Ortizb23aa672009-07-01 21:26:54 +02008547 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8548 void *data;
8549 int len, i;
8550
8551 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8552 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8553 settings->n_ciphers_pairwise = len / sizeof(u32);
8554
8555 if (len % sizeof(u32))
8556 return -EINVAL;
8557
Johannes Berg3dc27d22009-07-02 21:36:37 +02008558 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008559 return -EINVAL;
8560
8561 memcpy(settings->ciphers_pairwise, data, len);
8562
8563 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008564 if (!cfg80211_supported_cipher_suite(
8565 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008566 settings->ciphers_pairwise[i]))
8567 return -EINVAL;
8568 }
8569
8570 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8571 settings->cipher_group =
8572 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008573 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8574 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008575 return -EINVAL;
8576 }
8577
8578 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8579 settings->wpa_versions =
8580 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8581 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8582 return -EINVAL;
8583 }
8584
8585 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8586 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008587 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008588
8589 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8590 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8591 settings->n_akm_suites = len / sizeof(u32);
8592
8593 if (len % sizeof(u32))
8594 return -EINVAL;
8595
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008596 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8597 return -EINVAL;
8598
Samuel Ortizb23aa672009-07-01 21:26:54 +02008599 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008600 }
8601
Eliad Peller91b5ab62017-06-09 13:08:42 +01008602 if (info->attrs[NL80211_ATTR_PMK]) {
8603 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8604 return -EINVAL;
8605 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8606 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8607 return -EINVAL;
8608 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8609 }
8610
Samuel Ortizb23aa672009-07-01 21:26:54 +02008611 return 0;
8612}
8613
Jouni Malinen636a5d32009-03-19 13:39:22 +02008614static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8615{
Johannes Berg4c476992010-10-04 21:36:35 +02008616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8617 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008618 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008619 struct cfg80211_assoc_request req = {};
8620 const u8 *bssid, *ssid;
8621 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008622
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008623 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8624 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8625 return -EPERM;
8626
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008627 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8628 return -EINVAL;
8629
8630 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008631 !info->attrs[NL80211_ATTR_SSID] ||
8632 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008633 return -EINVAL;
8634
Johannes Berg4c476992010-10-04 21:36:35 +02008635 if (!rdev->ops->assoc)
8636 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008637
Johannes Berg074ac8d2010-09-16 14:58:22 +02008638 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008639 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8640 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008641
Johannes Berg19957bb2009-07-02 17:20:43 +02008642 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008643
Jouni Malinen664834d2014-01-15 00:01:44 +02008644 chan = nl80211_get_valid_chan(&rdev->wiphy,
8645 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8646 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008647 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008648
Johannes Berg19957bb2009-07-02 17:20:43 +02008649 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8650 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008651
8652 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008653 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8654 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008655 }
8656
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008657 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008658 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008659 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008660 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008661 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008662 else if (mfp != NL80211_MFP_NO)
8663 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008664 }
8665
Johannes Berg3e5d7642009-07-07 14:37:26 +02008666 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008667 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008668
Ben Greear7e7c8922011-11-18 11:31:59 -08008669 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008670 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008671
8672 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008673 memcpy(&req.ht_capa_mask,
8674 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8675 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008676
8677 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008678 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008679 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008680 memcpy(&req.ht_capa,
8681 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8682 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008683 }
8684
Johannes Bergee2aca32013-02-21 17:36:01 +01008685 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008686 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008687
8688 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008689 memcpy(&req.vht_capa_mask,
8690 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8691 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008692
8693 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008694 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008695 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008696 memcpy(&req.vht_capa,
8697 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8698 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008699 }
8700
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008701 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008702 if (!((rdev->wiphy.features &
8703 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8704 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8705 !wiphy_ext_feature_isset(&rdev->wiphy,
8706 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008707 return -EINVAL;
8708 req.flags |= ASSOC_REQ_USE_RRM;
8709 }
8710
Jouni Malinen348bd452016-10-27 00:42:03 +03008711 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8712 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8713 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8714 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8715 return -EINVAL;
8716 req.fils_nonces =
8717 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8718 }
8719
Johannes Bergf62fab72013-02-21 20:09:09 +01008720 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008721 if (!err) {
8722 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008723
Johannes Bergf62fab72013-02-21 20:09:09 +01008724 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8725 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008726
8727 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8728 dev->ieee80211_ptr->conn_owner_nlportid =
8729 info->snd_portid;
8730 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8731 bssid, ETH_ALEN);
8732 }
8733
Johannes Berg91bf9b22013-05-15 17:44:01 +02008734 wdev_unlock(dev->ieee80211_ptr);
8735 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008736
Jouni Malinen636a5d32009-03-19 13:39:22 +02008737 return err;
8738}
8739
8740static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8741{
Johannes Berg4c476992010-10-04 21:36:35 +02008742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8743 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008744 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008745 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008746 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008747 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008748
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008749 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8750 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8751 return -EPERM;
8752
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008753 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8754 return -EINVAL;
8755
8756 if (!info->attrs[NL80211_ATTR_MAC])
8757 return -EINVAL;
8758
8759 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8760 return -EINVAL;
8761
Johannes Berg4c476992010-10-04 21:36:35 +02008762 if (!rdev->ops->deauth)
8763 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008764
Johannes Berg074ac8d2010-09-16 14:58:22 +02008765 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008766 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8767 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008768
Johannes Berg19957bb2009-07-02 17:20:43 +02008769 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008770
Johannes Berg19957bb2009-07-02 17:20:43 +02008771 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8772 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008773 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008774 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008775 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008776
8777 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008778 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8779 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008780 }
8781
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008782 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8783
Johannes Berg91bf9b22013-05-15 17:44:01 +02008784 wdev_lock(dev->ieee80211_ptr);
8785 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8786 local_state_change);
8787 wdev_unlock(dev->ieee80211_ptr);
8788 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008789}
8790
8791static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8792{
Johannes Berg4c476992010-10-04 21:36:35 +02008793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8794 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008795 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008796 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008797 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008798 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008799
Andrew Zaborowskibad29292018-05-22 02:46:02 +02008800 if (dev->ieee80211_ptr->conn_owner_nlportid &&
8801 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
8802 return -EPERM;
8803
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008804 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8805 return -EINVAL;
8806
8807 if (!info->attrs[NL80211_ATTR_MAC])
8808 return -EINVAL;
8809
8810 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8811 return -EINVAL;
8812
Johannes Berg4c476992010-10-04 21:36:35 +02008813 if (!rdev->ops->disassoc)
8814 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008815
Johannes Berg074ac8d2010-09-16 14:58:22 +02008816 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008817 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8818 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008819
Johannes Berg19957bb2009-07-02 17:20:43 +02008820 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008821
Johannes Berg19957bb2009-07-02 17:20:43 +02008822 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8823 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008824 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008825 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008826 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008827
8828 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008829 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8830 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008831 }
8832
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008833 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8834
Johannes Berg91bf9b22013-05-15 17:44:01 +02008835 wdev_lock(dev->ieee80211_ptr);
8836 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8837 local_state_change);
8838 wdev_unlock(dev->ieee80211_ptr);
8839 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008840}
8841
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008842static bool
8843nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008844 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008845 int rateval)
8846{
8847 struct wiphy *wiphy = &rdev->wiphy;
8848 bool found = false;
8849 int band, i;
8850
Johannes Berg57fbcce2016-04-12 15:56:15 +02008851 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008852 struct ieee80211_supported_band *sband;
8853
8854 sband = wiphy->bands[band];
8855 if (!sband)
8856 continue;
8857
8858 for (i = 0; i < sband->n_bitrates; i++) {
8859 if (sband->bitrates[i].bitrate == rateval) {
8860 mcast_rate[band] = i + 1;
8861 found = true;
8862 break;
8863 }
8864 }
8865 }
8866
8867 return found;
8868}
8869
Johannes Berg04a773a2009-04-19 21:24:32 +02008870static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8871{
Johannes Berg4c476992010-10-04 21:36:35 +02008872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8873 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008874 struct cfg80211_ibss_params ibss;
8875 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008876 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008877 int err;
8878
Johannes Berg8e30bc52009-04-22 17:45:38 +02008879 memset(&ibss, 0, sizeof(ibss));
8880
Johannes Berg04a773a2009-04-19 21:24:32 +02008881 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8882 return -EINVAL;
8883
Johannes Berg683b6d32012-11-08 21:25:48 +01008884 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008885 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8886 return -EINVAL;
8887
Johannes Berg8e30bc52009-04-22 17:45:38 +02008888 ibss.beacon_interval = 100;
8889
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308890 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008891 ibss.beacon_interval =
8892 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308893
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308894 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8895 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308896 if (err)
8897 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008898
Johannes Berg4c476992010-10-04 21:36:35 +02008899 if (!rdev->ops->join_ibss)
8900 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008901
Johannes Berg4c476992010-10-04 21:36:35 +02008902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8903 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008904
Johannes Berg79c97e92009-07-07 03:56:12 +02008905 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008906
Johannes Berg39193492011-09-16 13:45:25 +02008907 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008908 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008909
8910 if (!is_valid_ether_addr(ibss.bssid))
8911 return -EINVAL;
8912 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008913 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8914 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8915
8916 if (info->attrs[NL80211_ATTR_IE]) {
8917 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8918 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8919 }
8920
Johannes Berg683b6d32012-11-08 21:25:48 +01008921 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8922 if (err)
8923 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008924
Ilan Peer174e0cd2014-02-23 09:13:01 +02008925 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8926 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008927 return -EINVAL;
8928
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008929 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008930 case NL80211_CHAN_WIDTH_5:
8931 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008932 case NL80211_CHAN_WIDTH_20_NOHT:
8933 break;
8934 case NL80211_CHAN_WIDTH_20:
8935 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008936 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8937 return -EINVAL;
8938 break;
8939 case NL80211_CHAN_WIDTH_80:
8940 case NL80211_CHAN_WIDTH_80P80:
8941 case NL80211_CHAN_WIDTH_160:
8942 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8943 return -EINVAL;
8944 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8945 NL80211_EXT_FEATURE_VHT_IBSS))
8946 return -EINVAL;
8947 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008948 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008949 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008950 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008951
Johannes Berg04a773a2009-04-19 21:24:32 +02008952 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008953 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008954
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008955 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8956 u8 *rates =
8957 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8958 int n_rates =
8959 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8960 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008961 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008962
Johannes Berg34850ab2011-07-18 18:08:35 +02008963 err = ieee80211_get_ratemask(sband, rates, n_rates,
8964 &ibss.basic_rates);
8965 if (err)
8966 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008967 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008968
Simon Wunderlich803768f2013-06-28 10:39:58 +02008969 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8970 memcpy(&ibss.ht_capa_mask,
8971 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8972 sizeof(ibss.ht_capa_mask));
8973
8974 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8975 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8976 return -EINVAL;
8977 memcpy(&ibss.ht_capa,
8978 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8979 sizeof(ibss.ht_capa));
8980 }
8981
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008982 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8983 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8984 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8985 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008986
Johannes Berg4c476992010-10-04 21:36:35 +02008987 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308988 bool no_ht = false;
8989
Johannes Berg768075e2017-11-13 15:35:06 +01008990 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008991 if (IS_ERR(connkeys))
8992 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308993
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008994 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8995 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008996 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308997 return -EINVAL;
8998 }
Johannes Berg4c476992010-10-04 21:36:35 +02008999 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009000
Antonio Quartulli267335d2012-01-31 20:25:47 +01009001 ibss.control_port =
9002 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9003
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009004 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9005 int r = validate_pae_over_nl80211(rdev, info);
9006
9007 if (r < 0)
9008 return r;
9009
9010 ibss.control_port_over_nl80211 = true;
9011 }
9012
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009013 ibss.userspace_handles_dfs =
9014 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9015
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009016 wdev_lock(dev->ieee80211_ptr);
9017 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009018 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009019 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009020 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9021 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9022 wdev_unlock(dev->ieee80211_ptr);
9023
Johannes Berg04a773a2009-04-19 21:24:32 +02009024 return err;
9025}
9026
9027static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9028{
Johannes Berg4c476992010-10-04 21:36:35 +02009029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9030 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009031
Johannes Berg4c476992010-10-04 21:36:35 +02009032 if (!rdev->ops->leave_ibss)
9033 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009034
Johannes Berg4c476992010-10-04 21:36:35 +02009035 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9036 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009037
Johannes Berg4c476992010-10-04 21:36:35 +02009038 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009039}
9040
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009041static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9042{
9043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9044 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009045 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009046 u32 nla_rate;
9047 int err;
9048
9049 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009050 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9051 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009052 return -EOPNOTSUPP;
9053
9054 if (!rdev->ops->set_mcast_rate)
9055 return -EOPNOTSUPP;
9056
9057 memset(mcast_rate, 0, sizeof(mcast_rate));
9058
9059 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9060 return -EINVAL;
9061
9062 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9063 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9064 return -EINVAL;
9065
Ilan Peera1056b1b2015-10-22 22:27:46 +03009066 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009067
9068 return err;
9069}
9070
Johannes Bergad7e7182013-11-13 13:37:47 +01009071static struct sk_buff *
9072__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009073 struct wireless_dev *wdev, int approxlen,
9074 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009075 enum nl80211_attrs attr,
9076 const struct nl80211_vendor_cmd_info *info,
9077 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009078{
9079 struct sk_buff *skb;
9080 void *hdr;
9081 struct nlattr *data;
9082
9083 skb = nlmsg_new(approxlen + 100, gfp);
9084 if (!skb)
9085 return NULL;
9086
9087 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9088 if (!hdr) {
9089 kfree_skb(skb);
9090 return NULL;
9091 }
9092
9093 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9094 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009095
9096 if (info) {
9097 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9098 info->vendor_id))
9099 goto nla_put_failure;
9100 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9101 info->subcmd))
9102 goto nla_put_failure;
9103 }
9104
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009105 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009106 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9107 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009108 goto nla_put_failure;
9109 if (wdev->netdev &&
9110 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9111 wdev->netdev->ifindex))
9112 goto nla_put_failure;
9113 }
9114
Johannes Bergad7e7182013-11-13 13:37:47 +01009115 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009116 if (!data)
9117 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009118
9119 ((void **)skb->cb)[0] = rdev;
9120 ((void **)skb->cb)[1] = hdr;
9121 ((void **)skb->cb)[2] = data;
9122
9123 return skb;
9124
9125 nla_put_failure:
9126 kfree_skb(skb);
9127 return NULL;
9128}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009129
Johannes Berge03ad6e2014-01-01 17:22:30 +01009130struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009131 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009132 enum nl80211_commands cmd,
9133 enum nl80211_attrs attr,
9134 int vendor_event_idx,
9135 int approxlen, gfp_t gfp)
9136{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009137 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009138 const struct nl80211_vendor_cmd_info *info;
9139
9140 switch (cmd) {
9141 case NL80211_CMD_TESTMODE:
9142 if (WARN_ON(vendor_event_idx != -1))
9143 return NULL;
9144 info = NULL;
9145 break;
9146 case NL80211_CMD_VENDOR:
9147 if (WARN_ON(vendor_event_idx < 0 ||
9148 vendor_event_idx >= wiphy->n_vendor_events))
9149 return NULL;
9150 info = &wiphy->vendor_events[vendor_event_idx];
9151 break;
9152 default:
9153 WARN_ON(1);
9154 return NULL;
9155 }
9156
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009157 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009158 cmd, attr, info, gfp);
9159}
9160EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9161
9162void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9163{
9164 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9165 void *hdr = ((void **)skb->cb)[1];
9166 struct nlattr *data = ((void **)skb->cb)[2];
9167 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9168
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009169 /* clear CB data for netlink core to own from now on */
9170 memset(skb->cb, 0, sizeof(skb->cb));
9171
Johannes Berge03ad6e2014-01-01 17:22:30 +01009172 nla_nest_end(skb, data);
9173 genlmsg_end(skb, hdr);
9174
9175 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9176 mcgrp = NL80211_MCGRP_VENDOR;
9177
9178 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
9179 mcgrp, gfp);
9180}
9181EXPORT_SYMBOL(__cfg80211_send_event_skb);
9182
Johannes Bergaff89a92009-07-01 21:26:51 +02009183#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009184static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9185{
Johannes Berg4c476992010-10-04 21:36:35 +02009186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009187 struct wireless_dev *wdev =
9188 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009189 int err;
9190
David Spinadelfc73f112013-07-31 18:04:15 +03009191 if (!rdev->ops->testmode_cmd)
9192 return -EOPNOTSUPP;
9193
9194 if (IS_ERR(wdev)) {
9195 err = PTR_ERR(wdev);
9196 if (err != -EINVAL)
9197 return err;
9198 wdev = NULL;
9199 } else if (wdev->wiphy != &rdev->wiphy) {
9200 return -EINVAL;
9201 }
9202
Johannes Bergaff89a92009-07-01 21:26:51 +02009203 if (!info->attrs[NL80211_ATTR_TESTDATA])
9204 return -EINVAL;
9205
Johannes Bergad7e7182013-11-13 13:37:47 +01009206 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009207 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009208 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9209 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009210 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009211
Johannes Bergaff89a92009-07-01 21:26:51 +02009212 return err;
9213}
9214
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009215static int nl80211_testmode_dump(struct sk_buff *skb,
9216 struct netlink_callback *cb)
9217{
Johannes Berg00918d32011-12-13 17:22:05 +01009218 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009219 int err;
9220 long phy_idx;
9221 void *data = NULL;
9222 int data_len = 0;
9223
Johannes Berg5fe231e2013-05-08 21:45:15 +02009224 rtnl_lock();
9225
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009226 if (cb->args[0]) {
9227 /*
9228 * 0 is a valid index, but not valid for args[0],
9229 * so we need to offset by 1.
9230 */
9231 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009232
9233 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9234 if (!rdev) {
9235 err = -ENOENT;
9236 goto out_err;
9237 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009238 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009239 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9240
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009241 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02009242 attrbuf, nl80211_fam.maxattr,
9243 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009244 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009245 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009246
Johannes Bergc90c39d2016-10-24 14:40:01 +02009247 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009248 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009249 err = PTR_ERR(rdev);
9250 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009251 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009252 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009253
Johannes Bergc90c39d2016-10-24 14:40:01 +02009254 if (attrbuf[NL80211_ATTR_TESTDATA])
9255 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009256 }
9257
9258 if (cb->args[1]) {
9259 data = nla_data((void *)cb->args[1]);
9260 data_len = nla_len((void *)cb->args[1]);
9261 }
9262
Johannes Berg00918d32011-12-13 17:22:05 +01009263 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009264 err = -EOPNOTSUPP;
9265 goto out_err;
9266 }
9267
9268 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009269 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009270 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9271 NL80211_CMD_TESTMODE);
9272 struct nlattr *tmdata;
9273
Dan Carpentercb35fba2013-08-14 14:50:01 +03009274 if (!hdr)
9275 break;
9276
David S. Miller9360ffd2012-03-29 04:41:26 -04009277 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009278 genlmsg_cancel(skb, hdr);
9279 break;
9280 }
9281
9282 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
9283 if (!tmdata) {
9284 genlmsg_cancel(skb, hdr);
9285 break;
9286 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009287 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009288 nla_nest_end(skb, tmdata);
9289
9290 if (err == -ENOBUFS || err == -ENOENT) {
9291 genlmsg_cancel(skb, hdr);
9292 break;
9293 } else if (err) {
9294 genlmsg_cancel(skb, hdr);
9295 goto out_err;
9296 }
9297
9298 genlmsg_end(skb, hdr);
9299 }
9300
9301 err = skb->len;
9302 /* see above */
9303 cb->args[0] = phy_idx + 1;
9304 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009305 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009306 return err;
9307}
Johannes Bergaff89a92009-07-01 21:26:51 +02009308#endif
9309
Samuel Ortizb23aa672009-07-01 21:26:54 +02009310static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9311{
Johannes Berg4c476992010-10-04 21:36:35 +02009312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9313 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009314 struct cfg80211_connect_params connect;
9315 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009316 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009317 int err;
9318
9319 memset(&connect, 0, sizeof(connect));
9320
9321 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9322 return -EINVAL;
9323
9324 if (!info->attrs[NL80211_ATTR_SSID] ||
9325 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9326 return -EINVAL;
9327
9328 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9329 connect.auth_type =
9330 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009331 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9332 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009333 return -EINVAL;
9334 } else
9335 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9336
9337 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9338
Avraham Stern3a00df52017-06-09 13:08:43 +01009339 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9340 !wiphy_ext_feature_isset(&rdev->wiphy,
9341 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9342 return -EINVAL;
9343 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9344
Johannes Bergc0692b82010-08-27 14:26:53 +03009345 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009346 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009347 if (err)
9348 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009349
Johannes Berg074ac8d2010-09-16 14:58:22 +02009350 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009351 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9352 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009353
Johannes Berg79c97e92009-07-07 03:56:12 +02009354 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009355
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309356 connect.bg_scan_period = -1;
9357 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9358 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9359 connect.bg_scan_period =
9360 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9361 }
9362
Samuel Ortizb23aa672009-07-01 21:26:54 +02009363 if (info->attrs[NL80211_ATTR_MAC])
9364 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009365 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9366 connect.bssid_hint =
9367 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009368 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9369 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9370
9371 if (info->attrs[NL80211_ATTR_IE]) {
9372 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9373 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9374 }
9375
Jouni Malinencee00a92013-01-15 17:15:57 +02009376 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9377 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009378 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9379 !wiphy_ext_feature_isset(&rdev->wiphy,
9380 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9381 return -EOPNOTSUPP;
9382
Jouni Malinencee00a92013-01-15 17:15:57 +02009383 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009384 connect.mfp != NL80211_MFP_NO &&
9385 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02009386 return -EINVAL;
9387 } else {
9388 connect.mfp = NL80211_MFP_NO;
9389 }
9390
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009391 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9392 connect.prev_bssid =
9393 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9394
Samuel Ortizb23aa672009-07-01 21:26:54 +02009395 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009396 connect.channel = nl80211_get_valid_chan(
9397 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9398 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009399 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009400 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009401 connect.channel_hint = nl80211_get_valid_chan(
9402 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9403 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009404 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009405 }
9406
Johannes Bergfffd0932009-07-08 14:22:54 +02009407 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009408 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009409 if (IS_ERR(connkeys))
9410 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009411 }
9412
Ben Greear7e7c8922011-11-18 11:31:59 -08009413 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9414 connect.flags |= ASSOC_REQ_DISABLE_HT;
9415
9416 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9417 memcpy(&connect.ht_capa_mask,
9418 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9419 sizeof(connect.ht_capa_mask));
9420
9421 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009422 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009423 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009424 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009425 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009426 memcpy(&connect.ht_capa,
9427 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9428 sizeof(connect.ht_capa));
9429 }
9430
Johannes Bergee2aca32013-02-21 17:36:01 +01009431 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9432 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9433
9434 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9435 memcpy(&connect.vht_capa_mask,
9436 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9437 sizeof(connect.vht_capa_mask));
9438
9439 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9440 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009441 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009442 return -EINVAL;
9443 }
9444 memcpy(&connect.vht_capa,
9445 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9446 sizeof(connect.vht_capa));
9447 }
9448
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009449 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009450 if (!((rdev->wiphy.features &
9451 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9452 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9453 !wiphy_ext_feature_isset(&rdev->wiphy,
9454 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009455 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009456 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009457 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009458 connect.flags |= ASSOC_REQ_USE_RRM;
9459 }
9460
Lior David34d50512016-01-28 10:58:25 +02009461 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009462 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009463 kzfree(connkeys);
9464 return -EOPNOTSUPP;
9465 }
9466
Arend van Spriel38de03d2016-03-02 20:37:18 +01009467 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9468 /* bss selection makes no sense if bssid is set */
9469 if (connect.bssid) {
9470 kzfree(connkeys);
9471 return -EINVAL;
9472 }
9473
9474 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9475 wiphy, &connect.bss_select);
9476 if (err) {
9477 kzfree(connkeys);
9478 return err;
9479 }
9480 }
9481
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009482 if (wiphy_ext_feature_isset(&rdev->wiphy,
9483 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9484 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9485 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9486 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9487 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9488 connect.fils_erp_username =
9489 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9490 connect.fils_erp_username_len =
9491 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9492 connect.fils_erp_realm =
9493 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9494 connect.fils_erp_realm_len =
9495 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9496 connect.fils_erp_next_seq_num =
9497 nla_get_u16(
9498 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9499 connect.fils_erp_rrk =
9500 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9501 connect.fils_erp_rrk_len =
9502 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9503 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9504 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9505 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9506 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9507 kzfree(connkeys);
9508 return -EINVAL;
9509 }
9510
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009511 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9512 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309513 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009514 GENL_SET_ERR_MSG(info,
9515 "external auth requires connection ownership");
9516 return -EINVAL;
9517 }
9518 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9519 }
9520
Johannes Berg83739b02013-05-15 17:44:01 +02009521 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009522
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009523 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9524 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009525 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009526 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009527
9528 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9529 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9530 if (connect.bssid)
9531 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9532 connect.bssid, ETH_ALEN);
9533 else
9534 memset(dev->ieee80211_ptr->disconnect_bssid,
9535 0, ETH_ALEN);
9536 }
9537
9538 wdev_unlock(dev->ieee80211_ptr);
9539
Samuel Ortizb23aa672009-07-01 21:26:54 +02009540 return err;
9541}
9542
vamsi krishna088e8df2016-10-27 16:51:11 +03009543static int nl80211_update_connect_params(struct sk_buff *skb,
9544 struct genl_info *info)
9545{
9546 struct cfg80211_connect_params connect = {};
9547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9548 struct net_device *dev = info->user_ptr[1];
9549 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009550 bool fils_sk_offload;
9551 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +03009552 u32 changed = 0;
9553 int ret;
9554
9555 if (!rdev->ops->update_connect_params)
9556 return -EOPNOTSUPP;
9557
9558 if (info->attrs[NL80211_ATTR_IE]) {
9559 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9560 return -EINVAL;
9561 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9562 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9563 changed |= UPDATE_ASSOC_IES;
9564 }
9565
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +02009566 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
9567 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
9568
9569 /*
9570 * when driver supports fils-sk offload all attributes must be
9571 * provided. So the else covers "fils-sk-not-all" and
9572 * "no-fils-sk-any".
9573 */
9574 if (fils_sk_offload &&
9575 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9576 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9577 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9578 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9579 connect.fils_erp_username =
9580 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9581 connect.fils_erp_username_len =
9582 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9583 connect.fils_erp_realm =
9584 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9585 connect.fils_erp_realm_len =
9586 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9587 connect.fils_erp_next_seq_num =
9588 nla_get_u16(
9589 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9590 connect.fils_erp_rrk =
9591 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9592 connect.fils_erp_rrk_len =
9593 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9594 changed |= UPDATE_FILS_ERP_INFO;
9595 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9596 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9597 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9598 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9599 return -EINVAL;
9600 }
9601
9602 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9603 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9604 if (!nl80211_valid_auth_type(rdev, auth_type,
9605 NL80211_CMD_CONNECT))
9606 return -EINVAL;
9607
9608 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
9609 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
9610 return -EINVAL;
9611
9612 connect.auth_type = auth_type;
9613 changed |= UPDATE_AUTH_TYPE;
9614 }
9615
vamsi krishna088e8df2016-10-27 16:51:11 +03009616 wdev_lock(dev->ieee80211_ptr);
9617 if (!wdev->current_bss)
9618 ret = -ENOLINK;
9619 else
9620 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9621 wdev_unlock(dev->ieee80211_ptr);
9622
9623 return ret;
9624}
9625
Samuel Ortizb23aa672009-07-01 21:26:54 +02009626static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9627{
Johannes Berg4c476992010-10-04 21:36:35 +02009628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9629 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009630 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009631 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009632
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009633 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9634 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9635 return -EPERM;
9636
Samuel Ortizb23aa672009-07-01 21:26:54 +02009637 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9638 reason = WLAN_REASON_DEAUTH_LEAVING;
9639 else
9640 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9641
9642 if (reason == 0)
9643 return -EINVAL;
9644
Johannes Berg074ac8d2010-09-16 14:58:22 +02009645 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009646 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9647 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009648
Johannes Berg83739b02013-05-15 17:44:01 +02009649 wdev_lock(dev->ieee80211_ptr);
9650 ret = cfg80211_disconnect(rdev, dev, reason, true);
9651 wdev_unlock(dev->ieee80211_ptr);
9652 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009653}
9654
Johannes Berg463d0182009-07-14 00:33:35 +02009655static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9656{
Johannes Berg4c476992010-10-04 21:36:35 +02009657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009658 struct net *net;
9659 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009660
Vadim Kochan4b681c82015-01-12 16:34:05 +02009661 if (info->attrs[NL80211_ATTR_PID]) {
9662 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9663
9664 net = get_net_ns_by_pid(pid);
9665 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9666 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9667
9668 net = get_net_ns_by_fd(fd);
9669 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009670 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009671 }
Johannes Berg463d0182009-07-14 00:33:35 +02009672
Johannes Berg4c476992010-10-04 21:36:35 +02009673 if (IS_ERR(net))
9674 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009675
9676 err = 0;
9677
9678 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009679 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9680 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009681
Johannes Berg463d0182009-07-14 00:33:35 +02009682 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009683 return err;
9684}
9685
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009686static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9687{
Johannes Berg4c476992010-10-04 21:36:35 +02009688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009689 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9690 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009691 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009692 struct cfg80211_pmksa pmksa;
9693
9694 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9695
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009696 if (!info->attrs[NL80211_ATTR_PMKID])
9697 return -EINVAL;
9698
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009699 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009700
9701 if (info->attrs[NL80211_ATTR_MAC]) {
9702 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9703 } else if (info->attrs[NL80211_ATTR_SSID] &&
9704 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9705 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9706 info->attrs[NL80211_ATTR_PMK])) {
9707 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9708 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9709 pmksa.cache_id =
9710 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9711 } else {
9712 return -EINVAL;
9713 }
9714 if (info->attrs[NL80211_ATTR_PMK]) {
9715 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9716 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9717 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009718
Johannes Berg074ac8d2010-09-16 14:58:22 +02009719 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009720 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9721 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009722
9723 switch (info->genlhdr->cmd) {
9724 case NL80211_CMD_SET_PMKSA:
9725 rdev_ops = rdev->ops->set_pmksa;
9726 break;
9727 case NL80211_CMD_DEL_PMKSA:
9728 rdev_ops = rdev->ops->del_pmksa;
9729 break;
9730 default:
9731 WARN_ON(1);
9732 break;
9733 }
9734
Johannes Berg4c476992010-10-04 21:36:35 +02009735 if (!rdev_ops)
9736 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009737
Johannes Berg4c476992010-10-04 21:36:35 +02009738 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009739}
9740
9741static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9742{
Johannes Berg4c476992010-10-04 21:36:35 +02009743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9744 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009745
Johannes Berg074ac8d2010-09-16 14:58:22 +02009746 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009747 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9748 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009749
Johannes Berg4c476992010-10-04 21:36:35 +02009750 if (!rdev->ops->flush_pmksa)
9751 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009752
Hila Gonene35e4d22012-06-27 17:19:42 +03009753 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009754}
9755
Arik Nemtsov109086c2011-09-28 14:12:50 +03009756static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9757{
9758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9759 struct net_device *dev = info->user_ptr[1];
9760 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309761 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009762 u16 status_code;
9763 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009764 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009765
9766 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9767 !rdev->ops->tdls_mgmt)
9768 return -EOPNOTSUPP;
9769
9770 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9771 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9772 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9773 !info->attrs[NL80211_ATTR_IE] ||
9774 !info->attrs[NL80211_ATTR_MAC])
9775 return -EINVAL;
9776
9777 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9778 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9779 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9780 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009781 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309782 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9783 peer_capability =
9784 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009785
Hila Gonene35e4d22012-06-27 17:19:42 +03009786 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309787 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009788 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009789 nla_data(info->attrs[NL80211_ATTR_IE]),
9790 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009791}
9792
9793static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9794{
9795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9796 struct net_device *dev = info->user_ptr[1];
9797 enum nl80211_tdls_operation operation;
9798 u8 *peer;
9799
9800 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9801 !rdev->ops->tdls_oper)
9802 return -EOPNOTSUPP;
9803
9804 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9805 !info->attrs[NL80211_ATTR_MAC])
9806 return -EINVAL;
9807
9808 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9809 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9810
Hila Gonene35e4d22012-06-27 17:19:42 +03009811 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009812}
9813
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009814static int nl80211_remain_on_channel(struct sk_buff *skb,
9815 struct genl_info *info)
9816{
Johannes Berg4c476992010-10-04 21:36:35 +02009817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009818 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009819 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309820 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009821 struct sk_buff *msg;
9822 void *hdr;
9823 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009824 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009825 int err;
9826
9827 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9828 !info->attrs[NL80211_ATTR_DURATION])
9829 return -EINVAL;
9830
9831 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9832
Johannes Berg7c4ef712011-11-18 15:33:48 +01009833 if (!rdev->ops->remain_on_channel ||
9834 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009835 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009836
Johannes Bergebf348f2012-06-01 12:50:54 +02009837 /*
9838 * We should be on that channel for at least a minimum amount of
9839 * time (10ms) but no longer than the driver supports.
9840 */
9841 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9842 duration > rdev->wiphy.max_remain_on_channel_duration)
9843 return -EINVAL;
9844
Johannes Berg683b6d32012-11-08 21:25:48 +01009845 err = nl80211_parse_chandef(rdev, info, &chandef);
9846 if (err)
9847 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009848
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309849 wdev_lock(wdev);
9850 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9851 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9852 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9853 &chandef);
9854 if (compat_chandef != &chandef) {
9855 wdev_unlock(wdev);
9856 return -EBUSY;
9857 }
9858 }
9859 wdev_unlock(wdev);
9860
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009862 if (!msg)
9863 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009864
Eric W. Biederman15e47302012-09-07 20:12:54 +00009865 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009866 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009867 if (!hdr) {
9868 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009869 goto free_msg;
9870 }
9871
Johannes Berg683b6d32012-11-08 21:25:48 +01009872 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9873 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009874
9875 if (err)
9876 goto free_msg;
9877
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009878 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9879 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009880 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009881
9882 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009883
9884 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009885
9886 nla_put_failure:
9887 err = -ENOBUFS;
9888 free_msg:
9889 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009890 return err;
9891}
9892
9893static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9894 struct genl_info *info)
9895{
Johannes Berg4c476992010-10-04 21:36:35 +02009896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009897 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009898 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009899
9900 if (!info->attrs[NL80211_ATTR_COOKIE])
9901 return -EINVAL;
9902
Johannes Berg4c476992010-10-04 21:36:35 +02009903 if (!rdev->ops->cancel_remain_on_channel)
9904 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009905
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009906 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9907
Hila Gonene35e4d22012-06-27 17:19:42 +03009908 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009909}
9910
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009911static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9912 struct genl_info *info)
9913{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009914 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009916 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309917 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009918
Johannes Berg4c476992010-10-04 21:36:35 +02009919 if (!rdev->ops->set_bitrate_mask)
9920 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009921
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309922 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9923 if (err)
9924 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009925
Hila Gonene35e4d22012-06-27 17:19:42 +03009926 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009927}
9928
Johannes Berg2e161f782010-08-12 15:38:38 +02009929static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009930{
Johannes Berg4c476992010-10-04 21:36:35 +02009931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009932 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02009933 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009934
9935 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9936 return -EINVAL;
9937
Johannes Berg2e161f782010-08-12 15:38:38 +02009938 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9939 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009940
Johannes Berg71bbc992012-06-15 15:30:18 +02009941 switch (wdev->iftype) {
9942 case NL80211_IFTYPE_STATION:
9943 case NL80211_IFTYPE_ADHOC:
9944 case NL80211_IFTYPE_P2P_CLIENT:
9945 case NL80211_IFTYPE_AP:
9946 case NL80211_IFTYPE_AP_VLAN:
9947 case NL80211_IFTYPE_MESH_POINT:
9948 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009949 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009950 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009951 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009952 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009953 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009954 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009955
9956 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009957 if (!rdev->ops->mgmt_tx)
9958 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009959
Eric W. Biederman15e47302012-09-07 20:12:54 +00009960 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009961 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9962 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009963}
9964
Johannes Berg2e161f782010-08-12 15:38:38 +02009965static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009966{
Johannes Berg4c476992010-10-04 21:36:35 +02009967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009968 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009969 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009970 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009971 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009972 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009973 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009974 struct cfg80211_mgmt_tx_params params = {
9975 .dont_wait_for_ack =
9976 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9977 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009978
Johannes Berg683b6d32012-11-08 21:25:48 +01009979 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009980 return -EINVAL;
9981
Johannes Berg4c476992010-10-04 21:36:35 +02009982 if (!rdev->ops->mgmt_tx)
9983 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009984
Johannes Berg71bbc992012-06-15 15:30:18 +02009985 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009986 case NL80211_IFTYPE_P2P_DEVICE:
9987 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9988 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009989 case NL80211_IFTYPE_STATION:
9990 case NL80211_IFTYPE_ADHOC:
9991 case NL80211_IFTYPE_P2P_CLIENT:
9992 case NL80211_IFTYPE_AP:
9993 case NL80211_IFTYPE_AP_VLAN:
9994 case NL80211_IFTYPE_MESH_POINT:
9995 case NL80211_IFTYPE_P2P_GO:
9996 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009997 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009998 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009999 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010000 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010001
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010002 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010003 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010004 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010005 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010006
10007 /*
10008 * We should wait on the channel for at least a minimum amount
10009 * of time (10ms) but no longer than the driver supports.
10010 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010011 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10012 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010013 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010014 }
10015
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010016 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010017
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010018 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010019 return -EINVAL;
10020
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010021 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010022
Antonio Quartulliea141b752013-06-11 14:20:03 +020010023 /* get the channel if any has been specified, otherwise pass NULL to
10024 * the driver. The latter will use the current one
10025 */
10026 chandef.chan = NULL;
10027 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10028 err = nl80211_parse_chandef(rdev, info, &chandef);
10029 if (err)
10030 return err;
10031 }
10032
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010033 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010034 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010035
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010036 wdev_lock(wdev);
10037 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10038 wdev_unlock(wdev);
10039 return -EBUSY;
10040 }
10041 wdev_unlock(wdev);
10042
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010043 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10044 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10045
10046 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10047 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10048 int i;
10049
10050 if (len % sizeof(u16))
10051 return -EINVAL;
10052
10053 params.n_csa_offsets = len / sizeof(u16);
10054 params.csa_offsets =
10055 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10056
10057 /* check that all the offsets fit the frame */
10058 for (i = 0; i < params.n_csa_offsets; i++) {
10059 if (params.csa_offsets[i] >= params.len)
10060 return -EINVAL;
10061 }
10062 }
10063
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010064 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10066 if (!msg)
10067 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010068
Eric W. Biederman15e47302012-09-07 20:12:54 +000010069 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010070 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010071 if (!hdr) {
10072 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010073 goto free_msg;
10074 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010075 }
Johannes Berge247bd902011-11-04 11:18:21 +010010076
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010077 params.chan = chandef.chan;
10078 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010079 if (err)
10080 goto free_msg;
10081
Johannes Berge247bd902011-11-04 11:18:21 +010010082 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010083 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10084 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010085 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010086
Johannes Berge247bd902011-11-04 11:18:21 +010010087 genlmsg_end(msg, hdr);
10088 return genlmsg_reply(msg, info);
10089 }
10090
10091 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010092
10093 nla_put_failure:
10094 err = -ENOBUFS;
10095 free_msg:
10096 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010097 return err;
10098}
10099
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010100static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10101{
10102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010103 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010104 u64 cookie;
10105
10106 if (!info->attrs[NL80211_ATTR_COOKIE])
10107 return -EINVAL;
10108
10109 if (!rdev->ops->mgmt_tx_cancel_wait)
10110 return -EOPNOTSUPP;
10111
Johannes Berg71bbc992012-06-15 15:30:18 +020010112 switch (wdev->iftype) {
10113 case NL80211_IFTYPE_STATION:
10114 case NL80211_IFTYPE_ADHOC:
10115 case NL80211_IFTYPE_P2P_CLIENT:
10116 case NL80211_IFTYPE_AP:
10117 case NL80211_IFTYPE_AP_VLAN:
10118 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010119 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010120 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010121 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010122 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010123 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010124 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010125
10126 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10127
Hila Gonene35e4d22012-06-27 17:19:42 +030010128 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010129}
10130
Kalle Valoffb9eb32010-02-17 17:58:10 +020010131static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10132{
Johannes Berg4c476992010-10-04 21:36:35 +020010133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010134 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010135 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010136 u8 ps_state;
10137 bool state;
10138 int err;
10139
Johannes Berg4c476992010-10-04 21:36:35 +020010140 if (!info->attrs[NL80211_ATTR_PS_STATE])
10141 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010142
10143 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10144
Johannes Berg4c476992010-10-04 21:36:35 +020010145 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
10146 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010147
10148 wdev = dev->ieee80211_ptr;
10149
Johannes Berg4c476992010-10-04 21:36:35 +020010150 if (!rdev->ops->set_power_mgmt)
10151 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010152
10153 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10154
10155 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010156 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010157
Hila Gonene35e4d22012-06-27 17:19:42 +030010158 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010159 if (!err)
10160 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010161 return err;
10162}
10163
10164static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10165{
Johannes Berg4c476992010-10-04 21:36:35 +020010166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010167 enum nl80211_ps_state ps_state;
10168 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010169 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010170 struct sk_buff *msg;
10171 void *hdr;
10172 int err;
10173
Kalle Valoffb9eb32010-02-17 17:58:10 +020010174 wdev = dev->ieee80211_ptr;
10175
Johannes Berg4c476992010-10-04 21:36:35 +020010176 if (!rdev->ops->set_power_mgmt)
10177 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010178
10179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010180 if (!msg)
10181 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010182
Eric W. Biederman15e47302012-09-07 20:12:54 +000010183 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010184 NL80211_CMD_GET_POWER_SAVE);
10185 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010186 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010187 goto free_msg;
10188 }
10189
10190 if (wdev->ps)
10191 ps_state = NL80211_PS_ENABLED;
10192 else
10193 ps_state = NL80211_PS_DISABLED;
10194
David S. Miller9360ffd2012-03-29 04:41:26 -040010195 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10196 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010197
10198 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010199 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010200
Johannes Berg4c476992010-10-04 21:36:35 +020010201 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010202 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010203 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010204 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010205 return err;
10206}
10207
Johannes Berg94e860f2014-01-20 23:58:15 +010010208static const struct nla_policy
10209nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010210 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010211 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10212 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010213 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10214 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10215 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010216 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010217};
10218
Thomas Pedersen84f10702012-07-12 16:17:33 -070010219static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010220 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010221{
10222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010223 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010224 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010225
Johannes Bergd9d8b012012-11-26 12:51:52 +010010226 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010227 return -EINVAL;
10228
Thomas Pedersen84f10702012-07-12 16:17:33 -070010229 if (!rdev->ops->set_cqm_txe_config)
10230 return -EOPNOTSUPP;
10231
10232 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10233 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10234 return -EOPNOTSUPP;
10235
Hila Gonene35e4d22012-06-27 17:19:42 +030010236 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010237}
10238
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010239static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10240 struct net_device *dev)
10241{
10242 struct wireless_dev *wdev = dev->ieee80211_ptr;
10243 s32 last, low, high;
10244 u32 hyst;
10245 int i, n;
10246 int err;
10247
10248 /* RSSI reporting disabled? */
10249 if (!wdev->cqm_config)
10250 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10251
10252 /*
10253 * Obtain current RSSI value if possible, if not and no RSSI threshold
10254 * event has been received yet, we should receive an event after a
10255 * connection is established and enough beacons received to calculate
10256 * the average.
10257 */
10258 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10259 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010260 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010261 u8 *mac_addr;
10262
10263 mac_addr = wdev->current_bss->pub.bssid;
10264
Johannes Berg73887fd2018-05-18 09:57:55 +020010265 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10266 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010267 return err;
10268
Omer Efrat397c6572018-06-17 13:06:14 +030010269 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010270 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010271 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010272 }
10273
10274 last = wdev->cqm_config->last_rssi_event_value;
10275 hyst = wdev->cqm_config->rssi_hyst;
10276 n = wdev->cqm_config->n_rssi_thresholds;
10277
10278 for (i = 0; i < n; i++)
10279 if (last < wdev->cqm_config->rssi_thresholds[i])
10280 break;
10281
10282 low = i > 0 ?
10283 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
10284 high = i < n ?
10285 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
10286
10287 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10288}
10289
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010290static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010291 const s32 *thresholds, int n_thresholds,
10292 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010293{
Johannes Berg4c476992010-10-04 21:36:35 +020010294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010295 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010296 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010297 int i, err;
10298 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010299
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010300 /* Check all values negative and sorted */
10301 for (i = 0; i < n_thresholds; i++) {
10302 if (thresholds[i] > 0 || thresholds[i] <= prev)
10303 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010304
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010305 prev = thresholds[i];
10306 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010307
Johannes Berg074ac8d2010-09-16 14:58:22 +020010308 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010309 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10310 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010311
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010312 wdev_lock(wdev);
10313 cfg80211_cqm_config_free(wdev);
10314 wdev_unlock(wdev);
10315
10316 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10317 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10318 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10319
10320 return rdev_set_cqm_rssi_config(rdev, dev,
10321 thresholds[0], hysteresis);
10322 }
10323
10324 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10325 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10326 return -EOPNOTSUPP;
10327
10328 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10329 n_thresholds = 0;
10330
10331 wdev_lock(wdev);
10332 if (n_thresholds) {
10333 struct cfg80211_cqm_config *cqm_config;
10334
10335 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10336 n_thresholds * sizeof(s32), GFP_KERNEL);
10337 if (!cqm_config) {
10338 err = -ENOMEM;
10339 goto unlock;
10340 }
10341
10342 cqm_config->rssi_hyst = hysteresis;
10343 cqm_config->n_rssi_thresholds = n_thresholds;
10344 memcpy(cqm_config->rssi_thresholds, thresholds,
10345 n_thresholds * sizeof(s32));
10346
10347 wdev->cqm_config = cqm_config;
10348 }
10349
10350 err = cfg80211_cqm_rssi_update(rdev, dev);
10351
10352unlock:
10353 wdev_unlock(wdev);
10354
10355 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010356}
10357
10358static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10359{
10360 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10361 struct nlattr *cqm;
10362 int err;
10363
10364 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010365 if (!cqm)
10366 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010367
10368 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +020010369 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010370 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010371 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010372
10373 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10374 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010375 const s32 *thresholds =
10376 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10377 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010378 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010379
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010380 if (len % 4)
10381 return -EINVAL;
10382
10383 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10384 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010385 }
10386
10387 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10388 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10389 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10390 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10391 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10392 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10393
10394 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10395 }
10396
10397 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010398}
10399
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010400static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10401{
10402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10403 struct net_device *dev = info->user_ptr[1];
10404 struct ocb_setup setup = {};
10405 int err;
10406
10407 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10408 if (err)
10409 return err;
10410
10411 return cfg80211_join_ocb(rdev, dev, &setup);
10412}
10413
10414static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10415{
10416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10417 struct net_device *dev = info->user_ptr[1];
10418
10419 return cfg80211_leave_ocb(rdev, dev);
10420}
10421
Johannes Berg29cbe682010-12-03 09:20:44 +010010422static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10423{
10424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10425 struct net_device *dev = info->user_ptr[1];
10426 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010427 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010428 int err;
10429
10430 /* start with default */
10431 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010432 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010433
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010434 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010435 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010436 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010437 if (err)
10438 return err;
10439 }
10440
10441 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10442 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10443 return -EINVAL;
10444
Javier Cardonac80d5452010-12-16 17:37:49 -080010445 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10446 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10447
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010448 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10449 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10450 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10451 return -EINVAL;
10452
Marco Porsch9bdbf042013-01-07 16:04:51 +010010453 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10454 setup.beacon_interval =
10455 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010456
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010457 err = cfg80211_validate_beacon_int(rdev,
10458 NL80211_IFTYPE_MESH_POINT,
10459 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010460 if (err)
10461 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010462 }
10463
10464 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10465 setup.dtim_period =
10466 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10467 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10468 return -EINVAL;
10469 }
10470
Javier Cardonac80d5452010-12-16 17:37:49 -080010471 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10472 /* parse additional setup parameters if given */
10473 err = nl80211_parse_mesh_setup(info, &setup);
10474 if (err)
10475 return err;
10476 }
10477
Thomas Pedersend37bb182013-03-04 13:06:13 -080010478 if (setup.user_mpm)
10479 cfg.auto_open_plinks = false;
10480
Johannes Bergcc1d2802012-05-16 23:50:20 +020010481 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010482 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10483 if (err)
10484 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010485 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010486 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010487 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010488 }
10489
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010490 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10491 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10492 int n_rates =
10493 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10494 struct ieee80211_supported_band *sband;
10495
10496 if (!setup.chandef.chan)
10497 return -EINVAL;
10498
10499 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10500
10501 err = ieee80211_get_ratemask(sband, rates, n_rates,
10502 &setup.basic_rates);
10503 if (err)
10504 return err;
10505 }
10506
Johannes Berg8564e382016-09-19 09:44:44 +020010507 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10508 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10509 if (err)
10510 return err;
10511
Johannes Berg265698d2017-09-18 22:46:36 +020010512 if (!setup.chandef.chan)
10513 return -EINVAL;
10514
Johannes Berg8564e382016-09-19 09:44:44 +020010515 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10516 &setup.beacon_rate);
10517 if (err)
10518 return err;
10519 }
10520
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010521 setup.userspace_handles_dfs =
10522 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10523
Denis Kenzior1224f582018-03-26 12:52:49 -050010524 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10525 int r = validate_pae_over_nl80211(rdev, info);
10526
10527 if (r < 0)
10528 return r;
10529
10530 setup.control_port_over_nl80211 = true;
10531 }
10532
Denis Kenzior188c1b32018-03-26 12:52:46 -050010533 wdev_lock(dev->ieee80211_ptr);
10534 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10535 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10536 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10537 wdev_unlock(dev->ieee80211_ptr);
10538
10539 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010540}
10541
10542static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10543{
10544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10545 struct net_device *dev = info->user_ptr[1];
10546
10547 return cfg80211_leave_mesh(rdev, dev);
10548}
10549
Johannes Bergdfb89c52012-06-27 09:23:48 +020010550#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010551static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10552 struct cfg80211_registered_device *rdev)
10553{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010554 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010555 struct nlattr *nl_pats, *nl_pat;
10556 int i, pat_len;
10557
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010558 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010559 return 0;
10560
10561 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10562 if (!nl_pats)
10563 return -ENOBUFS;
10564
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010565 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010566 nl_pat = nla_nest_start(msg, i + 1);
10567 if (!nl_pat)
10568 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010569 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010570 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010571 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010572 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10573 wowlan->patterns[i].pattern) ||
10574 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010575 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010576 return -ENOBUFS;
10577 nla_nest_end(msg, nl_pat);
10578 }
10579 nla_nest_end(msg, nl_pats);
10580
10581 return 0;
10582}
10583
Johannes Berg2a0e0472013-01-23 22:57:40 +010010584static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10585 struct cfg80211_wowlan_tcp *tcp)
10586{
10587 struct nlattr *nl_tcp;
10588
10589 if (!tcp)
10590 return 0;
10591
10592 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10593 if (!nl_tcp)
10594 return -ENOBUFS;
10595
Jiri Benc930345e2015-03-29 16:59:25 +020010596 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10597 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010598 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10599 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10600 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10601 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10602 tcp->payload_len, tcp->payload) ||
10603 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10604 tcp->data_interval) ||
10605 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10606 tcp->wake_len, tcp->wake_data) ||
10607 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10608 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10609 return -ENOBUFS;
10610
10611 if (tcp->payload_seq.len &&
10612 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10613 sizeof(tcp->payload_seq), &tcp->payload_seq))
10614 return -ENOBUFS;
10615
10616 if (tcp->payload_tok.len &&
10617 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10618 sizeof(tcp->payload_tok) + tcp->tokens_size,
10619 &tcp->payload_tok))
10620 return -ENOBUFS;
10621
Johannes Berge248ad32013-05-16 10:24:28 +020010622 nla_nest_end(msg, nl_tcp);
10623
Johannes Berg2a0e0472013-01-23 22:57:40 +010010624 return 0;
10625}
10626
Luciano Coelho75453cc2015-01-09 14:06:37 +020010627static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10628 struct cfg80211_sched_scan_request *req)
10629{
Avraham Stern3b06d272015-10-12 09:51:34 +030010630 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010631 int i;
10632
10633 if (!req)
10634 return 0;
10635
10636 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10637 if (!nd)
10638 return -ENOBUFS;
10639
Avraham Stern3b06d272015-10-12 09:51:34 +030010640 if (req->n_scan_plans == 1 &&
10641 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10642 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010643 return -ENOBUFS;
10644
Luciano Coelho21fea562015-03-17 16:36:01 +020010645 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10646 return -ENOBUFS;
10647
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010648 if (req->relative_rssi_set) {
10649 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10650
10651 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10652 req->relative_rssi))
10653 return -ENOBUFS;
10654
10655 rssi_adjust.band = req->rssi_adjust.band;
10656 rssi_adjust.delta = req->rssi_adjust.delta;
10657 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10658 sizeof(rssi_adjust), &rssi_adjust))
10659 return -ENOBUFS;
10660 }
10661
Luciano Coelho75453cc2015-01-09 14:06:37 +020010662 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10663 if (!freqs)
10664 return -ENOBUFS;
10665
Johannes Berg53b18982016-09-14 09:59:21 +020010666 for (i = 0; i < req->n_channels; i++) {
10667 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10668 return -ENOBUFS;
10669 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010670
10671 nla_nest_end(msg, freqs);
10672
10673 if (req->n_match_sets) {
10674 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010675 if (!matches)
10676 return -ENOBUFS;
10677
Luciano Coelho75453cc2015-01-09 14:06:37 +020010678 for (i = 0; i < req->n_match_sets; i++) {
10679 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010680 if (!match)
10681 return -ENOBUFS;
10682
Johannes Berg53b18982016-09-14 09:59:21 +020010683 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10684 req->match_sets[i].ssid.ssid_len,
10685 req->match_sets[i].ssid.ssid))
10686 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010687 nla_nest_end(msg, match);
10688 }
10689 nla_nest_end(msg, matches);
10690 }
10691
Avraham Stern3b06d272015-10-12 09:51:34 +030010692 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10693 if (!scan_plans)
10694 return -ENOBUFS;
10695
10696 for (i = 0; i < req->n_scan_plans; i++) {
10697 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010698 if (!scan_plan)
10699 return -ENOBUFS;
10700
Avraham Stern3b06d272015-10-12 09:51:34 +030010701 if (!scan_plan ||
10702 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10703 req->scan_plans[i].interval) ||
10704 (req->scan_plans[i].iterations &&
10705 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10706 req->scan_plans[i].iterations)))
10707 return -ENOBUFS;
10708 nla_nest_end(msg, scan_plan);
10709 }
10710 nla_nest_end(msg, scan_plans);
10711
Luciano Coelho75453cc2015-01-09 14:06:37 +020010712 nla_nest_end(msg, nd);
10713
10714 return 0;
10715}
10716
Johannes Bergff1b6e62011-05-04 15:37:28 +020010717static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10718{
10719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10720 struct sk_buff *msg;
10721 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010722 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010723
Johannes Berg964dc9e2013-06-03 17:25:34 +020010724 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010725 return -EOPNOTSUPP;
10726
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010727 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010728 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010729 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10730 rdev->wiphy.wowlan_config->tcp->payload_len +
10731 rdev->wiphy.wowlan_config->tcp->wake_len +
10732 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010733 }
10734
10735 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010736 if (!msg)
10737 return -ENOMEM;
10738
Eric W. Biederman15e47302012-09-07 20:12:54 +000010739 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010740 NL80211_CMD_GET_WOWLAN);
10741 if (!hdr)
10742 goto nla_put_failure;
10743
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010744 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010745 struct nlattr *nl_wowlan;
10746
10747 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10748 if (!nl_wowlan)
10749 goto nla_put_failure;
10750
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010751 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010752 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010753 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010754 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010755 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010756 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010757 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010758 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010759 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010760 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010761 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010762 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010763 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010764 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10765 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010766
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010767 if (nl80211_send_wowlan_patterns(msg, rdev))
10768 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010769
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010770 if (nl80211_send_wowlan_tcp(msg,
10771 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010772 goto nla_put_failure;
10773
Luciano Coelho75453cc2015-01-09 14:06:37 +020010774 if (nl80211_send_wowlan_nd(
10775 msg,
10776 rdev->wiphy.wowlan_config->nd_config))
10777 goto nla_put_failure;
10778
Johannes Bergff1b6e62011-05-04 15:37:28 +020010779 nla_nest_end(msg, nl_wowlan);
10780 }
10781
10782 genlmsg_end(msg, hdr);
10783 return genlmsg_reply(msg, info);
10784
10785nla_put_failure:
10786 nlmsg_free(msg);
10787 return -ENOBUFS;
10788}
10789
Johannes Berg2a0e0472013-01-23 22:57:40 +010010790static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10791 struct nlattr *attr,
10792 struct cfg80211_wowlan *trig)
10793{
10794 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10795 struct cfg80211_wowlan_tcp *cfg;
10796 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10797 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10798 u32 size;
10799 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10800 int err, port;
10801
Johannes Berg964dc9e2013-06-03 17:25:34 +020010802 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010803 return -EINVAL;
10804
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010805 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010806 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010807 if (err)
10808 return err;
10809
10810 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10811 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10812 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10813 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10814 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10815 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10816 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10817 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10818 return -EINVAL;
10819
10820 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010821 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010822 return -EINVAL;
10823
10824 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010825 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010826 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010827 return -EINVAL;
10828
10829 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010830 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010831 return -EINVAL;
10832
10833 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10834 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10835 return -EINVAL;
10836
10837 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10838 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10839
10840 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10841 tokens_size = tokln - sizeof(*tok);
10842
10843 if (!tok->len || tokens_size % tok->len)
10844 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010845 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010846 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010847 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010848 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010849 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010850 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010851 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010852 return -EINVAL;
10853 if (tok->offset + tok->len > data_size)
10854 return -EINVAL;
10855 }
10856
10857 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10858 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010859 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010860 return -EINVAL;
10861 if (seq->len == 0 || seq->len > 4)
10862 return -EINVAL;
10863 if (seq->len + seq->offset > data_size)
10864 return -EINVAL;
10865 }
10866
10867 size = sizeof(*cfg);
10868 size += data_size;
10869 size += wake_size + wake_mask_size;
10870 size += tokens_size;
10871
10872 cfg = kzalloc(size, GFP_KERNEL);
10873 if (!cfg)
10874 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010875 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10876 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010877 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10878 ETH_ALEN);
10879 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10880 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10881 else
10882 port = 0;
10883#ifdef CONFIG_INET
10884 /* allocate a socket and port for it and use it */
10885 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10886 IPPROTO_TCP, &cfg->sock, 1);
10887 if (err) {
10888 kfree(cfg);
10889 return err;
10890 }
10891 if (inet_csk_get_port(cfg->sock->sk, port)) {
10892 sock_release(cfg->sock);
10893 kfree(cfg);
10894 return -EADDRINUSE;
10895 }
10896 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10897#else
10898 if (!port) {
10899 kfree(cfg);
10900 return -EINVAL;
10901 }
10902 cfg->src_port = port;
10903#endif
10904
10905 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10906 cfg->payload_len = data_size;
10907 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10908 memcpy((void *)cfg->payload,
10909 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10910 data_size);
10911 if (seq)
10912 cfg->payload_seq = *seq;
10913 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10914 cfg->wake_len = wake_size;
10915 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10916 memcpy((void *)cfg->wake_data,
10917 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10918 wake_size);
10919 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10920 data_size + wake_size;
10921 memcpy((void *)cfg->wake_mask,
10922 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10923 wake_mask_size);
10924 if (tok) {
10925 cfg->tokens_size = tokens_size;
10926 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10927 }
10928
10929 trig->tcp = cfg;
10930
10931 return 0;
10932}
10933
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010934static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10935 const struct wiphy_wowlan_support *wowlan,
10936 struct nlattr *attr,
10937 struct cfg80211_wowlan *trig)
10938{
10939 struct nlattr **tb;
10940 int err;
10941
10942 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10943 if (!tb)
10944 return -ENOMEM;
10945
10946 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10947 err = -EOPNOTSUPP;
10948 goto out;
10949 }
10950
Johannes Bergfceb6432017-04-12 14:34:07 +020010951 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10952 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010953 if (err)
10954 goto out;
10955
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010956 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10957 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010958 err = PTR_ERR_OR_ZERO(trig->nd_config);
10959 if (err)
10960 trig->nd_config = NULL;
10961
10962out:
10963 kfree(tb);
10964 return err;
10965}
10966
Johannes Bergff1b6e62011-05-04 15:37:28 +020010967static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10968{
10969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10970 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010971 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010972 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010973 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010974 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010975 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010976 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010977
Johannes Berg964dc9e2013-06-03 17:25:34 +020010978 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010979 return -EOPNOTSUPP;
10980
Johannes Bergae33bd82012-07-12 16:25:02 +020010981 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10982 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010983 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010984 goto set_wakeup;
10985 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010986
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010987 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10988 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010989 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010990 if (err)
10991 return err;
10992
10993 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10994 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10995 return -EINVAL;
10996 new_triggers.any = true;
10997 }
10998
10999 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11000 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11001 return -EINVAL;
11002 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011003 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011004 }
11005
11006 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11007 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11008 return -EINVAL;
11009 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011010 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011011 }
11012
Johannes Berg77dbbb12011-07-13 10:48:55 +020011013 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11014 return -EINVAL;
11015
11016 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11017 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11018 return -EINVAL;
11019 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011020 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011021 }
11022
11023 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11024 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11025 return -EINVAL;
11026 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011027 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011028 }
11029
11030 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11031 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11032 return -EINVAL;
11033 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011034 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011035 }
11036
11037 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11038 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11039 return -EINVAL;
11040 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011041 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011042 }
11043
Johannes Bergff1b6e62011-05-04 15:37:28 +020011044 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11045 struct nlattr *pat;
11046 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011047 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011048 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011049
Johannes Berg98fc4382015-03-01 09:10:13 +020011050 regular = true;
11051
Johannes Bergff1b6e62011-05-04 15:37:28 +020011052 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11053 rem)
11054 n_patterns++;
11055 if (n_patterns > wowlan->n_patterns)
11056 return -EINVAL;
11057
11058 new_triggers.patterns = kcalloc(n_patterns,
11059 sizeof(new_triggers.patterns[0]),
11060 GFP_KERNEL);
11061 if (!new_triggers.patterns)
11062 return -ENOMEM;
11063
11064 new_triggers.n_patterns = n_patterns;
11065 i = 0;
11066
11067 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11068 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011069 u8 *mask_pat;
11070
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011071 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030011072 nl80211_packet_pattern_policy,
11073 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011074 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011075 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11076 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011077 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011078 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011079 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011080 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011081 goto error;
11082 if (pat_len > wowlan->pattern_max_len ||
11083 pat_len < wowlan->pattern_min_len)
11084 goto error;
11085
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011086 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011087 pkt_offset = 0;
11088 else
11089 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011090 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011091 if (pkt_offset > wowlan->max_pkt_offset)
11092 goto error;
11093 new_triggers.patterns[i].pkt_offset = pkt_offset;
11094
Johannes Berg922bd802014-05-19 17:59:50 +020011095 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11096 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011097 err = -ENOMEM;
11098 goto error;
11099 }
Johannes Berg922bd802014-05-19 17:59:50 +020011100 new_triggers.patterns[i].mask = mask_pat;
11101 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011102 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011103 mask_pat += mask_len;
11104 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011105 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011106 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011107 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011108 pat_len);
11109 i++;
11110 }
11111 }
11112
Johannes Berg2a0e0472013-01-23 22:57:40 +010011113 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011114 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011115 err = nl80211_parse_wowlan_tcp(
11116 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11117 &new_triggers);
11118 if (err)
11119 goto error;
11120 }
11121
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011122 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011123 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011124 err = nl80211_parse_wowlan_nd(
11125 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11126 &new_triggers);
11127 if (err)
11128 goto error;
11129 }
11130
Johannes Berg98fc4382015-03-01 09:10:13 +020011131 /* The 'any' trigger means the device continues operating more or less
11132 * as in its normal operation mode and wakes up the host on most of the
11133 * normal interrupts (like packet RX, ...)
11134 * It therefore makes little sense to combine with the more constrained
11135 * wakeup trigger modes.
11136 */
11137 if (new_triggers.any && regular) {
11138 err = -EINVAL;
11139 goto error;
11140 }
11141
Johannes Bergae33bd82012-07-12 16:25:02 +020011142 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11143 if (!ntrig) {
11144 err = -ENOMEM;
11145 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011146 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011147 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011148 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011149
Johannes Bergae33bd82012-07-12 16:25:02 +020011150 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011151 if (rdev->ops->set_wakeup &&
11152 prev_enabled != !!rdev->wiphy.wowlan_config)
11153 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011154
Johannes Bergff1b6e62011-05-04 15:37:28 +020011155 return 0;
11156 error:
11157 for (i = 0; i < new_triggers.n_patterns; i++)
11158 kfree(new_triggers.patterns[i].mask);
11159 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011160 if (new_triggers.tcp && new_triggers.tcp->sock)
11161 sock_release(new_triggers.tcp->sock);
11162 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011163 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011164 return err;
11165}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011166#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011167
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011168static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11169 struct cfg80211_registered_device *rdev)
11170{
11171 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11172 int i, j, pat_len;
11173 struct cfg80211_coalesce_rules *rule;
11174
11175 if (!rdev->coalesce->n_rules)
11176 return 0;
11177
11178 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
11179 if (!nl_rules)
11180 return -ENOBUFS;
11181
11182 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11183 nl_rule = nla_nest_start(msg, i + 1);
11184 if (!nl_rule)
11185 return -ENOBUFS;
11186
11187 rule = &rdev->coalesce->rules[i];
11188 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11189 rule->delay))
11190 return -ENOBUFS;
11191
11192 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11193 rule->condition))
11194 return -ENOBUFS;
11195
11196 nl_pats = nla_nest_start(msg,
11197 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11198 if (!nl_pats)
11199 return -ENOBUFS;
11200
11201 for (j = 0; j < rule->n_patterns; j++) {
11202 nl_pat = nla_nest_start(msg, j + 1);
11203 if (!nl_pat)
11204 return -ENOBUFS;
11205 pat_len = rule->patterns[j].pattern_len;
11206 if (nla_put(msg, NL80211_PKTPAT_MASK,
11207 DIV_ROUND_UP(pat_len, 8),
11208 rule->patterns[j].mask) ||
11209 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11210 rule->patterns[j].pattern) ||
11211 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11212 rule->patterns[j].pkt_offset))
11213 return -ENOBUFS;
11214 nla_nest_end(msg, nl_pat);
11215 }
11216 nla_nest_end(msg, nl_pats);
11217 nla_nest_end(msg, nl_rule);
11218 }
11219 nla_nest_end(msg, nl_rules);
11220
11221 return 0;
11222}
11223
11224static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11225{
11226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11227 struct sk_buff *msg;
11228 void *hdr;
11229
11230 if (!rdev->wiphy.coalesce)
11231 return -EOPNOTSUPP;
11232
11233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11234 if (!msg)
11235 return -ENOMEM;
11236
11237 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11238 NL80211_CMD_GET_COALESCE);
11239 if (!hdr)
11240 goto nla_put_failure;
11241
11242 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11243 goto nla_put_failure;
11244
11245 genlmsg_end(msg, hdr);
11246 return genlmsg_reply(msg, info);
11247
11248nla_put_failure:
11249 nlmsg_free(msg);
11250 return -ENOBUFS;
11251}
11252
11253void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11254{
11255 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11256 int i, j;
11257 struct cfg80211_coalesce_rules *rule;
11258
11259 if (!coalesce)
11260 return;
11261
11262 for (i = 0; i < coalesce->n_rules; i++) {
11263 rule = &coalesce->rules[i];
11264 for (j = 0; j < rule->n_patterns; j++)
11265 kfree(rule->patterns[j].mask);
11266 kfree(rule->patterns);
11267 }
11268 kfree(coalesce->rules);
11269 kfree(coalesce);
11270 rdev->coalesce = NULL;
11271}
11272
11273static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11274 struct nlattr *rule,
11275 struct cfg80211_coalesce_rules *new_rule)
11276{
11277 int err, i;
11278 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11279 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11280 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11281 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11282
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011283 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020011284 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011285 if (err)
11286 return err;
11287
11288 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11289 new_rule->delay =
11290 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11291 if (new_rule->delay > coalesce->max_delay)
11292 return -EINVAL;
11293
11294 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11295 new_rule->condition =
11296 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
11297 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
11298 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
11299 return -EINVAL;
11300
11301 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11302 return -EINVAL;
11303
11304 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11305 rem)
11306 n_patterns++;
11307 if (n_patterns > coalesce->n_patterns)
11308 return -EINVAL;
11309
11310 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11311 GFP_KERNEL);
11312 if (!new_rule->patterns)
11313 return -ENOMEM;
11314
11315 new_rule->n_patterns = n_patterns;
11316 i = 0;
11317
11318 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11319 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011320 u8 *mask_pat;
11321
Peng Xuad670232017-10-03 23:21:51 +030011322 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11323 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011324 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11325 !pat_tb[NL80211_PKTPAT_PATTERN])
11326 return -EINVAL;
11327 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11328 mask_len = DIV_ROUND_UP(pat_len, 8);
11329 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11330 return -EINVAL;
11331 if (pat_len > coalesce->pattern_max_len ||
11332 pat_len < coalesce->pattern_min_len)
11333 return -EINVAL;
11334
11335 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11336 pkt_offset = 0;
11337 else
11338 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11339 if (pkt_offset > coalesce->max_pkt_offset)
11340 return -EINVAL;
11341 new_rule->patterns[i].pkt_offset = pkt_offset;
11342
Johannes Berg922bd802014-05-19 17:59:50 +020011343 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11344 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011345 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011346
11347 new_rule->patterns[i].mask = mask_pat;
11348 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11349 mask_len);
11350
11351 mask_pat += mask_len;
11352 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011353 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011354 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11355 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011356 i++;
11357 }
11358
11359 return 0;
11360}
11361
11362static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11363{
11364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11365 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11366 struct cfg80211_coalesce new_coalesce = {};
11367 struct cfg80211_coalesce *n_coalesce;
11368 int err, rem_rule, n_rules = 0, i, j;
11369 struct nlattr *rule;
11370 struct cfg80211_coalesce_rules *tmp_rule;
11371
11372 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11373 return -EOPNOTSUPP;
11374
11375 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11376 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030011377 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011378 return 0;
11379 }
11380
11381 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11382 rem_rule)
11383 n_rules++;
11384 if (n_rules > coalesce->n_rules)
11385 return -EINVAL;
11386
11387 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11388 GFP_KERNEL);
11389 if (!new_coalesce.rules)
11390 return -ENOMEM;
11391
11392 new_coalesce.n_rules = n_rules;
11393 i = 0;
11394
11395 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11396 rem_rule) {
11397 err = nl80211_parse_coalesce_rule(rdev, rule,
11398 &new_coalesce.rules[i]);
11399 if (err)
11400 goto error;
11401
11402 i++;
11403 }
11404
Ilan Peera1056b1b2015-10-22 22:27:46 +030011405 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011406 if (err)
11407 goto error;
11408
11409 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11410 if (!n_coalesce) {
11411 err = -ENOMEM;
11412 goto error;
11413 }
11414 cfg80211_rdev_free_coalesce(rdev);
11415 rdev->coalesce = n_coalesce;
11416
11417 return 0;
11418error:
11419 for (i = 0; i < new_coalesce.n_rules; i++) {
11420 tmp_rule = &new_coalesce.rules[i];
11421 for (j = 0; j < tmp_rule->n_patterns; j++)
11422 kfree(tmp_rule->patterns[j].mask);
11423 kfree(tmp_rule->patterns);
11424 }
11425 kfree(new_coalesce.rules);
11426
11427 return err;
11428}
11429
Johannes Berge5497d72011-07-05 16:35:40 +020011430static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11431{
11432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11433 struct net_device *dev = info->user_ptr[1];
11434 struct wireless_dev *wdev = dev->ieee80211_ptr;
11435 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11436 struct cfg80211_gtk_rekey_data rekey_data;
11437 int err;
11438
11439 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11440 return -EINVAL;
11441
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011442 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
11443 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020011444 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011445 if (err)
11446 return err;
11447
Vladis Dronove785fa02017-09-13 00:21:21 +020011448 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11449 !tb[NL80211_REKEY_DATA_KCK])
11450 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011451 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11452 return -ERANGE;
11453 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11454 return -ERANGE;
11455 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11456 return -ERANGE;
11457
Johannes Berg78f686c2014-09-10 22:28:06 +030011458 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11459 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11460 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011461
11462 wdev_lock(wdev);
11463 if (!wdev->current_bss) {
11464 err = -ENOTCONN;
11465 goto out;
11466 }
11467
11468 if (!rdev->ops->set_rekey_data) {
11469 err = -EOPNOTSUPP;
11470 goto out;
11471 }
11472
Hila Gonene35e4d22012-06-27 17:19:42 +030011473 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011474 out:
11475 wdev_unlock(wdev);
11476 return err;
11477}
11478
Johannes Berg28946da2011-11-04 11:18:12 +010011479static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11480 struct genl_info *info)
11481{
11482 struct net_device *dev = info->user_ptr[1];
11483 struct wireless_dev *wdev = dev->ieee80211_ptr;
11484
11485 if (wdev->iftype != NL80211_IFTYPE_AP &&
11486 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11487 return -EINVAL;
11488
Eric W. Biederman15e47302012-09-07 20:12:54 +000011489 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011490 return -EBUSY;
11491
Eric W. Biederman15e47302012-09-07 20:12:54 +000011492 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011493 return 0;
11494}
11495
Johannes Berg7f6cf312011-11-04 11:18:15 +010011496static int nl80211_probe_client(struct sk_buff *skb,
11497 struct genl_info *info)
11498{
11499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11500 struct net_device *dev = info->user_ptr[1];
11501 struct wireless_dev *wdev = dev->ieee80211_ptr;
11502 struct sk_buff *msg;
11503 void *hdr;
11504 const u8 *addr;
11505 u64 cookie;
11506 int err;
11507
11508 if (wdev->iftype != NL80211_IFTYPE_AP &&
11509 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11510 return -EOPNOTSUPP;
11511
11512 if (!info->attrs[NL80211_ATTR_MAC])
11513 return -EINVAL;
11514
11515 if (!rdev->ops->probe_client)
11516 return -EOPNOTSUPP;
11517
11518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11519 if (!msg)
11520 return -ENOMEM;
11521
Eric W. Biederman15e47302012-09-07 20:12:54 +000011522 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011523 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011524 if (!hdr) {
11525 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011526 goto free_msg;
11527 }
11528
11529 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11530
Hila Gonene35e4d22012-06-27 17:19:42 +030011531 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011532 if (err)
11533 goto free_msg;
11534
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011535 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11536 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011537 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011538
11539 genlmsg_end(msg, hdr);
11540
11541 return genlmsg_reply(msg, info);
11542
11543 nla_put_failure:
11544 err = -ENOBUFS;
11545 free_msg:
11546 nlmsg_free(msg);
11547 return err;
11548}
11549
Johannes Berg5e760232011-11-04 11:18:17 +010011550static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11551{
11552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011553 struct cfg80211_beacon_registration *reg, *nreg;
11554 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011555
11556 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11557 return -EOPNOTSUPP;
11558
Ben Greear37c73b52012-10-26 14:49:25 -070011559 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11560 if (!nreg)
11561 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011562
Ben Greear37c73b52012-10-26 14:49:25 -070011563 /* First, check if already registered. */
11564 spin_lock_bh(&rdev->beacon_registrations_lock);
11565 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11566 if (reg->nlportid == info->snd_portid) {
11567 rv = -EALREADY;
11568 goto out_err;
11569 }
11570 }
11571 /* Add it to the list */
11572 nreg->nlportid = info->snd_portid;
11573 list_add(&nreg->list, &rdev->beacon_registrations);
11574
11575 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011576
11577 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011578out_err:
11579 spin_unlock_bh(&rdev->beacon_registrations_lock);
11580 kfree(nreg);
11581 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011582}
11583
Johannes Berg98104fde2012-06-16 00:19:54 +020011584static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11585{
11586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11587 struct wireless_dev *wdev = info->user_ptr[1];
11588 int err;
11589
11590 if (!rdev->ops->start_p2p_device)
11591 return -EOPNOTSUPP;
11592
11593 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11594 return -EOPNOTSUPP;
11595
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011596 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011597 return 0;
11598
Luciano Coelhob6a55012014-02-27 11:07:21 +020011599 if (rfkill_blocked(rdev->rfkill))
11600 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011601
Johannes Bergeeb126e2012-10-23 15:16:50 +020011602 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011603 if (err)
11604 return err;
11605
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011606 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011607 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011608
11609 return 0;
11610}
11611
11612static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11613{
11614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11615 struct wireless_dev *wdev = info->user_ptr[1];
11616
11617 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11618 return -EOPNOTSUPP;
11619
11620 if (!rdev->ops->stop_p2p_device)
11621 return -EOPNOTSUPP;
11622
Johannes Bergf9f47522013-03-19 15:04:07 +010011623 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011624
11625 return 0;
11626}
11627
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011628static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11629{
11630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11631 struct wireless_dev *wdev = info->user_ptr[1];
11632 struct cfg80211_nan_conf conf = {};
11633 int err;
11634
11635 if (wdev->iftype != NL80211_IFTYPE_NAN)
11636 return -EOPNOTSUPP;
11637
Johannes Bergeeb04a92016-11-21 13:55:48 +010011638 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011639 return -EEXIST;
11640
11641 if (rfkill_blocked(rdev->rfkill))
11642 return -ERFKILL;
11643
11644 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11645 return -EINVAL;
11646
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011647 conf.master_pref =
11648 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11649 if (!conf.master_pref)
11650 return -EINVAL;
11651
Luca Coelho85859892017-02-08 15:00:34 +020011652 if (info->attrs[NL80211_ATTR_BANDS]) {
11653 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11654
11655 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11656 return -EOPNOTSUPP;
11657
11658 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11659 return -EINVAL;
11660
11661 conf.bands = bands;
11662 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011663
11664 err = rdev_start_nan(rdev, wdev, &conf);
11665 if (err)
11666 return err;
11667
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011668 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011669 rdev->opencount++;
11670
11671 return 0;
11672}
11673
11674static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11675{
11676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11677 struct wireless_dev *wdev = info->user_ptr[1];
11678
11679 if (wdev->iftype != NL80211_IFTYPE_NAN)
11680 return -EOPNOTSUPP;
11681
11682 cfg80211_stop_nan(rdev, wdev);
11683
11684 return 0;
11685}
11686
Ayala Bekera442b762016-09-20 17:31:15 +030011687static int validate_nan_filter(struct nlattr *filter_attr)
11688{
11689 struct nlattr *attr;
11690 int len = 0, n_entries = 0, rem;
11691
11692 nla_for_each_nested(attr, filter_attr, rem) {
11693 len += nla_len(attr);
11694 n_entries++;
11695 }
11696
11697 if (len >= U8_MAX)
11698 return -EINVAL;
11699
11700 return n_entries;
11701}
11702
11703static int handle_nan_filter(struct nlattr *attr_filter,
11704 struct cfg80211_nan_func *func,
11705 bool tx)
11706{
11707 struct nlattr *attr;
11708 int n_entries, rem, i;
11709 struct cfg80211_nan_func_filter *filter;
11710
11711 n_entries = validate_nan_filter(attr_filter);
11712 if (n_entries < 0)
11713 return n_entries;
11714
11715 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11716
11717 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11718 if (!filter)
11719 return -ENOMEM;
11720
11721 i = 0;
11722 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011723 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011724 filter[i].len = nla_len(attr);
11725 i++;
11726 }
11727 if (tx) {
11728 func->num_tx_filters = n_entries;
11729 func->tx_filters = filter;
11730 } else {
11731 func->num_rx_filters = n_entries;
11732 func->rx_filters = filter;
11733 }
11734
11735 return 0;
11736}
11737
11738static int nl80211_nan_add_func(struct sk_buff *skb,
11739 struct genl_info *info)
11740{
11741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11742 struct wireless_dev *wdev = info->user_ptr[1];
11743 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11744 struct cfg80211_nan_func *func;
11745 struct sk_buff *msg = NULL;
11746 void *hdr = NULL;
11747 int err = 0;
11748
11749 if (wdev->iftype != NL80211_IFTYPE_NAN)
11750 return -EOPNOTSUPP;
11751
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011752 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011753 return -ENOTCONN;
11754
11755 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11756 return -EINVAL;
11757
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011758 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11759 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011760 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011761 if (err)
11762 return err;
11763
11764 func = kzalloc(sizeof(*func), GFP_KERNEL);
11765 if (!func)
11766 return -ENOMEM;
11767
11768 func->cookie = wdev->wiphy->cookie_counter++;
11769
11770 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11771 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11772 err = -EINVAL;
11773 goto out;
11774 }
11775
11776
11777 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11778
11779 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11780 err = -EINVAL;
11781 goto out;
11782 }
11783
11784 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11785 sizeof(func->service_id));
11786
11787 func->close_range =
11788 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11789
11790 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11791 func->serv_spec_info_len =
11792 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11793 func->serv_spec_info =
11794 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11795 func->serv_spec_info_len,
11796 GFP_KERNEL);
11797 if (!func->serv_spec_info) {
11798 err = -ENOMEM;
11799 goto out;
11800 }
11801 }
11802
11803 if (tb[NL80211_NAN_FUNC_TTL])
11804 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11805
11806 switch (func->type) {
11807 case NL80211_NAN_FUNC_PUBLISH:
11808 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11809 err = -EINVAL;
11810 goto out;
11811 }
11812
11813 func->publish_type =
11814 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11815 func->publish_bcast =
11816 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11817
11818 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11819 func->publish_bcast) {
11820 err = -EINVAL;
11821 goto out;
11822 }
11823 break;
11824 case NL80211_NAN_FUNC_SUBSCRIBE:
11825 func->subscribe_active =
11826 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11827 break;
11828 case NL80211_NAN_FUNC_FOLLOW_UP:
11829 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080011830 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11831 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030011832 err = -EINVAL;
11833 goto out;
11834 }
11835
11836 func->followup_id =
11837 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11838 func->followup_reqid =
11839 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11840 memcpy(func->followup_dest.addr,
11841 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11842 sizeof(func->followup_dest.addr));
11843 if (func->ttl) {
11844 err = -EINVAL;
11845 goto out;
11846 }
11847 break;
11848 default:
11849 err = -EINVAL;
11850 goto out;
11851 }
11852
11853 if (tb[NL80211_NAN_FUNC_SRF]) {
11854 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11855
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011856 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11857 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011858 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011859 if (err)
11860 goto out;
11861
11862 func->srf_include =
11863 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11864
11865 if (srf_tb[NL80211_NAN_SRF_BF]) {
11866 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11867 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11868 err = -EINVAL;
11869 goto out;
11870 }
11871
11872 func->srf_bf_len =
11873 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11874 func->srf_bf =
11875 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11876 func->srf_bf_len, GFP_KERNEL);
11877 if (!func->srf_bf) {
11878 err = -ENOMEM;
11879 goto out;
11880 }
11881
11882 func->srf_bf_idx =
11883 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11884 } else {
11885 struct nlattr *attr, *mac_attr =
11886 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11887 int n_entries, rem, i = 0;
11888
11889 if (!mac_attr) {
11890 err = -EINVAL;
11891 goto out;
11892 }
11893
11894 n_entries = validate_acl_mac_addrs(mac_attr);
11895 if (n_entries <= 0) {
11896 err = -EINVAL;
11897 goto out;
11898 }
11899
11900 func->srf_num_macs = n_entries;
11901 func->srf_macs =
11902 kzalloc(sizeof(*func->srf_macs) * n_entries,
11903 GFP_KERNEL);
11904 if (!func->srf_macs) {
11905 err = -ENOMEM;
11906 goto out;
11907 }
11908
11909 nla_for_each_nested(attr, mac_attr, rem)
11910 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11911 sizeof(*func->srf_macs));
11912 }
11913 }
11914
11915 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11916 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11917 func, true);
11918 if (err)
11919 goto out;
11920 }
11921
11922 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11923 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11924 func, false);
11925 if (err)
11926 goto out;
11927 }
11928
11929 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11930 if (!msg) {
11931 err = -ENOMEM;
11932 goto out;
11933 }
11934
11935 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11936 NL80211_CMD_ADD_NAN_FUNCTION);
11937 /* This can't really happen - we just allocated 4KB */
11938 if (WARN_ON(!hdr)) {
11939 err = -ENOMEM;
11940 goto out;
11941 }
11942
11943 err = rdev_add_nan_func(rdev, wdev, func);
11944out:
11945 if (err < 0) {
11946 cfg80211_free_nan_func(func);
11947 nlmsg_free(msg);
11948 return err;
11949 }
11950
11951 /* propagate the instance id and cookie to userspace */
11952 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11953 NL80211_ATTR_PAD))
11954 goto nla_put_failure;
11955
11956 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11957 if (!func_attr)
11958 goto nla_put_failure;
11959
11960 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11961 func->instance_id))
11962 goto nla_put_failure;
11963
11964 nla_nest_end(msg, func_attr);
11965
11966 genlmsg_end(msg, hdr);
11967 return genlmsg_reply(msg, info);
11968
11969nla_put_failure:
11970 nlmsg_free(msg);
11971 return -ENOBUFS;
11972}
11973
11974static int nl80211_nan_del_func(struct sk_buff *skb,
11975 struct genl_info *info)
11976{
11977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11978 struct wireless_dev *wdev = info->user_ptr[1];
11979 u64 cookie;
11980
11981 if (wdev->iftype != NL80211_IFTYPE_NAN)
11982 return -EOPNOTSUPP;
11983
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011984 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011985 return -ENOTCONN;
11986
11987 if (!info->attrs[NL80211_ATTR_COOKIE])
11988 return -EINVAL;
11989
Ayala Bekera442b762016-09-20 17:31:15 +030011990 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11991
11992 rdev_del_nan_func(rdev, wdev, cookie);
11993
11994 return 0;
11995}
11996
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011997static int nl80211_nan_change_config(struct sk_buff *skb,
11998 struct genl_info *info)
11999{
12000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12001 struct wireless_dev *wdev = info->user_ptr[1];
12002 struct cfg80211_nan_conf conf = {};
12003 u32 changed = 0;
12004
12005 if (wdev->iftype != NL80211_IFTYPE_NAN)
12006 return -EOPNOTSUPP;
12007
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012008 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012009 return -ENOTCONN;
12010
12011 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12012 conf.master_pref =
12013 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12014 if (conf.master_pref <= 1 || conf.master_pref == 255)
12015 return -EINVAL;
12016
12017 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12018 }
12019
Luca Coelho85859892017-02-08 15:00:34 +020012020 if (info->attrs[NL80211_ATTR_BANDS]) {
12021 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12022
12023 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12024 return -EOPNOTSUPP;
12025
12026 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12027 return -EINVAL;
12028
12029 conf.bands = bands;
12030 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012031 }
12032
12033 if (!changed)
12034 return -EINVAL;
12035
12036 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12037}
12038
Ayala Beker50bcd312016-09-20 17:31:17 +030012039void cfg80211_nan_match(struct wireless_dev *wdev,
12040 struct cfg80211_nan_match_params *match, gfp_t gfp)
12041{
12042 struct wiphy *wiphy = wdev->wiphy;
12043 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12044 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12045 struct sk_buff *msg;
12046 void *hdr;
12047
12048 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12049 return;
12050
12051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12052 if (!msg)
12053 return;
12054
12055 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12056 if (!hdr) {
12057 nlmsg_free(msg);
12058 return;
12059 }
12060
12061 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12062 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12063 wdev->netdev->ifindex)) ||
12064 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12065 NL80211_ATTR_PAD))
12066 goto nla_put_failure;
12067
12068 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12069 NL80211_ATTR_PAD) ||
12070 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12071 goto nla_put_failure;
12072
12073 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
12074 if (!match_attr)
12075 goto nla_put_failure;
12076
12077 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
12078 if (!local_func_attr)
12079 goto nla_put_failure;
12080
12081 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12082 goto nla_put_failure;
12083
12084 nla_nest_end(msg, local_func_attr);
12085
12086 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
12087 if (!peer_func_attr)
12088 goto nla_put_failure;
12089
12090 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12091 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12092 goto nla_put_failure;
12093
12094 if (match->info && match->info_len &&
12095 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12096 match->info))
12097 goto nla_put_failure;
12098
12099 nla_nest_end(msg, peer_func_attr);
12100 nla_nest_end(msg, match_attr);
12101 genlmsg_end(msg, hdr);
12102
12103 if (!wdev->owner_nlportid)
12104 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12105 msg, 0, NL80211_MCGRP_NAN, gfp);
12106 else
12107 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12108 wdev->owner_nlportid);
12109
12110 return;
12111
12112nla_put_failure:
12113 nlmsg_free(msg);
12114}
12115EXPORT_SYMBOL(cfg80211_nan_match);
12116
Ayala Beker368e5a72016-09-20 17:31:18 +030012117void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12118 u8 inst_id,
12119 enum nl80211_nan_func_term_reason reason,
12120 u64 cookie, gfp_t gfp)
12121{
12122 struct wiphy *wiphy = wdev->wiphy;
12123 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12124 struct sk_buff *msg;
12125 struct nlattr *func_attr;
12126 void *hdr;
12127
12128 if (WARN_ON(!inst_id))
12129 return;
12130
12131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12132 if (!msg)
12133 return;
12134
12135 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12136 if (!hdr) {
12137 nlmsg_free(msg);
12138 return;
12139 }
12140
12141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12142 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12143 wdev->netdev->ifindex)) ||
12144 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12145 NL80211_ATTR_PAD))
12146 goto nla_put_failure;
12147
12148 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12149 NL80211_ATTR_PAD))
12150 goto nla_put_failure;
12151
12152 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
12153 if (!func_attr)
12154 goto nla_put_failure;
12155
12156 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12157 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12158 goto nla_put_failure;
12159
12160 nla_nest_end(msg, func_attr);
12161 genlmsg_end(msg, hdr);
12162
12163 if (!wdev->owner_nlportid)
12164 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12165 msg, 0, NL80211_MCGRP_NAN, gfp);
12166 else
12167 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12168 wdev->owner_nlportid);
12169
12170 return;
12171
12172nla_put_failure:
12173 nlmsg_free(msg);
12174}
12175EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12176
Johannes Berg3713b4e2013-02-14 16:19:38 +010012177static int nl80211_get_protocol_features(struct sk_buff *skb,
12178 struct genl_info *info)
12179{
12180 void *hdr;
12181 struct sk_buff *msg;
12182
12183 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12184 if (!msg)
12185 return -ENOMEM;
12186
12187 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12188 NL80211_CMD_GET_PROTOCOL_FEATURES);
12189 if (!hdr)
12190 goto nla_put_failure;
12191
12192 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12193 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12194 goto nla_put_failure;
12195
12196 genlmsg_end(msg, hdr);
12197 return genlmsg_reply(msg, info);
12198
12199 nla_put_failure:
12200 kfree_skb(msg);
12201 return -ENOBUFS;
12202}
12203
Jouni Malinen355199e2013-02-27 17:14:27 +020012204static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12205{
12206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12207 struct cfg80211_update_ft_ies_params ft_params;
12208 struct net_device *dev = info->user_ptr[1];
12209
12210 if (!rdev->ops->update_ft_ies)
12211 return -EOPNOTSUPP;
12212
12213 if (!info->attrs[NL80211_ATTR_MDID] ||
12214 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
12215 return -EINVAL;
12216
12217 memset(&ft_params, 0, sizeof(ft_params));
12218 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12219 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12220 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12221
12222 return rdev_update_ft_ies(rdev, dev, &ft_params);
12223}
12224
Arend van Spriel5de17982013-04-18 15:49:00 +020012225static int nl80211_crit_protocol_start(struct sk_buff *skb,
12226 struct genl_info *info)
12227{
12228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12229 struct wireless_dev *wdev = info->user_ptr[1];
12230 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12231 u16 duration;
12232 int ret;
12233
12234 if (!rdev->ops->crit_proto_start)
12235 return -EOPNOTSUPP;
12236
12237 if (WARN_ON(!rdev->ops->crit_proto_stop))
12238 return -EINVAL;
12239
12240 if (rdev->crit_proto_nlportid)
12241 return -EBUSY;
12242
12243 /* determine protocol if provided */
12244 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12245 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12246
12247 if (proto >= NUM_NL80211_CRIT_PROTO)
12248 return -EINVAL;
12249
12250 /* timeout must be provided */
12251 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12252 return -EINVAL;
12253
12254 duration =
12255 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12256
12257 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12258 return -ERANGE;
12259
12260 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12261 if (!ret)
12262 rdev->crit_proto_nlportid = info->snd_portid;
12263
12264 return ret;
12265}
12266
12267static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12268 struct genl_info *info)
12269{
12270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12271 struct wireless_dev *wdev = info->user_ptr[1];
12272
12273 if (!rdev->ops->crit_proto_stop)
12274 return -EOPNOTSUPP;
12275
12276 if (rdev->crit_proto_nlportid) {
12277 rdev->crit_proto_nlportid = 0;
12278 rdev_crit_proto_stop(rdev, wdev);
12279 }
12280 return 0;
12281}
12282
Johannes Bergad7e7182013-11-13 13:37:47 +010012283static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12284{
12285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12286 struct wireless_dev *wdev =
12287 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12288 int i, err;
12289 u32 vid, subcmd;
12290
12291 if (!rdev->wiphy.vendor_commands)
12292 return -EOPNOTSUPP;
12293
12294 if (IS_ERR(wdev)) {
12295 err = PTR_ERR(wdev);
12296 if (err != -EINVAL)
12297 return err;
12298 wdev = NULL;
12299 } else if (wdev->wiphy != &rdev->wiphy) {
12300 return -EINVAL;
12301 }
12302
12303 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12304 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12305 return -EINVAL;
12306
12307 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12308 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12309 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12310 const struct wiphy_vendor_command *vcmd;
12311 void *data = NULL;
12312 int len = 0;
12313
12314 vcmd = &rdev->wiphy.vendor_commands[i];
12315
12316 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12317 continue;
12318
12319 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12320 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12321 if (!wdev)
12322 return -EINVAL;
12323 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12324 !wdev->netdev)
12325 return -EINVAL;
12326
12327 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012328 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012329 return -ENETDOWN;
12330 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012331
12332 if (!vcmd->doit)
12333 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012334 } else {
12335 wdev = NULL;
12336 }
12337
12338 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12339 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12340 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12341 }
12342
12343 rdev->cur_cmd_info = info;
12344 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
12345 data, len);
12346 rdev->cur_cmd_info = NULL;
12347 return err;
12348 }
12349
12350 return -EOPNOTSUPP;
12351}
12352
Johannes Berg7bdbe402015-08-15 22:39:49 +030012353static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12354 struct netlink_callback *cb,
12355 struct cfg80211_registered_device **rdev,
12356 struct wireless_dev **wdev)
12357{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012358 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012359 u32 vid, subcmd;
12360 unsigned int i;
12361 int vcmd_idx = -1;
12362 int err;
12363 void *data = NULL;
12364 unsigned int data_len = 0;
12365
Johannes Berg7bdbe402015-08-15 22:39:49 +030012366 if (cb->args[0]) {
12367 /* subtract the 1 again here */
12368 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12369 struct wireless_dev *tmp;
12370
Johannes Bergea90e0d2017-03-15 14:26:04 +010012371 if (!wiphy)
12372 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012373 *rdev = wiphy_to_rdev(wiphy);
12374 *wdev = NULL;
12375
12376 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012377 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012378 if (tmp->identifier == cb->args[1] - 1) {
12379 *wdev = tmp;
12380 break;
12381 }
12382 }
12383 }
12384
12385 /* keep rtnl locked in successful case */
12386 return 0;
12387 }
12388
Johannes Bergfceb6432017-04-12 14:34:07 +020012389 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
12390 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012391 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012392 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012393
Johannes Bergc90c39d2016-10-24 14:40:01 +020012394 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012395 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12396 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012397
Johannes Bergc90c39d2016-10-24 14:40:01 +020012398 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012399 if (IS_ERR(*wdev))
12400 *wdev = NULL;
12401
Johannes Bergc90c39d2016-10-24 14:40:01 +020012402 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012403 if (IS_ERR(*rdev))
12404 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012405
Johannes Bergc90c39d2016-10-24 14:40:01 +020012406 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12407 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012408
12409 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12410 const struct wiphy_vendor_command *vcmd;
12411
12412 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12413
12414 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12415 continue;
12416
Johannes Bergea90e0d2017-03-15 14:26:04 +010012417 if (!vcmd->dumpit)
12418 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012419
12420 vcmd_idx = i;
12421 break;
12422 }
12423
Johannes Bergea90e0d2017-03-15 14:26:04 +010012424 if (vcmd_idx < 0)
12425 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012426
Johannes Bergc90c39d2016-10-24 14:40:01 +020012427 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12428 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12429 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012430 }
12431
12432 /* 0 is the first index - add 1 to parse only once */
12433 cb->args[0] = (*rdev)->wiphy_idx + 1;
12434 /* add 1 to know if it was NULL */
12435 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12436 cb->args[2] = vcmd_idx;
12437 cb->args[3] = (unsigned long)data;
12438 cb->args[4] = data_len;
12439
12440 /* keep rtnl locked in successful case */
12441 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012442}
12443
12444static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12445 struct netlink_callback *cb)
12446{
12447 struct cfg80211_registered_device *rdev;
12448 struct wireless_dev *wdev;
12449 unsigned int vcmd_idx;
12450 const struct wiphy_vendor_command *vcmd;
12451 void *data;
12452 int data_len;
12453 int err;
12454 struct nlattr *vendor_data;
12455
Johannes Bergea90e0d2017-03-15 14:26:04 +010012456 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012457 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12458 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012459 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012460
12461 vcmd_idx = cb->args[2];
12462 data = (void *)cb->args[3];
12463 data_len = cb->args[4];
12464 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12465
12466 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12467 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012468 if (!wdev) {
12469 err = -EINVAL;
12470 goto out;
12471 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012472 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012473 !wdev->netdev) {
12474 err = -EINVAL;
12475 goto out;
12476 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012477
12478 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012479 if (!wdev_running(wdev)) {
12480 err = -ENETDOWN;
12481 goto out;
12482 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012483 }
12484 }
12485
12486 while (1) {
12487 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12488 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12489 NL80211_CMD_VENDOR);
12490 if (!hdr)
12491 break;
12492
12493 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012494 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12495 wdev_id(wdev),
12496 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012497 genlmsg_cancel(skb, hdr);
12498 break;
12499 }
12500
12501 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12502 if (!vendor_data) {
12503 genlmsg_cancel(skb, hdr);
12504 break;
12505 }
12506
12507 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12508 (unsigned long *)&cb->args[5]);
12509 nla_nest_end(skb, vendor_data);
12510
12511 if (err == -ENOBUFS || err == -ENOENT) {
12512 genlmsg_cancel(skb, hdr);
12513 break;
12514 } else if (err) {
12515 genlmsg_cancel(skb, hdr);
12516 goto out;
12517 }
12518
12519 genlmsg_end(skb, hdr);
12520 }
12521
12522 err = skb->len;
12523 out:
12524 rtnl_unlock();
12525 return err;
12526}
12527
Johannes Bergad7e7182013-11-13 13:37:47 +010012528struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12529 enum nl80211_commands cmd,
12530 enum nl80211_attrs attr,
12531 int approxlen)
12532{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012533 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012534
12535 if (WARN_ON(!rdev->cur_cmd_info))
12536 return NULL;
12537
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012538 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012539 rdev->cur_cmd_info->snd_portid,
12540 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012541 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012542}
12543EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12544
12545int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12546{
12547 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12548 void *hdr = ((void **)skb->cb)[1];
12549 struct nlattr *data = ((void **)skb->cb)[2];
12550
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012551 /* clear CB data for netlink core to own from now on */
12552 memset(skb->cb, 0, sizeof(skb->cb));
12553
Johannes Bergad7e7182013-11-13 13:37:47 +010012554 if (WARN_ON(!rdev->cur_cmd_info)) {
12555 kfree_skb(skb);
12556 return -EINVAL;
12557 }
12558
12559 nla_nest_end(skb, data);
12560 genlmsg_end(skb, hdr);
12561 return genlmsg_reply(skb, rdev->cur_cmd_info);
12562}
12563EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12564
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012565static int nl80211_set_qos_map(struct sk_buff *skb,
12566 struct genl_info *info)
12567{
12568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12569 struct cfg80211_qos_map *qos_map = NULL;
12570 struct net_device *dev = info->user_ptr[1];
12571 u8 *pos, len, num_des, des_len, des;
12572 int ret;
12573
12574 if (!rdev->ops->set_qos_map)
12575 return -EOPNOTSUPP;
12576
12577 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12578 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12579 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12580
12581 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12582 len > IEEE80211_QOS_MAP_LEN_MAX)
12583 return -EINVAL;
12584
12585 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12586 if (!qos_map)
12587 return -ENOMEM;
12588
12589 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12590 if (num_des) {
12591 des_len = num_des *
12592 sizeof(struct cfg80211_dscp_exception);
12593 memcpy(qos_map->dscp_exception, pos, des_len);
12594 qos_map->num_des = num_des;
12595 for (des = 0; des < num_des; des++) {
12596 if (qos_map->dscp_exception[des].up > 7) {
12597 kfree(qos_map);
12598 return -EINVAL;
12599 }
12600 }
12601 pos += des_len;
12602 }
12603 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12604 }
12605
12606 wdev_lock(dev->ieee80211_ptr);
12607 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12608 if (!ret)
12609 ret = rdev_set_qos_map(rdev, dev, qos_map);
12610 wdev_unlock(dev->ieee80211_ptr);
12611
12612 kfree(qos_map);
12613 return ret;
12614}
12615
Johannes Berg960d01a2014-09-09 22:55:35 +030012616static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12617{
12618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12619 struct net_device *dev = info->user_ptr[1];
12620 struct wireless_dev *wdev = dev->ieee80211_ptr;
12621 const u8 *peer;
12622 u8 tsid, up;
12623 u16 admitted_time = 0;
12624 int err;
12625
Johannes Berg723e73a2014-10-22 09:25:06 +020012626 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012627 return -EOPNOTSUPP;
12628
12629 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12630 !info->attrs[NL80211_ATTR_USER_PRIO])
12631 return -EINVAL;
12632
12633 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12634 if (tsid >= IEEE80211_NUM_TIDS)
12635 return -EINVAL;
12636
12637 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12638 if (up >= IEEE80211_NUM_UPS)
12639 return -EINVAL;
12640
12641 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012642 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012643 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012644 * need more attributes for that (e.g. BA session requirement);
12645 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012646 */
12647 return -EINVAL;
12648 }
12649
12650 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12651
12652 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12653 admitted_time =
12654 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12655 if (!admitted_time)
12656 return -EINVAL;
12657 }
12658
12659 wdev_lock(wdev);
12660 switch (wdev->iftype) {
12661 case NL80211_IFTYPE_STATION:
12662 case NL80211_IFTYPE_P2P_CLIENT:
12663 if (wdev->current_bss)
12664 break;
12665 err = -ENOTCONN;
12666 goto out;
12667 default:
12668 err = -EOPNOTSUPP;
12669 goto out;
12670 }
12671
12672 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12673
12674 out:
12675 wdev_unlock(wdev);
12676 return err;
12677}
12678
12679static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12680{
12681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12682 struct net_device *dev = info->user_ptr[1];
12683 struct wireless_dev *wdev = dev->ieee80211_ptr;
12684 const u8 *peer;
12685 u8 tsid;
12686 int err;
12687
12688 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12689 return -EINVAL;
12690
12691 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12692 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12693
12694 wdev_lock(wdev);
12695 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12696 wdev_unlock(wdev);
12697
12698 return err;
12699}
12700
Arik Nemtsov1057d352014-11-19 12:54:26 +020012701static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12702 struct genl_info *info)
12703{
12704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12705 struct net_device *dev = info->user_ptr[1];
12706 struct wireless_dev *wdev = dev->ieee80211_ptr;
12707 struct cfg80211_chan_def chandef = {};
12708 const u8 *addr;
12709 u8 oper_class;
12710 int err;
12711
12712 if (!rdev->ops->tdls_channel_switch ||
12713 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12714 return -EOPNOTSUPP;
12715
12716 switch (dev->ieee80211_ptr->iftype) {
12717 case NL80211_IFTYPE_STATION:
12718 case NL80211_IFTYPE_P2P_CLIENT:
12719 break;
12720 default:
12721 return -EOPNOTSUPP;
12722 }
12723
12724 if (!info->attrs[NL80211_ATTR_MAC] ||
12725 !info->attrs[NL80211_ATTR_OPER_CLASS])
12726 return -EINVAL;
12727
12728 err = nl80211_parse_chandef(rdev, info, &chandef);
12729 if (err)
12730 return err;
12731
12732 /*
12733 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12734 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12735 * specification is not defined for them.
12736 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012737 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012738 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12739 chandef.width != NL80211_CHAN_WIDTH_20)
12740 return -EINVAL;
12741
12742 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012743 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12744 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012745 return -EINVAL;
12746
12747 /* don't allow switching to DFS channels */
12748 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12749 return -EINVAL;
12750
12751 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12752 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12753
12754 wdev_lock(wdev);
12755 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12756 wdev_unlock(wdev);
12757
12758 return err;
12759}
12760
12761static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12762 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 *addr;
12768
12769 if (!rdev->ops->tdls_channel_switch ||
12770 !rdev->ops->tdls_cancel_channel_switch ||
12771 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12772 return -EOPNOTSUPP;
12773
12774 switch (dev->ieee80211_ptr->iftype) {
12775 case NL80211_IFTYPE_STATION:
12776 case NL80211_IFTYPE_P2P_CLIENT:
12777 break;
12778 default:
12779 return -EOPNOTSUPP;
12780 }
12781
12782 if (!info->attrs[NL80211_ATTR_MAC])
12783 return -EINVAL;
12784
12785 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12786
12787 wdev_lock(wdev);
12788 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12789 wdev_unlock(wdev);
12790
12791 return 0;
12792}
12793
Michael Braunce0ce132016-10-10 19:12:22 +020012794static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12795 struct genl_info *info)
12796{
12797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12798 struct net_device *dev = info->user_ptr[1];
12799 struct wireless_dev *wdev = dev->ieee80211_ptr;
12800 const struct nlattr *nla;
12801 bool enabled;
12802
Michael Braunce0ce132016-10-10 19:12:22 +020012803 if (!rdev->ops->set_multicast_to_unicast)
12804 return -EOPNOTSUPP;
12805
12806 if (wdev->iftype != NL80211_IFTYPE_AP &&
12807 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12808 return -EOPNOTSUPP;
12809
12810 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12811 enabled = nla_get_flag(nla);
12812
12813 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12814}
12815
Avraham Stern3a00df52017-06-09 13:08:43 +010012816static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12817{
12818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12819 struct net_device *dev = info->user_ptr[1];
12820 struct wireless_dev *wdev = dev->ieee80211_ptr;
12821 struct cfg80211_pmk_conf pmk_conf = {};
12822 int ret;
12823
12824 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12825 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12826 return -EOPNOTSUPP;
12827
12828 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12829 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12830 return -EOPNOTSUPP;
12831
12832 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12833 return -EINVAL;
12834
12835 wdev_lock(wdev);
12836 if (!wdev->current_bss) {
12837 ret = -ENOTCONN;
12838 goto out;
12839 }
12840
12841 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12842 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12843 ret = -EINVAL;
12844 goto out;
12845 }
12846
12847 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12848 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12849 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12850 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12851 ret = -EINVAL;
12852 goto out;
12853 }
12854
12855 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12856 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12857
12858 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12859 ret = -EINVAL;
12860 goto out;
12861 }
12862
12863 pmk_conf.pmk_r0_name =
12864 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12865 }
12866
12867 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12868out:
12869 wdev_unlock(wdev);
12870 return ret;
12871}
12872
12873static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12874{
12875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12876 struct net_device *dev = info->user_ptr[1];
12877 struct wireless_dev *wdev = dev->ieee80211_ptr;
12878 const u8 *aa;
12879 int ret;
12880
12881 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12882 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12883 return -EOPNOTSUPP;
12884
12885 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12886 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12887 return -EOPNOTSUPP;
12888
12889 if (!info->attrs[NL80211_ATTR_MAC])
12890 return -EINVAL;
12891
12892 wdev_lock(wdev);
12893 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12894 ret = rdev_del_pmk(rdev, dev, aa);
12895 wdev_unlock(wdev);
12896
12897 return ret;
12898}
12899
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012900static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
12901{
12902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12903 struct net_device *dev = info->user_ptr[1];
12904 struct cfg80211_external_auth_params params;
12905
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020012906 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012907 return -EOPNOTSUPP;
12908
12909 if (!info->attrs[NL80211_ATTR_SSID])
12910 return -EINVAL;
12911
12912 if (!info->attrs[NL80211_ATTR_BSSID])
12913 return -EINVAL;
12914
12915 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
12916 return -EINVAL;
12917
12918 memset(&params, 0, sizeof(params));
12919
12920 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12921 if (params.ssid.ssid_len == 0 ||
12922 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
12923 return -EINVAL;
12924 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
12925 params.ssid.ssid_len);
12926
12927 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
12928 ETH_ALEN);
12929
12930 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12931
12932 return rdev_external_auth(rdev, dev, &params);
12933}
12934
Denis Kenzior2576a9a2018-03-26 12:52:42 -050012935static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
12936{
12937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12938 struct net_device *dev = info->user_ptr[1];
12939 struct wireless_dev *wdev = dev->ieee80211_ptr;
12940 const u8 *buf;
12941 size_t len;
12942 u8 *dest;
12943 u16 proto;
12944 bool noencrypt;
12945 int err;
12946
12947 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12948 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
12949 return -EOPNOTSUPP;
12950
12951 if (!rdev->ops->tx_control_port)
12952 return -EOPNOTSUPP;
12953
12954 if (!info->attrs[NL80211_ATTR_FRAME] ||
12955 !info->attrs[NL80211_ATTR_MAC] ||
12956 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
12957 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
12958 return -EINVAL;
12959 }
12960
12961 wdev_lock(wdev);
12962
12963 switch (wdev->iftype) {
12964 case NL80211_IFTYPE_AP:
12965 case NL80211_IFTYPE_P2P_GO:
12966 case NL80211_IFTYPE_MESH_POINT:
12967 break;
12968 case NL80211_IFTYPE_ADHOC:
12969 case NL80211_IFTYPE_STATION:
12970 case NL80211_IFTYPE_P2P_CLIENT:
12971 if (wdev->current_bss)
12972 break;
12973 err = -ENOTCONN;
12974 goto out;
12975 default:
12976 err = -EOPNOTSUPP;
12977 goto out;
12978 }
12979
12980 wdev_unlock(wdev);
12981
12982 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
12983 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
12984 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
12985 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
12986 noencrypt =
12987 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
12988
12989 return rdev_tx_control_port(rdev, dev, buf, len,
12990 dest, cpu_to_be16(proto), noencrypt);
12991
12992 out:
12993 wdev_unlock(wdev);
12994 return err;
12995}
12996
Johannes Berg4c476992010-10-04 21:36:35 +020012997#define NL80211_FLAG_NEED_WIPHY 0x01
12998#define NL80211_FLAG_NEED_NETDEV 0x02
12999#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020013000#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13001#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13002 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020013003#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020013004/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020013005#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13006 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030013007#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020013008
Johannes Bergf84f7712013-11-14 17:14:45 +010013009static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013010 struct genl_info *info)
13011{
13012 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020013013 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013014 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020013015 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13016
13017 if (rtnl)
13018 rtnl_lock();
13019
13020 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020013021 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020013022 if (IS_ERR(rdev)) {
13023 if (rtnl)
13024 rtnl_unlock();
13025 return PTR_ERR(rdev);
13026 }
13027 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013028 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13029 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020013030 ASSERT_RTNL();
13031
Johannes Berg89a54e42012-06-15 14:33:17 +020013032 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13033 info->attrs);
13034 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020013035 if (rtnl)
13036 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020013037 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020013038 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013039
Johannes Berg89a54e42012-06-15 14:33:17 +020013040 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013041 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020013042
Johannes Berg1bf614e2012-06-15 15:23:36 +020013043 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13044 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020013045 if (rtnl)
13046 rtnl_unlock();
13047 return -EINVAL;
13048 }
13049
13050 info->user_ptr[1] = dev;
13051 } else {
13052 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020013053 }
Johannes Berg89a54e42012-06-15 14:33:17 +020013054
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013055 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13056 !wdev_running(wdev)) {
13057 if (rtnl)
13058 rtnl_unlock();
13059 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020013060 }
13061
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013062 if (dev)
13063 dev_hold(dev);
13064
Johannes Berg4c476992010-10-04 21:36:35 +020013065 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020013066 }
13067
13068 return 0;
13069}
13070
Johannes Bergf84f7712013-11-14 17:14:45 +010013071static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020013072 struct genl_info *info)
13073{
Johannes Berg1bf614e2012-06-15 15:23:36 +020013074 if (info->user_ptr[1]) {
13075 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13076 struct wireless_dev *wdev = info->user_ptr[1];
13077
13078 if (wdev->netdev)
13079 dev_put(wdev->netdev);
13080 } else {
13081 dev_put(info->user_ptr[1]);
13082 }
13083 }
Johannes Berg5393b912014-09-10 15:00:16 +030013084
Johannes Berg4c476992010-10-04 21:36:35 +020013085 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13086 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030013087
13088 /* If needed, clear the netlink message payload from the SKB
13089 * as it might contain key data that shouldn't stick around on
13090 * the heap after the SKB is freed. The netlink message header
13091 * is still needed for further processing, so leave it intact.
13092 */
13093 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13094 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13095
13096 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13097 }
Johannes Berg4c476992010-10-04 21:36:35 +020013098}
13099
Johannes Berg4534de82013-11-14 17:14:46 +010013100static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040013101 {
13102 .cmd = NL80211_CMD_GET_WIPHY,
13103 .doit = nl80211_get_wiphy,
13104 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020013105 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040013106 .policy = nl80211_policy,
13107 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013108 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13109 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013110 },
13111 {
13112 .cmd = NL80211_CMD_SET_WIPHY,
13113 .doit = nl80211_set_wiphy,
13114 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013115 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013116 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013117 },
13118 {
13119 .cmd = NL80211_CMD_GET_INTERFACE,
13120 .doit = nl80211_get_interface,
13121 .dumpit = nl80211_dump_interface,
13122 .policy = nl80211_policy,
13123 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020013124 .internal_flags = NL80211_FLAG_NEED_WDEV |
13125 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013126 },
13127 {
13128 .cmd = NL80211_CMD_SET_INTERFACE,
13129 .doit = nl80211_set_interface,
13130 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013131 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013132 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13133 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013134 },
13135 {
13136 .cmd = NL80211_CMD_NEW_INTERFACE,
13137 .doit = nl80211_new_interface,
13138 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013139 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013140 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13141 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013142 },
13143 {
13144 .cmd = NL80211_CMD_DEL_INTERFACE,
13145 .doit = nl80211_del_interface,
13146 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013147 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020013148 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013149 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040013150 },
Johannes Berg41ade002007-12-19 02:03:29 +010013151 {
13152 .cmd = NL80211_CMD_GET_KEY,
13153 .doit = nl80211_get_key,
13154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013157 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013158 },
13159 {
13160 .cmd = NL80211_CMD_SET_KEY,
13161 .doit = nl80211_set_key,
13162 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013163 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013165 NL80211_FLAG_NEED_RTNL |
13166 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013167 },
13168 {
13169 .cmd = NL80211_CMD_NEW_KEY,
13170 .doit = nl80211_new_key,
13171 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013172 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013173 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013174 NL80211_FLAG_NEED_RTNL |
13175 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013176 },
13177 {
13178 .cmd = NL80211_CMD_DEL_KEY,
13179 .doit = nl80211_del_key,
13180 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013181 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013182 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013183 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013184 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013185 {
13186 .cmd = NL80211_CMD_SET_BEACON,
13187 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013188 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013189 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013190 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013191 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013192 },
13193 {
Johannes Berg88600202012-02-13 15:17:18 +010013194 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013195 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013196 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013197 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013198 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013199 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013200 },
13201 {
Johannes Berg88600202012-02-13 15:17:18 +010013202 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013203 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013204 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013205 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013207 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013208 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013209 {
13210 .cmd = NL80211_CMD_GET_STATION,
13211 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013212 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010013213 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020013214 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13215 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013216 },
13217 {
13218 .cmd = NL80211_CMD_SET_STATION,
13219 .doit = nl80211_set_station,
13220 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013221 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013222 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013223 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013224 },
13225 {
13226 .cmd = NL80211_CMD_NEW_STATION,
13227 .doit = nl80211_new_station,
13228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013229 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013231 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013232 },
13233 {
13234 .cmd = NL80211_CMD_DEL_STATION,
13235 .doit = nl80211_del_station,
13236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013237 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013239 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013240 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013241 {
13242 .cmd = NL80211_CMD_GET_MPATH,
13243 .doit = nl80211_get_mpath,
13244 .dumpit = nl80211_dump_mpath,
13245 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013246 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013247 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013248 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013249 },
13250 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013251 .cmd = NL80211_CMD_GET_MPP,
13252 .doit = nl80211_get_mpp,
13253 .dumpit = nl80211_dump_mpp,
13254 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013255 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13257 NL80211_FLAG_NEED_RTNL,
13258 },
13259 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013260 .cmd = NL80211_CMD_SET_MPATH,
13261 .doit = nl80211_set_mpath,
13262 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013263 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013265 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013266 },
13267 {
13268 .cmd = NL80211_CMD_NEW_MPATH,
13269 .doit = nl80211_new_mpath,
13270 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013271 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013273 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013274 },
13275 {
13276 .cmd = NL80211_CMD_DEL_MPATH,
13277 .doit = nl80211_del_mpath,
13278 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013281 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013282 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013283 {
13284 .cmd = NL80211_CMD_SET_BSS,
13285 .doit = nl80211_set_bss,
13286 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013289 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013290 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013291 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013292 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013293 .doit = nl80211_get_reg_do,
13294 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013295 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013296 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013297 /* can be retrieved by unprivileged users */
13298 },
Johannes Bergb6863032015-10-15 09:25:18 +020013299#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013300 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013301 .cmd = NL80211_CMD_SET_REG,
13302 .doit = nl80211_set_reg,
13303 .policy = nl80211_policy,
13304 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013305 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013306 },
Johannes Bergb6863032015-10-15 09:25:18 +020013307#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013308 {
13309 .cmd = NL80211_CMD_REQ_SET_REG,
13310 .doit = nl80211_req_set_reg,
13311 .policy = nl80211_policy,
13312 .flags = GENL_ADMIN_PERM,
13313 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013314 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020013315 .cmd = NL80211_CMD_RELOAD_REGDB,
13316 .doit = nl80211_reload_regdb,
13317 .policy = nl80211_policy,
13318 .flags = GENL_ADMIN_PERM,
13319 },
13320 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013321 .cmd = NL80211_CMD_GET_MESH_CONFIG,
13322 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013323 .policy = nl80211_policy,
13324 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013325 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013326 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013327 },
13328 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013329 .cmd = NL80211_CMD_SET_MESH_CONFIG,
13330 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013331 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013332 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013334 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013335 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013336 {
Johannes Berg2a519312009-02-10 21:25:55 +010013337 .cmd = NL80211_CMD_TRIGGER_SCAN,
13338 .doit = nl80211_trigger_scan,
13339 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013341 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013342 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013343 },
13344 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013345 .cmd = NL80211_CMD_ABORT_SCAN,
13346 .doit = nl80211_abort_scan,
13347 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013348 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013349 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13350 NL80211_FLAG_NEED_RTNL,
13351 },
13352 {
Johannes Berg2a519312009-02-10 21:25:55 +010013353 .cmd = NL80211_CMD_GET_SCAN,
13354 .policy = nl80211_policy,
13355 .dumpit = nl80211_dump_scan,
13356 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013357 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013358 .cmd = NL80211_CMD_START_SCHED_SCAN,
13359 .doit = nl80211_start_sched_scan,
13360 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013361 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13363 NL80211_FLAG_NEED_RTNL,
13364 },
13365 {
13366 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
13367 .doit = nl80211_stop_sched_scan,
13368 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013369 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13371 NL80211_FLAG_NEED_RTNL,
13372 },
13373 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013374 .cmd = NL80211_CMD_AUTHENTICATE,
13375 .doit = nl80211_authenticate,
13376 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013377 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013379 NL80211_FLAG_NEED_RTNL |
13380 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013381 },
13382 {
13383 .cmd = NL80211_CMD_ASSOCIATE,
13384 .doit = nl80211_associate,
13385 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013386 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013388 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013389 },
13390 {
13391 .cmd = NL80211_CMD_DEAUTHENTICATE,
13392 .doit = nl80211_deauthenticate,
13393 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013394 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013396 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013397 },
13398 {
13399 .cmd = NL80211_CMD_DISASSOCIATE,
13400 .doit = nl80211_disassociate,
13401 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013402 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013404 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013405 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013406 {
13407 .cmd = NL80211_CMD_JOIN_IBSS,
13408 .doit = nl80211_join_ibss,
13409 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013410 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013412 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013413 },
13414 {
13415 .cmd = NL80211_CMD_LEAVE_IBSS,
13416 .doit = nl80211_leave_ibss,
13417 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013420 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013421 },
Johannes Bergaff89a92009-07-01 21:26:51 +020013422#ifdef CONFIG_NL80211_TESTMODE
13423 {
13424 .cmd = NL80211_CMD_TESTMODE,
13425 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070013426 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020013427 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013428 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013429 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13430 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020013431 },
13432#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020013433 {
13434 .cmd = NL80211_CMD_CONNECT,
13435 .doit = nl80211_connect,
13436 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013437 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013438 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013439 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013440 },
13441 {
vamsi krishna088e8df2016-10-27 16:51:11 +030013442 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
13443 .doit = nl80211_update_connect_params,
13444 .policy = nl80211_policy,
13445 .flags = GENL_ADMIN_PERM,
13446 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13447 NL80211_FLAG_NEED_RTNL,
13448 },
13449 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020013450 .cmd = NL80211_CMD_DISCONNECT,
13451 .doit = nl80211_disconnect,
13452 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013453 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013454 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013455 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013456 },
Johannes Berg463d0182009-07-14 00:33:35 +020013457 {
13458 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
13459 .doit = nl80211_wiphy_netns,
13460 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013461 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013462 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13463 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013464 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013465 {
13466 .cmd = NL80211_CMD_GET_SURVEY,
13467 .policy = nl80211_policy,
13468 .dumpit = nl80211_dump_survey,
13469 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013470 {
13471 .cmd = NL80211_CMD_SET_PMKSA,
13472 .doit = nl80211_setdel_pmksa,
13473 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013474 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013475 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013476 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013477 },
13478 {
13479 .cmd = NL80211_CMD_DEL_PMKSA,
13480 .doit = nl80211_setdel_pmksa,
13481 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013482 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013484 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013485 },
13486 {
13487 .cmd = NL80211_CMD_FLUSH_PMKSA,
13488 .doit = nl80211_flush_pmksa,
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,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013493 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013494 {
13495 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13496 .doit = nl80211_remain_on_channel,
13497 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013498 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013499 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013500 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013501 },
13502 {
13503 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13504 .doit = nl80211_cancel_remain_on_channel,
13505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013506 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013507 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013508 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013509 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013510 {
13511 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
13512 .doit = nl80211_set_tx_bitrate_mask,
13513 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013514 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013515 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13516 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013517 },
Jouni Malinen026331c2010-02-15 12:53:10 +020013518 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013519 .cmd = NL80211_CMD_REGISTER_FRAME,
13520 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013521 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013522 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013523 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013524 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013525 },
13526 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013527 .cmd = NL80211_CMD_FRAME,
13528 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013529 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013530 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013531 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013533 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020013534 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013535 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
13536 .doit = nl80211_tx_mgmt_cancel_wait,
13537 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013538 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013539 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013540 NL80211_FLAG_NEED_RTNL,
13541 },
13542 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020013543 .cmd = NL80211_CMD_SET_POWER_SAVE,
13544 .doit = nl80211_set_power_save,
13545 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013546 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013547 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13548 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013549 },
13550 {
13551 .cmd = NL80211_CMD_GET_POWER_SAVE,
13552 .doit = nl80211_get_power_save,
13553 .policy = nl80211_policy,
13554 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020013555 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13556 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013557 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013558 {
13559 .cmd = NL80211_CMD_SET_CQM,
13560 .doit = nl80211_set_cqm,
13561 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013562 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013563 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13564 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013565 },
Johannes Bergf444de02010-05-05 15:25:02 +020013566 {
13567 .cmd = NL80211_CMD_SET_CHANNEL,
13568 .doit = nl80211_set_channel,
13569 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013570 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013571 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13572 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013573 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013574 {
13575 .cmd = NL80211_CMD_SET_WDS_PEER,
13576 .doit = nl80211_set_wds_peer,
13577 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013578 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013579 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13580 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013581 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013582 {
13583 .cmd = NL80211_CMD_JOIN_MESH,
13584 .doit = nl80211_join_mesh,
13585 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013586 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013587 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13588 NL80211_FLAG_NEED_RTNL,
13589 },
13590 {
13591 .cmd = NL80211_CMD_LEAVE_MESH,
13592 .doit = nl80211_leave_mesh,
13593 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013594 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13596 NL80211_FLAG_NEED_RTNL,
13597 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013598 {
13599 .cmd = NL80211_CMD_JOIN_OCB,
13600 .doit = nl80211_join_ocb,
13601 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013602 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13604 NL80211_FLAG_NEED_RTNL,
13605 },
13606 {
13607 .cmd = NL80211_CMD_LEAVE_OCB,
13608 .doit = nl80211_leave_ocb,
13609 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013610 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13612 NL80211_FLAG_NEED_RTNL,
13613 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013614#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013615 {
13616 .cmd = NL80211_CMD_GET_WOWLAN,
13617 .doit = nl80211_get_wowlan,
13618 .policy = nl80211_policy,
13619 /* can be retrieved by unprivileged users */
13620 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13621 NL80211_FLAG_NEED_RTNL,
13622 },
13623 {
13624 .cmd = NL80211_CMD_SET_WOWLAN,
13625 .doit = nl80211_set_wowlan,
13626 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013627 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013628 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13629 NL80211_FLAG_NEED_RTNL,
13630 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013631#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013632 {
13633 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13634 .doit = nl80211_set_rekey_data,
13635 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013636 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013637 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013638 NL80211_FLAG_NEED_RTNL |
13639 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013640 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013641 {
13642 .cmd = NL80211_CMD_TDLS_MGMT,
13643 .doit = nl80211_tdls_mgmt,
13644 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013645 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013646 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13647 NL80211_FLAG_NEED_RTNL,
13648 },
13649 {
13650 .cmd = NL80211_CMD_TDLS_OPER,
13651 .doit = nl80211_tdls_oper,
13652 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013653 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013654 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13655 NL80211_FLAG_NEED_RTNL,
13656 },
Johannes Berg28946da2011-11-04 11:18:12 +010013657 {
13658 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13659 .doit = nl80211_register_unexpected_frame,
13660 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013661 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013662 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13663 NL80211_FLAG_NEED_RTNL,
13664 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013665 {
13666 .cmd = NL80211_CMD_PROBE_CLIENT,
13667 .doit = nl80211_probe_client,
13668 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013669 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013670 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013671 NL80211_FLAG_NEED_RTNL,
13672 },
Johannes Berg5e760232011-11-04 11:18:17 +010013673 {
13674 .cmd = NL80211_CMD_REGISTER_BEACONS,
13675 .doit = nl80211_register_beacons,
13676 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013677 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013678 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13679 NL80211_FLAG_NEED_RTNL,
13680 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013681 {
13682 .cmd = NL80211_CMD_SET_NOACK_MAP,
13683 .doit = nl80211_set_noack_map,
13684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013685 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013686 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13687 NL80211_FLAG_NEED_RTNL,
13688 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013689 {
13690 .cmd = NL80211_CMD_START_P2P_DEVICE,
13691 .doit = nl80211_start_p2p_device,
13692 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013693 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013694 .internal_flags = NL80211_FLAG_NEED_WDEV |
13695 NL80211_FLAG_NEED_RTNL,
13696 },
13697 {
13698 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13699 .doit = nl80211_stop_p2p_device,
13700 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013701 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013702 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13703 NL80211_FLAG_NEED_RTNL,
13704 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013705 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013706 .cmd = NL80211_CMD_START_NAN,
13707 .doit = nl80211_start_nan,
13708 .policy = nl80211_policy,
13709 .flags = GENL_ADMIN_PERM,
13710 .internal_flags = NL80211_FLAG_NEED_WDEV |
13711 NL80211_FLAG_NEED_RTNL,
13712 },
13713 {
13714 .cmd = NL80211_CMD_STOP_NAN,
13715 .doit = nl80211_stop_nan,
13716 .policy = nl80211_policy,
13717 .flags = GENL_ADMIN_PERM,
13718 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13719 NL80211_FLAG_NEED_RTNL,
13720 },
13721 {
Ayala Bekera442b762016-09-20 17:31:15 +030013722 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13723 .doit = nl80211_nan_add_func,
13724 .policy = nl80211_policy,
13725 .flags = GENL_ADMIN_PERM,
13726 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13727 NL80211_FLAG_NEED_RTNL,
13728 },
13729 {
13730 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13731 .doit = nl80211_nan_del_func,
13732 .policy = nl80211_policy,
13733 .flags = GENL_ADMIN_PERM,
13734 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13735 NL80211_FLAG_NEED_RTNL,
13736 },
13737 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013738 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13739 .doit = nl80211_nan_change_config,
13740 .policy = nl80211_policy,
13741 .flags = GENL_ADMIN_PERM,
13742 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13743 NL80211_FLAG_NEED_RTNL,
13744 },
13745 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013746 .cmd = NL80211_CMD_SET_MCAST_RATE,
13747 .doit = nl80211_set_mcast_rate,
13748 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013749 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013750 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13751 NL80211_FLAG_NEED_RTNL,
13752 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013753 {
13754 .cmd = NL80211_CMD_SET_MAC_ACL,
13755 .doit = nl80211_set_mac_acl,
13756 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013757 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013758 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13759 NL80211_FLAG_NEED_RTNL,
13760 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013761 {
13762 .cmd = NL80211_CMD_RADAR_DETECT,
13763 .doit = nl80211_start_radar_detection,
13764 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013765 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013766 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13767 NL80211_FLAG_NEED_RTNL,
13768 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013769 {
13770 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13771 .doit = nl80211_get_protocol_features,
13772 .policy = nl80211_policy,
13773 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013774 {
13775 .cmd = NL80211_CMD_UPDATE_FT_IES,
13776 .doit = nl80211_update_ft_ies,
13777 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013778 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13780 NL80211_FLAG_NEED_RTNL,
13781 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013782 {
13783 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13784 .doit = nl80211_crit_protocol_start,
13785 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013786 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013787 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13788 NL80211_FLAG_NEED_RTNL,
13789 },
13790 {
13791 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13792 .doit = nl80211_crit_protocol_stop,
13793 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013794 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013795 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13796 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013797 },
13798 {
13799 .cmd = NL80211_CMD_GET_COALESCE,
13800 .doit = nl80211_get_coalesce,
13801 .policy = nl80211_policy,
13802 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13803 NL80211_FLAG_NEED_RTNL,
13804 },
13805 {
13806 .cmd = NL80211_CMD_SET_COALESCE,
13807 .doit = nl80211_set_coalesce,
13808 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013809 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013810 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13811 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013812 },
13813 {
13814 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13815 .doit = nl80211_channel_switch,
13816 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013817 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13819 NL80211_FLAG_NEED_RTNL,
13820 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013821 {
13822 .cmd = NL80211_CMD_VENDOR,
13823 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013824 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013825 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013826 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013827 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13828 NL80211_FLAG_NEED_RTNL,
13829 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013830 {
13831 .cmd = NL80211_CMD_SET_QOS_MAP,
13832 .doit = nl80211_set_qos_map,
13833 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013834 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13836 NL80211_FLAG_NEED_RTNL,
13837 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013838 {
13839 .cmd = NL80211_CMD_ADD_TX_TS,
13840 .doit = nl80211_add_tx_ts,
13841 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013842 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13844 NL80211_FLAG_NEED_RTNL,
13845 },
13846 {
13847 .cmd = NL80211_CMD_DEL_TX_TS,
13848 .doit = nl80211_del_tx_ts,
13849 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013850 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13852 NL80211_FLAG_NEED_RTNL,
13853 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013854 {
13855 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13856 .doit = nl80211_tdls_channel_switch,
13857 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013858 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013859 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13860 NL80211_FLAG_NEED_RTNL,
13861 },
13862 {
13863 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13864 .doit = nl80211_tdls_cancel_channel_switch,
13865 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013866 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13868 NL80211_FLAG_NEED_RTNL,
13869 },
Michael Braunce0ce132016-10-10 19:12:22 +020013870 {
13871 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13872 .doit = nl80211_set_multicast_to_unicast,
13873 .policy = nl80211_policy,
13874 .flags = GENL_UNS_ADMIN_PERM,
13875 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13876 NL80211_FLAG_NEED_RTNL,
13877 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013878 {
13879 .cmd = NL80211_CMD_SET_PMK,
13880 .doit = nl80211_set_pmk,
13881 .policy = nl80211_policy,
13882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13883 NL80211_FLAG_NEED_RTNL,
13884 },
13885 {
13886 .cmd = NL80211_CMD_DEL_PMK,
13887 .doit = nl80211_del_pmk,
13888 .policy = nl80211_policy,
13889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13890 NL80211_FLAG_NEED_RTNL,
13891 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013892 {
13893 .cmd = NL80211_CMD_EXTERNAL_AUTH,
13894 .doit = nl80211_external_auth,
13895 .policy = nl80211_policy,
13896 .flags = GENL_ADMIN_PERM,
13897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13898 NL80211_FLAG_NEED_RTNL,
13899 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013900 {
13901 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
13902 .doit = nl80211_tx_control_port,
13903 .policy = nl80211_policy,
13904 .flags = GENL_UNS_ADMIN_PERM,
13905 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13906 NL80211_FLAG_NEED_RTNL,
13907 },
Johannes Berg55682962007-09-20 13:09:35 -040013908};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013909
Johannes Berg56989f62016-10-24 14:40:05 +020013910static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013911 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13912 .hdrsize = 0, /* no private header */
13913 .version = 1, /* no particular meaning now */
13914 .maxattr = NL80211_ATTR_MAX,
13915 .netnsok = true,
13916 .pre_doit = nl80211_pre_doit,
13917 .post_doit = nl80211_post_doit,
13918 .module = THIS_MODULE,
13919 .ops = nl80211_ops,
13920 .n_ops = ARRAY_SIZE(nl80211_ops),
13921 .mcgrps = nl80211_mcgrps,
13922 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13923};
13924
Johannes Berg55682962007-09-20 13:09:35 -040013925/* notification functions */
13926
Johannes Berg3bb20552014-05-26 13:52:25 +020013927void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13928 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013929{
13930 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013931 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013932
Johannes Berg3bb20552014-05-26 13:52:25 +020013933 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13934 cmd != NL80211_CMD_DEL_WIPHY);
13935
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013937 if (!msg)
13938 return;
13939
Johannes Berg3bb20552014-05-26 13:52:25 +020013940 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013941 nlmsg_free(msg);
13942 return;
13943 }
13944
Johannes Berg68eb5502013-11-19 15:19:38 +010013945 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013946 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013947}
13948
Denis Kenzior896ff062016-08-03 16:58:33 -050013949void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13950 struct wireless_dev *wdev,
13951 enum nl80211_commands cmd)
13952{
13953 struct sk_buff *msg;
13954
13955 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13956 cmd != NL80211_CMD_DEL_INTERFACE);
13957
13958 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13959 if (!msg)
13960 return;
13961
13962 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13963 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13964 nlmsg_free(msg);
13965 return;
13966 }
13967
13968 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13969 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13970}
13971
Johannes Berg362a4152009-05-24 16:43:15 +020013972static int nl80211_add_scan_req(struct sk_buff *msg,
13973 struct cfg80211_registered_device *rdev)
13974{
13975 struct cfg80211_scan_request *req = rdev->scan_req;
13976 struct nlattr *nest;
13977 int i;
13978
13979 if (WARN_ON(!req))
13980 return 0;
13981
13982 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13983 if (!nest)
13984 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013985 for (i = 0; i < req->n_ssids; i++) {
13986 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13987 goto nla_put_failure;
13988 }
Johannes Berg362a4152009-05-24 16:43:15 +020013989 nla_nest_end(msg, nest);
13990
13991 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13992 if (!nest)
13993 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013994 for (i = 0; i < req->n_channels; i++) {
13995 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13996 goto nla_put_failure;
13997 }
Johannes Berg362a4152009-05-24 16:43:15 +020013998 nla_nest_end(msg, nest);
13999
David S. Miller9360ffd2012-03-29 04:41:26 -040014000 if (req->ie &&
14001 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14002 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020014003
Johannes Bergae917c92013-10-25 11:05:22 +020014004 if (req->flags &&
14005 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14006 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070014007
Avraham Stern1d762502016-07-05 17:10:13 +030014008 if (req->info.scan_start_tsf &&
14009 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14010 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14011 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14012 req->info.tsf_bssid)))
14013 goto nla_put_failure;
14014
Johannes Berg362a4152009-05-24 16:43:15 +020014015 return 0;
14016 nla_put_failure:
14017 return -ENOBUFS;
14018}
14019
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014020static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020014021 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014022 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014023 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020014024 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010014025{
14026 void *hdr;
14027
Eric W. Biederman15e47302012-09-07 20:12:54 +000014028 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010014029 if (!hdr)
14030 return -1;
14031
David S. Miller9360ffd2012-03-29 04:41:26 -040014032 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020014033 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14034 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014035 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14036 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014037 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010014038
Johannes Berg362a4152009-05-24 16:43:15 +020014039 /* ignore errors and send incomplete event anyway */
14040 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010014041
Johannes Berg053c0952015-01-16 22:09:00 +010014042 genlmsg_end(msg, hdr);
14043 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010014044
14045 nla_put_failure:
14046 genlmsg_cancel(msg, hdr);
14047 return -EMSGSIZE;
14048}
14049
Luciano Coelho807f8a82011-05-11 17:09:35 +030014050static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014051nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014052 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014053{
14054 void *hdr;
14055
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014056 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014057 if (!hdr)
14058 return -1;
14059
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014060 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14061 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14062 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14063 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14064 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014065 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014066
Johannes Berg053c0952015-01-16 22:09:00 +010014067 genlmsg_end(msg, hdr);
14068 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030014069
14070 nla_put_failure:
14071 genlmsg_cancel(msg, hdr);
14072 return -EMSGSIZE;
14073}
14074
Johannes Berga538e2d2009-06-16 19:56:42 +020014075void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020014076 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020014077{
14078 struct sk_buff *msg;
14079
Thomas Graf58050fc2012-06-28 03:57:45 +000014080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014081 if (!msg)
14082 return;
14083
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014084 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020014085 NL80211_CMD_TRIGGER_SCAN) < 0) {
14086 nlmsg_free(msg);
14087 return;
14088 }
14089
Johannes Berg68eb5502013-11-19 15:19:38 +010014090 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014091 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020014092}
14093
Johannes Bergf9d15d12014-01-22 11:14:19 +020014094struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14095 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010014096{
14097 struct sk_buff *msg;
14098
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014100 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020014101 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014102
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014103 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020014104 aborted ? NL80211_CMD_SCAN_ABORTED :
14105 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010014106 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020014107 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010014108 }
14109
Johannes Bergf9d15d12014-01-22 11:14:19 +020014110 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010014111}
14112
Arend Van Spriel505a2e82016-12-16 11:21:54 +000014113/* send message created by nl80211_build_scan_msg() */
14114void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14115 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010014116{
Johannes Berg2a519312009-02-10 21:25:55 +010014117 if (!msg)
14118 return;
14119
Johannes Berg68eb5502013-11-19 15:19:38 +010014120 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014121 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010014122}
14123
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014124void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030014125{
14126 struct sk_buff *msg;
14127
Thomas Graf58050fc2012-06-28 03:57:45 +000014128 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014129 if (!msg)
14130 return;
14131
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014132 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014133 nlmsg_free(msg);
14134 return;
14135 }
14136
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010014137 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014138 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030014139}
14140
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014141static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14142 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014143{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014144 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040014145 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14146 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014147
David S. Miller9360ffd2012-03-29 04:41:26 -040014148 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14149 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14150 NL80211_REGDOM_TYPE_WORLD))
14151 goto nla_put_failure;
14152 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
14153 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14154 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
14155 goto nla_put_failure;
14156 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
14157 request->intersect) {
14158 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14159 NL80211_REGDOM_TYPE_INTERSECTION))
14160 goto nla_put_failure;
14161 } else {
14162 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14163 NL80211_REGDOM_TYPE_COUNTRY) ||
14164 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
14165 request->alpha2))
14166 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014167 }
14168
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014169 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
14170 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
14171
14172 if (wiphy &&
14173 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14174 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014175
14176 if (wiphy &&
14177 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14178 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14179 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014180 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014181
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014182 return true;
14183
14184nla_put_failure:
14185 return false;
14186}
14187
14188/*
14189 * This can happen on global regulatory changes or device specific settings
14190 * based on custom regulatory domains.
14191 */
14192void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14193 struct regulatory_request *request)
14194{
14195 struct sk_buff *msg;
14196 void *hdr;
14197
14198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14199 if (!msg)
14200 return;
14201
14202 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14203 if (!hdr) {
14204 nlmsg_free(msg);
14205 return;
14206 }
14207
14208 if (nl80211_reg_change_event_fill(msg, request) == false)
14209 goto nla_put_failure;
14210
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014211 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014212
Johannes Bergbc43b282009-07-25 10:54:13 +020014213 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014214 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014215 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014216 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014217
14218 return;
14219
14220nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014221 nlmsg_free(msg);
14222}
14223
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014224static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14225 struct net_device *netdev,
14226 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014227 enum nl80211_commands cmd, gfp_t gfp,
14228 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014229{
14230 struct sk_buff *msg;
14231 void *hdr;
14232
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014233 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014234 if (!msg)
14235 return;
14236
14237 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14238 if (!hdr) {
14239 nlmsg_free(msg);
14240 return;
14241 }
14242
David S. Miller9360ffd2012-03-29 04:41:26 -040014243 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14244 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14245 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
14246 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014247
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014248 if (uapsd_queues >= 0) {
14249 struct nlattr *nla_wmm =
14250 nla_nest_start(msg, NL80211_ATTR_STA_WME);
14251 if (!nla_wmm)
14252 goto nla_put_failure;
14253
14254 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14255 uapsd_queues))
14256 goto nla_put_failure;
14257
14258 nla_nest_end(msg, nla_wmm);
14259 }
14260
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014261 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014262
Johannes Berg68eb5502013-11-19 15:19:38 +010014263 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014264 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014265 return;
14266
14267 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014268 nlmsg_free(msg);
14269}
14270
14271void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014272 struct net_device *netdev, const u8 *buf,
14273 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014274{
14275 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014276 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014277}
14278
14279void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14280 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014281 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014282{
Johannes Berge6d6e342009-07-01 21:26:47 +020014283 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014284 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014285}
14286
Jouni Malinen53b46b82009-03-27 20:53:56 +020014287void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014288 struct net_device *netdev, const u8 *buf,
14289 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014290{
14291 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014292 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014293}
14294
Jouni Malinen53b46b82009-03-27 20:53:56 +020014295void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14296 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014297 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014298{
14299 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014300 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014301}
14302
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014303void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14304 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014305{
Johannes Berg947add32013-02-22 22:05:20 +010014306 struct wireless_dev *wdev = dev->ieee80211_ptr;
14307 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014309 const struct ieee80211_mgmt *mgmt = (void *)buf;
14310 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014311
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014312 if (WARN_ON(len < 2))
14313 return;
14314
14315 if (ieee80211_is_deauth(mgmt->frame_control))
14316 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14317 else
14318 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14319
14320 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014321 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014322}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014323EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014324
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014325static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14326 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014327 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014328{
14329 struct sk_buff *msg;
14330 void *hdr;
14331
Johannes Berge6d6e342009-07-01 21:26:47 +020014332 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014333 if (!msg)
14334 return;
14335
14336 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14337 if (!hdr) {
14338 nlmsg_free(msg);
14339 return;
14340 }
14341
David S. Miller9360ffd2012-03-29 04:41:26 -040014342 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14343 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14344 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14345 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14346 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014347
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014348 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014349
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_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014352 return;
14353
14354 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014355 nlmsg_free(msg);
14356}
14357
14358void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014359 struct net_device *netdev, const u8 *addr,
14360 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014361{
14362 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014363 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014364}
14365
14366void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014367 struct net_device *netdev, const u8 *addr,
14368 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014369{
Johannes Berge6d6e342009-07-01 21:26:47 +020014370 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14371 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014372}
14373
Samuel Ortizb23aa672009-07-01 21:26:54 +020014374void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014375 struct net_device *netdev,
14376 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014377 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014378{
14379 struct sk_buff *msg;
14380 void *hdr;
14381
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014382 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020014383 cr->fils.kek_len + cr->fils.pmk_len +
14384 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014385 if (!msg)
14386 return;
14387
14388 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
14389 if (!hdr) {
14390 nlmsg_free(msg);
14391 return;
14392 }
14393
David S. Miller9360ffd2012-03-29 04:41:26 -040014394 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14395 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014396 (cr->bssid &&
14397 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030014398 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014399 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
14400 cr->status) ||
14401 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014402 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014403 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
14404 cr->timeout_reason))) ||
14405 (cr->req_ie &&
14406 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
14407 (cr->resp_ie &&
14408 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014409 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020014410 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014411 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020014412 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014413 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020014414 ((cr->fils.kek &&
14415 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
14416 cr->fils.kek)) ||
14417 (cr->fils.pmk &&
14418 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
14419 (cr->fils.pmkid &&
14420 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040014421 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014422
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014423 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014424
Johannes Berg68eb5502013-11-19 15:19:38 +010014425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014426 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014427 return;
14428
14429 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014430 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014431}
14432
14433void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014434 struct net_device *netdev,
14435 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014436{
14437 struct sk_buff *msg;
14438 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014439 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014440
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014441 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
14442 info->fils.kek_len + info->fils.pmk_len +
14443 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014444 if (!msg)
14445 return;
14446
14447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
14448 if (!hdr) {
14449 nlmsg_free(msg);
14450 return;
14451 }
14452
David S. Miller9360ffd2012-03-29 04:41:26 -040014453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14455 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014456 (info->req_ie &&
14457 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
14458 info->req_ie)) ||
14459 (info->resp_ie &&
14460 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020014461 info->resp_ie)) ||
14462 (info->fils.update_erp_next_seq_num &&
14463 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
14464 info->fils.erp_next_seq_num)) ||
14465 (info->fils.kek &&
14466 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
14467 info->fils.kek)) ||
14468 (info->fils.pmk &&
14469 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
14470 (info->fils.pmkid &&
14471 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014472 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014473
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014474 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014475
Johannes Berg68eb5502013-11-19 15:19:38 +010014476 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014477 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014478 return;
14479
14480 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014481 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014482}
14483
Avraham Stern503c1fb2017-09-29 14:21:49 +020014484void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
14485 struct net_device *netdev, const u8 *bssid)
14486{
14487 struct sk_buff *msg;
14488 void *hdr;
14489
14490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14491 if (!msg)
14492 return;
14493
14494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
14495 if (!hdr) {
14496 nlmsg_free(msg);
14497 return;
14498 }
14499
14500 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14501 goto nla_put_failure;
14502
14503 genlmsg_end(msg, hdr);
14504
14505 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14506 NL80211_MCGRP_MLME, GFP_KERNEL);
14507 return;
14508
14509 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020014510 nlmsg_free(msg);
14511}
14512
Samuel Ortizb23aa672009-07-01 21:26:54 +020014513void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
14514 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020014515 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014516{
14517 struct sk_buff *msg;
14518 void *hdr;
14519
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014520 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014521 if (!msg)
14522 return;
14523
14524 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
14525 if (!hdr) {
14526 nlmsg_free(msg);
14527 return;
14528 }
14529
David S. Miller9360ffd2012-03-29 04:41:26 -040014530 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14531 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020014532 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040014533 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
14534 (from_ap &&
14535 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
14536 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
14537 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014538
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014539 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014540
Johannes Berg68eb5502013-11-19 15:19:38 +010014541 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014542 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014543 return;
14544
14545 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014546 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014547}
14548
Johannes Berg04a773a2009-04-19 21:24:32 +020014549void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
14550 struct net_device *netdev, const u8 *bssid,
14551 gfp_t gfp)
14552{
14553 struct sk_buff *msg;
14554 void *hdr;
14555
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014557 if (!msg)
14558 return;
14559
14560 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
14561 if (!hdr) {
14562 nlmsg_free(msg);
14563 return;
14564 }
14565
David S. Miller9360ffd2012-03-29 04:41:26 -040014566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14568 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14569 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020014570
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014571 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020014572
Johannes Berg68eb5502013-11-19 15:19:38 +010014573 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014574 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014575 return;
14576
14577 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020014578 nlmsg_free(msg);
14579}
14580
Johannes Berg947add32013-02-22 22:05:20 +010014581void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
14582 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070014583{
Johannes Berg947add32013-02-22 22:05:20 +010014584 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014585 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014586 struct sk_buff *msg;
14587 void *hdr;
14588
Johannes Berg947add32013-02-22 22:05:20 +010014589 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14590 return;
14591
14592 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14593
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014594 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014595 if (!msg)
14596 return;
14597
14598 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14599 if (!hdr) {
14600 nlmsg_free(msg);
14601 return;
14602 }
14603
David S. Miller9360ffd2012-03-29 04:41:26 -040014604 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014605 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014607 (ie_len && ie &&
14608 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14609 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014610
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014611 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014612
Johannes Berg68eb5502013-11-19 15:19:38 +010014613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014614 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014615 return;
14616
14617 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070014618 nlmsg_free(msg);
14619}
Johannes Berg947add32013-02-22 22:05:20 +010014620EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014621
Jouni Malinena3b8b052009-03-27 21:59:49 +020014622void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14623 struct net_device *netdev, const u8 *addr,
14624 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014625 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014626{
14627 struct sk_buff *msg;
14628 void *hdr;
14629
Johannes Berge6d6e342009-07-01 21:26:47 +020014630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014631 if (!msg)
14632 return;
14633
14634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14635 if (!hdr) {
14636 nlmsg_free(msg);
14637 return;
14638 }
14639
David S. Miller9360ffd2012-03-29 04:41:26 -040014640 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14641 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14642 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14643 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14644 (key_id != -1 &&
14645 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14646 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14647 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014648
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014649 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014650
Johannes Berg68eb5502013-11-19 15:19:38 +010014651 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014652 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014653 return;
14654
14655 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020014656 nlmsg_free(msg);
14657}
14658
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014659void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14660 struct ieee80211_channel *channel_before,
14661 struct ieee80211_channel *channel_after)
14662{
14663 struct sk_buff *msg;
14664 void *hdr;
14665 struct nlattr *nl_freq;
14666
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014668 if (!msg)
14669 return;
14670
14671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14672 if (!hdr) {
14673 nlmsg_free(msg);
14674 return;
14675 }
14676
14677 /*
14678 * Since we are applying the beacon hint to a wiphy we know its
14679 * wiphy_idx is valid
14680 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14682 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014683
14684 /* Before */
14685 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14686 if (!nl_freq)
14687 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014688
14689 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014690 goto nla_put_failure;
14691 nla_nest_end(msg, nl_freq);
14692
14693 /* After */
14694 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14695 if (!nl_freq)
14696 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014697
14698 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014699 goto nla_put_failure;
14700 nla_nest_end(msg, nl_freq);
14701
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014702 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014703
Johannes Berg463d0182009-07-14 00:33:35 +020014704 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014705 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014706 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014707 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014708
14709 return;
14710
14711nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014712 nlmsg_free(msg);
14713}
14714
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014715static void nl80211_send_remain_on_chan_event(
14716 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014717 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014718 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014719 unsigned int duration, gfp_t gfp)
14720{
14721 struct sk_buff *msg;
14722 void *hdr;
14723
14724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14725 if (!msg)
14726 return;
14727
14728 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14729 if (!hdr) {
14730 nlmsg_free(msg);
14731 return;
14732 }
14733
David S. Miller9360ffd2012-03-29 04:41:26 -040014734 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014735 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14736 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014737 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14738 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014739 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014740 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14741 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014742 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14743 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014744 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014745
David S. Miller9360ffd2012-03-29 04:41:26 -040014746 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14747 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14748 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014749
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014750 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014751
Johannes Berg68eb5502013-11-19 15:19:38 +010014752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014753 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014754 return;
14755
14756 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014757 nlmsg_free(msg);
14758}
14759
Johannes Berg947add32013-02-22 22:05:20 +010014760void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14761 struct ieee80211_channel *chan,
14762 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014763{
Johannes Berg947add32013-02-22 22:05:20 +010014764 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014765 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014766
14767 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014768 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014769 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014770 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014771}
Johannes Berg947add32013-02-22 22:05:20 +010014772EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014773
Johannes Berg947add32013-02-22 22:05:20 +010014774void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14775 struct ieee80211_channel *chan,
14776 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014777{
Johannes Berg947add32013-02-22 22:05:20 +010014778 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014779 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014780
14781 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014782 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014783 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014784}
Johannes Berg947add32013-02-22 22:05:20 +010014785EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014786
Johannes Berg947add32013-02-22 22:05:20 +010014787void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14788 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014789{
Johannes Berg947add32013-02-22 22:05:20 +010014790 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014791 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014792 struct sk_buff *msg;
14793
Johannes Berg947add32013-02-22 22:05:20 +010014794 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14795
Thomas Graf58050fc2012-06-28 03:57:45 +000014796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014797 if (!msg)
14798 return;
14799
Johannes Bergcf5ead82014-11-14 17:14:00 +010014800 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014801 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014802 nlmsg_free(msg);
14803 return;
14804 }
14805
Johannes Berg68eb5502013-11-19 15:19:38 +010014806 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014807 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014808}
Johannes Berg947add32013-02-22 22:05:20 +010014809EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014810
Johannes Bergcf5ead82014-11-14 17:14:00 +010014811void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14812 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014813{
Johannes Berg947add32013-02-22 22:05:20 +010014814 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014815 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014816 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020014817 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010014818
Johannes Berg73887fd2018-05-18 09:57:55 +020014819 if (!sinfo)
14820 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014821
Johannes Berg947add32013-02-22 22:05:20 +010014822 trace_cfg80211_del_sta(dev, mac_addr);
14823
Thomas Graf58050fc2012-06-28 03:57:45 +000014824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020014825 if (!msg) {
14826 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020014827 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020014828 }
Jouni Malinenec15e682011-03-23 15:29:52 +020014829
Johannes Bergcf5ead82014-11-14 17:14:00 +010014830 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014831 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014832 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020014833 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020014834 }
14835
Johannes Berg68eb5502013-11-19 15:19:38 +010014836 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014837 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014838}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014839EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014840
Johannes Berg947add32013-02-22 22:05:20 +010014841void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14842 enum nl80211_connect_failed_reason reason,
14843 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014844{
Johannes Berg947add32013-02-22 22:05:20 +010014845 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014846 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014847 struct sk_buff *msg;
14848 void *hdr;
14849
14850 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14851 if (!msg)
14852 return;
14853
14854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14855 if (!hdr) {
14856 nlmsg_free(msg);
14857 return;
14858 }
14859
14860 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14862 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14863 goto nla_put_failure;
14864
14865 genlmsg_end(msg, hdr);
14866
Johannes Berg68eb5502013-11-19 15:19:38 +010014867 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014868 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014869 return;
14870
14871 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014872 nlmsg_free(msg);
14873}
Johannes Berg947add32013-02-22 22:05:20 +010014874EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014875
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014876static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14877 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014878{
14879 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014881 struct sk_buff *msg;
14882 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014883 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014884
Eric W. Biederman15e47302012-09-07 20:12:54 +000014885 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014886 return false;
14887
14888 msg = nlmsg_new(100, gfp);
14889 if (!msg)
14890 return true;
14891
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014892 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014893 if (!hdr) {
14894 nlmsg_free(msg);
14895 return true;
14896 }
14897
David S. Miller9360ffd2012-03-29 04:41:26 -040014898 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14899 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14900 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14901 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014902
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014903 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014904 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014905 return true;
14906
14907 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010014908 nlmsg_free(msg);
14909 return true;
14910}
14911
Johannes Berg947add32013-02-22 22:05:20 +010014912bool cfg80211_rx_spurious_frame(struct net_device *dev,
14913 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014914{
Johannes Berg947add32013-02-22 22:05:20 +010014915 struct wireless_dev *wdev = dev->ieee80211_ptr;
14916 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014917
Johannes Berg947add32013-02-22 22:05:20 +010014918 trace_cfg80211_rx_spurious_frame(dev, addr);
14919
14920 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14921 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14922 trace_cfg80211_return_bool(false);
14923 return false;
14924 }
14925 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14926 addr, gfp);
14927 trace_cfg80211_return_bool(ret);
14928 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014929}
Johannes Berg947add32013-02-22 22:05:20 +010014930EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14931
14932bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14933 const u8 *addr, gfp_t gfp)
14934{
14935 struct wireless_dev *wdev = dev->ieee80211_ptr;
14936 bool ret;
14937
14938 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14939
14940 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14941 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14942 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14943 trace_cfg80211_return_bool(false);
14944 return false;
14945 }
14946 ret = __nl80211_unexpected_frame(dev,
14947 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14948 addr, gfp);
14949 trace_cfg80211_return_bool(ret);
14950 return ret;
14951}
14952EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014953
Johannes Berg2e161f782010-08-12 15:38:38 +020014954int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014955 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014956 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014957 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014958{
Johannes Berg71bbc992012-06-15 15:30:18 +020014959 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014960 struct sk_buff *msg;
14961 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014962
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014963 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014964 if (!msg)
14965 return -ENOMEM;
14966
Johannes Berg2e161f782010-08-12 15:38:38 +020014967 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014968 if (!hdr) {
14969 nlmsg_free(msg);
14970 return -ENOMEM;
14971 }
14972
David S. Miller9360ffd2012-03-29 04:41:26 -040014973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014974 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14975 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014976 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14977 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014978 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14979 (sig_dbm &&
14980 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014981 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14982 (flags &&
14983 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014984 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014985
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014986 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014987
Eric W. Biederman15e47302012-09-07 20:12:54 +000014988 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014989
14990 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020014991 nlmsg_free(msg);
14992 return -ENOBUFS;
14993}
14994
Johannes Berg947add32013-02-22 22:05:20 +010014995void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14996 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014997{
Johannes Berg947add32013-02-22 22:05:20 +010014998 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014999 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020015000 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020015001 struct sk_buff *msg;
15002 void *hdr;
15003
Johannes Berg947add32013-02-22 22:05:20 +010015004 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15005
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015006 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015007 if (!msg)
15008 return;
15009
Johannes Berg2e161f782010-08-12 15:38:38 +020015010 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020015011 if (!hdr) {
15012 nlmsg_free(msg);
15013 return;
15014 }
15015
David S. Miller9360ffd2012-03-29 04:41:26 -040015016 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015017 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15018 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015019 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15020 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015021 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015022 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15023 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015024 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15025 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020015026
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015027 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020015028
Johannes Berg68eb5502013-11-19 15:19:38 +010015029 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015030 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020015031 return;
15032
15033 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020015034 nlmsg_free(msg);
15035}
Johannes Berg947add32013-02-22 22:05:20 +010015036EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020015037
Denis Kenzior6a671a52018-03-26 12:52:41 -050015038static int __nl80211_rx_control_port(struct net_device *dev,
15039 const u8 *buf, size_t len,
15040 const u8 *addr, u16 proto,
15041 bool unencrypted, gfp_t gfp)
15042{
15043 struct wireless_dev *wdev = dev->ieee80211_ptr;
15044 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15045 struct sk_buff *msg;
15046 void *hdr;
15047 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15048
15049 if (!nlportid)
15050 return -ENOENT;
15051
15052 msg = nlmsg_new(100 + len, gfp);
15053 if (!msg)
15054 return -ENOMEM;
15055
15056 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15057 if (!hdr) {
15058 nlmsg_free(msg);
15059 return -ENOBUFS;
15060 }
15061
15062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15063 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15064 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15065 NL80211_ATTR_PAD) ||
15066 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15067 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15068 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15069 (unencrypted && nla_put_flag(msg,
15070 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15071 goto nla_put_failure;
15072
15073 genlmsg_end(msg, hdr);
15074
15075 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15076
15077 nla_put_failure:
15078 nlmsg_free(msg);
15079 return -ENOBUFS;
15080}
15081
15082bool cfg80211_rx_control_port(struct net_device *dev,
15083 const u8 *buf, size_t len,
15084 const u8 *addr, u16 proto, bool unencrypted)
15085{
15086 int ret;
15087
15088 trace_cfg80211_rx_control_port(dev, buf, len, addr, proto, unencrypted);
15089 ret = __nl80211_rx_control_port(dev, buf, len, addr, proto,
15090 unencrypted, GFP_ATOMIC);
15091 trace_cfg80211_return_bool(ret == 0);
15092 return ret == 0;
15093}
15094EXPORT_SYMBOL(cfg80211_rx_control_port);
15095
Johannes Berg5b97f492014-11-26 12:37:43 +010015096static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15097 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015098{
Johannes Berg947add32013-02-22 22:05:20 +010015099 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010015100 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15101 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15102 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015103
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015104 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010015105 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015106
Johannes Berg5b97f492014-11-26 12:37:43 +010015107 cb = (void **)msg->cb;
15108
15109 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15110 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015111 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010015112 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015113 }
15114
David S. Miller9360ffd2012-03-29 04:41:26 -040015115 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015116 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040015117 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015118
Johannes Berg5b97f492014-11-26 12:37:43 +010015119 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015120 goto nla_put_failure;
15121
Johannes Berg5b97f492014-11-26 12:37:43 +010015122 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
15123 if (!cb[1])
15124 goto nla_put_failure;
15125
15126 cb[2] = rdev;
15127
15128 return msg;
15129 nla_put_failure:
15130 nlmsg_free(msg);
15131 return NULL;
15132}
15133
15134static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
15135{
15136 void **cb = (void **)msg->cb;
15137 struct cfg80211_registered_device *rdev = cb[2];
15138
15139 nla_nest_end(msg, cb[1]);
15140 genlmsg_end(msg, cb[0]);
15141
15142 memset(msg->cb, 0, sizeof(msg->cb));
15143
15144 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15145 NL80211_MCGRP_MLME, gfp);
15146}
15147
15148void cfg80211_cqm_rssi_notify(struct net_device *dev,
15149 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015150 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010015151{
15152 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015153 struct wireless_dev *wdev = dev->ieee80211_ptr;
15154 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010015155
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015156 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010015157
Johannes Berg98f03342014-11-26 12:42:02 +010015158 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
15159 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
15160 return;
15161
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010015162 if (wdev->cqm_config) {
15163 wdev->cqm_config->last_rssi_event_value = rssi_level;
15164
15165 cfg80211_cqm_rssi_update(rdev, dev);
15166
15167 if (rssi_level == 0)
15168 rssi_level = wdev->cqm_config->last_rssi_event_value;
15169 }
15170
Johannes Berg5b97f492014-11-26 12:37:43 +010015171 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15172 if (!msg)
15173 return;
15174
David S. Miller9360ffd2012-03-29 04:41:26 -040015175 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
15176 rssi_event))
15177 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015178
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010015179 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
15180 rssi_level))
15181 goto nla_put_failure;
15182
Johannes Berg5b97f492014-11-26 12:37:43 +010015183 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015184
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015185 return;
15186
15187 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015188 nlmsg_free(msg);
15189}
Johannes Berg947add32013-02-22 22:05:20 +010015190EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015191
Johannes Berg5b97f492014-11-26 12:37:43 +010015192void cfg80211_cqm_txe_notify(struct net_device *dev,
15193 const u8 *peer, u32 num_packets,
15194 u32 rate, u32 intvl, gfp_t gfp)
15195{
15196 struct sk_buff *msg;
15197
15198 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15199 if (!msg)
15200 return;
15201
15202 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15203 goto nla_put_failure;
15204
15205 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15206 goto nla_put_failure;
15207
15208 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15209 goto nla_put_failure;
15210
15211 cfg80211_send_cqm(msg, gfp);
15212 return;
15213
15214 nla_put_failure:
15215 nlmsg_free(msg);
15216}
15217EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15218
15219void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15220 const u8 *peer, u32 num_packets, gfp_t gfp)
15221{
15222 struct sk_buff *msg;
15223
15224 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15225
15226 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15227 if (!msg)
15228 return;
15229
15230 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15231 goto nla_put_failure;
15232
15233 cfg80211_send_cqm(msg, gfp);
15234 return;
15235
15236 nla_put_failure:
15237 nlmsg_free(msg);
15238}
15239EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15240
Johannes Berg98f03342014-11-26 12:42:02 +010015241void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15242{
15243 struct sk_buff *msg;
15244
15245 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15246 if (!msg)
15247 return;
15248
15249 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15250 goto nla_put_failure;
15251
15252 cfg80211_send_cqm(msg, gfp);
15253 return;
15254
15255 nla_put_failure:
15256 nlmsg_free(msg);
15257}
15258EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15259
Johannes Berg947add32013-02-22 22:05:20 +010015260static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15261 struct net_device *netdev, const u8 *bssid,
15262 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015263{
15264 struct sk_buff *msg;
15265 struct nlattr *rekey_attr;
15266 void *hdr;
15267
Thomas Graf58050fc2012-06-28 03:57:45 +000015268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015269 if (!msg)
15270 return;
15271
15272 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15273 if (!hdr) {
15274 nlmsg_free(msg);
15275 return;
15276 }
15277
David S. Miller9360ffd2012-03-29 04:41:26 -040015278 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15279 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15280 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15281 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015282
15283 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
15284 if (!rekey_attr)
15285 goto nla_put_failure;
15286
David S. Miller9360ffd2012-03-29 04:41:26 -040015287 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15288 NL80211_REPLAY_CTR_LEN, replay_ctr))
15289 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015290
15291 nla_nest_end(msg, rekey_attr);
15292
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015293 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015294
Johannes Berg68eb5502013-11-19 15:19:38 +010015295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015296 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015297 return;
15298
15299 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015300 nlmsg_free(msg);
15301}
15302
Johannes Berg947add32013-02-22 22:05:20 +010015303void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15304 const u8 *replay_ctr, gfp_t gfp)
15305{
15306 struct wireless_dev *wdev = dev->ieee80211_ptr;
15307 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015309
15310 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15311 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15312}
15313EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15314
15315static void
15316nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15317 struct net_device *netdev, int index,
15318 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015319{
15320 struct sk_buff *msg;
15321 struct nlattr *attr;
15322 void *hdr;
15323
Thomas Graf58050fc2012-06-28 03:57:45 +000015324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015325 if (!msg)
15326 return;
15327
15328 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15329 if (!hdr) {
15330 nlmsg_free(msg);
15331 return;
15332 }
15333
David S. Miller9360ffd2012-03-29 04:41:26 -040015334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15335 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15336 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015337
15338 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
15339 if (!attr)
15340 goto nla_put_failure;
15341
David S. Miller9360ffd2012-03-29 04:41:26 -040015342 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15343 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15344 (preauth &&
15345 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15346 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015347
15348 nla_nest_end(msg, attr);
15349
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015350 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015351
Johannes Berg68eb5502013-11-19 15:19:38 +010015352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015353 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015354 return;
15355
15356 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015357 nlmsg_free(msg);
15358}
15359
Johannes Berg947add32013-02-22 22:05:20 +010015360void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
15361 const u8 *bssid, bool preauth, gfp_t gfp)
15362{
15363 struct wireless_dev *wdev = dev->ieee80211_ptr;
15364 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015365 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015366
15367 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
15368 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
15369}
15370EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
15371
15372static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
15373 struct net_device *netdev,
15374 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020015375 gfp_t gfp,
15376 enum nl80211_commands notif,
15377 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070015378{
15379 struct sk_buff *msg;
15380 void *hdr;
15381
Thomas Graf58050fc2012-06-28 03:57:45 +000015382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015383 if (!msg)
15384 return;
15385
Luciano Coelhof8d75522014-11-07 14:31:35 +020015386 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070015387 if (!hdr) {
15388 nlmsg_free(msg);
15389 return;
15390 }
15391
Johannes Berg683b6d32012-11-08 21:25:48 +010015392 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15393 goto nla_put_failure;
15394
15395 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040015396 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070015397
Luciano Coelhof8d75522014-11-07 14:31:35 +020015398 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
15399 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
15400 goto nla_put_failure;
15401
Thomas Pedersen53145262012-04-06 13:35:47 -070015402 genlmsg_end(msg, hdr);
15403
Johannes Berg68eb5502013-11-19 15:19:38 +010015404 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015405 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015406 return;
15407
15408 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070015409 nlmsg_free(msg);
15410}
15411
Johannes Berg947add32013-02-22 22:05:20 +010015412void cfg80211_ch_switch_notify(struct net_device *dev,
15413 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070015414{
Johannes Berg947add32013-02-22 22:05:20 +010015415 struct wireless_dev *wdev = dev->ieee80211_ptr;
15416 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015417 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015418
Simon Wunderliche487eae2013-11-21 18:19:51 +010015419 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010015420
Simon Wunderliche487eae2013-11-21 18:19:51 +010015421 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010015422
Michal Kazior9e0e2962014-01-29 14:22:27 +010015423 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010015424 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020015425 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15426 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010015427}
15428EXPORT_SYMBOL(cfg80211_ch_switch_notify);
15429
Luciano Coelhof8d75522014-11-07 14:31:35 +020015430void cfg80211_ch_switch_started_notify(struct net_device *dev,
15431 struct cfg80211_chan_def *chandef,
15432 u8 count)
15433{
15434 struct wireless_dev *wdev = dev->ieee80211_ptr;
15435 struct wiphy *wiphy = wdev->wiphy;
15436 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15437
15438 trace_cfg80211_ch_switch_started_notify(dev, chandef);
15439
15440 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15441 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
15442}
15443EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
15444
Thomas Pedersen84f10702012-07-12 16:17:33 -070015445void
Simon Wunderlich04f39042013-02-08 18:16:19 +010015446nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010015447 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015448 enum nl80211_radar_event event,
15449 struct net_device *netdev, gfp_t gfp)
15450{
15451 struct sk_buff *msg;
15452 void *hdr;
15453
15454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15455 if (!msg)
15456 return;
15457
15458 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
15459 if (!hdr) {
15460 nlmsg_free(msg);
15461 return;
15462 }
15463
15464 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15465 goto nla_put_failure;
15466
15467 /* NOP and radar events don't need a netdev parameter */
15468 if (netdev) {
15469 struct wireless_dev *wdev = netdev->ieee80211_ptr;
15470
15471 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015472 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15473 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010015474 goto nla_put_failure;
15475 }
15476
15477 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
15478 goto nla_put_failure;
15479
15480 if (nl80211_send_chandef(msg, chandef))
15481 goto nla_put_failure;
15482
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015483 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015484
Johannes Berg68eb5502013-11-19 15:19:38 +010015485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015486 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015487 return;
15488
15489 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010015490 nlmsg_free(msg);
15491}
15492
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053015493void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
15494 struct sta_opmode_info *sta_opmode,
15495 gfp_t gfp)
15496{
15497 struct sk_buff *msg;
15498 struct wireless_dev *wdev = dev->ieee80211_ptr;
15499 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15500 void *hdr;
15501
15502 if (WARN_ON(!mac))
15503 return;
15504
15505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15506 if (!msg)
15507 return;
15508
15509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
15510 if (!hdr) {
15511 nlmsg_free(msg);
15512 return;
15513 }
15514
15515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15516 goto nla_put_failure;
15517
15518 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15519 goto nla_put_failure;
15520
15521 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15522 goto nla_put_failure;
15523
15524 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
15525 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
15526 goto nla_put_failure;
15527
15528 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
15529 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
15530 goto nla_put_failure;
15531
15532 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
15533 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
15534 goto nla_put_failure;
15535
15536 genlmsg_end(msg, hdr);
15537
15538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15539 NL80211_MCGRP_MLME, gfp);
15540
15541 return;
15542
15543nla_put_failure:
15544 nlmsg_free(msg);
15545}
15546EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
15547
Johannes Berg7f6cf312011-11-04 11:18:15 +010015548void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015549 u64 cookie, bool acked, s32 ack_signal,
15550 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010015551{
15552 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015553 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015554 struct sk_buff *msg;
15555 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015556
Beni Lev4ee3e062012-08-27 12:49:39 +030015557 trace_cfg80211_probe_status(dev, addr, cookie, acked);
15558
Thomas Graf58050fc2012-06-28 03:57:45 +000015559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030015560
Johannes Berg7f6cf312011-11-04 11:18:15 +010015561 if (!msg)
15562 return;
15563
15564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
15565 if (!hdr) {
15566 nlmsg_free(msg);
15567 return;
15568 }
15569
David S. Miller9360ffd2012-03-29 04:41:26 -040015570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15572 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015573 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15574 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015575 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
15576 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
15577 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015578 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015579
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015580 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015581
Johannes Berg68eb5502013-11-19 15:19:38 +010015582 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015583 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015584 return;
15585
15586 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010015587 nlmsg_free(msg);
15588}
15589EXPORT_SYMBOL(cfg80211_probe_status);
15590
Johannes Berg5e760232011-11-04 11:18:17 +010015591void cfg80211_report_obss_beacon(struct wiphy *wiphy,
15592 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070015593 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010015594{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015595 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010015596 struct sk_buff *msg;
15597 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070015598 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010015599
Beni Lev4ee3e062012-08-27 12:49:39 +030015600 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
15601
Ben Greear37c73b52012-10-26 14:49:25 -070015602 spin_lock_bh(&rdev->beacon_registrations_lock);
15603 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
15604 msg = nlmsg_new(len + 100, GFP_ATOMIC);
15605 if (!msg) {
15606 spin_unlock_bh(&rdev->beacon_registrations_lock);
15607 return;
15608 }
Johannes Berg5e760232011-11-04 11:18:17 +010015609
Ben Greear37c73b52012-10-26 14:49:25 -070015610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15611 if (!hdr)
15612 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010015613
Ben Greear37c73b52012-10-26 14:49:25 -070015614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15615 (freq &&
15616 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
15617 (sig_dbm &&
15618 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15619 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
15620 goto nla_put_failure;
15621
15622 genlmsg_end(msg, hdr);
15623
15624 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010015625 }
Ben Greear37c73b52012-10-26 14:49:25 -070015626 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015627 return;
15628
15629 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070015630 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015631 nlmsg_free(msg);
15632}
15633EXPORT_SYMBOL(cfg80211_report_obss_beacon);
15634
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015635#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015636static int cfg80211_net_detect_results(struct sk_buff *msg,
15637 struct cfg80211_wowlan_wakeup *wakeup)
15638{
15639 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
15640 struct nlattr *nl_results, *nl_match, *nl_freqs;
15641 int i, j;
15642
15643 nl_results = nla_nest_start(
15644 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15645 if (!nl_results)
15646 return -EMSGSIZE;
15647
15648 for (i = 0; i < nd->n_matches; i++) {
15649 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15650
15651 nl_match = nla_nest_start(msg, i);
15652 if (!nl_match)
15653 break;
15654
15655 /* The SSID attribute is optional in nl80211, but for
15656 * simplicity reasons it's always present in the
15657 * cfg80211 structure. If a driver can't pass the
15658 * SSID, that needs to be changed. A zero length SSID
15659 * is still a valid SSID (wildcard), so it cannot be
15660 * used for this purpose.
15661 */
15662 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
15663 match->ssid.ssid)) {
15664 nla_nest_cancel(msg, nl_match);
15665 goto out;
15666 }
15667
15668 if (match->n_channels) {
15669 nl_freqs = nla_nest_start(
15670 msg, NL80211_ATTR_SCAN_FREQUENCIES);
15671 if (!nl_freqs) {
15672 nla_nest_cancel(msg, nl_match);
15673 goto out;
15674 }
15675
15676 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020015677 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015678 nla_nest_cancel(msg, nl_freqs);
15679 nla_nest_cancel(msg, nl_match);
15680 goto out;
15681 }
15682 }
15683
15684 nla_nest_end(msg, nl_freqs);
15685 }
15686
15687 nla_nest_end(msg, nl_match);
15688 }
15689
15690out:
15691 nla_nest_end(msg, nl_results);
15692 return 0;
15693}
15694
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015695void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15696 struct cfg80211_wowlan_wakeup *wakeup,
15697 gfp_t gfp)
15698{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015699 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015700 struct sk_buff *msg;
15701 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015702 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015703
15704 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15705
15706 if (wakeup)
15707 size += wakeup->packet_present_len;
15708
15709 msg = nlmsg_new(size, gfp);
15710 if (!msg)
15711 return;
15712
15713 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15714 if (!hdr)
15715 goto free_msg;
15716
15717 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015718 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15719 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015720 goto free_msg;
15721
15722 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15723 wdev->netdev->ifindex))
15724 goto free_msg;
15725
15726 if (wakeup) {
15727 struct nlattr *reasons;
15728
15729 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015730 if (!reasons)
15731 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015732
15733 if (wakeup->disconnect &&
15734 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15735 goto free_msg;
15736 if (wakeup->magic_pkt &&
15737 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15738 goto free_msg;
15739 if (wakeup->gtk_rekey_failure &&
15740 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15741 goto free_msg;
15742 if (wakeup->eap_identity_req &&
15743 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15744 goto free_msg;
15745 if (wakeup->four_way_handshake &&
15746 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15747 goto free_msg;
15748 if (wakeup->rfkill_release &&
15749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15750 goto free_msg;
15751
15752 if (wakeup->pattern_idx >= 0 &&
15753 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15754 wakeup->pattern_idx))
15755 goto free_msg;
15756
Johannes Bergae917c92013-10-25 11:05:22 +020015757 if (wakeup->tcp_match &&
15758 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15759 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015760
Johannes Bergae917c92013-10-25 11:05:22 +020015761 if (wakeup->tcp_connlost &&
15762 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15763 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015764
Johannes Bergae917c92013-10-25 11:05:22 +020015765 if (wakeup->tcp_nomoretokens &&
15766 nla_put_flag(msg,
15767 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15768 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015769
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015770 if (wakeup->packet) {
15771 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15772 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15773
15774 if (!wakeup->packet_80211) {
15775 pkt_attr =
15776 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15777 len_attr =
15778 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15779 }
15780
15781 if (wakeup->packet_len &&
15782 nla_put_u32(msg, len_attr, wakeup->packet_len))
15783 goto free_msg;
15784
15785 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15786 wakeup->packet))
15787 goto free_msg;
15788 }
15789
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015790 if (wakeup->net_detect &&
15791 cfg80211_net_detect_results(msg, wakeup))
15792 goto free_msg;
15793
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015794 nla_nest_end(msg, reasons);
15795 }
15796
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015797 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015798
Johannes Berg68eb5502013-11-19 15:19:38 +010015799 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015800 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015801 return;
15802
15803 free_msg:
15804 nlmsg_free(msg);
15805}
15806EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15807#endif
15808
Jouni Malinen3475b092012-11-16 22:49:57 +020015809void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15810 enum nl80211_tdls_operation oper,
15811 u16 reason_code, gfp_t gfp)
15812{
15813 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015814 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015815 struct sk_buff *msg;
15816 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015817
15818 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15819 reason_code);
15820
15821 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15822 if (!msg)
15823 return;
15824
15825 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15826 if (!hdr) {
15827 nlmsg_free(msg);
15828 return;
15829 }
15830
15831 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15832 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15833 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15834 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15835 (reason_code > 0 &&
15836 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15837 goto nla_put_failure;
15838
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015839 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015840
Johannes Berg68eb5502013-11-19 15:19:38 +010015841 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015842 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015843 return;
15844
15845 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020015846 nlmsg_free(msg);
15847}
15848EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15849
Jouni Malinen026331c2010-02-15 12:53:10 +020015850static int nl80211_netlink_notify(struct notifier_block * nb,
15851 unsigned long state,
15852 void *_notify)
15853{
15854 struct netlink_notify *notify = _notify;
15855 struct cfg80211_registered_device *rdev;
15856 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015857 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015858
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015859 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015860 return NOTIFY_DONE;
15861
15862 rcu_read_lock();
15863
Johannes Berg5e760232011-11-04 11:18:17 +010015864 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015865 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015866
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015867 list_for_each_entry_rcu(sched_scan_req,
15868 &rdev->sched_scan_req_list,
15869 list) {
15870 if (sched_scan_req->owner_nlportid == notify->portid) {
15871 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015872 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015873 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015874 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015875
Johannes Berg53873f12016-05-03 16:52:04 +030015876 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015877 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015878
Johannes Bergab810072017-04-26 07:43:41 +020015879 if (wdev->owner_nlportid == notify->portid) {
15880 wdev->nl_owner_dead = true;
15881 schedule_work(&rdev->destroy_work);
15882 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015883 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015884 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015885 }
15886
Ben Greear37c73b52012-10-26 14:49:25 -070015887 spin_lock_bh(&rdev->beacon_registrations_lock);
15888 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15889 list) {
15890 if (reg->nlportid == notify->portid) {
15891 list_del(&reg->list);
15892 kfree(reg);
15893 break;
15894 }
15895 }
15896 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015897 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015898
15899 rcu_read_unlock();
15900
Ilan peer05050752015-03-04 00:32:06 -050015901 /*
15902 * It is possible that the user space process that is controlling the
15903 * indoor setting disappeared, so notify the regulatory core.
15904 */
15905 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015906 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015907}
15908
15909static struct notifier_block nl80211_netlink_notifier = {
15910 .notifier_call = nl80211_netlink_notify,
15911};
15912
Jouni Malinen355199e2013-02-27 17:14:27 +020015913void cfg80211_ft_event(struct net_device *netdev,
15914 struct cfg80211_ft_event_params *ft_event)
15915{
15916 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015917 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015918 struct sk_buff *msg;
15919 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015920
15921 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15922
15923 if (!ft_event->target_ap)
15924 return;
15925
Dedy Lansky1039d082018-05-17 16:25:03 +030015926 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
15927 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015928 if (!msg)
15929 return;
15930
15931 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015932 if (!hdr)
15933 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015934
Johannes Bergae917c92013-10-25 11:05:22 +020015935 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15936 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15937 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15938 goto out;
15939
15940 if (ft_event->ies &&
15941 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15942 goto out;
15943 if (ft_event->ric_ies &&
15944 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15945 ft_event->ric_ies))
15946 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015947
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015948 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015949
Johannes Berg68eb5502013-11-19 15:19:38 +010015950 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015951 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015952 return;
15953 out:
15954 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015955}
15956EXPORT_SYMBOL(cfg80211_ft_event);
15957
Arend van Spriel5de17982013-04-18 15:49:00 +020015958void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15959{
15960 struct cfg80211_registered_device *rdev;
15961 struct sk_buff *msg;
15962 void *hdr;
15963 u32 nlportid;
15964
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015965 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015966 if (!rdev->crit_proto_nlportid)
15967 return;
15968
15969 nlportid = rdev->crit_proto_nlportid;
15970 rdev->crit_proto_nlportid = 0;
15971
15972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15973 if (!msg)
15974 return;
15975
15976 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15977 if (!hdr)
15978 goto nla_put_failure;
15979
15980 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015981 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15982 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015983 goto nla_put_failure;
15984
15985 genlmsg_end(msg, hdr);
15986
15987 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15988 return;
15989
15990 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020015991 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015992}
15993EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15994
Johannes Berg348baf02014-01-24 14:06:29 +010015995void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15996{
15997 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015998 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015999 struct sk_buff *msg;
16000 void *hdr;
16001
16002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16003 if (!msg)
16004 return;
16005
16006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16007 if (!hdr)
16008 goto out;
16009
16010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16011 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016012 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16013 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010016014 goto out;
16015
16016 genlmsg_end(msg, hdr);
16017
16018 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16019 NL80211_MCGRP_MLME, GFP_KERNEL);
16020 return;
16021 out:
16022 nlmsg_free(msg);
16023}
16024
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020016025int cfg80211_external_auth_request(struct net_device *dev,
16026 struct cfg80211_external_auth_params *params,
16027 gfp_t gfp)
16028{
16029 struct wireless_dev *wdev = dev->ieee80211_ptr;
16030 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16031 struct sk_buff *msg;
16032 void *hdr;
16033
16034 if (!wdev->conn_owner_nlportid)
16035 return -EINVAL;
16036
16037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16038 if (!msg)
16039 return -ENOMEM;
16040
16041 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16042 if (!hdr)
16043 goto nla_put_failure;
16044
16045 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16046 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16047 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16048 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16049 params->action) ||
16050 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16051 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16052 params->ssid.ssid))
16053 goto nla_put_failure;
16054
16055 genlmsg_end(msg, hdr);
16056 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16057 wdev->conn_owner_nlportid);
16058 return 0;
16059
16060 nla_put_failure:
16061 nlmsg_free(msg);
16062 return -ENOBUFS;
16063}
16064EXPORT_SYMBOL(cfg80211_external_auth_request);
16065
Johannes Berg55682962007-09-20 13:09:35 -040016066/* initialisation/exit functions */
16067
Johannes Berg56989f62016-10-24 14:40:05 +020016068int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040016069{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000016070 int err;
Johannes Berg55682962007-09-20 13:09:35 -040016071
Johannes Berg489111e2016-10-24 14:40:03 +020016072 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040016073 if (err)
16074 return err;
16075
Jouni Malinen026331c2010-02-15 12:53:10 +020016076 err = netlink_register_notifier(&nl80211_netlink_notifier);
16077 if (err)
16078 goto err_out;
16079
Johannes Berg55682962007-09-20 13:09:35 -040016080 return 0;
16081 err_out:
16082 genl_unregister_family(&nl80211_fam);
16083 return err;
16084}
16085
16086void nl80211_exit(void)
16087{
Jouni Malinen026331c2010-02-15 12:53:10 +020016088 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040016089 genl_unregister_family(&nl80211_fam);
16090}