blob: 3ab443b13bb071aff902d3b543274d9cafa51fd9 [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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-06-15 14:09:58 +0200166 else
167 tmp = NULL;
168
Johannes Berg7fee4772012-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 Berg2e161f72010-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400431};
432
Johannes Berge31b8212010-10-05 19:39:30 +0200433/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000434static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200435 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200436 [NL80211_KEY_IDX] = { .type = NLA_U8 },
437 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200438 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200439 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
440 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200441 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100442 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
443};
444
445/* policy for the key default flags */
446static const struct nla_policy
447nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
448 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
449 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200450};
451
Johannes Bergf83ace32016-10-17 08:04:07 +0200452#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200453/* policy for WoWLAN attributes */
454static const struct nla_policy
455nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
456 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
457 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
458 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
459 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200460 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
461 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
462 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
463 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100464 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300465 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100466};
467
468static const struct nla_policy
469nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
470 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
471 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
472 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
473 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
474 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
475 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
476 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
477 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
478 },
479 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
480 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
481 },
482 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
483 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
484 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200485};
Johannes Bergf83ace32016-10-17 08:04:07 +0200486#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200487
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700488/* policy for coalesce rule attributes */
489static const struct nla_policy
490nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
491 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
492 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
493 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
494};
495
Johannes Berge5497d72011-07-05 16:35:40 +0200496/* policy for GTK rekey offload attributes */
497static const struct nla_policy
498nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
499 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
500 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
501 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
502};
503
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300504static const struct nla_policy
505nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200506 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300507 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100508 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700509 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300510};
511
Avraham Stern3b06d272015-10-12 09:51:34 +0300512static const struct nla_policy
513nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
514 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
515 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
516};
517
Arend van Spriel38de03d2016-03-02 20:37:18 +0100518static const struct nla_policy
519nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
520 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
521 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
522 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
523 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
524 },
525};
526
Ayala Bekera442b762016-09-20 17:31:15 +0300527/* policy for NAN function attributes */
528static const struct nla_policy
529nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
530 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300531 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300532 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
533 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
534 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
535 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
536 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
537 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
538 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
539 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
540 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
541 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
542 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
543 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
544 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
545 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
546 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
547 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
548};
549
550/* policy for Service Response Filter attributes */
551static const struct nla_policy
552nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
553 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
554 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
555 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
556 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
557 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
558};
559
Peng Xuad670232017-10-03 23:21:51 +0300560/* policy for packet pattern attributes */
561static const struct nla_policy
562nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
563 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
564 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
565 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
566};
567
Johannes Berg97990a02013-04-19 01:02:55 +0200568static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
569 struct netlink_callback *cb,
570 struct cfg80211_registered_device **rdev,
571 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100572{
Johannes Berg67748892010-10-04 21:14:06 +0200573 int err;
574
Johannes Berg97990a02013-04-19 01:02:55 +0200575 if (!cb->args[0]) {
576 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200577 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200578 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200579 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100580 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200581
Johannes Bergc90c39d2016-10-24 14:40:01 +0200582 *wdev = __cfg80211_wdev_from_attrs(
583 sock_net(skb->sk),
584 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100585 if (IS_ERR(*wdev))
586 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800587 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200588 /* 0 is the first index - add 1 to parse only once */
589 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200590 cb->args[1] = (*wdev)->identifier;
591 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200592 /* subtract the 1 again here */
593 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200594 struct wireless_dev *tmp;
595
Johannes Bergea90e0d2017-03-15 14:26:04 +0100596 if (!wiphy)
597 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800598 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200599 *wdev = NULL;
600
Johannes Berg53873f12016-05-03 16:52:04 +0300601 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200602 if (tmp->identifier == cb->args[1]) {
603 *wdev = tmp;
604 break;
605 }
606 }
Johannes Berg97990a02013-04-19 01:02:55 +0200607
Johannes Bergea90e0d2017-03-15 14:26:04 +0100608 if (!*wdev)
609 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200610 }
611
Johannes Berg67748892010-10-04 21:14:06 +0200612 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200613}
614
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100615/* IE validation */
616static bool is_valid_ie_attr(const struct nlattr *attr)
617{
618 const u8 *pos;
619 int len;
620
621 if (!attr)
622 return true;
623
624 pos = nla_data(attr);
625 len = nla_len(attr);
626
627 while (len) {
628 u8 elemlen;
629
630 if (len < 2)
631 return false;
632 len -= 2;
633
634 elemlen = pos[1];
635 if (elemlen > len)
636 return false;
637
638 len -= elemlen;
639 pos += 2 + elemlen;
640 }
641
642 return true;
643}
644
Johannes Berg55682962007-09-20 13:09:35 -0400645/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000646static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400647 int flags, u8 cmd)
648{
649 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000650 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400651}
652
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300653static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
654 const struct ieee80211_reg_rule *rule)
655{
656 int j;
657 struct nlattr *nl_wmm_rules =
658 nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM);
659
660 if (!nl_wmm_rules)
661 goto nla_put_failure;
662
663 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
664 struct nlattr *nl_wmm_rule = nla_nest_start(msg, j);
665
666 if (!nl_wmm_rule)
667 goto nla_put_failure;
668
669 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
670 rule->wmm_rule->client[j].cw_min) ||
671 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
672 rule->wmm_rule->client[j].cw_max) ||
673 nla_put_u8(msg, NL80211_WMMR_AIFSN,
674 rule->wmm_rule->client[j].aifsn) ||
675 nla_put_u8(msg, NL80211_WMMR_TXOP,
676 rule->wmm_rule->client[j].cot))
677 goto nla_put_failure;
678
679 nla_nest_end(msg, nl_wmm_rule);
680 }
681 nla_nest_end(msg, nl_wmm_rules);
682
683 return 0;
684
685nla_put_failure:
686 return -ENOBUFS;
687}
688
689static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100690 struct ieee80211_channel *chan,
691 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400692{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200693 /* Some channels must be completely excluded from the
694 * list to protect old user-space tools from breaking
695 */
696 if (!large && chan->flags &
697 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
698 return 0;
699
David S. Miller9360ffd2012-03-29 04:41:26 -0400700 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
701 chan->center_freq))
702 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400703
David S. Miller9360ffd2012-03-29 04:41:26 -0400704 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
705 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
706 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200707 if (chan->flags & IEEE80211_CHAN_NO_IR) {
708 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
709 goto nla_put_failure;
710 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
711 goto nla_put_failure;
712 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100713 if (chan->flags & IEEE80211_CHAN_RADAR) {
714 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
715 goto nla_put_failure;
716 if (large) {
717 u32 time;
718
719 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
720
721 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
722 chan->dfs_state))
723 goto nla_put_failure;
724 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
725 time))
726 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100727 if (nla_put_u32(msg,
728 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
729 chan->dfs_cac_ms))
730 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100731 }
732 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400733
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100734 if (large) {
735 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
736 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
737 goto nla_put_failure;
738 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
739 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
740 goto nla_put_failure;
741 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
742 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
743 goto nla_put_failure;
744 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
745 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
746 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200747 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
748 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
749 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300750 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
751 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200752 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200753 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
754 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
755 goto nla_put_failure;
756 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
757 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
758 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100759 }
760
David S. Miller9360ffd2012-03-29 04:41:26 -0400761 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
762 DBM_TO_MBM(chan->max_power)))
763 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400764
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300765 if (large) {
766 const struct ieee80211_reg_rule *rule =
767 freq_reg_info(wiphy, chan->center_freq);
768
769 if (!IS_ERR(rule) && rule->wmm_rule) {
770 if (nl80211_msg_put_wmm_rules(msg, rule))
771 goto nla_put_failure;
772 }
773 }
774
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400775 return 0;
776
777 nla_put_failure:
778 return -ENOBUFS;
779}
780
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200781static bool nl80211_put_txq_stats(struct sk_buff *msg,
782 struct cfg80211_txq_stats *txqstats,
783 int attrtype)
784{
785 struct nlattr *txqattr;
786
787#define PUT_TXQVAL_U32(attr, memb) do { \
788 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
789 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
790 return false; \
791 } while (0)
792
793 txqattr = nla_nest_start(msg, attrtype);
794 if (!txqattr)
795 return false;
796
797 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
798 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
799 PUT_TXQVAL_U32(FLOWS, flows);
800 PUT_TXQVAL_U32(DROPS, drops);
801 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
802 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
803 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
804 PUT_TXQVAL_U32(COLLISIONS, collisions);
805 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
806 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
807 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
808 nla_nest_end(msg, txqattr);
809
810#undef PUT_TXQVAL_U32
811 return true;
812}
813
Johannes Berg55682962007-09-20 13:09:35 -0400814/* netlink command implementations */
815
Johannes Bergb9454e82009-07-08 13:29:08 +0200816struct key_parse {
817 struct key_params p;
818 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200819 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200820 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100821 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200822};
823
Johannes Berg768075e2017-11-13 15:35:06 +0100824static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
825 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200826{
827 struct nlattr *tb[NL80211_KEY_MAX + 1];
828 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Berg768075e2017-11-13 15:35:06 +0100829 nl80211_key_policy, info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200830 if (err)
831 return err;
832
833 k->def = !!tb[NL80211_KEY_DEFAULT];
834 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
835
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100836 if (k->def) {
837 k->def_uni = true;
838 k->def_multi = true;
839 }
840 if (k->defmgmt)
841 k->def_multi = true;
842
Johannes Bergb9454e82009-07-08 13:29:08 +0200843 if (tb[NL80211_KEY_IDX])
844 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
845
846 if (tb[NL80211_KEY_DATA]) {
847 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
848 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
849 }
850
851 if (tb[NL80211_KEY_SEQ]) {
852 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
853 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
854 }
855
856 if (tb[NL80211_KEY_CIPHER])
857 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
858
Johannes Berge31b8212010-10-05 19:39:30 +0200859 if (tb[NL80211_KEY_TYPE]) {
860 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
861 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
Johannes Berg768075e2017-11-13 15:35:06 +0100862 return genl_err_attr(info, -EINVAL,
863 tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +0200864 }
865
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100866 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
867 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700868
Johannes Berg2da8f412012-01-20 13:52:37 +0100869 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
870 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Berg768075e2017-11-13 15:35:06 +0100871 nl80211_key_default_policy,
872 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100873 if (err)
874 return err;
875
876 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
877 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
878 }
879
Johannes Bergb9454e82009-07-08 13:29:08 +0200880 return 0;
881}
882
883static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
884{
885 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
886 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
887 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
888 }
889
890 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
891 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
892 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
893 }
894
895 if (info->attrs[NL80211_ATTR_KEY_IDX])
896 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
897
898 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
899 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
900
901 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
902 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
903
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100904 if (k->def) {
905 k->def_uni = true;
906 k->def_multi = true;
907 }
908 if (k->defmgmt)
909 k->def_multi = true;
910
Johannes Berge31b8212010-10-05 19:39:30 +0200911 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
912 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berg768075e2017-11-13 15:35:06 +0100913 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) {
914 GENL_SET_ERR_MSG(info, "key type out of range");
Johannes Berge31b8212010-10-05 19:39:30 +0200915 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100916 }
Johannes Berge31b8212010-10-05 19:39:30 +0200917 }
918
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100919 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
920 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200921 int err = nla_parse_nested(kdt,
922 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
923 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200924 nl80211_key_default_policy,
925 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100926 if (err)
927 return err;
928
929 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
930 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
931 }
932
Johannes Bergb9454e82009-07-08 13:29:08 +0200933 return 0;
934}
935
936static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
937{
938 int err;
939
940 memset(k, 0, sizeof(*k));
941 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200942 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200943
944 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +0100945 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +0200946 else
947 err = nl80211_parse_key_old(info, k);
948
949 if (err)
950 return err;
951
Johannes Berg768075e2017-11-13 15:35:06 +0100952 if (k->def && k->defmgmt) {
953 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +0200954 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100955 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200956
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100957 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100958 if (k->def_uni || !k->def_multi) {
959 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100960 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100961 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100962 }
963
Johannes Bergb9454e82009-07-08 13:29:08 +0200964 if (k->idx != -1) {
965 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100966 if (k->idx < 4 || k->idx > 5) {
967 GENL_SET_ERR_MSG(info,
968 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200969 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100970 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200971 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +0100972 if (k->idx < 0 || k->idx > 3) {
973 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +0200974 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100975 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200976 } else {
Johannes Berg768075e2017-11-13 15:35:06 +0100977 if (k->idx < 0 || k->idx > 5) {
978 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200979 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100980 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200981 }
982 }
983
984 return 0;
985}
986
Johannes Bergfffd0932009-07-08 14:22:54 +0200987static struct cfg80211_cached_keys *
988nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +0100989 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200990{
Johannes Berg768075e2017-11-13 15:35:06 +0100991 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +0200992 struct key_parse parse;
993 struct nlattr *key;
994 struct cfg80211_cached_keys *result;
995 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200996 bool have_key = false;
997
998 nla_for_each_nested(key, keys, rem) {
999 have_key = true;
1000 break;
1001 }
1002
1003 if (!have_key)
1004 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001005
1006 result = kzalloc(sizeof(*result), GFP_KERNEL);
1007 if (!result)
1008 return ERR_PTR(-ENOMEM);
1009
1010 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001011
1012 nla_for_each_nested(key, keys, rem) {
1013 memset(&parse, 0, sizeof(parse));
1014 parse.idx = -1;
1015
Johannes Berg768075e2017-11-13 15:35:06 +01001016 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001017 if (err)
1018 goto error;
1019 err = -EINVAL;
1020 if (!parse.p.key)
1021 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001022 if (parse.idx < 0 || parse.idx > 3) {
1023 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001024 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001025 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001026 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001027 if (def) {
1028 GENL_SET_ERR_MSG(info,
1029 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001030 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001031 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001032 def = 1;
1033 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001034 if (!parse.def_uni || !parse.def_multi)
1035 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001036 } else if (parse.defmgmt)
1037 goto error;
1038 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001039 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001040 if (err)
1041 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001042 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1043 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001044 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001045 err = -EINVAL;
1046 goto error;
1047 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001048 result->params[parse.idx].cipher = parse.p.cipher;
1049 result->params[parse.idx].key_len = parse.p.key_len;
1050 result->params[parse.idx].key = result->data[parse.idx];
1051 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301052
Johannes Berg386b1f22016-09-13 16:10:02 +02001053 /* must be WEP key if we got here */
1054 if (no_ht)
1055 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001056 }
1057
Johannes Bergf1c1f172016-09-13 17:08:23 +02001058 if (result->def < 0) {
1059 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001060 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001061 goto error;
1062 }
1063
Johannes Bergfffd0932009-07-08 14:22:54 +02001064 return result;
1065 error:
1066 kfree(result);
1067 return ERR_PTR(err);
1068}
1069
1070static int nl80211_key_allowed(struct wireless_dev *wdev)
1071{
1072 ASSERT_WDEV_LOCK(wdev);
1073
Johannes Bergfffd0932009-07-08 14:22:54 +02001074 switch (wdev->iftype) {
1075 case NL80211_IFTYPE_AP:
1076 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001077 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001078 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001079 break;
1080 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001081 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001082 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001083 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001084 return -ENOLINK;
1085 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001086 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001087 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001088 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001089 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001090 case NL80211_IFTYPE_P2P_DEVICE:
1091 case NL80211_IFTYPE_WDS:
1092 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001093 return -EINVAL;
1094 }
1095
1096 return 0;
1097}
1098
Jouni Malinen664834d2014-01-15 00:01:44 +02001099static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1100 struct nlattr *tb)
1101{
1102 struct ieee80211_channel *chan;
1103
1104 if (tb == NULL)
1105 return NULL;
1106 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1107 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1108 return NULL;
1109 return chan;
1110}
1111
Johannes Berg7527a782011-05-13 10:58:57 +02001112static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1113{
1114 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1115 int i;
1116
1117 if (!nl_modes)
1118 goto nla_put_failure;
1119
1120 i = 0;
1121 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001122 if ((ifmodes & 1) && nla_put_flag(msg, i))
1123 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001124 ifmodes >>= 1;
1125 i++;
1126 }
1127
1128 nla_nest_end(msg, nl_modes);
1129 return 0;
1130
1131nla_put_failure:
1132 return -ENOBUFS;
1133}
1134
1135static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001136 struct sk_buff *msg,
1137 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001138{
1139 struct nlattr *nl_combis;
1140 int i, j;
1141
1142 nl_combis = nla_nest_start(msg,
1143 NL80211_ATTR_INTERFACE_COMBINATIONS);
1144 if (!nl_combis)
1145 goto nla_put_failure;
1146
1147 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1148 const struct ieee80211_iface_combination *c;
1149 struct nlattr *nl_combi, *nl_limits;
1150
1151 c = &wiphy->iface_combinations[i];
1152
1153 nl_combi = nla_nest_start(msg, i + 1);
1154 if (!nl_combi)
1155 goto nla_put_failure;
1156
1157 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1158 if (!nl_limits)
1159 goto nla_put_failure;
1160
1161 for (j = 0; j < c->n_limits; j++) {
1162 struct nlattr *nl_limit;
1163
1164 nl_limit = nla_nest_start(msg, j + 1);
1165 if (!nl_limit)
1166 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001167 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1168 c->limits[j].max))
1169 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001170 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1171 c->limits[j].types))
1172 goto nla_put_failure;
1173 nla_nest_end(msg, nl_limit);
1174 }
1175
1176 nla_nest_end(msg, nl_limits);
1177
David S. Miller9360ffd2012-03-29 04:41:26 -04001178 if (c->beacon_int_infra_match &&
1179 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1180 goto nla_put_failure;
1181 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1182 c->num_different_channels) ||
1183 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1184 c->max_interfaces))
1185 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001186 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001187 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1188 c->radar_detect_widths) ||
1189 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1190 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001191 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301192 if (c->beacon_int_min_gcd &&
1193 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1194 c->beacon_int_min_gcd))
1195 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001196
1197 nla_nest_end(msg, nl_combi);
1198 }
1199
1200 nla_nest_end(msg, nl_combis);
1201
1202 return 0;
1203nla_put_failure:
1204 return -ENOBUFS;
1205}
1206
Johannes Berg3713b4e2013-02-14 16:19:38 +01001207#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001208static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1209 struct sk_buff *msg)
1210{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001211 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001212 struct nlattr *nl_tcp;
1213
1214 if (!tcp)
1215 return 0;
1216
1217 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1218 if (!nl_tcp)
1219 return -ENOBUFS;
1220
1221 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1222 tcp->data_payload_max))
1223 return -ENOBUFS;
1224
1225 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1226 tcp->data_payload_max))
1227 return -ENOBUFS;
1228
1229 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1230 return -ENOBUFS;
1231
1232 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1233 sizeof(*tcp->tok), tcp->tok))
1234 return -ENOBUFS;
1235
1236 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1237 tcp->data_interval_max))
1238 return -ENOBUFS;
1239
1240 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1241 tcp->wake_payload_max))
1242 return -ENOBUFS;
1243
1244 nla_nest_end(msg, nl_tcp);
1245 return 0;
1246}
1247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001249 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001250 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001251{
1252 struct nlattr *nl_wowlan;
1253
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 return 0;
1256
1257 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1258 if (!nl_wowlan)
1259 return -ENOBUFS;
1260
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001261 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001263 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1277 return -ENOBUFS;
1278
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001280 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1282 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1283 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1284 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 };
1286
1287 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1288 sizeof(pat), &pat))
1289 return -ENOBUFS;
1290 }
1291
Luciano Coelho75453cc2015-01-09 14:06:37 +02001292 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1293 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1294 rdev->wiphy.wowlan->max_nd_match_sets))
1295 return -ENOBUFS;
1296
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001298 return -ENOBUFS;
1299
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_nest_end(msg, nl_wowlan);
1301
1302 return 0;
1303}
1304#endif
1305
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001306static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001308{
1309 struct nl80211_coalesce_rule_support rule;
1310
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001312 return 0;
1313
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1315 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1316 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1317 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1318 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1319 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001320
1321 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1322 return -ENOBUFS;
1323
1324 return 0;
1325}
1326
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1328 struct ieee80211_supported_band *sband)
1329{
1330 struct nlattr *nl_rates, *nl_rate;
1331 struct ieee80211_rate *rate;
1332 int i;
1333
1334 /* add HT info */
1335 if (sband->ht_cap.ht_supported &&
1336 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1337 sizeof(sband->ht_cap.mcs),
1338 &sband->ht_cap.mcs) ||
1339 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1340 sband->ht_cap.cap) ||
1341 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1342 sband->ht_cap.ampdu_factor) ||
1343 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1344 sband->ht_cap.ampdu_density)))
1345 return -ENOBUFS;
1346
1347 /* add VHT info */
1348 if (sband->vht_cap.vht_supported &&
1349 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1350 sizeof(sband->vht_cap.vht_mcs),
1351 &sband->vht_cap.vht_mcs) ||
1352 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1353 sband->vht_cap.cap)))
1354 return -ENOBUFS;
1355
1356 /* add bitrates */
1357 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1358 if (!nl_rates)
1359 return -ENOBUFS;
1360
1361 for (i = 0; i < sband->n_bitrates; i++) {
1362 nl_rate = nla_nest_start(msg, i);
1363 if (!nl_rate)
1364 return -ENOBUFS;
1365
1366 rate = &sband->bitrates[i];
1367 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1368 rate->bitrate))
1369 return -ENOBUFS;
1370 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1371 nla_put_flag(msg,
1372 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1373 return -ENOBUFS;
1374
1375 nla_nest_end(msg, nl_rate);
1376 }
1377
1378 nla_nest_end(msg, nl_rates);
1379
1380 return 0;
1381}
1382
1383static int
1384nl80211_send_mgmt_stypes(struct sk_buff *msg,
1385 const struct ieee80211_txrx_stypes *mgmt_stypes)
1386{
1387 u16 stypes;
1388 struct nlattr *nl_ftypes, *nl_ifs;
1389 enum nl80211_iftype ift;
1390 int i;
1391
1392 if (!mgmt_stypes)
1393 return 0;
1394
1395 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1396 if (!nl_ifs)
1397 return -ENOBUFS;
1398
1399 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1400 nl_ftypes = nla_nest_start(msg, ift);
1401 if (!nl_ftypes)
1402 return -ENOBUFS;
1403 i = 0;
1404 stypes = mgmt_stypes[ift].tx;
1405 while (stypes) {
1406 if ((stypes & 1) &&
1407 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1408 (i << 4) | IEEE80211_FTYPE_MGMT))
1409 return -ENOBUFS;
1410 stypes >>= 1;
1411 i++;
1412 }
1413 nla_nest_end(msg, nl_ftypes);
1414 }
1415
1416 nla_nest_end(msg, nl_ifs);
1417
1418 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1419 if (!nl_ifs)
1420 return -ENOBUFS;
1421
1422 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1423 nl_ftypes = nla_nest_start(msg, ift);
1424 if (!nl_ftypes)
1425 return -ENOBUFS;
1426 i = 0;
1427 stypes = mgmt_stypes[ift].rx;
1428 while (stypes) {
1429 if ((stypes & 1) &&
1430 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1431 (i << 4) | IEEE80211_FTYPE_MGMT))
1432 return -ENOBUFS;
1433 stypes >>= 1;
1434 i++;
1435 }
1436 nla_nest_end(msg, nl_ftypes);
1437 }
1438 nla_nest_end(msg, nl_ifs);
1439
1440 return 0;
1441}
1442
Johannes Berg17948992016-10-26 11:42:04 +02001443#define CMD(op, n) \
1444 do { \
1445 if (rdev->ops->op) { \
1446 i++; \
1447 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1448 goto nla_put_failure; \
1449 } \
1450 } while (0)
1451
1452static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1453 struct sk_buff *msg)
1454{
1455 int i = 0;
1456
1457 /*
1458 * do *NOT* add anything into this function, new things need to be
1459 * advertised only to new versions of userspace that can deal with
1460 * the split (and they can't possibly care about new features...
1461 */
1462 CMD(add_virtual_intf, NEW_INTERFACE);
1463 CMD(change_virtual_intf, SET_INTERFACE);
1464 CMD(add_key, NEW_KEY);
1465 CMD(start_ap, START_AP);
1466 CMD(add_station, NEW_STATION);
1467 CMD(add_mpath, NEW_MPATH);
1468 CMD(update_mesh_config, SET_MESH_CONFIG);
1469 CMD(change_bss, SET_BSS);
1470 CMD(auth, AUTHENTICATE);
1471 CMD(assoc, ASSOCIATE);
1472 CMD(deauth, DEAUTHENTICATE);
1473 CMD(disassoc, DISASSOCIATE);
1474 CMD(join_ibss, JOIN_IBSS);
1475 CMD(join_mesh, JOIN_MESH);
1476 CMD(set_pmksa, SET_PMKSA);
1477 CMD(del_pmksa, DEL_PMKSA);
1478 CMD(flush_pmksa, FLUSH_PMKSA);
1479 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1480 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1481 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1482 CMD(mgmt_tx, FRAME);
1483 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1484 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1485 i++;
1486 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1487 goto nla_put_failure;
1488 }
1489 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1490 rdev->ops->join_mesh) {
1491 i++;
1492 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1493 goto nla_put_failure;
1494 }
1495 CMD(set_wds_peer, SET_WDS_PEER);
1496 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1497 CMD(tdls_mgmt, TDLS_MGMT);
1498 CMD(tdls_oper, TDLS_OPER);
1499 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001500 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001501 CMD(sched_scan_start, START_SCHED_SCAN);
1502 CMD(probe_client, PROBE_CLIENT);
1503 CMD(set_noack_map, SET_NOACK_MAP);
1504 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1505 i++;
1506 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1507 goto nla_put_failure;
1508 }
1509 CMD(start_p2p_device, START_P2P_DEVICE);
1510 CMD(set_mcast_rate, SET_MCAST_RATE);
1511#ifdef CONFIG_NL80211_TESTMODE
1512 CMD(testmode_cmd, TESTMODE);
1513#endif
1514
1515 if (rdev->ops->connect || rdev->ops->auth) {
1516 i++;
1517 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1518 goto nla_put_failure;
1519 }
1520
1521 if (rdev->ops->disconnect || rdev->ops->deauth) {
1522 i++;
1523 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1524 goto nla_put_failure;
1525 }
1526
1527 return i;
1528 nla_put_failure:
1529 return -ENOBUFS;
1530}
1531
Johannes Berg86e8cf92013-06-19 10:57:22 +02001532struct nl80211_dump_wiphy_state {
1533 s64 filter_wiphy;
1534 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301535 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 bool split;
1537};
1538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001539static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001540 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001542 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001543{
1544 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001545 struct nlattr *nl_bands, *nl_band;
1546 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001547 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001548 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001549 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001550 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001551 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001553 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001554
Johannes Berg3bb20552014-05-26 13:52:25 +02001555 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001556 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 return -ENOBUFS;
1558
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 if (WARN_ON(!state))
1560 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001561
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001565 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001567 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001568
Johannes Berg3bb20552014-05-26 13:52:25 +02001569 if (cmd != NL80211_CMD_NEW_WIPHY)
1570 goto finish;
1571
Johannes Berg86e8cf92013-06-19 10:57:22 +02001572 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 case 0:
1574 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001583 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001593 rdev->wiphy.max_match_sets) ||
1594 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1595 rdev->wiphy.max_sched_scan_plans) ||
1596 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1597 rdev->wiphy.max_sched_scan_plan_interval) ||
1598 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1599 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001600 goto nla_put_failure;
1601
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1604 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001606 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1607 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001608 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1610 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1613 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1616 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001617 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001619 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001620 state->split_start++;
1621 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 break;
1623 case 1:
1624 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1626 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001627 goto nla_put_failure;
1628
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001631 goto nla_put_failure;
1632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1635 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001636
Johannes Berg3713b4e2013-02-14 16:19:38 +01001637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001642
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001644 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001647
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 if ((rdev->wiphy.available_antennas_tx ||
1649 rdev->wiphy.available_antennas_rx) &&
1650 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001651 u32 tx_ant = 0, rx_ant = 0;
1652 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001653
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001655 if (!res) {
1656 if (nla_put_u32(msg,
1657 NL80211_ATTR_WIPHY_ANTENNA_TX,
1658 tx_ant) ||
1659 nla_put_u32(msg,
1660 NL80211_ATTR_WIPHY_ANTENNA_RX,
1661 rx_ant))
1662 goto nla_put_failure;
1663 }
Johannes Bergee688b002008-01-24 19:38:39 +01001664 }
1665
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
1667 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 break;
1669 case 2:
1670 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001673 state->split_start++;
1674 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675 break;
1676 case 3:
1677 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1678 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001679 goto nla_put_failure;
1680
Johannes Berg86e8cf92013-06-19 10:57:22 +02001681 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001682 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683 struct ieee80211_supported_band *sband;
1684
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001685 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686
1687 if (!sband)
1688 continue;
1689
1690 nl_band = nla_nest_start(msg, band);
1691 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001692 goto nla_put_failure;
1693
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 case 0:
1696 if (nl80211_send_band_rateinfo(msg, sband))
1697 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698 state->chan_start++;
1699 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001700 break;
1701 default:
1702 /* add frequencies */
1703 nl_freqs = nla_nest_start(
1704 msg, NL80211_BAND_ATTR_FREQS);
1705 if (!nl_freqs)
1706 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001707
Johannes Berg86e8cf92013-06-19 10:57:22 +02001708 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 i < sband->n_channels;
1710 i++) {
1711 nl_freq = nla_nest_start(msg, i);
1712 if (!nl_freq)
1713 goto nla_put_failure;
1714
1715 chan = &sband->channels[i];
1716
Johannes Berg86e8cf92013-06-19 10:57:22 +02001717 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001718 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 goto nla_put_failure;
1721
1722 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001724 break;
1725 }
1726 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001730 nla_nest_end(msg, nl_freqs);
1731 }
1732
1733 nla_nest_end(msg, nl_band);
1734
Johannes Berg86e8cf92013-06-19 10:57:22 +02001735 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001736 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001737 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001738 band--;
1739 break;
1740 }
Johannes Bergee688b002008-01-24 19:38:39 +01001741 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001742 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001743
Johannes Berg57fbcce2016-04-12 15:56:15 +02001744 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001745 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001746 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001748
Johannes Berg3713b4e2013-02-14 16:19:38 +01001749 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001750 if (state->band_start == 0 && state->chan_start == 0)
1751 state->split_start++;
1752 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 break;
1754 case 4:
1755 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1756 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001757 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001758
Johannes Berg17948992016-10-26 11:42:04 +02001759 i = nl80211_add_commands_unsplit(rdev, msg);
1760 if (i < 0)
1761 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001763 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1764 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001765 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001766 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001767 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001768 if (rdev->wiphy.features &
1769 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001770 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001771 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001772 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001773 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001774#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001775
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001777 state->split_start++;
1778 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 break;
1780 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001781 if (rdev->ops->remain_on_channel &&
1782 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001783 nla_put_u32(msg,
1784 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001785 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001786 goto nla_put_failure;
1787
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001788 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1790 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001791
Johannes Berg3713b4e2013-02-14 16:19:38 +01001792 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1793 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 state->split_start++;
1795 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001796 break;
1797 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001798#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001799 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001800 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001801 state->split_start++;
1802 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001803 break;
1804#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001805 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001806#endif
1807 case 7:
1808 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001809 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001810 goto nla_put_failure;
1811
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001812 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001815
Johannes Berg86e8cf92013-06-19 10:57:22 +02001816 state->split_start++;
1817 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001818 break;
1819 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001820 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001821 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001822 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 goto nla_put_failure;
1824
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001825 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001826 /*
1827 * We can only add the per-channel limit information if the
1828 * dump is split, otherwise it makes it too big. Therefore
1829 * only advertise it in that case.
1830 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001831 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001832 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1833 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001834 goto nla_put_failure;
1835
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001836 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001837 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001838 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1839 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001840 goto nla_put_failure;
1841
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001842 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1843 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001844 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001845 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001846 goto nla_put_failure;
1847
1848 /*
1849 * Any information below this point is only available to
1850 * applications that can deal with it being split. This
1851 * helps ensure that newly added capabilities don't break
1852 * older tools by overrunning their buffers.
1853 *
1854 * We still increment split_start so that in the split
1855 * case we'll continue with more data in the next round,
1856 * but break unconditionally so unsplit data stops here.
1857 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001859 break;
1860 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001861 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001862 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 rdev->wiphy.extended_capabilities_len,
1864 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001865 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001866 rdev->wiphy.extended_capabilities_len,
1867 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001868 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001870 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001871 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001872 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1873 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001874 goto nla_put_failure;
1875
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001876 state->split_start++;
1877 break;
1878 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001879 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001880 goto nla_put_failure;
1881
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001882 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001883 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1884 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1885 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001886
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001887 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001888 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001889 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001890 goto nla_put_failure;
1891
Johannes Bergad7e7182013-11-13 13:37:47 +01001892 state->split_start++;
1893 break;
1894 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001895 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001896 const struct nl80211_vendor_cmd_info *info;
1897 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001898
Johannes Berg567ffc32013-12-18 14:43:31 +01001899 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1900 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001901 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001902
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001903 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1904 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001905 if (nla_put(msg, i + 1, sizeof(*info), info))
1906 goto nla_put_failure;
1907 }
1908 nla_nest_end(msg, nested);
1909 }
1910
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001911 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001912 const struct nl80211_vendor_cmd_info *info;
1913 struct nlattr *nested;
1914
1915 nested = nla_nest_start(msg,
1916 NL80211_ATTR_VENDOR_EVENTS);
1917 if (!nested)
1918 goto nla_put_failure;
1919
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001920 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1921 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001922 if (nla_put(msg, i + 1, sizeof(*info), info))
1923 goto nla_put_failure;
1924 }
1925 nla_nest_end(msg, nested);
1926 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001927 state->split_start++;
1928 break;
1929 case 12:
1930 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1931 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1932 rdev->wiphy.max_num_csa_counters))
1933 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001934
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001935 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1936 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1937 goto nla_put_failure;
1938
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001939 if (rdev->wiphy.max_sched_scan_reqs &&
1940 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1941 rdev->wiphy.max_sched_scan_reqs))
1942 goto nla_put_failure;
1943
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001944 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1945 sizeof(rdev->wiphy.ext_features),
1946 rdev->wiphy.ext_features))
1947 goto nla_put_failure;
1948
Arend van Spriel38de03d2016-03-02 20:37:18 +01001949 if (rdev->wiphy.bss_select_support) {
1950 struct nlattr *nested;
1951 u32 bss_select_support = rdev->wiphy.bss_select_support;
1952
1953 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1954 if (!nested)
1955 goto nla_put_failure;
1956
1957 i = 0;
1958 while (bss_select_support) {
1959 if ((bss_select_support & 1) &&
1960 nla_put_flag(msg, i))
1961 goto nla_put_failure;
1962 i++;
1963 bss_select_support >>= 1;
1964 }
1965 nla_nest_end(msg, nested);
1966 }
1967
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301968 state->split_start++;
1969 break;
1970 case 13:
1971 if (rdev->wiphy.num_iftype_ext_capab &&
1972 rdev->wiphy.iftype_ext_capab) {
1973 struct nlattr *nested_ext_capab, *nested;
1974
1975 nested = nla_nest_start(msg,
1976 NL80211_ATTR_IFTYPE_EXT_CAPA);
1977 if (!nested)
1978 goto nla_put_failure;
1979
1980 for (i = state->capa_start;
1981 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1982 const struct wiphy_iftype_ext_capab *capab;
1983
1984 capab = &rdev->wiphy.iftype_ext_capab[i];
1985
1986 nested_ext_capab = nla_nest_start(msg, i);
1987 if (!nested_ext_capab ||
1988 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1989 capab->iftype) ||
1990 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1991 capab->extended_capabilities_len,
1992 capab->extended_capabilities) ||
1993 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1994 capab->extended_capabilities_len,
1995 capab->extended_capabilities_mask))
1996 goto nla_put_failure;
1997
1998 nla_nest_end(msg, nested_ext_capab);
1999 if (state->split)
2000 break;
2001 }
2002 nla_nest_end(msg, nested);
2003 if (i < rdev->wiphy.num_iftype_ext_capab) {
2004 state->capa_start = i + 1;
2005 break;
2006 }
2007 }
2008
Luca Coelho85859892017-02-08 15:00:34 +02002009 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2010 rdev->wiphy.nan_supported_bands))
2011 goto nla_put_failure;
2012
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002013 if (wiphy_ext_feature_isset(&rdev->wiphy,
2014 NL80211_EXT_FEATURE_TXQS)) {
2015 struct cfg80211_txq_stats txqstats = {};
2016 int res;
2017
2018 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2019 if (!res &&
2020 !nl80211_put_txq_stats(msg, &txqstats,
2021 NL80211_ATTR_TXQ_STATS))
2022 goto nla_put_failure;
2023
2024 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2025 rdev->wiphy.txq_limit))
2026 goto nla_put_failure;
2027 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2028 rdev->wiphy.txq_memory_limit))
2029 goto nla_put_failure;
2030 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2031 rdev->wiphy.txq_quantum))
2032 goto nla_put_failure;
2033 }
2034
Johannes Berg3713b4e2013-02-14 16:19:38 +01002035 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002036 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002037 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002038 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002039 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002040 genlmsg_end(msg, hdr);
2041 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002042
2043 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002044 genlmsg_cancel(msg, hdr);
2045 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002046}
2047
Johannes Berg86e8cf92013-06-19 10:57:22 +02002048static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2049 struct netlink_callback *cb,
2050 struct nl80211_dump_wiphy_state *state)
2051{
Johannes Bergc90c39d2016-10-24 14:40:01 +02002052 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02002053 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
2054 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002055 /* ignore parse errors for backward compatibility */
2056 if (ret)
2057 return 0;
2058
2059 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2060 if (tb[NL80211_ATTR_WIPHY])
2061 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2062 if (tb[NL80211_ATTR_WDEV])
2063 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2064 if (tb[NL80211_ATTR_IFINDEX]) {
2065 struct net_device *netdev;
2066 struct cfg80211_registered_device *rdev;
2067 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2068
Ying Xue7f2b8562014-01-15 10:23:45 +08002069 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002070 if (!netdev)
2071 return -ENODEV;
2072 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002073 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002074 netdev->ieee80211_ptr->wiphy);
2075 state->filter_wiphy = rdev->wiphy_idx;
2076 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002077 }
2078
2079 return 0;
2080}
2081
Johannes Berg55682962007-09-20 13:09:35 -04002082static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2083{
Johannes Berg645e77d2013-03-01 14:03:49 +01002084 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002085 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002086 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002087
Johannes Berg5fe231e2013-05-08 21:45:15 +02002088 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002089 if (!state) {
2090 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002091 if (!state) {
2092 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002093 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002094 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002095 state->filter_wiphy = -1;
2096 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2097 if (ret) {
2098 kfree(state);
2099 rtnl_unlock();
2100 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002101 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002102 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002103 }
2104
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002105 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2106 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002107 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002108 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002109 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002110 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002111 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002112 continue;
2113 /* attempt to fit multiple wiphy data chunks into the skb */
2114 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002115 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2116 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002117 NETLINK_CB(cb->skb).portid,
2118 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002119 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002120 if (ret < 0) {
2121 /*
2122 * If sending the wiphy data didn't fit (ENOBUFS
2123 * or EMSGSIZE returned), this SKB is still
2124 * empty (so it's not too big because another
2125 * wiphy dataset is already in the skb) and
2126 * we've not tried to adjust the dump allocation
2127 * yet ... then adjust the alloc size to be
2128 * bigger, and return 1 but with the empty skb.
2129 * This results in an empty message being RX'ed
2130 * in userspace, but that is ignored.
2131 *
2132 * We can then retry with the larger buffer.
2133 */
2134 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002135 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002136 cb->min_dump_alloc < 4096) {
2137 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002138 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002139 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002140 return 1;
2141 }
2142 idx--;
2143 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002144 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002145 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002146 break;
Johannes Berg55682962007-09-20 13:09:35 -04002147 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002148 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002149
Johannes Berg86e8cf92013-06-19 10:57:22 +02002150 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002151
2152 return skb->len;
2153}
2154
Johannes Berg86e8cf92013-06-19 10:57:22 +02002155static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2156{
2157 kfree((void *)cb->args[0]);
2158 return 0;
2159}
2160
Johannes Berg55682962007-09-20 13:09:35 -04002161static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2162{
2163 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002165 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002166
Johannes Berg645e77d2013-03-01 14:03:49 +01002167 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002168 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002169 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002170
Johannes Berg3bb20552014-05-26 13:52:25 +02002171 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2172 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002173 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002174 nlmsg_free(msg);
2175 return -ENOBUFS;
2176 }
Johannes Berg55682962007-09-20 13:09:35 -04002177
Johannes Berg134e6372009-07-10 09:51:34 +00002178 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002179}
2180
Jouni Malinen31888482008-10-30 16:59:24 +02002181static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2182 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2183 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2184 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2185 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2186 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2187};
2188
2189static int parse_txq_params(struct nlattr *tb[],
2190 struct ieee80211_txq_params *txq_params)
2191{
Dan Williams259d8c12018-01-29 17:03:15 -08002192 u8 ac;
2193
Johannes Berga3304b02012-03-28 11:04:24 +02002194 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002195 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2196 !tb[NL80211_TXQ_ATTR_AIFS])
2197 return -EINVAL;
2198
Dan Williams259d8c12018-01-29 17:03:15 -08002199 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002200 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2201 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2202 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2203 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2204
Dan Williams259d8c12018-01-29 17:03:15 -08002205 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002206 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002207 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002208 return 0;
2209}
2210
Johannes Bergf444de02010-05-05 15:25:02 +02002211static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2212{
2213 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002214 * You can only set the channel explicitly for WDS interfaces,
2215 * all others have their channel managed via their respective
2216 * "establish a connection" command (connect, join, ...)
2217 *
2218 * For AP/GO and mesh mode, the channel can be set with the
2219 * channel userspace API, but is only stored and passed to the
2220 * low-level driver when the AP starts or the mesh is joined.
2221 * This is for backward compatibility, userspace can also give
2222 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002223 *
2224 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002225 * whatever else is going on, so they have their own special
2226 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002227 */
2228 return !wdev ||
2229 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002230 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002231 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2232 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002233}
2234
Johannes Berg683b6d32012-11-08 21:25:48 +01002235static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2236 struct genl_info *info,
2237 struct cfg80211_chan_def *chandef)
2238{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302239 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002240
2241 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2242 return -EINVAL;
2243
2244 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2245
2246 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002247 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2248 chandef->center_freq1 = control_freq;
2249 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002250
2251 /* Primary channel not allowed */
2252 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2253 return -EINVAL;
2254
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002255 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2256 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002257
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002258 chantype = nla_get_u32(
2259 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2260
2261 switch (chantype) {
2262 case NL80211_CHAN_NO_HT:
2263 case NL80211_CHAN_HT20:
2264 case NL80211_CHAN_HT40PLUS:
2265 case NL80211_CHAN_HT40MINUS:
2266 cfg80211_chandef_create(chandef, chandef->chan,
2267 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002268 /* user input for center_freq is incorrect */
2269 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2270 chandef->center_freq1 != nla_get_u32(
2271 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2272 return -EINVAL;
2273 /* center_freq2 must be zero */
2274 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2275 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2276 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002277 break;
2278 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002279 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002280 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002281 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2282 chandef->width =
2283 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2284 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2285 chandef->center_freq1 =
2286 nla_get_u32(
2287 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2288 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2289 chandef->center_freq2 =
2290 nla_get_u32(
2291 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2292 }
2293
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002294 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002295 return -EINVAL;
2296
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002297 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2298 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002299 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002300
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002301 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2302 chandef->width == NL80211_CHAN_WIDTH_10) &&
2303 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2304 return -EINVAL;
2305
Johannes Berg683b6d32012-11-08 21:25:48 +01002306 return 0;
2307}
2308
Johannes Bergf444de02010-05-05 15:25:02 +02002309static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002310 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002311 struct genl_info *info)
2312{
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002314 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002315 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002316 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002317
Jouni Malinene16821b2014-04-28 11:22:08 +03002318 if (dev)
2319 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002320 if (!nl80211_can_set_dev_channel(wdev))
2321 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002322 if (wdev)
2323 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002324
Johannes Berg683b6d32012-11-08 21:25:48 +01002325 result = nl80211_parse_chandef(rdev, info, &chandef);
2326 if (result)
2327 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002328
Johannes Berge8c9bd52012-06-06 08:18:22 +02002329 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002330 case NL80211_IFTYPE_AP:
2331 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002332 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2333 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002334 result = -EINVAL;
2335 break;
2336 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002337 if (wdev->beacon_interval) {
2338 if (!dev || !rdev->ops->set_ap_chanwidth ||
2339 !(rdev->wiphy.features &
2340 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2341 result = -EBUSY;
2342 break;
2343 }
2344
2345 /* Only allow dynamic channel width changes */
2346 if (chandef.chan != wdev->preset_chandef.chan) {
2347 result = -EBUSY;
2348 break;
2349 }
2350 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2351 if (result)
2352 break;
2353 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002354 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002355 result = 0;
2356 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002357 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002358 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002359 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002360 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002361 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002362 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002363 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002364 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002365 }
Johannes Bergf444de02010-05-05 15:25:02 +02002366
2367 return result;
2368}
2369
2370static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2371{
Johannes Berg4c476992010-10-04 21:36:35 +02002372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2373 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002374
Jouni Malinene16821b2014-04-28 11:22:08 +03002375 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002376}
2377
Bill Jordane8347eb2010-10-01 13:54:28 -04002378static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2379{
Johannes Berg43b19952010-10-07 13:10:30 +02002380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2381 struct net_device *dev = info->user_ptr[1];
2382 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002383 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002384
2385 if (!info->attrs[NL80211_ATTR_MAC])
2386 return -EINVAL;
2387
Johannes Berg43b19952010-10-07 13:10:30 +02002388 if (netif_running(dev))
2389 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002390
Johannes Berg43b19952010-10-07 13:10:30 +02002391 if (!rdev->ops->set_wds_peer)
2392 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002393
Johannes Berg43b19952010-10-07 13:10:30 +02002394 if (wdev->iftype != NL80211_IFTYPE_WDS)
2395 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002396
2397 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002398 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002399}
2400
Johannes Berg55682962007-09-20 13:09:35 -04002401static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2402{
2403 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002404 struct net_device *netdev = NULL;
2405 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002406 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002407 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002408 u32 changed;
2409 u8 retry_short = 0, retry_long = 0;
2410 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002411 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002412 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002413
Johannes Berg5fe231e2013-05-08 21:45:15 +02002414 ASSERT_RTNL();
2415
Johannes Bergf444de02010-05-05 15:25:02 +02002416 /*
2417 * Try to find the wiphy and netdev. Normally this
2418 * function shouldn't need the netdev, but this is
2419 * done for backward compatibility -- previously
2420 * setting the channel was done per wiphy, but now
2421 * it is per netdev. Previous userland like hostapd
2422 * also passed a netdev to set_wiphy, so that it is
2423 * possible to let that go to the right netdev!
2424 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002425
Johannes Bergf444de02010-05-05 15:25:02 +02002426 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2427 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2428
Ying Xue7f2b8562014-01-15 10:23:45 +08002429 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002430 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002431 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002432 else
Johannes Bergf444de02010-05-05 15:25:02 +02002433 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002434 }
2435
Johannes Bergf444de02010-05-05 15:25:02 +02002436 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002437 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2438 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002439 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002440 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002441 wdev = NULL;
2442 netdev = NULL;
2443 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002444 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002445 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002446
2447 /*
2448 * end workaround code, by now the rdev is available
2449 * and locked, and wdev may or may not be NULL.
2450 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002451
2452 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002453 result = cfg80211_dev_rename(
2454 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002455
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002456 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002457 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002458
Jouni Malinen31888482008-10-30 16:59:24 +02002459 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2460 struct ieee80211_txq_params txq_params;
2461 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2462
Ying Xue7f2b8562014-01-15 10:23:45 +08002463 if (!rdev->ops->set_txq_params)
2464 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002465
Ying Xue7f2b8562014-01-15 10:23:45 +08002466 if (!netdev)
2467 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002468
Johannes Berg133a3ff2011-11-03 14:50:13 +01002469 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002470 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2471 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002472
Ying Xue7f2b8562014-01-15 10:23:45 +08002473 if (!netif_running(netdev))
2474 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002475
Jouni Malinen31888482008-10-30 16:59:24 +02002476 nla_for_each_nested(nl_txq_params,
2477 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2478 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002479 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2480 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002481 txq_params_policy,
2482 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002483 if (result)
2484 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002485 result = parse_txq_params(tb, &txq_params);
2486 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002487 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002488
Hila Gonene35e4d22012-06-27 17:19:42 +03002489 result = rdev_set_txq_params(rdev, netdev,
2490 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002491 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002492 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002493 }
2494 }
2495
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002496 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002497 result = __nl80211_set_channel(
2498 rdev,
2499 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2500 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002501 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002502 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002503 }
2504
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002505 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002506 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002507 enum nl80211_tx_power_setting type;
2508 int idx, mbm = 0;
2509
Johannes Bergc8442112012-10-24 10:17:18 +02002510 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2511 txp_wdev = NULL;
2512
Ying Xue7f2b8562014-01-15 10:23:45 +08002513 if (!rdev->ops->set_tx_power)
2514 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002515
2516 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2517 type = nla_get_u32(info->attrs[idx]);
2518
2519 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002520 (type != NL80211_TX_POWER_AUTOMATIC))
2521 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002522
2523 if (type != NL80211_TX_POWER_AUTOMATIC) {
2524 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2525 mbm = nla_get_u32(info->attrs[idx]);
2526 }
2527
Johannes Bergc8442112012-10-24 10:17:18 +02002528 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002529 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002530 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002531 }
2532
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002533 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2534 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2535 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002536
Bruno Randolf7f531e02010-12-16 11:30:22 +09002537 if ((!rdev->wiphy.available_antennas_tx &&
2538 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002539 !rdev->ops->set_antenna)
2540 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002541
2542 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2543 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2544
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002545 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002546 * available antenna masks, except for the "all" mask */
2547 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002548 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2549 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002550
Bruno Randolf7f531e02010-12-16 11:30:22 +09002551 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2552 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002553
Hila Gonene35e4d22012-06-27 17:19:42 +03002554 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002555 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002556 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002557 }
2558
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002559 changed = 0;
2560
2561 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2562 retry_short = nla_get_u8(
2563 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002564 if (retry_short == 0)
2565 return -EINVAL;
2566
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002567 changed |= WIPHY_PARAM_RETRY_SHORT;
2568 }
2569
2570 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2571 retry_long = nla_get_u8(
2572 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002573 if (retry_long == 0)
2574 return -EINVAL;
2575
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002576 changed |= WIPHY_PARAM_RETRY_LONG;
2577 }
2578
2579 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2580 frag_threshold = nla_get_u32(
2581 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002582 if (frag_threshold < 256)
2583 return -EINVAL;
2584
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002585 if (frag_threshold != (u32) -1) {
2586 /*
2587 * Fragments (apart from the last one) are required to
2588 * have even length. Make the fragmentation code
2589 * simpler by stripping LSB should someone try to use
2590 * odd threshold value.
2591 */
2592 frag_threshold &= ~0x1;
2593 }
2594 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2595 }
2596
2597 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2598 rts_threshold = nla_get_u32(
2599 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2600 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2601 }
2602
Lukáš Turek81077e82009-12-21 22:50:47 +01002603 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002604 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2605 return -EINVAL;
2606
Lukáš Turek81077e82009-12-21 22:50:47 +01002607 coverage_class = nla_get_u8(
2608 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2609 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2610 }
2611
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002612 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2613 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2614 return -EOPNOTSUPP;
2615
2616 changed |= WIPHY_PARAM_DYN_ACK;
2617 }
2618
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002619 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
2620 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2621 NL80211_EXT_FEATURE_TXQS))
2622 return -EOPNOTSUPP;
2623 txq_limit = nla_get_u32(
2624 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
2625 changed |= WIPHY_PARAM_TXQ_LIMIT;
2626 }
2627
2628 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
2629 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2630 NL80211_EXT_FEATURE_TXQS))
2631 return -EOPNOTSUPP;
2632 txq_memory_limit = nla_get_u32(
2633 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
2634 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
2635 }
2636
2637 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
2638 if (!wiphy_ext_feature_isset(&rdev->wiphy,
2639 NL80211_EXT_FEATURE_TXQS))
2640 return -EOPNOTSUPP;
2641 txq_quantum = nla_get_u32(
2642 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
2643 changed |= WIPHY_PARAM_TXQ_QUANTUM;
2644 }
2645
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002646 if (changed) {
2647 u8 old_retry_short, old_retry_long;
2648 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002649 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002650 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002651
Ying Xue7f2b8562014-01-15 10:23:45 +08002652 if (!rdev->ops->set_wiphy_params)
2653 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002654
2655 old_retry_short = rdev->wiphy.retry_short;
2656 old_retry_long = rdev->wiphy.retry_long;
2657 old_frag_threshold = rdev->wiphy.frag_threshold;
2658 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002659 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002660 old_txq_limit = rdev->wiphy.txq_limit;
2661 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
2662 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002663
2664 if (changed & WIPHY_PARAM_RETRY_SHORT)
2665 rdev->wiphy.retry_short = retry_short;
2666 if (changed & WIPHY_PARAM_RETRY_LONG)
2667 rdev->wiphy.retry_long = retry_long;
2668 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2669 rdev->wiphy.frag_threshold = frag_threshold;
2670 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2671 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002672 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2673 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002674 if (changed & WIPHY_PARAM_TXQ_LIMIT)
2675 rdev->wiphy.txq_limit = txq_limit;
2676 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
2677 rdev->wiphy.txq_memory_limit = txq_memory_limit;
2678 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
2679 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002680
Hila Gonene35e4d22012-06-27 17:19:42 +03002681 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002682 if (result) {
2683 rdev->wiphy.retry_short = old_retry_short;
2684 rdev->wiphy.retry_long = old_retry_long;
2685 rdev->wiphy.frag_threshold = old_frag_threshold;
2686 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002687 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002688 rdev->wiphy.txq_limit = old_txq_limit;
2689 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
2690 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02002691 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002692 }
2693 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002694 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002695}
2696
Johannes Berg71bbc992012-06-15 15:30:18 +02002697static inline u64 wdev_id(struct wireless_dev *wdev)
2698{
2699 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002700 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002701}
Johannes Berg55682962007-09-20 13:09:35 -04002702
Johannes Berg683b6d32012-11-08 21:25:48 +01002703static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002704 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002705{
Johannes Berg601555c2014-11-27 17:26:56 +01002706 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2707 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002708
Johannes Berg683b6d32012-11-08 21:25:48 +01002709 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2710 chandef->chan->center_freq))
2711 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002712 switch (chandef->width) {
2713 case NL80211_CHAN_WIDTH_20_NOHT:
2714 case NL80211_CHAN_WIDTH_20:
2715 case NL80211_CHAN_WIDTH_40:
2716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2717 cfg80211_get_chandef_type(chandef)))
2718 return -ENOBUFS;
2719 break;
2720 default:
2721 break;
2722 }
2723 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2724 return -ENOBUFS;
2725 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2726 return -ENOBUFS;
2727 if (chandef->center_freq2 &&
2728 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002729 return -ENOBUFS;
2730 return 0;
2731}
2732
Eric W. Biederman15e47302012-09-07 20:12:54 +00002733static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002734 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002735 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002736{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002737 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002738 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002739 void *hdr;
2740
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002741 if (removal)
2742 cmd = NL80211_CMD_DEL_INTERFACE;
2743
2744 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002745 if (!hdr)
2746 return -1;
2747
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002748 if (dev &&
2749 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002750 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002751 goto nla_put_failure;
2752
2753 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2754 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002755 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2756 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002757 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002758 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2759 rdev->devlist_generation ^
2760 (cfg80211_rdev_list_generation << 2)))
2761 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002762
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002763 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002764 int ret;
2765 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002766
Johannes Berg683b6d32012-11-08 21:25:48 +01002767 ret = rdev_get_channel(rdev, wdev, &chandef);
2768 if (ret == 0) {
2769 if (nl80211_send_chandef(msg, &chandef))
2770 goto nla_put_failure;
2771 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002772 }
2773
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002774 if (rdev->ops->get_tx_power) {
2775 int dbm, ret;
2776
2777 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2778 if (ret == 0 &&
2779 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2780 DBM_TO_MBM(dbm)))
2781 goto nla_put_failure;
2782 }
2783
Johannes Berg44905262017-10-17 21:56:01 +02002784 wdev_lock(wdev);
2785 switch (wdev->iftype) {
2786 case NL80211_IFTYPE_AP:
2787 if (wdev->ssid_len &&
2788 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01002789 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02002790 break;
2791 case NL80211_IFTYPE_STATION:
2792 case NL80211_IFTYPE_P2P_CLIENT:
2793 case NL80211_IFTYPE_ADHOC: {
2794 const u8 *ssid_ie;
2795 if (!wdev->current_bss)
2796 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002797 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02002798 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
2799 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002800 if (ssid_ie &&
2801 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
2802 goto nla_put_failure_rcu_locked;
2803 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02002804 break;
2805 }
2806 default:
2807 /* nothing */
2808 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002809 }
Johannes Berg44905262017-10-17 21:56:01 +02002810 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002811
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002812 if (rdev->ops->get_txq_stats) {
2813 struct cfg80211_txq_stats txqstats = {};
2814 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
2815
2816 if (ret == 0 &&
2817 !nl80211_put_txq_stats(msg, &txqstats,
2818 NL80211_ATTR_TXQ_STATS))
2819 goto nla_put_failure;
2820 }
2821
Johannes Berg053c0952015-01-16 22:09:00 +01002822 genlmsg_end(msg, hdr);
2823 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002824
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002825 nla_put_failure_rcu_locked:
2826 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01002827 nla_put_failure_locked:
2828 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002829 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002830 genlmsg_cancel(msg, hdr);
2831 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002832}
2833
2834static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2835{
2836 int wp_idx = 0;
2837 int if_idx = 0;
2838 int wp_start = cb->args[0];
2839 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002840 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002841 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002842 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002843 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002844
Johannes Berg5fe231e2013-05-08 21:45:15 +02002845 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002846 if (!cb->args[2]) {
2847 struct nl80211_dump_wiphy_state state = {
2848 .filter_wiphy = -1,
2849 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002850
2851 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2852 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002853 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002854
2855 filter_wiphy = state.filter_wiphy;
2856
2857 /*
2858 * if filtering, set cb->args[2] to +1 since 0 is the default
2859 * value needed to determine that parsing is necessary.
2860 */
2861 if (filter_wiphy >= 0)
2862 cb->args[2] = filter_wiphy + 1;
2863 else
2864 cb->args[2] = -1;
2865 } else if (cb->args[2] > 0) {
2866 filter_wiphy = cb->args[2] - 1;
2867 }
2868
Johannes Bergf5ea9122009-08-07 16:17:38 +02002869 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2870 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002871 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002872 if (wp_idx < wp_start) {
2873 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002874 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002875 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002876
2877 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2878 continue;
2879
Johannes Berg55682962007-09-20 13:09:35 -04002880 if_idx = 0;
2881
Johannes Berg53873f12016-05-03 16:52:04 +03002882 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002883 if (if_idx < if_start) {
2884 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002885 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002886 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002887 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002888 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002889 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002890 goto out;
2891 }
2892 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002893 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002894
2895 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002896 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002897 out:
Johannes Berg55682962007-09-20 13:09:35 -04002898 cb->args[0] = wp_idx;
2899 cb->args[1] = if_idx;
2900
Johannes Bergea90e0d2017-03-15 14:26:04 +01002901 ret = skb->len;
2902 out_unlock:
2903 rtnl_unlock();
2904
2905 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002906}
2907
2908static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2909{
2910 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002912 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002913
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002914 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002915 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002916 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002917
Eric W. Biederman15e47302012-09-07 20:12:54 +00002918 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002919 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002920 nlmsg_free(msg);
2921 return -ENOBUFS;
2922 }
Johannes Berg55682962007-09-20 13:09:35 -04002923
Johannes Berg134e6372009-07-10 09:51:34 +00002924 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002925}
2926
Michael Wu66f7ac52008-01-31 19:48:22 +01002927static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2928 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2929 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2930 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2931 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2932 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002933 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002934};
2935
2936static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2937{
2938 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2939 int flag;
2940
2941 *mntrflags = 0;
2942
2943 if (!nla)
2944 return -EINVAL;
2945
Johannes Bergfceb6432017-04-12 14:34:07 +02002946 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2947 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002948 return -EINVAL;
2949
2950 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2951 if (flags[flag])
2952 *mntrflags |= (1<<flag);
2953
Johannes Berg818a9862017-04-12 11:23:28 +02002954 *mntrflags |= MONITOR_FLAG_CHANGED;
2955
Michael Wu66f7ac52008-01-31 19:48:22 +01002956 return 0;
2957}
2958
Johannes Berg1db77592017-04-12 11:36:31 +02002959static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2960 enum nl80211_iftype type,
2961 struct genl_info *info,
2962 struct vif_params *params)
2963{
2964 bool change = false;
2965 int err;
2966
2967 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2968 if (type != NL80211_IFTYPE_MONITOR)
2969 return -EINVAL;
2970
2971 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2972 &params->flags);
2973 if (err)
2974 return err;
2975
2976 change = true;
2977 }
2978
2979 if (params->flags & MONITOR_FLAG_ACTIVE &&
2980 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2981 return -EOPNOTSUPP;
2982
2983 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2984 const u8 *mumimo_groups;
2985 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2986
2987 if (type != NL80211_IFTYPE_MONITOR)
2988 return -EINVAL;
2989
2990 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2991 return -EOPNOTSUPP;
2992
2993 mumimo_groups =
2994 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2995
2996 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002997 if ((mumimo_groups[0] & BIT(0)) ||
2998 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002999 return -EINVAL;
3000
3001 params->vht_mumimo_groups = mumimo_groups;
3002 change = true;
3003 }
3004
3005 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3006 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3007
3008 if (type != NL80211_IFTYPE_MONITOR)
3009 return -EINVAL;
3010
3011 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3012 return -EOPNOTSUPP;
3013
3014 params->vht_mumimo_follow_addr =
3015 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3016 change = true;
3017 }
3018
3019 return change ? 1 : 0;
3020}
3021
Johannes Berg9bc383d2009-11-19 11:55:19 +01003022static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003023 struct net_device *netdev, u8 use_4addr,
3024 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003025{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003026 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003027 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003028 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003029 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003030 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003031
3032 switch (iftype) {
3033 case NL80211_IFTYPE_AP_VLAN:
3034 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3035 return 0;
3036 break;
3037 case NL80211_IFTYPE_STATION:
3038 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3039 return 0;
3040 break;
3041 default:
3042 break;
3043 }
3044
3045 return -EOPNOTSUPP;
3046}
3047
Johannes Berg55682962007-09-20 13:09:35 -04003048static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3049{
Johannes Berg4c476992010-10-04 21:36:35 +02003050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003051 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003052 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003053 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003054 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003055 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003056
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003057 memset(&params, 0, sizeof(params));
3058
Johannes Berg04a773a2009-04-19 21:24:32 +02003059 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003060
Johannes Berg723b0382008-09-16 20:22:09 +02003061 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003062 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003063 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003064 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02003065 if (ntype > NL80211_IFTYPE_MAX)
3066 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02003067 }
3068
Johannes Berg92ffe052008-09-16 20:39:36 +02003069 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003070 struct wireless_dev *wdev = dev->ieee80211_ptr;
3071
Johannes Berg4c476992010-10-04 21:36:35 +02003072 if (ntype != NL80211_IFTYPE_MESH_POINT)
3073 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003074 if (netif_running(dev))
3075 return -EBUSY;
3076
3077 wdev_lock(wdev);
3078 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3079 IEEE80211_MAX_MESH_ID_LEN);
3080 wdev->mesh_id_up_len =
3081 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3082 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3083 wdev->mesh_id_up_len);
3084 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003085 }
3086
Felix Fietkau8b787642009-11-10 18:53:10 +01003087 if (info->attrs[NL80211_ATTR_4ADDR]) {
3088 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3089 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003090 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003091 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003092 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003093 } else {
3094 params.use_4addr = -1;
3095 }
3096
Johannes Berg1db77592017-04-12 11:36:31 +02003097 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3098 if (err < 0)
3099 return err;
3100 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003101 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003102
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003103 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003104 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003105 else
3106 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003107
Johannes Berg9bc383d2009-11-19 11:55:19 +01003108 if (!err && params.use_4addr != -1)
3109 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3110
Johannes Berg55682962007-09-20 13:09:35 -04003111 return err;
3112}
3113
3114static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3115{
Johannes Berg4c476992010-10-04 21:36:35 +02003116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003117 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003118 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003119 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003120 int err;
3121 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3122
Johannes Berg78f22b62014-03-24 17:57:27 +01003123 /* to avoid failing a new interface creation due to pending removal */
3124 cfg80211_destroy_ifaces(rdev);
3125
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003126 memset(&params, 0, sizeof(params));
3127
Johannes Berg55682962007-09-20 13:09:35 -04003128 if (!info->attrs[NL80211_ATTR_IFNAME])
3129 return -EINVAL;
3130
3131 if (info->attrs[NL80211_ATTR_IFTYPE]) {
3132 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3133 if (type > NL80211_IFTYPE_MAX)
3134 return -EINVAL;
3135 }
3136
Johannes Berg79c97e92009-07-07 03:56:12 +02003137 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02003138 !(rdev->wiphy.interface_modes & (1 << type)))
3139 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003140
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003141 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003142 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3143 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003144 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3145 ETH_ALEN);
3146 if (!is_valid_ether_addr(params.macaddr))
3147 return -EADDRNOTAVAIL;
3148 }
3149
Johannes Berg9bc383d2009-11-19 11:55:19 +01003150 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003151 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003152 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003153 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003154 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003155 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003156
Johannes Berg1db77592017-04-12 11:36:31 +02003157 err = nl80211_parse_mon_options(rdev, type, info, &params);
3158 if (err < 0)
3159 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003160
Johannes Berga18c7192015-02-24 10:56:42 +01003161 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3162 if (!msg)
3163 return -ENOMEM;
3164
Hila Gonene35e4d22012-06-27 17:19:42 +03003165 wdev = rdev_add_virtual_intf(rdev,
3166 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003167 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003168 if (WARN_ON(!wdev)) {
3169 nlmsg_free(msg);
3170 return -EPROTO;
3171 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003172 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003173 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003174 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003175
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003176 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003177 wdev->owner_nlportid = info->snd_portid;
3178
Johannes Berg98104fde2012-06-16 00:19:54 +02003179 switch (type) {
3180 case NL80211_IFTYPE_MESH_POINT:
3181 if (!info->attrs[NL80211_ATTR_MESH_ID])
3182 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003183 wdev_lock(wdev);
3184 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3185 IEEE80211_MAX_MESH_ID_LEN);
3186 wdev->mesh_id_up_len =
3187 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3188 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3189 wdev->mesh_id_up_len);
3190 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003191 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003192 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003193 case NL80211_IFTYPE_P2P_DEVICE:
3194 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003195 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003196 * through the netdev notifier and must be added here
3197 */
3198 mutex_init(&wdev->mtx);
3199 INIT_LIST_HEAD(&wdev->event_list);
3200 spin_lock_init(&wdev->event_lock);
3201 INIT_LIST_HEAD(&wdev->mgmt_registrations);
3202 spin_lock_init(&wdev->mgmt_registrations_lock);
3203
Johannes Berg98104fde2012-06-16 00:19:54 +02003204 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03003205 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02003206 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02003207 break;
3208 default:
3209 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003210 }
3211
Eric W. Biederman15e47302012-09-07 20:12:54 +00003212 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003213 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003214 nlmsg_free(msg);
3215 return -ENOBUFS;
3216 }
3217
Denis Kenzior896ff062016-08-03 16:58:33 -05003218 /*
3219 * For wdevs which have no associated netdev object (e.g. of type
3220 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3221 * For all other types, the event will be generated from the
3222 * netdev notifier
3223 */
3224 if (!wdev->netdev)
3225 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003226
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003227 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003228}
3229
3230static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3231{
Johannes Berg4c476992010-10-04 21:36:35 +02003232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003233 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003234
Johannes Berg4c476992010-10-04 21:36:35 +02003235 if (!rdev->ops->del_virtual_intf)
3236 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003237
Johannes Berg84efbb82012-06-16 00:00:26 +02003238 /*
3239 * If we remove a wireless device without a netdev then clear
3240 * user_ptr[1] so that nl80211_post_doit won't dereference it
3241 * to check if it needs to do dev_put(). Otherwise it crashes
3242 * since the wdev has been freed, unlike with a netdev where
3243 * we need the dev_put() for the netdev to really be freed.
3244 */
3245 if (!wdev->netdev)
3246 info->user_ptr[1] = NULL;
3247
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003248 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003249}
3250
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003251static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3252{
3253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3254 struct net_device *dev = info->user_ptr[1];
3255 u16 noack_map;
3256
3257 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3258 return -EINVAL;
3259
3260 if (!rdev->ops->set_noack_map)
3261 return -EOPNOTSUPP;
3262
3263 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3264
Hila Gonene35e4d22012-06-27 17:19:42 +03003265 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003266}
3267
Johannes Berg41ade002007-12-19 02:03:29 +01003268struct get_key_cookie {
3269 struct sk_buff *msg;
3270 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003271 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003272};
3273
3274static void get_key_callback(void *c, struct key_params *params)
3275{
Johannes Bergb9454e82009-07-08 13:29:08 +02003276 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003277 struct get_key_cookie *cookie = c;
3278
David S. Miller9360ffd2012-03-29 04:41:26 -04003279 if ((params->key &&
3280 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3281 params->key_len, params->key)) ||
3282 (params->seq &&
3283 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3284 params->seq_len, params->seq)) ||
3285 (params->cipher &&
3286 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3287 params->cipher)))
3288 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003289
Johannes Bergb9454e82009-07-08 13:29:08 +02003290 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3291 if (!key)
3292 goto nla_put_failure;
3293
David S. Miller9360ffd2012-03-29 04:41:26 -04003294 if ((params->key &&
3295 nla_put(cookie->msg, NL80211_KEY_DATA,
3296 params->key_len, params->key)) ||
3297 (params->seq &&
3298 nla_put(cookie->msg, NL80211_KEY_SEQ,
3299 params->seq_len, params->seq)) ||
3300 (params->cipher &&
3301 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3302 params->cipher)))
3303 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003304
David S. Miller9360ffd2012-03-29 04:41:26 -04003305 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3306 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003307
3308 nla_nest_end(cookie->msg, key);
3309
Johannes Berg41ade002007-12-19 02:03:29 +01003310 return;
3311 nla_put_failure:
3312 cookie->error = 1;
3313}
3314
3315static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3316{
Johannes Berg4c476992010-10-04 21:36:35 +02003317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003318 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003319 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003320 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003321 const u8 *mac_addr = NULL;
3322 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003323 struct get_key_cookie cookie = {
3324 .error = 0,
3325 };
3326 void *hdr;
3327 struct sk_buff *msg;
3328
3329 if (info->attrs[NL80211_ATTR_KEY_IDX])
3330 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3331
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003332 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003333 return -EINVAL;
3334
3335 if (info->attrs[NL80211_ATTR_MAC])
3336 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3337
Johannes Berge31b8212010-10-05 19:39:30 +02003338 pairwise = !!mac_addr;
3339 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3340 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003341
Johannes Berge31b8212010-10-05 19:39:30 +02003342 if (kt >= NUM_NL80211_KEYTYPES)
3343 return -EINVAL;
3344 if (kt != NL80211_KEYTYPE_GROUP &&
3345 kt != NL80211_KEYTYPE_PAIRWISE)
3346 return -EINVAL;
3347 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3348 }
3349
Johannes Berg4c476992010-10-04 21:36:35 +02003350 if (!rdev->ops->get_key)
3351 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003352
Johannes Berg0fa7b392015-01-23 11:10:12 +01003353 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3354 return -ENOENT;
3355
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003357 if (!msg)
3358 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003359
Eric W. Biederman15e47302012-09-07 20:12:54 +00003360 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003361 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003362 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003363 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003364
3365 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003366 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003367
David S. Miller9360ffd2012-03-29 04:41:26 -04003368 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3369 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3370 goto nla_put_failure;
3371 if (mac_addr &&
3372 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3373 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003374
Hila Gonene35e4d22012-06-27 17:19:42 +03003375 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3376 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003377
3378 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003379 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003380
3381 if (cookie.error)
3382 goto nla_put_failure;
3383
3384 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003385 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003386
3387 nla_put_failure:
3388 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003389 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003390 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003391 return err;
3392}
3393
3394static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3395{
Johannes Berg4c476992010-10-04 21:36:35 +02003396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003397 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003398 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003399 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003400
Johannes Bergb9454e82009-07-08 13:29:08 +02003401 err = nl80211_parse_key(info, &key);
3402 if (err)
3403 return err;
3404
3405 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003406 return -EINVAL;
3407
Johannes Bergb9454e82009-07-08 13:29:08 +02003408 /* only support setting default key */
3409 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003410 return -EINVAL;
3411
Johannes Bergfffd0932009-07-08 14:22:54 +02003412 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003413
3414 if (key.def) {
3415 if (!rdev->ops->set_default_key) {
3416 err = -EOPNOTSUPP;
3417 goto out;
3418 }
3419
3420 err = nl80211_key_allowed(dev->ieee80211_ptr);
3421 if (err)
3422 goto out;
3423
Hila Gonene35e4d22012-06-27 17:19:42 +03003424 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003425 key.def_uni, key.def_multi);
3426
3427 if (err)
3428 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003429
Johannes Berg3d23e342009-09-29 23:27:28 +02003430#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003431 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003432#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003433 } else {
3434 if (key.def_uni || !key.def_multi) {
3435 err = -EINVAL;
3436 goto out;
3437 }
3438
3439 if (!rdev->ops->set_default_mgmt_key) {
3440 err = -EOPNOTSUPP;
3441 goto out;
3442 }
3443
3444 err = nl80211_key_allowed(dev->ieee80211_ptr);
3445 if (err)
3446 goto out;
3447
Hila Gonene35e4d22012-06-27 17:19:42 +03003448 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003449 if (err)
3450 goto out;
3451
3452#ifdef CONFIG_CFG80211_WEXT
3453 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3454#endif
3455 }
3456
3457 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003458 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003459
Johannes Berg41ade002007-12-19 02:03:29 +01003460 return err;
3461}
3462
3463static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3464{
Johannes Berg4c476992010-10-04 21:36:35 +02003465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003466 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003467 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003468 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003469 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003470
Johannes Bergb9454e82009-07-08 13:29:08 +02003471 err = nl80211_parse_key(info, &key);
3472 if (err)
3473 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003474
Johannes Bergb9454e82009-07-08 13:29:08 +02003475 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003476 return -EINVAL;
3477
Johannes Berg41ade002007-12-19 02:03:29 +01003478 if (info->attrs[NL80211_ATTR_MAC])
3479 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3480
Johannes Berge31b8212010-10-05 19:39:30 +02003481 if (key.type == -1) {
3482 if (mac_addr)
3483 key.type = NL80211_KEYTYPE_PAIRWISE;
3484 else
3485 key.type = NL80211_KEYTYPE_GROUP;
3486 }
3487
3488 /* for now */
3489 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3490 key.type != NL80211_KEYTYPE_GROUP)
3491 return -EINVAL;
3492
Johannes Berg4c476992010-10-04 21:36:35 +02003493 if (!rdev->ops->add_key)
3494 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003495
Johannes Berge31b8212010-10-05 19:39:30 +02003496 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3497 key.type == NL80211_KEYTYPE_PAIRWISE,
3498 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003499 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003500
3501 wdev_lock(dev->ieee80211_ptr);
3502 err = nl80211_key_allowed(dev->ieee80211_ptr);
3503 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003504 err = rdev_add_key(rdev, dev, key.idx,
3505 key.type == NL80211_KEYTYPE_PAIRWISE,
3506 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003507 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003508
Johannes Berg41ade002007-12-19 02:03:29 +01003509 return err;
3510}
3511
3512static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3513{
Johannes Berg4c476992010-10-04 21:36:35 +02003514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003515 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003516 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003517 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003518 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003519
Johannes Bergb9454e82009-07-08 13:29:08 +02003520 err = nl80211_parse_key(info, &key);
3521 if (err)
3522 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003523
3524 if (info->attrs[NL80211_ATTR_MAC])
3525 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3526
Johannes Berge31b8212010-10-05 19:39:30 +02003527 if (key.type == -1) {
3528 if (mac_addr)
3529 key.type = NL80211_KEYTYPE_PAIRWISE;
3530 else
3531 key.type = NL80211_KEYTYPE_GROUP;
3532 }
3533
3534 /* for now */
3535 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3536 key.type != NL80211_KEYTYPE_GROUP)
3537 return -EINVAL;
3538
Johannes Berg4c476992010-10-04 21:36:35 +02003539 if (!rdev->ops->del_key)
3540 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003541
Johannes Bergfffd0932009-07-08 14:22:54 +02003542 wdev_lock(dev->ieee80211_ptr);
3543 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003544
Johannes Berg0fa7b392015-01-23 11:10:12 +01003545 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003546 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3547 err = -ENOENT;
3548
Johannes Bergfffd0932009-07-08 14:22:54 +02003549 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003550 err = rdev_del_key(rdev, dev, key.idx,
3551 key.type == NL80211_KEYTYPE_PAIRWISE,
3552 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003553
Johannes Berg3d23e342009-09-29 23:27:28 +02003554#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003555 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003556 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003557 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003558 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003559 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3560 }
3561#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003562 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003563
Johannes Berg41ade002007-12-19 02:03:29 +01003564 return err;
3565}
3566
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303567/* This function returns an error or the number of nested attributes */
3568static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3569{
3570 struct nlattr *attr;
3571 int n_entries = 0, tmp;
3572
3573 nla_for_each_nested(attr, nl_attr, tmp) {
3574 if (nla_len(attr) != ETH_ALEN)
3575 return -EINVAL;
3576
3577 n_entries++;
3578 }
3579
3580 return n_entries;
3581}
3582
3583/*
3584 * This function parses ACL information and allocates memory for ACL data.
3585 * On successful return, the calling function is responsible to free the
3586 * ACL buffer returned by this function.
3587 */
3588static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3589 struct genl_info *info)
3590{
3591 enum nl80211_acl_policy acl_policy;
3592 struct nlattr *attr;
3593 struct cfg80211_acl_data *acl;
3594 int i = 0, n_entries, tmp;
3595
3596 if (!wiphy->max_acl_mac_addrs)
3597 return ERR_PTR(-EOPNOTSUPP);
3598
3599 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3600 return ERR_PTR(-EINVAL);
3601
3602 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3603 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3604 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3605 return ERR_PTR(-EINVAL);
3606
3607 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3608 return ERR_PTR(-EINVAL);
3609
3610 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3611 if (n_entries < 0)
3612 return ERR_PTR(n_entries);
3613
3614 if (n_entries > wiphy->max_acl_mac_addrs)
3615 return ERR_PTR(-ENOTSUPP);
3616
3617 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3618 GFP_KERNEL);
3619 if (!acl)
3620 return ERR_PTR(-ENOMEM);
3621
3622 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3623 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3624 i++;
3625 }
3626
3627 acl->n_acl_entries = n_entries;
3628 acl->acl_policy = acl_policy;
3629
3630 return acl;
3631}
3632
3633static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3634{
3635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3636 struct net_device *dev = info->user_ptr[1];
3637 struct cfg80211_acl_data *acl;
3638 int err;
3639
3640 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3641 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3642 return -EOPNOTSUPP;
3643
3644 if (!dev->ieee80211_ptr->beacon_interval)
3645 return -EINVAL;
3646
3647 acl = parse_acl_data(&rdev->wiphy, info);
3648 if (IS_ERR(acl))
3649 return PTR_ERR(acl);
3650
3651 err = rdev_set_mac_acl(rdev, dev, acl);
3652
3653 kfree(acl);
3654
3655 return err;
3656}
3657
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303658static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3659 u8 *rates, u8 rates_len)
3660{
3661 u8 i;
3662 u32 mask = 0;
3663
3664 for (i = 0; i < rates_len; i++) {
3665 int rate = (rates[i] & 0x7f) * 5;
3666 int ridx;
3667
3668 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3669 struct ieee80211_rate *srate =
3670 &sband->bitrates[ridx];
3671 if (rate == srate->bitrate) {
3672 mask |= 1 << ridx;
3673 break;
3674 }
3675 }
3676 if (ridx == sband->n_bitrates)
3677 return 0; /* rate not found */
3678 }
3679
3680 return mask;
3681}
3682
3683static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3684 u8 *rates, u8 rates_len,
3685 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3686{
3687 u8 i;
3688
3689 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3690
3691 for (i = 0; i < rates_len; i++) {
3692 int ridx, rbit;
3693
3694 ridx = rates[i] / 8;
3695 rbit = BIT(rates[i] % 8);
3696
3697 /* check validity */
3698 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3699 return false;
3700
3701 /* check availability */
3702 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3703 mcs[ridx] |= rbit;
3704 else
3705 return false;
3706 }
3707
3708 return true;
3709}
3710
3711static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3712{
3713 u16 mcs_mask = 0;
3714
3715 switch (vht_mcs_map) {
3716 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3717 break;
3718 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3719 mcs_mask = 0x00FF;
3720 break;
3721 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3722 mcs_mask = 0x01FF;
3723 break;
3724 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3725 mcs_mask = 0x03FF;
3726 break;
3727 default:
3728 break;
3729 }
3730
3731 return mcs_mask;
3732}
3733
3734static void vht_build_mcs_mask(u16 vht_mcs_map,
3735 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3736{
3737 u8 nss;
3738
3739 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3740 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3741 vht_mcs_map >>= 2;
3742 }
3743}
3744
3745static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3746 struct nl80211_txrate_vht *txrate,
3747 u16 mcs[NL80211_VHT_NSS_MAX])
3748{
3749 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3750 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3751 u8 i;
3752
3753 if (!sband->vht_cap.vht_supported)
3754 return false;
3755
3756 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3757
3758 /* Build vht_mcs_mask from VHT capabilities */
3759 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3760
3761 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3762 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3763 mcs[i] = txrate->mcs[i];
3764 else
3765 return false;
3766 }
3767
3768 return true;
3769}
3770
3771static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3772 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3773 .len = NL80211_MAX_SUPP_RATES },
3774 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3775 .len = NL80211_MAX_SUPP_HT_RATES },
3776 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3777 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3778};
3779
3780static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3781 struct cfg80211_bitrate_mask *mask)
3782{
3783 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3785 int rem, i;
3786 struct nlattr *tx_rates;
3787 struct ieee80211_supported_band *sband;
3788 u16 vht_tx_mcs_map;
3789
3790 memset(mask, 0, sizeof(*mask));
3791 /* Default to all rates enabled */
3792 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3793 sband = rdev->wiphy.bands[i];
3794
3795 if (!sband)
3796 continue;
3797
3798 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3799 memcpy(mask->control[i].ht_mcs,
3800 sband->ht_cap.mcs.rx_mask,
3801 sizeof(mask->control[i].ht_mcs));
3802
3803 if (!sband->vht_cap.vht_supported)
3804 continue;
3805
3806 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3807 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3808 }
3809
3810 /* if no rates are given set it back to the defaults */
3811 if (!info->attrs[NL80211_ATTR_TX_RATES])
3812 goto out;
3813
3814 /* The nested attribute uses enum nl80211_band as the index. This maps
3815 * directly to the enum nl80211_band values used in cfg80211.
3816 */
3817 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3818 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3819 enum nl80211_band band = nla_type(tx_rates);
3820 int err;
3821
3822 if (band < 0 || band >= NUM_NL80211_BANDS)
3823 return -EINVAL;
3824 sband = rdev->wiphy.bands[band];
3825 if (sband == NULL)
3826 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003827 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003828 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303829 if (err)
3830 return err;
3831 if (tb[NL80211_TXRATE_LEGACY]) {
3832 mask->control[band].legacy = rateset_to_mask(
3833 sband,
3834 nla_data(tb[NL80211_TXRATE_LEGACY]),
3835 nla_len(tb[NL80211_TXRATE_LEGACY]));
3836 if ((mask->control[band].legacy == 0) &&
3837 nla_len(tb[NL80211_TXRATE_LEGACY]))
3838 return -EINVAL;
3839 }
3840 if (tb[NL80211_TXRATE_HT]) {
3841 if (!ht_rateset_to_mask(
3842 sband,
3843 nla_data(tb[NL80211_TXRATE_HT]),
3844 nla_len(tb[NL80211_TXRATE_HT]),
3845 mask->control[band].ht_mcs))
3846 return -EINVAL;
3847 }
3848 if (tb[NL80211_TXRATE_VHT]) {
3849 if (!vht_set_mcs_mask(
3850 sband,
3851 nla_data(tb[NL80211_TXRATE_VHT]),
3852 mask->control[band].vht_mcs))
3853 return -EINVAL;
3854 }
3855 if (tb[NL80211_TXRATE_GI]) {
3856 mask->control[band].gi =
3857 nla_get_u8(tb[NL80211_TXRATE_GI]);
3858 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3859 return -EINVAL;
3860 }
3861
3862 if (mask->control[band].legacy == 0) {
3863 /* don't allow empty legacy rates if HT or VHT
3864 * are not even supported.
3865 */
3866 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3867 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3868 return -EINVAL;
3869
3870 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3871 if (mask->control[band].ht_mcs[i])
3872 goto out;
3873
3874 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3875 if (mask->control[band].vht_mcs[i])
3876 goto out;
3877
3878 /* legacy and mcs rates may not be both empty */
3879 return -EINVAL;
3880 }
3881 }
3882
3883out:
3884 return 0;
3885}
3886
Johannes Berg8564e382016-09-19 09:44:44 +02003887static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3888 enum nl80211_band band,
3889 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303890{
Johannes Berg8564e382016-09-19 09:44:44 +02003891 u32 count_ht, count_vht, i;
3892 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303893
3894 /* Allow only one rate */
3895 if (hweight32(rate) > 1)
3896 return -EINVAL;
3897
3898 count_ht = 0;
3899 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003900 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303901 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003902 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303903 count_ht++;
3904 if (count_ht > 1)
3905 return -EINVAL;
3906 }
3907 if (count_ht && rate)
3908 return -EINVAL;
3909 }
3910
3911 count_vht = 0;
3912 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003913 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303914 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003915 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303916 count_vht++;
3917 if (count_vht > 1)
3918 return -EINVAL;
3919 }
3920 if (count_vht && rate)
3921 return -EINVAL;
3922 }
3923
3924 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3925 return -EINVAL;
3926
Johannes Berg8564e382016-09-19 09:44:44 +02003927 if (rate &&
3928 !wiphy_ext_feature_isset(&rdev->wiphy,
3929 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3930 return -EINVAL;
3931 if (count_ht &&
3932 !wiphy_ext_feature_isset(&rdev->wiphy,
3933 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3934 return -EINVAL;
3935 if (count_vht &&
3936 !wiphy_ext_feature_isset(&rdev->wiphy,
3937 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3938 return -EINVAL;
3939
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303940 return 0;
3941}
3942
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003943static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003944 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003945{
Johannes Berg88600202012-02-13 15:17:18 +01003946 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003947
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003948 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3949 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3950 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3951 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003952 return -EINVAL;
3953
Johannes Berg88600202012-02-13 15:17:18 +01003954 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003955
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003956 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3957 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3958 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003959 if (!bcn->head_len)
3960 return -EINVAL;
3961 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003962 }
3963
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003964 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3965 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3966 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003967 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003968 }
3969
Johannes Berg4c476992010-10-04 21:36:35 +02003970 if (!haveinfo)
3971 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003972
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003973 if (attrs[NL80211_ATTR_IE]) {
3974 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3975 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003976 }
3977
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003978 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003979 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003980 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003981 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003982 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003983 }
3984
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003985 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003986 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003987 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003988 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003989 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003990 }
3991
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003992 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3993 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3994 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003995 }
3996
Johannes Berg88600202012-02-13 15:17:18 +01003997 return 0;
3998}
3999
Johannes Berg66cd7942017-02-07 22:40:44 +02004000static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4001 const u8 *rates)
4002{
4003 int i;
4004
4005 if (!rates)
4006 return;
4007
4008 for (i = 0; i < rates[1]; i++) {
4009 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4010 params->ht_required = true;
4011 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4012 params->vht_required = true;
4013 }
4014}
4015
4016/*
4017 * Since the nl80211 API didn't include, from the beginning, attributes about
4018 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4019 * benefit of drivers that rebuild IEs in the firmware.
4020 */
4021static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4022{
4023 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004024 size_t ies_len = bcn->tail_len;
4025 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004026 const u8 *rates;
4027 const u8 *cap;
4028
4029 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4030 nl80211_check_ap_rate_selectors(params, rates);
4031
4032 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4033 nl80211_check_ap_rate_selectors(params, rates);
4034
4035 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4036 if (cap && cap[1] >= sizeof(*params->ht_cap))
4037 params->ht_cap = (void *)(cap + 2);
4038 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4039 if (cap && cap[1] >= sizeof(*params->vht_cap))
4040 params->vht_cap = (void *)(cap + 2);
4041}
4042
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004043static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4044 struct cfg80211_ap_settings *params)
4045{
4046 struct wireless_dev *wdev;
4047 bool ret = false;
4048
Johannes Berg53873f12016-05-03 16:52:04 +03004049 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004050 if (wdev->iftype != NL80211_IFTYPE_AP &&
4051 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4052 continue;
4053
Johannes Berg683b6d32012-11-08 21:25:48 +01004054 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004055 continue;
4056
Johannes Berg683b6d32012-11-08 21:25:48 +01004057 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004058 ret = true;
4059 break;
4060 }
4061
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004062 return ret;
4063}
4064
Jouni Malinene39e5b52012-09-30 19:29:39 +03004065static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4066 enum nl80211_auth_type auth_type,
4067 enum nl80211_commands cmd)
4068{
4069 if (auth_type > NL80211_AUTHTYPE_MAX)
4070 return false;
4071
4072 switch (cmd) {
4073 case NL80211_CMD_AUTHENTICATE:
4074 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4075 auth_type == NL80211_AUTHTYPE_SAE)
4076 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004077 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4078 NL80211_EXT_FEATURE_FILS_STA) &&
4079 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4080 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4081 auth_type == NL80211_AUTHTYPE_FILS_PK))
4082 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004083 return true;
4084 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004085 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4086 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004087 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004088
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004089 /* FILS with SK PFS or PK not supported yet */
4090 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4091 auth_type == NL80211_AUTHTYPE_FILS_PK)
4092 return false;
4093 if (!wiphy_ext_feature_isset(
4094 &rdev->wiphy,
4095 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4096 auth_type == NL80211_AUTHTYPE_FILS_SK)
4097 return false;
4098 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004099 case NL80211_CMD_START_AP:
4100 /* SAE not supported yet */
4101 if (auth_type == NL80211_AUTHTYPE_SAE)
4102 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004103 /* FILS not supported yet */
4104 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4105 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4106 auth_type == NL80211_AUTHTYPE_FILS_PK)
4107 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004108 return true;
4109 default:
4110 return false;
4111 }
4112}
4113
Johannes Berg88600202012-02-13 15:17:18 +01004114static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4115{
4116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4117 struct net_device *dev = info->user_ptr[1];
4118 struct wireless_dev *wdev = dev->ieee80211_ptr;
4119 struct cfg80211_ap_settings params;
4120 int err;
4121
4122 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4123 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4124 return -EOPNOTSUPP;
4125
4126 if (!rdev->ops->start_ap)
4127 return -EOPNOTSUPP;
4128
4129 if (wdev->beacon_interval)
4130 return -EALREADY;
4131
4132 memset(&params, 0, sizeof(params));
4133
4134 /* these are required for START_AP */
4135 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4136 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4137 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4138 return -EINVAL;
4139
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004140 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004141 if (err)
4142 return err;
4143
4144 params.beacon_interval =
4145 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4146 params.dtim_period =
4147 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4148
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304149 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4150 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004151 if (err)
4152 return err;
4153
4154 /*
4155 * In theory, some of these attributes should be required here
4156 * but since they were not used when the command was originally
4157 * added, keep them optional for old user space programs to let
4158 * them continue to work with drivers that do not need the
4159 * additional information -- drivers must check!
4160 */
4161 if (info->attrs[NL80211_ATTR_SSID]) {
4162 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4163 params.ssid_len =
4164 nla_len(info->attrs[NL80211_ATTR_SSID]);
4165 if (params.ssid_len == 0 ||
4166 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4167 return -EINVAL;
4168 }
4169
4170 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
4171 params.hidden_ssid = nla_get_u32(
4172 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4173 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
4174 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
4175 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
4176 return -EINVAL;
4177 }
4178
4179 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4180
4181 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4182 params.auth_type = nla_get_u32(
4183 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004184 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4185 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004186 return -EINVAL;
4187 } else
4188 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4189
4190 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4191 NL80211_MAX_NR_CIPHER_SUITES);
4192 if (err)
4193 return err;
4194
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304195 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4196 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4197 return -EOPNOTSUPP;
4198 params.inactivity_timeout = nla_get_u16(
4199 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4200 }
4201
Johannes Berg53cabad2012-11-14 15:17:28 +01004202 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4203 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4204 return -EINVAL;
4205 params.p2p_ctwindow =
4206 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4207 if (params.p2p_ctwindow > 127)
4208 return -EINVAL;
4209 if (params.p2p_ctwindow != 0 &&
4210 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4211 return -EINVAL;
4212 }
4213
4214 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4215 u8 tmp;
4216
4217 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4218 return -EINVAL;
4219 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4220 if (tmp > 1)
4221 return -EINVAL;
4222 params.p2p_opp_ps = tmp;
4223 if (params.p2p_opp_ps != 0 &&
4224 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4225 return -EINVAL;
4226 }
4227
Johannes Bergaa430da2012-05-16 23:50:18 +02004228 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004229 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4230 if (err)
4231 return err;
4232 } else if (wdev->preset_chandef.chan) {
4233 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004234 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004235 return -EINVAL;
4236
Arik Nemtsov923b3522015-07-08 15:41:44 +03004237 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4238 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004239 return -EINVAL;
4240
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304241 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4242 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4243 if (err)
4244 return err;
4245
Johannes Berg8564e382016-09-19 09:44:44 +02004246 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4247 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304248 if (err)
4249 return err;
4250 }
4251
Eliad Peller18998c32014-09-10 14:07:34 +03004252 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4253 params.smps_mode =
4254 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4255 switch (params.smps_mode) {
4256 case NL80211_SMPS_OFF:
4257 break;
4258 case NL80211_SMPS_STATIC:
4259 if (!(rdev->wiphy.features &
4260 NL80211_FEATURE_STATIC_SMPS))
4261 return -EINVAL;
4262 break;
4263 case NL80211_SMPS_DYNAMIC:
4264 if (!(rdev->wiphy.features &
4265 NL80211_FEATURE_DYNAMIC_SMPS))
4266 return -EINVAL;
4267 break;
4268 default:
4269 return -EINVAL;
4270 }
4271 } else {
4272 params.smps_mode = NL80211_SMPS_OFF;
4273 }
4274
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304275 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4276 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4277 return -EOPNOTSUPP;
4278
Ola Olsson4baf6be2015-10-29 07:04:58 +01004279 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4280 params.acl = parse_acl_data(&rdev->wiphy, info);
4281 if (IS_ERR(params.acl))
4282 return PTR_ERR(params.acl);
4283 }
4284
Johannes Berg66cd7942017-02-07 22:40:44 +02004285 nl80211_calculate_ap_params(&params);
4286
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004287 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004288 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004289 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004290 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004291 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004292 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004293 wdev->ssid_len = params.ssid_len;
4294 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05004295
4296 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4297 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004298 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004299 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304300
4301 kfree(params.acl);
4302
Johannes Berg56d18932011-05-09 18:41:15 +02004303 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004304}
4305
Johannes Berg88600202012-02-13 15:17:18 +01004306static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4307{
4308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4309 struct net_device *dev = info->user_ptr[1];
4310 struct wireless_dev *wdev = dev->ieee80211_ptr;
4311 struct cfg80211_beacon_data params;
4312 int err;
4313
4314 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4315 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4316 return -EOPNOTSUPP;
4317
4318 if (!rdev->ops->change_beacon)
4319 return -EOPNOTSUPP;
4320
4321 if (!wdev->beacon_interval)
4322 return -EINVAL;
4323
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004324 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004325 if (err)
4326 return err;
4327
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004328 wdev_lock(wdev);
4329 err = rdev_change_beacon(rdev, dev, &params);
4330 wdev_unlock(wdev);
4331
4332 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004333}
4334
4335static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004336{
Johannes Berg4c476992010-10-04 21:36:35 +02004337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4338 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004339
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004340 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004341}
4342
Johannes Berg5727ef12007-12-19 02:03:34 +01004343static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4344 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4345 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4346 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004347 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004348 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004349 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004350};
4351
Johannes Bergeccb8e82009-05-11 21:57:56 +03004352static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004353 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004354 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004355{
4356 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004357 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004358 int flag;
4359
Johannes Bergeccb8e82009-05-11 21:57:56 +03004360 /*
4361 * Try parsing the new attribute first so userspace
4362 * can specify both for older kernels.
4363 */
4364 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4365 if (nla) {
4366 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004367
Johannes Bergeccb8e82009-05-11 21:57:56 +03004368 sta_flags = nla_data(nla);
4369 params->sta_flags_mask = sta_flags->mask;
4370 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004371 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004372 if ((params->sta_flags_mask |
4373 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4374 return -EINVAL;
4375 return 0;
4376 }
4377
4378 /* if present, parse the old attribute */
4379
4380 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004381 if (!nla)
4382 return 0;
4383
Johannes Bergfceb6432017-04-12 14:34:07 +02004384 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004385 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004386 return -EINVAL;
4387
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004388 /*
4389 * Only allow certain flags for interface types so that
4390 * other attributes are silently ignored. Remember that
4391 * this is backward compatibility code with old userspace
4392 * and shouldn't be hit in other cases anyway.
4393 */
4394 switch (iftype) {
4395 case NL80211_IFTYPE_AP:
4396 case NL80211_IFTYPE_AP_VLAN:
4397 case NL80211_IFTYPE_P2P_GO:
4398 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4399 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4400 BIT(NL80211_STA_FLAG_WME) |
4401 BIT(NL80211_STA_FLAG_MFP);
4402 break;
4403 case NL80211_IFTYPE_P2P_CLIENT:
4404 case NL80211_IFTYPE_STATION:
4405 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4406 BIT(NL80211_STA_FLAG_TDLS_PEER);
4407 break;
4408 case NL80211_IFTYPE_MESH_POINT:
4409 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4410 BIT(NL80211_STA_FLAG_MFP) |
4411 BIT(NL80211_STA_FLAG_AUTHORIZED);
4412 default:
4413 return -EINVAL;
4414 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004415
Johannes Berg3383b5a2012-05-10 20:14:43 +02004416 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4417 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004418 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004419
Johannes Berg3383b5a2012-05-10 20:14:43 +02004420 /* no longer support new API additions in old API */
4421 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4422 return -EINVAL;
4423 }
4424 }
4425
Johannes Berg5727ef12007-12-19 02:03:34 +01004426 return 0;
4427}
4428
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004429static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4430 int attr)
4431{
4432 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004433 u32 bitrate;
4434 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004435 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004436
4437 rate = nla_nest_start(msg, attr);
4438 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004439 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004440
4441 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4442 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004443 /* report 16-bit bitrate only if we can */
4444 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004445 if (bitrate > 0 &&
4446 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4447 return false;
4448 if (bitrate_compat > 0 &&
4449 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4450 return false;
4451
Johannes Bergb51f3be2015-01-15 16:14:02 +01004452 switch (info->bw) {
4453 case RATE_INFO_BW_5:
4454 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4455 break;
4456 case RATE_INFO_BW_10:
4457 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4458 break;
4459 default:
4460 WARN_ON(1);
4461 /* fall through */
4462 case RATE_INFO_BW_20:
4463 rate_flg = 0;
4464 break;
4465 case RATE_INFO_BW_40:
4466 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4467 break;
4468 case RATE_INFO_BW_80:
4469 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4470 break;
4471 case RATE_INFO_BW_160:
4472 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4473 break;
4474 }
4475
4476 if (rate_flg && nla_put_flag(msg, rate_flg))
4477 return false;
4478
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004479 if (info->flags & RATE_INFO_FLAGS_MCS) {
4480 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4481 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004482 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4483 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4484 return false;
4485 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4486 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4487 return false;
4488 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4489 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004490 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4491 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4492 return false;
4493 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004494
4495 nla_nest_end(msg, rate);
4496 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004497}
4498
Felix Fietkau119363c2013-04-22 16:29:30 +02004499static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4500 int id)
4501{
4502 void *attr;
4503 int i = 0;
4504
4505 if (!mask)
4506 return true;
4507
4508 attr = nla_nest_start(msg, id);
4509 if (!attr)
4510 return false;
4511
4512 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4513 if (!(mask & BIT(i)))
4514 continue;
4515
4516 if (nla_put_u8(msg, i, signal[i]))
4517 return false;
4518 }
4519
4520 nla_nest_end(msg, attr);
4521
4522 return true;
4523}
4524
Johannes Bergcf5ead82014-11-14 17:14:00 +01004525static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4526 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004527 struct cfg80211_registered_device *rdev,
4528 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004529 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004530{
4531 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004532 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004533
Johannes Bergcf5ead82014-11-14 17:14:00 +01004534 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004535 if (!hdr)
4536 return -1;
4537
David S. Miller9360ffd2012-03-29 04:41:26 -04004538 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4539 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4540 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4541 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004542
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4544 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004545 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004546
4547#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004548 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304549 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004550 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4551 sinfo->memb)) \
4552 goto nla_put_failure; \
4553 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004554#define PUT_SINFO_U64(attr, memb) do { \
4555 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4556 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4557 sinfo->memb, NL80211_STA_INFO_PAD)) \
4558 goto nla_put_failure; \
4559 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004560
4561 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4562 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4563
4564 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4565 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004566 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004567 (u32)sinfo->rx_bytes))
4568 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004569
4570 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4571 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004572 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4573 (u32)sinfo->tx_bytes))
4574 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004575
Johannes Bergd686b922016-04-26 09:54:11 +02004576 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4577 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004578 PUT_SINFO(LLID, llid, u16);
4579 PUT_SINFO(PLID, plid, u16);
4580 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004581 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004582
John W. Linville66266b32012-03-15 13:25:41 -04004583 switch (rdev->wiphy.signal_type) {
4584 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004585 PUT_SINFO(SIGNAL, signal, u8);
4586 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004587 break;
4588 default:
4589 break;
4590 }
Johannes Berg319090b2014-11-17 14:08:11 +01004591 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004592 if (!nl80211_put_signal(msg, sinfo->chains,
4593 sinfo->chain_signal,
4594 NL80211_STA_INFO_CHAIN_SIGNAL))
4595 goto nla_put_failure;
4596 }
Johannes Berg319090b2014-11-17 14:08:11 +01004597 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004598 if (!nl80211_put_signal(msg, sinfo->chains,
4599 sinfo->chain_signal_avg,
4600 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4601 goto nla_put_failure;
4602 }
Johannes Berg319090b2014-11-17 14:08:11 +01004603 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004604 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4605 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004606 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004607 }
Johannes Berg319090b2014-11-17 14:08:11 +01004608 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004609 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4610 NL80211_STA_INFO_RX_BITRATE))
4611 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004612 }
Johannes Berg319090b2014-11-17 14:08:11 +01004613
4614 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4615 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4616 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4617 PUT_SINFO(TX_FAILED, tx_failed, u32);
4618 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4619 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4620 PUT_SINFO(LOCAL_PM, local_pm, u32);
4621 PUT_SINFO(PEER_PM, peer_pm, u32);
4622 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4623
4624 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004625 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4626 if (!bss_param)
4627 goto nla_put_failure;
4628
David S. Miller9360ffd2012-03-29 04:41:26 -04004629 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4630 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4631 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4632 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4633 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4634 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4635 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4636 sinfo->bss_param.dtim_period) ||
4637 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4638 sinfo->bss_param.beacon_interval))
4639 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004640
4641 nla_nest_end(msg, bss_param);
4642 }
Johannes Berg319090b2014-11-17 14:08:11 +01004643 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004644 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4645 sizeof(struct nl80211_sta_flag_update),
4646 &sinfo->sta_flags))
4647 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004648
Johannes Bergd686b922016-04-26 09:54:11 +02004649 PUT_SINFO_U64(T_OFFSET, t_offset);
4650 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4651 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004652 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +05304653 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05304654 if (wiphy_ext_feature_isset(&rdev->wiphy,
4655 NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT))
4656 PUT_SINFO(DATA_ACK_SIGNAL_AVG, avg_ack_signal, s8);
Johannes Berg319090b2014-11-17 14:08:11 +01004657
4658#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004659#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004660
Arend van Spriel8689c052018-05-10 13:50:12 +02004661 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01004662 struct nlattr *tidsattr;
4663 int tid;
4664
4665 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4666 if (!tidsattr)
4667 goto nla_put_failure;
4668
4669 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4670 struct cfg80211_tid_stats *tidstats;
4671 struct nlattr *tidattr;
4672
4673 tidstats = &sinfo->pertid[tid];
4674
4675 if (!tidstats->filled)
4676 continue;
4677
4678 tidattr = nla_nest_start(msg, tid + 1);
4679 if (!tidattr)
4680 goto nla_put_failure;
4681
Johannes Bergd686b922016-04-26 09:54:11 +02004682#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004683 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004684 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4685 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004686 goto nla_put_failure; \
4687 } while (0)
4688
Johannes Bergd686b922016-04-26 09:54:11 +02004689 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4690 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4691 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4692 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004693
Johannes Bergd686b922016-04-26 09:54:11 +02004694#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02004695 if ((tidstats->filled &
4696 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
4697 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
4698 NL80211_TID_STATS_TXQ_STATS))
4699 goto nla_put_failure;
4700
Johannes Berg6de39802014-12-19 12:34:00 +01004701 nla_nest_end(msg, tidattr);
4702 }
4703
4704 nla_nest_end(msg, tidsattr);
4705 }
4706
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004707 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004708
Johannes Berg319090b2014-11-17 14:08:11 +01004709 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004710 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4711 sinfo->assoc_req_ies))
4712 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004713
Johannes Berg7ea3e112018-05-18 11:40:44 +02004714 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01004715 genlmsg_end(msg, hdr);
4716 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004717
4718 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02004719 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07004720 genlmsg_cancel(msg, hdr);
4721 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004722}
4723
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004724static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004725 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726{
Johannes Berg73887fd2018-05-18 09:57:55 +02004727 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004728 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004729 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004730 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004731 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004732 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004733
Johannes Bergea90e0d2017-03-15 14:26:04 +01004734 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004735 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004736 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004737 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004738
Johannes Berg97990a02013-04-19 01:02:55 +02004739 if (!wdev->netdev) {
4740 err = -EINVAL;
4741 goto out_err;
4742 }
4743
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004744 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004745 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004746 goto out_err;
4747 }
4748
Johannes Bergbba95fe2008-07-29 13:22:51 +02004749 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02004750 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004751 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02004752 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004753 if (err == -ENOENT)
4754 break;
4755 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004756 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004757
Johannes Bergcf5ead82014-11-14 17:14:00 +01004758 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004759 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004760 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004761 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02004762 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02004763 goto out;
4764
4765 sta_idx++;
4766 }
4767
Johannes Bergbba95fe2008-07-29 13:22:51 +02004768 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004769 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004770 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004771 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004772 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004773
4774 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004775}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004776
Johannes Berg5727ef12007-12-19 02:03:34 +01004777static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4778{
Johannes Berg4c476992010-10-04 21:36:35 +02004779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4780 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02004781 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004782 struct sk_buff *msg;
4783 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004784 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004785
Johannes Berg73887fd2018-05-18 09:57:55 +02004786 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004787
Johannes Berg73887fd2018-05-18 09:57:55 +02004788 if (!info->attrs[NL80211_ATTR_MAC])
4789 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004790
4791 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4792
Johannes Berg73887fd2018-05-18 09:57:55 +02004793 if (!rdev->ops->get_station)
4794 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004795
Johannes Berg73887fd2018-05-18 09:57:55 +02004796 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004797 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02004798 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004799
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02004801 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05004802 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02004803 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02004804 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004805
Johannes Bergcf5ead82014-11-14 17:14:00 +01004806 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4807 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02004808 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004809 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02004810 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02004811 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004812
Johannes Berg73887fd2018-05-18 09:57:55 +02004813 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004814}
4815
Johannes Berg77ee7c82013-02-15 00:48:33 +01004816int cfg80211_check_station_change(struct wiphy *wiphy,
4817 struct station_parameters *params,
4818 enum cfg80211_station_type statype)
4819{
Ayala Bekere4208422015-10-23 11:20:06 +03004820 if (params->listen_interval != -1 &&
4821 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004822 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004823
Ayala Beker17b94242016-03-17 15:41:38 +02004824 if (params->support_p2p_ps != -1 &&
4825 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4826 return -EINVAL;
4827
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004828 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004829 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4830 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004831 return -EINVAL;
4832
4833 /* When you run into this, adjust the code below for the new flag */
4834 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4835
4836 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004837 case CFG80211_STA_MESH_PEER_KERNEL:
4838 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004839 /*
4840 * No ignoring the TDLS flag here -- the userspace mesh
4841 * code doesn't have the bug of including TDLS in the
4842 * mask everywhere.
4843 */
4844 if (params->sta_flags_mask &
4845 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4846 BIT(NL80211_STA_FLAG_MFP) |
4847 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4848 return -EINVAL;
4849 break;
4850 case CFG80211_STA_TDLS_PEER_SETUP:
4851 case CFG80211_STA_TDLS_PEER_ACTIVE:
4852 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4853 return -EINVAL;
4854 /* ignore since it can't change */
4855 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4856 break;
4857 default:
4858 /* disallow mesh-specific things */
4859 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4860 return -EINVAL;
4861 if (params->local_pm)
4862 return -EINVAL;
4863 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4864 return -EINVAL;
4865 }
4866
4867 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4868 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4869 /* TDLS can't be set, ... */
4870 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4871 return -EINVAL;
4872 /*
4873 * ... but don't bother the driver with it. This works around
4874 * a hostapd/wpa_supplicant issue -- it always includes the
4875 * TLDS_PEER flag in the mask even for AP mode.
4876 */
4877 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4878 }
4879
Ayala Beker47edb112015-09-21 15:49:53 +03004880 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4881 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004882 /* reject other things that can't change */
4883 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4884 return -EINVAL;
4885 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4886 return -EINVAL;
4887 if (params->supported_rates)
4888 return -EINVAL;
4889 if (params->ext_capab || params->ht_capa || params->vht_capa)
4890 return -EINVAL;
4891 }
4892
Ayala Beker47edb112015-09-21 15:49:53 +03004893 if (statype != CFG80211_STA_AP_CLIENT &&
4894 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004895 if (params->vlan)
4896 return -EINVAL;
4897 }
4898
4899 switch (statype) {
4900 case CFG80211_STA_AP_MLME_CLIENT:
4901 /* Use this only for authorizing/unauthorizing a station */
4902 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4903 return -EOPNOTSUPP;
4904 break;
4905 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004906 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004907 /* accept only the listed bits */
4908 if (params->sta_flags_mask &
4909 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4910 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4911 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4912 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4913 BIT(NL80211_STA_FLAG_WME) |
4914 BIT(NL80211_STA_FLAG_MFP)))
4915 return -EINVAL;
4916
4917 /* but authenticated/associated only if driver handles it */
4918 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4919 params->sta_flags_mask &
4920 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4921 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4922 return -EINVAL;
4923 break;
4924 case CFG80211_STA_IBSS:
4925 case CFG80211_STA_AP_STA:
4926 /* reject any changes other than AUTHORIZED */
4927 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4928 return -EINVAL;
4929 break;
4930 case CFG80211_STA_TDLS_PEER_SETUP:
4931 /* reject any changes other than AUTHORIZED or WME */
4932 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4933 BIT(NL80211_STA_FLAG_WME)))
4934 return -EINVAL;
4935 /* force (at least) rates when authorizing */
4936 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4937 !params->supported_rates)
4938 return -EINVAL;
4939 break;
4940 case CFG80211_STA_TDLS_PEER_ACTIVE:
4941 /* reject any changes */
4942 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004943 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004944 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4945 return -EINVAL;
4946 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004947 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004948 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4949 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004950 return -EINVAL;
4951 break;
4952 }
4953
Beni Lev06f7c882016-07-19 19:28:56 +03004954 /*
4955 * Older kernel versions ignored this attribute entirely, so don't
4956 * reject attempts to update it but mark it as unused instead so the
4957 * driver won't look at the data.
4958 */
4959 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4960 statype != CFG80211_STA_TDLS_PEER_SETUP)
4961 params->opmode_notif_used = false;
4962
Johannes Berg77ee7c82013-02-15 00:48:33 +01004963 return 0;
4964}
4965EXPORT_SYMBOL(cfg80211_check_station_change);
4966
Johannes Berg5727ef12007-12-19 02:03:34 +01004967/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004968 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004969 */
Johannes Berg80b99892011-11-18 16:23:01 +01004970static struct net_device *get_vlan(struct genl_info *info,
4971 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004972{
Johannes Berg463d0182009-07-14 00:33:35 +02004973 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004974 struct net_device *v;
4975 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004976
Johannes Berg80b99892011-11-18 16:23:01 +01004977 if (!vlanattr)
4978 return NULL;
4979
4980 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4981 if (!v)
4982 return ERR_PTR(-ENODEV);
4983
4984 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4985 ret = -EINVAL;
4986 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004987 }
Johannes Berg80b99892011-11-18 16:23:01 +01004988
Johannes Berg77ee7c82013-02-15 00:48:33 +01004989 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4990 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4991 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4992 ret = -EINVAL;
4993 goto error;
4994 }
4995
Johannes Berg80b99892011-11-18 16:23:01 +01004996 if (!netif_running(v)) {
4997 ret = -ENETDOWN;
4998 goto error;
4999 }
5000
5001 return v;
5002 error:
5003 dev_put(v);
5004 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005005}
5006
Johannes Berg94e860f2014-01-20 23:58:15 +01005007static const struct nla_policy
5008nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005009 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5010 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5011};
5012
Johannes Bergff276692013-02-15 00:09:01 +01005013static int nl80211_parse_sta_wme(struct genl_info *info,
5014 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005015{
Jouni Malinendf881292013-02-14 21:10:54 +02005016 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5017 struct nlattr *nla;
5018 int err;
5019
Jouni Malinendf881292013-02-14 21:10:54 +02005020 /* parse WME attributes if present */
5021 if (!info->attrs[NL80211_ATTR_STA_WME])
5022 return 0;
5023
5024 nla = info->attrs[NL80211_ATTR_STA_WME];
5025 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02005026 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005027 if (err)
5028 return err;
5029
5030 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5031 params->uapsd_queues = nla_get_u8(
5032 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5033 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5034 return -EINVAL;
5035
5036 if (tb[NL80211_STA_WME_MAX_SP])
5037 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5038
5039 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5040 return -EINVAL;
5041
5042 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5043
5044 return 0;
5045}
5046
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305047static int nl80211_parse_sta_channel_info(struct genl_info *info,
5048 struct station_parameters *params)
5049{
5050 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5051 params->supported_channels =
5052 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5053 params->supported_channels_len =
5054 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5055 /*
5056 * Need to include at least one (first channel, number of
5057 * channels) tuple for each subband, and must have proper
5058 * tuples for the rest of the data as well.
5059 */
5060 if (params->supported_channels_len < 2)
5061 return -EINVAL;
5062 if (params->supported_channels_len % 2)
5063 return -EINVAL;
5064 }
5065
5066 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5067 params->supported_oper_classes =
5068 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5069 params->supported_oper_classes_len =
5070 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5071 /*
5072 * The value of the Length field of the Supported Operating
5073 * Classes element is between 2 and 253.
5074 */
5075 if (params->supported_oper_classes_len < 2 ||
5076 params->supported_oper_classes_len > 253)
5077 return -EINVAL;
5078 }
5079 return 0;
5080}
5081
Johannes Bergff276692013-02-15 00:09:01 +01005082static int nl80211_set_station_tdls(struct genl_info *info,
5083 struct station_parameters *params)
5084{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305085 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005086 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005087 if (info->attrs[NL80211_ATTR_PEER_AID])
5088 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005089 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5090 params->ht_capa =
5091 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5092 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5093 params->vht_capa =
5094 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5095
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305096 err = nl80211_parse_sta_channel_info(info, params);
5097 if (err)
5098 return err;
5099
Johannes Bergff276692013-02-15 00:09:01 +01005100 return nl80211_parse_sta_wme(info, params);
5101}
5102
Johannes Berg5727ef12007-12-19 02:03:34 +01005103static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5104{
Johannes Berg4c476992010-10-04 21:36:35 +02005105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005106 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005107 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005108 u8 *mac_addr;
5109 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005110
5111 memset(&params, 0, sizeof(params));
5112
Johannes Berg77ee7c82013-02-15 00:48:33 +01005113 if (!rdev->ops->change_station)
5114 return -EOPNOTSUPP;
5115
Ayala Bekere4208422015-10-23 11:20:06 +03005116 /*
5117 * AID and listen_interval properties can be set only for unassociated
5118 * station. Include these parameters here and will check them in
5119 * cfg80211_check_station_change().
5120 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005121 if (info->attrs[NL80211_ATTR_STA_AID])
5122 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005123
5124 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5125 params.listen_interval =
5126 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5127 else
5128 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005129
Ayala Beker17b94242016-03-17 15:41:38 +02005130 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5131 u8 tmp;
5132
5133 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5134 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5135 return -EINVAL;
5136
5137 params.support_p2p_ps = tmp;
5138 } else {
5139 params.support_p2p_ps = -1;
5140 }
5141
Johannes Berg5727ef12007-12-19 02:03:34 +01005142 if (!info->attrs[NL80211_ATTR_MAC])
5143 return -EINVAL;
5144
5145 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5146
5147 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5148 params.supported_rates =
5149 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5150 params.supported_rates_len =
5151 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5152 }
5153
Jouni Malinen9d62a982013-02-14 21:10:13 +02005154 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5155 params.capability =
5156 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5157 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5158 }
5159
5160 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5161 params.ext_capab =
5162 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5163 params.ext_capab_len =
5164 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5165 }
5166
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005167 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005168 return -EINVAL;
5169
Johannes Bergf8bacc22013-02-14 23:27:01 +01005170 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005171 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005172 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5173 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5174 return -EINVAL;
5175 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005176
Johannes Bergf8bacc22013-02-14 23:27:01 +01005177 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005178 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005179 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
5180 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
5181 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005182 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
5183 params.peer_aid = nla_get_u16(
5184 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
5185 if (params.peer_aid > IEEE80211_MAX_AID)
5186 return -EINVAL;
5187 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01005188 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5189 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005190
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005191 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
5192 enum nl80211_mesh_power_mode pm = nla_get_u32(
5193 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5194
5195 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
5196 pm > NL80211_MESH_POWER_MAX)
5197 return -EINVAL;
5198
5199 params.local_pm = pm;
5200 }
5201
Beni Lev06f7c882016-07-19 19:28:56 +03005202 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5203 params.opmode_notif_used = true;
5204 params.opmode_notif =
5205 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5206 }
5207
Johannes Berg77ee7c82013-02-15 00:48:33 +01005208 /* Include parameters for TDLS peer (will check later) */
5209 err = nl80211_set_station_tdls(info, &params);
5210 if (err)
5211 return err;
5212
5213 params.vlan = get_vlan(info, rdev);
5214 if (IS_ERR(params.vlan))
5215 return PTR_ERR(params.vlan);
5216
Johannes Berga97f4422009-06-18 17:23:43 +02005217 switch (dev->ieee80211_ptr->iftype) {
5218 case NL80211_IFTYPE_AP:
5219 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005220 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005221 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005222 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005223 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005224 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005225 break;
5226 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005227 err = -EOPNOTSUPP;
5228 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005229 }
5230
Johannes Berg77ee7c82013-02-15 00:48:33 +01005231 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005232 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005233
Johannes Berg77ee7c82013-02-15 00:48:33 +01005234 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005235 if (params.vlan)
5236 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005237
Johannes Berg5727ef12007-12-19 02:03:34 +01005238 return err;
5239}
5240
5241static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5242{
Johannes Berg4c476992010-10-04 21:36:35 +02005243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005244 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005245 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005246 struct station_parameters params;
5247 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005248 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5249 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005250
5251 memset(&params, 0, sizeof(params));
5252
Johannes Berg984c3112013-02-14 23:43:25 +01005253 if (!rdev->ops->add_station)
5254 return -EOPNOTSUPP;
5255
Johannes Berg5727ef12007-12-19 02:03:34 +01005256 if (!info->attrs[NL80211_ATTR_MAC])
5257 return -EINVAL;
5258
Johannes Berg5727ef12007-12-19 02:03:34 +01005259 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5260 return -EINVAL;
5261
5262 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5263 return -EINVAL;
5264
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005265 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5266 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005267 return -EINVAL;
5268
Johannes Berg5727ef12007-12-19 02:03:34 +01005269 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5270 params.supported_rates =
5271 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5272 params.supported_rates_len =
5273 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5274 params.listen_interval =
5275 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005276
Ayala Beker17b94242016-03-17 15:41:38 +02005277 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5278 u8 tmp;
5279
5280 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5281 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5282 return -EINVAL;
5283
5284 params.support_p2p_ps = tmp;
5285 } else {
5286 /*
5287 * if not specified, assume it's supported for P2P GO interface,
5288 * and is NOT supported for AP interface
5289 */
5290 params.support_p2p_ps =
5291 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5292 }
5293
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005294 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005295 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005296 else
5297 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005298 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5299 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005300
Jouni Malinen9d62a982013-02-14 21:10:13 +02005301 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5302 params.capability =
5303 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5304 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5305 }
5306
5307 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5308 params.ext_capab =
5309 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5310 params.ext_capab_len =
5311 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5312 }
5313
Jouni Malinen36aedc92008-08-25 11:58:58 +03005314 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5315 params.ht_capa =
5316 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005317
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005318 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5319 params.vht_capa =
5320 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5321
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005322 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5323 params.opmode_notif_used = true;
5324 params.opmode_notif =
5325 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5326 }
5327
Johannes Bergf8bacc22013-02-14 23:27:01 +01005328 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005329 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005330 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5331 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5332 return -EINVAL;
5333 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005334
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305335 err = nl80211_parse_sta_channel_info(info, &params);
5336 if (err)
5337 return err;
5338
Johannes Bergff276692013-02-15 00:09:01 +01005339 err = nl80211_parse_sta_wme(info, &params);
5340 if (err)
5341 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005342
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005343 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005344 return -EINVAL;
5345
Johannes Berg496fcc22015-03-12 08:53:27 +02005346 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5347 * as userspace might just pass through the capabilities from the IEs
5348 * directly, rather than enforcing this restriction and returning an
5349 * error in this case.
5350 */
5351 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5352 params.ht_capa = NULL;
5353 params.vht_capa = NULL;
5354 }
5355
Johannes Berg77ee7c82013-02-15 00:48:33 +01005356 /* When you run into this, adjust the code below for the new flag */
5357 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5358
Johannes Bergbdd90d52011-12-14 12:20:27 +01005359 switch (dev->ieee80211_ptr->iftype) {
5360 case NL80211_IFTYPE_AP:
5361 case NL80211_IFTYPE_AP_VLAN:
5362 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005363 /* ignore WME attributes if iface/sta is not capable */
5364 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5365 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5366 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005367
Johannes Bergbdd90d52011-12-14 12:20:27 +01005368 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005369 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5370 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005371 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005372 /* but don't bother the driver with it */
5373 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005374
Johannes Bergd582cff2012-10-26 17:53:44 +02005375 /* allow authenticated/associated only if driver handles it */
5376 if (!(rdev->wiphy.features &
5377 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005378 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005379 return -EINVAL;
5380
Johannes Bergbda95eb2015-11-26 16:26:13 +01005381 /* Older userspace, or userspace wanting to be compatible with
5382 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5383 * and assoc flags in the mask, but assumes the station will be
5384 * added as associated anyway since this was the required driver
5385 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5386 * introduced.
5387 * In order to not bother drivers with this quirk in the API
5388 * set the flags in both the mask and set for new stations in
5389 * this case.
5390 */
5391 if (!(params.sta_flags_mask & auth_assoc)) {
5392 params.sta_flags_mask |= auth_assoc;
5393 params.sta_flags_set |= auth_assoc;
5394 }
5395
Johannes Bergbdd90d52011-12-14 12:20:27 +01005396 /* must be last in here for error handling */
5397 params.vlan = get_vlan(info, rdev);
5398 if (IS_ERR(params.vlan))
5399 return PTR_ERR(params.vlan);
5400 break;
5401 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005402 /* ignore uAPSD data */
5403 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5404
Johannes Bergd582cff2012-10-26 17:53:44 +02005405 /* associated is disallowed */
5406 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5407 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005408 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005409 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5410 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005411 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005412 break;
5413 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005414 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005415 /* ignore uAPSD data */
5416 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5417
Johannes Berg77ee7c82013-02-15 00:48:33 +01005418 /* these are disallowed */
5419 if (params.sta_flags_mask &
5420 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5421 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005422 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005423 /* Only TDLS peers can be added */
5424 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5425 return -EINVAL;
5426 /* Can only add if TDLS ... */
5427 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5428 return -EOPNOTSUPP;
5429 /* ... with external setup is supported */
5430 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5431 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005432 /*
5433 * Older wpa_supplicant versions always mark the TDLS peer
5434 * as authorized, but it shouldn't yet be.
5435 */
5436 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005437 break;
5438 default:
5439 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005440 }
5441
Johannes Bergbdd90d52011-12-14 12:20:27 +01005442 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005443
Hila Gonene35e4d22012-06-27 17:19:42 +03005444 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005445
Johannes Berg5727ef12007-12-19 02:03:34 +01005446 if (params.vlan)
5447 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005448 return err;
5449}
5450
5451static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5452{
Johannes Berg4c476992010-10-04 21:36:35 +02005453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5454 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005455 struct station_del_parameters params;
5456
5457 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005458
5459 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005460 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005461
Johannes Berge80cf852009-05-11 14:43:13 +02005462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005463 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005464 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005465 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5466 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005467
Johannes Berg4c476992010-10-04 21:36:35 +02005468 if (!rdev->ops->del_station)
5469 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005470
Jouni Malinen98856862014-10-20 13:20:45 +03005471 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5472 params.subtype =
5473 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5474 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5475 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5476 return -EINVAL;
5477 } else {
5478 /* Default to Deauthentication frame */
5479 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5480 }
5481
5482 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5483 params.reason_code =
5484 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5485 if (params.reason_code == 0)
5486 return -EINVAL; /* 0 is reserved */
5487 } else {
5488 /* Default to reason code 2 */
5489 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5490 }
5491
Jouni Malinen89c771e2014-10-10 20:52:40 +03005492 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005493}
5494
Eric W. Biederman15e47302012-09-07 20:12:54 +00005495static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005496 int flags, struct net_device *dev,
5497 u8 *dst, u8 *next_hop,
5498 struct mpath_info *pinfo)
5499{
5500 void *hdr;
5501 struct nlattr *pinfoattr;
5502
Henning Rogge1ef4c852014-11-04 16:14:58 +01005503 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005504 if (!hdr)
5505 return -1;
5506
David S. Miller9360ffd2012-03-29 04:41:26 -04005507 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5508 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5509 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5510 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5511 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005512
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005513 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5514 if (!pinfoattr)
5515 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005516 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5517 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5518 pinfo->frame_qlen))
5519 goto nla_put_failure;
5520 if (((pinfo->filled & MPATH_INFO_SN) &&
5521 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5522 ((pinfo->filled & MPATH_INFO_METRIC) &&
5523 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5524 pinfo->metric)) ||
5525 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5526 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5527 pinfo->exptime)) ||
5528 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5529 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5530 pinfo->flags)) ||
5531 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5532 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5533 pinfo->discovery_timeout)) ||
5534 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5535 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5536 pinfo->discovery_retries)))
5537 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005538
5539 nla_nest_end(msg, pinfoattr);
5540
Johannes Berg053c0952015-01-16 22:09:00 +01005541 genlmsg_end(msg, hdr);
5542 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005543
5544 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005545 genlmsg_cancel(msg, hdr);
5546 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005547}
5548
5549static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005550 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005551{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005552 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005553 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005554 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005555 u8 dst[ETH_ALEN];
5556 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005557 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005558 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005559
Johannes Bergea90e0d2017-03-15 14:26:04 +01005560 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005561 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005562 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005563 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005565 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005566 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005567 goto out_err;
5568 }
5569
Johannes Berg97990a02013-04-19 01:02:55 +02005570 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005571 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005572 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005573 }
5574
Johannes Bergbba95fe2008-07-29 13:22:51 +02005575 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005576 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005577 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005578 if (err == -ENOENT)
5579 break;
5580 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005581 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005582
Eric W. Biederman15e47302012-09-07 20:12:54 +00005583 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005584 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005585 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005586 &pinfo) < 0)
5587 goto out;
5588
5589 path_idx++;
5590 }
5591
Johannes Bergbba95fe2008-07-29 13:22:51 +02005592 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005593 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005594 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005595 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005596 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005597 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005598}
5599
5600static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5601{
Johannes Berg4c476992010-10-04 21:36:35 +02005602 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005603 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005604 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005605 struct mpath_info pinfo;
5606 struct sk_buff *msg;
5607 u8 *dst = NULL;
5608 u8 next_hop[ETH_ALEN];
5609
5610 memset(&pinfo, 0, sizeof(pinfo));
5611
5612 if (!info->attrs[NL80211_ATTR_MAC])
5613 return -EINVAL;
5614
5615 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5616
Johannes Berg4c476992010-10-04 21:36:35 +02005617 if (!rdev->ops->get_mpath)
5618 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005619
Johannes Berg4c476992010-10-04 21:36:35 +02005620 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5621 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005622
Hila Gonene35e4d22012-06-27 17:19:42 +03005623 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005624 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005625 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005626
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005627 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005628 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005629 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005630
Eric W. Biederman15e47302012-09-07 20:12:54 +00005631 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005632 dev, dst, next_hop, &pinfo) < 0) {
5633 nlmsg_free(msg);
5634 return -ENOBUFS;
5635 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005636
Johannes Berg4c476992010-10-04 21:36:35 +02005637 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005638}
5639
5640static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5641{
Johannes Berg4c476992010-10-04 21:36:35 +02005642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5643 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005644 u8 *dst = NULL;
5645 u8 *next_hop = NULL;
5646
5647 if (!info->attrs[NL80211_ATTR_MAC])
5648 return -EINVAL;
5649
5650 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5651 return -EINVAL;
5652
5653 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5654 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5655
Johannes Berg4c476992010-10-04 21:36:35 +02005656 if (!rdev->ops->change_mpath)
5657 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005658
Johannes Berg4c476992010-10-04 21:36:35 +02005659 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5660 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005661
Hila Gonene35e4d22012-06-27 17:19:42 +03005662 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005663}
Johannes Berg4c476992010-10-04 21:36:35 +02005664
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005665static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5666{
Johannes Berg4c476992010-10-04 21:36:35 +02005667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5668 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005669 u8 *dst = NULL;
5670 u8 *next_hop = NULL;
5671
5672 if (!info->attrs[NL80211_ATTR_MAC])
5673 return -EINVAL;
5674
5675 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5676 return -EINVAL;
5677
5678 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5679 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5680
Johannes Berg4c476992010-10-04 21:36:35 +02005681 if (!rdev->ops->add_mpath)
5682 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005683
Johannes Berg4c476992010-10-04 21:36:35 +02005684 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5685 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005686
Hila Gonene35e4d22012-06-27 17:19:42 +03005687 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005688}
5689
5690static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5691{
Johannes Berg4c476992010-10-04 21:36:35 +02005692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5693 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005694 u8 *dst = NULL;
5695
5696 if (info->attrs[NL80211_ATTR_MAC])
5697 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5698
Johannes Berg4c476992010-10-04 21:36:35 +02005699 if (!rdev->ops->del_mpath)
5700 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005701
Hila Gonene35e4d22012-06-27 17:19:42 +03005702 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005703}
5704
Henning Rogge66be7d22014-09-12 08:58:49 +02005705static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5706{
5707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5708 int err;
5709 struct net_device *dev = info->user_ptr[1];
5710 struct mpath_info pinfo;
5711 struct sk_buff *msg;
5712 u8 *dst = NULL;
5713 u8 mpp[ETH_ALEN];
5714
5715 memset(&pinfo, 0, sizeof(pinfo));
5716
5717 if (!info->attrs[NL80211_ATTR_MAC])
5718 return -EINVAL;
5719
5720 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5721
5722 if (!rdev->ops->get_mpp)
5723 return -EOPNOTSUPP;
5724
5725 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5726 return -EOPNOTSUPP;
5727
5728 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5729 if (err)
5730 return err;
5731
5732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5733 if (!msg)
5734 return -ENOMEM;
5735
5736 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5737 dev, dst, mpp, &pinfo) < 0) {
5738 nlmsg_free(msg);
5739 return -ENOBUFS;
5740 }
5741
5742 return genlmsg_reply(msg, info);
5743}
5744
5745static int nl80211_dump_mpp(struct sk_buff *skb,
5746 struct netlink_callback *cb)
5747{
5748 struct mpath_info pinfo;
5749 struct cfg80211_registered_device *rdev;
5750 struct wireless_dev *wdev;
5751 u8 dst[ETH_ALEN];
5752 u8 mpp[ETH_ALEN];
5753 int path_idx = cb->args[2];
5754 int err;
5755
Johannes Bergea90e0d2017-03-15 14:26:04 +01005756 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005757 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5758 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005759 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005760
5761 if (!rdev->ops->dump_mpp) {
5762 err = -EOPNOTSUPP;
5763 goto out_err;
5764 }
5765
5766 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5767 err = -EOPNOTSUPP;
5768 goto out_err;
5769 }
5770
5771 while (1) {
5772 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5773 mpp, &pinfo);
5774 if (err == -ENOENT)
5775 break;
5776 if (err)
5777 goto out_err;
5778
5779 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5780 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5781 wdev->netdev, dst, mpp,
5782 &pinfo) < 0)
5783 goto out;
5784
5785 path_idx++;
5786 }
5787
5788 out:
5789 cb->args[2] = path_idx;
5790 err = skb->len;
5791 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005792 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005793 return err;
5794}
5795
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005796static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5797{
Johannes Berg4c476992010-10-04 21:36:35 +02005798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5799 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005800 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005801 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005802 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005803
5804 memset(&params, 0, sizeof(params));
5805 /* default to not changing parameters */
5806 params.use_cts_prot = -1;
5807 params.use_short_preamble = -1;
5808 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005809 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005810 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005811 params.p2p_ctwindow = -1;
5812 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005813
5814 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5815 params.use_cts_prot =
5816 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5817 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5818 params.use_short_preamble =
5819 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5820 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5821 params.use_short_slot_time =
5822 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005823 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5824 params.basic_rates =
5825 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5826 params.basic_rates_len =
5827 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5828 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005829 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5830 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005831 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5832 params.ht_opmode =
5833 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005834
Johannes Berg53cabad2012-11-14 15:17:28 +01005835 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5836 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5837 return -EINVAL;
5838 params.p2p_ctwindow =
5839 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5840 if (params.p2p_ctwindow < 0)
5841 return -EINVAL;
5842 if (params.p2p_ctwindow != 0 &&
5843 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5844 return -EINVAL;
5845 }
5846
5847 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5848 u8 tmp;
5849
5850 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5851 return -EINVAL;
5852 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5853 if (tmp > 1)
5854 return -EINVAL;
5855 params.p2p_opp_ps = tmp;
5856 if (params.p2p_opp_ps &&
5857 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5858 return -EINVAL;
5859 }
5860
Johannes Berg4c476992010-10-04 21:36:35 +02005861 if (!rdev->ops->change_bss)
5862 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005863
Johannes Berg074ac8d2010-09-16 14:58:22 +02005864 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5866 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005867
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005868 wdev_lock(wdev);
5869 err = rdev_change_bss(rdev, dev, &params);
5870 wdev_unlock(wdev);
5871
5872 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005873}
5874
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005875static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5876{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005877 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005878 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005879 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005880 u32 owner_nlportid;
5881
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005882 /*
5883 * You should only get this when cfg80211 hasn't yet initialized
5884 * completely when built-in to the kernel right between the time
5885 * window between nl80211_init() and regulatory_init(), if that is
5886 * even possible.
5887 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005888 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005889 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005890
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005891 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5892 user_reg_hint_type =
5893 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5894 else
5895 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5896
5897 switch (user_reg_hint_type) {
5898 case NL80211_USER_REG_HINT_USER:
5899 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005900 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5901 return -EINVAL;
5902
5903 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5904 return regulatory_hint_user(data, user_reg_hint_type);
5905 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005906 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5907 owner_nlportid = info->snd_portid;
5908 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5909 } else {
5910 owner_nlportid = 0;
5911 is_indoor = true;
5912 }
5913
5914 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005915 default:
5916 return -EINVAL;
5917 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005918}
5919
Johannes Berg1ea4ff32017-09-13 16:07:22 +02005920static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
5921{
5922 return reg_reload_regdb();
5923}
5924
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005925static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005926 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005927{
Johannes Berg4c476992010-10-04 21:36:35 +02005928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005929 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005930 struct wireless_dev *wdev = dev->ieee80211_ptr;
5931 struct mesh_config cur_params;
5932 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005933 void *hdr;
5934 struct nlattr *pinfoattr;
5935 struct sk_buff *msg;
5936
Johannes Berg29cbe682010-12-03 09:20:44 +01005937 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5938 return -EOPNOTSUPP;
5939
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005940 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005941 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005942
Johannes Berg29cbe682010-12-03 09:20:44 +01005943 wdev_lock(wdev);
5944 /* If not connected, get default parameters */
5945 if (!wdev->mesh_id_len)
5946 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5947 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005948 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005949 wdev_unlock(wdev);
5950
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005951 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005952 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005953
5954 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005956 if (!msg)
5957 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005958 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005959 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005960 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005961 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005962 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005963 if (!pinfoattr)
5964 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005965 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5966 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5967 cur_params.dot11MeshRetryTimeout) ||
5968 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5969 cur_params.dot11MeshConfirmTimeout) ||
5970 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5971 cur_params.dot11MeshHoldingTimeout) ||
5972 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5973 cur_params.dot11MeshMaxPeerLinks) ||
5974 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5975 cur_params.dot11MeshMaxRetries) ||
5976 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5977 cur_params.dot11MeshTTL) ||
5978 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5979 cur_params.element_ttl) ||
5980 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5981 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005982 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5983 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005984 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5985 cur_params.dot11MeshHWMPmaxPREQretries) ||
5986 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5987 cur_params.path_refresh_time) ||
5988 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5989 cur_params.min_discovery_timeout) ||
5990 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5991 cur_params.dot11MeshHWMPactivePathTimeout) ||
5992 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5993 cur_params.dot11MeshHWMPpreqMinInterval) ||
5994 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5995 cur_params.dot11MeshHWMPperrMinInterval) ||
5996 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5997 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5998 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5999 cur_params.dot11MeshHWMPRootMode) ||
6000 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6001 cur_params.dot11MeshHWMPRannInterval) ||
6002 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6003 cur_params.dot11MeshGateAnnouncementProtocol) ||
6004 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6005 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006006 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006007 cur_params.rssi_threshold) ||
6008 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006009 cur_params.ht_opmode) ||
6010 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6011 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6012 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006013 cur_params.dot11MeshHWMProotInterval) ||
6014 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006015 cur_params.dot11MeshHWMPconfirmationInterval) ||
6016 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6017 cur_params.power_mode) ||
6018 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006019 cur_params.dot11MeshAwakeWindowDuration) ||
6020 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
6021 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04006022 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006023 nla_nest_end(msg, pinfoattr);
6024 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006025 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006026
Johannes Berg3b858752009-03-12 09:55:09 +01006027 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006028 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006029 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006030 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006031}
6032
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006033static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006034 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
6035 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
6036 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
6037 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
6038 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
6039 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01006040 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006041 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07006042 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006043 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6044 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
6045 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
6046 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
6047 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08006048 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006049 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07006050 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07006051 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07006052 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08006053 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006054 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
6055 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006056 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
6057 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006058 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006059 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
6060 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006061 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006062};
6063
Javier Cardonac80d5452010-12-16 17:37:49 -08006064static const struct nla_policy
6065 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006066 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006067 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6068 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006069 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006070 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006071 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07006072 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006073 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07006074 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006075};
6076
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006077static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
6078{
6079 u8 val = nla_get_u8(nla);
6080 if (val < min || val > max)
6081 return -EINVAL;
6082 *out = val;
6083 return 0;
6084}
6085
6086static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
6087{
6088 u8 val = nla_get_u8(nla);
6089 if (val < min || val > max)
6090 return -EINVAL;
6091 *out = val;
6092 return 0;
6093}
6094
6095static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
6096{
6097 u16 val = nla_get_u16(nla);
6098 if (val < min || val > max)
6099 return -EINVAL;
6100 *out = val;
6101 return 0;
6102}
6103
6104static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
6105{
6106 u32 val = nla_get_u32(nla);
6107 if (val < min || val > max)
6108 return -EINVAL;
6109 *out = val;
6110 return 0;
6111}
6112
6113static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
6114{
6115 s32 val = nla_get_s32(nla);
6116 if (val < min || val > max)
6117 return -EINVAL;
6118 *out = val;
6119 return 0;
6120}
6121
Johannes Bergff9a71a2016-08-11 14:59:53 +02006122static int nl80211_check_power_mode(const struct nlattr *nla,
6123 enum nl80211_mesh_power_mode min,
6124 enum nl80211_mesh_power_mode max,
6125 enum nl80211_mesh_power_mode *out)
6126{
6127 u32 val = nla_get_u32(nla);
6128 if (val < min || val > max)
6129 return -EINVAL;
6130 *out = val;
6131 return 0;
6132}
6133
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006134static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006135 struct mesh_config *cfg,
6136 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006137{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006138 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006139 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006140 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006141
Marco Porschea54fba2013-01-07 16:04:48 +01006142#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
6143do { \
6144 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006145 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01006146 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01006147 mask |= (1 << (attr - 1)); \
6148 } \
6149} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006150
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006151 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006152 return -EINVAL;
6153 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006154 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02006155 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006156 return -EINVAL;
6157
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006158 /* This makes sure that there aren't more than 32 mesh config
6159 * parameters (otherwise our bitfield scheme would not work.) */
6160 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6161
6162 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01006163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006164 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006165 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006167 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006168 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006169 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006170 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006171 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006172 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006173 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006174 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006175 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006176 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006177 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006178 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006179 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006180 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006181 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006182 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006183 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006184 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006185 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006186 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
6187 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006188 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006189 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006190 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006191 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006192 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006193 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006194 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006195 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006196 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006197 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006198 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006199 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
6200 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006201 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006202 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006203 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006204 1, 65535, mask,
6205 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006206 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08006207 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006208 1, 65535, mask,
6209 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006210 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006211 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006212 dot11MeshHWMPnetDiameterTraversalTime,
6213 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006214 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006215 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
6217 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006218 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006219 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
6220 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006221 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00006222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006223 dot11MeshGateAnnouncementProtocol, 0, 1,
6224 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006225 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006227 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006228 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08006229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006230 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006231 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09006232 /*
6233 * Check HT operation mode based on
6234 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6235 */
6236 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6237 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6238
6239 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6240 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6241 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6242 return -EINVAL;
6243
6244 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6245 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6246 return -EINVAL;
6247
6248 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6249 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6250 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6251 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6252 return -EINVAL;
6253 break;
6254 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6255 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6256 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6257 return -EINVAL;
6258 break;
6259 }
6260 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006261 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006262 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006263 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006264 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006265 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006266 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006267 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006268 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006269 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006271 dot11MeshHWMPconfirmationInterval,
6272 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006273 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006274 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006275 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6276 NL80211_MESH_POWER_ACTIVE,
6277 NL80211_MESH_POWER_MAX,
6278 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006279 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6281 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006282 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006284 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006285 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006286 if (mask_out)
6287 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006288
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006289 return 0;
6290
6291#undef FILL_IN_MESH_PARAM_IF_SET
6292}
6293
Javier Cardonac80d5452010-12-16 17:37:49 -08006294static int nl80211_parse_mesh_setup(struct genl_info *info,
6295 struct mesh_setup *setup)
6296{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006298 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6299
6300 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6301 return -EINVAL;
6302 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6303 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006304 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006305 return -EINVAL;
6306
Javier Cardonad299a1f2012-03-31 11:31:33 -07006307 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6308 setup->sync_method =
6309 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6310 IEEE80211_SYNC_METHOD_VENDOR :
6311 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6312
Javier Cardonac80d5452010-12-16 17:37:49 -08006313 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6314 setup->path_sel_proto =
6315 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6316 IEEE80211_PATH_PROTOCOL_VENDOR :
6317 IEEE80211_PATH_PROTOCOL_HWMP;
6318
6319 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6320 setup->path_metric =
6321 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6322 IEEE80211_PATH_METRIC_VENDOR :
6323 IEEE80211_PATH_METRIC_AIRTIME;
6324
Javier Cardona581a8b02011-04-07 15:08:27 -07006325 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006326 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006327 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006328 if (!is_valid_ie_attr(ieattr))
6329 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006330 setup->ie = nla_data(ieattr);
6331 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006332 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006333 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6334 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6335 return -EINVAL;
6336 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006337 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6338 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006339 if (setup->is_secure)
6340 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006341
Colleen Twitty6e16d902013-05-08 11:45:59 -07006342 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6343 if (!setup->user_mpm)
6344 return -EINVAL;
6345 setup->auth_id =
6346 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6347 }
6348
Javier Cardonac80d5452010-12-16 17:37:49 -08006349 return 0;
6350}
6351
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006352static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006353 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006354{
6355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6356 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006357 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006358 struct mesh_config cfg;
6359 u32 mask;
6360 int err;
6361
Johannes Berg29cbe682010-12-03 09:20:44 +01006362 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6363 return -EOPNOTSUPP;
6364
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006365 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006366 return -EOPNOTSUPP;
6367
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006368 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006369 if (err)
6370 return err;
6371
Johannes Berg29cbe682010-12-03 09:20:44 +01006372 wdev_lock(wdev);
6373 if (!wdev->mesh_id_len)
6374 err = -ENOLINK;
6375
6376 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006377 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006378
6379 wdev_unlock(wdev);
6380
6381 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006382}
6383
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006384static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6385 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006386{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006387 struct nlattr *nl_reg_rules;
6388 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006389
Johannes Berg458f4f92012-12-06 15:47:38 +01006390 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6391 (regdom->dfs_region &&
6392 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006393 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006394
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006395 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6396 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006397 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006398
Johannes Berg458f4f92012-12-06 15:47:38 +01006399 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006400 struct nlattr *nl_reg_rule;
6401 const struct ieee80211_reg_rule *reg_rule;
6402 const struct ieee80211_freq_range *freq_range;
6403 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006404 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006405
Johannes Berg458f4f92012-12-06 15:47:38 +01006406 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006407 freq_range = &reg_rule->freq_range;
6408 power_rule = &reg_rule->power_rule;
6409
6410 nl_reg_rule = nla_nest_start(msg, i);
6411 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006412 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006413
Janusz Dziedzic97524822014-01-30 09:52:20 +01006414 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6415 if (!max_bandwidth_khz)
6416 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6417 reg_rule);
6418
David S. Miller9360ffd2012-03-29 04:41:26 -04006419 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6420 reg_rule->flags) ||
6421 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6422 freq_range->start_freq_khz) ||
6423 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6424 freq_range->end_freq_khz) ||
6425 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006426 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006427 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6428 power_rule->max_antenna_gain) ||
6429 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006430 power_rule->max_eirp) ||
6431 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6432 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006433 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006434
6435 nla_nest_end(msg, nl_reg_rule);
6436 }
6437
6438 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006439 return 0;
6440
6441nla_put_failure:
6442 return -EMSGSIZE;
6443}
6444
6445static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6446{
6447 const struct ieee80211_regdomain *regdom = NULL;
6448 struct cfg80211_registered_device *rdev;
6449 struct wiphy *wiphy = NULL;
6450 struct sk_buff *msg;
6451 void *hdr;
6452
6453 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6454 if (!msg)
6455 return -ENOBUFS;
6456
6457 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6458 NL80211_CMD_GET_REG);
6459 if (!hdr)
6460 goto put_failure;
6461
6462 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006463 bool self_managed;
6464
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006465 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6466 if (IS_ERR(rdev)) {
6467 nlmsg_free(msg);
6468 return PTR_ERR(rdev);
6469 }
6470
6471 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006472 self_managed = wiphy->regulatory_flags &
6473 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006474 regdom = get_wiphy_regdom(wiphy);
6475
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006476 /* a self-managed-reg device must have a private regdom */
6477 if (WARN_ON(!regdom && self_managed)) {
6478 nlmsg_free(msg);
6479 return -EINVAL;
6480 }
6481
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006482 if (regdom &&
6483 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6484 goto nla_put_failure;
6485 }
6486
6487 if (!wiphy && reg_last_request_cell_base() &&
6488 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6489 NL80211_USER_REG_HINT_CELL_BASE))
6490 goto nla_put_failure;
6491
6492 rcu_read_lock();
6493
6494 if (!regdom)
6495 regdom = rcu_dereference(cfg80211_regdomain);
6496
6497 if (nl80211_put_regdom(regdom, msg))
6498 goto nla_put_failure_rcu;
6499
6500 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006501
6502 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006503 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006504
Johannes Berg458f4f92012-12-06 15:47:38 +01006505nla_put_failure_rcu:
6506 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006507nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006508put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006509 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006510 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006511}
6512
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006513static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6514 u32 seq, int flags, struct wiphy *wiphy,
6515 const struct ieee80211_regdomain *regdom)
6516{
6517 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6518 NL80211_CMD_GET_REG);
6519
6520 if (!hdr)
6521 return -1;
6522
Michal Kubecek0a833c22017-11-15 13:09:32 +01006523 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006524
6525 if (nl80211_put_regdom(regdom, msg))
6526 goto nla_put_failure;
6527
6528 if (!wiphy && reg_last_request_cell_base() &&
6529 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6530 NL80211_USER_REG_HINT_CELL_BASE))
6531 goto nla_put_failure;
6532
6533 if (wiphy &&
6534 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6535 goto nla_put_failure;
6536
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006537 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6538 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6539 goto nla_put_failure;
6540
Johannes Berg053c0952015-01-16 22:09:00 +01006541 genlmsg_end(msg, hdr);
6542 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006543
6544nla_put_failure:
6545 genlmsg_cancel(msg, hdr);
6546 return -EMSGSIZE;
6547}
6548
6549static int nl80211_get_reg_dump(struct sk_buff *skb,
6550 struct netlink_callback *cb)
6551{
6552 const struct ieee80211_regdomain *regdom = NULL;
6553 struct cfg80211_registered_device *rdev;
6554 int err, reg_idx, start = cb->args[2];
6555
6556 rtnl_lock();
6557
6558 if (cfg80211_regdomain && start == 0) {
6559 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6560 NLM_F_MULTI, NULL,
6561 rtnl_dereference(cfg80211_regdomain));
6562 if (err < 0)
6563 goto out_err;
6564 }
6565
6566 /* the global regdom is idx 0 */
6567 reg_idx = 1;
6568 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6569 regdom = get_wiphy_regdom(&rdev->wiphy);
6570 if (!regdom)
6571 continue;
6572
6573 if (++reg_idx <= start)
6574 continue;
6575
6576 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6577 NLM_F_MULTI, &rdev->wiphy, regdom);
6578 if (err < 0) {
6579 reg_idx--;
6580 break;
6581 }
6582 }
6583
6584 cb->args[2] = reg_idx;
6585 err = skb->len;
6586out_err:
6587 rtnl_unlock();
6588 return err;
6589}
6590
Johannes Bergb6863032015-10-15 09:25:18 +02006591#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6592static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6593 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6594 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6595 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6596 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6597 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6598 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6599 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6600};
6601
6602static int parse_reg_rule(struct nlattr *tb[],
6603 struct ieee80211_reg_rule *reg_rule)
6604{
6605 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6606 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6607
6608 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6609 return -EINVAL;
6610 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6611 return -EINVAL;
6612 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6613 return -EINVAL;
6614 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6615 return -EINVAL;
6616 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6617 return -EINVAL;
6618
6619 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6620
6621 freq_range->start_freq_khz =
6622 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6623 freq_range->end_freq_khz =
6624 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6625 freq_range->max_bandwidth_khz =
6626 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6627
6628 power_rule->max_eirp =
6629 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6630
6631 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6632 power_rule->max_antenna_gain =
6633 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6634
6635 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6636 reg_rule->dfs_cac_ms =
6637 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6638
6639 return 0;
6640}
6641
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006642static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6643{
6644 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6645 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006646 char *alpha2;
6647 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006648 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006649 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006650 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006651
6652 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6653 return -EINVAL;
6654
6655 if (!info->attrs[NL80211_ATTR_REG_RULES])
6656 return -EINVAL;
6657
6658 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6659
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006660 if (info->attrs[NL80211_ATTR_DFS_REGION])
6661 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6662
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006663 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006664 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006665 num_rules++;
6666 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006667 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006668 }
6669
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006670 if (!reg_is_valid_request(alpha2))
6671 return -EINVAL;
6672
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006673 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006674 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006675
6676 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006677 if (!rd)
6678 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006679
6680 rd->n_reg_rules = num_rules;
6681 rd->alpha2[0] = alpha2[0];
6682 rd->alpha2[1] = alpha2[1];
6683
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006684 /*
6685 * Disable DFS master mode if the DFS region was
6686 * not supported or known on this kernel.
6687 */
6688 if (reg_supported_dfs_region(dfs_region))
6689 rd->dfs_region = dfs_region;
6690
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006691 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006692 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006693 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006694 nl_reg_rule, reg_rule_policy,
6695 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006696 if (r)
6697 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006698 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6699 if (r)
6700 goto bad_reg;
6701
6702 rule_idx++;
6703
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006704 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6705 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006706 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006707 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006708 }
6709
Johannes Berg06627992016-06-09 10:40:09 +02006710 /* set_regdom takes ownership of rd */
6711 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006712 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006713 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006714 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006715}
Johannes Bergb6863032015-10-15 09:25:18 +02006716#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006717
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006718static int validate_scan_freqs(struct nlattr *freqs)
6719{
6720 struct nlattr *attr1, *attr2;
6721 int n_channels = 0, tmp1, tmp2;
6722
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006723 nla_for_each_nested(attr1, freqs, tmp1)
6724 if (nla_len(attr1) != sizeof(u32))
6725 return 0;
6726
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006727 nla_for_each_nested(attr1, freqs, tmp1) {
6728 n_channels++;
6729 /*
6730 * Some hardware has a limited channel list for
6731 * scanning, and it is pretty much nonsensical
6732 * to scan for a channel twice, so disallow that
6733 * and don't require drivers to check that the
6734 * channel list they get isn't longer than what
6735 * they can scan, as long as they can scan all
6736 * the channels they registered at once.
6737 */
6738 nla_for_each_nested(attr2, freqs, tmp2)
6739 if (attr1 != attr2 &&
6740 nla_get_u32(attr1) == nla_get_u32(attr2))
6741 return 0;
6742 }
6743
6744 return n_channels;
6745}
6746
Johannes Berg57fbcce2016-04-12 15:56:15 +02006747static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006748{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006749 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006750}
6751
6752static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6753 struct cfg80211_bss_selection *bss_select)
6754{
6755 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6756 struct nlattr *nest;
6757 int err;
6758 bool found = false;
6759 int i;
6760
6761 /* only process one nested attribute */
6762 nest = nla_data(nla);
6763 if (!nla_ok(nest, nla_len(nest)))
6764 return -EINVAL;
6765
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006766 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006767 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006768 if (err)
6769 return err;
6770
6771 /* only one attribute may be given */
6772 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6773 if (attr[i]) {
6774 if (found)
6775 return -EINVAL;
6776 found = true;
6777 }
6778 }
6779
6780 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6781
6782 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6783 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6784
6785 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6786 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6787 bss_select->param.band_pref =
6788 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6789 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6790 return -EINVAL;
6791 }
6792
6793 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6794 struct nl80211_bss_select_rssi_adjust *adj_param;
6795
6796 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6797 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6798 bss_select->param.adjust.band = adj_param->band;
6799 bss_select->param.adjust.delta = adj_param->delta;
6800 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6801 return -EINVAL;
6802 }
6803
6804 /* user-space did not provide behaviour attribute */
6805 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6806 return -EINVAL;
6807
6808 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6809 return -EINVAL;
6810
6811 return 0;
6812}
6813
Johannes Bergad2b26a2014-06-12 21:39:05 +02006814static int nl80211_parse_random_mac(struct nlattr **attrs,
6815 u8 *mac_addr, u8 *mac_addr_mask)
6816{
6817 int i;
6818
6819 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006820 eth_zero_addr(mac_addr);
6821 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006822 mac_addr[0] = 0x2;
6823 mac_addr_mask[0] = 0x3;
6824
6825 return 0;
6826 }
6827
6828 /* need both or none */
6829 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6830 return -EINVAL;
6831
6832 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6833 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6834
6835 /* don't allow or configure an mcast address */
6836 if (!is_multicast_ether_addr(mac_addr_mask) ||
6837 is_multicast_ether_addr(mac_addr))
6838 return -EINVAL;
6839
6840 /*
6841 * allow users to pass a MAC address that has bits set outside
6842 * of the mask, but don't bother drivers with having to deal
6843 * with such bits
6844 */
6845 for (i = 0; i < ETH_ALEN; i++)
6846 mac_addr[i] &= mac_addr_mask[i];
6847
6848 return 0;
6849}
6850
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306851static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6852{
6853 ASSERT_WDEV_LOCK(wdev);
6854
6855 if (!cfg80211_beaconing_iface_active(wdev))
6856 return true;
6857
6858 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6859 return true;
6860
6861 return regulatory_pre_cac_allowed(wdev->wiphy);
6862}
6863
Roee Zamir2d23d072017-08-06 11:38:22 +03006864static int
6865nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6866 void *request, struct nlattr **attrs,
6867 bool is_sched_scan)
6868{
6869 u8 *mac_addr, *mac_addr_mask;
6870 u32 *flags;
6871 enum nl80211_feature_flags randomness_flag;
6872
6873 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6874 return 0;
6875
6876 if (is_sched_scan) {
6877 struct cfg80211_sched_scan_request *req = request;
6878
6879 randomness_flag = wdev ?
6880 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6881 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6882 flags = &req->flags;
6883 mac_addr = req->mac_addr;
6884 mac_addr_mask = req->mac_addr_mask;
6885 } else {
6886 struct cfg80211_scan_request *req = request;
6887
6888 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6889 flags = &req->flags;
6890 mac_addr = req->mac_addr;
6891 mac_addr_mask = req->mac_addr_mask;
6892 }
6893
6894 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
6895
Sunil Dutt5037a002018-01-25 17:13:37 +02006896 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6897 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
6898 ((*flags & NL80211_SCAN_FLAG_LOW_SPAN) &&
6899 !wiphy_ext_feature_isset(wiphy,
6900 NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) ||
6901 ((*flags & NL80211_SCAN_FLAG_LOW_POWER) &&
6902 !wiphy_ext_feature_isset(wiphy,
6903 NL80211_EXT_FEATURE_LOW_POWER_SCAN)) ||
6904 ((*flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) &&
6905 !wiphy_ext_feature_isset(wiphy,
6906 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN)))
Roee Zamir2d23d072017-08-06 11:38:22 +03006907 return -EOPNOTSUPP;
6908
6909 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6910 int err;
6911
6912 if (!(wiphy->features & randomness_flag) ||
6913 (wdev && wdev->current_bss))
6914 return -EOPNOTSUPP;
6915
6916 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
6917 if (err)
6918 return err;
6919 }
6920
6921 if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) &&
6922 !wiphy_ext_feature_isset(wiphy,
6923 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME))
6924 return -EOPNOTSUPP;
6925
6926 if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) &&
6927 !wiphy_ext_feature_isset(wiphy,
6928 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP))
6929 return -EOPNOTSUPP;
6930
6931 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
6932 !wiphy_ext_feature_isset(wiphy,
6933 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
6934 return -EOPNOTSUPP;
6935
6936 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) &&
6937 !wiphy_ext_feature_isset(wiphy,
6938 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE))
6939 return -EOPNOTSUPP;
6940
6941 return 0;
6942}
6943
Johannes Berg2a519312009-02-10 21:25:55 +01006944static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6945{
Johannes Berg4c476992010-10-04 21:36:35 +02006946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006947 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006948 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006949 struct nlattr *attr;
6950 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006951 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006952 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006953
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006954 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6955 return -EINVAL;
6956
Johannes Berg79c97e92009-07-07 03:56:12 +02006957 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006958
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006959 if (wdev->iftype == NL80211_IFTYPE_NAN)
6960 return -EOPNOTSUPP;
6961
Johannes Berg4c476992010-10-04 21:36:35 +02006962 if (!rdev->ops->scan)
6963 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006964
Johannes Bergf9d15d12014-01-22 11:14:19 +02006965 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006966 err = -EBUSY;
6967 goto unlock;
6968 }
Johannes Berg2a519312009-02-10 21:25:55 +01006969
6970 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006971 n_channels = validate_scan_freqs(
6972 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006973 if (!n_channels) {
6974 err = -EINVAL;
6975 goto unlock;
6976 }
Johannes Berg2a519312009-02-10 21:25:55 +01006977 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006978 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006979 }
6980
6981 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6982 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6983 n_ssids++;
6984
Johannes Bergf9f47522013-03-19 15:04:07 +01006985 if (n_ssids > wiphy->max_scan_ssids) {
6986 err = -EINVAL;
6987 goto unlock;
6988 }
Johannes Berg2a519312009-02-10 21:25:55 +01006989
Jouni Malinen70692ad2009-02-16 19:39:13 +02006990 if (info->attrs[NL80211_ATTR_IE])
6991 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6992 else
6993 ie_len = 0;
6994
Johannes Bergf9f47522013-03-19 15:04:07 +01006995 if (ie_len > wiphy->max_scan_ie_len) {
6996 err = -EINVAL;
6997 goto unlock;
6998 }
Johannes Berg18a83652009-03-31 12:12:05 +02006999
Johannes Berg2a519312009-02-10 21:25:55 +01007000 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007001 + sizeof(*request->ssids) * n_ssids
7002 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007003 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007004 if (!request) {
7005 err = -ENOMEM;
7006 goto unlock;
7007 }
Johannes Berg2a519312009-02-10 21:25:55 +01007008
Johannes Berg2a519312009-02-10 21:25:55 +01007009 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007010 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007011 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007012 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007013 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007014 request->ie = (void *)(request->ssids + n_ssids);
7015 else
7016 request->ie = (void *)(request->channels + n_channels);
7017 }
Johannes Berg2a519312009-02-10 21:25:55 +01007018
Johannes Berg584991d2009-11-02 13:32:03 +01007019 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007020 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7021 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007022 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007023 struct ieee80211_channel *chan;
7024
7025 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7026
7027 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007028 err = -EINVAL;
7029 goto out_free;
7030 }
Johannes Berg584991d2009-11-02 13:32:03 +01007031
7032 /* ignore disabled channels */
7033 if (chan->flags & IEEE80211_CHAN_DISABLED)
7034 continue;
7035
7036 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007037 i++;
7038 }
7039 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007040 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007041
Johannes Berg2a519312009-02-10 21:25:55 +01007042 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007043 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007044 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007045
Johannes Berg2a519312009-02-10 21:25:55 +01007046 if (!wiphy->bands[band])
7047 continue;
7048 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007049 struct ieee80211_channel *chan;
7050
7051 chan = &wiphy->bands[band]->channels[j];
7052
7053 if (chan->flags & IEEE80211_CHAN_DISABLED)
7054 continue;
7055
7056 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007057 i++;
7058 }
7059 }
7060 }
7061
Johannes Berg584991d2009-11-02 13:32:03 +01007062 if (!i) {
7063 err = -EINVAL;
7064 goto out_free;
7065 }
7066
7067 request->n_channels = i;
7068
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307069 wdev_lock(wdev);
7070 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7071 struct ieee80211_channel *chan;
7072
7073 if (request->n_channels != 1) {
7074 wdev_unlock(wdev);
7075 err = -EBUSY;
7076 goto out_free;
7077 }
7078
7079 chan = request->channels[0];
7080 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7081 wdev_unlock(wdev);
7082 err = -EBUSY;
7083 goto out_free;
7084 }
7085 }
7086 wdev_unlock(wdev);
7087
Johannes Berg2a519312009-02-10 21:25:55 +01007088 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007089 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007090 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007091 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007092 err = -EINVAL;
7093 goto out_free;
7094 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007095 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007096 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007097 i++;
7098 }
7099 }
7100
Jouni Malinen70692ad2009-02-16 19:39:13 +02007101 if (info->attrs[NL80211_ATTR_IE]) {
7102 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02007103 memcpy((void *)request->ie,
7104 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007105 request->ie_len);
7106 }
7107
Johannes Berg57fbcce2016-04-12 15:56:15 +02007108 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007109 if (wiphy->bands[i])
7110 request->rates[i] =
7111 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007112
7113 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7114 nla_for_each_nested(attr,
7115 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7116 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007117 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007118
Johannes Berg57fbcce2016-04-12 15:56:15 +02007119 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007120 err = -EINVAL;
7121 goto out_free;
7122 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007123
7124 if (!wiphy->bands[band])
7125 continue;
7126
Johannes Berg34850ab2011-07-18 18:08:35 +02007127 err = ieee80211_get_ratemask(wiphy->bands[band],
7128 nla_data(attr),
7129 nla_len(attr),
7130 &request->rates[band]);
7131 if (err)
7132 goto out_free;
7133 }
7134 }
7135
Avraham Stern1d762502016-07-05 17:10:13 +03007136 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7137 if (!wiphy_ext_feature_isset(wiphy,
7138 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7139 err = -EOPNOTSUPP;
7140 goto out_free;
7141 }
7142
7143 request->duration =
7144 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7145 request->duration_mandatory =
7146 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7147 }
7148
Roee Zamir2d23d072017-08-06 11:38:22 +03007149 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7150 false);
7151 if (err)
7152 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007153
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307154 request->no_cck =
7155 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7156
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007157 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7158 * BSSID to scan for. This was problematic because that same attribute
7159 * was already used for another purpose (local random MAC address). The
7160 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7161 * compatibility with older userspace components, also use the
7162 * NL80211_ATTR_MAC value here if it can be determined to be used for
7163 * the specific BSSID use case instead of the random MAC address
7164 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7165 */
7166 if (info->attrs[NL80211_ATTR_BSSID])
7167 memcpy(request->bssid,
7168 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7169 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7170 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007171 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7172 ETH_ALEN);
7173 else
7174 eth_broadcast_addr(request->bssid);
7175
Johannes Bergfd014282012-06-18 19:17:03 +02007176 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007177 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007178 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007179
Johannes Berg79c97e92009-07-07 03:56:12 +02007180 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007181 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007182
Johannes Berg463d0182009-07-14 00:33:35 +02007183 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007184 nl80211_send_scan_start(rdev, wdev);
7185 if (wdev->netdev)
7186 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007187 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007188 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007189 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007190 kfree(request);
7191 }
Johannes Berg3b858752009-03-12 09:55:09 +01007192
Johannes Bergf9f47522013-03-19 15:04:07 +01007193 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007194 return err;
7195}
7196
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307197static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7198{
7199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7200 struct wireless_dev *wdev = info->user_ptr[1];
7201
7202 if (!rdev->ops->abort_scan)
7203 return -EOPNOTSUPP;
7204
7205 if (rdev->scan_msg)
7206 return 0;
7207
7208 if (!rdev->scan_req)
7209 return -ENOENT;
7210
7211 rdev_abort_scan(rdev, wdev);
7212 return 0;
7213}
7214
Avraham Stern3b06d272015-10-12 09:51:34 +03007215static int
7216nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7217 struct cfg80211_sched_scan_request *request,
7218 struct nlattr **attrs)
7219{
7220 int tmp, err, i = 0;
7221 struct nlattr *attr;
7222
7223 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7224 u32 interval;
7225
7226 /*
7227 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007228 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007229 * case one scan plan will be set with the specified scan
7230 * interval and infinite number of iterations.
7231 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007232 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7233 if (!interval)
7234 return -EINVAL;
7235
7236 request->scan_plans[0].interval =
7237 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7238 if (!request->scan_plans[0].interval)
7239 return -EINVAL;
7240
7241 if (request->scan_plans[0].interval >
7242 wiphy->max_sched_scan_plan_interval)
7243 request->scan_plans[0].interval =
7244 wiphy->max_sched_scan_plan_interval;
7245
7246 return 0;
7247 }
7248
7249 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7250 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7251
7252 if (WARN_ON(i >= n_plans))
7253 return -EINVAL;
7254
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007255 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007256 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007257 if (err)
7258 return err;
7259
7260 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7261 return -EINVAL;
7262
7263 request->scan_plans[i].interval =
7264 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7265 if (!request->scan_plans[i].interval ||
7266 request->scan_plans[i].interval >
7267 wiphy->max_sched_scan_plan_interval)
7268 return -EINVAL;
7269
7270 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7271 request->scan_plans[i].iterations =
7272 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7273 if (!request->scan_plans[i].iterations ||
7274 (request->scan_plans[i].iterations >
7275 wiphy->max_sched_scan_plan_iterations))
7276 return -EINVAL;
7277 } else if (i < n_plans - 1) {
7278 /*
7279 * All scan plans but the last one must specify
7280 * a finite number of iterations
7281 */
7282 return -EINVAL;
7283 }
7284
7285 i++;
7286 }
7287
7288 /*
7289 * The last scan plan must not specify the number of
7290 * iterations, it is supposed to run infinitely
7291 */
7292 if (request->scan_plans[n_plans - 1].iterations)
7293 return -EINVAL;
7294
7295 return 0;
7296}
7297
Luciano Coelho256da022014-11-10 16:13:46 +02007298static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007299nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007300 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007301{
7302 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007303 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007304 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007305 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007306 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007307 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007308 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007309
Luciano Coelho256da022014-11-10 16:13:46 +02007310 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7311 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007312
Luciano Coelho256da022014-11-10 16:13:46 +02007313 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007314 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007315 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007316 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007317 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007318 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007319 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007320 }
7321
Luciano Coelho256da022014-11-10 16:13:46 +02007322 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7323 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007324 tmp)
7325 n_ssids++;
7326
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007327 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007328 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007329
Johannes Bergea73cbc2014-01-24 10:53:53 +01007330 /*
7331 * First, count the number of 'real' matchsets. Due to an issue with
7332 * the old implementation, matchsets containing only the RSSI attribute
7333 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7334 * RSSI for all matchsets, rather than their own matchset for reporting
7335 * all APs with a strong RSSI. This is needed to be compatible with
7336 * older userspace that treated a matchset with only the RSSI as the
7337 * global RSSI for all other matchsets - if there are other matchsets.
7338 */
Luciano Coelho256da022014-11-10 16:13:46 +02007339 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007340 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007341 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007342 tmp) {
7343 struct nlattr *rssi;
7344
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007345 err = nla_parse_nested(tb,
7346 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007347 attr, nl80211_match_policy,
7348 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007349 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007350 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007351
7352 /* SSID and BSSID are mutually exclusive */
7353 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7354 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7355 return ERR_PTR(-EINVAL);
7356
Johannes Bergea73cbc2014-01-24 10:53:53 +01007357 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007358 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7359 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007360 n_match_sets++;
7361 continue;
7362 }
7363 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7364 if (rssi)
7365 default_match_rssi = nla_get_s32(rssi);
7366 }
7367 }
7368
7369 /* However, if there's no other matchset, add the RSSI one */
7370 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7371 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007372
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007373 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007374 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007375
Luciano Coelho256da022014-11-10 16:13:46 +02007376 if (attrs[NL80211_ATTR_IE])
7377 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007378 else
7379 ie_len = 0;
7380
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007381 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007382 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007383
Avraham Stern3b06d272015-10-12 09:51:34 +03007384 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7385 /*
7386 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7387 * each scan plan already specifies its own interval
7388 */
7389 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7390 return ERR_PTR(-EINVAL);
7391
7392 nla_for_each_nested(attr,
7393 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7394 n_plans++;
7395 } else {
7396 /*
7397 * The scan interval attribute is kept for backward
7398 * compatibility. If no scan plans are specified and sched scan
7399 * interval is specified, one scan plan will be set with this
7400 * scan interval and infinite number of iterations.
7401 */
7402 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7403 return ERR_PTR(-EINVAL);
7404
7405 n_plans = 1;
7406 }
7407
7408 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7409 return ERR_PTR(-EINVAL);
7410
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007411 if (!wiphy_ext_feature_isset(
7412 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7413 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7414 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7415 return ERR_PTR(-EINVAL);
7416
Luciano Coelho807f8a82011-05-11 17:09:35 +03007417 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007418 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007419 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007420 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007421 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007422 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007423 if (!request)
7424 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007425
7426 if (n_ssids)
7427 request->ssids = (void *)&request->channels[n_channels];
7428 request->n_ssids = n_ssids;
7429 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007430 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007431 request->ie = (void *)(request->ssids + n_ssids);
7432 else
7433 request->ie = (void *)(request->channels + n_channels);
7434 }
7435
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007436 if (n_match_sets) {
7437 if (request->ie)
7438 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007439 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007440 request->match_sets =
7441 (void *)(request->ssids + n_ssids);
7442 else
7443 request->match_sets =
7444 (void *)(request->channels + n_channels);
7445 }
7446 request->n_match_sets = n_match_sets;
7447
Avraham Stern3b06d272015-10-12 09:51:34 +03007448 if (n_match_sets)
7449 request->scan_plans = (void *)(request->match_sets +
7450 n_match_sets);
7451 else if (request->ie)
7452 request->scan_plans = (void *)(request->ie + ie_len);
7453 else if (n_ssids)
7454 request->scan_plans = (void *)(request->ssids + n_ssids);
7455 else
7456 request->scan_plans = (void *)(request->channels + n_channels);
7457
7458 request->n_scan_plans = n_plans;
7459
Luciano Coelho807f8a82011-05-11 17:09:35 +03007460 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007461 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007462 /* user specified, bail out if channel not found */
7463 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007464 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007465 tmp) {
7466 struct ieee80211_channel *chan;
7467
7468 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7469
7470 if (!chan) {
7471 err = -EINVAL;
7472 goto out_free;
7473 }
7474
7475 /* ignore disabled channels */
7476 if (chan->flags & IEEE80211_CHAN_DISABLED)
7477 continue;
7478
7479 request->channels[i] = chan;
7480 i++;
7481 }
7482 } else {
7483 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007484 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007485 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007486
Luciano Coelho807f8a82011-05-11 17:09:35 +03007487 if (!wiphy->bands[band])
7488 continue;
7489 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7490 struct ieee80211_channel *chan;
7491
7492 chan = &wiphy->bands[band]->channels[j];
7493
7494 if (chan->flags & IEEE80211_CHAN_DISABLED)
7495 continue;
7496
7497 request->channels[i] = chan;
7498 i++;
7499 }
7500 }
7501 }
7502
7503 if (!i) {
7504 err = -EINVAL;
7505 goto out_free;
7506 }
7507
7508 request->n_channels = i;
7509
7510 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007511 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007512 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007513 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007514 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007515 err = -EINVAL;
7516 goto out_free;
7517 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007518 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007519 memcpy(request->ssids[i].ssid, nla_data(attr),
7520 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007521 i++;
7522 }
7523 }
7524
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007525 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007526 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007527 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007528 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007529 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007530 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007531
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007532 err = nla_parse_nested(tb,
7533 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007534 attr, nl80211_match_policy,
7535 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007536 if (err)
7537 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007538 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007539 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7540 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007541 if (WARN_ON(i >= n_match_sets)) {
7542 /* this indicates a programming error,
7543 * the loop above should have verified
7544 * things properly
7545 */
7546 err = -EINVAL;
7547 goto out_free;
7548 }
7549
Arend Van Spriel3007e352017-04-21 13:05:01 +01007550 if (ssid) {
7551 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7552 err = -EINVAL;
7553 goto out_free;
7554 }
7555 memcpy(request->match_sets[i].ssid.ssid,
7556 nla_data(ssid), nla_len(ssid));
7557 request->match_sets[i].ssid.ssid_len =
7558 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007559 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007560 if (bssid) {
7561 if (nla_len(bssid) != ETH_ALEN) {
7562 err = -EINVAL;
7563 goto out_free;
7564 }
7565 memcpy(request->match_sets[i].bssid,
7566 nla_data(bssid), ETH_ALEN);
7567 }
7568
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007569 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007570 request->match_sets[i].rssi_thold =
7571 default_match_rssi;
7572 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7573 if (rssi)
7574 request->match_sets[i].rssi_thold =
7575 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007576 }
7577 i++;
7578 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007579
7580 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007581 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007582 request->match_sets[0].rssi_thold = default_match_rssi;
7583
7584 request->min_rssi_thold = INT_MAX;
7585 for (i = 0; i < n_match_sets; i++)
7586 request->min_rssi_thold =
7587 min(request->match_sets[i].rssi_thold,
7588 request->min_rssi_thold);
7589 } else {
7590 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007591 }
7592
Johannes Berg9900e482014-02-04 21:01:25 +01007593 if (ie_len) {
7594 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007595 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007596 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007597 request->ie_len);
7598 }
7599
Roee Zamir2d23d072017-08-06 11:38:22 +03007600 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7601 if (err)
7602 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007603
Luciano Coelho9c748932015-01-16 16:04:09 +02007604 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7605 request->delay =
7606 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7607
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007608 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7609 request->relative_rssi = nla_get_s8(
7610 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7611 request->relative_rssi_set = true;
7612 }
7613
7614 if (request->relative_rssi_set &&
7615 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7616 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7617
7618 rssi_adjust = nla_data(
7619 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7620 request->rssi_adjust.band = rssi_adjust->band;
7621 request->rssi_adjust.delta = rssi_adjust->delta;
7622 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7623 err = -EINVAL;
7624 goto out_free;
7625 }
7626 }
7627
Avraham Stern3b06d272015-10-12 09:51:34 +03007628 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7629 if (err)
7630 goto out_free;
7631
Sam Leffler15d60302012-10-11 21:03:34 -07007632 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007633
Luciano Coelho256da022014-11-10 16:13:46 +02007634 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007635
7636out_free:
7637 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007638 return ERR_PTR(err);
7639}
7640
7641static int nl80211_start_sched_scan(struct sk_buff *skb,
7642 struct genl_info *info)
7643{
7644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7645 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007646 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007647 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007648 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007649 int err;
7650
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007651 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007652 return -EOPNOTSUPP;
7653
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007654 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7655 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7656 if (err)
7657 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007658
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007659 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007660 info->attrs,
7661 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007662
7663 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007664 if (err)
7665 goto out_err;
7666
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007667 /* leave request id zero for legacy request
7668 * or if driver does not support multi-scheduled scan
7669 */
7670 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7671 while (!sched_scan_req->reqid)
7672 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7673 }
7674
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007675 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007676 if (err)
7677 goto out_free;
7678
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007679 sched_scan_req->dev = dev;
7680 sched_scan_req->wiphy = &rdev->wiphy;
7681
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007682 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7683 sched_scan_req->owner_nlportid = info->snd_portid;
7684
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007685 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007686
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007687 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007688 return 0;
7689
7690out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007691 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007692out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007693 return err;
7694}
7695
7696static int nl80211_stop_sched_scan(struct sk_buff *skb,
7697 struct genl_info *info)
7698{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007699 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007701 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007702
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007703 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007704 return -EOPNOTSUPP;
7705
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007706 if (info->attrs[NL80211_ATTR_COOKIE]) {
7707 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7708 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7709 }
7710
7711 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7712 struct cfg80211_sched_scan_request,
7713 list);
7714 if (!req || req->reqid ||
7715 (req->owner_nlportid &&
7716 req->owner_nlportid != info->snd_portid))
7717 return -ENOENT;
7718
7719 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007720}
7721
Simon Wunderlich04f39042013-02-08 18:16:19 +01007722static int nl80211_start_radar_detection(struct sk_buff *skb,
7723 struct genl_info *info)
7724{
7725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7726 struct net_device *dev = info->user_ptr[1];
7727 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007728 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007729 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007730 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007731 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007732 int err;
7733
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007734 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007735 if (dfs_region == NL80211_DFS_UNSET)
7736 return -EINVAL;
7737
Simon Wunderlich04f39042013-02-08 18:16:19 +01007738 err = nl80211_parse_chandef(rdev, info, &chandef);
7739 if (err)
7740 return err;
7741
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007742 if (netif_carrier_ok(dev))
7743 return -EBUSY;
7744
Simon Wunderlich04f39042013-02-08 18:16:19 +01007745 if (wdev->cac_started)
7746 return -EBUSY;
7747
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007748 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007749 if (err < 0)
7750 return err;
7751
7752 if (err == 0)
7753 return -EINVAL;
7754
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007755 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007756 return -EINVAL;
7757
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007758 /* CAC start is offloaded to HW and can't be started manually */
7759 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
7760 return -EOPNOTSUPP;
7761
Simon Wunderlich04f39042013-02-08 18:16:19 +01007762 if (!rdev->ops->start_radar_detection)
7763 return -EOPNOTSUPP;
7764
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007765 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7766 if (WARN_ON(!cac_time_ms))
7767 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7768
Ilan Peera1056b12015-10-22 22:27:46 +03007769 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007770 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007771 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007772 wdev->cac_started = true;
7773 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007774 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007775 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007776 return err;
7777}
7778
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007779static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7780{
7781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7782 struct net_device *dev = info->user_ptr[1];
7783 struct wireless_dev *wdev = dev->ieee80211_ptr;
7784 struct cfg80211_csa_settings params;
7785 /* csa_attrs is defined static to avoid waste of stack size - this
7786 * function is called under RTNL lock, so this should not be a problem.
7787 */
7788 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007789 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007790 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007791 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007792 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007793 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007794
7795 if (!rdev->ops->channel_switch ||
7796 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7797 return -EOPNOTSUPP;
7798
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007799 switch (dev->ieee80211_ptr->iftype) {
7800 case NL80211_IFTYPE_AP:
7801 case NL80211_IFTYPE_P2P_GO:
7802 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007803 /* For all modes except AP the handle_dfs flag needs to be
7804 * supplied to tell the kernel that userspace will handle radar
7805 * events when they happen. Otherwise a switch to a channel
7806 * requiring DFS will be rejected.
7807 */
7808 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007809
7810 /* useless if AP is not running */
7811 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007812 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007813 break;
7814 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007815 if (!wdev->ssid_len)
7816 return -ENOTCONN;
7817 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007818 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007819 if (!wdev->mesh_id_len)
7820 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007821 break;
7822 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007823 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007824 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007825
7826 memset(&params, 0, sizeof(params));
7827
7828 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7829 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7830 return -EINVAL;
7831
7832 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007833 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007834 return -EINVAL;
7835
Luciano Coelho252e07c2014-10-08 09:48:34 +03007836 /* Even though the attribute is u32, the specification says
7837 * u8, so let's make sure we don't overflow.
7838 */
7839 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7840 if (cs_count > 255)
7841 return -EINVAL;
7842
7843 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007844
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007845 if (!need_new_beacon)
7846 goto skip_beacons;
7847
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007848 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7849 if (err)
7850 return err;
7851
7852 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7853 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007854 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007855 if (err)
7856 return err;
7857
7858 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7859 if (err)
7860 return err;
7861
7862 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7863 return -EINVAL;
7864
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007865 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7866 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007867 return -EINVAL;
7868
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007869 params.n_counter_offsets_beacon = len / sizeof(u16);
7870 if (rdev->wiphy.max_num_csa_counters &&
7871 (params.n_counter_offsets_beacon >
7872 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007873 return -EINVAL;
7874
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007875 params.counter_offsets_beacon =
7876 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7877
7878 /* sanity checks - counters should fit and be the same */
7879 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7880 u16 offset = params.counter_offsets_beacon[i];
7881
7882 if (offset >= params.beacon_csa.tail_len)
7883 return -EINVAL;
7884
7885 if (params.beacon_csa.tail[offset] != params.count)
7886 return -EINVAL;
7887 }
7888
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007889 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007890 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7891 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007892 return -EINVAL;
7893
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007894 params.n_counter_offsets_presp = len / sizeof(u16);
7895 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007896 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007897 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007898 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007899
7900 params.counter_offsets_presp =
7901 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7902
7903 /* sanity checks - counters should fit and be the same */
7904 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7905 u16 offset = params.counter_offsets_presp[i];
7906
7907 if (offset >= params.beacon_csa.probe_resp_len)
7908 return -EINVAL;
7909
7910 if (params.beacon_csa.probe_resp[offset] !=
7911 params.count)
7912 return -EINVAL;
7913 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007914 }
7915
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007916skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007917 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7918 if (err)
7919 return err;
7920
Arik Nemtsov923b3522015-07-08 15:41:44 +03007921 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7922 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007923 return -EINVAL;
7924
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007925 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7926 &params.chandef,
7927 wdev->iftype);
7928 if (err < 0)
7929 return err;
7930
Benjamin Berg8d9de162017-05-16 11:23:12 +02007931 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007932 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007933 if (need_handle_dfs_flag &&
7934 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7935 return -EINVAL;
7936 }
7937 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007938
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007939 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7940 params.block_tx = true;
7941
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007942 wdev_lock(wdev);
7943 err = rdev_channel_switch(rdev, dev, &params);
7944 wdev_unlock(wdev);
7945
7946 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007947}
7948
Johannes Berg9720bb32011-06-21 09:45:33 +02007949static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7950 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007951 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007952 struct wireless_dev *wdev,
7953 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007954{
Johannes Berg48ab9052009-07-10 18:42:31 +02007955 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007956 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007957 void *hdr;
7958 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007959
7960 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007961
Eric W. Biederman15e47302012-09-07 20:12:54 +00007962 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007963 NL80211_CMD_NEW_SCAN_RESULTS);
7964 if (!hdr)
7965 return -1;
7966
Michal Kubecek0a833c22017-11-15 13:09:32 +01007967 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02007968
Johannes Berg97990a02013-04-19 01:02:55 +02007969 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7970 goto nla_put_failure;
7971 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007972 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7973 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007974 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7975 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007976 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007977
7978 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7979 if (!bss)
7980 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007981 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007982 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007983 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007984
7985 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007986 /* indicate whether we have probe response data or not */
7987 if (rcu_access_pointer(res->proberesp_ies) &&
7988 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7989 goto fail_unlock_rcu;
7990
7991 /* this pointer prefers to be pointed to probe response data
7992 * but is always valid
7993 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007994 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007995 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007996 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7997 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007998 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007999 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8000 ies->len, ies->data))
8001 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008002 }
Johannes Berg0e227082014-08-12 20:34:30 +02008003
8004 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008005 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008006 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008007 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8008 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008009 goto fail_unlock_rcu;
8010 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8011 ies->len, ies->data))
8012 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008013 }
8014 rcu_read_unlock();
8015
David S. Miller9360ffd2012-03-29 04:41:26 -04008016 if (res->beacon_interval &&
8017 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8018 goto nla_put_failure;
8019 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8020 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008021 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008022 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8023 jiffies_to_msecs(jiffies - intbss->ts)))
8024 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008025
Avraham Stern1d762502016-07-05 17:10:13 +03008026 if (intbss->parent_tsf &&
8027 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8028 intbss->parent_tsf, NL80211_BSS_PAD) ||
8029 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8030 intbss->parent_bssid)))
8031 goto nla_put_failure;
8032
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008033 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008034 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8035 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008036 goto nla_put_failure;
8037
Sunil Dutt983dafa2017-12-13 19:51:36 +02008038 if (!nl80211_put_signal(msg, intbss->pub.chains,
8039 intbss->pub.chain_signal,
8040 NL80211_BSS_CHAIN_SIGNAL))
8041 goto nla_put_failure;
8042
Johannes Berg77965c92009-02-18 18:45:06 +01008043 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008044 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008045 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8046 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008047 break;
8048 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008049 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8050 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008051 break;
8052 default:
8053 break;
8054 }
8055
Johannes Berg48ab9052009-07-10 18:42:31 +02008056 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008057 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008058 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008059 if (intbss == wdev->current_bss &&
8060 nla_put_u32(msg, NL80211_BSS_STATUS,
8061 NL80211_BSS_STATUS_ASSOCIATED))
8062 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008063 break;
8064 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008065 if (intbss == wdev->current_bss &&
8066 nla_put_u32(msg, NL80211_BSS_STATUS,
8067 NL80211_BSS_STATUS_IBSS_JOINED))
8068 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008069 break;
8070 default:
8071 break;
8072 }
8073
Johannes Berg2a519312009-02-10 21:25:55 +01008074 nla_nest_end(msg, bss);
8075
Johannes Berg053c0952015-01-16 22:09:00 +01008076 genlmsg_end(msg, hdr);
8077 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008078
Johannes Berg8cef2c92013-02-05 16:54:31 +01008079 fail_unlock_rcu:
8080 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008081 nla_put_failure:
8082 genlmsg_cancel(msg, hdr);
8083 return -EMSGSIZE;
8084}
8085
Johannes Berg97990a02013-04-19 01:02:55 +02008086static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008087{
Johannes Berg48ab9052009-07-10 18:42:31 +02008088 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008089 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008090 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008091 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008092 int err;
8093
Johannes Bergea90e0d2017-03-15 14:26:04 +01008094 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02008095 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008096 if (err) {
8097 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008098 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008099 }
Johannes Berg2a519312009-02-10 21:25:55 +01008100
Johannes Berg48ab9052009-07-10 18:42:31 +02008101 wdev_lock(wdev);
8102 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008103
8104 /*
8105 * dump_scan will be called multiple times to break up the scan results
8106 * into multiple messages. It is unlikely that any more bss-es will be
8107 * expired after the first call, so only call only call this on the
8108 * first dump_scan invocation.
8109 */
8110 if (start == 0)
8111 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008112
Johannes Berg9720bb32011-06-21 09:45:33 +02008113 cb->seq = rdev->bss_generation;
8114
Johannes Berg48ab9052009-07-10 18:42:31 +02008115 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008116 if (++idx <= start)
8117 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008118 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008119 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008120 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008121 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008122 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008123 }
8124 }
8125
Johannes Berg48ab9052009-07-10 18:42:31 +02008126 spin_unlock_bh(&rdev->bss_lock);
8127 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008128
Johannes Berg97990a02013-04-19 01:02:55 +02008129 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008130 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008131
Johannes Berg67748892010-10-04 21:14:06 +02008132 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008133}
8134
Eric W. Biederman15e47302012-09-07 20:12:54 +00008135static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008136 int flags, struct net_device *dev,
8137 bool allow_radio_stats,
8138 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008139{
8140 void *hdr;
8141 struct nlattr *infoattr;
8142
Johannes Berg11f78ac2014-11-14 16:43:50 +01008143 /* skip radio stats if userspace didn't request them */
8144 if (!survey->channel && !allow_radio_stats)
8145 return 0;
8146
Eric W. Biederman15e47302012-09-07 20:12:54 +00008147 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008148 NL80211_CMD_NEW_SURVEY_RESULTS);
8149 if (!hdr)
8150 return -ENOMEM;
8151
David S. Miller9360ffd2012-03-29 04:41:26 -04008152 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8153 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008154
8155 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
8156 if (!infoattr)
8157 goto nla_put_failure;
8158
Johannes Berg11f78ac2014-11-14 16:43:50 +01008159 if (survey->channel &&
8160 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04008161 survey->channel->center_freq))
8162 goto nla_put_failure;
8163
8164 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8165 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8166 goto nla_put_failure;
8167 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8168 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8169 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008170 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008171 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8172 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008173 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008174 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008175 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8176 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008177 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008178 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008179 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8180 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008181 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008182 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008183 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8184 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008185 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008186 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008187 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8188 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008189 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008190 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008191 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8192 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008193 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008194
8195 nla_nest_end(msg, infoattr);
8196
Johannes Berg053c0952015-01-16 22:09:00 +01008197 genlmsg_end(msg, hdr);
8198 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008199
8200 nla_put_failure:
8201 genlmsg_cancel(msg, hdr);
8202 return -EMSGSIZE;
8203}
8204
Johannes Berg11f78ac2014-11-14 16:43:50 +01008205static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008206{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008207 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008208 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008209 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008210 struct wireless_dev *wdev;
8211 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008212 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008213 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008214
Johannes Bergea90e0d2017-03-15 14:26:04 +01008215 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008216 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008217 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008218 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008219
Johannes Berg11f78ac2014-11-14 16:43:50 +01008220 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008221 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008222
Johannes Berg97990a02013-04-19 01:02:55 +02008223 if (!wdev->netdev) {
8224 res = -EINVAL;
8225 goto out_err;
8226 }
8227
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008228 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008229 res = -EOPNOTSUPP;
8230 goto out_err;
8231 }
8232
8233 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008234 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008235 if (res == -ENOENT)
8236 break;
8237 if (res)
8238 goto out_err;
8239
Johannes Berg11f78ac2014-11-14 16:43:50 +01008240 /* don't send disabled channels, but do send non-channel data */
8241 if (survey.channel &&
8242 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008243 survey_idx++;
8244 continue;
8245 }
8246
Holger Schurig61fa7132009-11-11 12:25:40 +01008247 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008248 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008249 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008250 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008251 goto out;
8252 survey_idx++;
8253 }
8254
8255 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008256 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008257 res = skb->len;
8258 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008259 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008260 return res;
8261}
8262
Samuel Ortizb23aa672009-07-01 21:26:54 +02008263static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8264{
8265 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8266 NL80211_WPA_VERSION_2));
8267}
8268
Jouni Malinen636a5d32009-03-19 13:39:22 +02008269static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8270{
Johannes Berg4c476992010-10-04 21:36:35 +02008271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8272 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008273 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008274 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8275 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008276 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008277 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008278 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008279
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008280 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8281 return -EINVAL;
8282
8283 if (!info->attrs[NL80211_ATTR_MAC])
8284 return -EINVAL;
8285
Jouni Malinen17780922009-03-27 20:52:47 +02008286 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8287 return -EINVAL;
8288
Johannes Berg19957bb2009-07-02 17:20:43 +02008289 if (!info->attrs[NL80211_ATTR_SSID])
8290 return -EINVAL;
8291
8292 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8293 return -EINVAL;
8294
Johannes Bergfffd0932009-07-08 14:22:54 +02008295 err = nl80211_parse_key(info, &key);
8296 if (err)
8297 return err;
8298
8299 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008300 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8301 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008302 if (!key.p.key || !key.p.key_len)
8303 return -EINVAL;
8304 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8305 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8306 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8307 key.p.key_len != WLAN_KEY_LEN_WEP104))
8308 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008309 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008310 return -EINVAL;
8311 } else {
8312 key.p.key_len = 0;
8313 key.p.key = NULL;
8314 }
8315
Johannes Bergafea0b72010-08-10 09:46:42 +02008316 if (key.idx >= 0) {
8317 int i;
8318 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008319
Johannes Bergafea0b72010-08-10 09:46:42 +02008320 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8321 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8322 ok = true;
8323 break;
8324 }
8325 }
Johannes Berg4c476992010-10-04 21:36:35 +02008326 if (!ok)
8327 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008328 }
8329
Johannes Berg4c476992010-10-04 21:36:35 +02008330 if (!rdev->ops->auth)
8331 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008332
Johannes Berg074ac8d2010-09-16 14:58:22 +02008333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008334 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8335 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008336
Johannes Berg19957bb2009-07-02 17:20:43 +02008337 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008338 chan = nl80211_get_valid_chan(&rdev->wiphy,
8339 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8340 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008341 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008342
Johannes Berg19957bb2009-07-02 17:20:43 +02008343 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8344 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8345
8346 if (info->attrs[NL80211_ATTR_IE]) {
8347 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8348 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8349 }
8350
8351 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008352 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008353 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008354
Jouni Malinen63181062016-10-27 00:42:02 +03008355 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8356 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8357 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8358 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008359 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008360 return -EINVAL;
8361
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008362 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008363 if (auth_type != NL80211_AUTHTYPE_SAE &&
8364 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8365 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8366 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008367 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008368 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8369 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008370 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008371 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008372 return -EINVAL;
8373 }
8374
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008375 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8376
Johannes Berg95de8172012-01-20 13:55:25 +01008377 /*
8378 * Since we no longer track auth state, ignore
8379 * requests to only change local state.
8380 */
8381 if (local_state_change)
8382 return 0;
8383
Johannes Berg91bf9b22013-05-15 17:44:01 +02008384 wdev_lock(dev->ieee80211_ptr);
8385 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8386 ssid, ssid_len, ie, ie_len,
8387 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008388 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008389 wdev_unlock(dev->ieee80211_ptr);
8390 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008391}
8392
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008393static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
8394 struct genl_info *info)
8395{
8396 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8397 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
8398 return -EINVAL;
8399 }
8400
8401 if (!rdev->ops->tx_control_port ||
8402 !wiphy_ext_feature_isset(&rdev->wiphy,
8403 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
8404 return -EOPNOTSUPP;
8405
8406 return 0;
8407}
8408
Johannes Bergc0692b82010-08-27 14:26:53 +03008409static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8410 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008411 struct cfg80211_crypto_settings *settings,
8412 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008413{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008414 memset(settings, 0, sizeof(*settings));
8415
Samuel Ortizb23aa672009-07-01 21:26:54 +02008416 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8417
Johannes Bergc0692b82010-08-27 14:26:53 +03008418 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8419 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008420
Johannes Bergc0692b82010-08-27 14:26:53 +03008421 proto = nla_get_u16(
8422 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8423 settings->control_port_ethertype = cpu_to_be16(proto);
8424 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8425 proto != ETH_P_PAE)
8426 return -EINVAL;
8427 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8428 settings->control_port_no_encrypt = true;
8429 } else
8430 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8431
Denis Kenzior64bf3d42018-03-26 12:52:43 -05008432 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8433 int r = validate_pae_over_nl80211(rdev, info);
8434
8435 if (r < 0)
8436 return r;
8437
8438 settings->control_port_over_nl80211 = true;
8439 }
8440
Samuel Ortizb23aa672009-07-01 21:26:54 +02008441 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8442 void *data;
8443 int len, i;
8444
8445 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8446 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8447 settings->n_ciphers_pairwise = len / sizeof(u32);
8448
8449 if (len % sizeof(u32))
8450 return -EINVAL;
8451
Johannes Berg3dc27d22009-07-02 21:36:37 +02008452 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008453 return -EINVAL;
8454
8455 memcpy(settings->ciphers_pairwise, data, len);
8456
8457 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008458 if (!cfg80211_supported_cipher_suite(
8459 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008460 settings->ciphers_pairwise[i]))
8461 return -EINVAL;
8462 }
8463
8464 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8465 settings->cipher_group =
8466 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008467 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8468 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008469 return -EINVAL;
8470 }
8471
8472 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8473 settings->wpa_versions =
8474 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8475 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8476 return -EINVAL;
8477 }
8478
8479 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8480 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008481 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008482
8483 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8484 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8485 settings->n_akm_suites = len / sizeof(u32);
8486
8487 if (len % sizeof(u32))
8488 return -EINVAL;
8489
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008490 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8491 return -EINVAL;
8492
Samuel Ortizb23aa672009-07-01 21:26:54 +02008493 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008494 }
8495
Eliad Peller91b5ab62017-06-09 13:08:42 +01008496 if (info->attrs[NL80211_ATTR_PMK]) {
8497 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8498 return -EINVAL;
8499 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8500 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8501 return -EINVAL;
8502 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8503 }
8504
Samuel Ortizb23aa672009-07-01 21:26:54 +02008505 return 0;
8506}
8507
Jouni Malinen636a5d32009-03-19 13:39:22 +02008508static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8509{
Johannes Berg4c476992010-10-04 21:36:35 +02008510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8511 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008512 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008513 struct cfg80211_assoc_request req = {};
8514 const u8 *bssid, *ssid;
8515 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008516
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008517 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8518 return -EINVAL;
8519
8520 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008521 !info->attrs[NL80211_ATTR_SSID] ||
8522 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008523 return -EINVAL;
8524
Johannes Berg4c476992010-10-04 21:36:35 +02008525 if (!rdev->ops->assoc)
8526 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008527
Johannes Berg074ac8d2010-09-16 14:58:22 +02008528 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008529 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8530 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008531
Johannes Berg19957bb2009-07-02 17:20:43 +02008532 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008533
Jouni Malinen664834d2014-01-15 00:01:44 +02008534 chan = nl80211_get_valid_chan(&rdev->wiphy,
8535 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8536 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008537 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008538
Johannes Berg19957bb2009-07-02 17:20:43 +02008539 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8540 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008541
8542 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008543 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8544 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008545 }
8546
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008547 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008548 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008549 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008550 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008551 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008552 else if (mfp != NL80211_MFP_NO)
8553 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008554 }
8555
Johannes Berg3e5d7642009-07-07 14:37:26 +02008556 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008557 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008558
Ben Greear7e7c8922011-11-18 11:31:59 -08008559 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008560 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008561
8562 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008563 memcpy(&req.ht_capa_mask,
8564 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8565 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008566
8567 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008568 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008569 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008570 memcpy(&req.ht_capa,
8571 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8572 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008573 }
8574
Johannes Bergee2aca32013-02-21 17:36:01 +01008575 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008576 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008577
8578 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008579 memcpy(&req.vht_capa_mask,
8580 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8581 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008582
8583 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008584 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008585 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008586 memcpy(&req.vht_capa,
8587 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8588 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008589 }
8590
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008591 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008592 if (!((rdev->wiphy.features &
8593 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8594 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8595 !wiphy_ext_feature_isset(&rdev->wiphy,
8596 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008597 return -EINVAL;
8598 req.flags |= ASSOC_REQ_USE_RRM;
8599 }
8600
Jouni Malinen348bd452016-10-27 00:42:03 +03008601 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8602 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8603 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8604 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8605 return -EINVAL;
8606 req.fils_nonces =
8607 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8608 }
8609
Johannes Bergf62fab72013-02-21 20:09:09 +01008610 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008611 if (!err) {
8612 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008613
Johannes Bergf62fab72013-02-21 20:09:09 +01008614 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8615 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008616
8617 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8618 dev->ieee80211_ptr->conn_owner_nlportid =
8619 info->snd_portid;
8620 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8621 bssid, ETH_ALEN);
8622 }
8623
Johannes Berg91bf9b22013-05-15 17:44:01 +02008624 wdev_unlock(dev->ieee80211_ptr);
8625 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008626
Jouni Malinen636a5d32009-03-19 13:39:22 +02008627 return err;
8628}
8629
8630static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8631{
Johannes Berg4c476992010-10-04 21:36:35 +02008632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8633 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008634 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008635 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008636 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008637 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008638
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008639 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8640 return -EINVAL;
8641
8642 if (!info->attrs[NL80211_ATTR_MAC])
8643 return -EINVAL;
8644
8645 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8646 return -EINVAL;
8647
Johannes Berg4c476992010-10-04 21:36:35 +02008648 if (!rdev->ops->deauth)
8649 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008650
Johannes Berg074ac8d2010-09-16 14:58:22 +02008651 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008652 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8653 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008654
Johannes Berg19957bb2009-07-02 17:20:43 +02008655 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008656
Johannes Berg19957bb2009-07-02 17:20:43 +02008657 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8658 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008659 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008660 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008661 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008662
8663 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008664 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8665 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008666 }
8667
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008668 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8669
Johannes Berg91bf9b22013-05-15 17:44:01 +02008670 wdev_lock(dev->ieee80211_ptr);
8671 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8672 local_state_change);
8673 wdev_unlock(dev->ieee80211_ptr);
8674 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008675}
8676
8677static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8678{
Johannes Berg4c476992010-10-04 21:36:35 +02008679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8680 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008681 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008682 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008683 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008684 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008685
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008686 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8687 return -EINVAL;
8688
8689 if (!info->attrs[NL80211_ATTR_MAC])
8690 return -EINVAL;
8691
8692 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8693 return -EINVAL;
8694
Johannes Berg4c476992010-10-04 21:36:35 +02008695 if (!rdev->ops->disassoc)
8696 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008697
Johannes Berg074ac8d2010-09-16 14:58:22 +02008698 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008699 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8700 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008701
Johannes Berg19957bb2009-07-02 17:20:43 +02008702 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008703
Johannes Berg19957bb2009-07-02 17:20:43 +02008704 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8705 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008706 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008707 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008708 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008709
8710 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008711 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8712 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008713 }
8714
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008715 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8716
Johannes Berg91bf9b22013-05-15 17:44:01 +02008717 wdev_lock(dev->ieee80211_ptr);
8718 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8719 local_state_change);
8720 wdev_unlock(dev->ieee80211_ptr);
8721 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008722}
8723
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008724static bool
8725nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008726 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008727 int rateval)
8728{
8729 struct wiphy *wiphy = &rdev->wiphy;
8730 bool found = false;
8731 int band, i;
8732
Johannes Berg57fbcce2016-04-12 15:56:15 +02008733 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008734 struct ieee80211_supported_band *sband;
8735
8736 sband = wiphy->bands[band];
8737 if (!sband)
8738 continue;
8739
8740 for (i = 0; i < sband->n_bitrates; i++) {
8741 if (sband->bitrates[i].bitrate == rateval) {
8742 mcast_rate[band] = i + 1;
8743 found = true;
8744 break;
8745 }
8746 }
8747 }
8748
8749 return found;
8750}
8751
Johannes Berg04a773a2009-04-19 21:24:32 +02008752static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8753{
Johannes Berg4c476992010-10-04 21:36:35 +02008754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8755 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008756 struct cfg80211_ibss_params ibss;
8757 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008758 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008759 int err;
8760
Johannes Berg8e30bc52009-04-22 17:45:38 +02008761 memset(&ibss, 0, sizeof(ibss));
8762
Johannes Berg04a773a2009-04-19 21:24:32 +02008763 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8764 return -EINVAL;
8765
Johannes Berg683b6d32012-11-08 21:25:48 +01008766 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008767 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8768 return -EINVAL;
8769
Johannes Berg8e30bc52009-04-22 17:45:38 +02008770 ibss.beacon_interval = 100;
8771
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308772 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008773 ibss.beacon_interval =
8774 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308775
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308776 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8777 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308778 if (err)
8779 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008780
Johannes Berg4c476992010-10-04 21:36:35 +02008781 if (!rdev->ops->join_ibss)
8782 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008783
Johannes Berg4c476992010-10-04 21:36:35 +02008784 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8785 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008786
Johannes Berg79c97e92009-07-07 03:56:12 +02008787 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008788
Johannes Berg39193492011-09-16 13:45:25 +02008789 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008790 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008791
8792 if (!is_valid_ether_addr(ibss.bssid))
8793 return -EINVAL;
8794 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008795 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8796 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8797
8798 if (info->attrs[NL80211_ATTR_IE]) {
8799 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8800 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8801 }
8802
Johannes Berg683b6d32012-11-08 21:25:48 +01008803 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8804 if (err)
8805 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008806
Ilan Peer174e0cd2014-02-23 09:13:01 +02008807 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8808 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008809 return -EINVAL;
8810
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008811 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008812 case NL80211_CHAN_WIDTH_5:
8813 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008814 case NL80211_CHAN_WIDTH_20_NOHT:
8815 break;
8816 case NL80211_CHAN_WIDTH_20:
8817 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008818 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8819 return -EINVAL;
8820 break;
8821 case NL80211_CHAN_WIDTH_80:
8822 case NL80211_CHAN_WIDTH_80P80:
8823 case NL80211_CHAN_WIDTH_160:
8824 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8825 return -EINVAL;
8826 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8827 NL80211_EXT_FEATURE_VHT_IBSS))
8828 return -EINVAL;
8829 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008830 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008831 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008832 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008833
Johannes Berg04a773a2009-04-19 21:24:32 +02008834 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008835 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008836
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008837 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8838 u8 *rates =
8839 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8840 int n_rates =
8841 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8842 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008843 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008844
Johannes Berg34850ab2011-07-18 18:08:35 +02008845 err = ieee80211_get_ratemask(sband, rates, n_rates,
8846 &ibss.basic_rates);
8847 if (err)
8848 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008849 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008850
Simon Wunderlich803768f2013-06-28 10:39:58 +02008851 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8852 memcpy(&ibss.ht_capa_mask,
8853 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8854 sizeof(ibss.ht_capa_mask));
8855
8856 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8857 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8858 return -EINVAL;
8859 memcpy(&ibss.ht_capa,
8860 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8861 sizeof(ibss.ht_capa));
8862 }
8863
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008864 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8865 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8866 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8867 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008868
Johannes Berg4c476992010-10-04 21:36:35 +02008869 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308870 bool no_ht = false;
8871
Johannes Berg768075e2017-11-13 15:35:06 +01008872 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008873 if (IS_ERR(connkeys))
8874 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308875
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008876 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8877 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008878 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308879 return -EINVAL;
8880 }
Johannes Berg4c476992010-10-04 21:36:35 +02008881 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008882
Antonio Quartulli267335d2012-01-31 20:25:47 +01008883 ibss.control_port =
8884 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8885
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05008886 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
8887 int r = validate_pae_over_nl80211(rdev, info);
8888
8889 if (r < 0)
8890 return r;
8891
8892 ibss.control_port_over_nl80211 = true;
8893 }
8894
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008895 ibss.userspace_handles_dfs =
8896 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8897
Denis Kenziorf8d16d32018-03-26 12:52:45 -05008898 wdev_lock(dev->ieee80211_ptr);
8899 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008900 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008901 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05008902 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8903 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8904 wdev_unlock(dev->ieee80211_ptr);
8905
Johannes Berg04a773a2009-04-19 21:24:32 +02008906 return err;
8907}
8908
8909static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8910{
Johannes Berg4c476992010-10-04 21:36:35 +02008911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8912 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008913
Johannes Berg4c476992010-10-04 21:36:35 +02008914 if (!rdev->ops->leave_ibss)
8915 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008916
Johannes Berg4c476992010-10-04 21:36:35 +02008917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8918 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008919
Johannes Berg4c476992010-10-04 21:36:35 +02008920 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008921}
8922
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008923static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8924{
8925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8926 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008927 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008928 u32 nla_rate;
8929 int err;
8930
8931 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008932 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008934 return -EOPNOTSUPP;
8935
8936 if (!rdev->ops->set_mcast_rate)
8937 return -EOPNOTSUPP;
8938
8939 memset(mcast_rate, 0, sizeof(mcast_rate));
8940
8941 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8942 return -EINVAL;
8943
8944 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8945 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8946 return -EINVAL;
8947
Ilan Peera1056b12015-10-22 22:27:46 +03008948 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008949
8950 return err;
8951}
8952
Johannes Bergad7e7182013-11-13 13:37:47 +01008953static struct sk_buff *
8954__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008955 struct wireless_dev *wdev, int approxlen,
8956 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008957 enum nl80211_attrs attr,
8958 const struct nl80211_vendor_cmd_info *info,
8959 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008960{
8961 struct sk_buff *skb;
8962 void *hdr;
8963 struct nlattr *data;
8964
8965 skb = nlmsg_new(approxlen + 100, gfp);
8966 if (!skb)
8967 return NULL;
8968
8969 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8970 if (!hdr) {
8971 kfree_skb(skb);
8972 return NULL;
8973 }
8974
8975 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8976 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008977
8978 if (info) {
8979 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8980 info->vendor_id))
8981 goto nla_put_failure;
8982 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8983 info->subcmd))
8984 goto nla_put_failure;
8985 }
8986
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008987 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008988 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8989 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008990 goto nla_put_failure;
8991 if (wdev->netdev &&
8992 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8993 wdev->netdev->ifindex))
8994 goto nla_put_failure;
8995 }
8996
Johannes Bergad7e7182013-11-13 13:37:47 +01008997 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008998 if (!data)
8999 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009000
9001 ((void **)skb->cb)[0] = rdev;
9002 ((void **)skb->cb)[1] = hdr;
9003 ((void **)skb->cb)[2] = data;
9004
9005 return skb;
9006
9007 nla_put_failure:
9008 kfree_skb(skb);
9009 return NULL;
9010}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009011
Johannes Berge03ad6e2014-01-01 17:22:30 +01009012struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009013 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009014 enum nl80211_commands cmd,
9015 enum nl80211_attrs attr,
9016 int vendor_event_idx,
9017 int approxlen, gfp_t gfp)
9018{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009019 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009020 const struct nl80211_vendor_cmd_info *info;
9021
9022 switch (cmd) {
9023 case NL80211_CMD_TESTMODE:
9024 if (WARN_ON(vendor_event_idx != -1))
9025 return NULL;
9026 info = NULL;
9027 break;
9028 case NL80211_CMD_VENDOR:
9029 if (WARN_ON(vendor_event_idx < 0 ||
9030 vendor_event_idx >= wiphy->n_vendor_events))
9031 return NULL;
9032 info = &wiphy->vendor_events[vendor_event_idx];
9033 break;
9034 default:
9035 WARN_ON(1);
9036 return NULL;
9037 }
9038
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009039 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009040 cmd, attr, info, gfp);
9041}
9042EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9043
9044void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9045{
9046 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9047 void *hdr = ((void **)skb->cb)[1];
9048 struct nlattr *data = ((void **)skb->cb)[2];
9049 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9050
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009051 /* clear CB data for netlink core to own from now on */
9052 memset(skb->cb, 0, sizeof(skb->cb));
9053
Johannes Berge03ad6e2014-01-01 17:22:30 +01009054 nla_nest_end(skb, data);
9055 genlmsg_end(skb, hdr);
9056
9057 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9058 mcgrp = NL80211_MCGRP_VENDOR;
9059
9060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
9061 mcgrp, gfp);
9062}
9063EXPORT_SYMBOL(__cfg80211_send_event_skb);
9064
Johannes Bergaff89a92009-07-01 21:26:51 +02009065#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009066static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9067{
Johannes Berg4c476992010-10-04 21:36:35 +02009068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009069 struct wireless_dev *wdev =
9070 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009071 int err;
9072
David Spinadelfc73f112013-07-31 18:04:15 +03009073 if (!rdev->ops->testmode_cmd)
9074 return -EOPNOTSUPP;
9075
9076 if (IS_ERR(wdev)) {
9077 err = PTR_ERR(wdev);
9078 if (err != -EINVAL)
9079 return err;
9080 wdev = NULL;
9081 } else if (wdev->wiphy != &rdev->wiphy) {
9082 return -EINVAL;
9083 }
9084
Johannes Bergaff89a92009-07-01 21:26:51 +02009085 if (!info->attrs[NL80211_ATTR_TESTDATA])
9086 return -EINVAL;
9087
Johannes Bergad7e7182013-11-13 13:37:47 +01009088 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009089 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009090 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9091 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009092 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009093
Johannes Bergaff89a92009-07-01 21:26:51 +02009094 return err;
9095}
9096
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009097static int nl80211_testmode_dump(struct sk_buff *skb,
9098 struct netlink_callback *cb)
9099{
Johannes Berg00918d32011-12-13 17:22:05 +01009100 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009101 int err;
9102 long phy_idx;
9103 void *data = NULL;
9104 int data_len = 0;
9105
Johannes Berg5fe231e2013-05-08 21:45:15 +02009106 rtnl_lock();
9107
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009108 if (cb->args[0]) {
9109 /*
9110 * 0 is a valid index, but not valid for args[0],
9111 * so we need to offset by 1.
9112 */
9113 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009114
9115 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9116 if (!rdev) {
9117 err = -ENOENT;
9118 goto out_err;
9119 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009120 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02009121 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9122
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009123 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02009124 attrbuf, nl80211_fam.maxattr,
9125 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009126 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02009127 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009128
Johannes Bergc90c39d2016-10-24 14:40:01 +02009129 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02009130 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009131 err = PTR_ERR(rdev);
9132 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01009133 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02009134 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02009135
Johannes Bergc90c39d2016-10-24 14:40:01 +02009136 if (attrbuf[NL80211_ATTR_TESTDATA])
9137 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009138 }
9139
9140 if (cb->args[1]) {
9141 data = nla_data((void *)cb->args[1]);
9142 data_len = nla_len((void *)cb->args[1]);
9143 }
9144
Johannes Berg00918d32011-12-13 17:22:05 +01009145 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009146 err = -EOPNOTSUPP;
9147 goto out_err;
9148 }
9149
9150 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00009151 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009152 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9153 NL80211_CMD_TESTMODE);
9154 struct nlattr *tmdata;
9155
Dan Carpentercb35fba2013-08-14 14:50:01 +03009156 if (!hdr)
9157 break;
9158
David S. Miller9360ffd2012-03-29 04:41:26 -04009159 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009160 genlmsg_cancel(skb, hdr);
9161 break;
9162 }
9163
9164 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
9165 if (!tmdata) {
9166 genlmsg_cancel(skb, hdr);
9167 break;
9168 }
Hila Gonene35e4d22012-06-27 17:19:42 +03009169 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009170 nla_nest_end(skb, tmdata);
9171
9172 if (err == -ENOBUFS || err == -ENOENT) {
9173 genlmsg_cancel(skb, hdr);
9174 break;
9175 } else if (err) {
9176 genlmsg_cancel(skb, hdr);
9177 goto out_err;
9178 }
9179
9180 genlmsg_end(skb, hdr);
9181 }
9182
9183 err = skb->len;
9184 /* see above */
9185 cb->args[0] = phy_idx + 1;
9186 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02009187 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009188 return err;
9189}
Johannes Bergaff89a92009-07-01 21:26:51 +02009190#endif
9191
Samuel Ortizb23aa672009-07-01 21:26:54 +02009192static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9193{
Johannes Berg4c476992010-10-04 21:36:35 +02009194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9195 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009196 struct cfg80211_connect_params connect;
9197 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009198 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009199 int err;
9200
9201 memset(&connect, 0, sizeof(connect));
9202
9203 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9204 return -EINVAL;
9205
9206 if (!info->attrs[NL80211_ATTR_SSID] ||
9207 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9208 return -EINVAL;
9209
9210 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9211 connect.auth_type =
9212 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009213 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9214 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009215 return -EINVAL;
9216 } else
9217 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9218
9219 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9220
Avraham Stern3a00df52017-06-09 13:08:43 +01009221 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9222 !wiphy_ext_feature_isset(&rdev->wiphy,
9223 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9224 return -EINVAL;
9225 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9226
Johannes Bergc0692b82010-08-27 14:26:53 +03009227 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009228 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009229 if (err)
9230 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009231
Johannes Berg074ac8d2010-09-16 14:58:22 +02009232 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009233 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9234 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009235
Johannes Berg79c97e92009-07-07 03:56:12 +02009236 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009237
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309238 connect.bg_scan_period = -1;
9239 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9240 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9241 connect.bg_scan_period =
9242 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9243 }
9244
Samuel Ortizb23aa672009-07-01 21:26:54 +02009245 if (info->attrs[NL80211_ATTR_MAC])
9246 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009247 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9248 connect.bssid_hint =
9249 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009250 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9251 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9252
9253 if (info->attrs[NL80211_ATTR_IE]) {
9254 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9255 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9256 }
9257
Jouni Malinencee00a92013-01-15 17:15:57 +02009258 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9259 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009260 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9261 !wiphy_ext_feature_isset(&rdev->wiphy,
9262 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9263 return -EOPNOTSUPP;
9264
Jouni Malinencee00a92013-01-15 17:15:57 +02009265 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009266 connect.mfp != NL80211_MFP_NO &&
9267 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02009268 return -EINVAL;
9269 } else {
9270 connect.mfp = NL80211_MFP_NO;
9271 }
9272
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009273 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9274 connect.prev_bssid =
9275 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9276
Samuel Ortizb23aa672009-07-01 21:26:54 +02009277 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009278 connect.channel = nl80211_get_valid_chan(
9279 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9280 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009281 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009282 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009283 connect.channel_hint = nl80211_get_valid_chan(
9284 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9285 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009286 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009287 }
9288
Johannes Bergfffd0932009-07-08 14:22:54 +02009289 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009290 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009291 if (IS_ERR(connkeys))
9292 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009293 }
9294
Ben Greear7e7c8922011-11-18 11:31:59 -08009295 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9296 connect.flags |= ASSOC_REQ_DISABLE_HT;
9297
9298 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9299 memcpy(&connect.ht_capa_mask,
9300 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9301 sizeof(connect.ht_capa_mask));
9302
9303 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009304 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009305 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009306 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009307 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009308 memcpy(&connect.ht_capa,
9309 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9310 sizeof(connect.ht_capa));
9311 }
9312
Johannes Bergee2aca32013-02-21 17:36:01 +01009313 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9314 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9315
9316 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9317 memcpy(&connect.vht_capa_mask,
9318 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9319 sizeof(connect.vht_capa_mask));
9320
9321 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9322 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009323 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009324 return -EINVAL;
9325 }
9326 memcpy(&connect.vht_capa,
9327 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9328 sizeof(connect.vht_capa));
9329 }
9330
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009331 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009332 if (!((rdev->wiphy.features &
9333 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9334 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9335 !wiphy_ext_feature_isset(&rdev->wiphy,
9336 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009337 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009338 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009339 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009340 connect.flags |= ASSOC_REQ_USE_RRM;
9341 }
9342
Lior David34d50512016-01-28 10:58:25 +02009343 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009344 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009345 kzfree(connkeys);
9346 return -EOPNOTSUPP;
9347 }
9348
Arend van Spriel38de03d2016-03-02 20:37:18 +01009349 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9350 /* bss selection makes no sense if bssid is set */
9351 if (connect.bssid) {
9352 kzfree(connkeys);
9353 return -EINVAL;
9354 }
9355
9356 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9357 wiphy, &connect.bss_select);
9358 if (err) {
9359 kzfree(connkeys);
9360 return err;
9361 }
9362 }
9363
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009364 if (wiphy_ext_feature_isset(&rdev->wiphy,
9365 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9366 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9367 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9368 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9369 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9370 connect.fils_erp_username =
9371 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9372 connect.fils_erp_username_len =
9373 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9374 connect.fils_erp_realm =
9375 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9376 connect.fils_erp_realm_len =
9377 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9378 connect.fils_erp_next_seq_num =
9379 nla_get_u16(
9380 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9381 connect.fils_erp_rrk =
9382 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9383 connect.fils_erp_rrk_len =
9384 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9385 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9386 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9387 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9388 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9389 kzfree(connkeys);
9390 return -EINVAL;
9391 }
9392
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009393 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9394 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +05309395 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009396 GENL_SET_ERR_MSG(info,
9397 "external auth requires connection ownership");
9398 return -EINVAL;
9399 }
9400 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9401 }
9402
Johannes Berg83739b02013-05-15 17:44:01 +02009403 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009404
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009405 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9406 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009407 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009408 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009409
9410 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9411 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9412 if (connect.bssid)
9413 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9414 connect.bssid, ETH_ALEN);
9415 else
9416 memset(dev->ieee80211_ptr->disconnect_bssid,
9417 0, ETH_ALEN);
9418 }
9419
9420 wdev_unlock(dev->ieee80211_ptr);
9421
Samuel Ortizb23aa672009-07-01 21:26:54 +02009422 return err;
9423}
9424
vamsi krishna088e8df2016-10-27 16:51:11 +03009425static int nl80211_update_connect_params(struct sk_buff *skb,
9426 struct genl_info *info)
9427{
9428 struct cfg80211_connect_params connect = {};
9429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9430 struct net_device *dev = info->user_ptr[1];
9431 struct wireless_dev *wdev = dev->ieee80211_ptr;
9432 u32 changed = 0;
9433 int ret;
9434
9435 if (!rdev->ops->update_connect_params)
9436 return -EOPNOTSUPP;
9437
9438 if (info->attrs[NL80211_ATTR_IE]) {
9439 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9440 return -EINVAL;
9441 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9442 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9443 changed |= UPDATE_ASSOC_IES;
9444 }
9445
9446 wdev_lock(dev->ieee80211_ptr);
9447 if (!wdev->current_bss)
9448 ret = -ENOLINK;
9449 else
9450 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9451 wdev_unlock(dev->ieee80211_ptr);
9452
9453 return ret;
9454}
9455
Samuel Ortizb23aa672009-07-01 21:26:54 +02009456static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9457{
Johannes Berg4c476992010-10-04 21:36:35 +02009458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9459 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009460 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009461 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009462
9463 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9464 reason = WLAN_REASON_DEAUTH_LEAVING;
9465 else
9466 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9467
9468 if (reason == 0)
9469 return -EINVAL;
9470
Johannes Berg074ac8d2010-09-16 14:58:22 +02009471 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009472 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9473 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009474
Johannes Berg83739b02013-05-15 17:44:01 +02009475 wdev_lock(dev->ieee80211_ptr);
9476 ret = cfg80211_disconnect(rdev, dev, reason, true);
9477 wdev_unlock(dev->ieee80211_ptr);
9478 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009479}
9480
Johannes Berg463d0182009-07-14 00:33:35 +02009481static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9482{
Johannes Berg4c476992010-10-04 21:36:35 +02009483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009484 struct net *net;
9485 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009486
Vadim Kochan4b681c82015-01-12 16:34:05 +02009487 if (info->attrs[NL80211_ATTR_PID]) {
9488 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9489
9490 net = get_net_ns_by_pid(pid);
9491 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9492 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9493
9494 net = get_net_ns_by_fd(fd);
9495 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009496 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009497 }
Johannes Berg463d0182009-07-14 00:33:35 +02009498
Johannes Berg4c476992010-10-04 21:36:35 +02009499 if (IS_ERR(net))
9500 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009501
9502 err = 0;
9503
9504 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009505 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9506 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009507
Johannes Berg463d0182009-07-14 00:33:35 +02009508 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009509 return err;
9510}
9511
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009512static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9513{
Johannes Berg4c476992010-10-04 21:36:35 +02009514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009515 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9516 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009517 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009518 struct cfg80211_pmksa pmksa;
9519
9520 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9521
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009522 if (!info->attrs[NL80211_ATTR_PMKID])
9523 return -EINVAL;
9524
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009525 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009526
9527 if (info->attrs[NL80211_ATTR_MAC]) {
9528 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9529 } else if (info->attrs[NL80211_ATTR_SSID] &&
9530 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9531 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9532 info->attrs[NL80211_ATTR_PMK])) {
9533 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9534 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9535 pmksa.cache_id =
9536 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9537 } else {
9538 return -EINVAL;
9539 }
9540 if (info->attrs[NL80211_ATTR_PMK]) {
9541 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9542 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9543 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009544
Johannes Berg074ac8d2010-09-16 14:58:22 +02009545 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009546 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9547 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009548
9549 switch (info->genlhdr->cmd) {
9550 case NL80211_CMD_SET_PMKSA:
9551 rdev_ops = rdev->ops->set_pmksa;
9552 break;
9553 case NL80211_CMD_DEL_PMKSA:
9554 rdev_ops = rdev->ops->del_pmksa;
9555 break;
9556 default:
9557 WARN_ON(1);
9558 break;
9559 }
9560
Johannes Berg4c476992010-10-04 21:36:35 +02009561 if (!rdev_ops)
9562 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009563
Johannes Berg4c476992010-10-04 21:36:35 +02009564 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009565}
9566
9567static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9568{
Johannes Berg4c476992010-10-04 21:36:35 +02009569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9570 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009571
Johannes Berg074ac8d2010-09-16 14:58:22 +02009572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009573 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9574 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009575
Johannes Berg4c476992010-10-04 21:36:35 +02009576 if (!rdev->ops->flush_pmksa)
9577 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009578
Hila Gonene35e4d22012-06-27 17:19:42 +03009579 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009580}
9581
Arik Nemtsov109086c2011-09-28 14:12:50 +03009582static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9583{
9584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9585 struct net_device *dev = info->user_ptr[1];
9586 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309587 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009588 u16 status_code;
9589 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009590 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009591
9592 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9593 !rdev->ops->tdls_mgmt)
9594 return -EOPNOTSUPP;
9595
9596 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9597 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9598 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9599 !info->attrs[NL80211_ATTR_IE] ||
9600 !info->attrs[NL80211_ATTR_MAC])
9601 return -EINVAL;
9602
9603 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9604 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9605 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9606 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009607 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309608 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9609 peer_capability =
9610 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009611
Hila Gonene35e4d22012-06-27 17:19:42 +03009612 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309613 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009614 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009615 nla_data(info->attrs[NL80211_ATTR_IE]),
9616 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009617}
9618
9619static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9620{
9621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9622 struct net_device *dev = info->user_ptr[1];
9623 enum nl80211_tdls_operation operation;
9624 u8 *peer;
9625
9626 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9627 !rdev->ops->tdls_oper)
9628 return -EOPNOTSUPP;
9629
9630 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9631 !info->attrs[NL80211_ATTR_MAC])
9632 return -EINVAL;
9633
9634 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9635 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9636
Hila Gonene35e4d22012-06-27 17:19:42 +03009637 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009638}
9639
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009640static int nl80211_remain_on_channel(struct sk_buff *skb,
9641 struct genl_info *info)
9642{
Johannes Berg4c476992010-10-04 21:36:35 +02009643 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009644 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009645 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309646 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009647 struct sk_buff *msg;
9648 void *hdr;
9649 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009650 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009651 int err;
9652
9653 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9654 !info->attrs[NL80211_ATTR_DURATION])
9655 return -EINVAL;
9656
9657 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9658
Johannes Berg7c4ef712011-11-18 15:33:48 +01009659 if (!rdev->ops->remain_on_channel ||
9660 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009661 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009662
Johannes Bergebf348f2012-06-01 12:50:54 +02009663 /*
9664 * We should be on that channel for at least a minimum amount of
9665 * time (10ms) but no longer than the driver supports.
9666 */
9667 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9668 duration > rdev->wiphy.max_remain_on_channel_duration)
9669 return -EINVAL;
9670
Johannes Berg683b6d32012-11-08 21:25:48 +01009671 err = nl80211_parse_chandef(rdev, info, &chandef);
9672 if (err)
9673 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009674
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309675 wdev_lock(wdev);
9676 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9677 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9678 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9679 &chandef);
9680 if (compat_chandef != &chandef) {
9681 wdev_unlock(wdev);
9682 return -EBUSY;
9683 }
9684 }
9685 wdev_unlock(wdev);
9686
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009688 if (!msg)
9689 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009690
Eric W. Biederman15e47302012-09-07 20:12:54 +00009691 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009692 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009693 if (!hdr) {
9694 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009695 goto free_msg;
9696 }
9697
Johannes Berg683b6d32012-11-08 21:25:48 +01009698 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9699 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009700
9701 if (err)
9702 goto free_msg;
9703
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009704 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9705 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009706 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009707
9708 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009709
9710 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009711
9712 nla_put_failure:
9713 err = -ENOBUFS;
9714 free_msg:
9715 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009716 return err;
9717}
9718
9719static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9720 struct genl_info *info)
9721{
Johannes Berg4c476992010-10-04 21:36:35 +02009722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009723 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009724 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009725
9726 if (!info->attrs[NL80211_ATTR_COOKIE])
9727 return -EINVAL;
9728
Johannes Berg4c476992010-10-04 21:36:35 +02009729 if (!rdev->ops->cancel_remain_on_channel)
9730 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009731
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009732 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9733
Hila Gonene35e4d22012-06-27 17:19:42 +03009734 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009735}
9736
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009737static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9738 struct genl_info *info)
9739{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009740 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009742 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309743 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009744
Johannes Berg4c476992010-10-04 21:36:35 +02009745 if (!rdev->ops->set_bitrate_mask)
9746 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009747
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309748 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9749 if (err)
9750 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009751
Hila Gonene35e4d22012-06-27 17:19:42 +03009752 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009753}
9754
Johannes Berg2e161f72010-08-12 15:38:38 +02009755static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009756{
Johannes Berg4c476992010-10-04 21:36:35 +02009757 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009758 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009759 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009760
9761 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9762 return -EINVAL;
9763
Johannes Berg2e161f72010-08-12 15:38:38 +02009764 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9765 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009766
Johannes Berg71bbc992012-06-15 15:30:18 +02009767 switch (wdev->iftype) {
9768 case NL80211_IFTYPE_STATION:
9769 case NL80211_IFTYPE_ADHOC:
9770 case NL80211_IFTYPE_P2P_CLIENT:
9771 case NL80211_IFTYPE_AP:
9772 case NL80211_IFTYPE_AP_VLAN:
9773 case NL80211_IFTYPE_MESH_POINT:
9774 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009775 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009776 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009777 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009778 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009779 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009780 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009781
9782 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009783 if (!rdev->ops->mgmt_tx)
9784 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009785
Eric W. Biederman15e47302012-09-07 20:12:54 +00009786 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009787 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9788 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009789}
9790
Johannes Berg2e161f72010-08-12 15:38:38 +02009791static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009792{
Johannes Berg4c476992010-10-04 21:36:35 +02009793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009794 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009795 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009796 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009797 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009798 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009799 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009800 struct cfg80211_mgmt_tx_params params = {
9801 .dont_wait_for_ack =
9802 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9803 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009804
Johannes Berg683b6d32012-11-08 21:25:48 +01009805 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009806 return -EINVAL;
9807
Johannes Berg4c476992010-10-04 21:36:35 +02009808 if (!rdev->ops->mgmt_tx)
9809 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009810
Johannes Berg71bbc992012-06-15 15:30:18 +02009811 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009812 case NL80211_IFTYPE_P2P_DEVICE:
9813 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9814 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009815 case NL80211_IFTYPE_STATION:
9816 case NL80211_IFTYPE_ADHOC:
9817 case NL80211_IFTYPE_P2P_CLIENT:
9818 case NL80211_IFTYPE_AP:
9819 case NL80211_IFTYPE_AP_VLAN:
9820 case NL80211_IFTYPE_MESH_POINT:
9821 case NL80211_IFTYPE_P2P_GO:
9822 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009823 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009824 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009825 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009826 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009827
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009828 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009829 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009830 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009831 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009832
9833 /*
9834 * We should wait on the channel for at least a minimum amount
9835 * of time (10ms) but no longer than the driver supports.
9836 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009837 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9838 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009839 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009840 }
9841
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009842 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009843
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009844 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009845 return -EINVAL;
9846
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009847 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309848
Antonio Quartulliea141b752013-06-11 14:20:03 +02009849 /* get the channel if any has been specified, otherwise pass NULL to
9850 * the driver. The latter will use the current one
9851 */
9852 chandef.chan = NULL;
9853 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9854 err = nl80211_parse_chandef(rdev, info, &chandef);
9855 if (err)
9856 return err;
9857 }
9858
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009859 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009860 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009861
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309862 wdev_lock(wdev);
9863 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9864 wdev_unlock(wdev);
9865 return -EBUSY;
9866 }
9867 wdev_unlock(wdev);
9868
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009869 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9870 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9871
9872 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9873 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9874 int i;
9875
9876 if (len % sizeof(u16))
9877 return -EINVAL;
9878
9879 params.n_csa_offsets = len / sizeof(u16);
9880 params.csa_offsets =
9881 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9882
9883 /* check that all the offsets fit the frame */
9884 for (i = 0; i < params.n_csa_offsets; i++) {
9885 if (params.csa_offsets[i] >= params.len)
9886 return -EINVAL;
9887 }
9888 }
9889
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009890 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009891 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9892 if (!msg)
9893 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009894
Eric W. Biederman15e47302012-09-07 20:12:54 +00009895 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009896 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009897 if (!hdr) {
9898 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009899 goto free_msg;
9900 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009901 }
Johannes Berge247bd902011-11-04 11:18:21 +01009902
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009903 params.chan = chandef.chan;
9904 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009905 if (err)
9906 goto free_msg;
9907
Johannes Berge247bd902011-11-04 11:18:21 +01009908 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009909 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9910 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009911 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009912
Johannes Berge247bd902011-11-04 11:18:21 +01009913 genlmsg_end(msg, hdr);
9914 return genlmsg_reply(msg, info);
9915 }
9916
9917 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009918
9919 nla_put_failure:
9920 err = -ENOBUFS;
9921 free_msg:
9922 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009923 return err;
9924}
9925
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009926static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9927{
9928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009929 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009930 u64 cookie;
9931
9932 if (!info->attrs[NL80211_ATTR_COOKIE])
9933 return -EINVAL;
9934
9935 if (!rdev->ops->mgmt_tx_cancel_wait)
9936 return -EOPNOTSUPP;
9937
Johannes Berg71bbc992012-06-15 15:30:18 +02009938 switch (wdev->iftype) {
9939 case NL80211_IFTYPE_STATION:
9940 case NL80211_IFTYPE_ADHOC:
9941 case NL80211_IFTYPE_P2P_CLIENT:
9942 case NL80211_IFTYPE_AP:
9943 case NL80211_IFTYPE_AP_VLAN:
9944 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009945 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009946 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009947 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009948 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009949 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009950 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009951
9952 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9953
Hila Gonene35e4d22012-06-27 17:19:42 +03009954 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009955}
9956
Kalle Valoffb9eb32010-02-17 17:58:10 +02009957static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9958{
Johannes Berg4c476992010-10-04 21:36:35 +02009959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009960 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009961 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009962 u8 ps_state;
9963 bool state;
9964 int err;
9965
Johannes Berg4c476992010-10-04 21:36:35 +02009966 if (!info->attrs[NL80211_ATTR_PS_STATE])
9967 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009968
9969 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9970
Johannes Berg4c476992010-10-04 21:36:35 +02009971 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9972 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009973
9974 wdev = dev->ieee80211_ptr;
9975
Johannes Berg4c476992010-10-04 21:36:35 +02009976 if (!rdev->ops->set_power_mgmt)
9977 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009978
9979 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9980
9981 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009982 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009983
Hila Gonene35e4d22012-06-27 17:19:42 +03009984 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009985 if (!err)
9986 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009987 return err;
9988}
9989
9990static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9991{
Johannes Berg4c476992010-10-04 21:36:35 +02009992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009993 enum nl80211_ps_state ps_state;
9994 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009995 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009996 struct sk_buff *msg;
9997 void *hdr;
9998 int err;
9999
Kalle Valoffb9eb32010-02-17 17:58:10 +020010000 wdev = dev->ieee80211_ptr;
10001
Johannes Berg4c476992010-10-04 21:36:35 +020010002 if (!rdev->ops->set_power_mgmt)
10003 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010004
10005 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010006 if (!msg)
10007 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010008
Eric W. Biederman15e47302012-09-07 20:12:54 +000010009 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010010 NL80211_CMD_GET_POWER_SAVE);
10011 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010012 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010013 goto free_msg;
10014 }
10015
10016 if (wdev->ps)
10017 ps_state = NL80211_PS_ENABLED;
10018 else
10019 ps_state = NL80211_PS_DISABLED;
10020
David S. Miller9360ffd2012-03-29 04:41:26 -040010021 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10022 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010023
10024 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010025 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010026
Johannes Berg4c476992010-10-04 21:36:35 +020010027 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010028 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010029 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010030 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010031 return err;
10032}
10033
Johannes Berg94e860f2014-01-20 23:58:15 +010010034static const struct nla_policy
10035nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010036 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010037 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10038 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010039 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10040 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10041 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010042 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010043};
10044
Thomas Pedersen84f10702012-07-12 16:17:33 -070010045static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010046 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010047{
10048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010049 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010050 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010051
Johannes Bergd9d8b012012-11-26 12:51:52 +010010052 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010053 return -EINVAL;
10054
Thomas Pedersen84f10702012-07-12 16:17:33 -070010055 if (!rdev->ops->set_cqm_txe_config)
10056 return -EOPNOTSUPP;
10057
10058 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10059 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10060 return -EOPNOTSUPP;
10061
Hila Gonene35e4d22012-06-27 17:19:42 +030010062 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010063}
10064
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010065static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10066 struct net_device *dev)
10067{
10068 struct wireless_dev *wdev = dev->ieee80211_ptr;
10069 s32 last, low, high;
10070 u32 hyst;
10071 int i, n;
10072 int err;
10073
10074 /* RSSI reporting disabled? */
10075 if (!wdev->cqm_config)
10076 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10077
10078 /*
10079 * Obtain current RSSI value if possible, if not and no RSSI threshold
10080 * event has been received yet, we should receive an event after a
10081 * connection is established and enough beacons received to calculate
10082 * the average.
10083 */
10084 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10085 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020010086 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010087 u8 *mac_addr;
10088
10089 mac_addr = wdev->current_bss->pub.bssid;
10090
Johannes Berg73887fd2018-05-18 09:57:55 +020010091 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10092 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010093 return err;
10094
Johannes Berg73887fd2018-05-18 09:57:55 +020010095 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010096 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020010097 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010098 }
10099
10100 last = wdev->cqm_config->last_rssi_event_value;
10101 hyst = wdev->cqm_config->rssi_hyst;
10102 n = wdev->cqm_config->n_rssi_thresholds;
10103
10104 for (i = 0; i < n; i++)
10105 if (last < wdev->cqm_config->rssi_thresholds[i])
10106 break;
10107
10108 low = i > 0 ?
10109 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
10110 high = i < n ?
10111 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
10112
10113 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10114}
10115
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010116static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010117 const s32 *thresholds, int n_thresholds,
10118 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010119{
Johannes Berg4c476992010-10-04 21:36:35 +020010120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010121 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010122 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010123 int i, err;
10124 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010125
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010126 /* Check all values negative and sorted */
10127 for (i = 0; i < n_thresholds; i++) {
10128 if (thresholds[i] > 0 || thresholds[i] <= prev)
10129 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010130
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010131 prev = thresholds[i];
10132 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010133
Johannes Berg074ac8d2010-09-16 14:58:22 +020010134 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010135 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10136 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010137
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010138 wdev_lock(wdev);
10139 cfg80211_cqm_config_free(wdev);
10140 wdev_unlock(wdev);
10141
10142 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10143 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10144 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10145
10146 return rdev_set_cqm_rssi_config(rdev, dev,
10147 thresholds[0], hysteresis);
10148 }
10149
10150 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10151 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10152 return -EOPNOTSUPP;
10153
10154 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10155 n_thresholds = 0;
10156
10157 wdev_lock(wdev);
10158 if (n_thresholds) {
10159 struct cfg80211_cqm_config *cqm_config;
10160
10161 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10162 n_thresholds * sizeof(s32), GFP_KERNEL);
10163 if (!cqm_config) {
10164 err = -ENOMEM;
10165 goto unlock;
10166 }
10167
10168 cqm_config->rssi_hyst = hysteresis;
10169 cqm_config->n_rssi_thresholds = n_thresholds;
10170 memcpy(cqm_config->rssi_thresholds, thresholds,
10171 n_thresholds * sizeof(s32));
10172
10173 wdev->cqm_config = cqm_config;
10174 }
10175
10176 err = cfg80211_cqm_rssi_update(rdev, dev);
10177
10178unlock:
10179 wdev_unlock(wdev);
10180
10181 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010182}
10183
10184static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10185{
10186 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10187 struct nlattr *cqm;
10188 int err;
10189
10190 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010191 if (!cqm)
10192 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010193
10194 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +020010195 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010196 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010197 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010198
10199 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10200 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010201 const s32 *thresholds =
10202 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10203 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010204 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010205
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010206 if (len % 4)
10207 return -EINVAL;
10208
10209 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10210 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010211 }
10212
10213 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10214 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10215 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10216 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10217 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10218 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10219
10220 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10221 }
10222
10223 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010224}
10225
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010226static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10227{
10228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10229 struct net_device *dev = info->user_ptr[1];
10230 struct ocb_setup setup = {};
10231 int err;
10232
10233 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10234 if (err)
10235 return err;
10236
10237 return cfg80211_join_ocb(rdev, dev, &setup);
10238}
10239
10240static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10241{
10242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10243 struct net_device *dev = info->user_ptr[1];
10244
10245 return cfg80211_leave_ocb(rdev, dev);
10246}
10247
Johannes Berg29cbe682010-12-03 09:20:44 +010010248static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10249{
10250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10251 struct net_device *dev = info->user_ptr[1];
10252 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010253 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010254 int err;
10255
10256 /* start with default */
10257 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010258 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010259
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010260 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010261 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010262 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010263 if (err)
10264 return err;
10265 }
10266
10267 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10268 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10269 return -EINVAL;
10270
Javier Cardonac80d5452010-12-16 17:37:49 -080010271 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10272 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10273
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010274 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10275 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10276 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10277 return -EINVAL;
10278
Marco Porsch9bdbf042013-01-07 16:04:51 +010010279 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10280 setup.beacon_interval =
10281 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010282
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010283 err = cfg80211_validate_beacon_int(rdev,
10284 NL80211_IFTYPE_MESH_POINT,
10285 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010286 if (err)
10287 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010288 }
10289
10290 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10291 setup.dtim_period =
10292 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10293 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10294 return -EINVAL;
10295 }
10296
Javier Cardonac80d5452010-12-16 17:37:49 -080010297 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10298 /* parse additional setup parameters if given */
10299 err = nl80211_parse_mesh_setup(info, &setup);
10300 if (err)
10301 return err;
10302 }
10303
Thomas Pedersend37bb182013-03-04 13:06:13 -080010304 if (setup.user_mpm)
10305 cfg.auto_open_plinks = false;
10306
Johannes Bergcc1d2802012-05-16 23:50:20 +020010307 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010308 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10309 if (err)
10310 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010311 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010312 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010313 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010314 }
10315
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010316 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10317 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10318 int n_rates =
10319 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10320 struct ieee80211_supported_band *sband;
10321
10322 if (!setup.chandef.chan)
10323 return -EINVAL;
10324
10325 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10326
10327 err = ieee80211_get_ratemask(sband, rates, n_rates,
10328 &setup.basic_rates);
10329 if (err)
10330 return err;
10331 }
10332
Johannes Berg8564e382016-09-19 09:44:44 +020010333 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10334 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10335 if (err)
10336 return err;
10337
Johannes Berg265698d2017-09-18 22:46:36 +020010338 if (!setup.chandef.chan)
10339 return -EINVAL;
10340
Johannes Berg8564e382016-09-19 09:44:44 +020010341 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10342 &setup.beacon_rate);
10343 if (err)
10344 return err;
10345 }
10346
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010347 setup.userspace_handles_dfs =
10348 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10349
Denis Kenzior1224f582018-03-26 12:52:49 -050010350 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10351 int r = validate_pae_over_nl80211(rdev, info);
10352
10353 if (r < 0)
10354 return r;
10355
10356 setup.control_port_over_nl80211 = true;
10357 }
10358
Denis Kenzior188c1b32018-03-26 12:52:46 -050010359 wdev_lock(dev->ieee80211_ptr);
10360 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10361 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10362 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10363 wdev_unlock(dev->ieee80211_ptr);
10364
10365 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010366}
10367
10368static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10369{
10370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10371 struct net_device *dev = info->user_ptr[1];
10372
10373 return cfg80211_leave_mesh(rdev, dev);
10374}
10375
Johannes Bergdfb89c52012-06-27 09:23:48 +020010376#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010377static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10378 struct cfg80211_registered_device *rdev)
10379{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010380 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010381 struct nlattr *nl_pats, *nl_pat;
10382 int i, pat_len;
10383
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010384 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010385 return 0;
10386
10387 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10388 if (!nl_pats)
10389 return -ENOBUFS;
10390
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010391 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010392 nl_pat = nla_nest_start(msg, i + 1);
10393 if (!nl_pat)
10394 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010395 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010396 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010397 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010398 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10399 wowlan->patterns[i].pattern) ||
10400 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010401 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010402 return -ENOBUFS;
10403 nla_nest_end(msg, nl_pat);
10404 }
10405 nla_nest_end(msg, nl_pats);
10406
10407 return 0;
10408}
10409
Johannes Berg2a0e0472013-01-23 22:57:40 +010010410static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10411 struct cfg80211_wowlan_tcp *tcp)
10412{
10413 struct nlattr *nl_tcp;
10414
10415 if (!tcp)
10416 return 0;
10417
10418 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10419 if (!nl_tcp)
10420 return -ENOBUFS;
10421
Jiri Benc930345e2015-03-29 16:59:25 +020010422 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10423 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010424 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10425 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10426 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10427 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10428 tcp->payload_len, tcp->payload) ||
10429 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10430 tcp->data_interval) ||
10431 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10432 tcp->wake_len, tcp->wake_data) ||
10433 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10434 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10435 return -ENOBUFS;
10436
10437 if (tcp->payload_seq.len &&
10438 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10439 sizeof(tcp->payload_seq), &tcp->payload_seq))
10440 return -ENOBUFS;
10441
10442 if (tcp->payload_tok.len &&
10443 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10444 sizeof(tcp->payload_tok) + tcp->tokens_size,
10445 &tcp->payload_tok))
10446 return -ENOBUFS;
10447
Johannes Berge248ad32013-05-16 10:24:28 +020010448 nla_nest_end(msg, nl_tcp);
10449
Johannes Berg2a0e0472013-01-23 22:57:40 +010010450 return 0;
10451}
10452
Luciano Coelho75453cc2015-01-09 14:06:37 +020010453static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10454 struct cfg80211_sched_scan_request *req)
10455{
Avraham Stern3b06d272015-10-12 09:51:34 +030010456 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010457 int i;
10458
10459 if (!req)
10460 return 0;
10461
10462 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10463 if (!nd)
10464 return -ENOBUFS;
10465
Avraham Stern3b06d272015-10-12 09:51:34 +030010466 if (req->n_scan_plans == 1 &&
10467 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10468 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010469 return -ENOBUFS;
10470
Luciano Coelho21fea562015-03-17 16:36:01 +020010471 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10472 return -ENOBUFS;
10473
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010474 if (req->relative_rssi_set) {
10475 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10476
10477 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10478 req->relative_rssi))
10479 return -ENOBUFS;
10480
10481 rssi_adjust.band = req->rssi_adjust.band;
10482 rssi_adjust.delta = req->rssi_adjust.delta;
10483 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10484 sizeof(rssi_adjust), &rssi_adjust))
10485 return -ENOBUFS;
10486 }
10487
Luciano Coelho75453cc2015-01-09 14:06:37 +020010488 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10489 if (!freqs)
10490 return -ENOBUFS;
10491
Johannes Berg53b18982016-09-14 09:59:21 +020010492 for (i = 0; i < req->n_channels; i++) {
10493 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10494 return -ENOBUFS;
10495 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010496
10497 nla_nest_end(msg, freqs);
10498
10499 if (req->n_match_sets) {
10500 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010501 if (!matches)
10502 return -ENOBUFS;
10503
Luciano Coelho75453cc2015-01-09 14:06:37 +020010504 for (i = 0; i < req->n_match_sets; i++) {
10505 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010506 if (!match)
10507 return -ENOBUFS;
10508
Johannes Berg53b18982016-09-14 09:59:21 +020010509 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10510 req->match_sets[i].ssid.ssid_len,
10511 req->match_sets[i].ssid.ssid))
10512 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010513 nla_nest_end(msg, match);
10514 }
10515 nla_nest_end(msg, matches);
10516 }
10517
Avraham Stern3b06d272015-10-12 09:51:34 +030010518 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10519 if (!scan_plans)
10520 return -ENOBUFS;
10521
10522 for (i = 0; i < req->n_scan_plans; i++) {
10523 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010524 if (!scan_plan)
10525 return -ENOBUFS;
10526
Avraham Stern3b06d272015-10-12 09:51:34 +030010527 if (!scan_plan ||
10528 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10529 req->scan_plans[i].interval) ||
10530 (req->scan_plans[i].iterations &&
10531 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10532 req->scan_plans[i].iterations)))
10533 return -ENOBUFS;
10534 nla_nest_end(msg, scan_plan);
10535 }
10536 nla_nest_end(msg, scan_plans);
10537
Luciano Coelho75453cc2015-01-09 14:06:37 +020010538 nla_nest_end(msg, nd);
10539
10540 return 0;
10541}
10542
Johannes Bergff1b6e62011-05-04 15:37:28 +020010543static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10544{
10545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10546 struct sk_buff *msg;
10547 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010548 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010549
Johannes Berg964dc9e2013-06-03 17:25:34 +020010550 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010551 return -EOPNOTSUPP;
10552
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010553 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010554 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010555 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10556 rdev->wiphy.wowlan_config->tcp->payload_len +
10557 rdev->wiphy.wowlan_config->tcp->wake_len +
10558 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010559 }
10560
10561 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010562 if (!msg)
10563 return -ENOMEM;
10564
Eric W. Biederman15e47302012-09-07 20:12:54 +000010565 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010566 NL80211_CMD_GET_WOWLAN);
10567 if (!hdr)
10568 goto nla_put_failure;
10569
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010570 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010571 struct nlattr *nl_wowlan;
10572
10573 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10574 if (!nl_wowlan)
10575 goto nla_put_failure;
10576
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010577 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010578 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010579 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010581 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010583 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010585 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010587 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010588 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010589 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010590 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10591 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010592
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010593 if (nl80211_send_wowlan_patterns(msg, rdev))
10594 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010595
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010596 if (nl80211_send_wowlan_tcp(msg,
10597 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010598 goto nla_put_failure;
10599
Luciano Coelho75453cc2015-01-09 14:06:37 +020010600 if (nl80211_send_wowlan_nd(
10601 msg,
10602 rdev->wiphy.wowlan_config->nd_config))
10603 goto nla_put_failure;
10604
Johannes Bergff1b6e62011-05-04 15:37:28 +020010605 nla_nest_end(msg, nl_wowlan);
10606 }
10607
10608 genlmsg_end(msg, hdr);
10609 return genlmsg_reply(msg, info);
10610
10611nla_put_failure:
10612 nlmsg_free(msg);
10613 return -ENOBUFS;
10614}
10615
Johannes Berg2a0e0472013-01-23 22:57:40 +010010616static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10617 struct nlattr *attr,
10618 struct cfg80211_wowlan *trig)
10619{
10620 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10621 struct cfg80211_wowlan_tcp *cfg;
10622 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10623 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10624 u32 size;
10625 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10626 int err, port;
10627
Johannes Berg964dc9e2013-06-03 17:25:34 +020010628 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010629 return -EINVAL;
10630
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010631 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010632 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010633 if (err)
10634 return err;
10635
10636 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10637 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10638 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10639 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10640 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10641 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10642 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10643 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10644 return -EINVAL;
10645
10646 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010647 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010648 return -EINVAL;
10649
10650 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010651 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010652 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010653 return -EINVAL;
10654
10655 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010656 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010657 return -EINVAL;
10658
10659 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10660 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10661 return -EINVAL;
10662
10663 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10664 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10665
10666 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10667 tokens_size = tokln - sizeof(*tok);
10668
10669 if (!tok->len || tokens_size % tok->len)
10670 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010671 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010672 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010673 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010674 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010675 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010676 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010677 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010678 return -EINVAL;
10679 if (tok->offset + tok->len > data_size)
10680 return -EINVAL;
10681 }
10682
10683 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10684 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010685 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010686 return -EINVAL;
10687 if (seq->len == 0 || seq->len > 4)
10688 return -EINVAL;
10689 if (seq->len + seq->offset > data_size)
10690 return -EINVAL;
10691 }
10692
10693 size = sizeof(*cfg);
10694 size += data_size;
10695 size += wake_size + wake_mask_size;
10696 size += tokens_size;
10697
10698 cfg = kzalloc(size, GFP_KERNEL);
10699 if (!cfg)
10700 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010701 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10702 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010703 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10704 ETH_ALEN);
10705 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10706 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10707 else
10708 port = 0;
10709#ifdef CONFIG_INET
10710 /* allocate a socket and port for it and use it */
10711 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10712 IPPROTO_TCP, &cfg->sock, 1);
10713 if (err) {
10714 kfree(cfg);
10715 return err;
10716 }
10717 if (inet_csk_get_port(cfg->sock->sk, port)) {
10718 sock_release(cfg->sock);
10719 kfree(cfg);
10720 return -EADDRINUSE;
10721 }
10722 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10723#else
10724 if (!port) {
10725 kfree(cfg);
10726 return -EINVAL;
10727 }
10728 cfg->src_port = port;
10729#endif
10730
10731 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10732 cfg->payload_len = data_size;
10733 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10734 memcpy((void *)cfg->payload,
10735 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10736 data_size);
10737 if (seq)
10738 cfg->payload_seq = *seq;
10739 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10740 cfg->wake_len = wake_size;
10741 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10742 memcpy((void *)cfg->wake_data,
10743 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10744 wake_size);
10745 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10746 data_size + wake_size;
10747 memcpy((void *)cfg->wake_mask,
10748 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10749 wake_mask_size);
10750 if (tok) {
10751 cfg->tokens_size = tokens_size;
10752 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10753 }
10754
10755 trig->tcp = cfg;
10756
10757 return 0;
10758}
10759
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010760static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10761 const struct wiphy_wowlan_support *wowlan,
10762 struct nlattr *attr,
10763 struct cfg80211_wowlan *trig)
10764{
10765 struct nlattr **tb;
10766 int err;
10767
10768 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10769 if (!tb)
10770 return -ENOMEM;
10771
10772 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10773 err = -EOPNOTSUPP;
10774 goto out;
10775 }
10776
Johannes Bergfceb6432017-04-12 14:34:07 +020010777 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10778 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010779 if (err)
10780 goto out;
10781
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010782 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10783 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010784 err = PTR_ERR_OR_ZERO(trig->nd_config);
10785 if (err)
10786 trig->nd_config = NULL;
10787
10788out:
10789 kfree(tb);
10790 return err;
10791}
10792
Johannes Bergff1b6e62011-05-04 15:37:28 +020010793static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10794{
10795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10796 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010797 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010798 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010799 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010800 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010801 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010802 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010803
Johannes Berg964dc9e2013-06-03 17:25:34 +020010804 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010805 return -EOPNOTSUPP;
10806
Johannes Bergae33bd82012-07-12 16:25:02 +020010807 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10808 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010809 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010810 goto set_wakeup;
10811 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010812
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010813 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10814 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010815 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010816 if (err)
10817 return err;
10818
10819 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10820 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10821 return -EINVAL;
10822 new_triggers.any = true;
10823 }
10824
10825 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10826 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10827 return -EINVAL;
10828 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010829 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010830 }
10831
10832 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10833 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10834 return -EINVAL;
10835 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010836 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010837 }
10838
Johannes Berg77dbbb12011-07-13 10:48:55 +020010839 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10840 return -EINVAL;
10841
10842 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10843 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10844 return -EINVAL;
10845 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010846 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010847 }
10848
10849 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10850 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10851 return -EINVAL;
10852 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010853 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010854 }
10855
10856 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10857 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10858 return -EINVAL;
10859 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010860 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010861 }
10862
10863 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10864 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10865 return -EINVAL;
10866 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010867 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010868 }
10869
Johannes Bergff1b6e62011-05-04 15:37:28 +020010870 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10871 struct nlattr *pat;
10872 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010873 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010874 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010875
Johannes Berg98fc4382015-03-01 09:10:13 +020010876 regular = true;
10877
Johannes Bergff1b6e62011-05-04 15:37:28 +020010878 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10879 rem)
10880 n_patterns++;
10881 if (n_patterns > wowlan->n_patterns)
10882 return -EINVAL;
10883
10884 new_triggers.patterns = kcalloc(n_patterns,
10885 sizeof(new_triggers.patterns[0]),
10886 GFP_KERNEL);
10887 if (!new_triggers.patterns)
10888 return -ENOMEM;
10889
10890 new_triggers.n_patterns = n_patterns;
10891 i = 0;
10892
10893 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10894 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010895 u8 *mask_pat;
10896
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010897 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030010898 nl80211_packet_pattern_policy,
10899 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010900 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010901 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10902 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010903 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010904 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010905 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010906 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010907 goto error;
10908 if (pat_len > wowlan->pattern_max_len ||
10909 pat_len < wowlan->pattern_min_len)
10910 goto error;
10911
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010912 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010913 pkt_offset = 0;
10914 else
10915 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010916 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010917 if (pkt_offset > wowlan->max_pkt_offset)
10918 goto error;
10919 new_triggers.patterns[i].pkt_offset = pkt_offset;
10920
Johannes Berg922bd802014-05-19 17:59:50 +020010921 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10922 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010923 err = -ENOMEM;
10924 goto error;
10925 }
Johannes Berg922bd802014-05-19 17:59:50 +020010926 new_triggers.patterns[i].mask = mask_pat;
10927 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010928 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010929 mask_pat += mask_len;
10930 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010931 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010932 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010933 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010934 pat_len);
10935 i++;
10936 }
10937 }
10938
Johannes Berg2a0e0472013-01-23 22:57:40 +010010939 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010940 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010941 err = nl80211_parse_wowlan_tcp(
10942 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10943 &new_triggers);
10944 if (err)
10945 goto error;
10946 }
10947
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010948 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010949 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010950 err = nl80211_parse_wowlan_nd(
10951 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10952 &new_triggers);
10953 if (err)
10954 goto error;
10955 }
10956
Johannes Berg98fc4382015-03-01 09:10:13 +020010957 /* The 'any' trigger means the device continues operating more or less
10958 * as in its normal operation mode and wakes up the host on most of the
10959 * normal interrupts (like packet RX, ...)
10960 * It therefore makes little sense to combine with the more constrained
10961 * wakeup trigger modes.
10962 */
10963 if (new_triggers.any && regular) {
10964 err = -EINVAL;
10965 goto error;
10966 }
10967
Johannes Bergae33bd82012-07-12 16:25:02 +020010968 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10969 if (!ntrig) {
10970 err = -ENOMEM;
10971 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010972 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010973 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010974 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010975
Johannes Bergae33bd82012-07-12 16:25:02 +020010976 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010977 if (rdev->ops->set_wakeup &&
10978 prev_enabled != !!rdev->wiphy.wowlan_config)
10979 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010980
Johannes Bergff1b6e62011-05-04 15:37:28 +020010981 return 0;
10982 error:
10983 for (i = 0; i < new_triggers.n_patterns; i++)
10984 kfree(new_triggers.patterns[i].mask);
10985 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010986 if (new_triggers.tcp && new_triggers.tcp->sock)
10987 sock_release(new_triggers.tcp->sock);
10988 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010989 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010990 return err;
10991}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010992#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010993
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010994static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10995 struct cfg80211_registered_device *rdev)
10996{
10997 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10998 int i, j, pat_len;
10999 struct cfg80211_coalesce_rules *rule;
11000
11001 if (!rdev->coalesce->n_rules)
11002 return 0;
11003
11004 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
11005 if (!nl_rules)
11006 return -ENOBUFS;
11007
11008 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11009 nl_rule = nla_nest_start(msg, i + 1);
11010 if (!nl_rule)
11011 return -ENOBUFS;
11012
11013 rule = &rdev->coalesce->rules[i];
11014 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11015 rule->delay))
11016 return -ENOBUFS;
11017
11018 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11019 rule->condition))
11020 return -ENOBUFS;
11021
11022 nl_pats = nla_nest_start(msg,
11023 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11024 if (!nl_pats)
11025 return -ENOBUFS;
11026
11027 for (j = 0; j < rule->n_patterns; j++) {
11028 nl_pat = nla_nest_start(msg, j + 1);
11029 if (!nl_pat)
11030 return -ENOBUFS;
11031 pat_len = rule->patterns[j].pattern_len;
11032 if (nla_put(msg, NL80211_PKTPAT_MASK,
11033 DIV_ROUND_UP(pat_len, 8),
11034 rule->patterns[j].mask) ||
11035 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11036 rule->patterns[j].pattern) ||
11037 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11038 rule->patterns[j].pkt_offset))
11039 return -ENOBUFS;
11040 nla_nest_end(msg, nl_pat);
11041 }
11042 nla_nest_end(msg, nl_pats);
11043 nla_nest_end(msg, nl_rule);
11044 }
11045 nla_nest_end(msg, nl_rules);
11046
11047 return 0;
11048}
11049
11050static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11051{
11052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11053 struct sk_buff *msg;
11054 void *hdr;
11055
11056 if (!rdev->wiphy.coalesce)
11057 return -EOPNOTSUPP;
11058
11059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11060 if (!msg)
11061 return -ENOMEM;
11062
11063 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11064 NL80211_CMD_GET_COALESCE);
11065 if (!hdr)
11066 goto nla_put_failure;
11067
11068 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11069 goto nla_put_failure;
11070
11071 genlmsg_end(msg, hdr);
11072 return genlmsg_reply(msg, info);
11073
11074nla_put_failure:
11075 nlmsg_free(msg);
11076 return -ENOBUFS;
11077}
11078
11079void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11080{
11081 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11082 int i, j;
11083 struct cfg80211_coalesce_rules *rule;
11084
11085 if (!coalesce)
11086 return;
11087
11088 for (i = 0; i < coalesce->n_rules; i++) {
11089 rule = &coalesce->rules[i];
11090 for (j = 0; j < rule->n_patterns; j++)
11091 kfree(rule->patterns[j].mask);
11092 kfree(rule->patterns);
11093 }
11094 kfree(coalesce->rules);
11095 kfree(coalesce);
11096 rdev->coalesce = NULL;
11097}
11098
11099static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11100 struct nlattr *rule,
11101 struct cfg80211_coalesce_rules *new_rule)
11102{
11103 int err, i;
11104 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11105 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11106 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11107 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11108
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011109 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020011110 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011111 if (err)
11112 return err;
11113
11114 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11115 new_rule->delay =
11116 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11117 if (new_rule->delay > coalesce->max_delay)
11118 return -EINVAL;
11119
11120 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11121 new_rule->condition =
11122 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
11123 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
11124 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
11125 return -EINVAL;
11126
11127 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11128 return -EINVAL;
11129
11130 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11131 rem)
11132 n_patterns++;
11133 if (n_patterns > coalesce->n_patterns)
11134 return -EINVAL;
11135
11136 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11137 GFP_KERNEL);
11138 if (!new_rule->patterns)
11139 return -ENOMEM;
11140
11141 new_rule->n_patterns = n_patterns;
11142 i = 0;
11143
11144 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11145 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011146 u8 *mask_pat;
11147
Peng Xuad670232017-10-03 23:21:51 +030011148 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
11149 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011150 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11151 !pat_tb[NL80211_PKTPAT_PATTERN])
11152 return -EINVAL;
11153 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11154 mask_len = DIV_ROUND_UP(pat_len, 8);
11155 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11156 return -EINVAL;
11157 if (pat_len > coalesce->pattern_max_len ||
11158 pat_len < coalesce->pattern_min_len)
11159 return -EINVAL;
11160
11161 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11162 pkt_offset = 0;
11163 else
11164 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11165 if (pkt_offset > coalesce->max_pkt_offset)
11166 return -EINVAL;
11167 new_rule->patterns[i].pkt_offset = pkt_offset;
11168
Johannes Berg922bd802014-05-19 17:59:50 +020011169 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11170 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011171 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020011172
11173 new_rule->patterns[i].mask = mask_pat;
11174 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11175 mask_len);
11176
11177 mask_pat += mask_len;
11178 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011179 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011180 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11181 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011182 i++;
11183 }
11184
11185 return 0;
11186}
11187
11188static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11189{
11190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11191 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11192 struct cfg80211_coalesce new_coalesce = {};
11193 struct cfg80211_coalesce *n_coalesce;
11194 int err, rem_rule, n_rules = 0, i, j;
11195 struct nlattr *rule;
11196 struct cfg80211_coalesce_rules *tmp_rule;
11197
11198 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11199 return -EOPNOTSUPP;
11200
11201 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11202 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030011203 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011204 return 0;
11205 }
11206
11207 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11208 rem_rule)
11209 n_rules++;
11210 if (n_rules > coalesce->n_rules)
11211 return -EINVAL;
11212
11213 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11214 GFP_KERNEL);
11215 if (!new_coalesce.rules)
11216 return -ENOMEM;
11217
11218 new_coalesce.n_rules = n_rules;
11219 i = 0;
11220
11221 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11222 rem_rule) {
11223 err = nl80211_parse_coalesce_rule(rdev, rule,
11224 &new_coalesce.rules[i]);
11225 if (err)
11226 goto error;
11227
11228 i++;
11229 }
11230
Ilan Peera1056b12015-10-22 22:27:46 +030011231 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011232 if (err)
11233 goto error;
11234
11235 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11236 if (!n_coalesce) {
11237 err = -ENOMEM;
11238 goto error;
11239 }
11240 cfg80211_rdev_free_coalesce(rdev);
11241 rdev->coalesce = n_coalesce;
11242
11243 return 0;
11244error:
11245 for (i = 0; i < new_coalesce.n_rules; i++) {
11246 tmp_rule = &new_coalesce.rules[i];
11247 for (j = 0; j < tmp_rule->n_patterns; j++)
11248 kfree(tmp_rule->patterns[j].mask);
11249 kfree(tmp_rule->patterns);
11250 }
11251 kfree(new_coalesce.rules);
11252
11253 return err;
11254}
11255
Johannes Berge5497d72011-07-05 16:35:40 +020011256static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11257{
11258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11259 struct net_device *dev = info->user_ptr[1];
11260 struct wireless_dev *wdev = dev->ieee80211_ptr;
11261 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11262 struct cfg80211_gtk_rekey_data rekey_data;
11263 int err;
11264
11265 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11266 return -EINVAL;
11267
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011268 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
11269 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020011270 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011271 if (err)
11272 return err;
11273
Vladis Dronove785fa02017-09-13 00:21:21 +020011274 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11275 !tb[NL80211_REKEY_DATA_KCK])
11276 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011277 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11278 return -ERANGE;
11279 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11280 return -ERANGE;
11281 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11282 return -ERANGE;
11283
Johannes Berg78f686c2014-09-10 22:28:06 +030011284 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11285 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11286 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011287
11288 wdev_lock(wdev);
11289 if (!wdev->current_bss) {
11290 err = -ENOTCONN;
11291 goto out;
11292 }
11293
11294 if (!rdev->ops->set_rekey_data) {
11295 err = -EOPNOTSUPP;
11296 goto out;
11297 }
11298
Hila Gonene35e4d22012-06-27 17:19:42 +030011299 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011300 out:
11301 wdev_unlock(wdev);
11302 return err;
11303}
11304
Johannes Berg28946da2011-11-04 11:18:12 +010011305static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11306 struct genl_info *info)
11307{
11308 struct net_device *dev = info->user_ptr[1];
11309 struct wireless_dev *wdev = dev->ieee80211_ptr;
11310
11311 if (wdev->iftype != NL80211_IFTYPE_AP &&
11312 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11313 return -EINVAL;
11314
Eric W. Biederman15e47302012-09-07 20:12:54 +000011315 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011316 return -EBUSY;
11317
Eric W. Biederman15e47302012-09-07 20:12:54 +000011318 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011319 return 0;
11320}
11321
Johannes Berg7f6cf312011-11-04 11:18:15 +010011322static int nl80211_probe_client(struct sk_buff *skb,
11323 struct genl_info *info)
11324{
11325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11326 struct net_device *dev = info->user_ptr[1];
11327 struct wireless_dev *wdev = dev->ieee80211_ptr;
11328 struct sk_buff *msg;
11329 void *hdr;
11330 const u8 *addr;
11331 u64 cookie;
11332 int err;
11333
11334 if (wdev->iftype != NL80211_IFTYPE_AP &&
11335 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11336 return -EOPNOTSUPP;
11337
11338 if (!info->attrs[NL80211_ATTR_MAC])
11339 return -EINVAL;
11340
11341 if (!rdev->ops->probe_client)
11342 return -EOPNOTSUPP;
11343
11344 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11345 if (!msg)
11346 return -ENOMEM;
11347
Eric W. Biederman15e47302012-09-07 20:12:54 +000011348 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011349 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011350 if (!hdr) {
11351 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011352 goto free_msg;
11353 }
11354
11355 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11356
Hila Gonene35e4d22012-06-27 17:19:42 +030011357 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011358 if (err)
11359 goto free_msg;
11360
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011361 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11362 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011363 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011364
11365 genlmsg_end(msg, hdr);
11366
11367 return genlmsg_reply(msg, info);
11368
11369 nla_put_failure:
11370 err = -ENOBUFS;
11371 free_msg:
11372 nlmsg_free(msg);
11373 return err;
11374}
11375
Johannes Berg5e760232011-11-04 11:18:17 +010011376static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11377{
11378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011379 struct cfg80211_beacon_registration *reg, *nreg;
11380 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011381
11382 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11383 return -EOPNOTSUPP;
11384
Ben Greear37c73b52012-10-26 14:49:25 -070011385 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11386 if (!nreg)
11387 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011388
Ben Greear37c73b52012-10-26 14:49:25 -070011389 /* First, check if already registered. */
11390 spin_lock_bh(&rdev->beacon_registrations_lock);
11391 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11392 if (reg->nlportid == info->snd_portid) {
11393 rv = -EALREADY;
11394 goto out_err;
11395 }
11396 }
11397 /* Add it to the list */
11398 nreg->nlportid = info->snd_portid;
11399 list_add(&nreg->list, &rdev->beacon_registrations);
11400
11401 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011402
11403 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011404out_err:
11405 spin_unlock_bh(&rdev->beacon_registrations_lock);
11406 kfree(nreg);
11407 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011408}
11409
Johannes Berg98104fde2012-06-16 00:19:54 +020011410static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11411{
11412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11413 struct wireless_dev *wdev = info->user_ptr[1];
11414 int err;
11415
11416 if (!rdev->ops->start_p2p_device)
11417 return -EOPNOTSUPP;
11418
11419 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11420 return -EOPNOTSUPP;
11421
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011422 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011423 return 0;
11424
Luciano Coelhob6a55012014-02-27 11:07:21 +020011425 if (rfkill_blocked(rdev->rfkill))
11426 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011427
Johannes Bergeeb126e2012-10-23 15:16:50 +020011428 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011429 if (err)
11430 return err;
11431
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011432 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011433 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011434
11435 return 0;
11436}
11437
11438static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11439{
11440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11441 struct wireless_dev *wdev = info->user_ptr[1];
11442
11443 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11444 return -EOPNOTSUPP;
11445
11446 if (!rdev->ops->stop_p2p_device)
11447 return -EOPNOTSUPP;
11448
Johannes Bergf9f47522013-03-19 15:04:07 +010011449 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011450
11451 return 0;
11452}
11453
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011454static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11455{
11456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11457 struct wireless_dev *wdev = info->user_ptr[1];
11458 struct cfg80211_nan_conf conf = {};
11459 int err;
11460
11461 if (wdev->iftype != NL80211_IFTYPE_NAN)
11462 return -EOPNOTSUPP;
11463
Johannes Bergeeb04a92016-11-21 13:55:48 +010011464 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011465 return -EEXIST;
11466
11467 if (rfkill_blocked(rdev->rfkill))
11468 return -ERFKILL;
11469
11470 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11471 return -EINVAL;
11472
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011473 conf.master_pref =
11474 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11475 if (!conf.master_pref)
11476 return -EINVAL;
11477
Luca Coelho85859892017-02-08 15:00:34 +020011478 if (info->attrs[NL80211_ATTR_BANDS]) {
11479 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11480
11481 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11482 return -EOPNOTSUPP;
11483
11484 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11485 return -EINVAL;
11486
11487 conf.bands = bands;
11488 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011489
11490 err = rdev_start_nan(rdev, wdev, &conf);
11491 if (err)
11492 return err;
11493
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011494 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011495 rdev->opencount++;
11496
11497 return 0;
11498}
11499
11500static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11501{
11502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11503 struct wireless_dev *wdev = info->user_ptr[1];
11504
11505 if (wdev->iftype != NL80211_IFTYPE_NAN)
11506 return -EOPNOTSUPP;
11507
11508 cfg80211_stop_nan(rdev, wdev);
11509
11510 return 0;
11511}
11512
Ayala Bekera442b762016-09-20 17:31:15 +030011513static int validate_nan_filter(struct nlattr *filter_attr)
11514{
11515 struct nlattr *attr;
11516 int len = 0, n_entries = 0, rem;
11517
11518 nla_for_each_nested(attr, filter_attr, rem) {
11519 len += nla_len(attr);
11520 n_entries++;
11521 }
11522
11523 if (len >= U8_MAX)
11524 return -EINVAL;
11525
11526 return n_entries;
11527}
11528
11529static int handle_nan_filter(struct nlattr *attr_filter,
11530 struct cfg80211_nan_func *func,
11531 bool tx)
11532{
11533 struct nlattr *attr;
11534 int n_entries, rem, i;
11535 struct cfg80211_nan_func_filter *filter;
11536
11537 n_entries = validate_nan_filter(attr_filter);
11538 if (n_entries < 0)
11539 return n_entries;
11540
11541 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11542
11543 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11544 if (!filter)
11545 return -ENOMEM;
11546
11547 i = 0;
11548 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011549 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011550 filter[i].len = nla_len(attr);
11551 i++;
11552 }
11553 if (tx) {
11554 func->num_tx_filters = n_entries;
11555 func->tx_filters = filter;
11556 } else {
11557 func->num_rx_filters = n_entries;
11558 func->rx_filters = filter;
11559 }
11560
11561 return 0;
11562}
11563
11564static int nl80211_nan_add_func(struct sk_buff *skb,
11565 struct genl_info *info)
11566{
11567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11568 struct wireless_dev *wdev = info->user_ptr[1];
11569 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11570 struct cfg80211_nan_func *func;
11571 struct sk_buff *msg = NULL;
11572 void *hdr = NULL;
11573 int err = 0;
11574
11575 if (wdev->iftype != NL80211_IFTYPE_NAN)
11576 return -EOPNOTSUPP;
11577
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011578 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011579 return -ENOTCONN;
11580
11581 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11582 return -EINVAL;
11583
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011584 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11585 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011586 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011587 if (err)
11588 return err;
11589
11590 func = kzalloc(sizeof(*func), GFP_KERNEL);
11591 if (!func)
11592 return -ENOMEM;
11593
11594 func->cookie = wdev->wiphy->cookie_counter++;
11595
11596 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11597 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11598 err = -EINVAL;
11599 goto out;
11600 }
11601
11602
11603 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11604
11605 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11606 err = -EINVAL;
11607 goto out;
11608 }
11609
11610 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11611 sizeof(func->service_id));
11612
11613 func->close_range =
11614 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11615
11616 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11617 func->serv_spec_info_len =
11618 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11619 func->serv_spec_info =
11620 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11621 func->serv_spec_info_len,
11622 GFP_KERNEL);
11623 if (!func->serv_spec_info) {
11624 err = -ENOMEM;
11625 goto out;
11626 }
11627 }
11628
11629 if (tb[NL80211_NAN_FUNC_TTL])
11630 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11631
11632 switch (func->type) {
11633 case NL80211_NAN_FUNC_PUBLISH:
11634 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11635 err = -EINVAL;
11636 goto out;
11637 }
11638
11639 func->publish_type =
11640 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11641 func->publish_bcast =
11642 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11643
11644 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11645 func->publish_bcast) {
11646 err = -EINVAL;
11647 goto out;
11648 }
11649 break;
11650 case NL80211_NAN_FUNC_SUBSCRIBE:
11651 func->subscribe_active =
11652 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11653 break;
11654 case NL80211_NAN_FUNC_FOLLOW_UP:
11655 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080011656 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11657 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030011658 err = -EINVAL;
11659 goto out;
11660 }
11661
11662 func->followup_id =
11663 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11664 func->followup_reqid =
11665 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11666 memcpy(func->followup_dest.addr,
11667 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11668 sizeof(func->followup_dest.addr));
11669 if (func->ttl) {
11670 err = -EINVAL;
11671 goto out;
11672 }
11673 break;
11674 default:
11675 err = -EINVAL;
11676 goto out;
11677 }
11678
11679 if (tb[NL80211_NAN_FUNC_SRF]) {
11680 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11681
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011682 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11683 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011684 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011685 if (err)
11686 goto out;
11687
11688 func->srf_include =
11689 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11690
11691 if (srf_tb[NL80211_NAN_SRF_BF]) {
11692 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11693 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11694 err = -EINVAL;
11695 goto out;
11696 }
11697
11698 func->srf_bf_len =
11699 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11700 func->srf_bf =
11701 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11702 func->srf_bf_len, GFP_KERNEL);
11703 if (!func->srf_bf) {
11704 err = -ENOMEM;
11705 goto out;
11706 }
11707
11708 func->srf_bf_idx =
11709 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11710 } else {
11711 struct nlattr *attr, *mac_attr =
11712 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11713 int n_entries, rem, i = 0;
11714
11715 if (!mac_attr) {
11716 err = -EINVAL;
11717 goto out;
11718 }
11719
11720 n_entries = validate_acl_mac_addrs(mac_attr);
11721 if (n_entries <= 0) {
11722 err = -EINVAL;
11723 goto out;
11724 }
11725
11726 func->srf_num_macs = n_entries;
11727 func->srf_macs =
11728 kzalloc(sizeof(*func->srf_macs) * n_entries,
11729 GFP_KERNEL);
11730 if (!func->srf_macs) {
11731 err = -ENOMEM;
11732 goto out;
11733 }
11734
11735 nla_for_each_nested(attr, mac_attr, rem)
11736 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11737 sizeof(*func->srf_macs));
11738 }
11739 }
11740
11741 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11742 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11743 func, true);
11744 if (err)
11745 goto out;
11746 }
11747
11748 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11749 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11750 func, false);
11751 if (err)
11752 goto out;
11753 }
11754
11755 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11756 if (!msg) {
11757 err = -ENOMEM;
11758 goto out;
11759 }
11760
11761 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11762 NL80211_CMD_ADD_NAN_FUNCTION);
11763 /* This can't really happen - we just allocated 4KB */
11764 if (WARN_ON(!hdr)) {
11765 err = -ENOMEM;
11766 goto out;
11767 }
11768
11769 err = rdev_add_nan_func(rdev, wdev, func);
11770out:
11771 if (err < 0) {
11772 cfg80211_free_nan_func(func);
11773 nlmsg_free(msg);
11774 return err;
11775 }
11776
11777 /* propagate the instance id and cookie to userspace */
11778 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11779 NL80211_ATTR_PAD))
11780 goto nla_put_failure;
11781
11782 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11783 if (!func_attr)
11784 goto nla_put_failure;
11785
11786 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11787 func->instance_id))
11788 goto nla_put_failure;
11789
11790 nla_nest_end(msg, func_attr);
11791
11792 genlmsg_end(msg, hdr);
11793 return genlmsg_reply(msg, info);
11794
11795nla_put_failure:
11796 nlmsg_free(msg);
11797 return -ENOBUFS;
11798}
11799
11800static int nl80211_nan_del_func(struct sk_buff *skb,
11801 struct genl_info *info)
11802{
11803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11804 struct wireless_dev *wdev = info->user_ptr[1];
11805 u64 cookie;
11806
11807 if (wdev->iftype != NL80211_IFTYPE_NAN)
11808 return -EOPNOTSUPP;
11809
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011810 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011811 return -ENOTCONN;
11812
11813 if (!info->attrs[NL80211_ATTR_COOKIE])
11814 return -EINVAL;
11815
Ayala Bekera442b762016-09-20 17:31:15 +030011816 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11817
11818 rdev_del_nan_func(rdev, wdev, cookie);
11819
11820 return 0;
11821}
11822
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011823static int nl80211_nan_change_config(struct sk_buff *skb,
11824 struct genl_info *info)
11825{
11826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11827 struct wireless_dev *wdev = info->user_ptr[1];
11828 struct cfg80211_nan_conf conf = {};
11829 u32 changed = 0;
11830
11831 if (wdev->iftype != NL80211_IFTYPE_NAN)
11832 return -EOPNOTSUPP;
11833
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011834 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011835 return -ENOTCONN;
11836
11837 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11838 conf.master_pref =
11839 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11840 if (conf.master_pref <= 1 || conf.master_pref == 255)
11841 return -EINVAL;
11842
11843 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11844 }
11845
Luca Coelho85859892017-02-08 15:00:34 +020011846 if (info->attrs[NL80211_ATTR_BANDS]) {
11847 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11848
11849 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11850 return -EOPNOTSUPP;
11851
11852 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11853 return -EINVAL;
11854
11855 conf.bands = bands;
11856 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011857 }
11858
11859 if (!changed)
11860 return -EINVAL;
11861
11862 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11863}
11864
Ayala Beker50bcd312016-09-20 17:31:17 +030011865void cfg80211_nan_match(struct wireless_dev *wdev,
11866 struct cfg80211_nan_match_params *match, gfp_t gfp)
11867{
11868 struct wiphy *wiphy = wdev->wiphy;
11869 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11870 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11871 struct sk_buff *msg;
11872 void *hdr;
11873
11874 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11875 return;
11876
11877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11878 if (!msg)
11879 return;
11880
11881 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11882 if (!hdr) {
11883 nlmsg_free(msg);
11884 return;
11885 }
11886
11887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11888 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11889 wdev->netdev->ifindex)) ||
11890 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11891 NL80211_ATTR_PAD))
11892 goto nla_put_failure;
11893
11894 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11895 NL80211_ATTR_PAD) ||
11896 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11897 goto nla_put_failure;
11898
11899 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11900 if (!match_attr)
11901 goto nla_put_failure;
11902
11903 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11904 if (!local_func_attr)
11905 goto nla_put_failure;
11906
11907 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11908 goto nla_put_failure;
11909
11910 nla_nest_end(msg, local_func_attr);
11911
11912 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11913 if (!peer_func_attr)
11914 goto nla_put_failure;
11915
11916 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11917 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11918 goto nla_put_failure;
11919
11920 if (match->info && match->info_len &&
11921 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11922 match->info))
11923 goto nla_put_failure;
11924
11925 nla_nest_end(msg, peer_func_attr);
11926 nla_nest_end(msg, match_attr);
11927 genlmsg_end(msg, hdr);
11928
11929 if (!wdev->owner_nlportid)
11930 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11931 msg, 0, NL80211_MCGRP_NAN, gfp);
11932 else
11933 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11934 wdev->owner_nlportid);
11935
11936 return;
11937
11938nla_put_failure:
11939 nlmsg_free(msg);
11940}
11941EXPORT_SYMBOL(cfg80211_nan_match);
11942
Ayala Beker368e5a72016-09-20 17:31:18 +030011943void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11944 u8 inst_id,
11945 enum nl80211_nan_func_term_reason reason,
11946 u64 cookie, gfp_t gfp)
11947{
11948 struct wiphy *wiphy = wdev->wiphy;
11949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11950 struct sk_buff *msg;
11951 struct nlattr *func_attr;
11952 void *hdr;
11953
11954 if (WARN_ON(!inst_id))
11955 return;
11956
11957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11958 if (!msg)
11959 return;
11960
11961 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11962 if (!hdr) {
11963 nlmsg_free(msg);
11964 return;
11965 }
11966
11967 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11968 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11969 wdev->netdev->ifindex)) ||
11970 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11971 NL80211_ATTR_PAD))
11972 goto nla_put_failure;
11973
11974 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11975 NL80211_ATTR_PAD))
11976 goto nla_put_failure;
11977
11978 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11979 if (!func_attr)
11980 goto nla_put_failure;
11981
11982 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11983 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11984 goto nla_put_failure;
11985
11986 nla_nest_end(msg, func_attr);
11987 genlmsg_end(msg, hdr);
11988
11989 if (!wdev->owner_nlportid)
11990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11991 msg, 0, NL80211_MCGRP_NAN, gfp);
11992 else
11993 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11994 wdev->owner_nlportid);
11995
11996 return;
11997
11998nla_put_failure:
11999 nlmsg_free(msg);
12000}
12001EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12002
Johannes Berg3713b4e2013-02-14 16:19:38 +010012003static int nl80211_get_protocol_features(struct sk_buff *skb,
12004 struct genl_info *info)
12005{
12006 void *hdr;
12007 struct sk_buff *msg;
12008
12009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12010 if (!msg)
12011 return -ENOMEM;
12012
12013 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12014 NL80211_CMD_GET_PROTOCOL_FEATURES);
12015 if (!hdr)
12016 goto nla_put_failure;
12017
12018 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12019 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12020 goto nla_put_failure;
12021
12022 genlmsg_end(msg, hdr);
12023 return genlmsg_reply(msg, info);
12024
12025 nla_put_failure:
12026 kfree_skb(msg);
12027 return -ENOBUFS;
12028}
12029
Jouni Malinen355199e2013-02-27 17:14:27 +020012030static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12031{
12032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12033 struct cfg80211_update_ft_ies_params ft_params;
12034 struct net_device *dev = info->user_ptr[1];
12035
12036 if (!rdev->ops->update_ft_ies)
12037 return -EOPNOTSUPP;
12038
12039 if (!info->attrs[NL80211_ATTR_MDID] ||
12040 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
12041 return -EINVAL;
12042
12043 memset(&ft_params, 0, sizeof(ft_params));
12044 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12045 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12046 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12047
12048 return rdev_update_ft_ies(rdev, dev, &ft_params);
12049}
12050
Arend van Spriel5de17982013-04-18 15:49:00 +020012051static int nl80211_crit_protocol_start(struct sk_buff *skb,
12052 struct genl_info *info)
12053{
12054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12055 struct wireless_dev *wdev = info->user_ptr[1];
12056 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12057 u16 duration;
12058 int ret;
12059
12060 if (!rdev->ops->crit_proto_start)
12061 return -EOPNOTSUPP;
12062
12063 if (WARN_ON(!rdev->ops->crit_proto_stop))
12064 return -EINVAL;
12065
12066 if (rdev->crit_proto_nlportid)
12067 return -EBUSY;
12068
12069 /* determine protocol if provided */
12070 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12071 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12072
12073 if (proto >= NUM_NL80211_CRIT_PROTO)
12074 return -EINVAL;
12075
12076 /* timeout must be provided */
12077 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12078 return -EINVAL;
12079
12080 duration =
12081 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12082
12083 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12084 return -ERANGE;
12085
12086 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12087 if (!ret)
12088 rdev->crit_proto_nlportid = info->snd_portid;
12089
12090 return ret;
12091}
12092
12093static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12094 struct genl_info *info)
12095{
12096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12097 struct wireless_dev *wdev = info->user_ptr[1];
12098
12099 if (!rdev->ops->crit_proto_stop)
12100 return -EOPNOTSUPP;
12101
12102 if (rdev->crit_proto_nlportid) {
12103 rdev->crit_proto_nlportid = 0;
12104 rdev_crit_proto_stop(rdev, wdev);
12105 }
12106 return 0;
12107}
12108
Johannes Bergad7e7182013-11-13 13:37:47 +010012109static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12110{
12111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12112 struct wireless_dev *wdev =
12113 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12114 int i, err;
12115 u32 vid, subcmd;
12116
12117 if (!rdev->wiphy.vendor_commands)
12118 return -EOPNOTSUPP;
12119
12120 if (IS_ERR(wdev)) {
12121 err = PTR_ERR(wdev);
12122 if (err != -EINVAL)
12123 return err;
12124 wdev = NULL;
12125 } else if (wdev->wiphy != &rdev->wiphy) {
12126 return -EINVAL;
12127 }
12128
12129 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12130 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12131 return -EINVAL;
12132
12133 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12134 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12135 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12136 const struct wiphy_vendor_command *vcmd;
12137 void *data = NULL;
12138 int len = 0;
12139
12140 vcmd = &rdev->wiphy.vendor_commands[i];
12141
12142 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12143 continue;
12144
12145 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12146 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12147 if (!wdev)
12148 return -EINVAL;
12149 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12150 !wdev->netdev)
12151 return -EINVAL;
12152
12153 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012154 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010012155 return -ENETDOWN;
12156 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012157
12158 if (!vcmd->doit)
12159 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010012160 } else {
12161 wdev = NULL;
12162 }
12163
12164 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12165 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12166 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12167 }
12168
12169 rdev->cur_cmd_info = info;
12170 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
12171 data, len);
12172 rdev->cur_cmd_info = NULL;
12173 return err;
12174 }
12175
12176 return -EOPNOTSUPP;
12177}
12178
Johannes Berg7bdbe402015-08-15 22:39:49 +030012179static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12180 struct netlink_callback *cb,
12181 struct cfg80211_registered_device **rdev,
12182 struct wireless_dev **wdev)
12183{
Johannes Bergc90c39d2016-10-24 14:40:01 +020012184 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012185 u32 vid, subcmd;
12186 unsigned int i;
12187 int vcmd_idx = -1;
12188 int err;
12189 void *data = NULL;
12190 unsigned int data_len = 0;
12191
Johannes Berg7bdbe402015-08-15 22:39:49 +030012192 if (cb->args[0]) {
12193 /* subtract the 1 again here */
12194 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12195 struct wireless_dev *tmp;
12196
Johannes Bergea90e0d2017-03-15 14:26:04 +010012197 if (!wiphy)
12198 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012199 *rdev = wiphy_to_rdev(wiphy);
12200 *wdev = NULL;
12201
12202 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030012203 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012204 if (tmp->identifier == cb->args[1] - 1) {
12205 *wdev = tmp;
12206 break;
12207 }
12208 }
12209 }
12210
12211 /* keep rtnl locked in successful case */
12212 return 0;
12213 }
12214
Johannes Bergfceb6432017-04-12 14:34:07 +020012215 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
12216 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012217 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012218 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012219
Johannes Bergc90c39d2016-10-24 14:40:01 +020012220 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010012221 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
12222 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012223
Johannes Bergc90c39d2016-10-24 14:40:01 +020012224 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012225 if (IS_ERR(*wdev))
12226 *wdev = NULL;
12227
Johannes Bergc90c39d2016-10-24 14:40:01 +020012228 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012229 if (IS_ERR(*rdev))
12230 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012231
Johannes Bergc90c39d2016-10-24 14:40:01 +020012232 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12233 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012234
12235 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12236 const struct wiphy_vendor_command *vcmd;
12237
12238 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12239
12240 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12241 continue;
12242
Johannes Bergea90e0d2017-03-15 14:26:04 +010012243 if (!vcmd->dumpit)
12244 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012245
12246 vcmd_idx = i;
12247 break;
12248 }
12249
Johannes Bergea90e0d2017-03-15 14:26:04 +010012250 if (vcmd_idx < 0)
12251 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012252
Johannes Bergc90c39d2016-10-24 14:40:01 +020012253 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12254 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12255 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012256 }
12257
12258 /* 0 is the first index - add 1 to parse only once */
12259 cb->args[0] = (*rdev)->wiphy_idx + 1;
12260 /* add 1 to know if it was NULL */
12261 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12262 cb->args[2] = vcmd_idx;
12263 cb->args[3] = (unsigned long)data;
12264 cb->args[4] = data_len;
12265
12266 /* keep rtnl locked in successful case */
12267 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012268}
12269
12270static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12271 struct netlink_callback *cb)
12272{
12273 struct cfg80211_registered_device *rdev;
12274 struct wireless_dev *wdev;
12275 unsigned int vcmd_idx;
12276 const struct wiphy_vendor_command *vcmd;
12277 void *data;
12278 int data_len;
12279 int err;
12280 struct nlattr *vendor_data;
12281
Johannes Bergea90e0d2017-03-15 14:26:04 +010012282 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012283 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12284 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012285 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012286
12287 vcmd_idx = cb->args[2];
12288 data = (void *)cb->args[3];
12289 data_len = cb->args[4];
12290 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12291
12292 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12293 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012294 if (!wdev) {
12295 err = -EINVAL;
12296 goto out;
12297 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012298 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012299 !wdev->netdev) {
12300 err = -EINVAL;
12301 goto out;
12302 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012303
12304 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012305 if (!wdev_running(wdev)) {
12306 err = -ENETDOWN;
12307 goto out;
12308 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012309 }
12310 }
12311
12312 while (1) {
12313 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12314 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12315 NL80211_CMD_VENDOR);
12316 if (!hdr)
12317 break;
12318
12319 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012320 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12321 wdev_id(wdev),
12322 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012323 genlmsg_cancel(skb, hdr);
12324 break;
12325 }
12326
12327 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12328 if (!vendor_data) {
12329 genlmsg_cancel(skb, hdr);
12330 break;
12331 }
12332
12333 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12334 (unsigned long *)&cb->args[5]);
12335 nla_nest_end(skb, vendor_data);
12336
12337 if (err == -ENOBUFS || err == -ENOENT) {
12338 genlmsg_cancel(skb, hdr);
12339 break;
12340 } else if (err) {
12341 genlmsg_cancel(skb, hdr);
12342 goto out;
12343 }
12344
12345 genlmsg_end(skb, hdr);
12346 }
12347
12348 err = skb->len;
12349 out:
12350 rtnl_unlock();
12351 return err;
12352}
12353
Johannes Bergad7e7182013-11-13 13:37:47 +010012354struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12355 enum nl80211_commands cmd,
12356 enum nl80211_attrs attr,
12357 int approxlen)
12358{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012359 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012360
12361 if (WARN_ON(!rdev->cur_cmd_info))
12362 return NULL;
12363
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012364 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012365 rdev->cur_cmd_info->snd_portid,
12366 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012367 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012368}
12369EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12370
12371int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12372{
12373 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12374 void *hdr = ((void **)skb->cb)[1];
12375 struct nlattr *data = ((void **)skb->cb)[2];
12376
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012377 /* clear CB data for netlink core to own from now on */
12378 memset(skb->cb, 0, sizeof(skb->cb));
12379
Johannes Bergad7e7182013-11-13 13:37:47 +010012380 if (WARN_ON(!rdev->cur_cmd_info)) {
12381 kfree_skb(skb);
12382 return -EINVAL;
12383 }
12384
12385 nla_nest_end(skb, data);
12386 genlmsg_end(skb, hdr);
12387 return genlmsg_reply(skb, rdev->cur_cmd_info);
12388}
12389EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12390
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012391static int nl80211_set_qos_map(struct sk_buff *skb,
12392 struct genl_info *info)
12393{
12394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12395 struct cfg80211_qos_map *qos_map = NULL;
12396 struct net_device *dev = info->user_ptr[1];
12397 u8 *pos, len, num_des, des_len, des;
12398 int ret;
12399
12400 if (!rdev->ops->set_qos_map)
12401 return -EOPNOTSUPP;
12402
12403 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12404 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12405 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12406
12407 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12408 len > IEEE80211_QOS_MAP_LEN_MAX)
12409 return -EINVAL;
12410
12411 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12412 if (!qos_map)
12413 return -ENOMEM;
12414
12415 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12416 if (num_des) {
12417 des_len = num_des *
12418 sizeof(struct cfg80211_dscp_exception);
12419 memcpy(qos_map->dscp_exception, pos, des_len);
12420 qos_map->num_des = num_des;
12421 for (des = 0; des < num_des; des++) {
12422 if (qos_map->dscp_exception[des].up > 7) {
12423 kfree(qos_map);
12424 return -EINVAL;
12425 }
12426 }
12427 pos += des_len;
12428 }
12429 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12430 }
12431
12432 wdev_lock(dev->ieee80211_ptr);
12433 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12434 if (!ret)
12435 ret = rdev_set_qos_map(rdev, dev, qos_map);
12436 wdev_unlock(dev->ieee80211_ptr);
12437
12438 kfree(qos_map);
12439 return ret;
12440}
12441
Johannes Berg960d01a2014-09-09 22:55:35 +030012442static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12443{
12444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12445 struct net_device *dev = info->user_ptr[1];
12446 struct wireless_dev *wdev = dev->ieee80211_ptr;
12447 const u8 *peer;
12448 u8 tsid, up;
12449 u16 admitted_time = 0;
12450 int err;
12451
Johannes Berg723e73a2014-10-22 09:25:06 +020012452 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012453 return -EOPNOTSUPP;
12454
12455 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12456 !info->attrs[NL80211_ATTR_USER_PRIO])
12457 return -EINVAL;
12458
12459 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12460 if (tsid >= IEEE80211_NUM_TIDS)
12461 return -EINVAL;
12462
12463 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12464 if (up >= IEEE80211_NUM_UPS)
12465 return -EINVAL;
12466
12467 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012468 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012469 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012470 * need more attributes for that (e.g. BA session requirement);
12471 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012472 */
12473 return -EINVAL;
12474 }
12475
12476 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12477
12478 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12479 admitted_time =
12480 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12481 if (!admitted_time)
12482 return -EINVAL;
12483 }
12484
12485 wdev_lock(wdev);
12486 switch (wdev->iftype) {
12487 case NL80211_IFTYPE_STATION:
12488 case NL80211_IFTYPE_P2P_CLIENT:
12489 if (wdev->current_bss)
12490 break;
12491 err = -ENOTCONN;
12492 goto out;
12493 default:
12494 err = -EOPNOTSUPP;
12495 goto out;
12496 }
12497
12498 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12499
12500 out:
12501 wdev_unlock(wdev);
12502 return err;
12503}
12504
12505static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12506{
12507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12508 struct net_device *dev = info->user_ptr[1];
12509 struct wireless_dev *wdev = dev->ieee80211_ptr;
12510 const u8 *peer;
12511 u8 tsid;
12512 int err;
12513
12514 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12515 return -EINVAL;
12516
12517 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12518 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12519
12520 wdev_lock(wdev);
12521 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12522 wdev_unlock(wdev);
12523
12524 return err;
12525}
12526
Arik Nemtsov1057d352014-11-19 12:54:26 +020012527static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12528 struct genl_info *info)
12529{
12530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12531 struct net_device *dev = info->user_ptr[1];
12532 struct wireless_dev *wdev = dev->ieee80211_ptr;
12533 struct cfg80211_chan_def chandef = {};
12534 const u8 *addr;
12535 u8 oper_class;
12536 int err;
12537
12538 if (!rdev->ops->tdls_channel_switch ||
12539 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12540 return -EOPNOTSUPP;
12541
12542 switch (dev->ieee80211_ptr->iftype) {
12543 case NL80211_IFTYPE_STATION:
12544 case NL80211_IFTYPE_P2P_CLIENT:
12545 break;
12546 default:
12547 return -EOPNOTSUPP;
12548 }
12549
12550 if (!info->attrs[NL80211_ATTR_MAC] ||
12551 !info->attrs[NL80211_ATTR_OPER_CLASS])
12552 return -EINVAL;
12553
12554 err = nl80211_parse_chandef(rdev, info, &chandef);
12555 if (err)
12556 return err;
12557
12558 /*
12559 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12560 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12561 * specification is not defined for them.
12562 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012563 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012564 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12565 chandef.width != NL80211_CHAN_WIDTH_20)
12566 return -EINVAL;
12567
12568 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012569 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12570 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012571 return -EINVAL;
12572
12573 /* don't allow switching to DFS channels */
12574 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12575 return -EINVAL;
12576
12577 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12578 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12579
12580 wdev_lock(wdev);
12581 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12582 wdev_unlock(wdev);
12583
12584 return err;
12585}
12586
12587static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12588 struct genl_info *info)
12589{
12590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12591 struct net_device *dev = info->user_ptr[1];
12592 struct wireless_dev *wdev = dev->ieee80211_ptr;
12593 const u8 *addr;
12594
12595 if (!rdev->ops->tdls_channel_switch ||
12596 !rdev->ops->tdls_cancel_channel_switch ||
12597 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12598 return -EOPNOTSUPP;
12599
12600 switch (dev->ieee80211_ptr->iftype) {
12601 case NL80211_IFTYPE_STATION:
12602 case NL80211_IFTYPE_P2P_CLIENT:
12603 break;
12604 default:
12605 return -EOPNOTSUPP;
12606 }
12607
12608 if (!info->attrs[NL80211_ATTR_MAC])
12609 return -EINVAL;
12610
12611 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12612
12613 wdev_lock(wdev);
12614 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12615 wdev_unlock(wdev);
12616
12617 return 0;
12618}
12619
Michael Braunce0ce132016-10-10 19:12:22 +020012620static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12621 struct genl_info *info)
12622{
12623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12624 struct net_device *dev = info->user_ptr[1];
12625 struct wireless_dev *wdev = dev->ieee80211_ptr;
12626 const struct nlattr *nla;
12627 bool enabled;
12628
Michael Braunce0ce132016-10-10 19:12:22 +020012629 if (!rdev->ops->set_multicast_to_unicast)
12630 return -EOPNOTSUPP;
12631
12632 if (wdev->iftype != NL80211_IFTYPE_AP &&
12633 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12634 return -EOPNOTSUPP;
12635
12636 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12637 enabled = nla_get_flag(nla);
12638
12639 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12640}
12641
Avraham Stern3a00df52017-06-09 13:08:43 +010012642static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12643{
12644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12645 struct net_device *dev = info->user_ptr[1];
12646 struct wireless_dev *wdev = dev->ieee80211_ptr;
12647 struct cfg80211_pmk_conf pmk_conf = {};
12648 int ret;
12649
12650 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12651 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12652 return -EOPNOTSUPP;
12653
12654 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12655 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12656 return -EOPNOTSUPP;
12657
12658 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12659 return -EINVAL;
12660
12661 wdev_lock(wdev);
12662 if (!wdev->current_bss) {
12663 ret = -ENOTCONN;
12664 goto out;
12665 }
12666
12667 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12668 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12669 ret = -EINVAL;
12670 goto out;
12671 }
12672
12673 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12674 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12675 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12676 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12677 ret = -EINVAL;
12678 goto out;
12679 }
12680
12681 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12682 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12683
12684 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12685 ret = -EINVAL;
12686 goto out;
12687 }
12688
12689 pmk_conf.pmk_r0_name =
12690 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12691 }
12692
12693 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12694out:
12695 wdev_unlock(wdev);
12696 return ret;
12697}
12698
12699static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12700{
12701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12702 struct net_device *dev = info->user_ptr[1];
12703 struct wireless_dev *wdev = dev->ieee80211_ptr;
12704 const u8 *aa;
12705 int ret;
12706
12707 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12708 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12709 return -EOPNOTSUPP;
12710
12711 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12712 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12713 return -EOPNOTSUPP;
12714
12715 if (!info->attrs[NL80211_ATTR_MAC])
12716 return -EINVAL;
12717
12718 wdev_lock(wdev);
12719 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12720 ret = rdev_del_pmk(rdev, dev, aa);
12721 wdev_unlock(wdev);
12722
12723 return ret;
12724}
12725
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012726static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
12727{
12728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12729 struct net_device *dev = info->user_ptr[1];
12730 struct cfg80211_external_auth_params params;
12731
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020012732 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012733 return -EOPNOTSUPP;
12734
12735 if (!info->attrs[NL80211_ATTR_SSID])
12736 return -EINVAL;
12737
12738 if (!info->attrs[NL80211_ATTR_BSSID])
12739 return -EINVAL;
12740
12741 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
12742 return -EINVAL;
12743
12744 memset(&params, 0, sizeof(params));
12745
12746 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12747 if (params.ssid.ssid_len == 0 ||
12748 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
12749 return -EINVAL;
12750 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
12751 params.ssid.ssid_len);
12752
12753 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
12754 ETH_ALEN);
12755
12756 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12757
12758 return rdev_external_auth(rdev, dev, &params);
12759}
12760
Denis Kenzior2576a9a2018-03-26 12:52:42 -050012761static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
12762{
12763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12764 struct net_device *dev = info->user_ptr[1];
12765 struct wireless_dev *wdev = dev->ieee80211_ptr;
12766 const u8 *buf;
12767 size_t len;
12768 u8 *dest;
12769 u16 proto;
12770 bool noencrypt;
12771 int err;
12772
12773 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12774 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
12775 return -EOPNOTSUPP;
12776
12777 if (!rdev->ops->tx_control_port)
12778 return -EOPNOTSUPP;
12779
12780 if (!info->attrs[NL80211_ATTR_FRAME] ||
12781 !info->attrs[NL80211_ATTR_MAC] ||
12782 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
12783 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
12784 return -EINVAL;
12785 }
12786
12787 wdev_lock(wdev);
12788
12789 switch (wdev->iftype) {
12790 case NL80211_IFTYPE_AP:
12791 case NL80211_IFTYPE_P2P_GO:
12792 case NL80211_IFTYPE_MESH_POINT:
12793 break;
12794 case NL80211_IFTYPE_ADHOC:
12795 case NL80211_IFTYPE_STATION:
12796 case NL80211_IFTYPE_P2P_CLIENT:
12797 if (wdev->current_bss)
12798 break;
12799 err = -ENOTCONN;
12800 goto out;
12801 default:
12802 err = -EOPNOTSUPP;
12803 goto out;
12804 }
12805
12806 wdev_unlock(wdev);
12807
12808 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
12809 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
12810 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
12811 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
12812 noencrypt =
12813 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
12814
12815 return rdev_tx_control_port(rdev, dev, buf, len,
12816 dest, cpu_to_be16(proto), noencrypt);
12817
12818 out:
12819 wdev_unlock(wdev);
12820 return err;
12821}
12822
Johannes Berg4c476992010-10-04 21:36:35 +020012823#define NL80211_FLAG_NEED_WIPHY 0x01
12824#define NL80211_FLAG_NEED_NETDEV 0x02
12825#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012826#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12827#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12828 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012829#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012830/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012831#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12832 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012833#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012834
Johannes Bergf84f7712013-11-14 17:14:45 +010012835static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012836 struct genl_info *info)
12837{
12838 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012839 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012840 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012841 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12842
12843 if (rtnl)
12844 rtnl_lock();
12845
12846 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012847 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012848 if (IS_ERR(rdev)) {
12849 if (rtnl)
12850 rtnl_unlock();
12851 return PTR_ERR(rdev);
12852 }
12853 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012854 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12855 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012856 ASSERT_RTNL();
12857
Johannes Berg89a54e42012-06-15 14:33:17 +020012858 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12859 info->attrs);
12860 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012861 if (rtnl)
12862 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012863 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012864 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012865
Johannes Berg89a54e42012-06-15 14:33:17 +020012866 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012867 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012868
Johannes Berg1bf614e2012-06-15 15:23:36 +020012869 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12870 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012871 if (rtnl)
12872 rtnl_unlock();
12873 return -EINVAL;
12874 }
12875
12876 info->user_ptr[1] = dev;
12877 } else {
12878 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012879 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012880
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012881 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12882 !wdev_running(wdev)) {
12883 if (rtnl)
12884 rtnl_unlock();
12885 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012886 }
12887
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012888 if (dev)
12889 dev_hold(dev);
12890
Johannes Berg4c476992010-10-04 21:36:35 +020012891 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012892 }
12893
12894 return 0;
12895}
12896
Johannes Bergf84f7712013-11-14 17:14:45 +010012897static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012898 struct genl_info *info)
12899{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012900 if (info->user_ptr[1]) {
12901 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12902 struct wireless_dev *wdev = info->user_ptr[1];
12903
12904 if (wdev->netdev)
12905 dev_put(wdev->netdev);
12906 } else {
12907 dev_put(info->user_ptr[1]);
12908 }
12909 }
Johannes Berg5393b912014-09-10 15:00:16 +030012910
Johannes Berg4c476992010-10-04 21:36:35 +020012911 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12912 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012913
12914 /* If needed, clear the netlink message payload from the SKB
12915 * as it might contain key data that shouldn't stick around on
12916 * the heap after the SKB is freed. The netlink message header
12917 * is still needed for further processing, so leave it intact.
12918 */
12919 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12920 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12921
12922 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12923 }
Johannes Berg4c476992010-10-04 21:36:35 +020012924}
12925
Johannes Berg4534de82013-11-14 17:14:46 +010012926static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012927 {
12928 .cmd = NL80211_CMD_GET_WIPHY,
12929 .doit = nl80211_get_wiphy,
12930 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012931 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012932 .policy = nl80211_policy,
12933 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012934 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12935 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012936 },
12937 {
12938 .cmd = NL80211_CMD_SET_WIPHY,
12939 .doit = nl80211_set_wiphy,
12940 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012941 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012942 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012943 },
12944 {
12945 .cmd = NL80211_CMD_GET_INTERFACE,
12946 .doit = nl80211_get_interface,
12947 .dumpit = nl80211_dump_interface,
12948 .policy = nl80211_policy,
12949 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012950 .internal_flags = NL80211_FLAG_NEED_WDEV |
12951 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012952 },
12953 {
12954 .cmd = NL80211_CMD_SET_INTERFACE,
12955 .doit = nl80211_set_interface,
12956 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012957 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012958 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12959 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012960 },
12961 {
12962 .cmd = NL80211_CMD_NEW_INTERFACE,
12963 .doit = nl80211_new_interface,
12964 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012965 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012966 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12967 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012968 },
12969 {
12970 .cmd = NL80211_CMD_DEL_INTERFACE,
12971 .doit = nl80211_del_interface,
12972 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012973 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012974 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012975 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012976 },
Johannes Berg41ade002007-12-19 02:03:29 +010012977 {
12978 .cmd = NL80211_CMD_GET_KEY,
12979 .doit = nl80211_get_key,
12980 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012981 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012982 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012983 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012984 },
12985 {
12986 .cmd = NL80211_CMD_SET_KEY,
12987 .doit = nl80211_set_key,
12988 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012989 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012990 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012991 NL80211_FLAG_NEED_RTNL |
12992 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012993 },
12994 {
12995 .cmd = NL80211_CMD_NEW_KEY,
12996 .doit = nl80211_new_key,
12997 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012998 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013000 NL80211_FLAG_NEED_RTNL |
13001 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010013002 },
13003 {
13004 .cmd = NL80211_CMD_DEL_KEY,
13005 .doit = nl80211_del_key,
13006 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013007 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013009 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010013010 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010013011 {
13012 .cmd = NL80211_CMD_SET_BEACON,
13013 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013014 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013015 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013017 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013018 },
13019 {
Johannes Berg88600202012-02-13 15:17:18 +010013020 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013021 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013022 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013023 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013025 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013026 },
13027 {
Johannes Berg88600202012-02-13 15:17:18 +010013028 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013029 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013030 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010013031 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013033 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010013034 },
Johannes Berg5727ef12007-12-19 02:03:34 +010013035 {
13036 .cmd = NL80211_CMD_GET_STATION,
13037 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013038 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010013039 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020013040 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13041 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013042 },
13043 {
13044 .cmd = NL80211_CMD_SET_STATION,
13045 .doit = nl80211_set_station,
13046 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013047 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013049 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013050 },
13051 {
13052 .cmd = NL80211_CMD_NEW_STATION,
13053 .doit = nl80211_new_station,
13054 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013055 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013057 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013058 },
13059 {
13060 .cmd = NL80211_CMD_DEL_STATION,
13061 .doit = nl80211_del_station,
13062 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013063 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013065 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010013066 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013067 {
13068 .cmd = NL80211_CMD_GET_MPATH,
13069 .doit = nl80211_get_mpath,
13070 .dumpit = nl80211_dump_mpath,
13071 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013072 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013074 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013075 },
13076 {
Henning Rogge66be7d22014-09-12 08:58:49 +020013077 .cmd = NL80211_CMD_GET_MPP,
13078 .doit = nl80211_get_mpp,
13079 .dumpit = nl80211_dump_mpp,
13080 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013081 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020013082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13083 NL80211_FLAG_NEED_RTNL,
13084 },
13085 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013086 .cmd = NL80211_CMD_SET_MPATH,
13087 .doit = nl80211_set_mpath,
13088 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013089 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013091 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013092 },
13093 {
13094 .cmd = NL80211_CMD_NEW_MPATH,
13095 .doit = nl80211_new_mpath,
13096 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013097 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013099 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013100 },
13101 {
13102 .cmd = NL80211_CMD_DEL_MPATH,
13103 .doit = nl80211_del_mpath,
13104 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013105 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013106 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013107 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010013108 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013109 {
13110 .cmd = NL80211_CMD_SET_BSS,
13111 .doit = nl80211_set_bss,
13112 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013113 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013114 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013115 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030013116 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013117 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013118 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013119 .doit = nl80211_get_reg_do,
13120 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013121 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013122 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013123 /* can be retrieved by unprivileged users */
13124 },
Johannes Bergb6863032015-10-15 09:25:18 +020013125#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080013126 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013127 .cmd = NL80211_CMD_SET_REG,
13128 .doit = nl80211_set_reg,
13129 .policy = nl80211_policy,
13130 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020013131 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013132 },
Johannes Bergb6863032015-10-15 09:25:18 +020013133#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070013134 {
13135 .cmd = NL80211_CMD_REQ_SET_REG,
13136 .doit = nl80211_req_set_reg,
13137 .policy = nl80211_policy,
13138 .flags = GENL_ADMIN_PERM,
13139 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013140 {
Johannes Berg1ea4ff32017-09-13 16:07:22 +020013141 .cmd = NL80211_CMD_RELOAD_REGDB,
13142 .doit = nl80211_reload_regdb,
13143 .policy = nl80211_policy,
13144 .flags = GENL_ADMIN_PERM,
13145 },
13146 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013147 .cmd = NL80211_CMD_GET_MESH_CONFIG,
13148 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013149 .policy = nl80211_policy,
13150 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013152 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013153 },
13154 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080013155 .cmd = NL80211_CMD_SET_MESH_CONFIG,
13156 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013157 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013158 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013159 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013160 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070013161 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020013162 {
Johannes Berg2a519312009-02-10 21:25:55 +010013163 .cmd = NL80211_CMD_TRIGGER_SCAN,
13164 .doit = nl80211_trigger_scan,
13165 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013166 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020013167 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013168 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010013169 },
13170 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013171 .cmd = NL80211_CMD_ABORT_SCAN,
13172 .doit = nl80211_abort_scan,
13173 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013174 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053013175 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13176 NL80211_FLAG_NEED_RTNL,
13177 },
13178 {
Johannes Berg2a519312009-02-10 21:25:55 +010013179 .cmd = NL80211_CMD_GET_SCAN,
13180 .policy = nl80211_policy,
13181 .dumpit = nl80211_dump_scan,
13182 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020013183 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013184 .cmd = NL80211_CMD_START_SCHED_SCAN,
13185 .doit = nl80211_start_sched_scan,
13186 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013187 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13189 NL80211_FLAG_NEED_RTNL,
13190 },
13191 {
13192 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
13193 .doit = nl80211_stop_sched_scan,
13194 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013195 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13197 NL80211_FLAG_NEED_RTNL,
13198 },
13199 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020013200 .cmd = NL80211_CMD_AUTHENTICATE,
13201 .doit = nl80211_authenticate,
13202 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013203 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013205 NL80211_FLAG_NEED_RTNL |
13206 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013207 },
13208 {
13209 .cmd = NL80211_CMD_ASSOCIATE,
13210 .doit = nl80211_associate,
13211 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013212 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013214 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013215 },
13216 {
13217 .cmd = NL80211_CMD_DEAUTHENTICATE,
13218 .doit = nl80211_deauthenticate,
13219 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013220 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013222 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013223 },
13224 {
13225 .cmd = NL80211_CMD_DISASSOCIATE,
13226 .doit = nl80211_disassociate,
13227 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013228 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013230 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020013231 },
Johannes Berg04a773a2009-04-19 21:24:32 +020013232 {
13233 .cmd = NL80211_CMD_JOIN_IBSS,
13234 .doit = nl80211_join_ibss,
13235 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013236 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013238 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013239 },
13240 {
13241 .cmd = NL80211_CMD_LEAVE_IBSS,
13242 .doit = nl80211_leave_ibss,
13243 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013246 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020013247 },
Johannes Bergaff89a92009-07-01 21:26:51 +020013248#ifdef CONFIG_NL80211_TESTMODE
13249 {
13250 .cmd = NL80211_CMD_TESTMODE,
13251 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070013252 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020013253 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013254 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013255 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13256 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020013257 },
13258#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020013259 {
13260 .cmd = NL80211_CMD_CONNECT,
13261 .doit = nl80211_connect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013266 },
13267 {
vamsi krishna088e8df2016-10-27 16:51:11 +030013268 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
13269 .doit = nl80211_update_connect_params,
13270 .policy = nl80211_policy,
13271 .flags = GENL_ADMIN_PERM,
13272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13273 NL80211_FLAG_NEED_RTNL,
13274 },
13275 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020013276 .cmd = NL80211_CMD_DISCONNECT,
13277 .doit = nl80211_disconnect,
13278 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020013280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013281 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020013282 },
Johannes Berg463d0182009-07-14 00:33:35 +020013283 {
13284 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
13285 .doit = nl80211_wiphy_netns,
13286 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013288 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13289 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013290 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013291 {
13292 .cmd = NL80211_CMD_GET_SURVEY,
13293 .policy = nl80211_policy,
13294 .dumpit = nl80211_dump_survey,
13295 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013296 {
13297 .cmd = NL80211_CMD_SET_PMKSA,
13298 .doit = nl80211_setdel_pmksa,
13299 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013300 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013302 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013303 },
13304 {
13305 .cmd = NL80211_CMD_DEL_PMKSA,
13306 .doit = nl80211_setdel_pmksa,
13307 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013308 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013309 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013310 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013311 },
13312 {
13313 .cmd = NL80211_CMD_FLUSH_PMKSA,
13314 .doit = nl80211_flush_pmksa,
13315 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013316 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013317 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013318 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013319 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013320 {
13321 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13322 .doit = nl80211_remain_on_channel,
13323 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013324 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013325 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013326 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013327 },
13328 {
13329 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13330 .doit = nl80211_cancel_remain_on_channel,
13331 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013332 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013333 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013334 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013335 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013336 {
13337 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
13338 .doit = nl80211_set_tx_bitrate_mask,
13339 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013341 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13342 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013343 },
Jouni Malinen026331c2010-02-15 12:53:10 +020013344 {
Johannes Berg2e161f72010-08-12 15:38:38 +020013345 .cmd = NL80211_CMD_REGISTER_FRAME,
13346 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013347 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013348 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013349 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013350 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013351 },
13352 {
Johannes Berg2e161f72010-08-12 15:38:38 +020013353 .cmd = NL80211_CMD_FRAME,
13354 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013355 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013356 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013357 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013358 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013359 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020013360 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013361 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
13362 .doit = nl80211_tx_mgmt_cancel_wait,
13363 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013364 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013365 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013366 NL80211_FLAG_NEED_RTNL,
13367 },
13368 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020013369 .cmd = NL80211_CMD_SET_POWER_SAVE,
13370 .doit = nl80211_set_power_save,
13371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013372 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013373 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13374 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013375 },
13376 {
13377 .cmd = NL80211_CMD_GET_POWER_SAVE,
13378 .doit = nl80211_get_power_save,
13379 .policy = nl80211_policy,
13380 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020013381 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13382 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013383 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013384 {
13385 .cmd = NL80211_CMD_SET_CQM,
13386 .doit = nl80211_set_cqm,
13387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013388 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013389 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13390 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013391 },
Johannes Bergf444de02010-05-05 15:25:02 +020013392 {
13393 .cmd = NL80211_CMD_SET_CHANNEL,
13394 .doit = nl80211_set_channel,
13395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013396 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013397 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13398 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013399 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013400 {
13401 .cmd = NL80211_CMD_SET_WDS_PEER,
13402 .doit = nl80211_set_wds_peer,
13403 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013404 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013405 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13406 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013407 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013408 {
13409 .cmd = NL80211_CMD_JOIN_MESH,
13410 .doit = nl80211_join_mesh,
13411 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013412 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13414 NL80211_FLAG_NEED_RTNL,
13415 },
13416 {
13417 .cmd = NL80211_CMD_LEAVE_MESH,
13418 .doit = nl80211_leave_mesh,
13419 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013420 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13422 NL80211_FLAG_NEED_RTNL,
13423 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013424 {
13425 .cmd = NL80211_CMD_JOIN_OCB,
13426 .doit = nl80211_join_ocb,
13427 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013428 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13430 NL80211_FLAG_NEED_RTNL,
13431 },
13432 {
13433 .cmd = NL80211_CMD_LEAVE_OCB,
13434 .doit = nl80211_leave_ocb,
13435 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013436 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13438 NL80211_FLAG_NEED_RTNL,
13439 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013440#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013441 {
13442 .cmd = NL80211_CMD_GET_WOWLAN,
13443 .doit = nl80211_get_wowlan,
13444 .policy = nl80211_policy,
13445 /* can be retrieved by unprivileged users */
13446 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13447 NL80211_FLAG_NEED_RTNL,
13448 },
13449 {
13450 .cmd = NL80211_CMD_SET_WOWLAN,
13451 .doit = nl80211_set_wowlan,
13452 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013453 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013454 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13455 NL80211_FLAG_NEED_RTNL,
13456 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013457#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013458 {
13459 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13460 .doit = nl80211_set_rekey_data,
13461 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013462 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013464 NL80211_FLAG_NEED_RTNL |
13465 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013466 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013467 {
13468 .cmd = NL80211_CMD_TDLS_MGMT,
13469 .doit = nl80211_tdls_mgmt,
13470 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013471 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13473 NL80211_FLAG_NEED_RTNL,
13474 },
13475 {
13476 .cmd = NL80211_CMD_TDLS_OPER,
13477 .doit = nl80211_tdls_oper,
13478 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013479 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13481 NL80211_FLAG_NEED_RTNL,
13482 },
Johannes Berg28946da2011-11-04 11:18:12 +010013483 {
13484 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13485 .doit = nl80211_register_unexpected_frame,
13486 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013487 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013488 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13489 NL80211_FLAG_NEED_RTNL,
13490 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013491 {
13492 .cmd = NL80211_CMD_PROBE_CLIENT,
13493 .doit = nl80211_probe_client,
13494 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013495 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013497 NL80211_FLAG_NEED_RTNL,
13498 },
Johannes Berg5e760232011-11-04 11:18:17 +010013499 {
13500 .cmd = NL80211_CMD_REGISTER_BEACONS,
13501 .doit = nl80211_register_beacons,
13502 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013503 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013504 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13505 NL80211_FLAG_NEED_RTNL,
13506 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013507 {
13508 .cmd = NL80211_CMD_SET_NOACK_MAP,
13509 .doit = nl80211_set_noack_map,
13510 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013511 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013512 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13513 NL80211_FLAG_NEED_RTNL,
13514 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013515 {
13516 .cmd = NL80211_CMD_START_P2P_DEVICE,
13517 .doit = nl80211_start_p2p_device,
13518 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013519 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013520 .internal_flags = NL80211_FLAG_NEED_WDEV |
13521 NL80211_FLAG_NEED_RTNL,
13522 },
13523 {
13524 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13525 .doit = nl80211_stop_p2p_device,
13526 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013527 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013528 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13529 NL80211_FLAG_NEED_RTNL,
13530 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013531 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013532 .cmd = NL80211_CMD_START_NAN,
13533 .doit = nl80211_start_nan,
13534 .policy = nl80211_policy,
13535 .flags = GENL_ADMIN_PERM,
13536 .internal_flags = NL80211_FLAG_NEED_WDEV |
13537 NL80211_FLAG_NEED_RTNL,
13538 },
13539 {
13540 .cmd = NL80211_CMD_STOP_NAN,
13541 .doit = nl80211_stop_nan,
13542 .policy = nl80211_policy,
13543 .flags = GENL_ADMIN_PERM,
13544 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13545 NL80211_FLAG_NEED_RTNL,
13546 },
13547 {
Ayala Bekera442b762016-09-20 17:31:15 +030013548 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13549 .doit = nl80211_nan_add_func,
13550 .policy = nl80211_policy,
13551 .flags = GENL_ADMIN_PERM,
13552 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13553 NL80211_FLAG_NEED_RTNL,
13554 },
13555 {
13556 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13557 .doit = nl80211_nan_del_func,
13558 .policy = nl80211_policy,
13559 .flags = GENL_ADMIN_PERM,
13560 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13561 NL80211_FLAG_NEED_RTNL,
13562 },
13563 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013564 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13565 .doit = nl80211_nan_change_config,
13566 .policy = nl80211_policy,
13567 .flags = GENL_ADMIN_PERM,
13568 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13569 NL80211_FLAG_NEED_RTNL,
13570 },
13571 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013572 .cmd = NL80211_CMD_SET_MCAST_RATE,
13573 .doit = nl80211_set_mcast_rate,
13574 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013575 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013576 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13577 NL80211_FLAG_NEED_RTNL,
13578 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013579 {
13580 .cmd = NL80211_CMD_SET_MAC_ACL,
13581 .doit = nl80211_set_mac_acl,
13582 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013583 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013584 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13585 NL80211_FLAG_NEED_RTNL,
13586 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013587 {
13588 .cmd = NL80211_CMD_RADAR_DETECT,
13589 .doit = nl80211_start_radar_detection,
13590 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013591 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013592 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13593 NL80211_FLAG_NEED_RTNL,
13594 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013595 {
13596 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13597 .doit = nl80211_get_protocol_features,
13598 .policy = nl80211_policy,
13599 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013600 {
13601 .cmd = NL80211_CMD_UPDATE_FT_IES,
13602 .doit = nl80211_update_ft_ies,
13603 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013604 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13606 NL80211_FLAG_NEED_RTNL,
13607 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013608 {
13609 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13610 .doit = nl80211_crit_protocol_start,
13611 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013612 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013613 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13614 NL80211_FLAG_NEED_RTNL,
13615 },
13616 {
13617 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13618 .doit = nl80211_crit_protocol_stop,
13619 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013620 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013621 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13622 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013623 },
13624 {
13625 .cmd = NL80211_CMD_GET_COALESCE,
13626 .doit = nl80211_get_coalesce,
13627 .policy = nl80211_policy,
13628 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13629 NL80211_FLAG_NEED_RTNL,
13630 },
13631 {
13632 .cmd = NL80211_CMD_SET_COALESCE,
13633 .doit = nl80211_set_coalesce,
13634 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013635 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013636 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13637 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013638 },
13639 {
13640 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13641 .doit = nl80211_channel_switch,
13642 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013643 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013644 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13645 NL80211_FLAG_NEED_RTNL,
13646 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013647 {
13648 .cmd = NL80211_CMD_VENDOR,
13649 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013650 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013651 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013652 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013653 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13654 NL80211_FLAG_NEED_RTNL,
13655 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013656 {
13657 .cmd = NL80211_CMD_SET_QOS_MAP,
13658 .doit = nl80211_set_qos_map,
13659 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013660 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13662 NL80211_FLAG_NEED_RTNL,
13663 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013664 {
13665 .cmd = NL80211_CMD_ADD_TX_TS,
13666 .doit = nl80211_add_tx_ts,
13667 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013668 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13670 NL80211_FLAG_NEED_RTNL,
13671 },
13672 {
13673 .cmd = NL80211_CMD_DEL_TX_TS,
13674 .doit = nl80211_del_tx_ts,
13675 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013676 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013677 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13678 NL80211_FLAG_NEED_RTNL,
13679 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013680 {
13681 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13682 .doit = nl80211_tdls_channel_switch,
13683 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013684 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013685 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13686 NL80211_FLAG_NEED_RTNL,
13687 },
13688 {
13689 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13690 .doit = nl80211_tdls_cancel_channel_switch,
13691 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013692 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13694 NL80211_FLAG_NEED_RTNL,
13695 },
Michael Braunce0ce132016-10-10 19:12:22 +020013696 {
13697 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13698 .doit = nl80211_set_multicast_to_unicast,
13699 .policy = nl80211_policy,
13700 .flags = GENL_UNS_ADMIN_PERM,
13701 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13702 NL80211_FLAG_NEED_RTNL,
13703 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013704 {
13705 .cmd = NL80211_CMD_SET_PMK,
13706 .doit = nl80211_set_pmk,
13707 .policy = nl80211_policy,
13708 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13709 NL80211_FLAG_NEED_RTNL,
13710 },
13711 {
13712 .cmd = NL80211_CMD_DEL_PMK,
13713 .doit = nl80211_del_pmk,
13714 .policy = nl80211_policy,
13715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13716 NL80211_FLAG_NEED_RTNL,
13717 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013718 {
13719 .cmd = NL80211_CMD_EXTERNAL_AUTH,
13720 .doit = nl80211_external_auth,
13721 .policy = nl80211_policy,
13722 .flags = GENL_ADMIN_PERM,
13723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13724 NL80211_FLAG_NEED_RTNL,
13725 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013726 {
13727 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
13728 .doit = nl80211_tx_control_port,
13729 .policy = nl80211_policy,
13730 .flags = GENL_UNS_ADMIN_PERM,
13731 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13732 NL80211_FLAG_NEED_RTNL,
13733 },
Johannes Berg55682962007-09-20 13:09:35 -040013734};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013735
Johannes Berg56989f62016-10-24 14:40:05 +020013736static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013737 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13738 .hdrsize = 0, /* no private header */
13739 .version = 1, /* no particular meaning now */
13740 .maxattr = NL80211_ATTR_MAX,
13741 .netnsok = true,
13742 .pre_doit = nl80211_pre_doit,
13743 .post_doit = nl80211_post_doit,
13744 .module = THIS_MODULE,
13745 .ops = nl80211_ops,
13746 .n_ops = ARRAY_SIZE(nl80211_ops),
13747 .mcgrps = nl80211_mcgrps,
13748 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13749};
13750
Johannes Berg55682962007-09-20 13:09:35 -040013751/* notification functions */
13752
Johannes Berg3bb20552014-05-26 13:52:25 +020013753void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13754 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013755{
13756 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013757 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013758
Johannes Berg3bb20552014-05-26 13:52:25 +020013759 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13760 cmd != NL80211_CMD_DEL_WIPHY);
13761
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013763 if (!msg)
13764 return;
13765
Johannes Berg3bb20552014-05-26 13:52:25 +020013766 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013767 nlmsg_free(msg);
13768 return;
13769 }
13770
Johannes Berg68eb5502013-11-19 15:19:38 +010013771 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013772 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013773}
13774
Denis Kenzior896ff062016-08-03 16:58:33 -050013775void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13776 struct wireless_dev *wdev,
13777 enum nl80211_commands cmd)
13778{
13779 struct sk_buff *msg;
13780
13781 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13782 cmd != NL80211_CMD_DEL_INTERFACE);
13783
13784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13785 if (!msg)
13786 return;
13787
13788 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13789 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13790 nlmsg_free(msg);
13791 return;
13792 }
13793
13794 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13795 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13796}
13797
Johannes Berg362a4152009-05-24 16:43:15 +020013798static int nl80211_add_scan_req(struct sk_buff *msg,
13799 struct cfg80211_registered_device *rdev)
13800{
13801 struct cfg80211_scan_request *req = rdev->scan_req;
13802 struct nlattr *nest;
13803 int i;
13804
13805 if (WARN_ON(!req))
13806 return 0;
13807
13808 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13809 if (!nest)
13810 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013811 for (i = 0; i < req->n_ssids; i++) {
13812 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13813 goto nla_put_failure;
13814 }
Johannes Berg362a4152009-05-24 16:43:15 +020013815 nla_nest_end(msg, nest);
13816
13817 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13818 if (!nest)
13819 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013820 for (i = 0; i < req->n_channels; i++) {
13821 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13822 goto nla_put_failure;
13823 }
Johannes Berg362a4152009-05-24 16:43:15 +020013824 nla_nest_end(msg, nest);
13825
David S. Miller9360ffd2012-03-29 04:41:26 -040013826 if (req->ie &&
13827 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13828 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013829
Johannes Bergae917c92013-10-25 11:05:22 +020013830 if (req->flags &&
13831 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13832 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013833
Avraham Stern1d762502016-07-05 17:10:13 +030013834 if (req->info.scan_start_tsf &&
13835 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13836 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13837 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13838 req->info.tsf_bssid)))
13839 goto nla_put_failure;
13840
Johannes Berg362a4152009-05-24 16:43:15 +020013841 return 0;
13842 nla_put_failure:
13843 return -ENOBUFS;
13844}
13845
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013846static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013847 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013848 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013849 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013850 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013851{
13852 void *hdr;
13853
Eric W. Biederman15e47302012-09-07 20:12:54 +000013854 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013855 if (!hdr)
13856 return -1;
13857
David S. Miller9360ffd2012-03-29 04:41:26 -040013858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013859 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13860 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013861 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13862 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013863 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013864
Johannes Berg362a4152009-05-24 16:43:15 +020013865 /* ignore errors and send incomplete event anyway */
13866 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013867
Johannes Berg053c0952015-01-16 22:09:00 +010013868 genlmsg_end(msg, hdr);
13869 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013870
13871 nla_put_failure:
13872 genlmsg_cancel(msg, hdr);
13873 return -EMSGSIZE;
13874}
13875
Luciano Coelho807f8a82011-05-11 17:09:35 +030013876static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013877nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013878 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013879{
13880 void *hdr;
13881
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013882 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013883 if (!hdr)
13884 return -1;
13885
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13887 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13888 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13889 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13890 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013891 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013892
Johannes Berg053c0952015-01-16 22:09:00 +010013893 genlmsg_end(msg, hdr);
13894 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013895
13896 nla_put_failure:
13897 genlmsg_cancel(msg, hdr);
13898 return -EMSGSIZE;
13899}
13900
Johannes Berga538e2d2009-06-16 19:56:42 +020013901void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013902 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013903{
13904 struct sk_buff *msg;
13905
Thomas Graf58050fc2012-06-28 03:57:45 +000013906 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013907 if (!msg)
13908 return;
13909
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013910 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013911 NL80211_CMD_TRIGGER_SCAN) < 0) {
13912 nlmsg_free(msg);
13913 return;
13914 }
13915
Johannes Berg68eb5502013-11-19 15:19:38 +010013916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013917 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013918}
13919
Johannes Bergf9d15d12014-01-22 11:14:19 +020013920struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13921 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013922{
13923 struct sk_buff *msg;
13924
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013925 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013926 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013927 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013928
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013929 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013930 aborted ? NL80211_CMD_SCAN_ABORTED :
13931 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013932 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013933 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013934 }
13935
Johannes Bergf9d15d12014-01-22 11:14:19 +020013936 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013937}
13938
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013939/* send message created by nl80211_build_scan_msg() */
13940void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13941 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013942{
Johannes Berg2a519312009-02-10 21:25:55 +010013943 if (!msg)
13944 return;
13945
Johannes Berg68eb5502013-11-19 15:19:38 +010013946 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013947 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013948}
13949
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013950void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013951{
13952 struct sk_buff *msg;
13953
Thomas Graf58050fc2012-06-28 03:57:45 +000013954 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013955 if (!msg)
13956 return;
13957
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013958 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013959 nlmsg_free(msg);
13960 return;
13961 }
13962
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013963 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013964 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013965}
13966
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013967static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13968 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013969{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013970 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013971 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13972 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013973
David S. Miller9360ffd2012-03-29 04:41:26 -040013974 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13975 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13976 NL80211_REGDOM_TYPE_WORLD))
13977 goto nla_put_failure;
13978 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13979 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13980 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13981 goto nla_put_failure;
13982 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13983 request->intersect) {
13984 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13985 NL80211_REGDOM_TYPE_INTERSECTION))
13986 goto nla_put_failure;
13987 } else {
13988 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13989 NL80211_REGDOM_TYPE_COUNTRY) ||
13990 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13991 request->alpha2))
13992 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013993 }
13994
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013995 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13996 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13997
13998 if (wiphy &&
13999 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
14000 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020014001
14002 if (wiphy &&
14003 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
14004 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
14005 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014006 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014007
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020014008 return true;
14009
14010nla_put_failure:
14011 return false;
14012}
14013
14014/*
14015 * This can happen on global regulatory changes or device specific settings
14016 * based on custom regulatory domains.
14017 */
14018void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
14019 struct regulatory_request *request)
14020{
14021 struct sk_buff *msg;
14022 void *hdr;
14023
14024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14025 if (!msg)
14026 return;
14027
14028 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
14029 if (!hdr) {
14030 nlmsg_free(msg);
14031 return;
14032 }
14033
14034 if (nl80211_reg_change_event_fill(msg, request) == false)
14035 goto nla_put_failure;
14036
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014037 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014038
Johannes Bergbc43b282009-07-25 10:54:13 +020014039 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014040 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014041 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020014042 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014043
14044 return;
14045
14046nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040014047 nlmsg_free(msg);
14048}
14049
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014050static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14051 struct net_device *netdev,
14052 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014053 enum nl80211_commands cmd, gfp_t gfp,
14054 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014055{
14056 struct sk_buff *msg;
14057 void *hdr;
14058
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014059 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014060 if (!msg)
14061 return;
14062
14063 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14064 if (!hdr) {
14065 nlmsg_free(msg);
14066 return;
14067 }
14068
David S. Miller9360ffd2012-03-29 04:41:26 -040014069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14071 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
14072 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014073
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014074 if (uapsd_queues >= 0) {
14075 struct nlattr *nla_wmm =
14076 nla_nest_start(msg, NL80211_ATTR_STA_WME);
14077 if (!nla_wmm)
14078 goto nla_put_failure;
14079
14080 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
14081 uapsd_queues))
14082 goto nla_put_failure;
14083
14084 nla_nest_end(msg, nla_wmm);
14085 }
14086
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014087 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014088
Johannes Berg68eb5502013-11-19 15:19:38 +010014089 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014090 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014091 return;
14092
14093 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014094 nlmsg_free(msg);
14095}
14096
14097void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014098 struct net_device *netdev, const u8 *buf,
14099 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014100{
14101 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014102 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014103}
14104
14105void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
14106 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014107 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014108{
Johannes Berge6d6e342009-07-01 21:26:47 +020014109 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014110 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014111}
14112
Jouni Malinen53b46b82009-03-27 20:53:56 +020014113void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014114 struct net_device *netdev, const u8 *buf,
14115 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014116{
14117 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014118 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014119}
14120
Jouni Malinen53b46b82009-03-27 20:53:56 +020014121void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
14122 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020014123 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014124{
14125 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014126 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014127}
14128
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014129void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
14130 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020014131{
Johannes Berg947add32013-02-22 22:05:20 +010014132 struct wireless_dev *wdev = dev->ieee80211_ptr;
14133 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014134 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014135 const struct ieee80211_mgmt *mgmt = (void *)buf;
14136 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020014137
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014138 if (WARN_ON(len < 2))
14139 return;
14140
14141 if (ieee80211_is_deauth(mgmt->frame_control))
14142 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
14143 else
14144 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
14145
14146 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030014147 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014148}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020014149EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020014150
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040014151static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
14152 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020014153 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014154{
14155 struct sk_buff *msg;
14156 void *hdr;
14157
Johannes Berge6d6e342009-07-01 21:26:47 +020014158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014159 if (!msg)
14160 return;
14161
14162 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14163 if (!hdr) {
14164 nlmsg_free(msg);
14165 return;
14166 }
14167
David S. Miller9360ffd2012-03-29 04:41:26 -040014168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14169 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14170 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
14171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14172 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030014173
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014174 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030014175
Johannes Berg68eb5502013-11-19 15:19:38 +010014176 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014177 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014178 return;
14179
14180 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030014181 nlmsg_free(msg);
14182}
14183
14184void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014185 struct net_device *netdev, const u8 *addr,
14186 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014187{
14188 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020014189 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014190}
14191
14192void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020014193 struct net_device *netdev, const u8 *addr,
14194 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030014195{
Johannes Berge6d6e342009-07-01 21:26:47 +020014196 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
14197 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030014198}
14199
Samuel Ortizb23aa672009-07-01 21:26:54 +020014200void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014201 struct net_device *netdev,
14202 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014203 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014204{
14205 struct sk_buff *msg;
14206 void *hdr;
14207
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014208 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020014209 cr->fils.kek_len + cr->fils.pmk_len +
14210 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014211 if (!msg)
14212 return;
14213
14214 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
14215 if (!hdr) {
14216 nlmsg_free(msg);
14217 return;
14218 }
14219
David S. Miller9360ffd2012-03-29 04:41:26 -040014220 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14221 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014222 (cr->bssid &&
14223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030014224 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014225 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
14226 cr->status) ||
14227 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020014228 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030014229 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
14230 cr->timeout_reason))) ||
14231 (cr->req_ie &&
14232 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
14233 (cr->resp_ie &&
14234 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014235 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020014236 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014237 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020014238 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030014239 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020014240 ((cr->fils.kek &&
14241 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
14242 cr->fils.kek)) ||
14243 (cr->fils.pmk &&
14244 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
14245 (cr->fils.pmkid &&
14246 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040014247 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014248
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014249 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014250
Johannes Berg68eb5502013-11-19 15:19:38 +010014251 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014252 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014253 return;
14254
14255 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014256 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014257}
14258
14259void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014260 struct net_device *netdev,
14261 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014262{
14263 struct sk_buff *msg;
14264 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014265 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014266
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014267 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014268 if (!msg)
14269 return;
14270
14271 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
14272 if (!hdr) {
14273 nlmsg_free(msg);
14274 return;
14275 }
14276
David S. Miller9360ffd2012-03-29 04:41:26 -040014277 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14279 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030014280 (info->req_ie &&
14281 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
14282 info->req_ie)) ||
14283 (info->resp_ie &&
14284 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern503c1fb2017-09-29 14:21:49 +020014285 info->resp_ie)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014286 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014287
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014288 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014289
Johannes Berg68eb5502013-11-19 15:19:38 +010014290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014291 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014292 return;
14293
14294 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014295 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014296}
14297
Avraham Stern503c1fb2017-09-29 14:21:49 +020014298void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
14299 struct net_device *netdev, const u8 *bssid)
14300{
14301 struct sk_buff *msg;
14302 void *hdr;
14303
14304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14305 if (!msg)
14306 return;
14307
14308 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
14309 if (!hdr) {
14310 nlmsg_free(msg);
14311 return;
14312 }
14313
14314 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14315 goto nla_put_failure;
14316
14317 genlmsg_end(msg, hdr);
14318
14319 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14320 NL80211_MCGRP_MLME, GFP_KERNEL);
14321 return;
14322
14323 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020014324 nlmsg_free(msg);
14325}
14326
Samuel Ortizb23aa672009-07-01 21:26:54 +020014327void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
14328 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020014329 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014330{
14331 struct sk_buff *msg;
14332 void *hdr;
14333
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014334 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014335 if (!msg)
14336 return;
14337
14338 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
14339 if (!hdr) {
14340 nlmsg_free(msg);
14341 return;
14342 }
14343
David S. Miller9360ffd2012-03-29 04:41:26 -040014344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14345 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020014346 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040014347 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
14348 (from_ap &&
14349 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
14350 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
14351 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014352
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014353 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014354
Johannes Berg68eb5502013-11-19 15:19:38 +010014355 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014356 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014357 return;
14358
14359 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014360 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014361}
14362
Johannes Berg04a773a2009-04-19 21:24:32 +020014363void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
14364 struct net_device *netdev, const u8 *bssid,
14365 gfp_t gfp)
14366{
14367 struct sk_buff *msg;
14368 void *hdr;
14369
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014371 if (!msg)
14372 return;
14373
14374 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
14375 if (!hdr) {
14376 nlmsg_free(msg);
14377 return;
14378 }
14379
David S. Miller9360ffd2012-03-29 04:41:26 -040014380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14381 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14383 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020014384
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014385 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020014386
Johannes Berg68eb5502013-11-19 15:19:38 +010014387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014388 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014389 return;
14390
14391 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020014392 nlmsg_free(msg);
14393}
14394
Johannes Berg947add32013-02-22 22:05:20 +010014395void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
14396 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070014397{
Johannes Berg947add32013-02-22 22:05:20 +010014398 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014400 struct sk_buff *msg;
14401 void *hdr;
14402
Johannes Berg947add32013-02-22 22:05:20 +010014403 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14404 return;
14405
14406 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14407
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014408 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014409 if (!msg)
14410 return;
14411
14412 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14413 if (!hdr) {
14414 nlmsg_free(msg);
14415 return;
14416 }
14417
David S. Miller9360ffd2012-03-29 04:41:26 -040014418 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14420 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014421 (ie_len && ie &&
14422 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14423 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014424
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014425 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014426
Johannes Berg68eb5502013-11-19 15:19:38 +010014427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014428 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014429 return;
14430
14431 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070014432 nlmsg_free(msg);
14433}
Johannes Berg947add32013-02-22 22:05:20 +010014434EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014435
Jouni Malinena3b8b052009-03-27 21:59:49 +020014436void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14437 struct net_device *netdev, const u8 *addr,
14438 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014439 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014440{
14441 struct sk_buff *msg;
14442 void *hdr;
14443
Johannes Berge6d6e342009-07-01 21:26:47 +020014444 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014445 if (!msg)
14446 return;
14447
14448 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14449 if (!hdr) {
14450 nlmsg_free(msg);
14451 return;
14452 }
14453
David S. Miller9360ffd2012-03-29 04:41:26 -040014454 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14455 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14456 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14457 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14458 (key_id != -1 &&
14459 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14460 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14461 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014462
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014463 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014464
Johannes Berg68eb5502013-11-19 15:19:38 +010014465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014466 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014467 return;
14468
14469 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020014470 nlmsg_free(msg);
14471}
14472
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014473void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14474 struct ieee80211_channel *channel_before,
14475 struct ieee80211_channel *channel_after)
14476{
14477 struct sk_buff *msg;
14478 void *hdr;
14479 struct nlattr *nl_freq;
14480
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014482 if (!msg)
14483 return;
14484
14485 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14486 if (!hdr) {
14487 nlmsg_free(msg);
14488 return;
14489 }
14490
14491 /*
14492 * Since we are applying the beacon hint to a wiphy we know its
14493 * wiphy_idx is valid
14494 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014495 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14496 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014497
14498 /* Before */
14499 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14500 if (!nl_freq)
14501 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014502
14503 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014504 goto nla_put_failure;
14505 nla_nest_end(msg, nl_freq);
14506
14507 /* After */
14508 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14509 if (!nl_freq)
14510 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030014511
14512 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014513 goto nla_put_failure;
14514 nla_nest_end(msg, nl_freq);
14515
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014516 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014517
Johannes Berg463d0182009-07-14 00:33:35 +020014518 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014519 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014520 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014521 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014522
14523 return;
14524
14525nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014526 nlmsg_free(msg);
14527}
14528
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014529static void nl80211_send_remain_on_chan_event(
14530 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014531 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014532 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014533 unsigned int duration, gfp_t gfp)
14534{
14535 struct sk_buff *msg;
14536 void *hdr;
14537
14538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14539 if (!msg)
14540 return;
14541
14542 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14543 if (!hdr) {
14544 nlmsg_free(msg);
14545 return;
14546 }
14547
David S. Miller9360ffd2012-03-29 04:41:26 -040014548 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014549 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14550 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014551 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14552 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014553 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014554 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14555 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014556 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14557 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014558 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014559
David S. Miller9360ffd2012-03-29 04:41:26 -040014560 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14561 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14562 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014563
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014564 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014565
Johannes Berg68eb5502013-11-19 15:19:38 +010014566 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014567 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014568 return;
14569
14570 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014571 nlmsg_free(msg);
14572}
14573
Johannes Berg947add32013-02-22 22:05:20 +010014574void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14575 struct ieee80211_channel *chan,
14576 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014577{
Johannes Berg947add32013-02-22 22:05:20 +010014578 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014579 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014580
14581 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014582 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014583 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014584 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014585}
Johannes Berg947add32013-02-22 22:05:20 +010014586EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014587
Johannes Berg947add32013-02-22 22:05:20 +010014588void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14589 struct ieee80211_channel *chan,
14590 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014591{
Johannes Berg947add32013-02-22 22:05:20 +010014592 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014593 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014594
14595 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014596 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014597 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014598}
Johannes Berg947add32013-02-22 22:05:20 +010014599EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014600
Johannes Berg947add32013-02-22 22:05:20 +010014601void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14602 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014603{
Johannes Berg947add32013-02-22 22:05:20 +010014604 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014605 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014606 struct sk_buff *msg;
14607
Johannes Berg947add32013-02-22 22:05:20 +010014608 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14609
Thomas Graf58050fc2012-06-28 03:57:45 +000014610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014611 if (!msg)
14612 return;
14613
Johannes Bergcf5ead82014-11-14 17:14:00 +010014614 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014615 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014616 nlmsg_free(msg);
14617 return;
14618 }
14619
Johannes Berg68eb5502013-11-19 15:19:38 +010014620 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014621 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014622}
Johannes Berg947add32013-02-22 22:05:20 +010014623EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014624
Johannes Bergcf5ead82014-11-14 17:14:00 +010014625void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14626 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014627{
Johannes Berg947add32013-02-22 22:05:20 +010014628 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014629 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014630 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020014631 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010014632
Johannes Berg73887fd2018-05-18 09:57:55 +020014633 if (!sinfo)
14634 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014635
Johannes Berg947add32013-02-22 22:05:20 +010014636 trace_cfg80211_del_sta(dev, mac_addr);
14637
Thomas Graf58050fc2012-06-28 03:57:45 +000014638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020014639 if (!msg) {
14640 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020014641 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020014642 }
Jouni Malinenec15e682011-03-23 15:29:52 +020014643
Johannes Bergcf5ead82014-11-14 17:14:00 +010014644 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014645 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014646 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020014647 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020014648 }
14649
Johannes Berg68eb5502013-11-19 15:19:38 +010014650 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014651 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014652}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014653EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014654
Johannes Berg947add32013-02-22 22:05:20 +010014655void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14656 enum nl80211_connect_failed_reason reason,
14657 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014658{
Johannes Berg947add32013-02-22 22:05:20 +010014659 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014661 struct sk_buff *msg;
14662 void *hdr;
14663
14664 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14665 if (!msg)
14666 return;
14667
14668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14669 if (!hdr) {
14670 nlmsg_free(msg);
14671 return;
14672 }
14673
14674 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14675 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14676 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14677 goto nla_put_failure;
14678
14679 genlmsg_end(msg, hdr);
14680
Johannes Berg68eb5502013-11-19 15:19:38 +010014681 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014682 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014683 return;
14684
14685 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014686 nlmsg_free(msg);
14687}
Johannes Berg947add32013-02-22 22:05:20 +010014688EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014689
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014690static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14691 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014692{
14693 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014694 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014695 struct sk_buff *msg;
14696 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014697 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014698
Eric W. Biederman15e47302012-09-07 20:12:54 +000014699 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014700 return false;
14701
14702 msg = nlmsg_new(100, gfp);
14703 if (!msg)
14704 return true;
14705
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014706 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014707 if (!hdr) {
14708 nlmsg_free(msg);
14709 return true;
14710 }
14711
David S. Miller9360ffd2012-03-29 04:41:26 -040014712 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14713 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14714 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14715 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014716
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014717 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014718 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014719 return true;
14720
14721 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010014722 nlmsg_free(msg);
14723 return true;
14724}
14725
Johannes Berg947add32013-02-22 22:05:20 +010014726bool cfg80211_rx_spurious_frame(struct net_device *dev,
14727 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014728{
Johannes Berg947add32013-02-22 22:05:20 +010014729 struct wireless_dev *wdev = dev->ieee80211_ptr;
14730 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014731
Johannes Berg947add32013-02-22 22:05:20 +010014732 trace_cfg80211_rx_spurious_frame(dev, addr);
14733
14734 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14735 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14736 trace_cfg80211_return_bool(false);
14737 return false;
14738 }
14739 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14740 addr, gfp);
14741 trace_cfg80211_return_bool(ret);
14742 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014743}
Johannes Berg947add32013-02-22 22:05:20 +010014744EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14745
14746bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14747 const u8 *addr, gfp_t gfp)
14748{
14749 struct wireless_dev *wdev = dev->ieee80211_ptr;
14750 bool ret;
14751
14752 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14753
14754 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14755 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14756 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14757 trace_cfg80211_return_bool(false);
14758 return false;
14759 }
14760 ret = __nl80211_unexpected_frame(dev,
14761 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14762 addr, gfp);
14763 trace_cfg80211_return_bool(ret);
14764 return ret;
14765}
14766EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014767
Johannes Berg2e161f72010-08-12 15:38:38 +020014768int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014769 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014770 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014771 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014772{
Johannes Berg71bbc992012-06-15 15:30:18 +020014773 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014774 struct sk_buff *msg;
14775 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014776
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014777 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014778 if (!msg)
14779 return -ENOMEM;
14780
Johannes Berg2e161f72010-08-12 15:38:38 +020014781 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014782 if (!hdr) {
14783 nlmsg_free(msg);
14784 return -ENOMEM;
14785 }
14786
David S. Miller9360ffd2012-03-29 04:41:26 -040014787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014788 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14789 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014790 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14791 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014792 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14793 (sig_dbm &&
14794 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014795 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14796 (flags &&
14797 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014798 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014799
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014800 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014801
Eric W. Biederman15e47302012-09-07 20:12:54 +000014802 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014803
14804 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020014805 nlmsg_free(msg);
14806 return -ENOBUFS;
14807}
14808
Johannes Berg947add32013-02-22 22:05:20 +010014809void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14810 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014811{
Johannes Berg947add32013-02-22 22:05:20 +010014812 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014813 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014814 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014815 struct sk_buff *msg;
14816 void *hdr;
14817
Johannes Berg947add32013-02-22 22:05:20 +010014818 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14819
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014820 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014821 if (!msg)
14822 return;
14823
Johannes Berg2e161f72010-08-12 15:38:38 +020014824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014825 if (!hdr) {
14826 nlmsg_free(msg);
14827 return;
14828 }
14829
David S. Miller9360ffd2012-03-29 04:41:26 -040014830 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014831 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14832 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014833 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14834 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014835 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014836 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14837 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014838 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14839 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014840
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014841 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014842
Johannes Berg68eb5502013-11-19 15:19:38 +010014843 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014844 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014845 return;
14846
14847 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020014848 nlmsg_free(msg);
14849}
Johannes Berg947add32013-02-22 22:05:20 +010014850EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014851
Denis Kenzior6a671a52018-03-26 12:52:41 -050014852static int __nl80211_rx_control_port(struct net_device *dev,
14853 const u8 *buf, size_t len,
14854 const u8 *addr, u16 proto,
14855 bool unencrypted, gfp_t gfp)
14856{
14857 struct wireless_dev *wdev = dev->ieee80211_ptr;
14858 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14859 struct sk_buff *msg;
14860 void *hdr;
14861 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
14862
14863 if (!nlportid)
14864 return -ENOENT;
14865
14866 msg = nlmsg_new(100 + len, gfp);
14867 if (!msg)
14868 return -ENOMEM;
14869
14870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
14871 if (!hdr) {
14872 nlmsg_free(msg);
14873 return -ENOBUFS;
14874 }
14875
14876 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14877 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14878 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14879 NL80211_ATTR_PAD) ||
14880 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14881 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
14882 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
14883 (unencrypted && nla_put_flag(msg,
14884 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
14885 goto nla_put_failure;
14886
14887 genlmsg_end(msg, hdr);
14888
14889 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14890
14891 nla_put_failure:
14892 nlmsg_free(msg);
14893 return -ENOBUFS;
14894}
14895
14896bool cfg80211_rx_control_port(struct net_device *dev,
14897 const u8 *buf, size_t len,
14898 const u8 *addr, u16 proto, bool unencrypted)
14899{
14900 int ret;
14901
14902 trace_cfg80211_rx_control_port(dev, buf, len, addr, proto, unencrypted);
14903 ret = __nl80211_rx_control_port(dev, buf, len, addr, proto,
14904 unencrypted, GFP_ATOMIC);
14905 trace_cfg80211_return_bool(ret == 0);
14906 return ret == 0;
14907}
14908EXPORT_SYMBOL(cfg80211_rx_control_port);
14909
Johannes Berg5b97f492014-11-26 12:37:43 +010014910static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14911 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014912{
Johannes Berg947add32013-02-22 22:05:20 +010014913 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014914 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14915 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14916 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014917
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014918 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014919 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014920
Johannes Berg5b97f492014-11-26 12:37:43 +010014921 cb = (void **)msg->cb;
14922
14923 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14924 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014925 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014926 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014927 }
14928
David S. Miller9360ffd2012-03-29 04:41:26 -040014929 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014930 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014931 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014932
Johannes Berg5b97f492014-11-26 12:37:43 +010014933 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014934 goto nla_put_failure;
14935
Johannes Berg5b97f492014-11-26 12:37:43 +010014936 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14937 if (!cb[1])
14938 goto nla_put_failure;
14939
14940 cb[2] = rdev;
14941
14942 return msg;
14943 nla_put_failure:
14944 nlmsg_free(msg);
14945 return NULL;
14946}
14947
14948static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14949{
14950 void **cb = (void **)msg->cb;
14951 struct cfg80211_registered_device *rdev = cb[2];
14952
14953 nla_nest_end(msg, cb[1]);
14954 genlmsg_end(msg, cb[0]);
14955
14956 memset(msg->cb, 0, sizeof(msg->cb));
14957
14958 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14959 NL80211_MCGRP_MLME, gfp);
14960}
14961
14962void cfg80211_cqm_rssi_notify(struct net_device *dev,
14963 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014964 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014965{
14966 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014967 struct wireless_dev *wdev = dev->ieee80211_ptr;
14968 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014969
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014970 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014971
Johannes Berg98f03342014-11-26 12:42:02 +010014972 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14973 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14974 return;
14975
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014976 if (wdev->cqm_config) {
14977 wdev->cqm_config->last_rssi_event_value = rssi_level;
14978
14979 cfg80211_cqm_rssi_update(rdev, dev);
14980
14981 if (rssi_level == 0)
14982 rssi_level = wdev->cqm_config->last_rssi_event_value;
14983 }
14984
Johannes Berg5b97f492014-11-26 12:37:43 +010014985 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14986 if (!msg)
14987 return;
14988
David S. Miller9360ffd2012-03-29 04:41:26 -040014989 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14990 rssi_event))
14991 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014992
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014993 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14994 rssi_level))
14995 goto nla_put_failure;
14996
Johannes Berg5b97f492014-11-26 12:37:43 +010014997 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014998
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014999 return;
15000
15001 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015002 nlmsg_free(msg);
15003}
Johannes Berg947add32013-02-22 22:05:20 +010015004EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015005
Johannes Berg5b97f492014-11-26 12:37:43 +010015006void cfg80211_cqm_txe_notify(struct net_device *dev,
15007 const u8 *peer, u32 num_packets,
15008 u32 rate, u32 intvl, gfp_t gfp)
15009{
15010 struct sk_buff *msg;
15011
15012 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15013 if (!msg)
15014 return;
15015
15016 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
15017 goto nla_put_failure;
15018
15019 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
15020 goto nla_put_failure;
15021
15022 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
15023 goto nla_put_failure;
15024
15025 cfg80211_send_cqm(msg, gfp);
15026 return;
15027
15028 nla_put_failure:
15029 nlmsg_free(msg);
15030}
15031EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
15032
15033void cfg80211_cqm_pktloss_notify(struct net_device *dev,
15034 const u8 *peer, u32 num_packets, gfp_t gfp)
15035{
15036 struct sk_buff *msg;
15037
15038 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
15039
15040 msg = cfg80211_prepare_cqm(dev, peer, gfp);
15041 if (!msg)
15042 return;
15043
15044 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
15045 goto nla_put_failure;
15046
15047 cfg80211_send_cqm(msg, gfp);
15048 return;
15049
15050 nla_put_failure:
15051 nlmsg_free(msg);
15052}
15053EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
15054
Johannes Berg98f03342014-11-26 12:42:02 +010015055void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
15056{
15057 struct sk_buff *msg;
15058
15059 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
15060 if (!msg)
15061 return;
15062
15063 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
15064 goto nla_put_failure;
15065
15066 cfg80211_send_cqm(msg, gfp);
15067 return;
15068
15069 nla_put_failure:
15070 nlmsg_free(msg);
15071}
15072EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
15073
Johannes Berg947add32013-02-22 22:05:20 +010015074static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15075 struct net_device *netdev, const u8 *bssid,
15076 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020015077{
15078 struct sk_buff *msg;
15079 struct nlattr *rekey_attr;
15080 void *hdr;
15081
Thomas Graf58050fc2012-06-28 03:57:45 +000015082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015083 if (!msg)
15084 return;
15085
15086 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
15087 if (!hdr) {
15088 nlmsg_free(msg);
15089 return;
15090 }
15091
David S. Miller9360ffd2012-03-29 04:41:26 -040015092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15093 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15094 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15095 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015096
15097 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
15098 if (!rekey_attr)
15099 goto nla_put_failure;
15100
David S. Miller9360ffd2012-03-29 04:41:26 -040015101 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
15102 NL80211_REPLAY_CTR_LEN, replay_ctr))
15103 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020015104
15105 nla_nest_end(msg, rekey_attr);
15106
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015107 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020015108
Johannes Berg68eb5502013-11-19 15:19:38 +010015109 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015110 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020015111 return;
15112
15113 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020015114 nlmsg_free(msg);
15115}
15116
Johannes Berg947add32013-02-22 22:05:20 +010015117void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
15118 const u8 *replay_ctr, gfp_t gfp)
15119{
15120 struct wireless_dev *wdev = dev->ieee80211_ptr;
15121 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015122 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015123
15124 trace_cfg80211_gtk_rekey_notify(dev, bssid);
15125 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
15126}
15127EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
15128
15129static void
15130nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15131 struct net_device *netdev, int index,
15132 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015133{
15134 struct sk_buff *msg;
15135 struct nlattr *attr;
15136 void *hdr;
15137
Thomas Graf58050fc2012-06-28 03:57:45 +000015138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015139 if (!msg)
15140 return;
15141
15142 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
15143 if (!hdr) {
15144 nlmsg_free(msg);
15145 return;
15146 }
15147
David S. Miller9360ffd2012-03-29 04:41:26 -040015148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15150 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015151
15152 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
15153 if (!attr)
15154 goto nla_put_failure;
15155
David S. Miller9360ffd2012-03-29 04:41:26 -040015156 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
15157 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
15158 (preauth &&
15159 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
15160 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015161
15162 nla_nest_end(msg, attr);
15163
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015164 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015165
Johannes Berg68eb5502013-11-19 15:19:38 +010015166 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015167 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015168 return;
15169
15170 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030015171 nlmsg_free(msg);
15172}
15173
Johannes Berg947add32013-02-22 22:05:20 +010015174void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
15175 const u8 *bssid, bool preauth, gfp_t gfp)
15176{
15177 struct wireless_dev *wdev = dev->ieee80211_ptr;
15178 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015179 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015180
15181 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
15182 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
15183}
15184EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
15185
15186static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
15187 struct net_device *netdev,
15188 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020015189 gfp_t gfp,
15190 enum nl80211_commands notif,
15191 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070015192{
15193 struct sk_buff *msg;
15194 void *hdr;
15195
Thomas Graf58050fc2012-06-28 03:57:45 +000015196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015197 if (!msg)
15198 return;
15199
Luciano Coelhof8d75522014-11-07 14:31:35 +020015200 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070015201 if (!hdr) {
15202 nlmsg_free(msg);
15203 return;
15204 }
15205
Johannes Berg683b6d32012-11-08 21:25:48 +010015206 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15207 goto nla_put_failure;
15208
15209 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040015210 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070015211
Luciano Coelhof8d75522014-11-07 14:31:35 +020015212 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
15213 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
15214 goto nla_put_failure;
15215
Thomas Pedersen53145262012-04-06 13:35:47 -070015216 genlmsg_end(msg, hdr);
15217
Johannes Berg68eb5502013-11-19 15:19:38 +010015218 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015219 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070015220 return;
15221
15222 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070015223 nlmsg_free(msg);
15224}
15225
Johannes Berg947add32013-02-22 22:05:20 +010015226void cfg80211_ch_switch_notify(struct net_device *dev,
15227 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070015228{
Johannes Berg947add32013-02-22 22:05:20 +010015229 struct wireless_dev *wdev = dev->ieee80211_ptr;
15230 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015232
Simon Wunderliche487eae2013-11-21 18:19:51 +010015233 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010015234
Simon Wunderliche487eae2013-11-21 18:19:51 +010015235 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010015236
Michal Kazior9e0e2962014-01-29 14:22:27 +010015237 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010015238 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020015239 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15240 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010015241}
15242EXPORT_SYMBOL(cfg80211_ch_switch_notify);
15243
Luciano Coelhof8d75522014-11-07 14:31:35 +020015244void cfg80211_ch_switch_started_notify(struct net_device *dev,
15245 struct cfg80211_chan_def *chandef,
15246 u8 count)
15247{
15248 struct wireless_dev *wdev = dev->ieee80211_ptr;
15249 struct wiphy *wiphy = wdev->wiphy;
15250 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15251
15252 trace_cfg80211_ch_switch_started_notify(dev, chandef);
15253
15254 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15255 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
15256}
15257EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
15258
Thomas Pedersen84f10702012-07-12 16:17:33 -070015259void
Simon Wunderlich04f39042013-02-08 18:16:19 +010015260nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010015261 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015262 enum nl80211_radar_event event,
15263 struct net_device *netdev, gfp_t gfp)
15264{
15265 struct sk_buff *msg;
15266 void *hdr;
15267
15268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15269 if (!msg)
15270 return;
15271
15272 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
15273 if (!hdr) {
15274 nlmsg_free(msg);
15275 return;
15276 }
15277
15278 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15279 goto nla_put_failure;
15280
15281 /* NOP and radar events don't need a netdev parameter */
15282 if (netdev) {
15283 struct wireless_dev *wdev = netdev->ieee80211_ptr;
15284
15285 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015286 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15287 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010015288 goto nla_put_failure;
15289 }
15290
15291 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
15292 goto nla_put_failure;
15293
15294 if (nl80211_send_chandef(msg, chandef))
15295 goto nla_put_failure;
15296
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015297 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015298
Johannes Berg68eb5502013-11-19 15:19:38 +010015299 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015300 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010015301 return;
15302
15303 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010015304 nlmsg_free(msg);
15305}
15306
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053015307void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
15308 struct sta_opmode_info *sta_opmode,
15309 gfp_t gfp)
15310{
15311 struct sk_buff *msg;
15312 struct wireless_dev *wdev = dev->ieee80211_ptr;
15313 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15314 void *hdr;
15315
15316 if (WARN_ON(!mac))
15317 return;
15318
15319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15320 if (!msg)
15321 return;
15322
15323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
15324 if (!hdr) {
15325 nlmsg_free(msg);
15326 return;
15327 }
15328
15329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
15330 goto nla_put_failure;
15331
15332 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15333 goto nla_put_failure;
15334
15335 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15336 goto nla_put_failure;
15337
15338 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
15339 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
15340 goto nla_put_failure;
15341
15342 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
15343 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
15344 goto nla_put_failure;
15345
15346 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
15347 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
15348 goto nla_put_failure;
15349
15350 genlmsg_end(msg, hdr);
15351
15352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15353 NL80211_MCGRP_MLME, gfp);
15354
15355 return;
15356
15357nla_put_failure:
15358 nlmsg_free(msg);
15359}
15360EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
15361
Johannes Berg7f6cf312011-11-04 11:18:15 +010015362void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015363 u64 cookie, bool acked, s32 ack_signal,
15364 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010015365{
15366 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015367 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015368 struct sk_buff *msg;
15369 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015370
Beni Lev4ee3e062012-08-27 12:49:39 +030015371 trace_cfg80211_probe_status(dev, addr, cookie, acked);
15372
Thomas Graf58050fc2012-06-28 03:57:45 +000015373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030015374
Johannes Berg7f6cf312011-11-04 11:18:15 +010015375 if (!msg)
15376 return;
15377
15378 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
15379 if (!hdr) {
15380 nlmsg_free(msg);
15381 return;
15382 }
15383
David S. Miller9360ffd2012-03-29 04:41:26 -040015384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15385 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15386 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015387 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15388 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015389 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
15390 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
15391 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015392 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015393
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015394 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015395
Johannes Berg68eb5502013-11-19 15:19:38 +010015396 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015397 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015398 return;
15399
15400 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010015401 nlmsg_free(msg);
15402}
15403EXPORT_SYMBOL(cfg80211_probe_status);
15404
Johannes Berg5e760232011-11-04 11:18:17 +010015405void cfg80211_report_obss_beacon(struct wiphy *wiphy,
15406 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070015407 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010015408{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015409 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010015410 struct sk_buff *msg;
15411 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070015412 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010015413
Beni Lev4ee3e062012-08-27 12:49:39 +030015414 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
15415
Ben Greear37c73b52012-10-26 14:49:25 -070015416 spin_lock_bh(&rdev->beacon_registrations_lock);
15417 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
15418 msg = nlmsg_new(len + 100, GFP_ATOMIC);
15419 if (!msg) {
15420 spin_unlock_bh(&rdev->beacon_registrations_lock);
15421 return;
15422 }
Johannes Berg5e760232011-11-04 11:18:17 +010015423
Ben Greear37c73b52012-10-26 14:49:25 -070015424 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15425 if (!hdr)
15426 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010015427
Ben Greear37c73b52012-10-26 14:49:25 -070015428 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15429 (freq &&
15430 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
15431 (sig_dbm &&
15432 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15433 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
15434 goto nla_put_failure;
15435
15436 genlmsg_end(msg, hdr);
15437
15438 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010015439 }
Ben Greear37c73b52012-10-26 14:49:25 -070015440 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015441 return;
15442
15443 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070015444 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015445 nlmsg_free(msg);
15446}
15447EXPORT_SYMBOL(cfg80211_report_obss_beacon);
15448
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015449#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015450static int cfg80211_net_detect_results(struct sk_buff *msg,
15451 struct cfg80211_wowlan_wakeup *wakeup)
15452{
15453 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
15454 struct nlattr *nl_results, *nl_match, *nl_freqs;
15455 int i, j;
15456
15457 nl_results = nla_nest_start(
15458 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15459 if (!nl_results)
15460 return -EMSGSIZE;
15461
15462 for (i = 0; i < nd->n_matches; i++) {
15463 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15464
15465 nl_match = nla_nest_start(msg, i);
15466 if (!nl_match)
15467 break;
15468
15469 /* The SSID attribute is optional in nl80211, but for
15470 * simplicity reasons it's always present in the
15471 * cfg80211 structure. If a driver can't pass the
15472 * SSID, that needs to be changed. A zero length SSID
15473 * is still a valid SSID (wildcard), so it cannot be
15474 * used for this purpose.
15475 */
15476 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
15477 match->ssid.ssid)) {
15478 nla_nest_cancel(msg, nl_match);
15479 goto out;
15480 }
15481
15482 if (match->n_channels) {
15483 nl_freqs = nla_nest_start(
15484 msg, NL80211_ATTR_SCAN_FREQUENCIES);
15485 if (!nl_freqs) {
15486 nla_nest_cancel(msg, nl_match);
15487 goto out;
15488 }
15489
15490 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020015491 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015492 nla_nest_cancel(msg, nl_freqs);
15493 nla_nest_cancel(msg, nl_match);
15494 goto out;
15495 }
15496 }
15497
15498 nla_nest_end(msg, nl_freqs);
15499 }
15500
15501 nla_nest_end(msg, nl_match);
15502 }
15503
15504out:
15505 nla_nest_end(msg, nl_results);
15506 return 0;
15507}
15508
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015509void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15510 struct cfg80211_wowlan_wakeup *wakeup,
15511 gfp_t gfp)
15512{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015513 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015514 struct sk_buff *msg;
15515 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015516 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015517
15518 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15519
15520 if (wakeup)
15521 size += wakeup->packet_present_len;
15522
15523 msg = nlmsg_new(size, gfp);
15524 if (!msg)
15525 return;
15526
15527 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15528 if (!hdr)
15529 goto free_msg;
15530
15531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015532 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15533 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015534 goto free_msg;
15535
15536 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15537 wdev->netdev->ifindex))
15538 goto free_msg;
15539
15540 if (wakeup) {
15541 struct nlattr *reasons;
15542
15543 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015544 if (!reasons)
15545 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015546
15547 if (wakeup->disconnect &&
15548 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15549 goto free_msg;
15550 if (wakeup->magic_pkt &&
15551 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15552 goto free_msg;
15553 if (wakeup->gtk_rekey_failure &&
15554 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15555 goto free_msg;
15556 if (wakeup->eap_identity_req &&
15557 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15558 goto free_msg;
15559 if (wakeup->four_way_handshake &&
15560 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15561 goto free_msg;
15562 if (wakeup->rfkill_release &&
15563 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15564 goto free_msg;
15565
15566 if (wakeup->pattern_idx >= 0 &&
15567 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15568 wakeup->pattern_idx))
15569 goto free_msg;
15570
Johannes Bergae917c92013-10-25 11:05:22 +020015571 if (wakeup->tcp_match &&
15572 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15573 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015574
Johannes Bergae917c92013-10-25 11:05:22 +020015575 if (wakeup->tcp_connlost &&
15576 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15577 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015578
Johannes Bergae917c92013-10-25 11:05:22 +020015579 if (wakeup->tcp_nomoretokens &&
15580 nla_put_flag(msg,
15581 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15582 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015583
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015584 if (wakeup->packet) {
15585 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15586 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15587
15588 if (!wakeup->packet_80211) {
15589 pkt_attr =
15590 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15591 len_attr =
15592 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15593 }
15594
15595 if (wakeup->packet_len &&
15596 nla_put_u32(msg, len_attr, wakeup->packet_len))
15597 goto free_msg;
15598
15599 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15600 wakeup->packet))
15601 goto free_msg;
15602 }
15603
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015604 if (wakeup->net_detect &&
15605 cfg80211_net_detect_results(msg, wakeup))
15606 goto free_msg;
15607
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015608 nla_nest_end(msg, reasons);
15609 }
15610
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015611 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015612
Johannes Berg68eb5502013-11-19 15:19:38 +010015613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015614 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015615 return;
15616
15617 free_msg:
15618 nlmsg_free(msg);
15619}
15620EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15621#endif
15622
Jouni Malinen3475b092012-11-16 22:49:57 +020015623void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15624 enum nl80211_tdls_operation oper,
15625 u16 reason_code, gfp_t gfp)
15626{
15627 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015628 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015629 struct sk_buff *msg;
15630 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015631
15632 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15633 reason_code);
15634
15635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15636 if (!msg)
15637 return;
15638
15639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15640 if (!hdr) {
15641 nlmsg_free(msg);
15642 return;
15643 }
15644
15645 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15646 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15647 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15648 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15649 (reason_code > 0 &&
15650 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15651 goto nla_put_failure;
15652
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015653 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015654
Johannes Berg68eb5502013-11-19 15:19:38 +010015655 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015656 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015657 return;
15658
15659 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020015660 nlmsg_free(msg);
15661}
15662EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15663
Jouni Malinen026331c2010-02-15 12:53:10 +020015664static int nl80211_netlink_notify(struct notifier_block * nb,
15665 unsigned long state,
15666 void *_notify)
15667{
15668 struct netlink_notify *notify = _notify;
15669 struct cfg80211_registered_device *rdev;
15670 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015671 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015672
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015673 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015674 return NOTIFY_DONE;
15675
15676 rcu_read_lock();
15677
Johannes Berg5e760232011-11-04 11:18:17 +010015678 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015679 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015680
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015681 list_for_each_entry_rcu(sched_scan_req,
15682 &rdev->sched_scan_req_list,
15683 list) {
15684 if (sched_scan_req->owner_nlportid == notify->portid) {
15685 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015686 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015687 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015688 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015689
Johannes Berg53873f12016-05-03 16:52:04 +030015690 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015691 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015692
Johannes Bergab810072017-04-26 07:43:41 +020015693 if (wdev->owner_nlportid == notify->portid) {
15694 wdev->nl_owner_dead = true;
15695 schedule_work(&rdev->destroy_work);
15696 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015697 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015698 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015699 }
15700
Ben Greear37c73b52012-10-26 14:49:25 -070015701 spin_lock_bh(&rdev->beacon_registrations_lock);
15702 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15703 list) {
15704 if (reg->nlportid == notify->portid) {
15705 list_del(&reg->list);
15706 kfree(reg);
15707 break;
15708 }
15709 }
15710 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015711 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015712
15713 rcu_read_unlock();
15714
Ilan peer05050752015-03-04 00:32:06 -050015715 /*
15716 * It is possible that the user space process that is controlling the
15717 * indoor setting disappeared, so notify the regulatory core.
15718 */
15719 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015720 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015721}
15722
15723static struct notifier_block nl80211_netlink_notifier = {
15724 .notifier_call = nl80211_netlink_notify,
15725};
15726
Jouni Malinen355199e2013-02-27 17:14:27 +020015727void cfg80211_ft_event(struct net_device *netdev,
15728 struct cfg80211_ft_event_params *ft_event)
15729{
15730 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015731 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015732 struct sk_buff *msg;
15733 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015734
15735 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15736
15737 if (!ft_event->target_ap)
15738 return;
15739
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015740 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015741 if (!msg)
15742 return;
15743
15744 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015745 if (!hdr)
15746 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015747
Johannes Bergae917c92013-10-25 11:05:22 +020015748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15749 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15750 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15751 goto out;
15752
15753 if (ft_event->ies &&
15754 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15755 goto out;
15756 if (ft_event->ric_ies &&
15757 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15758 ft_event->ric_ies))
15759 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015760
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015761 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015762
Johannes Berg68eb5502013-11-19 15:19:38 +010015763 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015764 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015765 return;
15766 out:
15767 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015768}
15769EXPORT_SYMBOL(cfg80211_ft_event);
15770
Arend van Spriel5de17982013-04-18 15:49:00 +020015771void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15772{
15773 struct cfg80211_registered_device *rdev;
15774 struct sk_buff *msg;
15775 void *hdr;
15776 u32 nlportid;
15777
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015778 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015779 if (!rdev->crit_proto_nlportid)
15780 return;
15781
15782 nlportid = rdev->crit_proto_nlportid;
15783 rdev->crit_proto_nlportid = 0;
15784
15785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15786 if (!msg)
15787 return;
15788
15789 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15790 if (!hdr)
15791 goto nla_put_failure;
15792
15793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015794 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15795 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015796 goto nla_put_failure;
15797
15798 genlmsg_end(msg, hdr);
15799
15800 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15801 return;
15802
15803 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020015804 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015805}
15806EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15807
Johannes Berg348baf02014-01-24 14:06:29 +010015808void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15809{
15810 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015811 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015812 struct sk_buff *msg;
15813 void *hdr;
15814
15815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15816 if (!msg)
15817 return;
15818
15819 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15820 if (!hdr)
15821 goto out;
15822
15823 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15824 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015825 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15826 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015827 goto out;
15828
15829 genlmsg_end(msg, hdr);
15830
15831 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15832 NL80211_MCGRP_MLME, GFP_KERNEL);
15833 return;
15834 out:
15835 nlmsg_free(msg);
15836}
15837
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015838int cfg80211_external_auth_request(struct net_device *dev,
15839 struct cfg80211_external_auth_params *params,
15840 gfp_t gfp)
15841{
15842 struct wireless_dev *wdev = dev->ieee80211_ptr;
15843 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15844 struct sk_buff *msg;
15845 void *hdr;
15846
15847 if (!wdev->conn_owner_nlportid)
15848 return -EINVAL;
15849
15850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15851 if (!msg)
15852 return -ENOMEM;
15853
15854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
15855 if (!hdr)
15856 goto nla_put_failure;
15857
15858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15859 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15860 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
15861 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
15862 params->action) ||
15863 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
15864 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
15865 params->ssid.ssid))
15866 goto nla_put_failure;
15867
15868 genlmsg_end(msg, hdr);
15869 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
15870 wdev->conn_owner_nlportid);
15871 return 0;
15872
15873 nla_put_failure:
15874 nlmsg_free(msg);
15875 return -ENOBUFS;
15876}
15877EXPORT_SYMBOL(cfg80211_external_auth_request);
15878
Johannes Berg55682962007-09-20 13:09:35 -040015879/* initialisation/exit functions */
15880
Johannes Berg56989f62016-10-24 14:40:05 +020015881int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015882{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015883 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015884
Johannes Berg489111e2016-10-24 14:40:03 +020015885 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015886 if (err)
15887 return err;
15888
Jouni Malinen026331c2010-02-15 12:53:10 +020015889 err = netlink_register_notifier(&nl80211_netlink_notifier);
15890 if (err)
15891 goto err_out;
15892
Johannes Berg55682962007-09-20 13:09:35 -040015893 return 0;
15894 err_out:
15895 genl_unregister_family(&nl80211_fam);
15896 return err;
15897}
15898
15899void nl80211_exit(void)
15900{
Jouni Malinen026331c2010-02-15 12:53:10 +020015901 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015902 genl_unregister_family(&nl80211_fam);
15903}