blob: 1d6e81e5b2c8a27c7922949f5e6d26b177f52207 [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
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Dan Williams259d8c12018-01-29 17:03:15 -080019#include <linux/nospec.h>
Johannes Berg2a519312009-02-10 21:25:55 +010020#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include <net/genetlink.h>
23#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020024#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010025#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040026#include "core.h"
27#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070028#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030029#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040030
Jouni Malinen5fb628e2011-08-10 23:54:35 +030031static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
32 struct genl_info *info,
33 struct cfg80211_crypto_settings *settings,
34 int cipher_limit);
35
Johannes Berg55682962007-09-20 13:09:35 -040036/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020037static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040038
Johannes Berg2a94fe42013-11-19 15:19:39 +010039/* multicast groups */
40enum nl80211_multicast_groups {
41 NL80211_MCGRP_CONFIG,
42 NL80211_MCGRP_SCAN,
43 NL80211_MCGRP_REGULATORY,
44 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010045 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030046 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010047 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
48};
49
50static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010051 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
52 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
53 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
54 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
55 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030056 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010057#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010058 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010059#endif
60};
61
Johannes Berg89a54e42012-06-15 14:33:17 +020062/* returns ERR_PTR values */
63static struct wireless_dev *
64__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040065{
Johannes Berg89a54e42012-06-15 14:33:17 +020066 struct cfg80211_registered_device *rdev;
67 struct wireless_dev *result = NULL;
68 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
69 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
70 u64 wdev_id;
71 int wiphy_idx = -1;
72 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040073
Johannes Berg5fe231e2013-05-08 21:45:15 +020074 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040075
Johannes Berg89a54e42012-06-15 14:33:17 +020076 if (!have_ifidx && !have_wdev_id)
77 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040078
Johannes Berg89a54e42012-06-15 14:33:17 +020079 if (have_ifidx)
80 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
81 if (have_wdev_id) {
82 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
83 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040084 }
85
Johannes Berg89a54e42012-06-15 14:33:17 +020086 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
87 struct wireless_dev *wdev;
88
89 if (wiphy_net(&rdev->wiphy) != netns)
90 continue;
91
92 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
93 continue;
94
Johannes Berg53873f12016-05-03 16:52:04 +030095 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020096 if (have_ifidx && wdev->netdev &&
97 wdev->netdev->ifindex == ifidx) {
98 result = wdev;
99 break;
100 }
101 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
102 result = wdev;
103 break;
104 }
105 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200106
107 if (result)
108 break;
109 }
110
111 if (result)
112 return result;
113 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400114}
115
Johannes Berga9455402012-06-15 13:32:49 +0200116static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200118{
Johannes Berg7fee47782012-06-15 14:09:58 +0200119 struct cfg80211_registered_device *rdev = NULL, *tmp;
120 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200121
Johannes Berg5fe231e2013-05-08 21:45:15 +0200122 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200123
Johannes Berg878d9ec2012-06-15 14:18:32 +0200124 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200125 !attrs[NL80211_ATTR_IFINDEX] &&
126 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200127 return ERR_PTR(-EINVAL);
128
Johannes Berg878d9ec2012-06-15 14:18:32 +0200129 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200130 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200131 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg89a54e42012-06-15 14:33:17 +0200133 if (attrs[NL80211_ATTR_WDEV]) {
134 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
135 struct wireless_dev *wdev;
136 bool found = false;
137
138 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
139 if (tmp) {
140 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300141 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (wdev->identifier != (u32)wdev_id)
143 continue;
144 found = true;
145 break;
146 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200147
148 if (!found)
149 tmp = NULL;
150
151 if (rdev && tmp != rdev)
152 return ERR_PTR(-EINVAL);
153 rdev = tmp;
154 }
155 }
156
Johannes Berg878d9ec2012-06-15 14:18:32 +0200157 if (attrs[NL80211_ATTR_IFINDEX]) {
158 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700159
Ying Xue7f2b8562014-01-15 10:23:45 +0800160 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200161 if (netdev) {
162 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800163 tmp = wiphy_to_rdev(
164 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200165 else
166 tmp = NULL;
167
Johannes Berg7fee47782012-06-15 14:09:58 +0200168 /* not wireless device -- return error */
169 if (!tmp)
170 return ERR_PTR(-EINVAL);
171
172 /* mismatch -- return error */
173 if (rdev && tmp != rdev)
174 return ERR_PTR(-EINVAL);
175
176 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
Johannes Berga9455402012-06-15 13:32:49 +0200178 }
179
Johannes Berg4f7eff12012-06-15 14:14:22 +0200180 if (!rdev)
181 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200182
Johannes Berg4f7eff12012-06-15 14:14:22 +0200183 if (netns != wiphy_net(&rdev->wiphy))
184 return ERR_PTR(-ENODEV);
185
186 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200187}
188
189/*
190 * This function returns a pointer to the driver
191 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200192 *
193 * The result of this can be a PTR_ERR and hence must
194 * be checked with IS_ERR() for errors.
195 */
196static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200197cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200198{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200199 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200200}
201
Johannes Berg55682962007-09-20 13:09:35 -0400202/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300203static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400204 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
205 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700206 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200207 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100208
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200209 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530210 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100211 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
213 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
214
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200215 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
217 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
218 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100219 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200220 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400221
222 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
224 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100225
Eliad Pellere007b852011-11-24 18:13:56 +0200226 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
227 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100228
Johannes Bergb9454e82009-07-08 13:29:08 +0200229 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100230 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
231 .len = WLAN_MAX_KEY_LEN },
232 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
233 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
234 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200235 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200236 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100237
238 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
239 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
240 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
241 .len = IEEE80211_MAX_DATA_LEN },
242 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
243 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100244 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
245 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
246 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
247 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
248 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100249 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100250 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200251 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100252 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800253 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100254 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300255
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700256 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
257 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
258
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300259 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
261 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200262 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
263 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100264 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300265
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800266 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700267 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700268
Johannes Berg6c739412011-11-03 09:27:01 +0100269 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200270
271 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
272 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
273 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100274 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
275 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200276
277 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
278 .len = IEEE80211_MAX_SSID_LEN },
279 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
280 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200281 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300282 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300283 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300284 [NL80211_ATTR_STA_FLAGS2] = {
285 .len = sizeof(struct nl80211_sta_flag_update),
286 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300287 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300288 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
289 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200290 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
291 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
292 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200293 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100294 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300295 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100296 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
297 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200298 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200299 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
300 .len = IEEE80211_MAX_DATA_LEN },
301 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200302 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200303 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300304 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200305 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300306 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
307 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200308 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900309 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
310 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100311 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100312 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100313 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200314 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700315 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300316 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200317 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200318 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300319 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300320 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
321 .len = IEEE80211_MAX_DATA_LEN },
322 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530324 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300325 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530326 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300327 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
330 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
331 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300332 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100333 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200334 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700336 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800337 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
338 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
339 .len = NL80211_HT_CAPABILITY_LEN
340 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100341 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530342 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530343 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200344 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700345 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300346 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000347 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700348 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100349 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
350 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasari8feb69c2017-07-07 01:43:41 +0300351 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530352 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
353 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200354 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
355 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100356 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100357 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
358 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
359 .len = NL80211_VHT_CAPABILITY_LEN,
360 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200361 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
362 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
363 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300364 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200365 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
366 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
367 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300368 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
369 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530370 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
371 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200372 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100373 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100374 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
376 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800377 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
378 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200379 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
380 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530381 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200382 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300383 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300384 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300385 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
386 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
387 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300388 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200389 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200390 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200391 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200392 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500393 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200394 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100395 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200396 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300397 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
398 .len = VHT_MUMIMO_GROUPS_DATA_LEN
399 },
400 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300401 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200402 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300403 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300404 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
405 .len = FILS_MAX_KEK_LEN },
406 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200407 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200408 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200409 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
410 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
411 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
412 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200413 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300414 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
415 .len = FILS_ERP_MAX_USERNAME_LEN },
416 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
417 .len = FILS_ERP_MAX_REALM_LEN },
418 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
419 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
420 .len = FILS_ERP_MAX_RRK_LEN },
421 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
422 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100423 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200424 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400425};
426
Johannes Berge31b8212010-10-05 19:39:30 +0200427/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000428static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200429 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200430 [NL80211_KEY_IDX] = { .type = NLA_U8 },
431 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200432 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200433 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
434 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200435 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100436 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
437};
438
439/* policy for the key default flags */
440static const struct nla_policy
441nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
442 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
443 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200444};
445
Johannes Bergf83ace32016-10-17 08:04:07 +0200446#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200447/* policy for WoWLAN attributes */
448static const struct nla_policy
449nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
450 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
452 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
453 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200454 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
456 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
457 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100458 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300459 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100460};
461
462static const struct nla_policy
463nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
464 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
465 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
466 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
467 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
468 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
469 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
470 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
471 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
472 },
473 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
474 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
475 },
476 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
477 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
478 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200479};
Johannes Bergf83ace32016-10-17 08:04:07 +0200480#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200481
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700482/* policy for coalesce rule attributes */
483static const struct nla_policy
484nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
485 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
486 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
487 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
488};
489
Johannes Berge5497d72011-07-05 16:35:40 +0200490/* policy for GTK rekey offload attributes */
491static const struct nla_policy
492nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
493 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
494 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
495 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
496};
497
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300498static const struct nla_policy
499nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200500 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300501 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100502 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700503 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300504};
505
Avraham Stern3b06d272015-10-12 09:51:34 +0300506static const struct nla_policy
507nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
508 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
509 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
510};
511
Arend van Spriel38de03d2016-03-02 20:37:18 +0100512static const struct nla_policy
513nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
514 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
515 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
516 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
517 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
518 },
519};
520
Ayala Bekera442b762016-09-20 17:31:15 +0300521/* policy for NAN function attributes */
522static const struct nla_policy
523nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
524 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300525 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300526 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
527 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
528 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
529 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
530 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
531 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
532 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
533 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
534 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
535 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
536 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
537 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
538 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
539 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
540 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
541 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
542};
543
544/* policy for Service Response Filter attributes */
545static const struct nla_policy
546nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
547 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
548 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
549 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
550 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
551 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
552};
553
Peng Xuad670232017-10-03 23:21:51 +0300554/* policy for packet pattern attributes */
555static const struct nla_policy
556nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
557 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
558 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
559 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
560};
561
Johannes Berg97990a02013-04-19 01:02:55 +0200562static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
563 struct netlink_callback *cb,
564 struct cfg80211_registered_device **rdev,
565 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100566{
Johannes Berg67748892010-10-04 21:14:06 +0200567 int err;
568
Johannes Berg97990a02013-04-19 01:02:55 +0200569 if (!cb->args[0]) {
570 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200571 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200572 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200573 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100574 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200575
Johannes Bergc90c39d2016-10-24 14:40:01 +0200576 *wdev = __cfg80211_wdev_from_attrs(
577 sock_net(skb->sk),
578 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100579 if (IS_ERR(*wdev))
580 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800581 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200582 /* 0 is the first index - add 1 to parse only once */
583 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200584 cb->args[1] = (*wdev)->identifier;
585 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200586 /* subtract the 1 again here */
587 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200588 struct wireless_dev *tmp;
589
Johannes Bergea90e0d2017-03-15 14:26:04 +0100590 if (!wiphy)
591 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800592 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200593 *wdev = NULL;
594
Johannes Berg53873f12016-05-03 16:52:04 +0300595 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200596 if (tmp->identifier == cb->args[1]) {
597 *wdev = tmp;
598 break;
599 }
600 }
Johannes Berg97990a02013-04-19 01:02:55 +0200601
Johannes Bergea90e0d2017-03-15 14:26:04 +0100602 if (!*wdev)
603 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200604 }
605
Johannes Berg67748892010-10-04 21:14:06 +0200606 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200607}
608
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100609/* IE validation */
610static bool is_valid_ie_attr(const struct nlattr *attr)
611{
612 const u8 *pos;
613 int len;
614
615 if (!attr)
616 return true;
617
618 pos = nla_data(attr);
619 len = nla_len(attr);
620
621 while (len) {
622 u8 elemlen;
623
624 if (len < 2)
625 return false;
626 len -= 2;
627
628 elemlen = pos[1];
629 if (elemlen > len)
630 return false;
631
632 len -= elemlen;
633 pos += 2 + elemlen;
634 }
635
636 return true;
637}
638
Johannes Berg55682962007-09-20 13:09:35 -0400639/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000640static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400641 int flags, u8 cmd)
642{
643 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000644 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400645}
646
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400647static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100648 struct ieee80211_channel *chan,
649 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400650{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200651 /* Some channels must be completely excluded from the
652 * list to protect old user-space tools from breaking
653 */
654 if (!large && chan->flags &
655 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
656 return 0;
657
David S. Miller9360ffd2012-03-29 04:41:26 -0400658 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
659 chan->center_freq))
660 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400661
David S. Miller9360ffd2012-03-29 04:41:26 -0400662 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
663 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
664 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200665 if (chan->flags & IEEE80211_CHAN_NO_IR) {
666 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
667 goto nla_put_failure;
668 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
669 goto nla_put_failure;
670 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100671 if (chan->flags & IEEE80211_CHAN_RADAR) {
672 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
673 goto nla_put_failure;
674 if (large) {
675 u32 time;
676
677 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
678
679 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
680 chan->dfs_state))
681 goto nla_put_failure;
682 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
683 time))
684 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100685 if (nla_put_u32(msg,
686 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
687 chan->dfs_cac_ms))
688 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100689 }
690 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400691
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100692 if (large) {
693 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
694 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
695 goto nla_put_failure;
696 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
697 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
698 goto nla_put_failure;
699 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
700 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
701 goto nla_put_failure;
702 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
703 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
704 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200705 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
706 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
707 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300708 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
709 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200710 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200711 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
712 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
713 goto nla_put_failure;
714 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
715 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
716 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100717 }
718
David S. Miller9360ffd2012-03-29 04:41:26 -0400719 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
720 DBM_TO_MBM(chan->max_power)))
721 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400722
723 return 0;
724
725 nla_put_failure:
726 return -ENOBUFS;
727}
728
Johannes Berg55682962007-09-20 13:09:35 -0400729/* netlink command implementations */
730
Johannes Bergb9454e82009-07-08 13:29:08 +0200731struct key_parse {
732 struct key_params p;
733 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200734 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200735 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100736 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200737};
738
Johannes Berg768075e2017-11-13 15:35:06 +0100739static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
740 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +0200741{
742 struct nlattr *tb[NL80211_KEY_MAX + 1];
743 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Berg768075e2017-11-13 15:35:06 +0100744 nl80211_key_policy, info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +0200745 if (err)
746 return err;
747
748 k->def = !!tb[NL80211_KEY_DEFAULT];
749 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
750
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100751 if (k->def) {
752 k->def_uni = true;
753 k->def_multi = true;
754 }
755 if (k->defmgmt)
756 k->def_multi = true;
757
Johannes Bergb9454e82009-07-08 13:29:08 +0200758 if (tb[NL80211_KEY_IDX])
759 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
760
761 if (tb[NL80211_KEY_DATA]) {
762 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
763 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
764 }
765
766 if (tb[NL80211_KEY_SEQ]) {
767 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
768 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
769 }
770
771 if (tb[NL80211_KEY_CIPHER])
772 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
773
Johannes Berge31b8212010-10-05 19:39:30 +0200774 if (tb[NL80211_KEY_TYPE]) {
775 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
776 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
Johannes Berg768075e2017-11-13 15:35:06 +0100777 return genl_err_attr(info, -EINVAL,
778 tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +0200779 }
780
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100781 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
782 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700783
Johannes Berg2da8f412012-01-20 13:52:37 +0100784 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
785 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Berg768075e2017-11-13 15:35:06 +0100786 nl80211_key_default_policy,
787 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100788 if (err)
789 return err;
790
791 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
792 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
793 }
794
Johannes Bergb9454e82009-07-08 13:29:08 +0200795 return 0;
796}
797
798static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
799{
800 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
801 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
802 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
803 }
804
805 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
806 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
807 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
808 }
809
810 if (info->attrs[NL80211_ATTR_KEY_IDX])
811 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
812
813 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
814 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
815
816 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
817 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
818
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100819 if (k->def) {
820 k->def_uni = true;
821 k->def_multi = true;
822 }
823 if (k->defmgmt)
824 k->def_multi = true;
825
Johannes Berge31b8212010-10-05 19:39:30 +0200826 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
827 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berg768075e2017-11-13 15:35:06 +0100828 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) {
829 GENL_SET_ERR_MSG(info, "key type out of range");
Johannes Berge31b8212010-10-05 19:39:30 +0200830 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100831 }
Johannes Berge31b8212010-10-05 19:39:30 +0200832 }
833
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100834 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
835 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200836 int err = nla_parse_nested(kdt,
837 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
838 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200839 nl80211_key_default_policy,
840 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100841 if (err)
842 return err;
843
844 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
845 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
846 }
847
Johannes Bergb9454e82009-07-08 13:29:08 +0200848 return 0;
849}
850
851static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
852{
853 int err;
854
855 memset(k, 0, sizeof(*k));
856 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200857 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200858
859 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +0100860 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +0200861 else
862 err = nl80211_parse_key_old(info, k);
863
864 if (err)
865 return err;
866
Johannes Berg768075e2017-11-13 15:35:06 +0100867 if (k->def && k->defmgmt) {
868 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +0200869 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100870 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200871
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100872 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100873 if (k->def_uni || !k->def_multi) {
874 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100875 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100876 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100877 }
878
Johannes Bergb9454e82009-07-08 13:29:08 +0200879 if (k->idx != -1) {
880 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +0100881 if (k->idx < 4 || k->idx > 5) {
882 GENL_SET_ERR_MSG(info,
883 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200884 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100885 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200886 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +0100887 if (k->idx < 0 || k->idx > 3) {
888 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +0200889 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100890 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200891 } else {
Johannes Berg768075e2017-11-13 15:35:06 +0100892 if (k->idx < 0 || k->idx > 5) {
893 GENL_SET_ERR_MSG(info, "key idx not 0-5");
Johannes Bergb9454e82009-07-08 13:29:08 +0200894 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100895 }
Johannes Bergb9454e82009-07-08 13:29:08 +0200896 }
897 }
898
899 return 0;
900}
901
Johannes Bergfffd0932009-07-08 14:22:54 +0200902static struct cfg80211_cached_keys *
903nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +0100904 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200905{
Johannes Berg768075e2017-11-13 15:35:06 +0100906 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 struct key_parse parse;
908 struct nlattr *key;
909 struct cfg80211_cached_keys *result;
910 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200911 bool have_key = false;
912
913 nla_for_each_nested(key, keys, rem) {
914 have_key = true;
915 break;
916 }
917
918 if (!have_key)
919 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200920
921 result = kzalloc(sizeof(*result), GFP_KERNEL);
922 if (!result)
923 return ERR_PTR(-ENOMEM);
924
925 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200926
927 nla_for_each_nested(key, keys, rem) {
928 memset(&parse, 0, sizeof(parse));
929 parse.idx = -1;
930
Johannes Berg768075e2017-11-13 15:35:06 +0100931 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +0200932 if (err)
933 goto error;
934 err = -EINVAL;
935 if (!parse.p.key)
936 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +0100937 if (parse.idx < 0 || parse.idx > 3) {
938 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +0200939 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +0100940 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200941 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +0100942 if (def) {
943 GENL_SET_ERR_MSG(info,
944 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +0200945 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +0100946 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200947 def = 1;
948 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100949 if (!parse.def_uni || !parse.def_multi)
950 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200951 } else if (parse.defmgmt)
952 goto error;
953 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200954 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200955 if (err)
956 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200957 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
958 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +0100959 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +0200960 err = -EINVAL;
961 goto error;
962 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200963 result->params[parse.idx].cipher = parse.p.cipher;
964 result->params[parse.idx].key_len = parse.p.key_len;
965 result->params[parse.idx].key = result->data[parse.idx];
966 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530967
Johannes Berg386b1f22016-09-13 16:10:02 +0200968 /* must be WEP key if we got here */
969 if (no_ht)
970 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200971 }
972
Johannes Bergf1c1f172016-09-13 17:08:23 +0200973 if (result->def < 0) {
974 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +0100975 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +0200976 goto error;
977 }
978
Johannes Bergfffd0932009-07-08 14:22:54 +0200979 return result;
980 error:
981 kfree(result);
982 return ERR_PTR(err);
983}
984
985static int nl80211_key_allowed(struct wireless_dev *wdev)
986{
987 ASSERT_WDEV_LOCK(wdev);
988
Johannes Bergfffd0932009-07-08 14:22:54 +0200989 switch (wdev->iftype) {
990 case NL80211_IFTYPE_AP:
991 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200992 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700993 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200994 break;
995 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200996 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200997 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200998 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200999 return -ENOLINK;
1000 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001001 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001002 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001003 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001004 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001005 case NL80211_IFTYPE_P2P_DEVICE:
1006 case NL80211_IFTYPE_WDS:
1007 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001008 return -EINVAL;
1009 }
1010
1011 return 0;
1012}
1013
Jouni Malinen664834d2014-01-15 00:01:44 +02001014static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1015 struct nlattr *tb)
1016{
1017 struct ieee80211_channel *chan;
1018
1019 if (tb == NULL)
1020 return NULL;
1021 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1022 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1023 return NULL;
1024 return chan;
1025}
1026
Johannes Berg7527a782011-05-13 10:58:57 +02001027static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1028{
1029 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1030 int i;
1031
1032 if (!nl_modes)
1033 goto nla_put_failure;
1034
1035 i = 0;
1036 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001037 if ((ifmodes & 1) && nla_put_flag(msg, i))
1038 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001039 ifmodes >>= 1;
1040 i++;
1041 }
1042
1043 nla_nest_end(msg, nl_modes);
1044 return 0;
1045
1046nla_put_failure:
1047 return -ENOBUFS;
1048}
1049
1050static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001051 struct sk_buff *msg,
1052 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001053{
1054 struct nlattr *nl_combis;
1055 int i, j;
1056
1057 nl_combis = nla_nest_start(msg,
1058 NL80211_ATTR_INTERFACE_COMBINATIONS);
1059 if (!nl_combis)
1060 goto nla_put_failure;
1061
1062 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1063 const struct ieee80211_iface_combination *c;
1064 struct nlattr *nl_combi, *nl_limits;
1065
1066 c = &wiphy->iface_combinations[i];
1067
1068 nl_combi = nla_nest_start(msg, i + 1);
1069 if (!nl_combi)
1070 goto nla_put_failure;
1071
1072 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1073 if (!nl_limits)
1074 goto nla_put_failure;
1075
1076 for (j = 0; j < c->n_limits; j++) {
1077 struct nlattr *nl_limit;
1078
1079 nl_limit = nla_nest_start(msg, j + 1);
1080 if (!nl_limit)
1081 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001082 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1083 c->limits[j].max))
1084 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001085 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1086 c->limits[j].types))
1087 goto nla_put_failure;
1088 nla_nest_end(msg, nl_limit);
1089 }
1090
1091 nla_nest_end(msg, nl_limits);
1092
David S. Miller9360ffd2012-03-29 04:41:26 -04001093 if (c->beacon_int_infra_match &&
1094 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1095 goto nla_put_failure;
1096 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1097 c->num_different_channels) ||
1098 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1099 c->max_interfaces))
1100 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001101 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001102 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1103 c->radar_detect_widths) ||
1104 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1105 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001106 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301107 if (c->beacon_int_min_gcd &&
1108 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1109 c->beacon_int_min_gcd))
1110 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001111
1112 nla_nest_end(msg, nl_combi);
1113 }
1114
1115 nla_nest_end(msg, nl_combis);
1116
1117 return 0;
1118nla_put_failure:
1119 return -ENOBUFS;
1120}
1121
Johannes Berg3713b4e2013-02-14 16:19:38 +01001122#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001123static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1124 struct sk_buff *msg)
1125{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001126 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001127 struct nlattr *nl_tcp;
1128
1129 if (!tcp)
1130 return 0;
1131
1132 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1133 if (!nl_tcp)
1134 return -ENOBUFS;
1135
1136 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1137 tcp->data_payload_max))
1138 return -ENOBUFS;
1139
1140 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1141 tcp->data_payload_max))
1142 return -ENOBUFS;
1143
1144 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1145 return -ENOBUFS;
1146
1147 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1148 sizeof(*tcp->tok), tcp->tok))
1149 return -ENOBUFS;
1150
1151 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1152 tcp->data_interval_max))
1153 return -ENOBUFS;
1154
1155 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1156 tcp->wake_payload_max))
1157 return -ENOBUFS;
1158
1159 nla_nest_end(msg, nl_tcp);
1160 return 0;
1161}
1162
Johannes Berg3713b4e2013-02-14 16:19:38 +01001163static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001164 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001165 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166{
1167 struct nlattr *nl_wowlan;
1168
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001169 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001170 return 0;
1171
1172 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1173 if (!nl_wowlan)
1174 return -ENOBUFS;
1175
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001176 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001177 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001178 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001180 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001181 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001182 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001183 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001184 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001185 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001186 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001187 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001188 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001189 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001190 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001191 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1192 return -ENOBUFS;
1193
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001194 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001195 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001196 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1197 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1198 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1199 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001200 };
1201
1202 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1203 sizeof(pat), &pat))
1204 return -ENOBUFS;
1205 }
1206
Luciano Coelho75453cc2015-01-09 14:06:37 +02001207 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1208 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1209 rdev->wiphy.wowlan->max_nd_match_sets))
1210 return -ENOBUFS;
1211
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001212 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001213 return -ENOBUFS;
1214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215 nla_nest_end(msg, nl_wowlan);
1216
1217 return 0;
1218}
1219#endif
1220
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001221static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001222 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001223{
1224 struct nl80211_coalesce_rule_support rule;
1225
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001226 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001227 return 0;
1228
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001229 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1230 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1231 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1232 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1233 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1234 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001235
1236 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1237 return -ENOBUFS;
1238
1239 return 0;
1240}
1241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1243 struct ieee80211_supported_band *sband)
1244{
1245 struct nlattr *nl_rates, *nl_rate;
1246 struct ieee80211_rate *rate;
1247 int i;
1248
1249 /* add HT info */
1250 if (sband->ht_cap.ht_supported &&
1251 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1252 sizeof(sband->ht_cap.mcs),
1253 &sband->ht_cap.mcs) ||
1254 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1255 sband->ht_cap.cap) ||
1256 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1257 sband->ht_cap.ampdu_factor) ||
1258 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1259 sband->ht_cap.ampdu_density)))
1260 return -ENOBUFS;
1261
1262 /* add VHT info */
1263 if (sband->vht_cap.vht_supported &&
1264 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1265 sizeof(sband->vht_cap.vht_mcs),
1266 &sband->vht_cap.vht_mcs) ||
1267 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1268 sband->vht_cap.cap)))
1269 return -ENOBUFS;
1270
1271 /* add bitrates */
1272 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1273 if (!nl_rates)
1274 return -ENOBUFS;
1275
1276 for (i = 0; i < sband->n_bitrates; i++) {
1277 nl_rate = nla_nest_start(msg, i);
1278 if (!nl_rate)
1279 return -ENOBUFS;
1280
1281 rate = &sband->bitrates[i];
1282 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1283 rate->bitrate))
1284 return -ENOBUFS;
1285 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1286 nla_put_flag(msg,
1287 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1288 return -ENOBUFS;
1289
1290 nla_nest_end(msg, nl_rate);
1291 }
1292
1293 nla_nest_end(msg, nl_rates);
1294
1295 return 0;
1296}
1297
1298static int
1299nl80211_send_mgmt_stypes(struct sk_buff *msg,
1300 const struct ieee80211_txrx_stypes *mgmt_stypes)
1301{
1302 u16 stypes;
1303 struct nlattr *nl_ftypes, *nl_ifs;
1304 enum nl80211_iftype ift;
1305 int i;
1306
1307 if (!mgmt_stypes)
1308 return 0;
1309
1310 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1311 if (!nl_ifs)
1312 return -ENOBUFS;
1313
1314 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1315 nl_ftypes = nla_nest_start(msg, ift);
1316 if (!nl_ftypes)
1317 return -ENOBUFS;
1318 i = 0;
1319 stypes = mgmt_stypes[ift].tx;
1320 while (stypes) {
1321 if ((stypes & 1) &&
1322 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1323 (i << 4) | IEEE80211_FTYPE_MGMT))
1324 return -ENOBUFS;
1325 stypes >>= 1;
1326 i++;
1327 }
1328 nla_nest_end(msg, nl_ftypes);
1329 }
1330
1331 nla_nest_end(msg, nl_ifs);
1332
1333 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1334 if (!nl_ifs)
1335 return -ENOBUFS;
1336
1337 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1338 nl_ftypes = nla_nest_start(msg, ift);
1339 if (!nl_ftypes)
1340 return -ENOBUFS;
1341 i = 0;
1342 stypes = mgmt_stypes[ift].rx;
1343 while (stypes) {
1344 if ((stypes & 1) &&
1345 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1346 (i << 4) | IEEE80211_FTYPE_MGMT))
1347 return -ENOBUFS;
1348 stypes >>= 1;
1349 i++;
1350 }
1351 nla_nest_end(msg, nl_ftypes);
1352 }
1353 nla_nest_end(msg, nl_ifs);
1354
1355 return 0;
1356}
1357
Johannes Berg17948992016-10-26 11:42:04 +02001358#define CMD(op, n) \
1359 do { \
1360 if (rdev->ops->op) { \
1361 i++; \
1362 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1363 goto nla_put_failure; \
1364 } \
1365 } while (0)
1366
1367static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1368 struct sk_buff *msg)
1369{
1370 int i = 0;
1371
1372 /*
1373 * do *NOT* add anything into this function, new things need to be
1374 * advertised only to new versions of userspace that can deal with
1375 * the split (and they can't possibly care about new features...
1376 */
1377 CMD(add_virtual_intf, NEW_INTERFACE);
1378 CMD(change_virtual_intf, SET_INTERFACE);
1379 CMD(add_key, NEW_KEY);
1380 CMD(start_ap, START_AP);
1381 CMD(add_station, NEW_STATION);
1382 CMD(add_mpath, NEW_MPATH);
1383 CMD(update_mesh_config, SET_MESH_CONFIG);
1384 CMD(change_bss, SET_BSS);
1385 CMD(auth, AUTHENTICATE);
1386 CMD(assoc, ASSOCIATE);
1387 CMD(deauth, DEAUTHENTICATE);
1388 CMD(disassoc, DISASSOCIATE);
1389 CMD(join_ibss, JOIN_IBSS);
1390 CMD(join_mesh, JOIN_MESH);
1391 CMD(set_pmksa, SET_PMKSA);
1392 CMD(del_pmksa, DEL_PMKSA);
1393 CMD(flush_pmksa, FLUSH_PMKSA);
1394 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1395 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1396 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1397 CMD(mgmt_tx, FRAME);
1398 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1399 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1400 i++;
1401 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1402 goto nla_put_failure;
1403 }
1404 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1405 rdev->ops->join_mesh) {
1406 i++;
1407 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1408 goto nla_put_failure;
1409 }
1410 CMD(set_wds_peer, SET_WDS_PEER);
1411 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1412 CMD(tdls_mgmt, TDLS_MGMT);
1413 CMD(tdls_oper, TDLS_OPER);
1414 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001415 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001416 CMD(sched_scan_start, START_SCHED_SCAN);
1417 CMD(probe_client, PROBE_CLIENT);
1418 CMD(set_noack_map, SET_NOACK_MAP);
1419 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1420 i++;
1421 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1422 goto nla_put_failure;
1423 }
1424 CMD(start_p2p_device, START_P2P_DEVICE);
1425 CMD(set_mcast_rate, SET_MCAST_RATE);
1426#ifdef CONFIG_NL80211_TESTMODE
1427 CMD(testmode_cmd, TESTMODE);
1428#endif
1429
1430 if (rdev->ops->connect || rdev->ops->auth) {
1431 i++;
1432 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1433 goto nla_put_failure;
1434 }
1435
1436 if (rdev->ops->disconnect || rdev->ops->deauth) {
1437 i++;
1438 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1439 goto nla_put_failure;
1440 }
1441
1442 return i;
1443 nla_put_failure:
1444 return -ENOBUFS;
1445}
1446
Johannes Berg86e8cf92013-06-19 10:57:22 +02001447struct nl80211_dump_wiphy_state {
1448 s64 filter_wiphy;
1449 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301450 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 bool split;
1452};
1453
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001454static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001455 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001458{
1459 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001460 struct nlattr *nl_bands, *nl_band;
1461 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001462 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001463 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001464 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001465 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001466 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001467 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001468 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001469
Johannes Berg3bb20552014-05-26 13:52:25 +02001470 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001471 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 return -ENOBUFS;
1473
Johannes Berg86e8cf92013-06-19 10:57:22 +02001474 if (WARN_ON(!state))
1475 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001476
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001479 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001480 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001482 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001483
Johannes Berg3bb20552014-05-26 13:52:25 +02001484 if (cmd != NL80211_CMD_NEW_WIPHY)
1485 goto finish;
1486
Johannes Berg86e8cf92013-06-19 10:57:22 +02001487 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 case 0:
1489 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001498 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001504 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001508 rdev->wiphy.max_match_sets) ||
1509 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1510 rdev->wiphy.max_sched_scan_plans) ||
1511 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1512 rdev->wiphy.max_sched_scan_plan_interval) ||
1513 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1514 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001515 goto nla_put_failure;
1516
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1519 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1522 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1525 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001526 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1528 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1531 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001534 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001535 state->split_start++;
1536 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001537 break;
1538 case 1:
1539 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1541 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001542 goto nla_put_failure;
1543
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001546 goto nla_put_failure;
1547
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1550 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001553 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001557
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001560 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001562
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 if ((rdev->wiphy.available_antennas_tx ||
1564 rdev->wiphy.available_antennas_rx) &&
1565 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 u32 tx_ant = 0, rx_ant = 0;
1567 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001568
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 if (!res) {
1571 if (nla_put_u32(msg,
1572 NL80211_ATTR_WIPHY_ANTENNA_TX,
1573 tx_ant) ||
1574 nla_put_u32(msg,
1575 NL80211_ATTR_WIPHY_ANTENNA_RX,
1576 rx_ant))
1577 goto nla_put_failure;
1578 }
Johannes Bergee688b002008-01-24 19:38:39 +01001579 }
1580
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
1582 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 break;
1584 case 2:
1585 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001588 state->split_start++;
1589 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 break;
1591 case 3:
1592 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1593 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001594 goto nla_put_failure;
1595
Johannes Berg86e8cf92013-06-19 10:57:22 +02001596 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001597 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 struct ieee80211_supported_band *sband;
1599
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001600 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601
1602 if (!sband)
1603 continue;
1604
1605 nl_band = nla_nest_start(msg, band);
1606 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001607 goto nla_put_failure;
1608
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 case 0:
1611 if (nl80211_send_band_rateinfo(msg, sband))
1612 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001613 state->chan_start++;
1614 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 break;
1616 default:
1617 /* add frequencies */
1618 nl_freqs = nla_nest_start(
1619 msg, NL80211_BAND_ATTR_FREQS);
1620 if (!nl_freqs)
1621 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001622
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 i < sband->n_channels;
1625 i++) {
1626 nl_freq = nla_nest_start(msg, i);
1627 if (!nl_freq)
1628 goto nla_put_failure;
1629
1630 chan = &sband->channels[i];
1631
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (nl80211_msg_put_channel(
1633 msg, chan,
1634 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 goto nla_put_failure;
1636
1637 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001638 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639 break;
1640 }
1641 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001642 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001643 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001644 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_nest_end(msg, nl_freqs);
1646 }
1647
1648 nla_nest_end(msg, nl_band);
1649
Johannes Berg86e8cf92013-06-19 10:57:22 +02001650 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001651 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001652 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001653 band--;
1654 break;
1655 }
Johannes Bergee688b002008-01-24 19:38:39 +01001656 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001657 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001658
Johannes Berg57fbcce2016-04-12 15:56:15 +02001659 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001660 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001662 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001663
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001665 if (state->band_start == 0 && state->chan_start == 0)
1666 state->split_start++;
1667 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 break;
1669 case 4:
1670 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1671 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001672 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673
Johannes Berg17948992016-10-26 11:42:04 +02001674 i = nl80211_add_commands_unsplit(rdev, msg);
1675 if (i < 0)
1676 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001677 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001678 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1679 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001681 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001682 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001683 if (rdev->wiphy.features &
1684 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001685 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001686 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001687 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001688 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001689#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001690
Johannes Berg3713b4e2013-02-14 16:19:38 +01001691 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001692 state->split_start++;
1693 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001694 break;
1695 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 if (rdev->ops->remain_on_channel &&
1697 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001698 nla_put_u32(msg,
1699 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001700 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001701 goto nla_put_failure;
1702
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1705 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001706
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1708 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001709 state->split_start++;
1710 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001711 break;
1712 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001713#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001714 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001715 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001716 state->split_start++;
1717 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001718 break;
1719#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001720 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721#endif
1722 case 7:
1723 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001724 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001725 goto nla_put_failure;
1726
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001728 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001730
Johannes Berg86e8cf92013-06-19 10:57:22 +02001731 state->split_start++;
1732 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001733 break;
1734 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001736 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001737 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001738 goto nla_put_failure;
1739
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001740 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001741 /*
1742 * We can only add the per-channel limit information if the
1743 * dump is split, otherwise it makes it too big. Therefore
1744 * only advertise it in that case.
1745 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001746 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001747 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1748 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001749 goto nla_put_failure;
1750
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001751 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001753 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1754 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001755 goto nla_put_failure;
1756
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001757 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1758 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001759 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001760 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001761 goto nla_put_failure;
1762
1763 /*
1764 * Any information below this point is only available to
1765 * applications that can deal with it being split. This
1766 * helps ensure that newly added capabilities don't break
1767 * older tools by overrunning their buffers.
1768 *
1769 * We still increment split_start so that in the split
1770 * case we'll continue with more data in the next round,
1771 * but break unconditionally so unsplit data stops here.
1772 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001774 break;
1775 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001776 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001777 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 rdev->wiphy.extended_capabilities_len,
1779 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001780 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001781 rdev->wiphy.extended_capabilities_len,
1782 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001783 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001784
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001785 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001786 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001787 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1788 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001789 goto nla_put_failure;
1790
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001791 state->split_start++;
1792 break;
1793 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001794 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001795 goto nla_put_failure;
1796
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001797 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001798 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1799 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1800 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001801
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001802 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001803 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001804 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001805 goto nla_put_failure;
1806
Johannes Bergad7e7182013-11-13 13:37:47 +01001807 state->split_start++;
1808 break;
1809 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001810 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001811 const struct nl80211_vendor_cmd_info *info;
1812 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001813
Johannes Berg567ffc32013-12-18 14:43:31 +01001814 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1815 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001816 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001817
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001818 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1819 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001820 if (nla_put(msg, i + 1, sizeof(*info), info))
1821 goto nla_put_failure;
1822 }
1823 nla_nest_end(msg, nested);
1824 }
1825
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001826 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001827 const struct nl80211_vendor_cmd_info *info;
1828 struct nlattr *nested;
1829
1830 nested = nla_nest_start(msg,
1831 NL80211_ATTR_VENDOR_EVENTS);
1832 if (!nested)
1833 goto nla_put_failure;
1834
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001835 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1836 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001837 if (nla_put(msg, i + 1, sizeof(*info), info))
1838 goto nla_put_failure;
1839 }
1840 nla_nest_end(msg, nested);
1841 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001842 state->split_start++;
1843 break;
1844 case 12:
1845 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1846 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1847 rdev->wiphy.max_num_csa_counters))
1848 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001849
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001850 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1851 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1852 goto nla_put_failure;
1853
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001854 if (rdev->wiphy.max_sched_scan_reqs &&
1855 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1856 rdev->wiphy.max_sched_scan_reqs))
1857 goto nla_put_failure;
1858
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001859 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1860 sizeof(rdev->wiphy.ext_features),
1861 rdev->wiphy.ext_features))
1862 goto nla_put_failure;
1863
Arend van Spriel38de03d2016-03-02 20:37:18 +01001864 if (rdev->wiphy.bss_select_support) {
1865 struct nlattr *nested;
1866 u32 bss_select_support = rdev->wiphy.bss_select_support;
1867
1868 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1869 if (!nested)
1870 goto nla_put_failure;
1871
1872 i = 0;
1873 while (bss_select_support) {
1874 if ((bss_select_support & 1) &&
1875 nla_put_flag(msg, i))
1876 goto nla_put_failure;
1877 i++;
1878 bss_select_support >>= 1;
1879 }
1880 nla_nest_end(msg, nested);
1881 }
1882
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301883 state->split_start++;
1884 break;
1885 case 13:
1886 if (rdev->wiphy.num_iftype_ext_capab &&
1887 rdev->wiphy.iftype_ext_capab) {
1888 struct nlattr *nested_ext_capab, *nested;
1889
1890 nested = nla_nest_start(msg,
1891 NL80211_ATTR_IFTYPE_EXT_CAPA);
1892 if (!nested)
1893 goto nla_put_failure;
1894
1895 for (i = state->capa_start;
1896 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1897 const struct wiphy_iftype_ext_capab *capab;
1898
1899 capab = &rdev->wiphy.iftype_ext_capab[i];
1900
1901 nested_ext_capab = nla_nest_start(msg, i);
1902 if (!nested_ext_capab ||
1903 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1904 capab->iftype) ||
1905 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1906 capab->extended_capabilities_len,
1907 capab->extended_capabilities) ||
1908 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1909 capab->extended_capabilities_len,
1910 capab->extended_capabilities_mask))
1911 goto nla_put_failure;
1912
1913 nla_nest_end(msg, nested_ext_capab);
1914 if (state->split)
1915 break;
1916 }
1917 nla_nest_end(msg, nested);
1918 if (i < rdev->wiphy.num_iftype_ext_capab) {
1919 state->capa_start = i + 1;
1920 break;
1921 }
1922 }
1923
Luca Coelho85859892017-02-08 15:00:34 +02001924 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1925 rdev->wiphy.nan_supported_bands))
1926 goto nla_put_failure;
1927
Johannes Berg3713b4e2013-02-14 16:19:38 +01001928 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001930 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001931 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001932 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001933 genlmsg_end(msg, hdr);
1934 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001935
1936 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001937 genlmsg_cancel(msg, hdr);
1938 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001939}
1940
Johannes Berg86e8cf92013-06-19 10:57:22 +02001941static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1942 struct netlink_callback *cb,
1943 struct nl80211_dump_wiphy_state *state)
1944{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001945 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02001946 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
1947 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001948 /* ignore parse errors for backward compatibility */
1949 if (ret)
1950 return 0;
1951
1952 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1953 if (tb[NL80211_ATTR_WIPHY])
1954 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1955 if (tb[NL80211_ATTR_WDEV])
1956 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1957 if (tb[NL80211_ATTR_IFINDEX]) {
1958 struct net_device *netdev;
1959 struct cfg80211_registered_device *rdev;
1960 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1961
Ying Xue7f2b8562014-01-15 10:23:45 +08001962 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001963 if (!netdev)
1964 return -ENODEV;
1965 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001966 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001967 netdev->ieee80211_ptr->wiphy);
1968 state->filter_wiphy = rdev->wiphy_idx;
1969 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001970 }
1971
1972 return 0;
1973}
1974
Johannes Berg55682962007-09-20 13:09:35 -04001975static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1976{
Johannes Berg645e77d2013-03-01 14:03:49 +01001977 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001978 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001979 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001980
Johannes Berg5fe231e2013-05-08 21:45:15 +02001981 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001982 if (!state) {
1983 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001984 if (!state) {
1985 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001986 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001987 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001988 state->filter_wiphy = -1;
1989 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1990 if (ret) {
1991 kfree(state);
1992 rtnl_unlock();
1993 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001994 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001995 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001996 }
1997
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001998 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1999 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002000 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002001 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002002 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002003 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002004 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002005 continue;
2006 /* attempt to fit multiple wiphy data chunks into the skb */
2007 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002008 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2009 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002010 NETLINK_CB(cb->skb).portid,
2011 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002012 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002013 if (ret < 0) {
2014 /*
2015 * If sending the wiphy data didn't fit (ENOBUFS
2016 * or EMSGSIZE returned), this SKB is still
2017 * empty (so it's not too big because another
2018 * wiphy dataset is already in the skb) and
2019 * we've not tried to adjust the dump allocation
2020 * yet ... then adjust the alloc size to be
2021 * bigger, and return 1 but with the empty skb.
2022 * This results in an empty message being RX'ed
2023 * in userspace, but that is ignored.
2024 *
2025 * We can then retry with the larger buffer.
2026 */
2027 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002028 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002029 cb->min_dump_alloc < 4096) {
2030 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002031 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002032 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002033 return 1;
2034 }
2035 idx--;
2036 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002037 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002038 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002039 break;
Johannes Berg55682962007-09-20 13:09:35 -04002040 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002041 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002042
Johannes Berg86e8cf92013-06-19 10:57:22 +02002043 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002044
2045 return skb->len;
2046}
2047
Johannes Berg86e8cf92013-06-19 10:57:22 +02002048static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2049{
2050 kfree((void *)cb->args[0]);
2051 return 0;
2052}
2053
Johannes Berg55682962007-09-20 13:09:35 -04002054static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2055{
2056 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002058 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002059
Johannes Berg645e77d2013-03-01 14:03:49 +01002060 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002061 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002062 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002063
Johannes Berg3bb20552014-05-26 13:52:25 +02002064 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2065 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002066 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002067 nlmsg_free(msg);
2068 return -ENOBUFS;
2069 }
Johannes Berg55682962007-09-20 13:09:35 -04002070
Johannes Berg134e6372009-07-10 09:51:34 +00002071 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002072}
2073
Jouni Malinen31888482008-10-30 16:59:24 +02002074static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2075 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2076 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2077 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2078 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2079 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2080};
2081
2082static int parse_txq_params(struct nlattr *tb[],
2083 struct ieee80211_txq_params *txq_params)
2084{
Dan Williams259d8c12018-01-29 17:03:15 -08002085 u8 ac;
2086
Johannes Berga3304b02012-03-28 11:04:24 +02002087 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002088 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2089 !tb[NL80211_TXQ_ATTR_AIFS])
2090 return -EINVAL;
2091
Dan Williams259d8c12018-01-29 17:03:15 -08002092 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002093 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2094 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2095 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2096 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2097
Dan Williams259d8c12018-01-29 17:03:15 -08002098 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002099 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002100 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002101 return 0;
2102}
2103
Johannes Bergf444de02010-05-05 15:25:02 +02002104static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2105{
2106 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002107 * You can only set the channel explicitly for WDS interfaces,
2108 * all others have their channel managed via their respective
2109 * "establish a connection" command (connect, join, ...)
2110 *
2111 * For AP/GO and mesh mode, the channel can be set with the
2112 * channel userspace API, but is only stored and passed to the
2113 * low-level driver when the AP starts or the mesh is joined.
2114 * This is for backward compatibility, userspace can also give
2115 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002116 *
2117 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002118 * whatever else is going on, so they have their own special
2119 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002120 */
2121 return !wdev ||
2122 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002123 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002124 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2125 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002126}
2127
Johannes Berg683b6d32012-11-08 21:25:48 +01002128static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2129 struct genl_info *info,
2130 struct cfg80211_chan_def *chandef)
2131{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302132 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002133
2134 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2135 return -EINVAL;
2136
2137 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2138
2139 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002140 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2141 chandef->center_freq1 = control_freq;
2142 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002143
2144 /* Primary channel not allowed */
2145 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2146 return -EINVAL;
2147
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002148 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2149 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002150
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002151 chantype = nla_get_u32(
2152 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2153
2154 switch (chantype) {
2155 case NL80211_CHAN_NO_HT:
2156 case NL80211_CHAN_HT20:
2157 case NL80211_CHAN_HT40PLUS:
2158 case NL80211_CHAN_HT40MINUS:
2159 cfg80211_chandef_create(chandef, chandef->chan,
2160 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002161 /* user input for center_freq is incorrect */
2162 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2163 chandef->center_freq1 != nla_get_u32(
2164 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2165 return -EINVAL;
2166 /* center_freq2 must be zero */
2167 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2168 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2169 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002170 break;
2171 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002172 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002173 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002174 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2175 chandef->width =
2176 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2177 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2178 chandef->center_freq1 =
2179 nla_get_u32(
2180 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2181 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2182 chandef->center_freq2 =
2183 nla_get_u32(
2184 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2185 }
2186
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002187 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002188 return -EINVAL;
2189
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002190 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2191 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002192 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002193
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002194 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2195 chandef->width == NL80211_CHAN_WIDTH_10) &&
2196 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2197 return -EINVAL;
2198
Johannes Berg683b6d32012-11-08 21:25:48 +01002199 return 0;
2200}
2201
Johannes Bergf444de02010-05-05 15:25:02 +02002202static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002203 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002204 struct genl_info *info)
2205{
Johannes Berg683b6d32012-11-08 21:25:48 +01002206 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002207 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002208 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002209 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002210
Jouni Malinene16821b2014-04-28 11:22:08 +03002211 if (dev)
2212 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002213 if (!nl80211_can_set_dev_channel(wdev))
2214 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002215 if (wdev)
2216 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002217
Johannes Berg683b6d32012-11-08 21:25:48 +01002218 result = nl80211_parse_chandef(rdev, info, &chandef);
2219 if (result)
2220 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002221
Johannes Berge8c9bd52012-06-06 08:18:22 +02002222 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002223 case NL80211_IFTYPE_AP:
2224 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002225 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2226 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002227 result = -EINVAL;
2228 break;
2229 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002230 if (wdev->beacon_interval) {
2231 if (!dev || !rdev->ops->set_ap_chanwidth ||
2232 !(rdev->wiphy.features &
2233 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2234 result = -EBUSY;
2235 break;
2236 }
2237
2238 /* Only allow dynamic channel width changes */
2239 if (chandef.chan != wdev->preset_chandef.chan) {
2240 result = -EBUSY;
2241 break;
2242 }
2243 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2244 if (result)
2245 break;
2246 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002247 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002248 result = 0;
2249 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002250 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002251 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002252 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002253 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002254 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002255 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002256 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002257 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002258 }
Johannes Bergf444de02010-05-05 15:25:02 +02002259
2260 return result;
2261}
2262
2263static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2264{
Johannes Berg4c476992010-10-04 21:36:35 +02002265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2266 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002267
Jouni Malinene16821b2014-04-28 11:22:08 +03002268 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002269}
2270
Bill Jordane8347eb2010-10-01 13:54:28 -04002271static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2272{
Johannes Berg43b19952010-10-07 13:10:30 +02002273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2274 struct net_device *dev = info->user_ptr[1];
2275 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002276 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002277
2278 if (!info->attrs[NL80211_ATTR_MAC])
2279 return -EINVAL;
2280
Johannes Berg43b19952010-10-07 13:10:30 +02002281 if (netif_running(dev))
2282 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002283
Johannes Berg43b19952010-10-07 13:10:30 +02002284 if (!rdev->ops->set_wds_peer)
2285 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002286
Johannes Berg43b19952010-10-07 13:10:30 +02002287 if (wdev->iftype != NL80211_IFTYPE_WDS)
2288 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002289
2290 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002291 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002292}
2293
Johannes Berg55682962007-09-20 13:09:35 -04002294static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2295{
2296 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002297 struct net_device *netdev = NULL;
2298 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002299 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002300 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002301 u32 changed;
2302 u8 retry_short = 0, retry_long = 0;
2303 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002304 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002305
Johannes Berg5fe231e2013-05-08 21:45:15 +02002306 ASSERT_RTNL();
2307
Johannes Bergf444de02010-05-05 15:25:02 +02002308 /*
2309 * Try to find the wiphy and netdev. Normally this
2310 * function shouldn't need the netdev, but this is
2311 * done for backward compatibility -- previously
2312 * setting the channel was done per wiphy, but now
2313 * it is per netdev. Previous userland like hostapd
2314 * also passed a netdev to set_wiphy, so that it is
2315 * possible to let that go to the right netdev!
2316 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002317
Johannes Bergf444de02010-05-05 15:25:02 +02002318 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2319 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2320
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002322 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002323 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002324 else
Johannes Bergf444de02010-05-05 15:25:02 +02002325 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002326 }
2327
Johannes Bergf444de02010-05-05 15:25:02 +02002328 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002329 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2330 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002331 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002332 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002333 wdev = NULL;
2334 netdev = NULL;
2335 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002336 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002337 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002338
2339 /*
2340 * end workaround code, by now the rdev is available
2341 * and locked, and wdev may or may not be NULL.
2342 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002343
2344 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002345 result = cfg80211_dev_rename(
2346 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002347
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002348 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002349 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002350
Jouni Malinen31888482008-10-30 16:59:24 +02002351 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2352 struct ieee80211_txq_params txq_params;
2353 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2354
Ying Xue7f2b8562014-01-15 10:23:45 +08002355 if (!rdev->ops->set_txq_params)
2356 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002357
Ying Xue7f2b8562014-01-15 10:23:45 +08002358 if (!netdev)
2359 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002360
Johannes Berg133a3ff2011-11-03 14:50:13 +01002361 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002362 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2363 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002364
Ying Xue7f2b8562014-01-15 10:23:45 +08002365 if (!netif_running(netdev))
2366 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002367
Jouni Malinen31888482008-10-30 16:59:24 +02002368 nla_for_each_nested(nl_txq_params,
2369 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2370 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002371 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2372 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002373 txq_params_policy,
2374 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002375 if (result)
2376 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002377 result = parse_txq_params(tb, &txq_params);
2378 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002379 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002380
Hila Gonene35e4d22012-06-27 17:19:42 +03002381 result = rdev_set_txq_params(rdev, netdev,
2382 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002383 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002384 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002385 }
2386 }
2387
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002388 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002389 result = __nl80211_set_channel(
2390 rdev,
2391 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2392 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002393 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002394 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002395 }
2396
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002397 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002398 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002399 enum nl80211_tx_power_setting type;
2400 int idx, mbm = 0;
2401
Johannes Bergc8442112012-10-24 10:17:18 +02002402 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2403 txp_wdev = NULL;
2404
Ying Xue7f2b8562014-01-15 10:23:45 +08002405 if (!rdev->ops->set_tx_power)
2406 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002407
2408 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2409 type = nla_get_u32(info->attrs[idx]);
2410
2411 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002412 (type != NL80211_TX_POWER_AUTOMATIC))
2413 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002414
2415 if (type != NL80211_TX_POWER_AUTOMATIC) {
2416 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2417 mbm = nla_get_u32(info->attrs[idx]);
2418 }
2419
Johannes Bergc8442112012-10-24 10:17:18 +02002420 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002421 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002422 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002423 }
2424
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002425 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2426 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2427 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002428
Bruno Randolf7f531e02010-12-16 11:30:22 +09002429 if ((!rdev->wiphy.available_antennas_tx &&
2430 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002431 !rdev->ops->set_antenna)
2432 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002433
2434 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2435 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2436
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002437 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002438 * available antenna masks, except for the "all" mask */
2439 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002440 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2441 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002442
Bruno Randolf7f531e02010-12-16 11:30:22 +09002443 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2444 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002445
Hila Gonene35e4d22012-06-27 17:19:42 +03002446 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002447 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002448 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002449 }
2450
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002451 changed = 0;
2452
2453 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2454 retry_short = nla_get_u8(
2455 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002456 if (retry_short == 0)
2457 return -EINVAL;
2458
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002459 changed |= WIPHY_PARAM_RETRY_SHORT;
2460 }
2461
2462 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2463 retry_long = nla_get_u8(
2464 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002465 if (retry_long == 0)
2466 return -EINVAL;
2467
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002468 changed |= WIPHY_PARAM_RETRY_LONG;
2469 }
2470
2471 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2472 frag_threshold = nla_get_u32(
2473 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002474 if (frag_threshold < 256)
2475 return -EINVAL;
2476
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002477 if (frag_threshold != (u32) -1) {
2478 /*
2479 * Fragments (apart from the last one) are required to
2480 * have even length. Make the fragmentation code
2481 * simpler by stripping LSB should someone try to use
2482 * odd threshold value.
2483 */
2484 frag_threshold &= ~0x1;
2485 }
2486 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2487 }
2488
2489 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2490 rts_threshold = nla_get_u32(
2491 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2492 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2493 }
2494
Lukáš Turek81077e82009-12-21 22:50:47 +01002495 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002496 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2497 return -EINVAL;
2498
Lukáš Turek81077e82009-12-21 22:50:47 +01002499 coverage_class = nla_get_u8(
2500 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2501 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2502 }
2503
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002504 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2505 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2506 return -EOPNOTSUPP;
2507
2508 changed |= WIPHY_PARAM_DYN_ACK;
2509 }
2510
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002511 if (changed) {
2512 u8 old_retry_short, old_retry_long;
2513 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002514 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002515
Ying Xue7f2b8562014-01-15 10:23:45 +08002516 if (!rdev->ops->set_wiphy_params)
2517 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002518
2519 old_retry_short = rdev->wiphy.retry_short;
2520 old_retry_long = rdev->wiphy.retry_long;
2521 old_frag_threshold = rdev->wiphy.frag_threshold;
2522 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002523 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002524
2525 if (changed & WIPHY_PARAM_RETRY_SHORT)
2526 rdev->wiphy.retry_short = retry_short;
2527 if (changed & WIPHY_PARAM_RETRY_LONG)
2528 rdev->wiphy.retry_long = retry_long;
2529 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2530 rdev->wiphy.frag_threshold = frag_threshold;
2531 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2532 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002533 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2534 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002535
Hila Gonene35e4d22012-06-27 17:19:42 +03002536 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002537 if (result) {
2538 rdev->wiphy.retry_short = old_retry_short;
2539 rdev->wiphy.retry_long = old_retry_long;
2540 rdev->wiphy.frag_threshold = old_frag_threshold;
2541 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002542 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002543 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002544 }
2545 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002546 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002547}
2548
Johannes Berg71bbc992012-06-15 15:30:18 +02002549static inline u64 wdev_id(struct wireless_dev *wdev)
2550{
2551 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002552 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002553}
Johannes Berg55682962007-09-20 13:09:35 -04002554
Johannes Berg683b6d32012-11-08 21:25:48 +01002555static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002556 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002557{
Johannes Berg601555c2014-11-27 17:26:56 +01002558 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2559 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002560
Johannes Berg683b6d32012-11-08 21:25:48 +01002561 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2562 chandef->chan->center_freq))
2563 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002564 switch (chandef->width) {
2565 case NL80211_CHAN_WIDTH_20_NOHT:
2566 case NL80211_CHAN_WIDTH_20:
2567 case NL80211_CHAN_WIDTH_40:
2568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2569 cfg80211_get_chandef_type(chandef)))
2570 return -ENOBUFS;
2571 break;
2572 default:
2573 break;
2574 }
2575 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2576 return -ENOBUFS;
2577 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2578 return -ENOBUFS;
2579 if (chandef->center_freq2 &&
2580 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002581 return -ENOBUFS;
2582 return 0;
2583}
2584
Eric W. Biederman15e47302012-09-07 20:12:54 +00002585static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002586 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002587 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002588{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002589 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002590 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002591 void *hdr;
2592
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002593 if (removal)
2594 cmd = NL80211_CMD_DEL_INTERFACE;
2595
2596 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002597 if (!hdr)
2598 return -1;
2599
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002600 if (dev &&
2601 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002602 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002603 goto nla_put_failure;
2604
2605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2606 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002607 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2608 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002609 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002610 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2611 rdev->devlist_generation ^
2612 (cfg80211_rdev_list_generation << 2)))
2613 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002614
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002615 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002616 int ret;
2617 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002618
Johannes Berg683b6d32012-11-08 21:25:48 +01002619 ret = rdev_get_channel(rdev, wdev, &chandef);
2620 if (ret == 0) {
2621 if (nl80211_send_chandef(msg, &chandef))
2622 goto nla_put_failure;
2623 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002624 }
2625
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002626 if (rdev->ops->get_tx_power) {
2627 int dbm, ret;
2628
2629 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2630 if (ret == 0 &&
2631 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2632 DBM_TO_MBM(dbm)))
2633 goto nla_put_failure;
2634 }
2635
Johannes Berg44905262017-10-17 21:56:01 +02002636 wdev_lock(wdev);
2637 switch (wdev->iftype) {
2638 case NL80211_IFTYPE_AP:
2639 if (wdev->ssid_len &&
2640 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01002641 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02002642 break;
2643 case NL80211_IFTYPE_STATION:
2644 case NL80211_IFTYPE_P2P_CLIENT:
2645 case NL80211_IFTYPE_ADHOC: {
2646 const u8 *ssid_ie;
2647 if (!wdev->current_bss)
2648 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002649 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02002650 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
2651 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002652 if (ssid_ie &&
2653 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
2654 goto nla_put_failure_rcu_locked;
2655 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02002656 break;
2657 }
2658 default:
2659 /* nothing */
2660 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002661 }
Johannes Berg44905262017-10-17 21:56:01 +02002662 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002663
Johannes Berg053c0952015-01-16 22:09:00 +01002664 genlmsg_end(msg, hdr);
2665 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002666
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01002667 nla_put_failure_rcu_locked:
2668 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01002669 nla_put_failure_locked:
2670 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002671 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002672 genlmsg_cancel(msg, hdr);
2673 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002674}
2675
2676static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2677{
2678 int wp_idx = 0;
2679 int if_idx = 0;
2680 int wp_start = cb->args[0];
2681 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002682 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002683 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002684 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002685 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002686
Johannes Berg5fe231e2013-05-08 21:45:15 +02002687 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002688 if (!cb->args[2]) {
2689 struct nl80211_dump_wiphy_state state = {
2690 .filter_wiphy = -1,
2691 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002692
2693 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2694 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002695 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002696
2697 filter_wiphy = state.filter_wiphy;
2698
2699 /*
2700 * if filtering, set cb->args[2] to +1 since 0 is the default
2701 * value needed to determine that parsing is necessary.
2702 */
2703 if (filter_wiphy >= 0)
2704 cb->args[2] = filter_wiphy + 1;
2705 else
2706 cb->args[2] = -1;
2707 } else if (cb->args[2] > 0) {
2708 filter_wiphy = cb->args[2] - 1;
2709 }
2710
Johannes Bergf5ea9122009-08-07 16:17:38 +02002711 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2712 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002713 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002714 if (wp_idx < wp_start) {
2715 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002716 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002717 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002718
2719 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2720 continue;
2721
Johannes Berg55682962007-09-20 13:09:35 -04002722 if_idx = 0;
2723
Johannes Berg53873f12016-05-03 16:52:04 +03002724 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002725 if (if_idx < if_start) {
2726 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002727 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002728 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002729 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002730 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002731 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002732 goto out;
2733 }
2734 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002735 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002736
2737 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002738 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002739 out:
Johannes Berg55682962007-09-20 13:09:35 -04002740 cb->args[0] = wp_idx;
2741 cb->args[1] = if_idx;
2742
Johannes Bergea90e0d2017-03-15 14:26:04 +01002743 ret = skb->len;
2744 out_unlock:
2745 rtnl_unlock();
2746
2747 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002748}
2749
2750static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2751{
2752 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002754 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002755
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002757 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002758 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002759
Eric W. Biederman15e47302012-09-07 20:12:54 +00002760 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002761 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002762 nlmsg_free(msg);
2763 return -ENOBUFS;
2764 }
Johannes Berg55682962007-09-20 13:09:35 -04002765
Johannes Berg134e6372009-07-10 09:51:34 +00002766 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002767}
2768
Michael Wu66f7ac52008-01-31 19:48:22 +01002769static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2770 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2771 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2772 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2773 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2774 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002775 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002776};
2777
2778static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2779{
2780 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2781 int flag;
2782
2783 *mntrflags = 0;
2784
2785 if (!nla)
2786 return -EINVAL;
2787
Johannes Bergfceb6432017-04-12 14:34:07 +02002788 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2789 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002790 return -EINVAL;
2791
2792 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2793 if (flags[flag])
2794 *mntrflags |= (1<<flag);
2795
Johannes Berg818a9862017-04-12 11:23:28 +02002796 *mntrflags |= MONITOR_FLAG_CHANGED;
2797
Michael Wu66f7ac52008-01-31 19:48:22 +01002798 return 0;
2799}
2800
Johannes Berg1db77592017-04-12 11:36:31 +02002801static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2802 enum nl80211_iftype type,
2803 struct genl_info *info,
2804 struct vif_params *params)
2805{
2806 bool change = false;
2807 int err;
2808
2809 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2810 if (type != NL80211_IFTYPE_MONITOR)
2811 return -EINVAL;
2812
2813 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2814 &params->flags);
2815 if (err)
2816 return err;
2817
2818 change = true;
2819 }
2820
2821 if (params->flags & MONITOR_FLAG_ACTIVE &&
2822 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2823 return -EOPNOTSUPP;
2824
2825 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2826 const u8 *mumimo_groups;
2827 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2828
2829 if (type != NL80211_IFTYPE_MONITOR)
2830 return -EINVAL;
2831
2832 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2833 return -EOPNOTSUPP;
2834
2835 mumimo_groups =
2836 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2837
2838 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002839 if ((mumimo_groups[0] & BIT(0)) ||
2840 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002841 return -EINVAL;
2842
2843 params->vht_mumimo_groups = mumimo_groups;
2844 change = true;
2845 }
2846
2847 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2848 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2849
2850 if (type != NL80211_IFTYPE_MONITOR)
2851 return -EINVAL;
2852
2853 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2854 return -EOPNOTSUPP;
2855
2856 params->vht_mumimo_follow_addr =
2857 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2858 change = true;
2859 }
2860
2861 return change ? 1 : 0;
2862}
2863
Johannes Berg9bc383d2009-11-19 11:55:19 +01002864static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002865 struct net_device *netdev, u8 use_4addr,
2866 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002867{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002868 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002869 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002870 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002871 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002872 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002873
2874 switch (iftype) {
2875 case NL80211_IFTYPE_AP_VLAN:
2876 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2877 return 0;
2878 break;
2879 case NL80211_IFTYPE_STATION:
2880 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2881 return 0;
2882 break;
2883 default:
2884 break;
2885 }
2886
2887 return -EOPNOTSUPP;
2888}
2889
Johannes Berg55682962007-09-20 13:09:35 -04002890static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2891{
Johannes Berg4c476992010-10-04 21:36:35 +02002892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002893 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002894 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002895 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002896 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002897 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002898
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002899 memset(&params, 0, sizeof(params));
2900
Johannes Berg04a773a2009-04-19 21:24:32 +02002901 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002902
Johannes Berg723b0382008-09-16 20:22:09 +02002903 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002904 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002905 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002906 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002907 if (ntype > NL80211_IFTYPE_MAX)
2908 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002909 }
2910
Johannes Berg92ffe052008-09-16 20:39:36 +02002911 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002912 struct wireless_dev *wdev = dev->ieee80211_ptr;
2913
Johannes Berg4c476992010-10-04 21:36:35 +02002914 if (ntype != NL80211_IFTYPE_MESH_POINT)
2915 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002916 if (netif_running(dev))
2917 return -EBUSY;
2918
2919 wdev_lock(wdev);
2920 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2921 IEEE80211_MAX_MESH_ID_LEN);
2922 wdev->mesh_id_up_len =
2923 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2924 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2925 wdev->mesh_id_up_len);
2926 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002927 }
2928
Felix Fietkau8b787642009-11-10 18:53:10 +01002929 if (info->attrs[NL80211_ATTR_4ADDR]) {
2930 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2931 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002932 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002933 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002934 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002935 } else {
2936 params.use_4addr = -1;
2937 }
2938
Johannes Berg1db77592017-04-12 11:36:31 +02002939 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2940 if (err < 0)
2941 return err;
2942 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002943 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002944
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002945 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002946 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002947 else
2948 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002949
Johannes Berg9bc383d2009-11-19 11:55:19 +01002950 if (!err && params.use_4addr != -1)
2951 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2952
Johannes Berg55682962007-09-20 13:09:35 -04002953 return err;
2954}
2955
2956static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2957{
Johannes Berg4c476992010-10-04 21:36:35 +02002958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002959 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002960 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002961 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002962 int err;
2963 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2964
Johannes Berg78f22b62014-03-24 17:57:27 +01002965 /* to avoid failing a new interface creation due to pending removal */
2966 cfg80211_destroy_ifaces(rdev);
2967
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002968 memset(&params, 0, sizeof(params));
2969
Johannes Berg55682962007-09-20 13:09:35 -04002970 if (!info->attrs[NL80211_ATTR_IFNAME])
2971 return -EINVAL;
2972
2973 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2974 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2975 if (type > NL80211_IFTYPE_MAX)
2976 return -EINVAL;
2977 }
2978
Johannes Berg79c97e92009-07-07 03:56:12 +02002979 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002980 !(rdev->wiphy.interface_modes & (1 << type)))
2981 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002982
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002983 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002984 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2985 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002986 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2987 ETH_ALEN);
2988 if (!is_valid_ether_addr(params.macaddr))
2989 return -EADDRNOTAVAIL;
2990 }
2991
Johannes Berg9bc383d2009-11-19 11:55:19 +01002992 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002993 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002994 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002995 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002996 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002997 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002998
Johannes Berg1db77592017-04-12 11:36:31 +02002999 err = nl80211_parse_mon_options(rdev, type, info, &params);
3000 if (err < 0)
3001 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003002
Johannes Berga18c7192015-02-24 10:56:42 +01003003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3004 if (!msg)
3005 return -ENOMEM;
3006
Hila Gonene35e4d22012-06-27 17:19:42 +03003007 wdev = rdev_add_virtual_intf(rdev,
3008 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003009 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003010 if (WARN_ON(!wdev)) {
3011 nlmsg_free(msg);
3012 return -EPROTO;
3013 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003014 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003015 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003016 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003017
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003018 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003019 wdev->owner_nlportid = info->snd_portid;
3020
Johannes Berg98104fde2012-06-16 00:19:54 +02003021 switch (type) {
3022 case NL80211_IFTYPE_MESH_POINT:
3023 if (!info->attrs[NL80211_ATTR_MESH_ID])
3024 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003025 wdev_lock(wdev);
3026 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3027 IEEE80211_MAX_MESH_ID_LEN);
3028 wdev->mesh_id_up_len =
3029 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3030 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3031 wdev->mesh_id_up_len);
3032 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003033 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003034 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003035 case NL80211_IFTYPE_P2P_DEVICE:
3036 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003037 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003038 * through the netdev notifier and must be added here
3039 */
3040 mutex_init(&wdev->mtx);
3041 INIT_LIST_HEAD(&wdev->event_list);
3042 spin_lock_init(&wdev->event_lock);
3043 INIT_LIST_HEAD(&wdev->mgmt_registrations);
3044 spin_lock_init(&wdev->mgmt_registrations_lock);
3045
Johannes Berg98104fde2012-06-16 00:19:54 +02003046 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03003047 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02003048 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02003049 break;
3050 default:
3051 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003052 }
3053
Eric W. Biederman15e47302012-09-07 20:12:54 +00003054 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003055 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003056 nlmsg_free(msg);
3057 return -ENOBUFS;
3058 }
3059
Denis Kenzior896ff062016-08-03 16:58:33 -05003060 /*
3061 * For wdevs which have no associated netdev object (e.g. of type
3062 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3063 * For all other types, the event will be generated from the
3064 * netdev notifier
3065 */
3066 if (!wdev->netdev)
3067 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003068
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003069 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003070}
3071
3072static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3073{
Johannes Berg4c476992010-10-04 21:36:35 +02003074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003075 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003076
Johannes Berg4c476992010-10-04 21:36:35 +02003077 if (!rdev->ops->del_virtual_intf)
3078 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003079
Johannes Berg84efbb82012-06-16 00:00:26 +02003080 /*
3081 * If we remove a wireless device without a netdev then clear
3082 * user_ptr[1] so that nl80211_post_doit won't dereference it
3083 * to check if it needs to do dev_put(). Otherwise it crashes
3084 * since the wdev has been freed, unlike with a netdev where
3085 * we need the dev_put() for the netdev to really be freed.
3086 */
3087 if (!wdev->netdev)
3088 info->user_ptr[1] = NULL;
3089
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003090 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003091}
3092
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003093static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3094{
3095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3096 struct net_device *dev = info->user_ptr[1];
3097 u16 noack_map;
3098
3099 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3100 return -EINVAL;
3101
3102 if (!rdev->ops->set_noack_map)
3103 return -EOPNOTSUPP;
3104
3105 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3106
Hila Gonene35e4d22012-06-27 17:19:42 +03003107 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003108}
3109
Johannes Berg41ade002007-12-19 02:03:29 +01003110struct get_key_cookie {
3111 struct sk_buff *msg;
3112 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003113 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003114};
3115
3116static void get_key_callback(void *c, struct key_params *params)
3117{
Johannes Bergb9454e82009-07-08 13:29:08 +02003118 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003119 struct get_key_cookie *cookie = c;
3120
David S. Miller9360ffd2012-03-29 04:41:26 -04003121 if ((params->key &&
3122 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3123 params->key_len, params->key)) ||
3124 (params->seq &&
3125 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3126 params->seq_len, params->seq)) ||
3127 (params->cipher &&
3128 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3129 params->cipher)))
3130 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003131
Johannes Bergb9454e82009-07-08 13:29:08 +02003132 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3133 if (!key)
3134 goto nla_put_failure;
3135
David S. Miller9360ffd2012-03-29 04:41:26 -04003136 if ((params->key &&
3137 nla_put(cookie->msg, NL80211_KEY_DATA,
3138 params->key_len, params->key)) ||
3139 (params->seq &&
3140 nla_put(cookie->msg, NL80211_KEY_SEQ,
3141 params->seq_len, params->seq)) ||
3142 (params->cipher &&
3143 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3144 params->cipher)))
3145 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003146
David S. Miller9360ffd2012-03-29 04:41:26 -04003147 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3148 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003149
3150 nla_nest_end(cookie->msg, key);
3151
Johannes Berg41ade002007-12-19 02:03:29 +01003152 return;
3153 nla_put_failure:
3154 cookie->error = 1;
3155}
3156
3157static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3158{
Johannes Berg4c476992010-10-04 21:36:35 +02003159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003160 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003161 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003162 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003163 const u8 *mac_addr = NULL;
3164 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003165 struct get_key_cookie cookie = {
3166 .error = 0,
3167 };
3168 void *hdr;
3169 struct sk_buff *msg;
3170
3171 if (info->attrs[NL80211_ATTR_KEY_IDX])
3172 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3173
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003174 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003175 return -EINVAL;
3176
3177 if (info->attrs[NL80211_ATTR_MAC])
3178 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3179
Johannes Berge31b8212010-10-05 19:39:30 +02003180 pairwise = !!mac_addr;
3181 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3182 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003183
Johannes Berge31b8212010-10-05 19:39:30 +02003184 if (kt >= NUM_NL80211_KEYTYPES)
3185 return -EINVAL;
3186 if (kt != NL80211_KEYTYPE_GROUP &&
3187 kt != NL80211_KEYTYPE_PAIRWISE)
3188 return -EINVAL;
3189 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3190 }
3191
Johannes Berg4c476992010-10-04 21:36:35 +02003192 if (!rdev->ops->get_key)
3193 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003194
Johannes Berg0fa7b392015-01-23 11:10:12 +01003195 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3196 return -ENOENT;
3197
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003199 if (!msg)
3200 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003201
Eric W. Biederman15e47302012-09-07 20:12:54 +00003202 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003203 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003204 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003205 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003206
3207 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003208 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003209
David S. Miller9360ffd2012-03-29 04:41:26 -04003210 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3211 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3212 goto nla_put_failure;
3213 if (mac_addr &&
3214 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3215 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003216
Hila Gonene35e4d22012-06-27 17:19:42 +03003217 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3218 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003219
3220 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003221 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003222
3223 if (cookie.error)
3224 goto nla_put_failure;
3225
3226 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003227 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003228
3229 nla_put_failure:
3230 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003231 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003232 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003233 return err;
3234}
3235
3236static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3237{
Johannes Berg4c476992010-10-04 21:36:35 +02003238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003239 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003240 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003241 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003242
Johannes Bergb9454e82009-07-08 13:29:08 +02003243 err = nl80211_parse_key(info, &key);
3244 if (err)
3245 return err;
3246
3247 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003248 return -EINVAL;
3249
Johannes Bergb9454e82009-07-08 13:29:08 +02003250 /* only support setting default key */
3251 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003252 return -EINVAL;
3253
Johannes Bergfffd0932009-07-08 14:22:54 +02003254 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003255
3256 if (key.def) {
3257 if (!rdev->ops->set_default_key) {
3258 err = -EOPNOTSUPP;
3259 goto out;
3260 }
3261
3262 err = nl80211_key_allowed(dev->ieee80211_ptr);
3263 if (err)
3264 goto out;
3265
Hila Gonene35e4d22012-06-27 17:19:42 +03003266 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003267 key.def_uni, key.def_multi);
3268
3269 if (err)
3270 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003271
Johannes Berg3d23e342009-09-29 23:27:28 +02003272#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003273 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003274#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003275 } else {
3276 if (key.def_uni || !key.def_multi) {
3277 err = -EINVAL;
3278 goto out;
3279 }
3280
3281 if (!rdev->ops->set_default_mgmt_key) {
3282 err = -EOPNOTSUPP;
3283 goto out;
3284 }
3285
3286 err = nl80211_key_allowed(dev->ieee80211_ptr);
3287 if (err)
3288 goto out;
3289
Hila Gonene35e4d22012-06-27 17:19:42 +03003290 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003291 if (err)
3292 goto out;
3293
3294#ifdef CONFIG_CFG80211_WEXT
3295 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3296#endif
3297 }
3298
3299 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003300 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003301
Johannes Berg41ade002007-12-19 02:03:29 +01003302 return err;
3303}
3304
3305static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3306{
Johannes Berg4c476992010-10-04 21:36:35 +02003307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003308 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003309 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003310 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003311 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003312
Johannes Bergb9454e82009-07-08 13:29:08 +02003313 err = nl80211_parse_key(info, &key);
3314 if (err)
3315 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003316
Johannes Bergb9454e82009-07-08 13:29:08 +02003317 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003318 return -EINVAL;
3319
Johannes Berg41ade002007-12-19 02:03:29 +01003320 if (info->attrs[NL80211_ATTR_MAC])
3321 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3322
Johannes Berge31b8212010-10-05 19:39:30 +02003323 if (key.type == -1) {
3324 if (mac_addr)
3325 key.type = NL80211_KEYTYPE_PAIRWISE;
3326 else
3327 key.type = NL80211_KEYTYPE_GROUP;
3328 }
3329
3330 /* for now */
3331 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3332 key.type != NL80211_KEYTYPE_GROUP)
3333 return -EINVAL;
3334
Johannes Berg4c476992010-10-04 21:36:35 +02003335 if (!rdev->ops->add_key)
3336 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003337
Johannes Berge31b8212010-10-05 19:39:30 +02003338 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3339 key.type == NL80211_KEYTYPE_PAIRWISE,
3340 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003341 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003342
3343 wdev_lock(dev->ieee80211_ptr);
3344 err = nl80211_key_allowed(dev->ieee80211_ptr);
3345 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003346 err = rdev_add_key(rdev, dev, key.idx,
3347 key.type == NL80211_KEYTYPE_PAIRWISE,
3348 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003349 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003350
Johannes Berg41ade002007-12-19 02:03:29 +01003351 return err;
3352}
3353
3354static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3355{
Johannes Berg4c476992010-10-04 21:36:35 +02003356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003357 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003358 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003359 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003360 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003361
Johannes Bergb9454e82009-07-08 13:29:08 +02003362 err = nl80211_parse_key(info, &key);
3363 if (err)
3364 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003365
3366 if (info->attrs[NL80211_ATTR_MAC])
3367 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3368
Johannes Berge31b8212010-10-05 19:39:30 +02003369 if (key.type == -1) {
3370 if (mac_addr)
3371 key.type = NL80211_KEYTYPE_PAIRWISE;
3372 else
3373 key.type = NL80211_KEYTYPE_GROUP;
3374 }
3375
3376 /* for now */
3377 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3378 key.type != NL80211_KEYTYPE_GROUP)
3379 return -EINVAL;
3380
Johannes Berg4c476992010-10-04 21:36:35 +02003381 if (!rdev->ops->del_key)
3382 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003383
Johannes Bergfffd0932009-07-08 14:22:54 +02003384 wdev_lock(dev->ieee80211_ptr);
3385 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003386
Johannes Berg0fa7b392015-01-23 11:10:12 +01003387 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003388 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3389 err = -ENOENT;
3390
Johannes Bergfffd0932009-07-08 14:22:54 +02003391 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003392 err = rdev_del_key(rdev, dev, key.idx,
3393 key.type == NL80211_KEYTYPE_PAIRWISE,
3394 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003395
Johannes Berg3d23e342009-09-29 23:27:28 +02003396#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003397 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003398 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003399 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003400 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003401 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3402 }
3403#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003404 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003405
Johannes Berg41ade002007-12-19 02:03:29 +01003406 return err;
3407}
3408
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303409/* This function returns an error or the number of nested attributes */
3410static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3411{
3412 struct nlattr *attr;
3413 int n_entries = 0, tmp;
3414
3415 nla_for_each_nested(attr, nl_attr, tmp) {
3416 if (nla_len(attr) != ETH_ALEN)
3417 return -EINVAL;
3418
3419 n_entries++;
3420 }
3421
3422 return n_entries;
3423}
3424
3425/*
3426 * This function parses ACL information and allocates memory for ACL data.
3427 * On successful return, the calling function is responsible to free the
3428 * ACL buffer returned by this function.
3429 */
3430static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3431 struct genl_info *info)
3432{
3433 enum nl80211_acl_policy acl_policy;
3434 struct nlattr *attr;
3435 struct cfg80211_acl_data *acl;
3436 int i = 0, n_entries, tmp;
3437
3438 if (!wiphy->max_acl_mac_addrs)
3439 return ERR_PTR(-EOPNOTSUPP);
3440
3441 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3442 return ERR_PTR(-EINVAL);
3443
3444 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3445 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3446 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3447 return ERR_PTR(-EINVAL);
3448
3449 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3450 return ERR_PTR(-EINVAL);
3451
3452 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3453 if (n_entries < 0)
3454 return ERR_PTR(n_entries);
3455
3456 if (n_entries > wiphy->max_acl_mac_addrs)
3457 return ERR_PTR(-ENOTSUPP);
3458
3459 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3460 GFP_KERNEL);
3461 if (!acl)
3462 return ERR_PTR(-ENOMEM);
3463
3464 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3465 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3466 i++;
3467 }
3468
3469 acl->n_acl_entries = n_entries;
3470 acl->acl_policy = acl_policy;
3471
3472 return acl;
3473}
3474
3475static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3476{
3477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3478 struct net_device *dev = info->user_ptr[1];
3479 struct cfg80211_acl_data *acl;
3480 int err;
3481
3482 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3483 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3484 return -EOPNOTSUPP;
3485
3486 if (!dev->ieee80211_ptr->beacon_interval)
3487 return -EINVAL;
3488
3489 acl = parse_acl_data(&rdev->wiphy, info);
3490 if (IS_ERR(acl))
3491 return PTR_ERR(acl);
3492
3493 err = rdev_set_mac_acl(rdev, dev, acl);
3494
3495 kfree(acl);
3496
3497 return err;
3498}
3499
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303500static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3501 u8 *rates, u8 rates_len)
3502{
3503 u8 i;
3504 u32 mask = 0;
3505
3506 for (i = 0; i < rates_len; i++) {
3507 int rate = (rates[i] & 0x7f) * 5;
3508 int ridx;
3509
3510 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3511 struct ieee80211_rate *srate =
3512 &sband->bitrates[ridx];
3513 if (rate == srate->bitrate) {
3514 mask |= 1 << ridx;
3515 break;
3516 }
3517 }
3518 if (ridx == sband->n_bitrates)
3519 return 0; /* rate not found */
3520 }
3521
3522 return mask;
3523}
3524
3525static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3526 u8 *rates, u8 rates_len,
3527 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3528{
3529 u8 i;
3530
3531 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3532
3533 for (i = 0; i < rates_len; i++) {
3534 int ridx, rbit;
3535
3536 ridx = rates[i] / 8;
3537 rbit = BIT(rates[i] % 8);
3538
3539 /* check validity */
3540 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3541 return false;
3542
3543 /* check availability */
3544 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3545 mcs[ridx] |= rbit;
3546 else
3547 return false;
3548 }
3549
3550 return true;
3551}
3552
3553static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3554{
3555 u16 mcs_mask = 0;
3556
3557 switch (vht_mcs_map) {
3558 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3559 break;
3560 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3561 mcs_mask = 0x00FF;
3562 break;
3563 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3564 mcs_mask = 0x01FF;
3565 break;
3566 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3567 mcs_mask = 0x03FF;
3568 break;
3569 default:
3570 break;
3571 }
3572
3573 return mcs_mask;
3574}
3575
3576static void vht_build_mcs_mask(u16 vht_mcs_map,
3577 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3578{
3579 u8 nss;
3580
3581 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3582 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3583 vht_mcs_map >>= 2;
3584 }
3585}
3586
3587static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3588 struct nl80211_txrate_vht *txrate,
3589 u16 mcs[NL80211_VHT_NSS_MAX])
3590{
3591 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3592 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3593 u8 i;
3594
3595 if (!sband->vht_cap.vht_supported)
3596 return false;
3597
3598 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3599
3600 /* Build vht_mcs_mask from VHT capabilities */
3601 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3602
3603 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3604 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3605 mcs[i] = txrate->mcs[i];
3606 else
3607 return false;
3608 }
3609
3610 return true;
3611}
3612
3613static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3614 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3615 .len = NL80211_MAX_SUPP_RATES },
3616 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3617 .len = NL80211_MAX_SUPP_HT_RATES },
3618 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3619 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3620};
3621
3622static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3623 struct cfg80211_bitrate_mask *mask)
3624{
3625 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3627 int rem, i;
3628 struct nlattr *tx_rates;
3629 struct ieee80211_supported_band *sband;
3630 u16 vht_tx_mcs_map;
3631
3632 memset(mask, 0, sizeof(*mask));
3633 /* Default to all rates enabled */
3634 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3635 sband = rdev->wiphy.bands[i];
3636
3637 if (!sband)
3638 continue;
3639
3640 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3641 memcpy(mask->control[i].ht_mcs,
3642 sband->ht_cap.mcs.rx_mask,
3643 sizeof(mask->control[i].ht_mcs));
3644
3645 if (!sband->vht_cap.vht_supported)
3646 continue;
3647
3648 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3649 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3650 }
3651
3652 /* if no rates are given set it back to the defaults */
3653 if (!info->attrs[NL80211_ATTR_TX_RATES])
3654 goto out;
3655
3656 /* The nested attribute uses enum nl80211_band as the index. This maps
3657 * directly to the enum nl80211_band values used in cfg80211.
3658 */
3659 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3660 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3661 enum nl80211_band band = nla_type(tx_rates);
3662 int err;
3663
3664 if (band < 0 || band >= NUM_NL80211_BANDS)
3665 return -EINVAL;
3666 sband = rdev->wiphy.bands[band];
3667 if (sband == NULL)
3668 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003669 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003670 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303671 if (err)
3672 return err;
3673 if (tb[NL80211_TXRATE_LEGACY]) {
3674 mask->control[band].legacy = rateset_to_mask(
3675 sband,
3676 nla_data(tb[NL80211_TXRATE_LEGACY]),
3677 nla_len(tb[NL80211_TXRATE_LEGACY]));
3678 if ((mask->control[band].legacy == 0) &&
3679 nla_len(tb[NL80211_TXRATE_LEGACY]))
3680 return -EINVAL;
3681 }
3682 if (tb[NL80211_TXRATE_HT]) {
3683 if (!ht_rateset_to_mask(
3684 sband,
3685 nla_data(tb[NL80211_TXRATE_HT]),
3686 nla_len(tb[NL80211_TXRATE_HT]),
3687 mask->control[band].ht_mcs))
3688 return -EINVAL;
3689 }
3690 if (tb[NL80211_TXRATE_VHT]) {
3691 if (!vht_set_mcs_mask(
3692 sband,
3693 nla_data(tb[NL80211_TXRATE_VHT]),
3694 mask->control[band].vht_mcs))
3695 return -EINVAL;
3696 }
3697 if (tb[NL80211_TXRATE_GI]) {
3698 mask->control[band].gi =
3699 nla_get_u8(tb[NL80211_TXRATE_GI]);
3700 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3701 return -EINVAL;
3702 }
3703
3704 if (mask->control[band].legacy == 0) {
3705 /* don't allow empty legacy rates if HT or VHT
3706 * are not even supported.
3707 */
3708 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3709 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3710 return -EINVAL;
3711
3712 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3713 if (mask->control[band].ht_mcs[i])
3714 goto out;
3715
3716 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3717 if (mask->control[band].vht_mcs[i])
3718 goto out;
3719
3720 /* legacy and mcs rates may not be both empty */
3721 return -EINVAL;
3722 }
3723 }
3724
3725out:
3726 return 0;
3727}
3728
Johannes Berg8564e382016-09-19 09:44:44 +02003729static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3730 enum nl80211_band band,
3731 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303732{
Johannes Berg8564e382016-09-19 09:44:44 +02003733 u32 count_ht, count_vht, i;
3734 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303735
3736 /* Allow only one rate */
3737 if (hweight32(rate) > 1)
3738 return -EINVAL;
3739
3740 count_ht = 0;
3741 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003742 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303743 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003744 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303745 count_ht++;
3746 if (count_ht > 1)
3747 return -EINVAL;
3748 }
3749 if (count_ht && rate)
3750 return -EINVAL;
3751 }
3752
3753 count_vht = 0;
3754 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003755 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303756 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003757 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303758 count_vht++;
3759 if (count_vht > 1)
3760 return -EINVAL;
3761 }
3762 if (count_vht && rate)
3763 return -EINVAL;
3764 }
3765
3766 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3767 return -EINVAL;
3768
Johannes Berg8564e382016-09-19 09:44:44 +02003769 if (rate &&
3770 !wiphy_ext_feature_isset(&rdev->wiphy,
3771 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3772 return -EINVAL;
3773 if (count_ht &&
3774 !wiphy_ext_feature_isset(&rdev->wiphy,
3775 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3776 return -EINVAL;
3777 if (count_vht &&
3778 !wiphy_ext_feature_isset(&rdev->wiphy,
3779 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3780 return -EINVAL;
3781
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303782 return 0;
3783}
3784
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003785static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003786 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003787{
Johannes Berg88600202012-02-13 15:17:18 +01003788 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003789
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003790 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3791 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3792 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3793 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003794 return -EINVAL;
3795
Johannes Berg88600202012-02-13 15:17:18 +01003796 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003797
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003798 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3799 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3800 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003801 if (!bcn->head_len)
3802 return -EINVAL;
3803 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003804 }
3805
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003806 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3807 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3808 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003809 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003810 }
3811
Johannes Berg4c476992010-10-04 21:36:35 +02003812 if (!haveinfo)
3813 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003814
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003815 if (attrs[NL80211_ATTR_IE]) {
3816 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3817 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003818 }
3819
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003820 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003821 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003822 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003823 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003824 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003825 }
3826
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003827 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003828 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003829 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003830 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003831 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003832 }
3833
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003834 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3835 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3836 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003837 }
3838
Johannes Berg88600202012-02-13 15:17:18 +01003839 return 0;
3840}
3841
Johannes Berg66cd7942017-02-07 22:40:44 +02003842static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3843 const u8 *rates)
3844{
3845 int i;
3846
3847 if (!rates)
3848 return;
3849
3850 for (i = 0; i < rates[1]; i++) {
3851 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3852 params->ht_required = true;
3853 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3854 params->vht_required = true;
3855 }
3856}
3857
3858/*
3859 * Since the nl80211 API didn't include, from the beginning, attributes about
3860 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3861 * benefit of drivers that rebuild IEs in the firmware.
3862 */
3863static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3864{
3865 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07003866 size_t ies_len = bcn->tail_len;
3867 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02003868 const u8 *rates;
3869 const u8 *cap;
3870
3871 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3872 nl80211_check_ap_rate_selectors(params, rates);
3873
3874 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3875 nl80211_check_ap_rate_selectors(params, rates);
3876
3877 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3878 if (cap && cap[1] >= sizeof(*params->ht_cap))
3879 params->ht_cap = (void *)(cap + 2);
3880 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3881 if (cap && cap[1] >= sizeof(*params->vht_cap))
3882 params->vht_cap = (void *)(cap + 2);
3883}
3884
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003885static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3886 struct cfg80211_ap_settings *params)
3887{
3888 struct wireless_dev *wdev;
3889 bool ret = false;
3890
Johannes Berg53873f12016-05-03 16:52:04 +03003891 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003892 if (wdev->iftype != NL80211_IFTYPE_AP &&
3893 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3894 continue;
3895
Johannes Berg683b6d32012-11-08 21:25:48 +01003896 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003897 continue;
3898
Johannes Berg683b6d32012-11-08 21:25:48 +01003899 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003900 ret = true;
3901 break;
3902 }
3903
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003904 return ret;
3905}
3906
Jouni Malinene39e5b52012-09-30 19:29:39 +03003907static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3908 enum nl80211_auth_type auth_type,
3909 enum nl80211_commands cmd)
3910{
3911 if (auth_type > NL80211_AUTHTYPE_MAX)
3912 return false;
3913
3914 switch (cmd) {
3915 case NL80211_CMD_AUTHENTICATE:
3916 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3917 auth_type == NL80211_AUTHTYPE_SAE)
3918 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003919 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3920 NL80211_EXT_FEATURE_FILS_STA) &&
3921 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3922 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3923 auth_type == NL80211_AUTHTYPE_FILS_PK))
3924 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003925 return true;
3926 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02003927 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3928 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003929 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02003930
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003931 /* FILS with SK PFS or PK not supported yet */
3932 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3933 auth_type == NL80211_AUTHTYPE_FILS_PK)
3934 return false;
3935 if (!wiphy_ext_feature_isset(
3936 &rdev->wiphy,
3937 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3938 auth_type == NL80211_AUTHTYPE_FILS_SK)
3939 return false;
3940 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003941 case NL80211_CMD_START_AP:
3942 /* SAE not supported yet */
3943 if (auth_type == NL80211_AUTHTYPE_SAE)
3944 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003945 /* FILS not supported yet */
3946 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3947 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3948 auth_type == NL80211_AUTHTYPE_FILS_PK)
3949 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003950 return true;
3951 default:
3952 return false;
3953 }
3954}
3955
Johannes Berg88600202012-02-13 15:17:18 +01003956static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3957{
3958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3959 struct net_device *dev = info->user_ptr[1];
3960 struct wireless_dev *wdev = dev->ieee80211_ptr;
3961 struct cfg80211_ap_settings params;
3962 int err;
3963
3964 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3965 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3966 return -EOPNOTSUPP;
3967
3968 if (!rdev->ops->start_ap)
3969 return -EOPNOTSUPP;
3970
3971 if (wdev->beacon_interval)
3972 return -EALREADY;
3973
3974 memset(&params, 0, sizeof(params));
3975
3976 /* these are required for START_AP */
3977 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3978 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3979 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3980 return -EINVAL;
3981
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003982 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003983 if (err)
3984 return err;
3985
3986 params.beacon_interval =
3987 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3988 params.dtim_period =
3989 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3990
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303991 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3992 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003993 if (err)
3994 return err;
3995
3996 /*
3997 * In theory, some of these attributes should be required here
3998 * but since they were not used when the command was originally
3999 * added, keep them optional for old user space programs to let
4000 * them continue to work with drivers that do not need the
4001 * additional information -- drivers must check!
4002 */
4003 if (info->attrs[NL80211_ATTR_SSID]) {
4004 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4005 params.ssid_len =
4006 nla_len(info->attrs[NL80211_ATTR_SSID]);
4007 if (params.ssid_len == 0 ||
4008 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4009 return -EINVAL;
4010 }
4011
4012 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
4013 params.hidden_ssid = nla_get_u32(
4014 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4015 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
4016 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
4017 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
4018 return -EINVAL;
4019 }
4020
4021 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4022
4023 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4024 params.auth_type = nla_get_u32(
4025 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004026 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4027 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004028 return -EINVAL;
4029 } else
4030 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4031
4032 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4033 NL80211_MAX_NR_CIPHER_SUITES);
4034 if (err)
4035 return err;
4036
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304037 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4038 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4039 return -EOPNOTSUPP;
4040 params.inactivity_timeout = nla_get_u16(
4041 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4042 }
4043
Johannes Berg53cabad2012-11-14 15:17:28 +01004044 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4045 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4046 return -EINVAL;
4047 params.p2p_ctwindow =
4048 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4049 if (params.p2p_ctwindow > 127)
4050 return -EINVAL;
4051 if (params.p2p_ctwindow != 0 &&
4052 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4053 return -EINVAL;
4054 }
4055
4056 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4057 u8 tmp;
4058
4059 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4060 return -EINVAL;
4061 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4062 if (tmp > 1)
4063 return -EINVAL;
4064 params.p2p_opp_ps = tmp;
4065 if (params.p2p_opp_ps != 0 &&
4066 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4067 return -EINVAL;
4068 }
4069
Johannes Bergaa430da2012-05-16 23:50:18 +02004070 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004071 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4072 if (err)
4073 return err;
4074 } else if (wdev->preset_chandef.chan) {
4075 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004076 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004077 return -EINVAL;
4078
Arik Nemtsov923b3522015-07-08 15:41:44 +03004079 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4080 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004081 return -EINVAL;
4082
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304083 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4084 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4085 if (err)
4086 return err;
4087
Johannes Berg8564e382016-09-19 09:44:44 +02004088 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4089 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304090 if (err)
4091 return err;
4092 }
4093
Eliad Peller18998c32014-09-10 14:07:34 +03004094 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4095 params.smps_mode =
4096 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4097 switch (params.smps_mode) {
4098 case NL80211_SMPS_OFF:
4099 break;
4100 case NL80211_SMPS_STATIC:
4101 if (!(rdev->wiphy.features &
4102 NL80211_FEATURE_STATIC_SMPS))
4103 return -EINVAL;
4104 break;
4105 case NL80211_SMPS_DYNAMIC:
4106 if (!(rdev->wiphy.features &
4107 NL80211_FEATURE_DYNAMIC_SMPS))
4108 return -EINVAL;
4109 break;
4110 default:
4111 return -EINVAL;
4112 }
4113 } else {
4114 params.smps_mode = NL80211_SMPS_OFF;
4115 }
4116
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304117 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4118 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4119 return -EOPNOTSUPP;
4120
Ola Olsson4baf6be2015-10-29 07:04:58 +01004121 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4122 params.acl = parse_acl_data(&rdev->wiphy, info);
4123 if (IS_ERR(params.acl))
4124 return PTR_ERR(params.acl);
4125 }
4126
Johannes Berg66cd7942017-02-07 22:40:44 +02004127 nl80211_calculate_ap_params(&params);
4128
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004129 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004130 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004131 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004132 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004133 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004134 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004135 wdev->ssid_len = params.ssid_len;
4136 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004137 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004138 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304139
4140 kfree(params.acl);
4141
Johannes Berg56d18932011-05-09 18:41:15 +02004142 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004143}
4144
Johannes Berg88600202012-02-13 15:17:18 +01004145static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4146{
4147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4148 struct net_device *dev = info->user_ptr[1];
4149 struct wireless_dev *wdev = dev->ieee80211_ptr;
4150 struct cfg80211_beacon_data params;
4151 int err;
4152
4153 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4154 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4155 return -EOPNOTSUPP;
4156
4157 if (!rdev->ops->change_beacon)
4158 return -EOPNOTSUPP;
4159
4160 if (!wdev->beacon_interval)
4161 return -EINVAL;
4162
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004163 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004164 if (err)
4165 return err;
4166
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004167 wdev_lock(wdev);
4168 err = rdev_change_beacon(rdev, dev, &params);
4169 wdev_unlock(wdev);
4170
4171 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004172}
4173
4174static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004175{
Johannes Berg4c476992010-10-04 21:36:35 +02004176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4177 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004178
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004179 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004180}
4181
Johannes Berg5727ef12007-12-19 02:03:34 +01004182static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4183 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4184 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4185 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004186 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004187 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004188 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004189};
4190
Johannes Bergeccb8e82009-05-11 21:57:56 +03004191static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004192 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004194{
4195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004197 int flag;
4198
Johannes Bergeccb8e82009-05-11 21:57:56 +03004199 /*
4200 * Try parsing the new attribute first so userspace
4201 * can specify both for older kernels.
4202 */
4203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4204 if (nla) {
4205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004206
Johannes Bergeccb8e82009-05-11 21:57:56 +03004207 sta_flags = nla_data(nla);
4208 params->sta_flags_mask = sta_flags->mask;
4209 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004210 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004211 if ((params->sta_flags_mask |
4212 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4213 return -EINVAL;
4214 return 0;
4215 }
4216
4217 /* if present, parse the old attribute */
4218
4219 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004220 if (!nla)
4221 return 0;
4222
Johannes Bergfceb6432017-04-12 14:34:07 +02004223 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004224 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 return -EINVAL;
4226
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004227 /*
4228 * Only allow certain flags for interface types so that
4229 * other attributes are silently ignored. Remember that
4230 * this is backward compatibility code with old userspace
4231 * and shouldn't be hit in other cases anyway.
4232 */
4233 switch (iftype) {
4234 case NL80211_IFTYPE_AP:
4235 case NL80211_IFTYPE_AP_VLAN:
4236 case NL80211_IFTYPE_P2P_GO:
4237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4238 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4239 BIT(NL80211_STA_FLAG_WME) |
4240 BIT(NL80211_STA_FLAG_MFP);
4241 break;
4242 case NL80211_IFTYPE_P2P_CLIENT:
4243 case NL80211_IFTYPE_STATION:
4244 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4245 BIT(NL80211_STA_FLAG_TDLS_PEER);
4246 break;
4247 case NL80211_IFTYPE_MESH_POINT:
4248 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4249 BIT(NL80211_STA_FLAG_MFP) |
4250 BIT(NL80211_STA_FLAG_AUTHORIZED);
4251 default:
4252 return -EINVAL;
4253 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004254
Johannes Berg3383b5a2012-05-10 20:14:43 +02004255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4256 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004258
Johannes Berg3383b5a2012-05-10 20:14:43 +02004259 /* no longer support new API additions in old API */
4260 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4261 return -EINVAL;
4262 }
4263 }
4264
Johannes Berg5727ef12007-12-19 02:03:34 +01004265 return 0;
4266}
4267
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004268static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4269 int attr)
4270{
4271 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004272 u32 bitrate;
4273 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004274 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004275
4276 rate = nla_nest_start(msg, attr);
4277 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004278 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004279
4280 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4281 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004282 /* report 16-bit bitrate only if we can */
4283 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004284 if (bitrate > 0 &&
4285 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4286 return false;
4287 if (bitrate_compat > 0 &&
4288 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4289 return false;
4290
Johannes Bergb51f3be2015-01-15 16:14:02 +01004291 switch (info->bw) {
4292 case RATE_INFO_BW_5:
4293 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4294 break;
4295 case RATE_INFO_BW_10:
4296 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4297 break;
4298 default:
4299 WARN_ON(1);
4300 /* fall through */
4301 case RATE_INFO_BW_20:
4302 rate_flg = 0;
4303 break;
4304 case RATE_INFO_BW_40:
4305 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4306 break;
4307 case RATE_INFO_BW_80:
4308 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4309 break;
4310 case RATE_INFO_BW_160:
4311 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4312 break;
4313 }
4314
4315 if (rate_flg && nla_put_flag(msg, rate_flg))
4316 return false;
4317
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004318 if (info->flags & RATE_INFO_FLAGS_MCS) {
4319 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4320 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004321 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4322 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4323 return false;
4324 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4325 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4326 return false;
4327 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4328 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004329 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4330 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4331 return false;
4332 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004333
4334 nla_nest_end(msg, rate);
4335 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004336}
4337
Felix Fietkau119363c2013-04-22 16:29:30 +02004338static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4339 int id)
4340{
4341 void *attr;
4342 int i = 0;
4343
4344 if (!mask)
4345 return true;
4346
4347 attr = nla_nest_start(msg, id);
4348 if (!attr)
4349 return false;
4350
4351 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4352 if (!(mask & BIT(i)))
4353 continue;
4354
4355 if (nla_put_u8(msg, i, signal[i]))
4356 return false;
4357 }
4358
4359 nla_nest_end(msg, attr);
4360
4361 return true;
4362}
4363
Johannes Bergcf5ead82014-11-14 17:14:00 +01004364static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4365 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004366 struct cfg80211_registered_device *rdev,
4367 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004368 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004369{
4370 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004371 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004372
Johannes Bergcf5ead82014-11-14 17:14:00 +01004373 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004374 if (!hdr)
4375 return -1;
4376
David S. Miller9360ffd2012-03-29 04:41:26 -04004377 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4378 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4379 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4380 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004381
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004382 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4383 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004384 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004385
4386#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004387 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304388 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004389 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4390 sinfo->memb)) \
4391 goto nla_put_failure; \
4392 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004393#define PUT_SINFO_U64(attr, memb) do { \
4394 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4395 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4396 sinfo->memb, NL80211_STA_INFO_PAD)) \
4397 goto nla_put_failure; \
4398 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004399
4400 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4401 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4402
4403 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4404 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004405 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004406 (u32)sinfo->rx_bytes))
4407 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004408
4409 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4410 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004411 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4412 (u32)sinfo->tx_bytes))
4413 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004414
Johannes Bergd686b922016-04-26 09:54:11 +02004415 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4416 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004417 PUT_SINFO(LLID, llid, u16);
4418 PUT_SINFO(PLID, plid, u16);
4419 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004420 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004421
John W. Linville66266b32012-03-15 13:25:41 -04004422 switch (rdev->wiphy.signal_type) {
4423 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004424 PUT_SINFO(SIGNAL, signal, u8);
4425 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004426 break;
4427 default:
4428 break;
4429 }
Johannes Berg319090b2014-11-17 14:08:11 +01004430 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004431 if (!nl80211_put_signal(msg, sinfo->chains,
4432 sinfo->chain_signal,
4433 NL80211_STA_INFO_CHAIN_SIGNAL))
4434 goto nla_put_failure;
4435 }
Johannes Berg319090b2014-11-17 14:08:11 +01004436 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004437 if (!nl80211_put_signal(msg, sinfo->chains,
4438 sinfo->chain_signal_avg,
4439 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4440 goto nla_put_failure;
4441 }
Johannes Berg319090b2014-11-17 14:08:11 +01004442 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004443 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4444 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004445 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004446 }
Johannes Berg319090b2014-11-17 14:08:11 +01004447 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004448 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4449 NL80211_STA_INFO_RX_BITRATE))
4450 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004451 }
Johannes Berg319090b2014-11-17 14:08:11 +01004452
4453 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4454 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4455 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4456 PUT_SINFO(TX_FAILED, tx_failed, u32);
4457 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4458 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4459 PUT_SINFO(LOCAL_PM, local_pm, u32);
4460 PUT_SINFO(PEER_PM, peer_pm, u32);
4461 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4462
4463 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004464 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4465 if (!bss_param)
4466 goto nla_put_failure;
4467
David S. Miller9360ffd2012-03-29 04:41:26 -04004468 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4469 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4470 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4471 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4472 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4473 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4474 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4475 sinfo->bss_param.dtim_period) ||
4476 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4477 sinfo->bss_param.beacon_interval))
4478 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004479
4480 nla_nest_end(msg, bss_param);
4481 }
Johannes Berg319090b2014-11-17 14:08:11 +01004482 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004483 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4484 sizeof(struct nl80211_sta_flag_update),
4485 &sinfo->sta_flags))
4486 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004487
Johannes Bergd686b922016-04-26 09:54:11 +02004488 PUT_SINFO_U64(T_OFFSET, t_offset);
4489 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4490 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004491 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +05304492 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004493
4494#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004495#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004496
4497 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4498 struct nlattr *tidsattr;
4499 int tid;
4500
4501 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4502 if (!tidsattr)
4503 goto nla_put_failure;
4504
4505 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4506 struct cfg80211_tid_stats *tidstats;
4507 struct nlattr *tidattr;
4508
4509 tidstats = &sinfo->pertid[tid];
4510
4511 if (!tidstats->filled)
4512 continue;
4513
4514 tidattr = nla_nest_start(msg, tid + 1);
4515 if (!tidattr)
4516 goto nla_put_failure;
4517
Johannes Bergd686b922016-04-26 09:54:11 +02004518#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004519 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004520 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4521 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004522 goto nla_put_failure; \
4523 } while (0)
4524
Johannes Bergd686b922016-04-26 09:54:11 +02004525 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4526 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4527 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4528 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004529
Johannes Bergd686b922016-04-26 09:54:11 +02004530#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004531 nla_nest_end(msg, tidattr);
4532 }
4533
4534 nla_nest_end(msg, tidsattr);
4535 }
4536
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004537 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004538
Johannes Berg319090b2014-11-17 14:08:11 +01004539 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004540 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4541 sinfo->assoc_req_ies))
4542 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004543
Johannes Berg053c0952015-01-16 22:09:00 +01004544 genlmsg_end(msg, hdr);
4545 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004546
4547 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004548 genlmsg_cancel(msg, hdr);
4549 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004550}
4551
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004552static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004553 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004554{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004555 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004556 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004557 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004558 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004559 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004560 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004561
Johannes Bergea90e0d2017-03-15 14:26:04 +01004562 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004563 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004564 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004565 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004566
Johannes Berg97990a02013-04-19 01:02:55 +02004567 if (!wdev->netdev) {
4568 err = -EINVAL;
4569 goto out_err;
4570 }
4571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004572 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004573 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004574 goto out_err;
4575 }
4576
Johannes Bergbba95fe2008-07-29 13:22:51 +02004577 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004578 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004579 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004580 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004581 if (err == -ENOENT)
4582 break;
4583 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004584 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004585
Johannes Bergcf5ead82014-11-14 17:14:00 +01004586 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004587 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004588 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004589 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004590 &sinfo) < 0)
4591 goto out;
4592
4593 sta_idx++;
4594 }
4595
Johannes Bergbba95fe2008-07-29 13:22:51 +02004596 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004597 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004598 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004599 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004600 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004601
4602 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004603}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004604
Johannes Berg5727ef12007-12-19 02:03:34 +01004605static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4606{
Johannes Berg4c476992010-10-04 21:36:35 +02004607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4608 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004609 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004610 struct sk_buff *msg;
4611 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004612 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004613
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004614 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004615
4616 if (!info->attrs[NL80211_ATTR_MAC])
4617 return -EINVAL;
4618
4619 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4620
Johannes Berg4c476992010-10-04 21:36:35 +02004621 if (!rdev->ops->get_station)
4622 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004623
Hila Gonene35e4d22012-06-27 17:19:42 +03004624 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004625 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004626 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004627
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004628 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004629 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004630 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004631
Johannes Bergcf5ead82014-11-14 17:14:00 +01004632 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4633 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004634 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004635 nlmsg_free(msg);
4636 return -ENOBUFS;
4637 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004638
Johannes Berg4c476992010-10-04 21:36:35 +02004639 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004640}
4641
Johannes Berg77ee7c82013-02-15 00:48:33 +01004642int cfg80211_check_station_change(struct wiphy *wiphy,
4643 struct station_parameters *params,
4644 enum cfg80211_station_type statype)
4645{
Ayala Bekere4208422015-10-23 11:20:06 +03004646 if (params->listen_interval != -1 &&
4647 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004648 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004649
Ayala Beker17b94242016-03-17 15:41:38 +02004650 if (params->support_p2p_ps != -1 &&
4651 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4652 return -EINVAL;
4653
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004654 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004655 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4656 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004657 return -EINVAL;
4658
4659 /* When you run into this, adjust the code below for the new flag */
4660 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4661
4662 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004663 case CFG80211_STA_MESH_PEER_KERNEL:
4664 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004665 /*
4666 * No ignoring the TDLS flag here -- the userspace mesh
4667 * code doesn't have the bug of including TDLS in the
4668 * mask everywhere.
4669 */
4670 if (params->sta_flags_mask &
4671 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4672 BIT(NL80211_STA_FLAG_MFP) |
4673 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4674 return -EINVAL;
4675 break;
4676 case CFG80211_STA_TDLS_PEER_SETUP:
4677 case CFG80211_STA_TDLS_PEER_ACTIVE:
4678 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4679 return -EINVAL;
4680 /* ignore since it can't change */
4681 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4682 break;
4683 default:
4684 /* disallow mesh-specific things */
4685 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4686 return -EINVAL;
4687 if (params->local_pm)
4688 return -EINVAL;
4689 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4690 return -EINVAL;
4691 }
4692
4693 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4694 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4695 /* TDLS can't be set, ... */
4696 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4697 return -EINVAL;
4698 /*
4699 * ... but don't bother the driver with it. This works around
4700 * a hostapd/wpa_supplicant issue -- it always includes the
4701 * TLDS_PEER flag in the mask even for AP mode.
4702 */
4703 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4704 }
4705
Ayala Beker47edb112015-09-21 15:49:53 +03004706 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4707 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004708 /* reject other things that can't change */
4709 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4710 return -EINVAL;
4711 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4712 return -EINVAL;
4713 if (params->supported_rates)
4714 return -EINVAL;
4715 if (params->ext_capab || params->ht_capa || params->vht_capa)
4716 return -EINVAL;
4717 }
4718
Ayala Beker47edb112015-09-21 15:49:53 +03004719 if (statype != CFG80211_STA_AP_CLIENT &&
4720 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004721 if (params->vlan)
4722 return -EINVAL;
4723 }
4724
4725 switch (statype) {
4726 case CFG80211_STA_AP_MLME_CLIENT:
4727 /* Use this only for authorizing/unauthorizing a station */
4728 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4729 return -EOPNOTSUPP;
4730 break;
4731 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004732 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004733 /* accept only the listed bits */
4734 if (params->sta_flags_mask &
4735 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4736 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4737 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4738 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4739 BIT(NL80211_STA_FLAG_WME) |
4740 BIT(NL80211_STA_FLAG_MFP)))
4741 return -EINVAL;
4742
4743 /* but authenticated/associated only if driver handles it */
4744 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4745 params->sta_flags_mask &
4746 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4747 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4748 return -EINVAL;
4749 break;
4750 case CFG80211_STA_IBSS:
4751 case CFG80211_STA_AP_STA:
4752 /* reject any changes other than AUTHORIZED */
4753 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4754 return -EINVAL;
4755 break;
4756 case CFG80211_STA_TDLS_PEER_SETUP:
4757 /* reject any changes other than AUTHORIZED or WME */
4758 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4759 BIT(NL80211_STA_FLAG_WME)))
4760 return -EINVAL;
4761 /* force (at least) rates when authorizing */
4762 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4763 !params->supported_rates)
4764 return -EINVAL;
4765 break;
4766 case CFG80211_STA_TDLS_PEER_ACTIVE:
4767 /* reject any changes */
4768 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004769 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004770 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4771 return -EINVAL;
4772 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004773 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004774 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4775 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004776 return -EINVAL;
4777 break;
4778 }
4779
Beni Lev06f7c882016-07-19 19:28:56 +03004780 /*
4781 * Older kernel versions ignored this attribute entirely, so don't
4782 * reject attempts to update it but mark it as unused instead so the
4783 * driver won't look at the data.
4784 */
4785 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4786 statype != CFG80211_STA_TDLS_PEER_SETUP)
4787 params->opmode_notif_used = false;
4788
Johannes Berg77ee7c82013-02-15 00:48:33 +01004789 return 0;
4790}
4791EXPORT_SYMBOL(cfg80211_check_station_change);
4792
Johannes Berg5727ef12007-12-19 02:03:34 +01004793/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004794 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004795 */
Johannes Berg80b99892011-11-18 16:23:01 +01004796static struct net_device *get_vlan(struct genl_info *info,
4797 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004798{
Johannes Berg463d0182009-07-14 00:33:35 +02004799 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004800 struct net_device *v;
4801 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004802
Johannes Berg80b99892011-11-18 16:23:01 +01004803 if (!vlanattr)
4804 return NULL;
4805
4806 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4807 if (!v)
4808 return ERR_PTR(-ENODEV);
4809
4810 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4811 ret = -EINVAL;
4812 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004813 }
Johannes Berg80b99892011-11-18 16:23:01 +01004814
Johannes Berg77ee7c82013-02-15 00:48:33 +01004815 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4816 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4817 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4818 ret = -EINVAL;
4819 goto error;
4820 }
4821
Johannes Berg80b99892011-11-18 16:23:01 +01004822 if (!netif_running(v)) {
4823 ret = -ENETDOWN;
4824 goto error;
4825 }
4826
4827 return v;
4828 error:
4829 dev_put(v);
4830 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004831}
4832
Johannes Berg94e860f2014-01-20 23:58:15 +01004833static const struct nla_policy
4834nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004835 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4836 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4837};
4838
Johannes Bergff276692013-02-15 00:09:01 +01004839static int nl80211_parse_sta_wme(struct genl_info *info,
4840 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004841{
Jouni Malinendf881292013-02-14 21:10:54 +02004842 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4843 struct nlattr *nla;
4844 int err;
4845
Jouni Malinendf881292013-02-14 21:10:54 +02004846 /* parse WME attributes if present */
4847 if (!info->attrs[NL80211_ATTR_STA_WME])
4848 return 0;
4849
4850 nla = info->attrs[NL80211_ATTR_STA_WME];
4851 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004852 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004853 if (err)
4854 return err;
4855
4856 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4857 params->uapsd_queues = nla_get_u8(
4858 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4859 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4860 return -EINVAL;
4861
4862 if (tb[NL80211_STA_WME_MAX_SP])
4863 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4864
4865 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4866 return -EINVAL;
4867
4868 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4869
4870 return 0;
4871}
4872
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304873static int nl80211_parse_sta_channel_info(struct genl_info *info,
4874 struct station_parameters *params)
4875{
4876 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4877 params->supported_channels =
4878 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4879 params->supported_channels_len =
4880 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4881 /*
4882 * Need to include at least one (first channel, number of
4883 * channels) tuple for each subband, and must have proper
4884 * tuples for the rest of the data as well.
4885 */
4886 if (params->supported_channels_len < 2)
4887 return -EINVAL;
4888 if (params->supported_channels_len % 2)
4889 return -EINVAL;
4890 }
4891
4892 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4893 params->supported_oper_classes =
4894 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4895 params->supported_oper_classes_len =
4896 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4897 /*
4898 * The value of the Length field of the Supported Operating
4899 * Classes element is between 2 and 253.
4900 */
4901 if (params->supported_oper_classes_len < 2 ||
4902 params->supported_oper_classes_len > 253)
4903 return -EINVAL;
4904 }
4905 return 0;
4906}
4907
Johannes Bergff276692013-02-15 00:09:01 +01004908static int nl80211_set_station_tdls(struct genl_info *info,
4909 struct station_parameters *params)
4910{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304911 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004912 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004913 if (info->attrs[NL80211_ATTR_PEER_AID])
4914 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004915 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4916 params->ht_capa =
4917 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4918 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4919 params->vht_capa =
4920 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4921
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304922 err = nl80211_parse_sta_channel_info(info, params);
4923 if (err)
4924 return err;
4925
Johannes Bergff276692013-02-15 00:09:01 +01004926 return nl80211_parse_sta_wme(info, params);
4927}
4928
Johannes Berg5727ef12007-12-19 02:03:34 +01004929static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4930{
Johannes Berg4c476992010-10-04 21:36:35 +02004931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004932 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004933 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004934 u8 *mac_addr;
4935 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004936
4937 memset(&params, 0, sizeof(params));
4938
Johannes Berg77ee7c82013-02-15 00:48:33 +01004939 if (!rdev->ops->change_station)
4940 return -EOPNOTSUPP;
4941
Ayala Bekere4208422015-10-23 11:20:06 +03004942 /*
4943 * AID and listen_interval properties can be set only for unassociated
4944 * station. Include these parameters here and will check them in
4945 * cfg80211_check_station_change().
4946 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004947 if (info->attrs[NL80211_ATTR_STA_AID])
4948 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004949
4950 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4951 params.listen_interval =
4952 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4953 else
4954 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004955
Ayala Beker17b94242016-03-17 15:41:38 +02004956 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4957 u8 tmp;
4958
4959 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4960 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4961 return -EINVAL;
4962
4963 params.support_p2p_ps = tmp;
4964 } else {
4965 params.support_p2p_ps = -1;
4966 }
4967
Johannes Berg5727ef12007-12-19 02:03:34 +01004968 if (!info->attrs[NL80211_ATTR_MAC])
4969 return -EINVAL;
4970
4971 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4972
4973 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4974 params.supported_rates =
4975 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4976 params.supported_rates_len =
4977 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4978 }
4979
Jouni Malinen9d62a982013-02-14 21:10:13 +02004980 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4981 params.capability =
4982 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4983 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4984 }
4985
4986 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4987 params.ext_capab =
4988 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4989 params.ext_capab_len =
4990 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4991 }
4992
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004993 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004994 return -EINVAL;
4995
Johannes Bergf8bacc22013-02-14 23:27:01 +01004996 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004997 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004998 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4999 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5000 return -EINVAL;
5001 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005002
Johannes Bergf8bacc22013-02-14 23:27:01 +01005003 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005004 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005005 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
5006 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
5007 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005008 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
5009 params.peer_aid = nla_get_u16(
5010 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
5011 if (params.peer_aid > IEEE80211_MAX_AID)
5012 return -EINVAL;
5013 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01005014 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5015 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005016
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005017 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
5018 enum nl80211_mesh_power_mode pm = nla_get_u32(
5019 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5020
5021 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
5022 pm > NL80211_MESH_POWER_MAX)
5023 return -EINVAL;
5024
5025 params.local_pm = pm;
5026 }
5027
Beni Lev06f7c882016-07-19 19:28:56 +03005028 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5029 params.opmode_notif_used = true;
5030 params.opmode_notif =
5031 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5032 }
5033
Johannes Berg77ee7c82013-02-15 00:48:33 +01005034 /* Include parameters for TDLS peer (will check later) */
5035 err = nl80211_set_station_tdls(info, &params);
5036 if (err)
5037 return err;
5038
5039 params.vlan = get_vlan(info, rdev);
5040 if (IS_ERR(params.vlan))
5041 return PTR_ERR(params.vlan);
5042
Johannes Berga97f4422009-06-18 17:23:43 +02005043 switch (dev->ieee80211_ptr->iftype) {
5044 case NL80211_IFTYPE_AP:
5045 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005046 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005047 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005048 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005049 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005050 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005051 break;
5052 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005053 err = -EOPNOTSUPP;
5054 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005055 }
5056
Johannes Berg77ee7c82013-02-15 00:48:33 +01005057 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005058 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005059
Johannes Berg77ee7c82013-02-15 00:48:33 +01005060 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005061 if (params.vlan)
5062 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005063
Johannes Berg5727ef12007-12-19 02:03:34 +01005064 return err;
5065}
5066
5067static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5068{
Johannes Berg4c476992010-10-04 21:36:35 +02005069 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005070 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005071 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005072 struct station_parameters params;
5073 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005074 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5075 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005076
5077 memset(&params, 0, sizeof(params));
5078
Johannes Berg984c3112013-02-14 23:43:25 +01005079 if (!rdev->ops->add_station)
5080 return -EOPNOTSUPP;
5081
Johannes Berg5727ef12007-12-19 02:03:34 +01005082 if (!info->attrs[NL80211_ATTR_MAC])
5083 return -EINVAL;
5084
Johannes Berg5727ef12007-12-19 02:03:34 +01005085 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5086 return -EINVAL;
5087
5088 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5089 return -EINVAL;
5090
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005091 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5092 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005093 return -EINVAL;
5094
Johannes Berg5727ef12007-12-19 02:03:34 +01005095 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5096 params.supported_rates =
5097 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5098 params.supported_rates_len =
5099 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5100 params.listen_interval =
5101 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005102
Ayala Beker17b94242016-03-17 15:41:38 +02005103 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5104 u8 tmp;
5105
5106 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5107 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5108 return -EINVAL;
5109
5110 params.support_p2p_ps = tmp;
5111 } else {
5112 /*
5113 * if not specified, assume it's supported for P2P GO interface,
5114 * and is NOT supported for AP interface
5115 */
5116 params.support_p2p_ps =
5117 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5118 }
5119
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005120 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005121 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005122 else
5123 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005124 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5125 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005126
Jouni Malinen9d62a982013-02-14 21:10:13 +02005127 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5128 params.capability =
5129 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5130 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5131 }
5132
5133 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5134 params.ext_capab =
5135 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5136 params.ext_capab_len =
5137 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5138 }
5139
Jouni Malinen36aedc92008-08-25 11:58:58 +03005140 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5141 params.ht_capa =
5142 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005143
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005144 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5145 params.vht_capa =
5146 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5147
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005148 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5149 params.opmode_notif_used = true;
5150 params.opmode_notif =
5151 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5152 }
5153
Johannes Bergf8bacc22013-02-14 23:27:01 +01005154 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005155 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005156 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5157 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5158 return -EINVAL;
5159 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005160
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305161 err = nl80211_parse_sta_channel_info(info, &params);
5162 if (err)
5163 return err;
5164
Johannes Bergff276692013-02-15 00:09:01 +01005165 err = nl80211_parse_sta_wme(info, &params);
5166 if (err)
5167 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005168
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005169 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005170 return -EINVAL;
5171
Johannes Berg496fcc22015-03-12 08:53:27 +02005172 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5173 * as userspace might just pass through the capabilities from the IEs
5174 * directly, rather than enforcing this restriction and returning an
5175 * error in this case.
5176 */
5177 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5178 params.ht_capa = NULL;
5179 params.vht_capa = NULL;
5180 }
5181
Johannes Berg77ee7c82013-02-15 00:48:33 +01005182 /* When you run into this, adjust the code below for the new flag */
5183 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5184
Johannes Bergbdd90d52011-12-14 12:20:27 +01005185 switch (dev->ieee80211_ptr->iftype) {
5186 case NL80211_IFTYPE_AP:
5187 case NL80211_IFTYPE_AP_VLAN:
5188 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005189 /* ignore WME attributes if iface/sta is not capable */
5190 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5191 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5192 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005193
Johannes Bergbdd90d52011-12-14 12:20:27 +01005194 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005195 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5196 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005197 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005198 /* but don't bother the driver with it */
5199 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005200
Johannes Bergd582cff2012-10-26 17:53:44 +02005201 /* allow authenticated/associated only if driver handles it */
5202 if (!(rdev->wiphy.features &
5203 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005204 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005205 return -EINVAL;
5206
Johannes Bergbda95eb2015-11-26 16:26:13 +01005207 /* Older userspace, or userspace wanting to be compatible with
5208 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5209 * and assoc flags in the mask, but assumes the station will be
5210 * added as associated anyway since this was the required driver
5211 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5212 * introduced.
5213 * In order to not bother drivers with this quirk in the API
5214 * set the flags in both the mask and set for new stations in
5215 * this case.
5216 */
5217 if (!(params.sta_flags_mask & auth_assoc)) {
5218 params.sta_flags_mask |= auth_assoc;
5219 params.sta_flags_set |= auth_assoc;
5220 }
5221
Johannes Bergbdd90d52011-12-14 12:20:27 +01005222 /* must be last in here for error handling */
5223 params.vlan = get_vlan(info, rdev);
5224 if (IS_ERR(params.vlan))
5225 return PTR_ERR(params.vlan);
5226 break;
5227 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005228 /* ignore uAPSD data */
5229 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5230
Johannes Bergd582cff2012-10-26 17:53:44 +02005231 /* associated is disallowed */
5232 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5233 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005234 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005235 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5236 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005237 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005238 break;
5239 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005240 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005241 /* ignore uAPSD data */
5242 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5243
Johannes Berg77ee7c82013-02-15 00:48:33 +01005244 /* these are disallowed */
5245 if (params.sta_flags_mask &
5246 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5247 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005248 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005249 /* Only TDLS peers can be added */
5250 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5251 return -EINVAL;
5252 /* Can only add if TDLS ... */
5253 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5254 return -EOPNOTSUPP;
5255 /* ... with external setup is supported */
5256 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5257 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005258 /*
5259 * Older wpa_supplicant versions always mark the TDLS peer
5260 * as authorized, but it shouldn't yet be.
5261 */
5262 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005263 break;
5264 default:
5265 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005266 }
5267
Johannes Bergbdd90d52011-12-14 12:20:27 +01005268 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005269
Hila Gonene35e4d22012-06-27 17:19:42 +03005270 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005271
Johannes Berg5727ef12007-12-19 02:03:34 +01005272 if (params.vlan)
5273 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005274 return err;
5275}
5276
5277static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5278{
Johannes Berg4c476992010-10-04 21:36:35 +02005279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5280 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005281 struct station_del_parameters params;
5282
5283 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005284
5285 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005286 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005287
Johannes Berge80cf852009-05-11 14:43:13 +02005288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005291 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5292 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005293
Johannes Berg4c476992010-10-04 21:36:35 +02005294 if (!rdev->ops->del_station)
5295 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005296
Jouni Malinen98856862014-10-20 13:20:45 +03005297 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5298 params.subtype =
5299 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5300 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5301 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5302 return -EINVAL;
5303 } else {
5304 /* Default to Deauthentication frame */
5305 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5306 }
5307
5308 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5309 params.reason_code =
5310 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5311 if (params.reason_code == 0)
5312 return -EINVAL; /* 0 is reserved */
5313 } else {
5314 /* Default to reason code 2 */
5315 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5316 }
5317
Jouni Malinen89c771e2014-10-10 20:52:40 +03005318 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005319}
5320
Eric W. Biederman15e47302012-09-07 20:12:54 +00005321static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005322 int flags, struct net_device *dev,
5323 u8 *dst, u8 *next_hop,
5324 struct mpath_info *pinfo)
5325{
5326 void *hdr;
5327 struct nlattr *pinfoattr;
5328
Henning Rogge1ef4c852014-11-04 16:14:58 +01005329 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005330 if (!hdr)
5331 return -1;
5332
David S. Miller9360ffd2012-03-29 04:41:26 -04005333 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5334 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5335 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5336 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5337 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005338
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005339 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5340 if (!pinfoattr)
5341 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005342 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5343 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5344 pinfo->frame_qlen))
5345 goto nla_put_failure;
5346 if (((pinfo->filled & MPATH_INFO_SN) &&
5347 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5348 ((pinfo->filled & MPATH_INFO_METRIC) &&
5349 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5350 pinfo->metric)) ||
5351 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5352 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5353 pinfo->exptime)) ||
5354 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5355 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5356 pinfo->flags)) ||
5357 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5358 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5359 pinfo->discovery_timeout)) ||
5360 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5361 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5362 pinfo->discovery_retries)))
5363 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005364
5365 nla_nest_end(msg, pinfoattr);
5366
Johannes Berg053c0952015-01-16 22:09:00 +01005367 genlmsg_end(msg, hdr);
5368 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005369
5370 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005371 genlmsg_cancel(msg, hdr);
5372 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005373}
5374
5375static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005376 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005377{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005378 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005379 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005380 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005381 u8 dst[ETH_ALEN];
5382 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005383 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005384 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005385
Johannes Bergea90e0d2017-03-15 14:26:04 +01005386 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005387 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005388 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005389 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005390
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005391 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005392 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005393 goto out_err;
5394 }
5395
Johannes Berg97990a02013-04-19 01:02:55 +02005396 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005397 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005398 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005399 }
5400
Johannes Bergbba95fe2008-07-29 13:22:51 +02005401 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005402 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005403 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005404 if (err == -ENOENT)
5405 break;
5406 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005407 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005408
Eric W. Biederman15e47302012-09-07 20:12:54 +00005409 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005410 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005411 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005412 &pinfo) < 0)
5413 goto out;
5414
5415 path_idx++;
5416 }
5417
Johannes Bergbba95fe2008-07-29 13:22:51 +02005418 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005419 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005420 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005421 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005422 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005423 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005424}
5425
5426static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5427{
Johannes Berg4c476992010-10-04 21:36:35 +02005428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005429 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005430 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005431 struct mpath_info pinfo;
5432 struct sk_buff *msg;
5433 u8 *dst = NULL;
5434 u8 next_hop[ETH_ALEN];
5435
5436 memset(&pinfo, 0, sizeof(pinfo));
5437
5438 if (!info->attrs[NL80211_ATTR_MAC])
5439 return -EINVAL;
5440
5441 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5442
Johannes Berg4c476992010-10-04 21:36:35 +02005443 if (!rdev->ops->get_mpath)
5444 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005445
Johannes Berg4c476992010-10-04 21:36:35 +02005446 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5447 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005448
Hila Gonene35e4d22012-06-27 17:19:42 +03005449 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005450 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005451 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005452
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005453 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005454 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005455 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005456
Eric W. Biederman15e47302012-09-07 20:12:54 +00005457 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005458 dev, dst, next_hop, &pinfo) < 0) {
5459 nlmsg_free(msg);
5460 return -ENOBUFS;
5461 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005462
Johannes Berg4c476992010-10-04 21:36:35 +02005463 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005464}
5465
5466static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5467{
Johannes Berg4c476992010-10-04 21:36:35 +02005468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5469 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005470 u8 *dst = NULL;
5471 u8 *next_hop = NULL;
5472
5473 if (!info->attrs[NL80211_ATTR_MAC])
5474 return -EINVAL;
5475
5476 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5477 return -EINVAL;
5478
5479 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5480 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5481
Johannes Berg4c476992010-10-04 21:36:35 +02005482 if (!rdev->ops->change_mpath)
5483 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005484
Johannes Berg4c476992010-10-04 21:36:35 +02005485 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5486 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005487
Hila Gonene35e4d22012-06-27 17:19:42 +03005488 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005489}
Johannes Berg4c476992010-10-04 21:36:35 +02005490
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005491static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5492{
Johannes Berg4c476992010-10-04 21:36:35 +02005493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5494 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005495 u8 *dst = NULL;
5496 u8 *next_hop = NULL;
5497
5498 if (!info->attrs[NL80211_ATTR_MAC])
5499 return -EINVAL;
5500
5501 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5502 return -EINVAL;
5503
5504 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5505 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5506
Johannes Berg4c476992010-10-04 21:36:35 +02005507 if (!rdev->ops->add_mpath)
5508 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005509
Johannes Berg4c476992010-10-04 21:36:35 +02005510 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5511 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005512
Hila Gonene35e4d22012-06-27 17:19:42 +03005513 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005514}
5515
5516static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5517{
Johannes Berg4c476992010-10-04 21:36:35 +02005518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5519 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005520 u8 *dst = NULL;
5521
5522 if (info->attrs[NL80211_ATTR_MAC])
5523 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5524
Johannes Berg4c476992010-10-04 21:36:35 +02005525 if (!rdev->ops->del_mpath)
5526 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005527
Hila Gonene35e4d22012-06-27 17:19:42 +03005528 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005529}
5530
Henning Rogge66be7d22014-09-12 08:58:49 +02005531static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5532{
5533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5534 int err;
5535 struct net_device *dev = info->user_ptr[1];
5536 struct mpath_info pinfo;
5537 struct sk_buff *msg;
5538 u8 *dst = NULL;
5539 u8 mpp[ETH_ALEN];
5540
5541 memset(&pinfo, 0, sizeof(pinfo));
5542
5543 if (!info->attrs[NL80211_ATTR_MAC])
5544 return -EINVAL;
5545
5546 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5547
5548 if (!rdev->ops->get_mpp)
5549 return -EOPNOTSUPP;
5550
5551 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5552 return -EOPNOTSUPP;
5553
5554 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5555 if (err)
5556 return err;
5557
5558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5559 if (!msg)
5560 return -ENOMEM;
5561
5562 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5563 dev, dst, mpp, &pinfo) < 0) {
5564 nlmsg_free(msg);
5565 return -ENOBUFS;
5566 }
5567
5568 return genlmsg_reply(msg, info);
5569}
5570
5571static int nl80211_dump_mpp(struct sk_buff *skb,
5572 struct netlink_callback *cb)
5573{
5574 struct mpath_info pinfo;
5575 struct cfg80211_registered_device *rdev;
5576 struct wireless_dev *wdev;
5577 u8 dst[ETH_ALEN];
5578 u8 mpp[ETH_ALEN];
5579 int path_idx = cb->args[2];
5580 int err;
5581
Johannes Bergea90e0d2017-03-15 14:26:04 +01005582 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005583 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5584 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005585 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005586
5587 if (!rdev->ops->dump_mpp) {
5588 err = -EOPNOTSUPP;
5589 goto out_err;
5590 }
5591
5592 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5593 err = -EOPNOTSUPP;
5594 goto out_err;
5595 }
5596
5597 while (1) {
5598 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5599 mpp, &pinfo);
5600 if (err == -ENOENT)
5601 break;
5602 if (err)
5603 goto out_err;
5604
5605 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5606 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5607 wdev->netdev, dst, mpp,
5608 &pinfo) < 0)
5609 goto out;
5610
5611 path_idx++;
5612 }
5613
5614 out:
5615 cb->args[2] = path_idx;
5616 err = skb->len;
5617 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005618 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005619 return err;
5620}
5621
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005622static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5623{
Johannes Berg4c476992010-10-04 21:36:35 +02005624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5625 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005626 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005627 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005628 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005629
5630 memset(&params, 0, sizeof(params));
5631 /* default to not changing parameters */
5632 params.use_cts_prot = -1;
5633 params.use_short_preamble = -1;
5634 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005635 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005636 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005637 params.p2p_ctwindow = -1;
5638 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005639
5640 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5641 params.use_cts_prot =
5642 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5643 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5644 params.use_short_preamble =
5645 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5646 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5647 params.use_short_slot_time =
5648 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005649 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5650 params.basic_rates =
5651 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5652 params.basic_rates_len =
5653 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5654 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005655 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5656 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005657 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5658 params.ht_opmode =
5659 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005660
Johannes Berg53cabad2012-11-14 15:17:28 +01005661 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5662 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5663 return -EINVAL;
5664 params.p2p_ctwindow =
5665 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5666 if (params.p2p_ctwindow < 0)
5667 return -EINVAL;
5668 if (params.p2p_ctwindow != 0 &&
5669 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5670 return -EINVAL;
5671 }
5672
5673 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5674 u8 tmp;
5675
5676 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5677 return -EINVAL;
5678 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5679 if (tmp > 1)
5680 return -EINVAL;
5681 params.p2p_opp_ps = tmp;
5682 if (params.p2p_opp_ps &&
5683 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5684 return -EINVAL;
5685 }
5686
Johannes Berg4c476992010-10-04 21:36:35 +02005687 if (!rdev->ops->change_bss)
5688 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005689
Johannes Berg074ac8d2010-09-16 14:58:22 +02005690 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005691 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5692 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005693
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005694 wdev_lock(wdev);
5695 err = rdev_change_bss(rdev, dev, &params);
5696 wdev_unlock(wdev);
5697
5698 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005699}
5700
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005701static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5702{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005703 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005704 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005705 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005706 u32 owner_nlportid;
5707
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005708 /*
5709 * You should only get this when cfg80211 hasn't yet initialized
5710 * completely when built-in to the kernel right between the time
5711 * window between nl80211_init() and regulatory_init(), if that is
5712 * even possible.
5713 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005714 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005715 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005716
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005717 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5718 user_reg_hint_type =
5719 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5720 else
5721 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5722
5723 switch (user_reg_hint_type) {
5724 case NL80211_USER_REG_HINT_USER:
5725 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005726 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5727 return -EINVAL;
5728
5729 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5730 return regulatory_hint_user(data, user_reg_hint_type);
5731 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005732 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5733 owner_nlportid = info->snd_portid;
5734 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5735 } else {
5736 owner_nlportid = 0;
5737 is_indoor = true;
5738 }
5739
5740 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005741 default:
5742 return -EINVAL;
5743 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005744}
5745
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02005746static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
5747{
5748 return reg_reload_regdb();
5749}
5750
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005751static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005752 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005753{
Johannes Berg4c476992010-10-04 21:36:35 +02005754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005755 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005756 struct wireless_dev *wdev = dev->ieee80211_ptr;
5757 struct mesh_config cur_params;
5758 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005759 void *hdr;
5760 struct nlattr *pinfoattr;
5761 struct sk_buff *msg;
5762
Johannes Berg29cbe682010-12-03 09:20:44 +01005763 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5764 return -EOPNOTSUPP;
5765
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005766 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005767 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005768
Johannes Berg29cbe682010-12-03 09:20:44 +01005769 wdev_lock(wdev);
5770 /* If not connected, get default parameters */
5771 if (!wdev->mesh_id_len)
5772 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5773 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005774 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005775 wdev_unlock(wdev);
5776
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005777 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005778 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005779
5780 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005782 if (!msg)
5783 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005784 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005785 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005786 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005787 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005788 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005789 if (!pinfoattr)
5790 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005791 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5792 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5793 cur_params.dot11MeshRetryTimeout) ||
5794 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5795 cur_params.dot11MeshConfirmTimeout) ||
5796 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5797 cur_params.dot11MeshHoldingTimeout) ||
5798 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5799 cur_params.dot11MeshMaxPeerLinks) ||
5800 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5801 cur_params.dot11MeshMaxRetries) ||
5802 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5803 cur_params.dot11MeshTTL) ||
5804 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5805 cur_params.element_ttl) ||
5806 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5807 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005808 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5809 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005810 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5811 cur_params.dot11MeshHWMPmaxPREQretries) ||
5812 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5813 cur_params.path_refresh_time) ||
5814 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5815 cur_params.min_discovery_timeout) ||
5816 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5817 cur_params.dot11MeshHWMPactivePathTimeout) ||
5818 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5819 cur_params.dot11MeshHWMPpreqMinInterval) ||
5820 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5821 cur_params.dot11MeshHWMPperrMinInterval) ||
5822 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5823 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5824 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5825 cur_params.dot11MeshHWMPRootMode) ||
5826 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5827 cur_params.dot11MeshHWMPRannInterval) ||
5828 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5829 cur_params.dot11MeshGateAnnouncementProtocol) ||
5830 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5831 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005832 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005833 cur_params.rssi_threshold) ||
5834 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005835 cur_params.ht_opmode) ||
5836 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5837 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5838 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005839 cur_params.dot11MeshHWMProotInterval) ||
5840 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005841 cur_params.dot11MeshHWMPconfirmationInterval) ||
5842 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5843 cur_params.power_mode) ||
5844 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005845 cur_params.dot11MeshAwakeWindowDuration) ||
5846 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5847 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005848 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005849 nla_nest_end(msg, pinfoattr);
5850 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005851 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005852
Johannes Berg3b858752009-03-12 09:55:09 +01005853 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01005854 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005855 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005856 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005857}
5858
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005859static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005860 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5861 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5862 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5863 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5864 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5865 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005866 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005867 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005868 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005869 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5870 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5871 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5872 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5873 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005874 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005875 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005876 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005877 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005878 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005879 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005880 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5881 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005882 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5883 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005884 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005885 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5886 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005887 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005888};
5889
Javier Cardonac80d5452010-12-16 17:37:49 -08005890static const struct nla_policy
5891 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005892 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005893 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5894 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005895 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005896 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005897 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005898 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005899 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005900 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005901};
5902
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005903static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5904{
5905 u8 val = nla_get_u8(nla);
5906 if (val < min || val > max)
5907 return -EINVAL;
5908 *out = val;
5909 return 0;
5910}
5911
5912static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5913{
5914 u8 val = nla_get_u8(nla);
5915 if (val < min || val > max)
5916 return -EINVAL;
5917 *out = val;
5918 return 0;
5919}
5920
5921static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5922{
5923 u16 val = nla_get_u16(nla);
5924 if (val < min || val > max)
5925 return -EINVAL;
5926 *out = val;
5927 return 0;
5928}
5929
5930static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5931{
5932 u32 val = nla_get_u32(nla);
5933 if (val < min || val > max)
5934 return -EINVAL;
5935 *out = val;
5936 return 0;
5937}
5938
5939static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5940{
5941 s32 val = nla_get_s32(nla);
5942 if (val < min || val > max)
5943 return -EINVAL;
5944 *out = val;
5945 return 0;
5946}
5947
Johannes Bergff9a71a2016-08-11 14:59:53 +02005948static int nl80211_check_power_mode(const struct nlattr *nla,
5949 enum nl80211_mesh_power_mode min,
5950 enum nl80211_mesh_power_mode max,
5951 enum nl80211_mesh_power_mode *out)
5952{
5953 u32 val = nla_get_u32(nla);
5954 if (val < min || val > max)
5955 return -EINVAL;
5956 *out = val;
5957 return 0;
5958}
5959
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005960static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005961 struct mesh_config *cfg,
5962 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005963{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005964 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005965 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005966 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005967
Marco Porschea54fba2013-01-07 16:04:48 +01005968#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5969do { \
5970 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005971 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005972 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005973 mask |= (1 << (attr - 1)); \
5974 } \
5975} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005976
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005977 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005978 return -EINVAL;
5979 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005980 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005981 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005982 return -EINVAL;
5983
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005984 /* This makes sure that there aren't more than 32 mesh config
5985 * parameters (otherwise our bitfield scheme would not work.) */
5986 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5987
5988 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005989 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005990 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005991 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005993 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005994 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005996 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005997 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005999 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006000 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006001 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006002 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006003 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006004 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006005 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006006 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006007 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006008 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006010 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006011 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006012 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
6013 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006014 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006015 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006016 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006017 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006018 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006019 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006020 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006021 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006022 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006023 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006024 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
6026 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006027 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006028 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006029 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006030 1, 65535, mask,
6031 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006032 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08006033 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006034 1, 65535, mask,
6035 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006036 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006037 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006038 dot11MeshHWMPnetDiameterTraversalTime,
6039 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006040 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006041 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006042 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
6043 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006044 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
6046 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006047 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00006048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006049 dot11MeshGateAnnouncementProtocol, 0, 1,
6050 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006051 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006052 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006053 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006054 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08006055 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006056 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006057 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09006058 /*
6059 * Check HT operation mode based on
6060 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6061 */
6062 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6063 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6064
6065 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6066 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6067 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6068 return -EINVAL;
6069
6070 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6071 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6072 return -EINVAL;
6073
6074 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6075 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6076 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6077 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6078 return -EINVAL;
6079 break;
6080 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6081 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6082 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6083 return -EINVAL;
6084 break;
6085 }
6086 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006087 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006088 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006089 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006090 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006091 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006092 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006093 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006094 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006095 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006096 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006097 dot11MeshHWMPconfirmationInterval,
6098 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006099 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006100 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006101 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6102 NL80211_MESH_POWER_ACTIVE,
6103 NL80211_MESH_POWER_MAX,
6104 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006105 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6107 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006108 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006110 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006111 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006112 if (mask_out)
6113 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006114
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006115 return 0;
6116
6117#undef FILL_IN_MESH_PARAM_IF_SET
6118}
6119
Javier Cardonac80d5452010-12-16 17:37:49 -08006120static int nl80211_parse_mesh_setup(struct genl_info *info,
6121 struct mesh_setup *setup)
6122{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006124 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6125
6126 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6127 return -EINVAL;
6128 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6129 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006130 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006131 return -EINVAL;
6132
Javier Cardonad299a1f2012-03-31 11:31:33 -07006133 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6134 setup->sync_method =
6135 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6136 IEEE80211_SYNC_METHOD_VENDOR :
6137 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6138
Javier Cardonac80d5452010-12-16 17:37:49 -08006139 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6140 setup->path_sel_proto =
6141 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6142 IEEE80211_PATH_PROTOCOL_VENDOR :
6143 IEEE80211_PATH_PROTOCOL_HWMP;
6144
6145 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6146 setup->path_metric =
6147 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6148 IEEE80211_PATH_METRIC_VENDOR :
6149 IEEE80211_PATH_METRIC_AIRTIME;
6150
Javier Cardona581a8b02011-04-07 15:08:27 -07006151 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006152 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006153 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006154 if (!is_valid_ie_attr(ieattr))
6155 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006156 setup->ie = nla_data(ieattr);
6157 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006158 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006159 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6160 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6161 return -EINVAL;
6162 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006163 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6164 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006165 if (setup->is_secure)
6166 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006167
Colleen Twitty6e16d902013-05-08 11:45:59 -07006168 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6169 if (!setup->user_mpm)
6170 return -EINVAL;
6171 setup->auth_id =
6172 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6173 }
6174
Javier Cardonac80d5452010-12-16 17:37:49 -08006175 return 0;
6176}
6177
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006178static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006179 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006180{
6181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6182 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006183 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006184 struct mesh_config cfg;
6185 u32 mask;
6186 int err;
6187
Johannes Berg29cbe682010-12-03 09:20:44 +01006188 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6189 return -EOPNOTSUPP;
6190
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006191 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006192 return -EOPNOTSUPP;
6193
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006194 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006195 if (err)
6196 return err;
6197
Johannes Berg29cbe682010-12-03 09:20:44 +01006198 wdev_lock(wdev);
6199 if (!wdev->mesh_id_len)
6200 err = -ENOLINK;
6201
6202 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006203 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006204
6205 wdev_unlock(wdev);
6206
6207 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006208}
6209
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006210static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6211 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006212{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006213 struct nlattr *nl_reg_rules;
6214 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006215
Johannes Berg458f4f92012-12-06 15:47:38 +01006216 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6217 (regdom->dfs_region &&
6218 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006219 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006220
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006221 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6222 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006223 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006224
Johannes Berg458f4f92012-12-06 15:47:38 +01006225 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006226 struct nlattr *nl_reg_rule;
6227 const struct ieee80211_reg_rule *reg_rule;
6228 const struct ieee80211_freq_range *freq_range;
6229 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006230 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006231
Johannes Berg458f4f92012-12-06 15:47:38 +01006232 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006233 freq_range = &reg_rule->freq_range;
6234 power_rule = &reg_rule->power_rule;
6235
6236 nl_reg_rule = nla_nest_start(msg, i);
6237 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006238 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006239
Janusz Dziedzic97524822014-01-30 09:52:20 +01006240 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6241 if (!max_bandwidth_khz)
6242 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6243 reg_rule);
6244
David S. Miller9360ffd2012-03-29 04:41:26 -04006245 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6246 reg_rule->flags) ||
6247 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6248 freq_range->start_freq_khz) ||
6249 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6250 freq_range->end_freq_khz) ||
6251 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006252 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006253 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6254 power_rule->max_antenna_gain) ||
6255 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006256 power_rule->max_eirp) ||
6257 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6258 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006259 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006260
6261 nla_nest_end(msg, nl_reg_rule);
6262 }
6263
6264 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006265 return 0;
6266
6267nla_put_failure:
6268 return -EMSGSIZE;
6269}
6270
6271static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6272{
6273 const struct ieee80211_regdomain *regdom = NULL;
6274 struct cfg80211_registered_device *rdev;
6275 struct wiphy *wiphy = NULL;
6276 struct sk_buff *msg;
6277 void *hdr;
6278
6279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6280 if (!msg)
6281 return -ENOBUFS;
6282
6283 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6284 NL80211_CMD_GET_REG);
6285 if (!hdr)
6286 goto put_failure;
6287
6288 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006289 bool self_managed;
6290
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006291 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6292 if (IS_ERR(rdev)) {
6293 nlmsg_free(msg);
6294 return PTR_ERR(rdev);
6295 }
6296
6297 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006298 self_managed = wiphy->regulatory_flags &
6299 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006300 regdom = get_wiphy_regdom(wiphy);
6301
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006302 /* a self-managed-reg device must have a private regdom */
6303 if (WARN_ON(!regdom && self_managed)) {
6304 nlmsg_free(msg);
6305 return -EINVAL;
6306 }
6307
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006308 if (regdom &&
6309 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6310 goto nla_put_failure;
6311 }
6312
6313 if (!wiphy && reg_last_request_cell_base() &&
6314 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6315 NL80211_USER_REG_HINT_CELL_BASE))
6316 goto nla_put_failure;
6317
6318 rcu_read_lock();
6319
6320 if (!regdom)
6321 regdom = rcu_dereference(cfg80211_regdomain);
6322
6323 if (nl80211_put_regdom(regdom, msg))
6324 goto nla_put_failure_rcu;
6325
6326 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006327
6328 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006329 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006330
Johannes Berg458f4f92012-12-06 15:47:38 +01006331nla_put_failure_rcu:
6332 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006333nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006334put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006335 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006336 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006337}
6338
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006339static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6340 u32 seq, int flags, struct wiphy *wiphy,
6341 const struct ieee80211_regdomain *regdom)
6342{
6343 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6344 NL80211_CMD_GET_REG);
6345
6346 if (!hdr)
6347 return -1;
6348
Michal Kubecek0a833c22017-11-15 13:09:32 +01006349 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006350
6351 if (nl80211_put_regdom(regdom, msg))
6352 goto nla_put_failure;
6353
6354 if (!wiphy && reg_last_request_cell_base() &&
6355 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6356 NL80211_USER_REG_HINT_CELL_BASE))
6357 goto nla_put_failure;
6358
6359 if (wiphy &&
6360 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6361 goto nla_put_failure;
6362
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006363 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6364 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6365 goto nla_put_failure;
6366
Johannes Berg053c0952015-01-16 22:09:00 +01006367 genlmsg_end(msg, hdr);
6368 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006369
6370nla_put_failure:
6371 genlmsg_cancel(msg, hdr);
6372 return -EMSGSIZE;
6373}
6374
6375static int nl80211_get_reg_dump(struct sk_buff *skb,
6376 struct netlink_callback *cb)
6377{
6378 const struct ieee80211_regdomain *regdom = NULL;
6379 struct cfg80211_registered_device *rdev;
6380 int err, reg_idx, start = cb->args[2];
6381
6382 rtnl_lock();
6383
6384 if (cfg80211_regdomain && start == 0) {
6385 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6386 NLM_F_MULTI, NULL,
6387 rtnl_dereference(cfg80211_regdomain));
6388 if (err < 0)
6389 goto out_err;
6390 }
6391
6392 /* the global regdom is idx 0 */
6393 reg_idx = 1;
6394 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6395 regdom = get_wiphy_regdom(&rdev->wiphy);
6396 if (!regdom)
6397 continue;
6398
6399 if (++reg_idx <= start)
6400 continue;
6401
6402 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6403 NLM_F_MULTI, &rdev->wiphy, regdom);
6404 if (err < 0) {
6405 reg_idx--;
6406 break;
6407 }
6408 }
6409
6410 cb->args[2] = reg_idx;
6411 err = skb->len;
6412out_err:
6413 rtnl_unlock();
6414 return err;
6415}
6416
Johannes Bergb6863032015-10-15 09:25:18 +02006417#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6418static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6419 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6420 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6421 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6422 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6423 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6424 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6425 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6426};
6427
6428static int parse_reg_rule(struct nlattr *tb[],
6429 struct ieee80211_reg_rule *reg_rule)
6430{
6431 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6432 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6433
6434 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6435 return -EINVAL;
6436 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6437 return -EINVAL;
6438 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6439 return -EINVAL;
6440 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6441 return -EINVAL;
6442 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6443 return -EINVAL;
6444
6445 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6446
6447 freq_range->start_freq_khz =
6448 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6449 freq_range->end_freq_khz =
6450 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6451 freq_range->max_bandwidth_khz =
6452 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6453
6454 power_rule->max_eirp =
6455 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6456
6457 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6458 power_rule->max_antenna_gain =
6459 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6460
6461 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6462 reg_rule->dfs_cac_ms =
6463 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6464
6465 return 0;
6466}
6467
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006468static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6469{
6470 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6471 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006472 char *alpha2;
6473 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006474 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006475 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006476 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006477
6478 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6479 return -EINVAL;
6480
6481 if (!info->attrs[NL80211_ATTR_REG_RULES])
6482 return -EINVAL;
6483
6484 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6485
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006486 if (info->attrs[NL80211_ATTR_DFS_REGION])
6487 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6488
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006489 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006490 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006491 num_rules++;
6492 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006493 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006494 }
6495
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006496 if (!reg_is_valid_request(alpha2))
6497 return -EINVAL;
6498
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006499 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006500 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006501
6502 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006503 if (!rd)
6504 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006505
6506 rd->n_reg_rules = num_rules;
6507 rd->alpha2[0] = alpha2[0];
6508 rd->alpha2[1] = alpha2[1];
6509
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006510 /*
6511 * Disable DFS master mode if the DFS region was
6512 * not supported or known on this kernel.
6513 */
6514 if (reg_supported_dfs_region(dfs_region))
6515 rd->dfs_region = dfs_region;
6516
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006517 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006518 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006519 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006520 nl_reg_rule, reg_rule_policy,
6521 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006522 if (r)
6523 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006524 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6525 if (r)
6526 goto bad_reg;
6527
6528 rule_idx++;
6529
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006530 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6531 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006532 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006533 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006534 }
6535
Johannes Berg06627992016-06-09 10:40:09 +02006536 /* set_regdom takes ownership of rd */
6537 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006538 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006539 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006540 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006541}
Johannes Bergb6863032015-10-15 09:25:18 +02006542#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006543
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006544static int validate_scan_freqs(struct nlattr *freqs)
6545{
6546 struct nlattr *attr1, *attr2;
6547 int n_channels = 0, tmp1, tmp2;
6548
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006549 nla_for_each_nested(attr1, freqs, tmp1)
6550 if (nla_len(attr1) != sizeof(u32))
6551 return 0;
6552
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006553 nla_for_each_nested(attr1, freqs, tmp1) {
6554 n_channels++;
6555 /*
6556 * Some hardware has a limited channel list for
6557 * scanning, and it is pretty much nonsensical
6558 * to scan for a channel twice, so disallow that
6559 * and don't require drivers to check that the
6560 * channel list they get isn't longer than what
6561 * they can scan, as long as they can scan all
6562 * the channels they registered at once.
6563 */
6564 nla_for_each_nested(attr2, freqs, tmp2)
6565 if (attr1 != attr2 &&
6566 nla_get_u32(attr1) == nla_get_u32(attr2))
6567 return 0;
6568 }
6569
6570 return n_channels;
6571}
6572
Johannes Berg57fbcce2016-04-12 15:56:15 +02006573static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006574{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006575 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006576}
6577
6578static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6579 struct cfg80211_bss_selection *bss_select)
6580{
6581 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6582 struct nlattr *nest;
6583 int err;
6584 bool found = false;
6585 int i;
6586
6587 /* only process one nested attribute */
6588 nest = nla_data(nla);
6589 if (!nla_ok(nest, nla_len(nest)))
6590 return -EINVAL;
6591
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006592 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006593 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006594 if (err)
6595 return err;
6596
6597 /* only one attribute may be given */
6598 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6599 if (attr[i]) {
6600 if (found)
6601 return -EINVAL;
6602 found = true;
6603 }
6604 }
6605
6606 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6607
6608 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6609 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6610
6611 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6612 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6613 bss_select->param.band_pref =
6614 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6615 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6616 return -EINVAL;
6617 }
6618
6619 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6620 struct nl80211_bss_select_rssi_adjust *adj_param;
6621
6622 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6623 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6624 bss_select->param.adjust.band = adj_param->band;
6625 bss_select->param.adjust.delta = adj_param->delta;
6626 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6627 return -EINVAL;
6628 }
6629
6630 /* user-space did not provide behaviour attribute */
6631 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6632 return -EINVAL;
6633
6634 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6635 return -EINVAL;
6636
6637 return 0;
6638}
6639
Johannes Bergad2b26a2014-06-12 21:39:05 +02006640static int nl80211_parse_random_mac(struct nlattr **attrs,
6641 u8 *mac_addr, u8 *mac_addr_mask)
6642{
6643 int i;
6644
6645 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006646 eth_zero_addr(mac_addr);
6647 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006648 mac_addr[0] = 0x2;
6649 mac_addr_mask[0] = 0x3;
6650
6651 return 0;
6652 }
6653
6654 /* need both or none */
6655 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6656 return -EINVAL;
6657
6658 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6659 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6660
6661 /* don't allow or configure an mcast address */
6662 if (!is_multicast_ether_addr(mac_addr_mask) ||
6663 is_multicast_ether_addr(mac_addr))
6664 return -EINVAL;
6665
6666 /*
6667 * allow users to pass a MAC address that has bits set outside
6668 * of the mask, but don't bother drivers with having to deal
6669 * with such bits
6670 */
6671 for (i = 0; i < ETH_ALEN; i++)
6672 mac_addr[i] &= mac_addr_mask[i];
6673
6674 return 0;
6675}
6676
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306677static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6678{
6679 ASSERT_WDEV_LOCK(wdev);
6680
6681 if (!cfg80211_beaconing_iface_active(wdev))
6682 return true;
6683
6684 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6685 return true;
6686
6687 return regulatory_pre_cac_allowed(wdev->wiphy);
6688}
6689
Roee Zamir2d23d072017-08-06 11:38:22 +03006690static int
6691nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6692 void *request, struct nlattr **attrs,
6693 bool is_sched_scan)
6694{
6695 u8 *mac_addr, *mac_addr_mask;
6696 u32 *flags;
6697 enum nl80211_feature_flags randomness_flag;
6698
6699 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6700 return 0;
6701
6702 if (is_sched_scan) {
6703 struct cfg80211_sched_scan_request *req = request;
6704
6705 randomness_flag = wdev ?
6706 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6707 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6708 flags = &req->flags;
6709 mac_addr = req->mac_addr;
6710 mac_addr_mask = req->mac_addr_mask;
6711 } else {
6712 struct cfg80211_scan_request *req = request;
6713
6714 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6715 flags = &req->flags;
6716 mac_addr = req->mac_addr;
6717 mac_addr_mask = req->mac_addr_mask;
6718 }
6719
6720 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
6721
Sunil Dutt5037a002018-01-25 17:13:37 +02006722 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6723 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
6724 ((*flags & NL80211_SCAN_FLAG_LOW_SPAN) &&
6725 !wiphy_ext_feature_isset(wiphy,
6726 NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) ||
6727 ((*flags & NL80211_SCAN_FLAG_LOW_POWER) &&
6728 !wiphy_ext_feature_isset(wiphy,
6729 NL80211_EXT_FEATURE_LOW_POWER_SCAN)) ||
6730 ((*flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) &&
6731 !wiphy_ext_feature_isset(wiphy,
6732 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN)))
Roee Zamir2d23d072017-08-06 11:38:22 +03006733 return -EOPNOTSUPP;
6734
6735 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6736 int err;
6737
6738 if (!(wiphy->features & randomness_flag) ||
6739 (wdev && wdev->current_bss))
6740 return -EOPNOTSUPP;
6741
6742 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
6743 if (err)
6744 return err;
6745 }
6746
6747 if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) &&
6748 !wiphy_ext_feature_isset(wiphy,
6749 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME))
6750 return -EOPNOTSUPP;
6751
6752 if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) &&
6753 !wiphy_ext_feature_isset(wiphy,
6754 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP))
6755 return -EOPNOTSUPP;
6756
6757 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
6758 !wiphy_ext_feature_isset(wiphy,
6759 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
6760 return -EOPNOTSUPP;
6761
6762 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) &&
6763 !wiphy_ext_feature_isset(wiphy,
6764 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE))
6765 return -EOPNOTSUPP;
6766
6767 return 0;
6768}
6769
Johannes Berg2a519312009-02-10 21:25:55 +01006770static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6771{
Johannes Berg4c476992010-10-04 21:36:35 +02006772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006773 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006774 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006775 struct nlattr *attr;
6776 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006777 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006778 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006779
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006780 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6781 return -EINVAL;
6782
Johannes Berg79c97e92009-07-07 03:56:12 +02006783 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006784
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006785 if (wdev->iftype == NL80211_IFTYPE_NAN)
6786 return -EOPNOTSUPP;
6787
Johannes Berg4c476992010-10-04 21:36:35 +02006788 if (!rdev->ops->scan)
6789 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006790
Johannes Bergf9d15d12014-01-22 11:14:19 +02006791 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006792 err = -EBUSY;
6793 goto unlock;
6794 }
Johannes Berg2a519312009-02-10 21:25:55 +01006795
6796 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006797 n_channels = validate_scan_freqs(
6798 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006799 if (!n_channels) {
6800 err = -EINVAL;
6801 goto unlock;
6802 }
Johannes Berg2a519312009-02-10 21:25:55 +01006803 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006804 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006805 }
6806
6807 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6808 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6809 n_ssids++;
6810
Johannes Bergf9f47522013-03-19 15:04:07 +01006811 if (n_ssids > wiphy->max_scan_ssids) {
6812 err = -EINVAL;
6813 goto unlock;
6814 }
Johannes Berg2a519312009-02-10 21:25:55 +01006815
Jouni Malinen70692ad2009-02-16 19:39:13 +02006816 if (info->attrs[NL80211_ATTR_IE])
6817 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6818 else
6819 ie_len = 0;
6820
Johannes Bergf9f47522013-03-19 15:04:07 +01006821 if (ie_len > wiphy->max_scan_ie_len) {
6822 err = -EINVAL;
6823 goto unlock;
6824 }
Johannes Berg18a83652009-03-31 12:12:05 +02006825
Johannes Berg2a519312009-02-10 21:25:55 +01006826 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006827 + sizeof(*request->ssids) * n_ssids
6828 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006829 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006830 if (!request) {
6831 err = -ENOMEM;
6832 goto unlock;
6833 }
Johannes Berg2a519312009-02-10 21:25:55 +01006834
Johannes Berg2a519312009-02-10 21:25:55 +01006835 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006836 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006837 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006838 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006839 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006840 request->ie = (void *)(request->ssids + n_ssids);
6841 else
6842 request->ie = (void *)(request->channels + n_channels);
6843 }
Johannes Berg2a519312009-02-10 21:25:55 +01006844
Johannes Berg584991d2009-11-02 13:32:03 +01006845 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006846 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6847 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006848 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006849 struct ieee80211_channel *chan;
6850
6851 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6852
6853 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006854 err = -EINVAL;
6855 goto out_free;
6856 }
Johannes Berg584991d2009-11-02 13:32:03 +01006857
6858 /* ignore disabled channels */
6859 if (chan->flags & IEEE80211_CHAN_DISABLED)
6860 continue;
6861
6862 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006863 i++;
6864 }
6865 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006866 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006867
Johannes Berg2a519312009-02-10 21:25:55 +01006868 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006869 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006870 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006871
Johannes Berg2a519312009-02-10 21:25:55 +01006872 if (!wiphy->bands[band])
6873 continue;
6874 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006875 struct ieee80211_channel *chan;
6876
6877 chan = &wiphy->bands[band]->channels[j];
6878
6879 if (chan->flags & IEEE80211_CHAN_DISABLED)
6880 continue;
6881
6882 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006883 i++;
6884 }
6885 }
6886 }
6887
Johannes Berg584991d2009-11-02 13:32:03 +01006888 if (!i) {
6889 err = -EINVAL;
6890 goto out_free;
6891 }
6892
6893 request->n_channels = i;
6894
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306895 wdev_lock(wdev);
6896 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6897 struct ieee80211_channel *chan;
6898
6899 if (request->n_channels != 1) {
6900 wdev_unlock(wdev);
6901 err = -EBUSY;
6902 goto out_free;
6903 }
6904
6905 chan = request->channels[0];
6906 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6907 wdev_unlock(wdev);
6908 err = -EBUSY;
6909 goto out_free;
6910 }
6911 }
6912 wdev_unlock(wdev);
6913
Johannes Berg2a519312009-02-10 21:25:55 +01006914 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006915 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006916 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006917 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006918 err = -EINVAL;
6919 goto out_free;
6920 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006921 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006922 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006923 i++;
6924 }
6925 }
6926
Jouni Malinen70692ad2009-02-16 19:39:13 +02006927 if (info->attrs[NL80211_ATTR_IE]) {
6928 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02006929 memcpy((void *)request->ie,
6930 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006931 request->ie_len);
6932 }
6933
Johannes Berg57fbcce2016-04-12 15:56:15 +02006934 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006935 if (wiphy->bands[i])
6936 request->rates[i] =
6937 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006938
6939 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6940 nla_for_each_nested(attr,
6941 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6942 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006943 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006944
Johannes Berg57fbcce2016-04-12 15:56:15 +02006945 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006946 err = -EINVAL;
6947 goto out_free;
6948 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006949
6950 if (!wiphy->bands[band])
6951 continue;
6952
Johannes Berg34850ab2011-07-18 18:08:35 +02006953 err = ieee80211_get_ratemask(wiphy->bands[band],
6954 nla_data(attr),
6955 nla_len(attr),
6956 &request->rates[band]);
6957 if (err)
6958 goto out_free;
6959 }
6960 }
6961
Avraham Stern1d762502016-07-05 17:10:13 +03006962 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6963 if (!wiphy_ext_feature_isset(wiphy,
6964 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6965 err = -EOPNOTSUPP;
6966 goto out_free;
6967 }
6968
6969 request->duration =
6970 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6971 request->duration_mandatory =
6972 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6973 }
6974
Roee Zamir2d23d072017-08-06 11:38:22 +03006975 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
6976 false);
6977 if (err)
6978 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07006979
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306980 request->no_cck =
6981 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6982
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006983 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6984 * BSSID to scan for. This was problematic because that same attribute
6985 * was already used for another purpose (local random MAC address). The
6986 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6987 * compatibility with older userspace components, also use the
6988 * NL80211_ATTR_MAC value here if it can be determined to be used for
6989 * the specific BSSID use case instead of the random MAC address
6990 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6991 */
6992 if (info->attrs[NL80211_ATTR_BSSID])
6993 memcpy(request->bssid,
6994 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6995 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6996 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006997 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6998 ETH_ALEN);
6999 else
7000 eth_broadcast_addr(request->bssid);
7001
Johannes Bergfd014282012-06-18 19:17:03 +02007002 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007003 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007004 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007005
Johannes Berg79c97e92009-07-07 03:56:12 +02007006 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007007 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007008
Johannes Berg463d0182009-07-14 00:33:35 +02007009 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007010 nl80211_send_scan_start(rdev, wdev);
7011 if (wdev->netdev)
7012 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007013 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007014 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007015 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007016 kfree(request);
7017 }
Johannes Berg3b858752009-03-12 09:55:09 +01007018
Johannes Bergf9f47522013-03-19 15:04:07 +01007019 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007020 return err;
7021}
7022
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307023static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7024{
7025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7026 struct wireless_dev *wdev = info->user_ptr[1];
7027
7028 if (!rdev->ops->abort_scan)
7029 return -EOPNOTSUPP;
7030
7031 if (rdev->scan_msg)
7032 return 0;
7033
7034 if (!rdev->scan_req)
7035 return -ENOENT;
7036
7037 rdev_abort_scan(rdev, wdev);
7038 return 0;
7039}
7040
Avraham Stern3b06d272015-10-12 09:51:34 +03007041static int
7042nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7043 struct cfg80211_sched_scan_request *request,
7044 struct nlattr **attrs)
7045{
7046 int tmp, err, i = 0;
7047 struct nlattr *attr;
7048
7049 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7050 u32 interval;
7051
7052 /*
7053 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007054 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007055 * case one scan plan will be set with the specified scan
7056 * interval and infinite number of iterations.
7057 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007058 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7059 if (!interval)
7060 return -EINVAL;
7061
7062 request->scan_plans[0].interval =
7063 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7064 if (!request->scan_plans[0].interval)
7065 return -EINVAL;
7066
7067 if (request->scan_plans[0].interval >
7068 wiphy->max_sched_scan_plan_interval)
7069 request->scan_plans[0].interval =
7070 wiphy->max_sched_scan_plan_interval;
7071
7072 return 0;
7073 }
7074
7075 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7076 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7077
7078 if (WARN_ON(i >= n_plans))
7079 return -EINVAL;
7080
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007081 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007082 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007083 if (err)
7084 return err;
7085
7086 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7087 return -EINVAL;
7088
7089 request->scan_plans[i].interval =
7090 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7091 if (!request->scan_plans[i].interval ||
7092 request->scan_plans[i].interval >
7093 wiphy->max_sched_scan_plan_interval)
7094 return -EINVAL;
7095
7096 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7097 request->scan_plans[i].iterations =
7098 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7099 if (!request->scan_plans[i].iterations ||
7100 (request->scan_plans[i].iterations >
7101 wiphy->max_sched_scan_plan_iterations))
7102 return -EINVAL;
7103 } else if (i < n_plans - 1) {
7104 /*
7105 * All scan plans but the last one must specify
7106 * a finite number of iterations
7107 */
7108 return -EINVAL;
7109 }
7110
7111 i++;
7112 }
7113
7114 /*
7115 * The last scan plan must not specify the number of
7116 * iterations, it is supposed to run infinitely
7117 */
7118 if (request->scan_plans[n_plans - 1].iterations)
7119 return -EINVAL;
7120
7121 return 0;
7122}
7123
Luciano Coelho256da022014-11-10 16:13:46 +02007124static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007125nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007126 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007127{
7128 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007129 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007130 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007131 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007132 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007133 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007134 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007135
Luciano Coelho256da022014-11-10 16:13:46 +02007136 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7137 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007138
Luciano Coelho256da022014-11-10 16:13:46 +02007139 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007140 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007141 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007142 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007143 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007144 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007145 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007146 }
7147
Luciano Coelho256da022014-11-10 16:13:46 +02007148 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7149 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007150 tmp)
7151 n_ssids++;
7152
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007153 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007154 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007155
Johannes Bergea73cbc2014-01-24 10:53:53 +01007156 /*
7157 * First, count the number of 'real' matchsets. Due to an issue with
7158 * the old implementation, matchsets containing only the RSSI attribute
7159 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7160 * RSSI for all matchsets, rather than their own matchset for reporting
7161 * all APs with a strong RSSI. This is needed to be compatible with
7162 * older userspace that treated a matchset with only the RSSI as the
7163 * global RSSI for all other matchsets - if there are other matchsets.
7164 */
Luciano Coelho256da022014-11-10 16:13:46 +02007165 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007166 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007167 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007168 tmp) {
7169 struct nlattr *rssi;
7170
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007171 err = nla_parse_nested(tb,
7172 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007173 attr, nl80211_match_policy,
7174 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007175 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007176 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007177
7178 /* SSID and BSSID are mutually exclusive */
7179 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7180 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7181 return ERR_PTR(-EINVAL);
7182
Johannes Bergea73cbc2014-01-24 10:53:53 +01007183 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007184 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7185 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007186 n_match_sets++;
7187 continue;
7188 }
7189 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7190 if (rssi)
7191 default_match_rssi = nla_get_s32(rssi);
7192 }
7193 }
7194
7195 /* However, if there's no other matchset, add the RSSI one */
7196 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7197 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007198
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007199 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007200 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007201
Luciano Coelho256da022014-11-10 16:13:46 +02007202 if (attrs[NL80211_ATTR_IE])
7203 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007204 else
7205 ie_len = 0;
7206
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007207 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007208 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007209
Avraham Stern3b06d272015-10-12 09:51:34 +03007210 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7211 /*
7212 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7213 * each scan plan already specifies its own interval
7214 */
7215 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7216 return ERR_PTR(-EINVAL);
7217
7218 nla_for_each_nested(attr,
7219 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7220 n_plans++;
7221 } else {
7222 /*
7223 * The scan interval attribute is kept for backward
7224 * compatibility. If no scan plans are specified and sched scan
7225 * interval is specified, one scan plan will be set with this
7226 * scan interval and infinite number of iterations.
7227 */
7228 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7229 return ERR_PTR(-EINVAL);
7230
7231 n_plans = 1;
7232 }
7233
7234 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7235 return ERR_PTR(-EINVAL);
7236
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007237 if (!wiphy_ext_feature_isset(
7238 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7239 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7240 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7241 return ERR_PTR(-EINVAL);
7242
Luciano Coelho807f8a82011-05-11 17:09:35 +03007243 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007244 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007245 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007246 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007247 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007248 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007249 if (!request)
7250 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007251
7252 if (n_ssids)
7253 request->ssids = (void *)&request->channels[n_channels];
7254 request->n_ssids = n_ssids;
7255 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007256 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007257 request->ie = (void *)(request->ssids + n_ssids);
7258 else
7259 request->ie = (void *)(request->channels + n_channels);
7260 }
7261
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007262 if (n_match_sets) {
7263 if (request->ie)
7264 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007265 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007266 request->match_sets =
7267 (void *)(request->ssids + n_ssids);
7268 else
7269 request->match_sets =
7270 (void *)(request->channels + n_channels);
7271 }
7272 request->n_match_sets = n_match_sets;
7273
Avraham Stern3b06d272015-10-12 09:51:34 +03007274 if (n_match_sets)
7275 request->scan_plans = (void *)(request->match_sets +
7276 n_match_sets);
7277 else if (request->ie)
7278 request->scan_plans = (void *)(request->ie + ie_len);
7279 else if (n_ssids)
7280 request->scan_plans = (void *)(request->ssids + n_ssids);
7281 else
7282 request->scan_plans = (void *)(request->channels + n_channels);
7283
7284 request->n_scan_plans = n_plans;
7285
Luciano Coelho807f8a82011-05-11 17:09:35 +03007286 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007287 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007288 /* user specified, bail out if channel not found */
7289 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007290 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007291 tmp) {
7292 struct ieee80211_channel *chan;
7293
7294 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7295
7296 if (!chan) {
7297 err = -EINVAL;
7298 goto out_free;
7299 }
7300
7301 /* ignore disabled channels */
7302 if (chan->flags & IEEE80211_CHAN_DISABLED)
7303 continue;
7304
7305 request->channels[i] = chan;
7306 i++;
7307 }
7308 } else {
7309 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007310 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007311 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007312
Luciano Coelho807f8a82011-05-11 17:09:35 +03007313 if (!wiphy->bands[band])
7314 continue;
7315 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7316 struct ieee80211_channel *chan;
7317
7318 chan = &wiphy->bands[band]->channels[j];
7319
7320 if (chan->flags & IEEE80211_CHAN_DISABLED)
7321 continue;
7322
7323 request->channels[i] = chan;
7324 i++;
7325 }
7326 }
7327 }
7328
7329 if (!i) {
7330 err = -EINVAL;
7331 goto out_free;
7332 }
7333
7334 request->n_channels = i;
7335
7336 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007337 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007338 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007339 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007340 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007341 err = -EINVAL;
7342 goto out_free;
7343 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007344 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007345 memcpy(request->ssids[i].ssid, nla_data(attr),
7346 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007347 i++;
7348 }
7349 }
7350
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007351 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007352 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007353 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007354 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007355 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007356 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007357
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007358 err = nla_parse_nested(tb,
7359 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007360 attr, nl80211_match_policy,
7361 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007362 if (err)
7363 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007364 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007365 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7366 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007367 if (WARN_ON(i >= n_match_sets)) {
7368 /* this indicates a programming error,
7369 * the loop above should have verified
7370 * things properly
7371 */
7372 err = -EINVAL;
7373 goto out_free;
7374 }
7375
Arend Van Spriel3007e352017-04-21 13:05:01 +01007376 if (ssid) {
7377 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7378 err = -EINVAL;
7379 goto out_free;
7380 }
7381 memcpy(request->match_sets[i].ssid.ssid,
7382 nla_data(ssid), nla_len(ssid));
7383 request->match_sets[i].ssid.ssid_len =
7384 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007385 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007386 if (bssid) {
7387 if (nla_len(bssid) != ETH_ALEN) {
7388 err = -EINVAL;
7389 goto out_free;
7390 }
7391 memcpy(request->match_sets[i].bssid,
7392 nla_data(bssid), ETH_ALEN);
7393 }
7394
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007395 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007396 request->match_sets[i].rssi_thold =
7397 default_match_rssi;
7398 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7399 if (rssi)
7400 request->match_sets[i].rssi_thold =
7401 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007402 }
7403 i++;
7404 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007405
7406 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007407 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007408 request->match_sets[0].rssi_thold = default_match_rssi;
7409
7410 request->min_rssi_thold = INT_MAX;
7411 for (i = 0; i < n_match_sets; i++)
7412 request->min_rssi_thold =
7413 min(request->match_sets[i].rssi_thold,
7414 request->min_rssi_thold);
7415 } else {
7416 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007417 }
7418
Johannes Berg9900e482014-02-04 21:01:25 +01007419 if (ie_len) {
7420 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007421 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007422 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007423 request->ie_len);
7424 }
7425
Roee Zamir2d23d072017-08-06 11:38:22 +03007426 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7427 if (err)
7428 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007429
Luciano Coelho9c748932015-01-16 16:04:09 +02007430 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7431 request->delay =
7432 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7433
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007434 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7435 request->relative_rssi = nla_get_s8(
7436 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7437 request->relative_rssi_set = true;
7438 }
7439
7440 if (request->relative_rssi_set &&
7441 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7442 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7443
7444 rssi_adjust = nla_data(
7445 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7446 request->rssi_adjust.band = rssi_adjust->band;
7447 request->rssi_adjust.delta = rssi_adjust->delta;
7448 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7449 err = -EINVAL;
7450 goto out_free;
7451 }
7452 }
7453
Avraham Stern3b06d272015-10-12 09:51:34 +03007454 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7455 if (err)
7456 goto out_free;
7457
Sam Leffler15d60302012-10-11 21:03:34 -07007458 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007459
Luciano Coelho256da022014-11-10 16:13:46 +02007460 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007461
7462out_free:
7463 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007464 return ERR_PTR(err);
7465}
7466
7467static int nl80211_start_sched_scan(struct sk_buff *skb,
7468 struct genl_info *info)
7469{
7470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7471 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007472 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007473 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007474 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007475 int err;
7476
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007477 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007478 return -EOPNOTSUPP;
7479
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007480 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7481 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7482 if (err)
7483 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007484
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007485 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007486 info->attrs,
7487 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007488
7489 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007490 if (err)
7491 goto out_err;
7492
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007493 /* leave request id zero for legacy request
7494 * or if driver does not support multi-scheduled scan
7495 */
7496 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7497 while (!sched_scan_req->reqid)
7498 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7499 }
7500
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007501 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007502 if (err)
7503 goto out_free;
7504
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007505 sched_scan_req->dev = dev;
7506 sched_scan_req->wiphy = &rdev->wiphy;
7507
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007508 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7509 sched_scan_req->owner_nlportid = info->snd_portid;
7510
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007511 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007512
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007513 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007514 return 0;
7515
7516out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007517 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007518out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007519 return err;
7520}
7521
7522static int nl80211_stop_sched_scan(struct sk_buff *skb,
7523 struct genl_info *info)
7524{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007525 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007527 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007528
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007529 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007530 return -EOPNOTSUPP;
7531
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007532 if (info->attrs[NL80211_ATTR_COOKIE]) {
7533 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7534 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7535 }
7536
7537 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7538 struct cfg80211_sched_scan_request,
7539 list);
7540 if (!req || req->reqid ||
7541 (req->owner_nlportid &&
7542 req->owner_nlportid != info->snd_portid))
7543 return -ENOENT;
7544
7545 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007546}
7547
Simon Wunderlich04f39042013-02-08 18:16:19 +01007548static int nl80211_start_radar_detection(struct sk_buff *skb,
7549 struct genl_info *info)
7550{
7551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7552 struct net_device *dev = info->user_ptr[1];
7553 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007554 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007555 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007556 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007557 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007558 int err;
7559
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007560 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007561 if (dfs_region == NL80211_DFS_UNSET)
7562 return -EINVAL;
7563
Simon Wunderlich04f39042013-02-08 18:16:19 +01007564 err = nl80211_parse_chandef(rdev, info, &chandef);
7565 if (err)
7566 return err;
7567
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007568 if (netif_carrier_ok(dev))
7569 return -EBUSY;
7570
Simon Wunderlich04f39042013-02-08 18:16:19 +01007571 if (wdev->cac_started)
7572 return -EBUSY;
7573
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007574 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007575 if (err < 0)
7576 return err;
7577
7578 if (err == 0)
7579 return -EINVAL;
7580
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007581 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007582 return -EINVAL;
7583
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03007584 /* CAC start is offloaded to HW and can't be started manually */
7585 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
7586 return -EOPNOTSUPP;
7587
Simon Wunderlich04f39042013-02-08 18:16:19 +01007588 if (!rdev->ops->start_radar_detection)
7589 return -EOPNOTSUPP;
7590
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007591 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7592 if (WARN_ON(!cac_time_ms))
7593 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7594
Ilan Peera1056b1b2015-10-22 22:27:46 +03007595 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007596 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007597 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007598 wdev->cac_started = true;
7599 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007600 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007601 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007602 return err;
7603}
7604
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007605static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7606{
7607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7608 struct net_device *dev = info->user_ptr[1];
7609 struct wireless_dev *wdev = dev->ieee80211_ptr;
7610 struct cfg80211_csa_settings params;
7611 /* csa_attrs is defined static to avoid waste of stack size - this
7612 * function is called under RTNL lock, so this should not be a problem.
7613 */
7614 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007615 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007616 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007617 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007618 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007619 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007620
7621 if (!rdev->ops->channel_switch ||
7622 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7623 return -EOPNOTSUPP;
7624
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007625 switch (dev->ieee80211_ptr->iftype) {
7626 case NL80211_IFTYPE_AP:
7627 case NL80211_IFTYPE_P2P_GO:
7628 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007629 /* For all modes except AP the handle_dfs flag needs to be
7630 * supplied to tell the kernel that userspace will handle radar
7631 * events when they happen. Otherwise a switch to a channel
7632 * requiring DFS will be rejected.
7633 */
7634 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007635
7636 /* useless if AP is not running */
7637 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007638 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007639 break;
7640 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007641 if (!wdev->ssid_len)
7642 return -ENOTCONN;
7643 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007644 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007645 if (!wdev->mesh_id_len)
7646 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007647 break;
7648 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007649 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007650 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007651
7652 memset(&params, 0, sizeof(params));
7653
7654 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7655 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7656 return -EINVAL;
7657
7658 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007659 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007660 return -EINVAL;
7661
Luciano Coelho252e07c2014-10-08 09:48:34 +03007662 /* Even though the attribute is u32, the specification says
7663 * u8, so let's make sure we don't overflow.
7664 */
7665 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7666 if (cs_count > 255)
7667 return -EINVAL;
7668
7669 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007670
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007671 if (!need_new_beacon)
7672 goto skip_beacons;
7673
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007674 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7675 if (err)
7676 return err;
7677
7678 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7679 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007680 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007681 if (err)
7682 return err;
7683
7684 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7685 if (err)
7686 return err;
7687
7688 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7689 return -EINVAL;
7690
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007691 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7692 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007693 return -EINVAL;
7694
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007695 params.n_counter_offsets_beacon = len / sizeof(u16);
7696 if (rdev->wiphy.max_num_csa_counters &&
7697 (params.n_counter_offsets_beacon >
7698 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007699 return -EINVAL;
7700
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007701 params.counter_offsets_beacon =
7702 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7703
7704 /* sanity checks - counters should fit and be the same */
7705 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7706 u16 offset = params.counter_offsets_beacon[i];
7707
7708 if (offset >= params.beacon_csa.tail_len)
7709 return -EINVAL;
7710
7711 if (params.beacon_csa.tail[offset] != params.count)
7712 return -EINVAL;
7713 }
7714
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007715 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007716 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7717 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007718 return -EINVAL;
7719
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007720 params.n_counter_offsets_presp = len / sizeof(u16);
7721 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007722 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007723 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007724 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007725
7726 params.counter_offsets_presp =
7727 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7728
7729 /* sanity checks - counters should fit and be the same */
7730 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7731 u16 offset = params.counter_offsets_presp[i];
7732
7733 if (offset >= params.beacon_csa.probe_resp_len)
7734 return -EINVAL;
7735
7736 if (params.beacon_csa.probe_resp[offset] !=
7737 params.count)
7738 return -EINVAL;
7739 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007740 }
7741
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007742skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007743 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7744 if (err)
7745 return err;
7746
Arik Nemtsov923b3522015-07-08 15:41:44 +03007747 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7748 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007749 return -EINVAL;
7750
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007751 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7752 &params.chandef,
7753 wdev->iftype);
7754 if (err < 0)
7755 return err;
7756
Benjamin Berg8d9de162017-05-16 11:23:12 +02007757 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007758 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007759 if (need_handle_dfs_flag &&
7760 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7761 return -EINVAL;
7762 }
7763 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007764
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007765 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7766 params.block_tx = true;
7767
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007768 wdev_lock(wdev);
7769 err = rdev_channel_switch(rdev, dev, &params);
7770 wdev_unlock(wdev);
7771
7772 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007773}
7774
Johannes Berg9720bb32011-06-21 09:45:33 +02007775static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7776 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007777 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007778 struct wireless_dev *wdev,
7779 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007780{
Johannes Berg48ab9052009-07-10 18:42:31 +02007781 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007782 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007783 void *hdr;
7784 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007785
7786 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007787
Eric W. Biederman15e47302012-09-07 20:12:54 +00007788 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007789 NL80211_CMD_NEW_SCAN_RESULTS);
7790 if (!hdr)
7791 return -1;
7792
Michal Kubecek0a833c22017-11-15 13:09:32 +01007793 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02007794
Johannes Berg97990a02013-04-19 01:02:55 +02007795 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7796 goto nla_put_failure;
7797 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007798 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7799 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007800 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7801 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007802 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007803
7804 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7805 if (!bss)
7806 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007807 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007808 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007809 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007810
7811 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007812 /* indicate whether we have probe response data or not */
7813 if (rcu_access_pointer(res->proberesp_ies) &&
7814 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7815 goto fail_unlock_rcu;
7816
7817 /* this pointer prefers to be pointed to probe response data
7818 * but is always valid
7819 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007820 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007821 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007822 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7823 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007824 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007825 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7826 ies->len, ies->data))
7827 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007828 }
Johannes Berg0e227082014-08-12 20:34:30 +02007829
7830 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007831 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007832 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007833 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7834 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007835 goto fail_unlock_rcu;
7836 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7837 ies->len, ies->data))
7838 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007839 }
7840 rcu_read_unlock();
7841
David S. Miller9360ffd2012-03-29 04:41:26 -04007842 if (res->beacon_interval &&
7843 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7844 goto nla_put_failure;
7845 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7846 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007847 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007848 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7849 jiffies_to_msecs(jiffies - intbss->ts)))
7850 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007851
Avraham Stern1d762502016-07-05 17:10:13 +03007852 if (intbss->parent_tsf &&
7853 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7854 intbss->parent_tsf, NL80211_BSS_PAD) ||
7855 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7856 intbss->parent_bssid)))
7857 goto nla_put_failure;
7858
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007859 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007860 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7861 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007862 goto nla_put_failure;
7863
Sunil Dutt983dafa2017-12-13 19:51:36 +02007864 if (!nl80211_put_signal(msg, intbss->pub.chains,
7865 intbss->pub.chain_signal,
7866 NL80211_BSS_CHAIN_SIGNAL))
7867 goto nla_put_failure;
7868
Johannes Berg77965c972009-02-18 18:45:06 +01007869 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007870 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007871 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7872 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007873 break;
7874 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007875 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7876 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007877 break;
7878 default:
7879 break;
7880 }
7881
Johannes Berg48ab9052009-07-10 18:42:31 +02007882 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007883 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007884 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007885 if (intbss == wdev->current_bss &&
7886 nla_put_u32(msg, NL80211_BSS_STATUS,
7887 NL80211_BSS_STATUS_ASSOCIATED))
7888 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007889 break;
7890 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007891 if (intbss == wdev->current_bss &&
7892 nla_put_u32(msg, NL80211_BSS_STATUS,
7893 NL80211_BSS_STATUS_IBSS_JOINED))
7894 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007895 break;
7896 default:
7897 break;
7898 }
7899
Johannes Berg2a519312009-02-10 21:25:55 +01007900 nla_nest_end(msg, bss);
7901
Johannes Berg053c0952015-01-16 22:09:00 +01007902 genlmsg_end(msg, hdr);
7903 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007904
Johannes Berg8cef2c92013-02-05 16:54:31 +01007905 fail_unlock_rcu:
7906 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007907 nla_put_failure:
7908 genlmsg_cancel(msg, hdr);
7909 return -EMSGSIZE;
7910}
7911
Johannes Berg97990a02013-04-19 01:02:55 +02007912static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007913{
Johannes Berg48ab9052009-07-10 18:42:31 +02007914 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007915 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007916 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007917 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007918 int err;
7919
Johannes Bergea90e0d2017-03-15 14:26:04 +01007920 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007921 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007922 if (err) {
7923 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007924 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007925 }
Johannes Berg2a519312009-02-10 21:25:55 +01007926
Johannes Berg48ab9052009-07-10 18:42:31 +02007927 wdev_lock(wdev);
7928 spin_lock_bh(&rdev->bss_lock);
7929 cfg80211_bss_expire(rdev);
7930
Johannes Berg9720bb32011-06-21 09:45:33 +02007931 cb->seq = rdev->bss_generation;
7932
Johannes Berg48ab9052009-07-10 18:42:31 +02007933 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007934 if (++idx <= start)
7935 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007936 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007937 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007938 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007939 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007940 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007941 }
7942 }
7943
Johannes Berg48ab9052009-07-10 18:42:31 +02007944 spin_unlock_bh(&rdev->bss_lock);
7945 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007946
Johannes Berg97990a02013-04-19 01:02:55 +02007947 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007948 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007949
Johannes Berg67748892010-10-04 21:14:06 +02007950 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007951}
7952
Eric W. Biederman15e47302012-09-07 20:12:54 +00007953static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007954 int flags, struct net_device *dev,
7955 bool allow_radio_stats,
7956 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007957{
7958 void *hdr;
7959 struct nlattr *infoattr;
7960
Johannes Berg11f78ac2014-11-14 16:43:50 +01007961 /* skip radio stats if userspace didn't request them */
7962 if (!survey->channel && !allow_radio_stats)
7963 return 0;
7964
Eric W. Biederman15e47302012-09-07 20:12:54 +00007965 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007966 NL80211_CMD_NEW_SURVEY_RESULTS);
7967 if (!hdr)
7968 return -ENOMEM;
7969
David S. Miller9360ffd2012-03-29 04:41:26 -04007970 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7971 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007972
7973 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7974 if (!infoattr)
7975 goto nla_put_failure;
7976
Johannes Berg11f78ac2014-11-14 16:43:50 +01007977 if (survey->channel &&
7978 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007979 survey->channel->center_freq))
7980 goto nla_put_failure;
7981
7982 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7983 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7984 goto nla_put_failure;
7985 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7986 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7987 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007988 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007989 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7990 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007991 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007992 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007993 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7994 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007995 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007996 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007997 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7998 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007999 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008000 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008001 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8002 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008003 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01008004 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008005 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8006 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008007 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01008008 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008009 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8010 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01008011 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008012
8013 nla_nest_end(msg, infoattr);
8014
Johannes Berg053c0952015-01-16 22:09:00 +01008015 genlmsg_end(msg, hdr);
8016 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01008017
8018 nla_put_failure:
8019 genlmsg_cancel(msg, hdr);
8020 return -EMSGSIZE;
8021}
8022
Johannes Berg11f78ac2014-11-14 16:43:50 +01008023static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01008024{
Johannes Bergc90c39d2016-10-24 14:40:01 +02008025 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01008026 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008027 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008028 struct wireless_dev *wdev;
8029 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01008030 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01008031 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01008032
Johannes Bergea90e0d2017-03-15 14:26:04 +01008033 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008034 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02008035 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01008036 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01008037
Johannes Berg11f78ac2014-11-14 16:43:50 +01008038 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02008039 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01008040
Johannes Berg97990a02013-04-19 01:02:55 +02008041 if (!wdev->netdev) {
8042 res = -EINVAL;
8043 goto out_err;
8044 }
8045
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008046 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01008047 res = -EOPNOTSUPP;
8048 goto out_err;
8049 }
8050
8051 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008052 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008053 if (res == -ENOENT)
8054 break;
8055 if (res)
8056 goto out_err;
8057
Johannes Berg11f78ac2014-11-14 16:43:50 +01008058 /* don't send disabled channels, but do send non-channel data */
8059 if (survey.channel &&
8060 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008061 survey_idx++;
8062 continue;
8063 }
8064
Holger Schurig61fa7132009-11-11 12:25:40 +01008065 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008066 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008067 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008068 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008069 goto out;
8070 survey_idx++;
8071 }
8072
8073 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008074 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008075 res = skb->len;
8076 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008077 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008078 return res;
8079}
8080
Samuel Ortizb23aa672009-07-01 21:26:54 +02008081static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8082{
8083 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8084 NL80211_WPA_VERSION_2));
8085}
8086
Jouni Malinen636a5d32009-03-19 13:39:22 +02008087static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8088{
Johannes Berg4c476992010-10-04 21:36:35 +02008089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8090 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008091 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008092 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8093 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008094 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008095 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008096 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008097
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008098 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8099 return -EINVAL;
8100
8101 if (!info->attrs[NL80211_ATTR_MAC])
8102 return -EINVAL;
8103
Jouni Malinen17780922009-03-27 20:52:47 +02008104 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8105 return -EINVAL;
8106
Johannes Berg19957bb2009-07-02 17:20:43 +02008107 if (!info->attrs[NL80211_ATTR_SSID])
8108 return -EINVAL;
8109
8110 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8111 return -EINVAL;
8112
Johannes Bergfffd0932009-07-08 14:22:54 +02008113 err = nl80211_parse_key(info, &key);
8114 if (err)
8115 return err;
8116
8117 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008118 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8119 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008120 if (!key.p.key || !key.p.key_len)
8121 return -EINVAL;
8122 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8123 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8124 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8125 key.p.key_len != WLAN_KEY_LEN_WEP104))
8126 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008127 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008128 return -EINVAL;
8129 } else {
8130 key.p.key_len = 0;
8131 key.p.key = NULL;
8132 }
8133
Johannes Bergafea0b72010-08-10 09:46:42 +02008134 if (key.idx >= 0) {
8135 int i;
8136 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008137
Johannes Bergafea0b72010-08-10 09:46:42 +02008138 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8139 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8140 ok = true;
8141 break;
8142 }
8143 }
Johannes Berg4c476992010-10-04 21:36:35 +02008144 if (!ok)
8145 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008146 }
8147
Johannes Berg4c476992010-10-04 21:36:35 +02008148 if (!rdev->ops->auth)
8149 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008150
Johannes Berg074ac8d2010-09-16 14:58:22 +02008151 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008152 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8153 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008154
Johannes Berg19957bb2009-07-02 17:20:43 +02008155 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008156 chan = nl80211_get_valid_chan(&rdev->wiphy,
8157 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8158 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008159 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008160
Johannes Berg19957bb2009-07-02 17:20:43 +02008161 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8162 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8163
8164 if (info->attrs[NL80211_ATTR_IE]) {
8165 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8166 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8167 }
8168
8169 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008170 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008171 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008172
Jouni Malinen63181062016-10-27 00:42:02 +03008173 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8174 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8175 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8176 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008177 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008178 return -EINVAL;
8179
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008180 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008181 if (auth_type != NL80211_AUTHTYPE_SAE &&
8182 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8183 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8184 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008185 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008186 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8187 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008188 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008189 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008190 return -EINVAL;
8191 }
8192
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008193 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8194
Johannes Berg95de8172012-01-20 13:55:25 +01008195 /*
8196 * Since we no longer track auth state, ignore
8197 * requests to only change local state.
8198 */
8199 if (local_state_change)
8200 return 0;
8201
Johannes Berg91bf9b22013-05-15 17:44:01 +02008202 wdev_lock(dev->ieee80211_ptr);
8203 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8204 ssid, ssid_len, ie, ie_len,
8205 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008206 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008207 wdev_unlock(dev->ieee80211_ptr);
8208 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008209}
8210
Johannes Bergc0692b82010-08-27 14:26:53 +03008211static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8212 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008213 struct cfg80211_crypto_settings *settings,
8214 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008215{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008216 memset(settings, 0, sizeof(*settings));
8217
Samuel Ortizb23aa672009-07-01 21:26:54 +02008218 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8219
Johannes Bergc0692b82010-08-27 14:26:53 +03008220 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8221 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008222
Johannes Bergc0692b82010-08-27 14:26:53 +03008223 proto = nla_get_u16(
8224 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8225 settings->control_port_ethertype = cpu_to_be16(proto);
8226 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8227 proto != ETH_P_PAE)
8228 return -EINVAL;
8229 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8230 settings->control_port_no_encrypt = true;
8231 } else
8232 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8233
Samuel Ortizb23aa672009-07-01 21:26:54 +02008234 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8235 void *data;
8236 int len, i;
8237
8238 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8239 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8240 settings->n_ciphers_pairwise = len / sizeof(u32);
8241
8242 if (len % sizeof(u32))
8243 return -EINVAL;
8244
Johannes Berg3dc27d22009-07-02 21:36:37 +02008245 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008246 return -EINVAL;
8247
8248 memcpy(settings->ciphers_pairwise, data, len);
8249
8250 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008251 if (!cfg80211_supported_cipher_suite(
8252 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008253 settings->ciphers_pairwise[i]))
8254 return -EINVAL;
8255 }
8256
8257 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8258 settings->cipher_group =
8259 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008260 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8261 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008262 return -EINVAL;
8263 }
8264
8265 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8266 settings->wpa_versions =
8267 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8268 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8269 return -EINVAL;
8270 }
8271
8272 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8273 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008274 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008275
8276 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8277 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8278 settings->n_akm_suites = len / sizeof(u32);
8279
8280 if (len % sizeof(u32))
8281 return -EINVAL;
8282
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008283 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8284 return -EINVAL;
8285
Samuel Ortizb23aa672009-07-01 21:26:54 +02008286 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008287 }
8288
Eliad Peller91b5ab62017-06-09 13:08:42 +01008289 if (info->attrs[NL80211_ATTR_PMK]) {
8290 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8291 return -EINVAL;
8292 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8293 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8294 return -EINVAL;
8295 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8296 }
8297
Samuel Ortizb23aa672009-07-01 21:26:54 +02008298 return 0;
8299}
8300
Jouni Malinen636a5d32009-03-19 13:39:22 +02008301static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8302{
Johannes Berg4c476992010-10-04 21:36:35 +02008303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8304 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008305 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008306 struct cfg80211_assoc_request req = {};
8307 const u8 *bssid, *ssid;
8308 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008309
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008310 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8311 return -EINVAL;
8312
8313 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008314 !info->attrs[NL80211_ATTR_SSID] ||
8315 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008316 return -EINVAL;
8317
Johannes Berg4c476992010-10-04 21:36:35 +02008318 if (!rdev->ops->assoc)
8319 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008320
Johannes Berg074ac8d2010-09-16 14:58:22 +02008321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008322 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8323 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008324
Johannes Berg19957bb2009-07-02 17:20:43 +02008325 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008326
Jouni Malinen664834d2014-01-15 00:01:44 +02008327 chan = nl80211_get_valid_chan(&rdev->wiphy,
8328 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8329 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008330 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008331
Johannes Berg19957bb2009-07-02 17:20:43 +02008332 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8333 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008334
8335 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008336 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8337 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008338 }
8339
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008340 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008341 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008342 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008343 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008344 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008345 else if (mfp != NL80211_MFP_NO)
8346 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008347 }
8348
Johannes Berg3e5d7642009-07-07 14:37:26 +02008349 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008350 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008351
Ben Greear7e7c8922011-11-18 11:31:59 -08008352 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008353 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008354
8355 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008356 memcpy(&req.ht_capa_mask,
8357 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8358 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008359
8360 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008361 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008362 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008363 memcpy(&req.ht_capa,
8364 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8365 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008366 }
8367
Johannes Bergee2aca32013-02-21 17:36:01 +01008368 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008369 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008370
8371 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008372 memcpy(&req.vht_capa_mask,
8373 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8374 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008375
8376 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008377 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008378 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008379 memcpy(&req.vht_capa,
8380 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8381 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008382 }
8383
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008384 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008385 if (!((rdev->wiphy.features &
8386 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8387 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8388 !wiphy_ext_feature_isset(&rdev->wiphy,
8389 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008390 return -EINVAL;
8391 req.flags |= ASSOC_REQ_USE_RRM;
8392 }
8393
Jouni Malinen348bd452016-10-27 00:42:03 +03008394 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8395 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8396 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8397 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8398 return -EINVAL;
8399 req.fils_nonces =
8400 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8401 }
8402
Johannes Bergf62fab72013-02-21 20:09:09 +01008403 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008404 if (!err) {
8405 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008406
Johannes Bergf62fab72013-02-21 20:09:09 +01008407 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8408 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008409
8410 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8411 dev->ieee80211_ptr->conn_owner_nlportid =
8412 info->snd_portid;
8413 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8414 bssid, ETH_ALEN);
8415 }
8416
Johannes Berg91bf9b22013-05-15 17:44:01 +02008417 wdev_unlock(dev->ieee80211_ptr);
8418 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008419
Jouni Malinen636a5d32009-03-19 13:39:22 +02008420 return err;
8421}
8422
8423static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8424{
Johannes Berg4c476992010-10-04 21:36:35 +02008425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8426 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008427 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008428 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008429 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008430 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008431
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008432 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8433 return -EINVAL;
8434
8435 if (!info->attrs[NL80211_ATTR_MAC])
8436 return -EINVAL;
8437
8438 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8439 return -EINVAL;
8440
Johannes Berg4c476992010-10-04 21:36:35 +02008441 if (!rdev->ops->deauth)
8442 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008443
Johannes Berg074ac8d2010-09-16 14:58:22 +02008444 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008445 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8446 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008447
Johannes Berg19957bb2009-07-02 17:20:43 +02008448 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008449
Johannes Berg19957bb2009-07-02 17:20:43 +02008450 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8451 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008452 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008453 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008454 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008455
8456 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008457 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8458 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008459 }
8460
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008461 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8462
Johannes Berg91bf9b22013-05-15 17:44:01 +02008463 wdev_lock(dev->ieee80211_ptr);
8464 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8465 local_state_change);
8466 wdev_unlock(dev->ieee80211_ptr);
8467 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008468}
8469
8470static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8471{
Johannes Berg4c476992010-10-04 21:36:35 +02008472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8473 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008474 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008475 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008476 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008477 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008478
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008479 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8480 return -EINVAL;
8481
8482 if (!info->attrs[NL80211_ATTR_MAC])
8483 return -EINVAL;
8484
8485 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8486 return -EINVAL;
8487
Johannes Berg4c476992010-10-04 21:36:35 +02008488 if (!rdev->ops->disassoc)
8489 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008490
Johannes Berg074ac8d2010-09-16 14:58:22 +02008491 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008492 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8493 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008494
Johannes Berg19957bb2009-07-02 17:20:43 +02008495 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008496
Johannes Berg19957bb2009-07-02 17:20:43 +02008497 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8498 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008499 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008500 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008501 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008502
8503 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008504 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8505 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008506 }
8507
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008508 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8509
Johannes Berg91bf9b22013-05-15 17:44:01 +02008510 wdev_lock(dev->ieee80211_ptr);
8511 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8512 local_state_change);
8513 wdev_unlock(dev->ieee80211_ptr);
8514 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008515}
8516
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008517static bool
8518nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008519 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008520 int rateval)
8521{
8522 struct wiphy *wiphy = &rdev->wiphy;
8523 bool found = false;
8524 int band, i;
8525
Johannes Berg57fbcce2016-04-12 15:56:15 +02008526 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008527 struct ieee80211_supported_band *sband;
8528
8529 sband = wiphy->bands[band];
8530 if (!sband)
8531 continue;
8532
8533 for (i = 0; i < sband->n_bitrates; i++) {
8534 if (sband->bitrates[i].bitrate == rateval) {
8535 mcast_rate[band] = i + 1;
8536 found = true;
8537 break;
8538 }
8539 }
8540 }
8541
8542 return found;
8543}
8544
Johannes Berg04a773a2009-04-19 21:24:32 +02008545static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8546{
Johannes Berg4c476992010-10-04 21:36:35 +02008547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8548 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008549 struct cfg80211_ibss_params ibss;
8550 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008551 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008552 int err;
8553
Johannes Berg8e30bc52009-04-22 17:45:38 +02008554 memset(&ibss, 0, sizeof(ibss));
8555
Johannes Berg04a773a2009-04-19 21:24:32 +02008556 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8557 return -EINVAL;
8558
Johannes Berg683b6d32012-11-08 21:25:48 +01008559 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008560 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8561 return -EINVAL;
8562
Johannes Berg8e30bc52009-04-22 17:45:38 +02008563 ibss.beacon_interval = 100;
8564
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308565 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008566 ibss.beacon_interval =
8567 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308568
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308569 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8570 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308571 if (err)
8572 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008573
Johannes Berg4c476992010-10-04 21:36:35 +02008574 if (!rdev->ops->join_ibss)
8575 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008576
Johannes Berg4c476992010-10-04 21:36:35 +02008577 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8578 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008579
Johannes Berg79c97e92009-07-07 03:56:12 +02008580 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008581
Johannes Berg39193492011-09-16 13:45:25 +02008582 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008583 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008584
8585 if (!is_valid_ether_addr(ibss.bssid))
8586 return -EINVAL;
8587 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008588 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8589 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8590
8591 if (info->attrs[NL80211_ATTR_IE]) {
8592 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8593 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8594 }
8595
Johannes Berg683b6d32012-11-08 21:25:48 +01008596 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8597 if (err)
8598 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008599
Ilan Peer174e0cd2014-02-23 09:13:01 +02008600 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8601 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008602 return -EINVAL;
8603
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008604 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008605 case NL80211_CHAN_WIDTH_5:
8606 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008607 case NL80211_CHAN_WIDTH_20_NOHT:
8608 break;
8609 case NL80211_CHAN_WIDTH_20:
8610 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008611 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8612 return -EINVAL;
8613 break;
8614 case NL80211_CHAN_WIDTH_80:
8615 case NL80211_CHAN_WIDTH_80P80:
8616 case NL80211_CHAN_WIDTH_160:
8617 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8618 return -EINVAL;
8619 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8620 NL80211_EXT_FEATURE_VHT_IBSS))
8621 return -EINVAL;
8622 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008623 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008624 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008625 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008626
Johannes Berg04a773a2009-04-19 21:24:32 +02008627 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008628 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008629
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008630 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8631 u8 *rates =
8632 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8633 int n_rates =
8634 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8635 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008636 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008637
Johannes Berg34850ab2011-07-18 18:08:35 +02008638 err = ieee80211_get_ratemask(sband, rates, n_rates,
8639 &ibss.basic_rates);
8640 if (err)
8641 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008642 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008643
Simon Wunderlich803768f2013-06-28 10:39:58 +02008644 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8645 memcpy(&ibss.ht_capa_mask,
8646 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8647 sizeof(ibss.ht_capa_mask));
8648
8649 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8650 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8651 return -EINVAL;
8652 memcpy(&ibss.ht_capa,
8653 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8654 sizeof(ibss.ht_capa));
8655 }
8656
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008657 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8658 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8659 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8660 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008661
Johannes Berg4c476992010-10-04 21:36:35 +02008662 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308663 bool no_ht = false;
8664
Johannes Berg768075e2017-11-13 15:35:06 +01008665 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008666 if (IS_ERR(connkeys))
8667 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308668
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008669 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8670 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008671 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308672 return -EINVAL;
8673 }
Johannes Berg4c476992010-10-04 21:36:35 +02008674 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008675
Antonio Quartulli267335d2012-01-31 20:25:47 +01008676 ibss.control_port =
8677 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8678
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008679 ibss.userspace_handles_dfs =
8680 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8681
Denis Kenziorf8d16d32018-03-26 12:52:45 -05008682 wdev_lock(dev->ieee80211_ptr);
8683 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008684 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008685 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05008686 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8687 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8688 wdev_unlock(dev->ieee80211_ptr);
8689
Johannes Berg04a773a2009-04-19 21:24:32 +02008690 return err;
8691}
8692
8693static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8694{
Johannes Berg4c476992010-10-04 21:36:35 +02008695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8696 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008697
Johannes Berg4c476992010-10-04 21:36:35 +02008698 if (!rdev->ops->leave_ibss)
8699 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008700
Johannes Berg4c476992010-10-04 21:36:35 +02008701 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8702 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008703
Johannes Berg4c476992010-10-04 21:36:35 +02008704 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008705}
8706
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008707static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8708{
8709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8710 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008711 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008712 u32 nla_rate;
8713 int err;
8714
8715 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008716 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8717 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008718 return -EOPNOTSUPP;
8719
8720 if (!rdev->ops->set_mcast_rate)
8721 return -EOPNOTSUPP;
8722
8723 memset(mcast_rate, 0, sizeof(mcast_rate));
8724
8725 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8726 return -EINVAL;
8727
8728 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8729 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8730 return -EINVAL;
8731
Ilan Peera1056b1b2015-10-22 22:27:46 +03008732 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008733
8734 return err;
8735}
8736
Johannes Bergad7e7182013-11-13 13:37:47 +01008737static struct sk_buff *
8738__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008739 struct wireless_dev *wdev, int approxlen,
8740 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008741 enum nl80211_attrs attr,
8742 const struct nl80211_vendor_cmd_info *info,
8743 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008744{
8745 struct sk_buff *skb;
8746 void *hdr;
8747 struct nlattr *data;
8748
8749 skb = nlmsg_new(approxlen + 100, gfp);
8750 if (!skb)
8751 return NULL;
8752
8753 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8754 if (!hdr) {
8755 kfree_skb(skb);
8756 return NULL;
8757 }
8758
8759 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8760 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008761
8762 if (info) {
8763 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8764 info->vendor_id))
8765 goto nla_put_failure;
8766 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8767 info->subcmd))
8768 goto nla_put_failure;
8769 }
8770
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008771 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008772 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8773 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008774 goto nla_put_failure;
8775 if (wdev->netdev &&
8776 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8777 wdev->netdev->ifindex))
8778 goto nla_put_failure;
8779 }
8780
Johannes Bergad7e7182013-11-13 13:37:47 +01008781 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008782 if (!data)
8783 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008784
8785 ((void **)skb->cb)[0] = rdev;
8786 ((void **)skb->cb)[1] = hdr;
8787 ((void **)skb->cb)[2] = data;
8788
8789 return skb;
8790
8791 nla_put_failure:
8792 kfree_skb(skb);
8793 return NULL;
8794}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008795
Johannes Berge03ad6e2014-01-01 17:22:30 +01008796struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008797 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008798 enum nl80211_commands cmd,
8799 enum nl80211_attrs attr,
8800 int vendor_event_idx,
8801 int approxlen, gfp_t gfp)
8802{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008803 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008804 const struct nl80211_vendor_cmd_info *info;
8805
8806 switch (cmd) {
8807 case NL80211_CMD_TESTMODE:
8808 if (WARN_ON(vendor_event_idx != -1))
8809 return NULL;
8810 info = NULL;
8811 break;
8812 case NL80211_CMD_VENDOR:
8813 if (WARN_ON(vendor_event_idx < 0 ||
8814 vendor_event_idx >= wiphy->n_vendor_events))
8815 return NULL;
8816 info = &wiphy->vendor_events[vendor_event_idx];
8817 break;
8818 default:
8819 WARN_ON(1);
8820 return NULL;
8821 }
8822
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008823 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008824 cmd, attr, info, gfp);
8825}
8826EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8827
8828void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8829{
8830 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8831 void *hdr = ((void **)skb->cb)[1];
8832 struct nlattr *data = ((void **)skb->cb)[2];
8833 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8834
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008835 /* clear CB data for netlink core to own from now on */
8836 memset(skb->cb, 0, sizeof(skb->cb));
8837
Johannes Berge03ad6e2014-01-01 17:22:30 +01008838 nla_nest_end(skb, data);
8839 genlmsg_end(skb, hdr);
8840
8841 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8842 mcgrp = NL80211_MCGRP_VENDOR;
8843
8844 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8845 mcgrp, gfp);
8846}
8847EXPORT_SYMBOL(__cfg80211_send_event_skb);
8848
Johannes Bergaff89a92009-07-01 21:26:51 +02008849#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008850static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8851{
Johannes Berg4c476992010-10-04 21:36:35 +02008852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008853 struct wireless_dev *wdev =
8854 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008855 int err;
8856
David Spinadelfc73f112013-07-31 18:04:15 +03008857 if (!rdev->ops->testmode_cmd)
8858 return -EOPNOTSUPP;
8859
8860 if (IS_ERR(wdev)) {
8861 err = PTR_ERR(wdev);
8862 if (err != -EINVAL)
8863 return err;
8864 wdev = NULL;
8865 } else if (wdev->wiphy != &rdev->wiphy) {
8866 return -EINVAL;
8867 }
8868
Johannes Bergaff89a92009-07-01 21:26:51 +02008869 if (!info->attrs[NL80211_ATTR_TESTDATA])
8870 return -EINVAL;
8871
Johannes Bergad7e7182013-11-13 13:37:47 +01008872 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008873 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008874 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8875 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008876 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008877
Johannes Bergaff89a92009-07-01 21:26:51 +02008878 return err;
8879}
8880
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008881static int nl80211_testmode_dump(struct sk_buff *skb,
8882 struct netlink_callback *cb)
8883{
Johannes Berg00918d32011-12-13 17:22:05 +01008884 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008885 int err;
8886 long phy_idx;
8887 void *data = NULL;
8888 int data_len = 0;
8889
Johannes Berg5fe231e2013-05-08 21:45:15 +02008890 rtnl_lock();
8891
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008892 if (cb->args[0]) {
8893 /*
8894 * 0 is a valid index, but not valid for args[0],
8895 * so we need to offset by 1.
8896 */
8897 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008898
8899 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8900 if (!rdev) {
8901 err = -ENOENT;
8902 goto out_err;
8903 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008904 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008905 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8906
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008907 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008908 attrbuf, nl80211_fam.maxattr,
8909 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008910 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008911 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008912
Johannes Bergc90c39d2016-10-24 14:40:01 +02008913 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008914 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008915 err = PTR_ERR(rdev);
8916 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008917 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008918 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008919
Johannes Bergc90c39d2016-10-24 14:40:01 +02008920 if (attrbuf[NL80211_ATTR_TESTDATA])
8921 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008922 }
8923
8924 if (cb->args[1]) {
8925 data = nla_data((void *)cb->args[1]);
8926 data_len = nla_len((void *)cb->args[1]);
8927 }
8928
Johannes Berg00918d32011-12-13 17:22:05 +01008929 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008930 err = -EOPNOTSUPP;
8931 goto out_err;
8932 }
8933
8934 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008935 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008936 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8937 NL80211_CMD_TESTMODE);
8938 struct nlattr *tmdata;
8939
Dan Carpentercb35fba2013-08-14 14:50:01 +03008940 if (!hdr)
8941 break;
8942
David S. Miller9360ffd2012-03-29 04:41:26 -04008943 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008944 genlmsg_cancel(skb, hdr);
8945 break;
8946 }
8947
8948 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8949 if (!tmdata) {
8950 genlmsg_cancel(skb, hdr);
8951 break;
8952 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008953 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008954 nla_nest_end(skb, tmdata);
8955
8956 if (err == -ENOBUFS || err == -ENOENT) {
8957 genlmsg_cancel(skb, hdr);
8958 break;
8959 } else if (err) {
8960 genlmsg_cancel(skb, hdr);
8961 goto out_err;
8962 }
8963
8964 genlmsg_end(skb, hdr);
8965 }
8966
8967 err = skb->len;
8968 /* see above */
8969 cb->args[0] = phy_idx + 1;
8970 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008971 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008972 return err;
8973}
Johannes Bergaff89a92009-07-01 21:26:51 +02008974#endif
8975
Samuel Ortizb23aa672009-07-01 21:26:54 +02008976static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8977{
Johannes Berg4c476992010-10-04 21:36:35 +02008978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8979 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008980 struct cfg80211_connect_params connect;
8981 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008982 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008983 int err;
8984
8985 memset(&connect, 0, sizeof(connect));
8986
8987 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8988 return -EINVAL;
8989
8990 if (!info->attrs[NL80211_ATTR_SSID] ||
8991 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8992 return -EINVAL;
8993
8994 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8995 connect.auth_type =
8996 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008997 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8998 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008999 return -EINVAL;
9000 } else
9001 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9002
9003 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9004
Avraham Stern3a00df52017-06-09 13:08:43 +01009005 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9006 !wiphy_ext_feature_isset(&rdev->wiphy,
9007 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9008 return -EINVAL;
9009 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9010
Johannes Bergc0692b82010-08-27 14:26:53 +03009011 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009012 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009013 if (err)
9014 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009015
Johannes Berg074ac8d2010-09-16 14:58:22 +02009016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009017 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9018 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009019
Johannes Berg79c97e92009-07-07 03:56:12 +02009020 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009021
Bala Shanmugam4486ea92012-03-07 17:27:12 +05309022 connect.bg_scan_period = -1;
9023 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9024 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9025 connect.bg_scan_period =
9026 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9027 }
9028
Samuel Ortizb23aa672009-07-01 21:26:54 +02009029 if (info->attrs[NL80211_ATTR_MAC])
9030 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02009031 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9032 connect.bssid_hint =
9033 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009034 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9035 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9036
9037 if (info->attrs[NL80211_ATTR_IE]) {
9038 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9039 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9040 }
9041
Jouni Malinencee00a92013-01-15 17:15:57 +02009042 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9043 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009044 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9045 !wiphy_ext_feature_isset(&rdev->wiphy,
9046 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9047 return -EOPNOTSUPP;
9048
Jouni Malinencee00a92013-01-15 17:15:57 +02009049 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03009050 connect.mfp != NL80211_MFP_NO &&
9051 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02009052 return -EINVAL;
9053 } else {
9054 connect.mfp = NL80211_MFP_NO;
9055 }
9056
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009057 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9058 connect.prev_bssid =
9059 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9060
Samuel Ortizb23aa672009-07-01 21:26:54 +02009061 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009062 connect.channel = nl80211_get_valid_chan(
9063 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9064 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009065 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009066 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009067 connect.channel_hint = nl80211_get_valid_chan(
9068 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9069 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009070 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009071 }
9072
Johannes Bergfffd0932009-07-08 14:22:54 +02009073 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +01009074 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009075 if (IS_ERR(connkeys))
9076 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009077 }
9078
Ben Greear7e7c8922011-11-18 11:31:59 -08009079 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9080 connect.flags |= ASSOC_REQ_DISABLE_HT;
9081
9082 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9083 memcpy(&connect.ht_capa_mask,
9084 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9085 sizeof(connect.ht_capa_mask));
9086
9087 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009088 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009089 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009090 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009091 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009092 memcpy(&connect.ht_capa,
9093 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9094 sizeof(connect.ht_capa));
9095 }
9096
Johannes Bergee2aca32013-02-21 17:36:01 +01009097 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9098 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9099
9100 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9101 memcpy(&connect.vht_capa_mask,
9102 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9103 sizeof(connect.vht_capa_mask));
9104
9105 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9106 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009107 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009108 return -EINVAL;
9109 }
9110 memcpy(&connect.vht_capa,
9111 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9112 sizeof(connect.vht_capa));
9113 }
9114
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009115 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009116 if (!((rdev->wiphy.features &
9117 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9118 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9119 !wiphy_ext_feature_isset(&rdev->wiphy,
9120 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009121 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009122 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009123 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009124 connect.flags |= ASSOC_REQ_USE_RRM;
9125 }
9126
Lior David34d50512016-01-28 10:58:25 +02009127 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009128 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009129 kzfree(connkeys);
9130 return -EOPNOTSUPP;
9131 }
9132
Arend van Spriel38de03d2016-03-02 20:37:18 +01009133 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9134 /* bss selection makes no sense if bssid is set */
9135 if (connect.bssid) {
9136 kzfree(connkeys);
9137 return -EINVAL;
9138 }
9139
9140 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9141 wiphy, &connect.bss_select);
9142 if (err) {
9143 kzfree(connkeys);
9144 return err;
9145 }
9146 }
9147
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009148 if (wiphy_ext_feature_isset(&rdev->wiphy,
9149 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9150 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9151 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9152 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9153 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9154 connect.fils_erp_username =
9155 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9156 connect.fils_erp_username_len =
9157 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9158 connect.fils_erp_realm =
9159 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9160 connect.fils_erp_realm_len =
9161 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9162 connect.fils_erp_next_seq_num =
9163 nla_get_u16(
9164 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9165 connect.fils_erp_rrk =
9166 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9167 connect.fils_erp_rrk_len =
9168 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9169 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9170 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9171 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9172 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9173 kzfree(connkeys);
9174 return -EINVAL;
9175 }
9176
Srinivas Dasari40cbfa92018-01-25 17:13:38 +02009177 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
9178 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9179 GENL_SET_ERR_MSG(info,
9180 "external auth requires connection ownership");
9181 return -EINVAL;
9182 }
9183 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
9184 }
9185
Johannes Berg83739b02013-05-15 17:44:01 +02009186 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009187
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009188 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9189 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009190 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009191 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009192
9193 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9194 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9195 if (connect.bssid)
9196 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9197 connect.bssid, ETH_ALEN);
9198 else
9199 memset(dev->ieee80211_ptr->disconnect_bssid,
9200 0, ETH_ALEN);
9201 }
9202
9203 wdev_unlock(dev->ieee80211_ptr);
9204
Samuel Ortizb23aa672009-07-01 21:26:54 +02009205 return err;
9206}
9207
vamsi krishna088e8df2016-10-27 16:51:11 +03009208static int nl80211_update_connect_params(struct sk_buff *skb,
9209 struct genl_info *info)
9210{
9211 struct cfg80211_connect_params connect = {};
9212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9213 struct net_device *dev = info->user_ptr[1];
9214 struct wireless_dev *wdev = dev->ieee80211_ptr;
9215 u32 changed = 0;
9216 int ret;
9217
9218 if (!rdev->ops->update_connect_params)
9219 return -EOPNOTSUPP;
9220
9221 if (info->attrs[NL80211_ATTR_IE]) {
9222 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9223 return -EINVAL;
9224 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9225 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9226 changed |= UPDATE_ASSOC_IES;
9227 }
9228
9229 wdev_lock(dev->ieee80211_ptr);
9230 if (!wdev->current_bss)
9231 ret = -ENOLINK;
9232 else
9233 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9234 wdev_unlock(dev->ieee80211_ptr);
9235
9236 return ret;
9237}
9238
Samuel Ortizb23aa672009-07-01 21:26:54 +02009239static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9240{
Johannes Berg4c476992010-10-04 21:36:35 +02009241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9242 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009243 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009244 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009245
9246 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9247 reason = WLAN_REASON_DEAUTH_LEAVING;
9248 else
9249 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9250
9251 if (reason == 0)
9252 return -EINVAL;
9253
Johannes Berg074ac8d2010-09-16 14:58:22 +02009254 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009255 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9256 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009257
Johannes Berg83739b02013-05-15 17:44:01 +02009258 wdev_lock(dev->ieee80211_ptr);
9259 ret = cfg80211_disconnect(rdev, dev, reason, true);
9260 wdev_unlock(dev->ieee80211_ptr);
9261 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009262}
9263
Johannes Berg463d0182009-07-14 00:33:35 +02009264static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9265{
Johannes Berg4c476992010-10-04 21:36:35 +02009266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009267 struct net *net;
9268 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009269
Vadim Kochan4b681c82015-01-12 16:34:05 +02009270 if (info->attrs[NL80211_ATTR_PID]) {
9271 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9272
9273 net = get_net_ns_by_pid(pid);
9274 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9275 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9276
9277 net = get_net_ns_by_fd(fd);
9278 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009279 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009280 }
Johannes Berg463d0182009-07-14 00:33:35 +02009281
Johannes Berg4c476992010-10-04 21:36:35 +02009282 if (IS_ERR(net))
9283 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009284
9285 err = 0;
9286
9287 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009288 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9289 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009290
Johannes Berg463d0182009-07-14 00:33:35 +02009291 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009292 return err;
9293}
9294
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009295static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9296{
Johannes Berg4c476992010-10-04 21:36:35 +02009297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009298 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9299 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009300 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009301 struct cfg80211_pmksa pmksa;
9302
9303 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9304
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009305 if (!info->attrs[NL80211_ATTR_PMKID])
9306 return -EINVAL;
9307
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009308 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009309
9310 if (info->attrs[NL80211_ATTR_MAC]) {
9311 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9312 } else if (info->attrs[NL80211_ATTR_SSID] &&
9313 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9314 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9315 info->attrs[NL80211_ATTR_PMK])) {
9316 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9317 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9318 pmksa.cache_id =
9319 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9320 } else {
9321 return -EINVAL;
9322 }
9323 if (info->attrs[NL80211_ATTR_PMK]) {
9324 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9325 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9326 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009327
Johannes Berg074ac8d2010-09-16 14:58:22 +02009328 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009329 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9330 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009331
9332 switch (info->genlhdr->cmd) {
9333 case NL80211_CMD_SET_PMKSA:
9334 rdev_ops = rdev->ops->set_pmksa;
9335 break;
9336 case NL80211_CMD_DEL_PMKSA:
9337 rdev_ops = rdev->ops->del_pmksa;
9338 break;
9339 default:
9340 WARN_ON(1);
9341 break;
9342 }
9343
Johannes Berg4c476992010-10-04 21:36:35 +02009344 if (!rdev_ops)
9345 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009346
Johannes Berg4c476992010-10-04 21:36:35 +02009347 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009348}
9349
9350static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9351{
Johannes Berg4c476992010-10-04 21:36:35 +02009352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9353 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009354
Johannes Berg074ac8d2010-09-16 14:58:22 +02009355 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009356 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9357 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009358
Johannes Berg4c476992010-10-04 21:36:35 +02009359 if (!rdev->ops->flush_pmksa)
9360 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009361
Hila Gonene35e4d22012-06-27 17:19:42 +03009362 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009363}
9364
Arik Nemtsov109086c2011-09-28 14:12:50 +03009365static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9366{
9367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9368 struct net_device *dev = info->user_ptr[1];
9369 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309370 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009371 u16 status_code;
9372 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009373 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009374
9375 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9376 !rdev->ops->tdls_mgmt)
9377 return -EOPNOTSUPP;
9378
9379 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9380 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9381 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9382 !info->attrs[NL80211_ATTR_IE] ||
9383 !info->attrs[NL80211_ATTR_MAC])
9384 return -EINVAL;
9385
9386 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9387 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9388 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9389 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009390 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309391 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9392 peer_capability =
9393 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009394
Hila Gonene35e4d22012-06-27 17:19:42 +03009395 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309396 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009397 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009398 nla_data(info->attrs[NL80211_ATTR_IE]),
9399 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009400}
9401
9402static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9403{
9404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9405 struct net_device *dev = info->user_ptr[1];
9406 enum nl80211_tdls_operation operation;
9407 u8 *peer;
9408
9409 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9410 !rdev->ops->tdls_oper)
9411 return -EOPNOTSUPP;
9412
9413 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9414 !info->attrs[NL80211_ATTR_MAC])
9415 return -EINVAL;
9416
9417 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9418 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9419
Hila Gonene35e4d22012-06-27 17:19:42 +03009420 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009421}
9422
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009423static int nl80211_remain_on_channel(struct sk_buff *skb,
9424 struct genl_info *info)
9425{
Johannes Berg4c476992010-10-04 21:36:35 +02009426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009427 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009428 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309429 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009430 struct sk_buff *msg;
9431 void *hdr;
9432 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009433 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009434 int err;
9435
9436 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9437 !info->attrs[NL80211_ATTR_DURATION])
9438 return -EINVAL;
9439
9440 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9441
Johannes Berg7c4ef712011-11-18 15:33:48 +01009442 if (!rdev->ops->remain_on_channel ||
9443 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009444 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009445
Johannes Bergebf348f2012-06-01 12:50:54 +02009446 /*
9447 * We should be on that channel for at least a minimum amount of
9448 * time (10ms) but no longer than the driver supports.
9449 */
9450 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9451 duration > rdev->wiphy.max_remain_on_channel_duration)
9452 return -EINVAL;
9453
Johannes Berg683b6d32012-11-08 21:25:48 +01009454 err = nl80211_parse_chandef(rdev, info, &chandef);
9455 if (err)
9456 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009457
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309458 wdev_lock(wdev);
9459 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9460 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9461 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9462 &chandef);
9463 if (compat_chandef != &chandef) {
9464 wdev_unlock(wdev);
9465 return -EBUSY;
9466 }
9467 }
9468 wdev_unlock(wdev);
9469
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009470 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009471 if (!msg)
9472 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009473
Eric W. Biederman15e47302012-09-07 20:12:54 +00009474 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009475 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009476 if (!hdr) {
9477 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009478 goto free_msg;
9479 }
9480
Johannes Berg683b6d32012-11-08 21:25:48 +01009481 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9482 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009483
9484 if (err)
9485 goto free_msg;
9486
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009487 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9488 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009489 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009490
9491 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009492
9493 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009494
9495 nla_put_failure:
9496 err = -ENOBUFS;
9497 free_msg:
9498 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009499 return err;
9500}
9501
9502static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9503 struct genl_info *info)
9504{
Johannes Berg4c476992010-10-04 21:36:35 +02009505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009506 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009507 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009508
9509 if (!info->attrs[NL80211_ATTR_COOKIE])
9510 return -EINVAL;
9511
Johannes Berg4c476992010-10-04 21:36:35 +02009512 if (!rdev->ops->cancel_remain_on_channel)
9513 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009514
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009515 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9516
Hila Gonene35e4d22012-06-27 17:19:42 +03009517 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009518}
9519
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009520static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9521 struct genl_info *info)
9522{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009523 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009525 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309526 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009527
Johannes Berg4c476992010-10-04 21:36:35 +02009528 if (!rdev->ops->set_bitrate_mask)
9529 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009530
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309531 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9532 if (err)
9533 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009534
Hila Gonene35e4d22012-06-27 17:19:42 +03009535 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009536}
9537
Johannes Berg2e161f782010-08-12 15:38:38 +02009538static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009539{
Johannes Berg4c476992010-10-04 21:36:35 +02009540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009541 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02009542 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009543
9544 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9545 return -EINVAL;
9546
Johannes Berg2e161f782010-08-12 15:38:38 +02009547 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9548 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009549
Johannes Berg71bbc992012-06-15 15:30:18 +02009550 switch (wdev->iftype) {
9551 case NL80211_IFTYPE_STATION:
9552 case NL80211_IFTYPE_ADHOC:
9553 case NL80211_IFTYPE_P2P_CLIENT:
9554 case NL80211_IFTYPE_AP:
9555 case NL80211_IFTYPE_AP_VLAN:
9556 case NL80211_IFTYPE_MESH_POINT:
9557 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009558 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009559 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009560 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009561 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009562 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009563 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009564
9565 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009566 if (!rdev->ops->mgmt_tx)
9567 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009568
Eric W. Biederman15e47302012-09-07 20:12:54 +00009569 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009570 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9571 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009572}
9573
Johannes Berg2e161f782010-08-12 15:38:38 +02009574static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009575{
Johannes Berg4c476992010-10-04 21:36:35 +02009576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009577 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009578 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009579 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009580 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009581 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009582 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009583 struct cfg80211_mgmt_tx_params params = {
9584 .dont_wait_for_ack =
9585 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9586 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009587
Johannes Berg683b6d32012-11-08 21:25:48 +01009588 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009589 return -EINVAL;
9590
Johannes Berg4c476992010-10-04 21:36:35 +02009591 if (!rdev->ops->mgmt_tx)
9592 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009593
Johannes Berg71bbc992012-06-15 15:30:18 +02009594 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009595 case NL80211_IFTYPE_P2P_DEVICE:
9596 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9597 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009598 case NL80211_IFTYPE_STATION:
9599 case NL80211_IFTYPE_ADHOC:
9600 case NL80211_IFTYPE_P2P_CLIENT:
9601 case NL80211_IFTYPE_AP:
9602 case NL80211_IFTYPE_AP_VLAN:
9603 case NL80211_IFTYPE_MESH_POINT:
9604 case NL80211_IFTYPE_P2P_GO:
9605 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009606 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009607 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009608 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009609 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009610
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009611 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009612 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009613 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009614 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009615
9616 /*
9617 * We should wait on the channel for at least a minimum amount
9618 * of time (10ms) but no longer than the driver supports.
9619 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009620 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9621 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009622 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009623 }
9624
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009625 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009626
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009627 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009628 return -EINVAL;
9629
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009630 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309631
Antonio Quartulliea141b752013-06-11 14:20:03 +02009632 /* get the channel if any has been specified, otherwise pass NULL to
9633 * the driver. The latter will use the current one
9634 */
9635 chandef.chan = NULL;
9636 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9637 err = nl80211_parse_chandef(rdev, info, &chandef);
9638 if (err)
9639 return err;
9640 }
9641
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009642 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009643 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009644
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309645 wdev_lock(wdev);
9646 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9647 wdev_unlock(wdev);
9648 return -EBUSY;
9649 }
9650 wdev_unlock(wdev);
9651
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009652 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9653 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9654
9655 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9656 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9657 int i;
9658
9659 if (len % sizeof(u16))
9660 return -EINVAL;
9661
9662 params.n_csa_offsets = len / sizeof(u16);
9663 params.csa_offsets =
9664 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9665
9666 /* check that all the offsets fit the frame */
9667 for (i = 0; i < params.n_csa_offsets; i++) {
9668 if (params.csa_offsets[i] >= params.len)
9669 return -EINVAL;
9670 }
9671 }
9672
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009673 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9675 if (!msg)
9676 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009677
Eric W. Biederman15e47302012-09-07 20:12:54 +00009678 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009679 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009680 if (!hdr) {
9681 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009682 goto free_msg;
9683 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009684 }
Johannes Berge247bd902011-11-04 11:18:21 +01009685
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009686 params.chan = chandef.chan;
9687 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009688 if (err)
9689 goto free_msg;
9690
Johannes Berge247bd902011-11-04 11:18:21 +01009691 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009692 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9693 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009694 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009695
Johannes Berge247bd902011-11-04 11:18:21 +01009696 genlmsg_end(msg, hdr);
9697 return genlmsg_reply(msg, info);
9698 }
9699
9700 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009701
9702 nla_put_failure:
9703 err = -ENOBUFS;
9704 free_msg:
9705 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009706 return err;
9707}
9708
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009709static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9710{
9711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009712 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009713 u64 cookie;
9714
9715 if (!info->attrs[NL80211_ATTR_COOKIE])
9716 return -EINVAL;
9717
9718 if (!rdev->ops->mgmt_tx_cancel_wait)
9719 return -EOPNOTSUPP;
9720
Johannes Berg71bbc992012-06-15 15:30:18 +02009721 switch (wdev->iftype) {
9722 case NL80211_IFTYPE_STATION:
9723 case NL80211_IFTYPE_ADHOC:
9724 case NL80211_IFTYPE_P2P_CLIENT:
9725 case NL80211_IFTYPE_AP:
9726 case NL80211_IFTYPE_AP_VLAN:
9727 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009728 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009729 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009730 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009731 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009732 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009733 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009734
9735 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9736
Hila Gonene35e4d22012-06-27 17:19:42 +03009737 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009738}
9739
Kalle Valoffb9eb32010-02-17 17:58:10 +02009740static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9741{
Johannes Berg4c476992010-10-04 21:36:35 +02009742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009743 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009744 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009745 u8 ps_state;
9746 bool state;
9747 int err;
9748
Johannes Berg4c476992010-10-04 21:36:35 +02009749 if (!info->attrs[NL80211_ATTR_PS_STATE])
9750 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009751
9752 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9753
Johannes Berg4c476992010-10-04 21:36:35 +02009754 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9755 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009756
9757 wdev = dev->ieee80211_ptr;
9758
Johannes Berg4c476992010-10-04 21:36:35 +02009759 if (!rdev->ops->set_power_mgmt)
9760 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009761
9762 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9763
9764 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009765 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009766
Hila Gonene35e4d22012-06-27 17:19:42 +03009767 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009768 if (!err)
9769 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009770 return err;
9771}
9772
9773static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9774{
Johannes Berg4c476992010-10-04 21:36:35 +02009775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009776 enum nl80211_ps_state ps_state;
9777 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009778 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009779 struct sk_buff *msg;
9780 void *hdr;
9781 int err;
9782
Kalle Valoffb9eb32010-02-17 17:58:10 +02009783 wdev = dev->ieee80211_ptr;
9784
Johannes Berg4c476992010-10-04 21:36:35 +02009785 if (!rdev->ops->set_power_mgmt)
9786 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009787
9788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009789 if (!msg)
9790 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009791
Eric W. Biederman15e47302012-09-07 20:12:54 +00009792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009793 NL80211_CMD_GET_POWER_SAVE);
9794 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009795 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009796 goto free_msg;
9797 }
9798
9799 if (wdev->ps)
9800 ps_state = NL80211_PS_ENABLED;
9801 else
9802 ps_state = NL80211_PS_DISABLED;
9803
David S. Miller9360ffd2012-03-29 04:41:26 -04009804 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9805 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009806
9807 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009808 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009809
Johannes Berg4c476992010-10-04 21:36:35 +02009810 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009811 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009812 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009813 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009814 return err;
9815}
9816
Johannes Berg94e860f2014-01-20 23:58:15 +01009817static const struct nla_policy
9818nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009819 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009820 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9821 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009822 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9823 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9824 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009825 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009826};
9827
Thomas Pedersen84f10702012-07-12 16:17:33 -07009828static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009829 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009830{
9831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009832 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009833 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009834
Johannes Bergd9d8b012012-11-26 12:51:52 +01009835 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009836 return -EINVAL;
9837
Thomas Pedersen84f10702012-07-12 16:17:33 -07009838 if (!rdev->ops->set_cqm_txe_config)
9839 return -EOPNOTSUPP;
9840
9841 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9842 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9843 return -EOPNOTSUPP;
9844
Hila Gonene35e4d22012-06-27 17:19:42 +03009845 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009846}
9847
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009848static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9849 struct net_device *dev)
9850{
9851 struct wireless_dev *wdev = dev->ieee80211_ptr;
9852 s32 last, low, high;
9853 u32 hyst;
9854 int i, n;
9855 int err;
9856
9857 /* RSSI reporting disabled? */
9858 if (!wdev->cqm_config)
9859 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9860
9861 /*
9862 * Obtain current RSSI value if possible, if not and no RSSI threshold
9863 * event has been received yet, we should receive an event after a
9864 * connection is established and enough beacons received to calculate
9865 * the average.
9866 */
9867 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9868 rdev->ops->get_station) {
Johannes Berg5762d7d2018-01-16 23:20:22 +01009869 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009870 u8 *mac_addr;
9871
9872 mac_addr = wdev->current_bss->pub.bssid;
9873
9874 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9875 if (err)
9876 return err;
9877
9878 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9879 wdev->cqm_config->last_rssi_event_value =
9880 (s8) sinfo.rx_beacon_signal_avg;
9881 }
9882
9883 last = wdev->cqm_config->last_rssi_event_value;
9884 hyst = wdev->cqm_config->rssi_hyst;
9885 n = wdev->cqm_config->n_rssi_thresholds;
9886
9887 for (i = 0; i < n; i++)
9888 if (last < wdev->cqm_config->rssi_thresholds[i])
9889 break;
9890
9891 low = i > 0 ?
9892 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9893 high = i < n ?
9894 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9895
9896 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9897}
9898
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009899static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009900 const s32 *thresholds, int n_thresholds,
9901 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009902{
Johannes Berg4c476992010-10-04 21:36:35 +02009903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009904 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009905 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009906 int i, err;
9907 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009908
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009909 /* Check all values negative and sorted */
9910 for (i = 0; i < n_thresholds; i++) {
9911 if (thresholds[i] > 0 || thresholds[i] <= prev)
9912 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009913
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009914 prev = thresholds[i];
9915 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009916
Johannes Berg074ac8d2010-09-16 14:58:22 +02009917 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009918 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9919 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009920
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009921 wdev_lock(wdev);
9922 cfg80211_cqm_config_free(wdev);
9923 wdev_unlock(wdev);
9924
9925 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9926 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9927 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9928
9929 return rdev_set_cqm_rssi_config(rdev, dev,
9930 thresholds[0], hysteresis);
9931 }
9932
9933 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9934 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9935 return -EOPNOTSUPP;
9936
9937 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9938 n_thresholds = 0;
9939
9940 wdev_lock(wdev);
9941 if (n_thresholds) {
9942 struct cfg80211_cqm_config *cqm_config;
9943
9944 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9945 n_thresholds * sizeof(s32), GFP_KERNEL);
9946 if (!cqm_config) {
9947 err = -ENOMEM;
9948 goto unlock;
9949 }
9950
9951 cqm_config->rssi_hyst = hysteresis;
9952 cqm_config->n_rssi_thresholds = n_thresholds;
9953 memcpy(cqm_config->rssi_thresholds, thresholds,
9954 n_thresholds * sizeof(s32));
9955
9956 wdev->cqm_config = cqm_config;
9957 }
9958
9959 err = cfg80211_cqm_rssi_update(rdev, dev);
9960
9961unlock:
9962 wdev_unlock(wdev);
9963
9964 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009965}
9966
9967static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9968{
9969 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9970 struct nlattr *cqm;
9971 int err;
9972
9973 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009974 if (!cqm)
9975 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009976
9977 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009978 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009979 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009980 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009981
9982 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9983 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009984 const s32 *thresholds =
9985 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9986 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009987 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009988
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009989 if (len % 4)
9990 return -EINVAL;
9991
9992 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9993 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009994 }
9995
9996 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9997 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9998 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9999 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10000 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10001 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10002
10003 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10004 }
10005
10006 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010007}
10008
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010009static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10010{
10011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10012 struct net_device *dev = info->user_ptr[1];
10013 struct ocb_setup setup = {};
10014 int err;
10015
10016 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10017 if (err)
10018 return err;
10019
10020 return cfg80211_join_ocb(rdev, dev, &setup);
10021}
10022
10023static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
10024{
10025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10026 struct net_device *dev = info->user_ptr[1];
10027
10028 return cfg80211_leave_ocb(rdev, dev);
10029}
10030
Johannes Berg29cbe682010-12-03 09:20:44 +010010031static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
10032{
10033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10034 struct net_device *dev = info->user_ptr[1];
10035 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080010036 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010010037 int err;
10038
10039 /* start with default */
10040 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080010041 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010010042
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010043 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010010044 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010045 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010010046 if (err)
10047 return err;
10048 }
10049
10050 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
10051 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
10052 return -EINVAL;
10053
Javier Cardonac80d5452010-12-16 17:37:49 -080010054 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
10055 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
10056
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080010057 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10058 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
10059 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10060 return -EINVAL;
10061
Marco Porsch9bdbf042013-01-07 16:04:51 +010010062 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10063 setup.beacon_interval =
10064 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010065
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010066 err = cfg80211_validate_beacon_int(rdev,
10067 NL80211_IFTYPE_MESH_POINT,
10068 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010069 if (err)
10070 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010071 }
10072
10073 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10074 setup.dtim_period =
10075 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10076 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10077 return -EINVAL;
10078 }
10079
Javier Cardonac80d5452010-12-16 17:37:49 -080010080 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10081 /* parse additional setup parameters if given */
10082 err = nl80211_parse_mesh_setup(info, &setup);
10083 if (err)
10084 return err;
10085 }
10086
Thomas Pedersend37bb182013-03-04 13:06:13 -080010087 if (setup.user_mpm)
10088 cfg.auto_open_plinks = false;
10089
Johannes Bergcc1d2802012-05-16 23:50:20 +020010090 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010091 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10092 if (err)
10093 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010094 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050010095 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010096 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010097 }
10098
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010099 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10100 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10101 int n_rates =
10102 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10103 struct ieee80211_supported_band *sband;
10104
10105 if (!setup.chandef.chan)
10106 return -EINVAL;
10107
10108 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10109
10110 err = ieee80211_get_ratemask(sband, rates, n_rates,
10111 &setup.basic_rates);
10112 if (err)
10113 return err;
10114 }
10115
Johannes Berg8564e382016-09-19 09:44:44 +020010116 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10117 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10118 if (err)
10119 return err;
10120
Johannes Berg265698d2017-09-18 22:46:36 +020010121 if (!setup.chandef.chan)
10122 return -EINVAL;
10123
Johannes Berg8564e382016-09-19 09:44:44 +020010124 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10125 &setup.beacon_rate);
10126 if (err)
10127 return err;
10128 }
10129
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010130 setup.userspace_handles_dfs =
10131 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10132
Denis Kenzior188c1b32018-03-26 12:52:46 -050010133 wdev_lock(dev->ieee80211_ptr);
10134 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10135 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
10136 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10137 wdev_unlock(dev->ieee80211_ptr);
10138
10139 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010010140}
10141
10142static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10143{
10144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10145 struct net_device *dev = info->user_ptr[1];
10146
10147 return cfg80211_leave_mesh(rdev, dev);
10148}
10149
Johannes Bergdfb89c52012-06-27 09:23:48 +020010150#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010151static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10152 struct cfg80211_registered_device *rdev)
10153{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010154 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010155 struct nlattr *nl_pats, *nl_pat;
10156 int i, pat_len;
10157
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010158 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010159 return 0;
10160
10161 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10162 if (!nl_pats)
10163 return -ENOBUFS;
10164
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010165 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010166 nl_pat = nla_nest_start(msg, i + 1);
10167 if (!nl_pat)
10168 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010169 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010170 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010171 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010172 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10173 wowlan->patterns[i].pattern) ||
10174 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010175 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010176 return -ENOBUFS;
10177 nla_nest_end(msg, nl_pat);
10178 }
10179 nla_nest_end(msg, nl_pats);
10180
10181 return 0;
10182}
10183
Johannes Berg2a0e0472013-01-23 22:57:40 +010010184static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10185 struct cfg80211_wowlan_tcp *tcp)
10186{
10187 struct nlattr *nl_tcp;
10188
10189 if (!tcp)
10190 return 0;
10191
10192 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10193 if (!nl_tcp)
10194 return -ENOBUFS;
10195
Jiri Benc930345e2015-03-29 16:59:25 +020010196 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10197 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010198 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10199 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10200 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10201 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10202 tcp->payload_len, tcp->payload) ||
10203 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10204 tcp->data_interval) ||
10205 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10206 tcp->wake_len, tcp->wake_data) ||
10207 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10208 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10209 return -ENOBUFS;
10210
10211 if (tcp->payload_seq.len &&
10212 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10213 sizeof(tcp->payload_seq), &tcp->payload_seq))
10214 return -ENOBUFS;
10215
10216 if (tcp->payload_tok.len &&
10217 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10218 sizeof(tcp->payload_tok) + tcp->tokens_size,
10219 &tcp->payload_tok))
10220 return -ENOBUFS;
10221
Johannes Berge248ad32013-05-16 10:24:28 +020010222 nla_nest_end(msg, nl_tcp);
10223
Johannes Berg2a0e0472013-01-23 22:57:40 +010010224 return 0;
10225}
10226
Luciano Coelho75453cc2015-01-09 14:06:37 +020010227static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10228 struct cfg80211_sched_scan_request *req)
10229{
Avraham Stern3b06d272015-10-12 09:51:34 +030010230 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010231 int i;
10232
10233 if (!req)
10234 return 0;
10235
10236 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10237 if (!nd)
10238 return -ENOBUFS;
10239
Avraham Stern3b06d272015-10-12 09:51:34 +030010240 if (req->n_scan_plans == 1 &&
10241 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10242 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010243 return -ENOBUFS;
10244
Luciano Coelho21fea562015-03-17 16:36:01 +020010245 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10246 return -ENOBUFS;
10247
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010248 if (req->relative_rssi_set) {
10249 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10250
10251 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10252 req->relative_rssi))
10253 return -ENOBUFS;
10254
10255 rssi_adjust.band = req->rssi_adjust.band;
10256 rssi_adjust.delta = req->rssi_adjust.delta;
10257 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10258 sizeof(rssi_adjust), &rssi_adjust))
10259 return -ENOBUFS;
10260 }
10261
Luciano Coelho75453cc2015-01-09 14:06:37 +020010262 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10263 if (!freqs)
10264 return -ENOBUFS;
10265
Johannes Berg53b18982016-09-14 09:59:21 +020010266 for (i = 0; i < req->n_channels; i++) {
10267 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10268 return -ENOBUFS;
10269 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010270
10271 nla_nest_end(msg, freqs);
10272
10273 if (req->n_match_sets) {
10274 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010275 if (!matches)
10276 return -ENOBUFS;
10277
Luciano Coelho75453cc2015-01-09 14:06:37 +020010278 for (i = 0; i < req->n_match_sets; i++) {
10279 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010280 if (!match)
10281 return -ENOBUFS;
10282
Johannes Berg53b18982016-09-14 09:59:21 +020010283 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10284 req->match_sets[i].ssid.ssid_len,
10285 req->match_sets[i].ssid.ssid))
10286 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010287 nla_nest_end(msg, match);
10288 }
10289 nla_nest_end(msg, matches);
10290 }
10291
Avraham Stern3b06d272015-10-12 09:51:34 +030010292 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10293 if (!scan_plans)
10294 return -ENOBUFS;
10295
10296 for (i = 0; i < req->n_scan_plans; i++) {
10297 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010298 if (!scan_plan)
10299 return -ENOBUFS;
10300
Avraham Stern3b06d272015-10-12 09:51:34 +030010301 if (!scan_plan ||
10302 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10303 req->scan_plans[i].interval) ||
10304 (req->scan_plans[i].iterations &&
10305 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10306 req->scan_plans[i].iterations)))
10307 return -ENOBUFS;
10308 nla_nest_end(msg, scan_plan);
10309 }
10310 nla_nest_end(msg, scan_plans);
10311
Luciano Coelho75453cc2015-01-09 14:06:37 +020010312 nla_nest_end(msg, nd);
10313
10314 return 0;
10315}
10316
Johannes Bergff1b6e62011-05-04 15:37:28 +020010317static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10318{
10319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10320 struct sk_buff *msg;
10321 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010322 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010323
Johannes Berg964dc9e2013-06-03 17:25:34 +020010324 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010325 return -EOPNOTSUPP;
10326
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010327 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010328 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010329 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10330 rdev->wiphy.wowlan_config->tcp->payload_len +
10331 rdev->wiphy.wowlan_config->tcp->wake_len +
10332 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010333 }
10334
10335 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010336 if (!msg)
10337 return -ENOMEM;
10338
Eric W. Biederman15e47302012-09-07 20:12:54 +000010339 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010340 NL80211_CMD_GET_WOWLAN);
10341 if (!hdr)
10342 goto nla_put_failure;
10343
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010344 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010345 struct nlattr *nl_wowlan;
10346
10347 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10348 if (!nl_wowlan)
10349 goto nla_put_failure;
10350
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010351 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010352 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010353 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010354 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010355 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010356 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010357 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010358 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010359 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010360 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010361 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010362 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010363 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010364 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10365 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010366
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010367 if (nl80211_send_wowlan_patterns(msg, rdev))
10368 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010369
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010370 if (nl80211_send_wowlan_tcp(msg,
10371 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010372 goto nla_put_failure;
10373
Luciano Coelho75453cc2015-01-09 14:06:37 +020010374 if (nl80211_send_wowlan_nd(
10375 msg,
10376 rdev->wiphy.wowlan_config->nd_config))
10377 goto nla_put_failure;
10378
Johannes Bergff1b6e62011-05-04 15:37:28 +020010379 nla_nest_end(msg, nl_wowlan);
10380 }
10381
10382 genlmsg_end(msg, hdr);
10383 return genlmsg_reply(msg, info);
10384
10385nla_put_failure:
10386 nlmsg_free(msg);
10387 return -ENOBUFS;
10388}
10389
Johannes Berg2a0e0472013-01-23 22:57:40 +010010390static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10391 struct nlattr *attr,
10392 struct cfg80211_wowlan *trig)
10393{
10394 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10395 struct cfg80211_wowlan_tcp *cfg;
10396 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10397 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10398 u32 size;
10399 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10400 int err, port;
10401
Johannes Berg964dc9e2013-06-03 17:25:34 +020010402 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010403 return -EINVAL;
10404
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010405 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010406 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010407 if (err)
10408 return err;
10409
10410 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10411 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10412 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10413 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10414 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10415 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10416 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10417 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10418 return -EINVAL;
10419
10420 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010421 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010422 return -EINVAL;
10423
10424 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010425 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010426 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010427 return -EINVAL;
10428
10429 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010430 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010431 return -EINVAL;
10432
10433 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10434 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10435 return -EINVAL;
10436
10437 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10438 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10439
10440 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10441 tokens_size = tokln - sizeof(*tok);
10442
10443 if (!tok->len || tokens_size % tok->len)
10444 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010445 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010446 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010447 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010448 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010449 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010450 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010451 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010452 return -EINVAL;
10453 if (tok->offset + tok->len > data_size)
10454 return -EINVAL;
10455 }
10456
10457 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10458 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010459 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010460 return -EINVAL;
10461 if (seq->len == 0 || seq->len > 4)
10462 return -EINVAL;
10463 if (seq->len + seq->offset > data_size)
10464 return -EINVAL;
10465 }
10466
10467 size = sizeof(*cfg);
10468 size += data_size;
10469 size += wake_size + wake_mask_size;
10470 size += tokens_size;
10471
10472 cfg = kzalloc(size, GFP_KERNEL);
10473 if (!cfg)
10474 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010475 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10476 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010477 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10478 ETH_ALEN);
10479 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10480 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10481 else
10482 port = 0;
10483#ifdef CONFIG_INET
10484 /* allocate a socket and port for it and use it */
10485 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10486 IPPROTO_TCP, &cfg->sock, 1);
10487 if (err) {
10488 kfree(cfg);
10489 return err;
10490 }
10491 if (inet_csk_get_port(cfg->sock->sk, port)) {
10492 sock_release(cfg->sock);
10493 kfree(cfg);
10494 return -EADDRINUSE;
10495 }
10496 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10497#else
10498 if (!port) {
10499 kfree(cfg);
10500 return -EINVAL;
10501 }
10502 cfg->src_port = port;
10503#endif
10504
10505 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10506 cfg->payload_len = data_size;
10507 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10508 memcpy((void *)cfg->payload,
10509 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10510 data_size);
10511 if (seq)
10512 cfg->payload_seq = *seq;
10513 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10514 cfg->wake_len = wake_size;
10515 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10516 memcpy((void *)cfg->wake_data,
10517 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10518 wake_size);
10519 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10520 data_size + wake_size;
10521 memcpy((void *)cfg->wake_mask,
10522 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10523 wake_mask_size);
10524 if (tok) {
10525 cfg->tokens_size = tokens_size;
10526 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10527 }
10528
10529 trig->tcp = cfg;
10530
10531 return 0;
10532}
10533
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010534static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10535 const struct wiphy_wowlan_support *wowlan,
10536 struct nlattr *attr,
10537 struct cfg80211_wowlan *trig)
10538{
10539 struct nlattr **tb;
10540 int err;
10541
10542 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10543 if (!tb)
10544 return -ENOMEM;
10545
10546 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10547 err = -EOPNOTSUPP;
10548 goto out;
10549 }
10550
Johannes Bergfceb6432017-04-12 14:34:07 +020010551 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10552 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010553 if (err)
10554 goto out;
10555
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010556 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10557 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010558 err = PTR_ERR_OR_ZERO(trig->nd_config);
10559 if (err)
10560 trig->nd_config = NULL;
10561
10562out:
10563 kfree(tb);
10564 return err;
10565}
10566
Johannes Bergff1b6e62011-05-04 15:37:28 +020010567static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10568{
10569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10570 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010571 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010572 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010573 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010574 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010575 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010576 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010577
Johannes Berg964dc9e2013-06-03 17:25:34 +020010578 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010579 return -EOPNOTSUPP;
10580
Johannes Bergae33bd82012-07-12 16:25:02 +020010581 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10582 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010583 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010584 goto set_wakeup;
10585 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010586
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010587 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10588 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010589 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010590 if (err)
10591 return err;
10592
10593 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10594 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10595 return -EINVAL;
10596 new_triggers.any = true;
10597 }
10598
10599 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10600 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10601 return -EINVAL;
10602 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010603 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010604 }
10605
10606 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10607 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10608 return -EINVAL;
10609 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010610 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010611 }
10612
Johannes Berg77dbbb12011-07-13 10:48:55 +020010613 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10614 return -EINVAL;
10615
10616 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10617 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10618 return -EINVAL;
10619 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010620 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010621 }
10622
10623 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10624 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10625 return -EINVAL;
10626 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010627 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010628 }
10629
10630 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10631 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10632 return -EINVAL;
10633 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010634 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010635 }
10636
10637 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10638 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10639 return -EINVAL;
10640 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010641 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010642 }
10643
Johannes Bergff1b6e62011-05-04 15:37:28 +020010644 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10645 struct nlattr *pat;
10646 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010647 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010648 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010649
Johannes Berg98fc4382015-03-01 09:10:13 +020010650 regular = true;
10651
Johannes Bergff1b6e62011-05-04 15:37:28 +020010652 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10653 rem)
10654 n_patterns++;
10655 if (n_patterns > wowlan->n_patterns)
10656 return -EINVAL;
10657
10658 new_triggers.patterns = kcalloc(n_patterns,
10659 sizeof(new_triggers.patterns[0]),
10660 GFP_KERNEL);
10661 if (!new_triggers.patterns)
10662 return -ENOMEM;
10663
10664 new_triggers.n_patterns = n_patterns;
10665 i = 0;
10666
10667 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10668 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010669 u8 *mask_pat;
10670
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010671 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030010672 nl80211_packet_pattern_policy,
10673 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010674 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010675 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10676 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010677 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010678 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010679 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010680 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010681 goto error;
10682 if (pat_len > wowlan->pattern_max_len ||
10683 pat_len < wowlan->pattern_min_len)
10684 goto error;
10685
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010686 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010687 pkt_offset = 0;
10688 else
10689 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010690 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010691 if (pkt_offset > wowlan->max_pkt_offset)
10692 goto error;
10693 new_triggers.patterns[i].pkt_offset = pkt_offset;
10694
Johannes Berg922bd802014-05-19 17:59:50 +020010695 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10696 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010697 err = -ENOMEM;
10698 goto error;
10699 }
Johannes Berg922bd802014-05-19 17:59:50 +020010700 new_triggers.patterns[i].mask = mask_pat;
10701 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010702 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010703 mask_pat += mask_len;
10704 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010705 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010706 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010707 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010708 pat_len);
10709 i++;
10710 }
10711 }
10712
Johannes Berg2a0e0472013-01-23 22:57:40 +010010713 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010714 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010715 err = nl80211_parse_wowlan_tcp(
10716 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10717 &new_triggers);
10718 if (err)
10719 goto error;
10720 }
10721
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010722 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010723 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010724 err = nl80211_parse_wowlan_nd(
10725 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10726 &new_triggers);
10727 if (err)
10728 goto error;
10729 }
10730
Johannes Berg98fc4382015-03-01 09:10:13 +020010731 /* The 'any' trigger means the device continues operating more or less
10732 * as in its normal operation mode and wakes up the host on most of the
10733 * normal interrupts (like packet RX, ...)
10734 * It therefore makes little sense to combine with the more constrained
10735 * wakeup trigger modes.
10736 */
10737 if (new_triggers.any && regular) {
10738 err = -EINVAL;
10739 goto error;
10740 }
10741
Johannes Bergae33bd82012-07-12 16:25:02 +020010742 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10743 if (!ntrig) {
10744 err = -ENOMEM;
10745 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010746 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010747 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010748 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010749
Johannes Bergae33bd82012-07-12 16:25:02 +020010750 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010751 if (rdev->ops->set_wakeup &&
10752 prev_enabled != !!rdev->wiphy.wowlan_config)
10753 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010754
Johannes Bergff1b6e62011-05-04 15:37:28 +020010755 return 0;
10756 error:
10757 for (i = 0; i < new_triggers.n_patterns; i++)
10758 kfree(new_triggers.patterns[i].mask);
10759 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010760 if (new_triggers.tcp && new_triggers.tcp->sock)
10761 sock_release(new_triggers.tcp->sock);
10762 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010763 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010764 return err;
10765}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010766#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010767
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010768static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10769 struct cfg80211_registered_device *rdev)
10770{
10771 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10772 int i, j, pat_len;
10773 struct cfg80211_coalesce_rules *rule;
10774
10775 if (!rdev->coalesce->n_rules)
10776 return 0;
10777
10778 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10779 if (!nl_rules)
10780 return -ENOBUFS;
10781
10782 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10783 nl_rule = nla_nest_start(msg, i + 1);
10784 if (!nl_rule)
10785 return -ENOBUFS;
10786
10787 rule = &rdev->coalesce->rules[i];
10788 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10789 rule->delay))
10790 return -ENOBUFS;
10791
10792 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10793 rule->condition))
10794 return -ENOBUFS;
10795
10796 nl_pats = nla_nest_start(msg,
10797 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10798 if (!nl_pats)
10799 return -ENOBUFS;
10800
10801 for (j = 0; j < rule->n_patterns; j++) {
10802 nl_pat = nla_nest_start(msg, j + 1);
10803 if (!nl_pat)
10804 return -ENOBUFS;
10805 pat_len = rule->patterns[j].pattern_len;
10806 if (nla_put(msg, NL80211_PKTPAT_MASK,
10807 DIV_ROUND_UP(pat_len, 8),
10808 rule->patterns[j].mask) ||
10809 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10810 rule->patterns[j].pattern) ||
10811 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10812 rule->patterns[j].pkt_offset))
10813 return -ENOBUFS;
10814 nla_nest_end(msg, nl_pat);
10815 }
10816 nla_nest_end(msg, nl_pats);
10817 nla_nest_end(msg, nl_rule);
10818 }
10819 nla_nest_end(msg, nl_rules);
10820
10821 return 0;
10822}
10823
10824static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10825{
10826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10827 struct sk_buff *msg;
10828 void *hdr;
10829
10830 if (!rdev->wiphy.coalesce)
10831 return -EOPNOTSUPP;
10832
10833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10834 if (!msg)
10835 return -ENOMEM;
10836
10837 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10838 NL80211_CMD_GET_COALESCE);
10839 if (!hdr)
10840 goto nla_put_failure;
10841
10842 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10843 goto nla_put_failure;
10844
10845 genlmsg_end(msg, hdr);
10846 return genlmsg_reply(msg, info);
10847
10848nla_put_failure:
10849 nlmsg_free(msg);
10850 return -ENOBUFS;
10851}
10852
10853void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10854{
10855 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10856 int i, j;
10857 struct cfg80211_coalesce_rules *rule;
10858
10859 if (!coalesce)
10860 return;
10861
10862 for (i = 0; i < coalesce->n_rules; i++) {
10863 rule = &coalesce->rules[i];
10864 for (j = 0; j < rule->n_patterns; j++)
10865 kfree(rule->patterns[j].mask);
10866 kfree(rule->patterns);
10867 }
10868 kfree(coalesce->rules);
10869 kfree(coalesce);
10870 rdev->coalesce = NULL;
10871}
10872
10873static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10874 struct nlattr *rule,
10875 struct cfg80211_coalesce_rules *new_rule)
10876{
10877 int err, i;
10878 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10879 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10880 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10881 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10882
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010883 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010884 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010885 if (err)
10886 return err;
10887
10888 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10889 new_rule->delay =
10890 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10891 if (new_rule->delay > coalesce->max_delay)
10892 return -EINVAL;
10893
10894 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10895 new_rule->condition =
10896 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10897 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10898 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10899 return -EINVAL;
10900
10901 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10902 return -EINVAL;
10903
10904 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10905 rem)
10906 n_patterns++;
10907 if (n_patterns > coalesce->n_patterns)
10908 return -EINVAL;
10909
10910 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10911 GFP_KERNEL);
10912 if (!new_rule->patterns)
10913 return -ENOMEM;
10914
10915 new_rule->n_patterns = n_patterns;
10916 i = 0;
10917
10918 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10919 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010920 u8 *mask_pat;
10921
Peng Xuad670232017-10-03 23:21:51 +030010922 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10923 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010924 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10925 !pat_tb[NL80211_PKTPAT_PATTERN])
10926 return -EINVAL;
10927 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10928 mask_len = DIV_ROUND_UP(pat_len, 8);
10929 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10930 return -EINVAL;
10931 if (pat_len > coalesce->pattern_max_len ||
10932 pat_len < coalesce->pattern_min_len)
10933 return -EINVAL;
10934
10935 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10936 pkt_offset = 0;
10937 else
10938 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10939 if (pkt_offset > coalesce->max_pkt_offset)
10940 return -EINVAL;
10941 new_rule->patterns[i].pkt_offset = pkt_offset;
10942
Johannes Berg922bd802014-05-19 17:59:50 +020010943 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10944 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010945 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010946
10947 new_rule->patterns[i].mask = mask_pat;
10948 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10949 mask_len);
10950
10951 mask_pat += mask_len;
10952 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010953 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010954 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10955 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010956 i++;
10957 }
10958
10959 return 0;
10960}
10961
10962static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10963{
10964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10965 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10966 struct cfg80211_coalesce new_coalesce = {};
10967 struct cfg80211_coalesce *n_coalesce;
10968 int err, rem_rule, n_rules = 0, i, j;
10969 struct nlattr *rule;
10970 struct cfg80211_coalesce_rules *tmp_rule;
10971
10972 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10973 return -EOPNOTSUPP;
10974
10975 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10976 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010977 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010978 return 0;
10979 }
10980
10981 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10982 rem_rule)
10983 n_rules++;
10984 if (n_rules > coalesce->n_rules)
10985 return -EINVAL;
10986
10987 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10988 GFP_KERNEL);
10989 if (!new_coalesce.rules)
10990 return -ENOMEM;
10991
10992 new_coalesce.n_rules = n_rules;
10993 i = 0;
10994
10995 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10996 rem_rule) {
10997 err = nl80211_parse_coalesce_rule(rdev, rule,
10998 &new_coalesce.rules[i]);
10999 if (err)
11000 goto error;
11001
11002 i++;
11003 }
11004
Ilan Peera1056b1b2015-10-22 22:27:46 +030011005 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011006 if (err)
11007 goto error;
11008
11009 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
11010 if (!n_coalesce) {
11011 err = -ENOMEM;
11012 goto error;
11013 }
11014 cfg80211_rdev_free_coalesce(rdev);
11015 rdev->coalesce = n_coalesce;
11016
11017 return 0;
11018error:
11019 for (i = 0; i < new_coalesce.n_rules; i++) {
11020 tmp_rule = &new_coalesce.rules[i];
11021 for (j = 0; j < tmp_rule->n_patterns; j++)
11022 kfree(tmp_rule->patterns[j].mask);
11023 kfree(tmp_rule->patterns);
11024 }
11025 kfree(new_coalesce.rules);
11026
11027 return err;
11028}
11029
Johannes Berge5497d72011-07-05 16:35:40 +020011030static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11031{
11032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11033 struct net_device *dev = info->user_ptr[1];
11034 struct wireless_dev *wdev = dev->ieee80211_ptr;
11035 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
11036 struct cfg80211_gtk_rekey_data rekey_data;
11037 int err;
11038
11039 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11040 return -EINVAL;
11041
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011042 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
11043 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020011044 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020011045 if (err)
11046 return err;
11047
Vladis Dronove785fa02017-09-13 00:21:21 +020011048 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
11049 !tb[NL80211_REKEY_DATA_KCK])
11050 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020011051 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
11052 return -ERANGE;
11053 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
11054 return -ERANGE;
11055 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
11056 return -ERANGE;
11057
Johannes Berg78f686c2014-09-10 22:28:06 +030011058 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
11059 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
11060 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020011061
11062 wdev_lock(wdev);
11063 if (!wdev->current_bss) {
11064 err = -ENOTCONN;
11065 goto out;
11066 }
11067
11068 if (!rdev->ops->set_rekey_data) {
11069 err = -EOPNOTSUPP;
11070 goto out;
11071 }
11072
Hila Gonene35e4d22012-06-27 17:19:42 +030011073 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011074 out:
11075 wdev_unlock(wdev);
11076 return err;
11077}
11078
Johannes Berg28946da2011-11-04 11:18:12 +010011079static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11080 struct genl_info *info)
11081{
11082 struct net_device *dev = info->user_ptr[1];
11083 struct wireless_dev *wdev = dev->ieee80211_ptr;
11084
11085 if (wdev->iftype != NL80211_IFTYPE_AP &&
11086 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11087 return -EINVAL;
11088
Eric W. Biederman15e47302012-09-07 20:12:54 +000011089 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011090 return -EBUSY;
11091
Eric W. Biederman15e47302012-09-07 20:12:54 +000011092 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011093 return 0;
11094}
11095
Johannes Berg7f6cf312011-11-04 11:18:15 +010011096static int nl80211_probe_client(struct sk_buff *skb,
11097 struct genl_info *info)
11098{
11099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11100 struct net_device *dev = info->user_ptr[1];
11101 struct wireless_dev *wdev = dev->ieee80211_ptr;
11102 struct sk_buff *msg;
11103 void *hdr;
11104 const u8 *addr;
11105 u64 cookie;
11106 int err;
11107
11108 if (wdev->iftype != NL80211_IFTYPE_AP &&
11109 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11110 return -EOPNOTSUPP;
11111
11112 if (!info->attrs[NL80211_ATTR_MAC])
11113 return -EINVAL;
11114
11115 if (!rdev->ops->probe_client)
11116 return -EOPNOTSUPP;
11117
11118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11119 if (!msg)
11120 return -ENOMEM;
11121
Eric W. Biederman15e47302012-09-07 20:12:54 +000011122 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011123 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011124 if (!hdr) {
11125 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011126 goto free_msg;
11127 }
11128
11129 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11130
Hila Gonene35e4d22012-06-27 17:19:42 +030011131 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011132 if (err)
11133 goto free_msg;
11134
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011135 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11136 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011137 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011138
11139 genlmsg_end(msg, hdr);
11140
11141 return genlmsg_reply(msg, info);
11142
11143 nla_put_failure:
11144 err = -ENOBUFS;
11145 free_msg:
11146 nlmsg_free(msg);
11147 return err;
11148}
11149
Johannes Berg5e760232011-11-04 11:18:17 +010011150static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11151{
11152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011153 struct cfg80211_beacon_registration *reg, *nreg;
11154 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011155
11156 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11157 return -EOPNOTSUPP;
11158
Ben Greear37c73b52012-10-26 14:49:25 -070011159 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11160 if (!nreg)
11161 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011162
Ben Greear37c73b52012-10-26 14:49:25 -070011163 /* First, check if already registered. */
11164 spin_lock_bh(&rdev->beacon_registrations_lock);
11165 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11166 if (reg->nlportid == info->snd_portid) {
11167 rv = -EALREADY;
11168 goto out_err;
11169 }
11170 }
11171 /* Add it to the list */
11172 nreg->nlportid = info->snd_portid;
11173 list_add(&nreg->list, &rdev->beacon_registrations);
11174
11175 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011176
11177 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011178out_err:
11179 spin_unlock_bh(&rdev->beacon_registrations_lock);
11180 kfree(nreg);
11181 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011182}
11183
Johannes Berg98104fde2012-06-16 00:19:54 +020011184static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11185{
11186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11187 struct wireless_dev *wdev = info->user_ptr[1];
11188 int err;
11189
11190 if (!rdev->ops->start_p2p_device)
11191 return -EOPNOTSUPP;
11192
11193 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11194 return -EOPNOTSUPP;
11195
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011196 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011197 return 0;
11198
Luciano Coelhob6a55012014-02-27 11:07:21 +020011199 if (rfkill_blocked(rdev->rfkill))
11200 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011201
Johannes Bergeeb126e2012-10-23 15:16:50 +020011202 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011203 if (err)
11204 return err;
11205
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011206 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011207 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011208
11209 return 0;
11210}
11211
11212static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11213{
11214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11215 struct wireless_dev *wdev = info->user_ptr[1];
11216
11217 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11218 return -EOPNOTSUPP;
11219
11220 if (!rdev->ops->stop_p2p_device)
11221 return -EOPNOTSUPP;
11222
Johannes Bergf9f47522013-03-19 15:04:07 +010011223 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011224
11225 return 0;
11226}
11227
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011228static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11229{
11230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11231 struct wireless_dev *wdev = info->user_ptr[1];
11232 struct cfg80211_nan_conf conf = {};
11233 int err;
11234
11235 if (wdev->iftype != NL80211_IFTYPE_NAN)
11236 return -EOPNOTSUPP;
11237
Johannes Bergeeb04a92016-11-21 13:55:48 +010011238 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011239 return -EEXIST;
11240
11241 if (rfkill_blocked(rdev->rfkill))
11242 return -ERFKILL;
11243
11244 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11245 return -EINVAL;
11246
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011247 conf.master_pref =
11248 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11249 if (!conf.master_pref)
11250 return -EINVAL;
11251
Luca Coelho85859892017-02-08 15:00:34 +020011252 if (info->attrs[NL80211_ATTR_BANDS]) {
11253 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11254
11255 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11256 return -EOPNOTSUPP;
11257
11258 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11259 return -EINVAL;
11260
11261 conf.bands = bands;
11262 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011263
11264 err = rdev_start_nan(rdev, wdev, &conf);
11265 if (err)
11266 return err;
11267
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011268 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011269 rdev->opencount++;
11270
11271 return 0;
11272}
11273
11274static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11275{
11276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11277 struct wireless_dev *wdev = info->user_ptr[1];
11278
11279 if (wdev->iftype != NL80211_IFTYPE_NAN)
11280 return -EOPNOTSUPP;
11281
11282 cfg80211_stop_nan(rdev, wdev);
11283
11284 return 0;
11285}
11286
Ayala Bekera442b762016-09-20 17:31:15 +030011287static int validate_nan_filter(struct nlattr *filter_attr)
11288{
11289 struct nlattr *attr;
11290 int len = 0, n_entries = 0, rem;
11291
11292 nla_for_each_nested(attr, filter_attr, rem) {
11293 len += nla_len(attr);
11294 n_entries++;
11295 }
11296
11297 if (len >= U8_MAX)
11298 return -EINVAL;
11299
11300 return n_entries;
11301}
11302
11303static int handle_nan_filter(struct nlattr *attr_filter,
11304 struct cfg80211_nan_func *func,
11305 bool tx)
11306{
11307 struct nlattr *attr;
11308 int n_entries, rem, i;
11309 struct cfg80211_nan_func_filter *filter;
11310
11311 n_entries = validate_nan_filter(attr_filter);
11312 if (n_entries < 0)
11313 return n_entries;
11314
11315 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11316
11317 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11318 if (!filter)
11319 return -ENOMEM;
11320
11321 i = 0;
11322 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011323 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011324 filter[i].len = nla_len(attr);
11325 i++;
11326 }
11327 if (tx) {
11328 func->num_tx_filters = n_entries;
11329 func->tx_filters = filter;
11330 } else {
11331 func->num_rx_filters = n_entries;
11332 func->rx_filters = filter;
11333 }
11334
11335 return 0;
11336}
11337
11338static int nl80211_nan_add_func(struct sk_buff *skb,
11339 struct genl_info *info)
11340{
11341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11342 struct wireless_dev *wdev = info->user_ptr[1];
11343 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11344 struct cfg80211_nan_func *func;
11345 struct sk_buff *msg = NULL;
11346 void *hdr = NULL;
11347 int err = 0;
11348
11349 if (wdev->iftype != NL80211_IFTYPE_NAN)
11350 return -EOPNOTSUPP;
11351
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011352 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011353 return -ENOTCONN;
11354
11355 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11356 return -EINVAL;
11357
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011358 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11359 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011360 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011361 if (err)
11362 return err;
11363
11364 func = kzalloc(sizeof(*func), GFP_KERNEL);
11365 if (!func)
11366 return -ENOMEM;
11367
11368 func->cookie = wdev->wiphy->cookie_counter++;
11369
11370 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11371 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11372 err = -EINVAL;
11373 goto out;
11374 }
11375
11376
11377 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11378
11379 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11380 err = -EINVAL;
11381 goto out;
11382 }
11383
11384 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11385 sizeof(func->service_id));
11386
11387 func->close_range =
11388 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11389
11390 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11391 func->serv_spec_info_len =
11392 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11393 func->serv_spec_info =
11394 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11395 func->serv_spec_info_len,
11396 GFP_KERNEL);
11397 if (!func->serv_spec_info) {
11398 err = -ENOMEM;
11399 goto out;
11400 }
11401 }
11402
11403 if (tb[NL80211_NAN_FUNC_TTL])
11404 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11405
11406 switch (func->type) {
11407 case NL80211_NAN_FUNC_PUBLISH:
11408 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11409 err = -EINVAL;
11410 goto out;
11411 }
11412
11413 func->publish_type =
11414 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11415 func->publish_bcast =
11416 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11417
11418 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11419 func->publish_bcast) {
11420 err = -EINVAL;
11421 goto out;
11422 }
11423 break;
11424 case NL80211_NAN_FUNC_SUBSCRIBE:
11425 func->subscribe_active =
11426 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11427 break;
11428 case NL80211_NAN_FUNC_FOLLOW_UP:
11429 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080011430 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11431 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030011432 err = -EINVAL;
11433 goto out;
11434 }
11435
11436 func->followup_id =
11437 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11438 func->followup_reqid =
11439 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11440 memcpy(func->followup_dest.addr,
11441 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11442 sizeof(func->followup_dest.addr));
11443 if (func->ttl) {
11444 err = -EINVAL;
11445 goto out;
11446 }
11447 break;
11448 default:
11449 err = -EINVAL;
11450 goto out;
11451 }
11452
11453 if (tb[NL80211_NAN_FUNC_SRF]) {
11454 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11455
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011456 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11457 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011458 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011459 if (err)
11460 goto out;
11461
11462 func->srf_include =
11463 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11464
11465 if (srf_tb[NL80211_NAN_SRF_BF]) {
11466 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11467 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11468 err = -EINVAL;
11469 goto out;
11470 }
11471
11472 func->srf_bf_len =
11473 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11474 func->srf_bf =
11475 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11476 func->srf_bf_len, GFP_KERNEL);
11477 if (!func->srf_bf) {
11478 err = -ENOMEM;
11479 goto out;
11480 }
11481
11482 func->srf_bf_idx =
11483 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11484 } else {
11485 struct nlattr *attr, *mac_attr =
11486 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11487 int n_entries, rem, i = 0;
11488
11489 if (!mac_attr) {
11490 err = -EINVAL;
11491 goto out;
11492 }
11493
11494 n_entries = validate_acl_mac_addrs(mac_attr);
11495 if (n_entries <= 0) {
11496 err = -EINVAL;
11497 goto out;
11498 }
11499
11500 func->srf_num_macs = n_entries;
11501 func->srf_macs =
11502 kzalloc(sizeof(*func->srf_macs) * n_entries,
11503 GFP_KERNEL);
11504 if (!func->srf_macs) {
11505 err = -ENOMEM;
11506 goto out;
11507 }
11508
11509 nla_for_each_nested(attr, mac_attr, rem)
11510 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11511 sizeof(*func->srf_macs));
11512 }
11513 }
11514
11515 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11516 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11517 func, true);
11518 if (err)
11519 goto out;
11520 }
11521
11522 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11523 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11524 func, false);
11525 if (err)
11526 goto out;
11527 }
11528
11529 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11530 if (!msg) {
11531 err = -ENOMEM;
11532 goto out;
11533 }
11534
11535 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11536 NL80211_CMD_ADD_NAN_FUNCTION);
11537 /* This can't really happen - we just allocated 4KB */
11538 if (WARN_ON(!hdr)) {
11539 err = -ENOMEM;
11540 goto out;
11541 }
11542
11543 err = rdev_add_nan_func(rdev, wdev, func);
11544out:
11545 if (err < 0) {
11546 cfg80211_free_nan_func(func);
11547 nlmsg_free(msg);
11548 return err;
11549 }
11550
11551 /* propagate the instance id and cookie to userspace */
11552 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11553 NL80211_ATTR_PAD))
11554 goto nla_put_failure;
11555
11556 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11557 if (!func_attr)
11558 goto nla_put_failure;
11559
11560 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11561 func->instance_id))
11562 goto nla_put_failure;
11563
11564 nla_nest_end(msg, func_attr);
11565
11566 genlmsg_end(msg, hdr);
11567 return genlmsg_reply(msg, info);
11568
11569nla_put_failure:
11570 nlmsg_free(msg);
11571 return -ENOBUFS;
11572}
11573
11574static int nl80211_nan_del_func(struct sk_buff *skb,
11575 struct genl_info *info)
11576{
11577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11578 struct wireless_dev *wdev = info->user_ptr[1];
11579 u64 cookie;
11580
11581 if (wdev->iftype != NL80211_IFTYPE_NAN)
11582 return -EOPNOTSUPP;
11583
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011584 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011585 return -ENOTCONN;
11586
11587 if (!info->attrs[NL80211_ATTR_COOKIE])
11588 return -EINVAL;
11589
Ayala Bekera442b762016-09-20 17:31:15 +030011590 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11591
11592 rdev_del_nan_func(rdev, wdev, cookie);
11593
11594 return 0;
11595}
11596
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011597static int nl80211_nan_change_config(struct sk_buff *skb,
11598 struct genl_info *info)
11599{
11600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11601 struct wireless_dev *wdev = info->user_ptr[1];
11602 struct cfg80211_nan_conf conf = {};
11603 u32 changed = 0;
11604
11605 if (wdev->iftype != NL80211_IFTYPE_NAN)
11606 return -EOPNOTSUPP;
11607
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011608 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011609 return -ENOTCONN;
11610
11611 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11612 conf.master_pref =
11613 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11614 if (conf.master_pref <= 1 || conf.master_pref == 255)
11615 return -EINVAL;
11616
11617 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11618 }
11619
Luca Coelho85859892017-02-08 15:00:34 +020011620 if (info->attrs[NL80211_ATTR_BANDS]) {
11621 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11622
11623 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11624 return -EOPNOTSUPP;
11625
11626 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11627 return -EINVAL;
11628
11629 conf.bands = bands;
11630 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011631 }
11632
11633 if (!changed)
11634 return -EINVAL;
11635
11636 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11637}
11638
Ayala Beker50bcd312016-09-20 17:31:17 +030011639void cfg80211_nan_match(struct wireless_dev *wdev,
11640 struct cfg80211_nan_match_params *match, gfp_t gfp)
11641{
11642 struct wiphy *wiphy = wdev->wiphy;
11643 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11644 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11645 struct sk_buff *msg;
11646 void *hdr;
11647
11648 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11649 return;
11650
11651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11652 if (!msg)
11653 return;
11654
11655 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11656 if (!hdr) {
11657 nlmsg_free(msg);
11658 return;
11659 }
11660
11661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11662 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11663 wdev->netdev->ifindex)) ||
11664 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11665 NL80211_ATTR_PAD))
11666 goto nla_put_failure;
11667
11668 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11669 NL80211_ATTR_PAD) ||
11670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11671 goto nla_put_failure;
11672
11673 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11674 if (!match_attr)
11675 goto nla_put_failure;
11676
11677 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11678 if (!local_func_attr)
11679 goto nla_put_failure;
11680
11681 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11682 goto nla_put_failure;
11683
11684 nla_nest_end(msg, local_func_attr);
11685
11686 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11687 if (!peer_func_attr)
11688 goto nla_put_failure;
11689
11690 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11691 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11692 goto nla_put_failure;
11693
11694 if (match->info && match->info_len &&
11695 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11696 match->info))
11697 goto nla_put_failure;
11698
11699 nla_nest_end(msg, peer_func_attr);
11700 nla_nest_end(msg, match_attr);
11701 genlmsg_end(msg, hdr);
11702
11703 if (!wdev->owner_nlportid)
11704 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11705 msg, 0, NL80211_MCGRP_NAN, gfp);
11706 else
11707 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11708 wdev->owner_nlportid);
11709
11710 return;
11711
11712nla_put_failure:
11713 nlmsg_free(msg);
11714}
11715EXPORT_SYMBOL(cfg80211_nan_match);
11716
Ayala Beker368e5a72016-09-20 17:31:18 +030011717void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11718 u8 inst_id,
11719 enum nl80211_nan_func_term_reason reason,
11720 u64 cookie, gfp_t gfp)
11721{
11722 struct wiphy *wiphy = wdev->wiphy;
11723 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11724 struct sk_buff *msg;
11725 struct nlattr *func_attr;
11726 void *hdr;
11727
11728 if (WARN_ON(!inst_id))
11729 return;
11730
11731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11732 if (!msg)
11733 return;
11734
11735 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11736 if (!hdr) {
11737 nlmsg_free(msg);
11738 return;
11739 }
11740
11741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11742 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11743 wdev->netdev->ifindex)) ||
11744 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11745 NL80211_ATTR_PAD))
11746 goto nla_put_failure;
11747
11748 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11749 NL80211_ATTR_PAD))
11750 goto nla_put_failure;
11751
11752 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11753 if (!func_attr)
11754 goto nla_put_failure;
11755
11756 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11757 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11758 goto nla_put_failure;
11759
11760 nla_nest_end(msg, func_attr);
11761 genlmsg_end(msg, hdr);
11762
11763 if (!wdev->owner_nlportid)
11764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11765 msg, 0, NL80211_MCGRP_NAN, gfp);
11766 else
11767 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11768 wdev->owner_nlportid);
11769
11770 return;
11771
11772nla_put_failure:
11773 nlmsg_free(msg);
11774}
11775EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11776
Johannes Berg3713b4e2013-02-14 16:19:38 +010011777static int nl80211_get_protocol_features(struct sk_buff *skb,
11778 struct genl_info *info)
11779{
11780 void *hdr;
11781 struct sk_buff *msg;
11782
11783 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11784 if (!msg)
11785 return -ENOMEM;
11786
11787 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11788 NL80211_CMD_GET_PROTOCOL_FEATURES);
11789 if (!hdr)
11790 goto nla_put_failure;
11791
11792 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11793 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11794 goto nla_put_failure;
11795
11796 genlmsg_end(msg, hdr);
11797 return genlmsg_reply(msg, info);
11798
11799 nla_put_failure:
11800 kfree_skb(msg);
11801 return -ENOBUFS;
11802}
11803
Jouni Malinen355199e2013-02-27 17:14:27 +020011804static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11805{
11806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11807 struct cfg80211_update_ft_ies_params ft_params;
11808 struct net_device *dev = info->user_ptr[1];
11809
11810 if (!rdev->ops->update_ft_ies)
11811 return -EOPNOTSUPP;
11812
11813 if (!info->attrs[NL80211_ATTR_MDID] ||
11814 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11815 return -EINVAL;
11816
11817 memset(&ft_params, 0, sizeof(ft_params));
11818 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11819 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11820 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11821
11822 return rdev_update_ft_ies(rdev, dev, &ft_params);
11823}
11824
Arend van Spriel5de17982013-04-18 15:49:00 +020011825static int nl80211_crit_protocol_start(struct sk_buff *skb,
11826 struct genl_info *info)
11827{
11828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11829 struct wireless_dev *wdev = info->user_ptr[1];
11830 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11831 u16 duration;
11832 int ret;
11833
11834 if (!rdev->ops->crit_proto_start)
11835 return -EOPNOTSUPP;
11836
11837 if (WARN_ON(!rdev->ops->crit_proto_stop))
11838 return -EINVAL;
11839
11840 if (rdev->crit_proto_nlportid)
11841 return -EBUSY;
11842
11843 /* determine protocol if provided */
11844 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11845 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11846
11847 if (proto >= NUM_NL80211_CRIT_PROTO)
11848 return -EINVAL;
11849
11850 /* timeout must be provided */
11851 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11852 return -EINVAL;
11853
11854 duration =
11855 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11856
11857 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11858 return -ERANGE;
11859
11860 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11861 if (!ret)
11862 rdev->crit_proto_nlportid = info->snd_portid;
11863
11864 return ret;
11865}
11866
11867static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11868 struct genl_info *info)
11869{
11870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11871 struct wireless_dev *wdev = info->user_ptr[1];
11872
11873 if (!rdev->ops->crit_proto_stop)
11874 return -EOPNOTSUPP;
11875
11876 if (rdev->crit_proto_nlportid) {
11877 rdev->crit_proto_nlportid = 0;
11878 rdev_crit_proto_stop(rdev, wdev);
11879 }
11880 return 0;
11881}
11882
Johannes Bergad7e7182013-11-13 13:37:47 +010011883static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11884{
11885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11886 struct wireless_dev *wdev =
11887 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11888 int i, err;
11889 u32 vid, subcmd;
11890
11891 if (!rdev->wiphy.vendor_commands)
11892 return -EOPNOTSUPP;
11893
11894 if (IS_ERR(wdev)) {
11895 err = PTR_ERR(wdev);
11896 if (err != -EINVAL)
11897 return err;
11898 wdev = NULL;
11899 } else if (wdev->wiphy != &rdev->wiphy) {
11900 return -EINVAL;
11901 }
11902
11903 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11904 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11905 return -EINVAL;
11906
11907 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11908 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11909 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11910 const struct wiphy_vendor_command *vcmd;
11911 void *data = NULL;
11912 int len = 0;
11913
11914 vcmd = &rdev->wiphy.vendor_commands[i];
11915
11916 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11917 continue;
11918
11919 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11920 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11921 if (!wdev)
11922 return -EINVAL;
11923 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11924 !wdev->netdev)
11925 return -EINVAL;
11926
11927 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011928 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011929 return -ENETDOWN;
11930 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011931
11932 if (!vcmd->doit)
11933 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011934 } else {
11935 wdev = NULL;
11936 }
11937
11938 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11939 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11940 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11941 }
11942
11943 rdev->cur_cmd_info = info;
11944 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11945 data, len);
11946 rdev->cur_cmd_info = NULL;
11947 return err;
11948 }
11949
11950 return -EOPNOTSUPP;
11951}
11952
Johannes Berg7bdbe402015-08-15 22:39:49 +030011953static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11954 struct netlink_callback *cb,
11955 struct cfg80211_registered_device **rdev,
11956 struct wireless_dev **wdev)
11957{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011958 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011959 u32 vid, subcmd;
11960 unsigned int i;
11961 int vcmd_idx = -1;
11962 int err;
11963 void *data = NULL;
11964 unsigned int data_len = 0;
11965
Johannes Berg7bdbe402015-08-15 22:39:49 +030011966 if (cb->args[0]) {
11967 /* subtract the 1 again here */
11968 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11969 struct wireless_dev *tmp;
11970
Johannes Bergea90e0d2017-03-15 14:26:04 +010011971 if (!wiphy)
11972 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011973 *rdev = wiphy_to_rdev(wiphy);
11974 *wdev = NULL;
11975
11976 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011977 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011978 if (tmp->identifier == cb->args[1] - 1) {
11979 *wdev = tmp;
11980 break;
11981 }
11982 }
11983 }
11984
11985 /* keep rtnl locked in successful case */
11986 return 0;
11987 }
11988
Johannes Bergfceb6432017-04-12 14:34:07 +020011989 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11990 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011991 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011992 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011993
Johannes Bergc90c39d2016-10-24 14:40:01 +020011994 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011995 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11996 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011997
Johannes Bergc90c39d2016-10-24 14:40:01 +020011998 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011999 if (IS_ERR(*wdev))
12000 *wdev = NULL;
12001
Johannes Bergc90c39d2016-10-24 14:40:01 +020012002 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010012003 if (IS_ERR(*rdev))
12004 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012005
Johannes Bergc90c39d2016-10-24 14:40:01 +020012006 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
12007 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012008
12009 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
12010 const struct wiphy_vendor_command *vcmd;
12011
12012 vcmd = &(*rdev)->wiphy.vendor_commands[i];
12013
12014 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12015 continue;
12016
Johannes Bergea90e0d2017-03-15 14:26:04 +010012017 if (!vcmd->dumpit)
12018 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012019
12020 vcmd_idx = i;
12021 break;
12022 }
12023
Johannes Bergea90e0d2017-03-15 14:26:04 +010012024 if (vcmd_idx < 0)
12025 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012026
Johannes Bergc90c39d2016-10-24 14:40:01 +020012027 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
12028 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
12029 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030012030 }
12031
12032 /* 0 is the first index - add 1 to parse only once */
12033 cb->args[0] = (*rdev)->wiphy_idx + 1;
12034 /* add 1 to know if it was NULL */
12035 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
12036 cb->args[2] = vcmd_idx;
12037 cb->args[3] = (unsigned long)data;
12038 cb->args[4] = data_len;
12039
12040 /* keep rtnl locked in successful case */
12041 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012042}
12043
12044static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12045 struct netlink_callback *cb)
12046{
12047 struct cfg80211_registered_device *rdev;
12048 struct wireless_dev *wdev;
12049 unsigned int vcmd_idx;
12050 const struct wiphy_vendor_command *vcmd;
12051 void *data;
12052 int data_len;
12053 int err;
12054 struct nlattr *vendor_data;
12055
Johannes Bergea90e0d2017-03-15 14:26:04 +010012056 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030012057 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
12058 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010012059 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030012060
12061 vcmd_idx = cb->args[2];
12062 data = (void *)cb->args[3];
12063 data_len = cb->args[4];
12064 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12065
12066 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12067 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012068 if (!wdev) {
12069 err = -EINVAL;
12070 goto out;
12071 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012072 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012073 !wdev->netdev) {
12074 err = -EINVAL;
12075 goto out;
12076 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012077
12078 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012079 if (!wdev_running(wdev)) {
12080 err = -ENETDOWN;
12081 goto out;
12082 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012083 }
12084 }
12085
12086 while (1) {
12087 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12088 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12089 NL80211_CMD_VENDOR);
12090 if (!hdr)
12091 break;
12092
12093 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012094 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12095 wdev_id(wdev),
12096 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012097 genlmsg_cancel(skb, hdr);
12098 break;
12099 }
12100
12101 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12102 if (!vendor_data) {
12103 genlmsg_cancel(skb, hdr);
12104 break;
12105 }
12106
12107 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12108 (unsigned long *)&cb->args[5]);
12109 nla_nest_end(skb, vendor_data);
12110
12111 if (err == -ENOBUFS || err == -ENOENT) {
12112 genlmsg_cancel(skb, hdr);
12113 break;
12114 } else if (err) {
12115 genlmsg_cancel(skb, hdr);
12116 goto out;
12117 }
12118
12119 genlmsg_end(skb, hdr);
12120 }
12121
12122 err = skb->len;
12123 out:
12124 rtnl_unlock();
12125 return err;
12126}
12127
Johannes Bergad7e7182013-11-13 13:37:47 +010012128struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12129 enum nl80211_commands cmd,
12130 enum nl80211_attrs attr,
12131 int approxlen)
12132{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012133 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012134
12135 if (WARN_ON(!rdev->cur_cmd_info))
12136 return NULL;
12137
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012138 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012139 rdev->cur_cmd_info->snd_portid,
12140 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012141 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012142}
12143EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12144
12145int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12146{
12147 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12148 void *hdr = ((void **)skb->cb)[1];
12149 struct nlattr *data = ((void **)skb->cb)[2];
12150
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012151 /* clear CB data for netlink core to own from now on */
12152 memset(skb->cb, 0, sizeof(skb->cb));
12153
Johannes Bergad7e7182013-11-13 13:37:47 +010012154 if (WARN_ON(!rdev->cur_cmd_info)) {
12155 kfree_skb(skb);
12156 return -EINVAL;
12157 }
12158
12159 nla_nest_end(skb, data);
12160 genlmsg_end(skb, hdr);
12161 return genlmsg_reply(skb, rdev->cur_cmd_info);
12162}
12163EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12164
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012165static int nl80211_set_qos_map(struct sk_buff *skb,
12166 struct genl_info *info)
12167{
12168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12169 struct cfg80211_qos_map *qos_map = NULL;
12170 struct net_device *dev = info->user_ptr[1];
12171 u8 *pos, len, num_des, des_len, des;
12172 int ret;
12173
12174 if (!rdev->ops->set_qos_map)
12175 return -EOPNOTSUPP;
12176
12177 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12178 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12179 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12180
12181 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12182 len > IEEE80211_QOS_MAP_LEN_MAX)
12183 return -EINVAL;
12184
12185 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12186 if (!qos_map)
12187 return -ENOMEM;
12188
12189 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12190 if (num_des) {
12191 des_len = num_des *
12192 sizeof(struct cfg80211_dscp_exception);
12193 memcpy(qos_map->dscp_exception, pos, des_len);
12194 qos_map->num_des = num_des;
12195 for (des = 0; des < num_des; des++) {
12196 if (qos_map->dscp_exception[des].up > 7) {
12197 kfree(qos_map);
12198 return -EINVAL;
12199 }
12200 }
12201 pos += des_len;
12202 }
12203 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12204 }
12205
12206 wdev_lock(dev->ieee80211_ptr);
12207 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12208 if (!ret)
12209 ret = rdev_set_qos_map(rdev, dev, qos_map);
12210 wdev_unlock(dev->ieee80211_ptr);
12211
12212 kfree(qos_map);
12213 return ret;
12214}
12215
Johannes Berg960d01a2014-09-09 22:55:35 +030012216static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12217{
12218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12219 struct net_device *dev = info->user_ptr[1];
12220 struct wireless_dev *wdev = dev->ieee80211_ptr;
12221 const u8 *peer;
12222 u8 tsid, up;
12223 u16 admitted_time = 0;
12224 int err;
12225
Johannes Berg723e73a2014-10-22 09:25:06 +020012226 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012227 return -EOPNOTSUPP;
12228
12229 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12230 !info->attrs[NL80211_ATTR_USER_PRIO])
12231 return -EINVAL;
12232
12233 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12234 if (tsid >= IEEE80211_NUM_TIDS)
12235 return -EINVAL;
12236
12237 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12238 if (up >= IEEE80211_NUM_UPS)
12239 return -EINVAL;
12240
12241 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012242 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012243 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012244 * need more attributes for that (e.g. BA session requirement);
12245 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012246 */
12247 return -EINVAL;
12248 }
12249
12250 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12251
12252 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12253 admitted_time =
12254 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12255 if (!admitted_time)
12256 return -EINVAL;
12257 }
12258
12259 wdev_lock(wdev);
12260 switch (wdev->iftype) {
12261 case NL80211_IFTYPE_STATION:
12262 case NL80211_IFTYPE_P2P_CLIENT:
12263 if (wdev->current_bss)
12264 break;
12265 err = -ENOTCONN;
12266 goto out;
12267 default:
12268 err = -EOPNOTSUPP;
12269 goto out;
12270 }
12271
12272 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12273
12274 out:
12275 wdev_unlock(wdev);
12276 return err;
12277}
12278
12279static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12280{
12281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12282 struct net_device *dev = info->user_ptr[1];
12283 struct wireless_dev *wdev = dev->ieee80211_ptr;
12284 const u8 *peer;
12285 u8 tsid;
12286 int err;
12287
12288 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12289 return -EINVAL;
12290
12291 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12292 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12293
12294 wdev_lock(wdev);
12295 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12296 wdev_unlock(wdev);
12297
12298 return err;
12299}
12300
Arik Nemtsov1057d352014-11-19 12:54:26 +020012301static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12302 struct genl_info *info)
12303{
12304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12305 struct net_device *dev = info->user_ptr[1];
12306 struct wireless_dev *wdev = dev->ieee80211_ptr;
12307 struct cfg80211_chan_def chandef = {};
12308 const u8 *addr;
12309 u8 oper_class;
12310 int err;
12311
12312 if (!rdev->ops->tdls_channel_switch ||
12313 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12314 return -EOPNOTSUPP;
12315
12316 switch (dev->ieee80211_ptr->iftype) {
12317 case NL80211_IFTYPE_STATION:
12318 case NL80211_IFTYPE_P2P_CLIENT:
12319 break;
12320 default:
12321 return -EOPNOTSUPP;
12322 }
12323
12324 if (!info->attrs[NL80211_ATTR_MAC] ||
12325 !info->attrs[NL80211_ATTR_OPER_CLASS])
12326 return -EINVAL;
12327
12328 err = nl80211_parse_chandef(rdev, info, &chandef);
12329 if (err)
12330 return err;
12331
12332 /*
12333 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12334 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12335 * specification is not defined for them.
12336 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012337 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012338 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12339 chandef.width != NL80211_CHAN_WIDTH_20)
12340 return -EINVAL;
12341
12342 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012343 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12344 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012345 return -EINVAL;
12346
12347 /* don't allow switching to DFS channels */
12348 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12349 return -EINVAL;
12350
12351 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12352 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12353
12354 wdev_lock(wdev);
12355 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12356 wdev_unlock(wdev);
12357
12358 return err;
12359}
12360
12361static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12362 struct genl_info *info)
12363{
12364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12365 struct net_device *dev = info->user_ptr[1];
12366 struct wireless_dev *wdev = dev->ieee80211_ptr;
12367 const u8 *addr;
12368
12369 if (!rdev->ops->tdls_channel_switch ||
12370 !rdev->ops->tdls_cancel_channel_switch ||
12371 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12372 return -EOPNOTSUPP;
12373
12374 switch (dev->ieee80211_ptr->iftype) {
12375 case NL80211_IFTYPE_STATION:
12376 case NL80211_IFTYPE_P2P_CLIENT:
12377 break;
12378 default:
12379 return -EOPNOTSUPP;
12380 }
12381
12382 if (!info->attrs[NL80211_ATTR_MAC])
12383 return -EINVAL;
12384
12385 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12386
12387 wdev_lock(wdev);
12388 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12389 wdev_unlock(wdev);
12390
12391 return 0;
12392}
12393
Michael Braunce0ce132016-10-10 19:12:22 +020012394static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12395 struct genl_info *info)
12396{
12397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12398 struct net_device *dev = info->user_ptr[1];
12399 struct wireless_dev *wdev = dev->ieee80211_ptr;
12400 const struct nlattr *nla;
12401 bool enabled;
12402
Michael Braunce0ce132016-10-10 19:12:22 +020012403 if (!rdev->ops->set_multicast_to_unicast)
12404 return -EOPNOTSUPP;
12405
12406 if (wdev->iftype != NL80211_IFTYPE_AP &&
12407 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12408 return -EOPNOTSUPP;
12409
12410 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12411 enabled = nla_get_flag(nla);
12412
12413 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12414}
12415
Avraham Stern3a00df52017-06-09 13:08:43 +010012416static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12417{
12418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12419 struct net_device *dev = info->user_ptr[1];
12420 struct wireless_dev *wdev = dev->ieee80211_ptr;
12421 struct cfg80211_pmk_conf pmk_conf = {};
12422 int ret;
12423
12424 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12425 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12426 return -EOPNOTSUPP;
12427
12428 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12429 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12430 return -EOPNOTSUPP;
12431
12432 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12433 return -EINVAL;
12434
12435 wdev_lock(wdev);
12436 if (!wdev->current_bss) {
12437 ret = -ENOTCONN;
12438 goto out;
12439 }
12440
12441 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12442 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12443 ret = -EINVAL;
12444 goto out;
12445 }
12446
12447 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12448 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12449 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12450 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12451 ret = -EINVAL;
12452 goto out;
12453 }
12454
12455 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12456 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12457
12458 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12459 ret = -EINVAL;
12460 goto out;
12461 }
12462
12463 pmk_conf.pmk_r0_name =
12464 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12465 }
12466
12467 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12468out:
12469 wdev_unlock(wdev);
12470 return ret;
12471}
12472
12473static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12474{
12475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12476 struct net_device *dev = info->user_ptr[1];
12477 struct wireless_dev *wdev = dev->ieee80211_ptr;
12478 const u8 *aa;
12479 int ret;
12480
12481 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12482 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12483 return -EOPNOTSUPP;
12484
12485 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12486 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12487 return -EOPNOTSUPP;
12488
12489 if (!info->attrs[NL80211_ATTR_MAC])
12490 return -EINVAL;
12491
12492 wdev_lock(wdev);
12493 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12494 ret = rdev_del_pmk(rdev, dev, aa);
12495 wdev_unlock(wdev);
12496
12497 return ret;
12498}
12499
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012500static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
12501{
12502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12503 struct net_device *dev = info->user_ptr[1];
12504 struct cfg80211_external_auth_params params;
12505
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020012506 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020012507 return -EOPNOTSUPP;
12508
12509 if (!info->attrs[NL80211_ATTR_SSID])
12510 return -EINVAL;
12511
12512 if (!info->attrs[NL80211_ATTR_BSSID])
12513 return -EINVAL;
12514
12515 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
12516 return -EINVAL;
12517
12518 memset(&params, 0, sizeof(params));
12519
12520 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12521 if (params.ssid.ssid_len == 0 ||
12522 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
12523 return -EINVAL;
12524 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
12525 params.ssid.ssid_len);
12526
12527 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
12528 ETH_ALEN);
12529
12530 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12531
12532 return rdev_external_auth(rdev, dev, &params);
12533}
12534
Johannes Berg4c476992010-10-04 21:36:35 +020012535#define NL80211_FLAG_NEED_WIPHY 0x01
12536#define NL80211_FLAG_NEED_NETDEV 0x02
12537#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012538#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12539#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12540 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012541#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012542/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012543#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12544 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012545#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012546
Johannes Bergf84f7712013-11-14 17:14:45 +010012547static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012548 struct genl_info *info)
12549{
12550 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012551 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012552 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012553 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12554
12555 if (rtnl)
12556 rtnl_lock();
12557
12558 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012559 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012560 if (IS_ERR(rdev)) {
12561 if (rtnl)
12562 rtnl_unlock();
12563 return PTR_ERR(rdev);
12564 }
12565 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012566 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12567 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012568 ASSERT_RTNL();
12569
Johannes Berg89a54e42012-06-15 14:33:17 +020012570 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12571 info->attrs);
12572 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012573 if (rtnl)
12574 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012575 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012576 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012577
Johannes Berg89a54e42012-06-15 14:33:17 +020012578 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012579 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012580
Johannes Berg1bf614e2012-06-15 15:23:36 +020012581 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12582 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012583 if (rtnl)
12584 rtnl_unlock();
12585 return -EINVAL;
12586 }
12587
12588 info->user_ptr[1] = dev;
12589 } else {
12590 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012591 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012592
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012593 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12594 !wdev_running(wdev)) {
12595 if (rtnl)
12596 rtnl_unlock();
12597 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012598 }
12599
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012600 if (dev)
12601 dev_hold(dev);
12602
Johannes Berg4c476992010-10-04 21:36:35 +020012603 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012604 }
12605
12606 return 0;
12607}
12608
Johannes Bergf84f7712013-11-14 17:14:45 +010012609static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012610 struct genl_info *info)
12611{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012612 if (info->user_ptr[1]) {
12613 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12614 struct wireless_dev *wdev = info->user_ptr[1];
12615
12616 if (wdev->netdev)
12617 dev_put(wdev->netdev);
12618 } else {
12619 dev_put(info->user_ptr[1]);
12620 }
12621 }
Johannes Berg5393b912014-09-10 15:00:16 +030012622
Johannes Berg4c476992010-10-04 21:36:35 +020012623 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12624 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012625
12626 /* If needed, clear the netlink message payload from the SKB
12627 * as it might contain key data that shouldn't stick around on
12628 * the heap after the SKB is freed. The netlink message header
12629 * is still needed for further processing, so leave it intact.
12630 */
12631 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12632 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12633
12634 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12635 }
Johannes Berg4c476992010-10-04 21:36:35 +020012636}
12637
Johannes Berg4534de82013-11-14 17:14:46 +010012638static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012639 {
12640 .cmd = NL80211_CMD_GET_WIPHY,
12641 .doit = nl80211_get_wiphy,
12642 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012643 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012644 .policy = nl80211_policy,
12645 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012646 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12647 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012648 },
12649 {
12650 .cmd = NL80211_CMD_SET_WIPHY,
12651 .doit = nl80211_set_wiphy,
12652 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012653 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012654 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012655 },
12656 {
12657 .cmd = NL80211_CMD_GET_INTERFACE,
12658 .doit = nl80211_get_interface,
12659 .dumpit = nl80211_dump_interface,
12660 .policy = nl80211_policy,
12661 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012662 .internal_flags = NL80211_FLAG_NEED_WDEV |
12663 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012664 },
12665 {
12666 .cmd = NL80211_CMD_SET_INTERFACE,
12667 .doit = nl80211_set_interface,
12668 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012669 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012670 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12671 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012672 },
12673 {
12674 .cmd = NL80211_CMD_NEW_INTERFACE,
12675 .doit = nl80211_new_interface,
12676 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012677 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012678 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12679 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012680 },
12681 {
12682 .cmd = NL80211_CMD_DEL_INTERFACE,
12683 .doit = nl80211_del_interface,
12684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012685 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012686 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012687 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012688 },
Johannes Berg41ade002007-12-19 02:03:29 +010012689 {
12690 .cmd = NL80211_CMD_GET_KEY,
12691 .doit = nl80211_get_key,
12692 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012693 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012694 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012695 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012696 },
12697 {
12698 .cmd = NL80211_CMD_SET_KEY,
12699 .doit = nl80211_set_key,
12700 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012701 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012703 NL80211_FLAG_NEED_RTNL |
12704 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012705 },
12706 {
12707 .cmd = NL80211_CMD_NEW_KEY,
12708 .doit = nl80211_new_key,
12709 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012710 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012712 NL80211_FLAG_NEED_RTNL |
12713 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012714 },
12715 {
12716 .cmd = NL80211_CMD_DEL_KEY,
12717 .doit = nl80211_del_key,
12718 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012719 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012720 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012721 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012722 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012723 {
12724 .cmd = NL80211_CMD_SET_BEACON,
12725 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012726 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012727 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012729 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012730 },
12731 {
Johannes Berg88600202012-02-13 15:17:18 +010012732 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012733 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012734 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012735 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012737 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012738 },
12739 {
Johannes Berg88600202012-02-13 15:17:18 +010012740 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012741 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012742 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012743 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012745 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012746 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012747 {
12748 .cmd = NL80211_CMD_GET_STATION,
12749 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012750 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012751 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012752 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12753 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012754 },
12755 {
12756 .cmd = NL80211_CMD_SET_STATION,
12757 .doit = nl80211_set_station,
12758 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012759 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012760 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012761 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012762 },
12763 {
12764 .cmd = NL80211_CMD_NEW_STATION,
12765 .doit = nl80211_new_station,
12766 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012767 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012769 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012770 },
12771 {
12772 .cmd = NL80211_CMD_DEL_STATION,
12773 .doit = nl80211_del_station,
12774 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012775 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012777 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012778 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012779 {
12780 .cmd = NL80211_CMD_GET_MPATH,
12781 .doit = nl80211_get_mpath,
12782 .dumpit = nl80211_dump_mpath,
12783 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012784 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012785 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012786 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012787 },
12788 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012789 .cmd = NL80211_CMD_GET_MPP,
12790 .doit = nl80211_get_mpp,
12791 .dumpit = nl80211_dump_mpp,
12792 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012793 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12795 NL80211_FLAG_NEED_RTNL,
12796 },
12797 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012798 .cmd = NL80211_CMD_SET_MPATH,
12799 .doit = nl80211_set_mpath,
12800 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012801 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012803 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012804 },
12805 {
12806 .cmd = NL80211_CMD_NEW_MPATH,
12807 .doit = nl80211_new_mpath,
12808 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012809 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012811 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012812 },
12813 {
12814 .cmd = NL80211_CMD_DEL_MPATH,
12815 .doit = nl80211_del_mpath,
12816 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012817 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012819 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012820 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012821 {
12822 .cmd = NL80211_CMD_SET_BSS,
12823 .doit = nl80211_set_bss,
12824 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012825 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012826 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012827 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012828 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012829 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012830 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012831 .doit = nl80211_get_reg_do,
12832 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012833 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012834 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012835 /* can be retrieved by unprivileged users */
12836 },
Johannes Bergb6863032015-10-15 09:25:18 +020012837#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012838 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012839 .cmd = NL80211_CMD_SET_REG,
12840 .doit = nl80211_set_reg,
12841 .policy = nl80211_policy,
12842 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012843 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012844 },
Johannes Bergb6863032015-10-15 09:25:18 +020012845#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012846 {
12847 .cmd = NL80211_CMD_REQ_SET_REG,
12848 .doit = nl80211_req_set_reg,
12849 .policy = nl80211_policy,
12850 .flags = GENL_ADMIN_PERM,
12851 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012852 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020012853 .cmd = NL80211_CMD_RELOAD_REGDB,
12854 .doit = nl80211_reload_regdb,
12855 .policy = nl80211_policy,
12856 .flags = GENL_ADMIN_PERM,
12857 },
12858 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012859 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12860 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012861 .policy = nl80211_policy,
12862 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012863 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012864 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012865 },
12866 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012867 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12868 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012869 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012870 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012872 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012873 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012874 {
Johannes Berg2a519312009-02-10 21:25:55 +010012875 .cmd = NL80211_CMD_TRIGGER_SCAN,
12876 .doit = nl80211_trigger_scan,
12877 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012878 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012879 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012880 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012881 },
12882 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012883 .cmd = NL80211_CMD_ABORT_SCAN,
12884 .doit = nl80211_abort_scan,
12885 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012886 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012887 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12888 NL80211_FLAG_NEED_RTNL,
12889 },
12890 {
Johannes Berg2a519312009-02-10 21:25:55 +010012891 .cmd = NL80211_CMD_GET_SCAN,
12892 .policy = nl80211_policy,
12893 .dumpit = nl80211_dump_scan,
12894 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012895 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012896 .cmd = NL80211_CMD_START_SCHED_SCAN,
12897 .doit = nl80211_start_sched_scan,
12898 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012899 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012900 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12901 NL80211_FLAG_NEED_RTNL,
12902 },
12903 {
12904 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12905 .doit = nl80211_stop_sched_scan,
12906 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012907 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012908 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12909 NL80211_FLAG_NEED_RTNL,
12910 },
12911 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012912 .cmd = NL80211_CMD_AUTHENTICATE,
12913 .doit = nl80211_authenticate,
12914 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012915 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012917 NL80211_FLAG_NEED_RTNL |
12918 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012919 },
12920 {
12921 .cmd = NL80211_CMD_ASSOCIATE,
12922 .doit = nl80211_associate,
12923 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012924 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012926 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012927 },
12928 {
12929 .cmd = NL80211_CMD_DEAUTHENTICATE,
12930 .doit = nl80211_deauthenticate,
12931 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012932 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012934 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012935 },
12936 {
12937 .cmd = NL80211_CMD_DISASSOCIATE,
12938 .doit = nl80211_disassociate,
12939 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012940 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012942 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012943 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012944 {
12945 .cmd = NL80211_CMD_JOIN_IBSS,
12946 .doit = nl80211_join_ibss,
12947 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012948 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012950 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012951 },
12952 {
12953 .cmd = NL80211_CMD_LEAVE_IBSS,
12954 .doit = nl80211_leave_ibss,
12955 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012956 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012958 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012959 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012960#ifdef CONFIG_NL80211_TESTMODE
12961 {
12962 .cmd = NL80211_CMD_TESTMODE,
12963 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012964 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012965 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012966 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012967 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12968 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012969 },
12970#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012971 {
12972 .cmd = NL80211_CMD_CONNECT,
12973 .doit = nl80211_connect,
12974 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012975 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012977 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012978 },
12979 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012980 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12981 .doit = nl80211_update_connect_params,
12982 .policy = nl80211_policy,
12983 .flags = GENL_ADMIN_PERM,
12984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12985 NL80211_FLAG_NEED_RTNL,
12986 },
12987 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012988 .cmd = NL80211_CMD_DISCONNECT,
12989 .doit = nl80211_disconnect,
12990 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012991 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012993 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012994 },
Johannes Berg463d0182009-07-14 00:33:35 +020012995 {
12996 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12997 .doit = nl80211_wiphy_netns,
12998 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012999 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013000 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13001 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020013002 },
Holger Schurig61fa7132009-11-11 12:25:40 +010013003 {
13004 .cmd = NL80211_CMD_GET_SURVEY,
13005 .policy = nl80211_policy,
13006 .dumpit = nl80211_dump_survey,
13007 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013008 {
13009 .cmd = NL80211_CMD_SET_PMKSA,
13010 .doit = nl80211_setdel_pmksa,
13011 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013012 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013014 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013015 },
13016 {
13017 .cmd = NL80211_CMD_DEL_PMKSA,
13018 .doit = nl80211_setdel_pmksa,
13019 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013020 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013022 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013023 },
13024 {
13025 .cmd = NL80211_CMD_FLUSH_PMKSA,
13026 .doit = nl80211_flush_pmksa,
13027 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013028 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013030 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010013031 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013032 {
13033 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13034 .doit = nl80211_remain_on_channel,
13035 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013036 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013037 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013038 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013039 },
13040 {
13041 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13042 .doit = nl80211_cancel_remain_on_channel,
13043 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013044 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013045 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013046 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013047 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013048 {
13049 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
13050 .doit = nl80211_set_tx_bitrate_mask,
13051 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013052 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013053 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13054 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020013055 },
Jouni Malinen026331c2010-02-15 12:53:10 +020013056 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013057 .cmd = NL80211_CMD_REGISTER_FRAME,
13058 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013059 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013060 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013061 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020013062 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013063 },
13064 {
Johannes Berg2e161f782010-08-12 15:38:38 +020013065 .cmd = NL80211_CMD_FRAME,
13066 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020013067 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013068 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013069 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020013070 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020013071 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020013072 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013073 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
13074 .doit = nl80211_tx_mgmt_cancel_wait,
13075 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013076 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020013077 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010013078 NL80211_FLAG_NEED_RTNL,
13079 },
13080 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020013081 .cmd = NL80211_CMD_SET_POWER_SAVE,
13082 .doit = nl80211_set_power_save,
13083 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013084 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013085 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13086 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013087 },
13088 {
13089 .cmd = NL80211_CMD_GET_POWER_SAVE,
13090 .doit = nl80211_get_power_save,
13091 .policy = nl80211_policy,
13092 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020013093 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13094 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020013095 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013096 {
13097 .cmd = NL80211_CMD_SET_CQM,
13098 .doit = nl80211_set_cqm,
13099 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013100 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013101 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13102 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013103 },
Johannes Bergf444de02010-05-05 15:25:02 +020013104 {
13105 .cmd = NL80211_CMD_SET_CHANNEL,
13106 .doit = nl80211_set_channel,
13107 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013108 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013109 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13110 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013111 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013112 {
13113 .cmd = NL80211_CMD_SET_WDS_PEER,
13114 .doit = nl80211_set_wds_peer,
13115 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013116 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013117 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13118 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013119 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013120 {
13121 .cmd = NL80211_CMD_JOIN_MESH,
13122 .doit = nl80211_join_mesh,
13123 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013124 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013125 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13126 NL80211_FLAG_NEED_RTNL,
13127 },
13128 {
13129 .cmd = NL80211_CMD_LEAVE_MESH,
13130 .doit = nl80211_leave_mesh,
13131 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013132 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013133 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13134 NL80211_FLAG_NEED_RTNL,
13135 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013136 {
13137 .cmd = NL80211_CMD_JOIN_OCB,
13138 .doit = nl80211_join_ocb,
13139 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013140 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013141 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13142 NL80211_FLAG_NEED_RTNL,
13143 },
13144 {
13145 .cmd = NL80211_CMD_LEAVE_OCB,
13146 .doit = nl80211_leave_ocb,
13147 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013148 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13150 NL80211_FLAG_NEED_RTNL,
13151 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013152#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013153 {
13154 .cmd = NL80211_CMD_GET_WOWLAN,
13155 .doit = nl80211_get_wowlan,
13156 .policy = nl80211_policy,
13157 /* can be retrieved by unprivileged users */
13158 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13159 NL80211_FLAG_NEED_RTNL,
13160 },
13161 {
13162 .cmd = NL80211_CMD_SET_WOWLAN,
13163 .doit = nl80211_set_wowlan,
13164 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013165 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013166 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13167 NL80211_FLAG_NEED_RTNL,
13168 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013169#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013170 {
13171 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13172 .doit = nl80211_set_rekey_data,
13173 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013174 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013176 NL80211_FLAG_NEED_RTNL |
13177 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013178 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013179 {
13180 .cmd = NL80211_CMD_TDLS_MGMT,
13181 .doit = nl80211_tdls_mgmt,
13182 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013183 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13185 NL80211_FLAG_NEED_RTNL,
13186 },
13187 {
13188 .cmd = NL80211_CMD_TDLS_OPER,
13189 .doit = nl80211_tdls_oper,
13190 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013191 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13193 NL80211_FLAG_NEED_RTNL,
13194 },
Johannes Berg28946da2011-11-04 11:18:12 +010013195 {
13196 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13197 .doit = nl80211_register_unexpected_frame,
13198 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013199 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013200 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13201 NL80211_FLAG_NEED_RTNL,
13202 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013203 {
13204 .cmd = NL80211_CMD_PROBE_CLIENT,
13205 .doit = nl80211_probe_client,
13206 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013207 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013208 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013209 NL80211_FLAG_NEED_RTNL,
13210 },
Johannes Berg5e760232011-11-04 11:18:17 +010013211 {
13212 .cmd = NL80211_CMD_REGISTER_BEACONS,
13213 .doit = nl80211_register_beacons,
13214 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013215 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013216 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13217 NL80211_FLAG_NEED_RTNL,
13218 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013219 {
13220 .cmd = NL80211_CMD_SET_NOACK_MAP,
13221 .doit = nl80211_set_noack_map,
13222 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013223 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013224 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13225 NL80211_FLAG_NEED_RTNL,
13226 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013227 {
13228 .cmd = NL80211_CMD_START_P2P_DEVICE,
13229 .doit = nl80211_start_p2p_device,
13230 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013231 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013232 .internal_flags = NL80211_FLAG_NEED_WDEV |
13233 NL80211_FLAG_NEED_RTNL,
13234 },
13235 {
13236 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13237 .doit = nl80211_stop_p2p_device,
13238 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013239 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013240 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13241 NL80211_FLAG_NEED_RTNL,
13242 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013243 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013244 .cmd = NL80211_CMD_START_NAN,
13245 .doit = nl80211_start_nan,
13246 .policy = nl80211_policy,
13247 .flags = GENL_ADMIN_PERM,
13248 .internal_flags = NL80211_FLAG_NEED_WDEV |
13249 NL80211_FLAG_NEED_RTNL,
13250 },
13251 {
13252 .cmd = NL80211_CMD_STOP_NAN,
13253 .doit = nl80211_stop_nan,
13254 .policy = nl80211_policy,
13255 .flags = GENL_ADMIN_PERM,
13256 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13257 NL80211_FLAG_NEED_RTNL,
13258 },
13259 {
Ayala Bekera442b762016-09-20 17:31:15 +030013260 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13261 .doit = nl80211_nan_add_func,
13262 .policy = nl80211_policy,
13263 .flags = GENL_ADMIN_PERM,
13264 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13265 NL80211_FLAG_NEED_RTNL,
13266 },
13267 {
13268 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13269 .doit = nl80211_nan_del_func,
13270 .policy = nl80211_policy,
13271 .flags = GENL_ADMIN_PERM,
13272 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13273 NL80211_FLAG_NEED_RTNL,
13274 },
13275 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013276 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13277 .doit = nl80211_nan_change_config,
13278 .policy = nl80211_policy,
13279 .flags = GENL_ADMIN_PERM,
13280 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13281 NL80211_FLAG_NEED_RTNL,
13282 },
13283 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013284 .cmd = NL80211_CMD_SET_MCAST_RATE,
13285 .doit = nl80211_set_mcast_rate,
13286 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013287 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013288 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13289 NL80211_FLAG_NEED_RTNL,
13290 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013291 {
13292 .cmd = NL80211_CMD_SET_MAC_ACL,
13293 .doit = nl80211_set_mac_acl,
13294 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013295 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013296 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13297 NL80211_FLAG_NEED_RTNL,
13298 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013299 {
13300 .cmd = NL80211_CMD_RADAR_DETECT,
13301 .doit = nl80211_start_radar_detection,
13302 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013303 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13305 NL80211_FLAG_NEED_RTNL,
13306 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013307 {
13308 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13309 .doit = nl80211_get_protocol_features,
13310 .policy = nl80211_policy,
13311 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013312 {
13313 .cmd = NL80211_CMD_UPDATE_FT_IES,
13314 .doit = nl80211_update_ft_ies,
13315 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013316 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013317 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13318 NL80211_FLAG_NEED_RTNL,
13319 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013320 {
13321 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13322 .doit = nl80211_crit_protocol_start,
13323 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013324 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013325 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13326 NL80211_FLAG_NEED_RTNL,
13327 },
13328 {
13329 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13330 .doit = nl80211_crit_protocol_stop,
13331 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013332 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013333 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13334 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013335 },
13336 {
13337 .cmd = NL80211_CMD_GET_COALESCE,
13338 .doit = nl80211_get_coalesce,
13339 .policy = nl80211_policy,
13340 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13341 NL80211_FLAG_NEED_RTNL,
13342 },
13343 {
13344 .cmd = NL80211_CMD_SET_COALESCE,
13345 .doit = nl80211_set_coalesce,
13346 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013347 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013348 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13349 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013350 },
13351 {
13352 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13353 .doit = nl80211_channel_switch,
13354 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013355 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13357 NL80211_FLAG_NEED_RTNL,
13358 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013359 {
13360 .cmd = NL80211_CMD_VENDOR,
13361 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013362 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013363 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013364 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013365 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13366 NL80211_FLAG_NEED_RTNL,
13367 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013368 {
13369 .cmd = NL80211_CMD_SET_QOS_MAP,
13370 .doit = nl80211_set_qos_map,
13371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013372 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13374 NL80211_FLAG_NEED_RTNL,
13375 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013376 {
13377 .cmd = NL80211_CMD_ADD_TX_TS,
13378 .doit = nl80211_add_tx_ts,
13379 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013380 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13382 NL80211_FLAG_NEED_RTNL,
13383 },
13384 {
13385 .cmd = NL80211_CMD_DEL_TX_TS,
13386 .doit = nl80211_del_tx_ts,
13387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013388 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13390 NL80211_FLAG_NEED_RTNL,
13391 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013392 {
13393 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13394 .doit = nl80211_tdls_channel_switch,
13395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013396 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13398 NL80211_FLAG_NEED_RTNL,
13399 },
13400 {
13401 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13402 .doit = nl80211_tdls_cancel_channel_switch,
13403 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013404 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13406 NL80211_FLAG_NEED_RTNL,
13407 },
Michael Braunce0ce132016-10-10 19:12:22 +020013408 {
13409 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13410 .doit = nl80211_set_multicast_to_unicast,
13411 .policy = nl80211_policy,
13412 .flags = GENL_UNS_ADMIN_PERM,
13413 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13414 NL80211_FLAG_NEED_RTNL,
13415 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013416 {
13417 .cmd = NL80211_CMD_SET_PMK,
13418 .doit = nl80211_set_pmk,
13419 .policy = nl80211_policy,
13420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13421 NL80211_FLAG_NEED_RTNL,
13422 },
13423 {
13424 .cmd = NL80211_CMD_DEL_PMK,
13425 .doit = nl80211_del_pmk,
13426 .policy = nl80211_policy,
13427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13428 NL80211_FLAG_NEED_RTNL,
13429 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013430 {
13431 .cmd = NL80211_CMD_EXTERNAL_AUTH,
13432 .doit = nl80211_external_auth,
13433 .policy = nl80211_policy,
13434 .flags = GENL_ADMIN_PERM,
13435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13436 NL80211_FLAG_NEED_RTNL,
13437 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013438
Johannes Berg55682962007-09-20 13:09:35 -040013439};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013440
Johannes Berg56989f62016-10-24 14:40:05 +020013441static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013442 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13443 .hdrsize = 0, /* no private header */
13444 .version = 1, /* no particular meaning now */
13445 .maxattr = NL80211_ATTR_MAX,
13446 .netnsok = true,
13447 .pre_doit = nl80211_pre_doit,
13448 .post_doit = nl80211_post_doit,
13449 .module = THIS_MODULE,
13450 .ops = nl80211_ops,
13451 .n_ops = ARRAY_SIZE(nl80211_ops),
13452 .mcgrps = nl80211_mcgrps,
13453 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13454};
13455
Johannes Berg55682962007-09-20 13:09:35 -040013456/* notification functions */
13457
Johannes Berg3bb20552014-05-26 13:52:25 +020013458void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13459 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013460{
13461 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013462 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013463
Johannes Berg3bb20552014-05-26 13:52:25 +020013464 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13465 cmd != NL80211_CMD_DEL_WIPHY);
13466
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013468 if (!msg)
13469 return;
13470
Johannes Berg3bb20552014-05-26 13:52:25 +020013471 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013472 nlmsg_free(msg);
13473 return;
13474 }
13475
Johannes Berg68eb5502013-11-19 15:19:38 +010013476 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013477 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013478}
13479
Denis Kenzior896ff062016-08-03 16:58:33 -050013480void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13481 struct wireless_dev *wdev,
13482 enum nl80211_commands cmd)
13483{
13484 struct sk_buff *msg;
13485
13486 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13487 cmd != NL80211_CMD_DEL_INTERFACE);
13488
13489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13490 if (!msg)
13491 return;
13492
13493 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13494 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13495 nlmsg_free(msg);
13496 return;
13497 }
13498
13499 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13500 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13501}
13502
Johannes Berg362a4152009-05-24 16:43:15 +020013503static int nl80211_add_scan_req(struct sk_buff *msg,
13504 struct cfg80211_registered_device *rdev)
13505{
13506 struct cfg80211_scan_request *req = rdev->scan_req;
13507 struct nlattr *nest;
13508 int i;
13509
13510 if (WARN_ON(!req))
13511 return 0;
13512
13513 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13514 if (!nest)
13515 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013516 for (i = 0; i < req->n_ssids; i++) {
13517 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13518 goto nla_put_failure;
13519 }
Johannes Berg362a4152009-05-24 16:43:15 +020013520 nla_nest_end(msg, nest);
13521
13522 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13523 if (!nest)
13524 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013525 for (i = 0; i < req->n_channels; i++) {
13526 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13527 goto nla_put_failure;
13528 }
Johannes Berg362a4152009-05-24 16:43:15 +020013529 nla_nest_end(msg, nest);
13530
David S. Miller9360ffd2012-03-29 04:41:26 -040013531 if (req->ie &&
13532 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13533 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013534
Johannes Bergae917c92013-10-25 11:05:22 +020013535 if (req->flags &&
13536 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13537 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013538
Avraham Stern1d762502016-07-05 17:10:13 +030013539 if (req->info.scan_start_tsf &&
13540 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13541 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13542 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13543 req->info.tsf_bssid)))
13544 goto nla_put_failure;
13545
Johannes Berg362a4152009-05-24 16:43:15 +020013546 return 0;
13547 nla_put_failure:
13548 return -ENOBUFS;
13549}
13550
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013551static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013552 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013553 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013554 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013555 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013556{
13557 void *hdr;
13558
Eric W. Biederman15e47302012-09-07 20:12:54 +000013559 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013560 if (!hdr)
13561 return -1;
13562
David S. Miller9360ffd2012-03-29 04:41:26 -040013563 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013564 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13565 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013566 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13567 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013568 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013569
Johannes Berg362a4152009-05-24 16:43:15 +020013570 /* ignore errors and send incomplete event anyway */
13571 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013572
Johannes Berg053c0952015-01-16 22:09:00 +010013573 genlmsg_end(msg, hdr);
13574 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013575
13576 nla_put_failure:
13577 genlmsg_cancel(msg, hdr);
13578 return -EMSGSIZE;
13579}
13580
Luciano Coelho807f8a82011-05-11 17:09:35 +030013581static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013582nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013583 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013584{
13585 void *hdr;
13586
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013587 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013588 if (!hdr)
13589 return -1;
13590
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013591 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13592 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13593 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13594 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13595 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013596 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013597
Johannes Berg053c0952015-01-16 22:09:00 +010013598 genlmsg_end(msg, hdr);
13599 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013600
13601 nla_put_failure:
13602 genlmsg_cancel(msg, hdr);
13603 return -EMSGSIZE;
13604}
13605
Johannes Berga538e2d2009-06-16 19:56:42 +020013606void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013607 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013608{
13609 struct sk_buff *msg;
13610
Thomas Graf58050fc2012-06-28 03:57:45 +000013611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013612 if (!msg)
13613 return;
13614
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013615 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013616 NL80211_CMD_TRIGGER_SCAN) < 0) {
13617 nlmsg_free(msg);
13618 return;
13619 }
13620
Johannes Berg68eb5502013-11-19 15:19:38 +010013621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013622 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013623}
13624
Johannes Bergf9d15d12014-01-22 11:14:19 +020013625struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13626 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013627{
13628 struct sk_buff *msg;
13629
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013631 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013632 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013633
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013634 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013635 aborted ? NL80211_CMD_SCAN_ABORTED :
13636 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013637 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013638 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013639 }
13640
Johannes Bergf9d15d12014-01-22 11:14:19 +020013641 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013642}
13643
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013644/* send message created by nl80211_build_scan_msg() */
13645void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13646 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013647{
Johannes Berg2a519312009-02-10 21:25:55 +010013648 if (!msg)
13649 return;
13650
Johannes Berg68eb5502013-11-19 15:19:38 +010013651 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013652 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013653}
13654
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013655void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013656{
13657 struct sk_buff *msg;
13658
Thomas Graf58050fc2012-06-28 03:57:45 +000013659 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013660 if (!msg)
13661 return;
13662
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013663 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013664 nlmsg_free(msg);
13665 return;
13666 }
13667
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013668 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013669 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013670}
13671
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013672static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13673 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013674{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013675 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013676 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13677 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013678
David S. Miller9360ffd2012-03-29 04:41:26 -040013679 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13680 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13681 NL80211_REGDOM_TYPE_WORLD))
13682 goto nla_put_failure;
13683 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13684 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13685 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13686 goto nla_put_failure;
13687 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13688 request->intersect) {
13689 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13690 NL80211_REGDOM_TYPE_INTERSECTION))
13691 goto nla_put_failure;
13692 } else {
13693 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13694 NL80211_REGDOM_TYPE_COUNTRY) ||
13695 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13696 request->alpha2))
13697 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013698 }
13699
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013700 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13701 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13702
13703 if (wiphy &&
13704 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13705 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013706
13707 if (wiphy &&
13708 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13709 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13710 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013711 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013712
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013713 return true;
13714
13715nla_put_failure:
13716 return false;
13717}
13718
13719/*
13720 * This can happen on global regulatory changes or device specific settings
13721 * based on custom regulatory domains.
13722 */
13723void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13724 struct regulatory_request *request)
13725{
13726 struct sk_buff *msg;
13727 void *hdr;
13728
13729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13730 if (!msg)
13731 return;
13732
13733 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13734 if (!hdr) {
13735 nlmsg_free(msg);
13736 return;
13737 }
13738
13739 if (nl80211_reg_change_event_fill(msg, request) == false)
13740 goto nla_put_failure;
13741
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013742 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013743
Johannes Bergbc43b282009-07-25 10:54:13 +020013744 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013745 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013746 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013747 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013748
13749 return;
13750
13751nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013752 nlmsg_free(msg);
13753}
13754
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013755static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13756 struct net_device *netdev,
13757 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013758 enum nl80211_commands cmd, gfp_t gfp,
13759 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013760{
13761 struct sk_buff *msg;
13762 void *hdr;
13763
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013764 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013765 if (!msg)
13766 return;
13767
13768 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13769 if (!hdr) {
13770 nlmsg_free(msg);
13771 return;
13772 }
13773
David S. Miller9360ffd2012-03-29 04:41:26 -040013774 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13775 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13776 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13777 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013778
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013779 if (uapsd_queues >= 0) {
13780 struct nlattr *nla_wmm =
13781 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13782 if (!nla_wmm)
13783 goto nla_put_failure;
13784
13785 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13786 uapsd_queues))
13787 goto nla_put_failure;
13788
13789 nla_nest_end(msg, nla_wmm);
13790 }
13791
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013792 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013793
Johannes Berg68eb5502013-11-19 15:19:38 +010013794 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013795 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013796 return;
13797
13798 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013799 nlmsg_free(msg);
13800}
13801
13802void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013803 struct net_device *netdev, const u8 *buf,
13804 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013805{
13806 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013807 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013808}
13809
13810void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13811 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013812 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013813{
Johannes Berge6d6e342009-07-01 21:26:47 +020013814 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013815 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013816}
13817
Jouni Malinen53b46b82009-03-27 20:53:56 +020013818void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013819 struct net_device *netdev, const u8 *buf,
13820 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013821{
13822 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013823 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013824}
13825
Jouni Malinen53b46b82009-03-27 20:53:56 +020013826void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13827 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013828 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013829{
13830 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013831 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013832}
13833
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013834void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13835 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013836{
Johannes Berg947add32013-02-22 22:05:20 +010013837 struct wireless_dev *wdev = dev->ieee80211_ptr;
13838 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013839 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013840 const struct ieee80211_mgmt *mgmt = (void *)buf;
13841 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013842
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013843 if (WARN_ON(len < 2))
13844 return;
13845
13846 if (ieee80211_is_deauth(mgmt->frame_control))
13847 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13848 else
13849 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13850
13851 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013852 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013853}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013854EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013855
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013856static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13857 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013858 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013859{
13860 struct sk_buff *msg;
13861 void *hdr;
13862
Johannes Berge6d6e342009-07-01 21:26:47 +020013863 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013864 if (!msg)
13865 return;
13866
13867 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13868 if (!hdr) {
13869 nlmsg_free(msg);
13870 return;
13871 }
13872
David S. Miller9360ffd2012-03-29 04:41:26 -040013873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13875 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13876 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13877 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013878
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013879 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013880
Johannes Berg68eb5502013-11-19 15:19:38 +010013881 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013882 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013883 return;
13884
13885 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030013886 nlmsg_free(msg);
13887}
13888
13889void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013890 struct net_device *netdev, const u8 *addr,
13891 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013892{
13893 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013894 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013895}
13896
13897void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013898 struct net_device *netdev, const u8 *addr,
13899 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013900{
Johannes Berge6d6e342009-07-01 21:26:47 +020013901 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13902 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013903}
13904
Samuel Ortizb23aa672009-07-01 21:26:54 +020013905void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013906 struct net_device *netdev,
13907 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013908 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013909{
13910 struct sk_buff *msg;
13911 void *hdr;
13912
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013913 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13914 cr->fils_kek_len + cr->pmk_len +
13915 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013916 if (!msg)
13917 return;
13918
13919 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13920 if (!hdr) {
13921 nlmsg_free(msg);
13922 return;
13923 }
13924
David S. Miller9360ffd2012-03-29 04:41:26 -040013925 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13926 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013927 (cr->bssid &&
13928 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013929 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013930 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13931 cr->status) ||
13932 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013933 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013934 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13935 cr->timeout_reason))) ||
13936 (cr->req_ie &&
13937 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13938 (cr->resp_ie &&
13939 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013940 cr->resp_ie)) ||
13941 (cr->update_erp_next_seq_num &&
13942 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13943 cr->fils_erp_next_seq_num)) ||
13944 (cr->status == WLAN_STATUS_SUCCESS &&
13945 ((cr->fils_kek &&
13946 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13947 cr->fils_kek)) ||
13948 (cr->pmk &&
13949 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13950 (cr->pmkid &&
13951 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013952 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013953
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013954 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013955
Johannes Berg68eb5502013-11-19 15:19:38 +010013956 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013957 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013958 return;
13959
13960 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020013961 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013962}
13963
13964void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013965 struct net_device *netdev,
13966 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013967{
13968 struct sk_buff *msg;
13969 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013970 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013971
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013972 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013973 if (!msg)
13974 return;
13975
13976 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13977 if (!hdr) {
13978 nlmsg_free(msg);
13979 return;
13980 }
13981
David S. Miller9360ffd2012-03-29 04:41:26 -040013982 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13983 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13984 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013985 (info->req_ie &&
13986 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13987 info->req_ie)) ||
13988 (info->resp_ie &&
13989 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern503c1fb2017-09-29 14:21:49 +020013990 info->resp_ie)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013991 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013992
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013993 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013994
Johannes Berg68eb5502013-11-19 15:19:38 +010013995 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013996 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013997 return;
13998
13999 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014000 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014001}
14002
Avraham Stern503c1fb2017-09-29 14:21:49 +020014003void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
14004 struct net_device *netdev, const u8 *bssid)
14005{
14006 struct sk_buff *msg;
14007 void *hdr;
14008
14009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14010 if (!msg)
14011 return;
14012
14013 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
14014 if (!hdr) {
14015 nlmsg_free(msg);
14016 return;
14017 }
14018
14019 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14020 goto nla_put_failure;
14021
14022 genlmsg_end(msg, hdr);
14023
14024 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14025 NL80211_MCGRP_MLME, GFP_KERNEL);
14026 return;
14027
14028 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020014029 nlmsg_free(msg);
14030}
14031
Samuel Ortizb23aa672009-07-01 21:26:54 +020014032void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
14033 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020014034 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020014035{
14036 struct sk_buff *msg;
14037 void *hdr;
14038
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014039 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014040 if (!msg)
14041 return;
14042
14043 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
14044 if (!hdr) {
14045 nlmsg_free(msg);
14046 return;
14047 }
14048
David S. Miller9360ffd2012-03-29 04:41:26 -040014049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14050 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020014051 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040014052 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
14053 (from_ap &&
14054 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
14055 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
14056 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020014057
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014058 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014059
Johannes Berg68eb5502013-11-19 15:19:38 +010014060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014061 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014062 return;
14063
14064 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020014065 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020014066}
14067
Johannes Berg04a773a2009-04-19 21:24:32 +020014068void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
14069 struct net_device *netdev, const u8 *bssid,
14070 gfp_t gfp)
14071{
14072 struct sk_buff *msg;
14073 void *hdr;
14074
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014076 if (!msg)
14077 return;
14078
14079 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
14080 if (!hdr) {
14081 nlmsg_free(msg);
14082 return;
14083 }
14084
David S. Miller9360ffd2012-03-29 04:41:26 -040014085 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14086 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14087 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14088 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020014089
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014090 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020014091
Johannes Berg68eb5502013-11-19 15:19:38 +010014092 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014093 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020014094 return;
14095
14096 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020014097 nlmsg_free(msg);
14098}
14099
Johannes Berg947add32013-02-22 22:05:20 +010014100void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
14101 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070014102{
Johannes Berg947add32013-02-22 22:05:20 +010014103 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014104 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014105 struct sk_buff *msg;
14106 void *hdr;
14107
Johannes Berg947add32013-02-22 22:05:20 +010014108 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14109 return;
14110
14111 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14112
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014113 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014114 if (!msg)
14115 return;
14116
14117 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14118 if (!hdr) {
14119 nlmsg_free(msg);
14120 return;
14121 }
14122
David S. Miller9360ffd2012-03-29 04:41:26 -040014123 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014124 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14125 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014126 (ie_len && ie &&
14127 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14128 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014129
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014130 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014131
Johannes Berg68eb5502013-11-19 15:19:38 +010014132 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014133 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014134 return;
14135
14136 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070014137 nlmsg_free(msg);
14138}
Johannes Berg947add32013-02-22 22:05:20 +010014139EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014140
Jouni Malinena3b8b052009-03-27 21:59:49 +020014141void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14142 struct net_device *netdev, const u8 *addr,
14143 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014144 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014145{
14146 struct sk_buff *msg;
14147 void *hdr;
14148
Johannes Berge6d6e342009-07-01 21:26:47 +020014149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014150 if (!msg)
14151 return;
14152
14153 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14154 if (!hdr) {
14155 nlmsg_free(msg);
14156 return;
14157 }
14158
David S. Miller9360ffd2012-03-29 04:41:26 -040014159 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14160 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14161 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14162 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14163 (key_id != -1 &&
14164 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14165 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14166 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014167
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014168 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014169
Johannes Berg68eb5502013-11-19 15:19:38 +010014170 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014171 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014172 return;
14173
14174 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020014175 nlmsg_free(msg);
14176}
14177
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014178void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14179 struct ieee80211_channel *channel_before,
14180 struct ieee80211_channel *channel_after)
14181{
14182 struct sk_buff *msg;
14183 void *hdr;
14184 struct nlattr *nl_freq;
14185
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014187 if (!msg)
14188 return;
14189
14190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14191 if (!hdr) {
14192 nlmsg_free(msg);
14193 return;
14194 }
14195
14196 /*
14197 * Since we are applying the beacon hint to a wiphy we know its
14198 * wiphy_idx is valid
14199 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014200 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14201 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014202
14203 /* Before */
14204 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14205 if (!nl_freq)
14206 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014207 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014208 goto nla_put_failure;
14209 nla_nest_end(msg, nl_freq);
14210
14211 /* After */
14212 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14213 if (!nl_freq)
14214 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014215 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014216 goto nla_put_failure;
14217 nla_nest_end(msg, nl_freq);
14218
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014219 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014220
Johannes Berg463d0182009-07-14 00:33:35 +020014221 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014222 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014223 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014224 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014225
14226 return;
14227
14228nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014229 nlmsg_free(msg);
14230}
14231
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014232static void nl80211_send_remain_on_chan_event(
14233 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014234 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014235 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014236 unsigned int duration, gfp_t gfp)
14237{
14238 struct sk_buff *msg;
14239 void *hdr;
14240
14241 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14242 if (!msg)
14243 return;
14244
14245 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14246 if (!hdr) {
14247 nlmsg_free(msg);
14248 return;
14249 }
14250
David S. Miller9360ffd2012-03-29 04:41:26 -040014251 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014252 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14253 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014254 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14255 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014256 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014257 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14258 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014259 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14260 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014261 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014262
David S. Miller9360ffd2012-03-29 04:41:26 -040014263 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14264 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14265 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014266
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014267 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014268
Johannes Berg68eb5502013-11-19 15:19:38 +010014269 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014270 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014271 return;
14272
14273 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014274 nlmsg_free(msg);
14275}
14276
Johannes Berg947add32013-02-22 22:05:20 +010014277void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14278 struct ieee80211_channel *chan,
14279 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014280{
Johannes Berg947add32013-02-22 22:05:20 +010014281 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014283
14284 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014285 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014286 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014287 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014288}
Johannes Berg947add32013-02-22 22:05:20 +010014289EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014290
Johannes Berg947add32013-02-22 22:05:20 +010014291void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14292 struct ieee80211_channel *chan,
14293 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014294{
Johannes Berg947add32013-02-22 22:05:20 +010014295 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014296 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014297
14298 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014299 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014300 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014301}
Johannes Berg947add32013-02-22 22:05:20 +010014302EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014303
Johannes Berg947add32013-02-22 22:05:20 +010014304void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14305 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014306{
Johannes Berg947add32013-02-22 22:05:20 +010014307 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014309 struct sk_buff *msg;
14310
Johannes Berg947add32013-02-22 22:05:20 +010014311 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14312
Thomas Graf58050fc2012-06-28 03:57:45 +000014313 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014314 if (!msg)
14315 return;
14316
Johannes Bergcf5ead82014-11-14 17:14:00 +010014317 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014318 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014319 nlmsg_free(msg);
14320 return;
14321 }
14322
Johannes Berg68eb5502013-11-19 15:19:38 +010014323 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014324 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014325}
Johannes Berg947add32013-02-22 22:05:20 +010014326EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014327
Johannes Bergcf5ead82014-11-14 17:14:00 +010014328void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14329 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014330{
Johannes Berg947add32013-02-22 22:05:20 +010014331 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014333 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014334 struct station_info empty_sinfo = {};
14335
14336 if (!sinfo)
14337 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014338
Johannes Berg947add32013-02-22 22:05:20 +010014339 trace_cfg80211_del_sta(dev, mac_addr);
14340
Thomas Graf58050fc2012-06-28 03:57:45 +000014341 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014342 if (!msg)
14343 return;
14344
Johannes Bergcf5ead82014-11-14 17:14:00 +010014345 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014346 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014347 nlmsg_free(msg);
14348 return;
14349 }
14350
Johannes Berg68eb5502013-11-19 15:19:38 +010014351 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014352 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014353}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014354EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014355
Johannes Berg947add32013-02-22 22:05:20 +010014356void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14357 enum nl80211_connect_failed_reason reason,
14358 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014359{
Johannes Berg947add32013-02-22 22:05:20 +010014360 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014361 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014362 struct sk_buff *msg;
14363 void *hdr;
14364
14365 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14366 if (!msg)
14367 return;
14368
14369 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14370 if (!hdr) {
14371 nlmsg_free(msg);
14372 return;
14373 }
14374
14375 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14376 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14377 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14378 goto nla_put_failure;
14379
14380 genlmsg_end(msg, hdr);
14381
Johannes Berg68eb5502013-11-19 15:19:38 +010014382 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014383 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014384 return;
14385
14386 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014387 nlmsg_free(msg);
14388}
Johannes Berg947add32013-02-22 22:05:20 +010014389EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014390
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014391static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14392 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014393{
14394 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014396 struct sk_buff *msg;
14397 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014398 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014399
Eric W. Biederman15e47302012-09-07 20:12:54 +000014400 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014401 return false;
14402
14403 msg = nlmsg_new(100, gfp);
14404 if (!msg)
14405 return true;
14406
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014407 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014408 if (!hdr) {
14409 nlmsg_free(msg);
14410 return true;
14411 }
14412
David S. Miller9360ffd2012-03-29 04:41:26 -040014413 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14414 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14415 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14416 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014417
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014418 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014419 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014420 return true;
14421
14422 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010014423 nlmsg_free(msg);
14424 return true;
14425}
14426
Johannes Berg947add32013-02-22 22:05:20 +010014427bool cfg80211_rx_spurious_frame(struct net_device *dev,
14428 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014429{
Johannes Berg947add32013-02-22 22:05:20 +010014430 struct wireless_dev *wdev = dev->ieee80211_ptr;
14431 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014432
Johannes Berg947add32013-02-22 22:05:20 +010014433 trace_cfg80211_rx_spurious_frame(dev, addr);
14434
14435 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14436 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14437 trace_cfg80211_return_bool(false);
14438 return false;
14439 }
14440 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14441 addr, gfp);
14442 trace_cfg80211_return_bool(ret);
14443 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014444}
Johannes Berg947add32013-02-22 22:05:20 +010014445EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14446
14447bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14448 const u8 *addr, gfp_t gfp)
14449{
14450 struct wireless_dev *wdev = dev->ieee80211_ptr;
14451 bool ret;
14452
14453 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14454
14455 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14456 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14457 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14458 trace_cfg80211_return_bool(false);
14459 return false;
14460 }
14461 ret = __nl80211_unexpected_frame(dev,
14462 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14463 addr, gfp);
14464 trace_cfg80211_return_bool(ret);
14465 return ret;
14466}
14467EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014468
Johannes Berg2e161f782010-08-12 15:38:38 +020014469int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014470 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014471 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014472 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014473{
Johannes Berg71bbc992012-06-15 15:30:18 +020014474 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014475 struct sk_buff *msg;
14476 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014477
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014478 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014479 if (!msg)
14480 return -ENOMEM;
14481
Johannes Berg2e161f782010-08-12 15:38:38 +020014482 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014483 if (!hdr) {
14484 nlmsg_free(msg);
14485 return -ENOMEM;
14486 }
14487
David S. Miller9360ffd2012-03-29 04:41:26 -040014488 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014489 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14490 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014491 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14492 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014493 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14494 (sig_dbm &&
14495 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014496 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14497 (flags &&
14498 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014499 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014500
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014501 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014502
Eric W. Biederman15e47302012-09-07 20:12:54 +000014503 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014504
14505 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020014506 nlmsg_free(msg);
14507 return -ENOBUFS;
14508}
14509
Johannes Berg947add32013-02-22 22:05:20 +010014510void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14511 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014512{
Johannes Berg947add32013-02-22 22:05:20 +010014513 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014514 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014515 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014516 struct sk_buff *msg;
14517 void *hdr;
14518
Johannes Berg947add32013-02-22 22:05:20 +010014519 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14520
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014521 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014522 if (!msg)
14523 return;
14524
Johannes Berg2e161f782010-08-12 15:38:38 +020014525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014526 if (!hdr) {
14527 nlmsg_free(msg);
14528 return;
14529 }
14530
David S. Miller9360ffd2012-03-29 04:41:26 -040014531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014532 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14533 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014534 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14535 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014536 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014537 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14538 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014539 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14540 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014541
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014542 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014543
Johannes Berg68eb5502013-11-19 15:19:38 +010014544 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014545 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014546 return;
14547
14548 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020014549 nlmsg_free(msg);
14550}
Johannes Berg947add32013-02-22 22:05:20 +010014551EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014552
Johannes Berg5b97f492014-11-26 12:37:43 +010014553static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14554 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014555{
Johannes Berg947add32013-02-22 22:05:20 +010014556 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014557 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14558 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14559 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014560
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014561 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014562 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014563
Johannes Berg5b97f492014-11-26 12:37:43 +010014564 cb = (void **)msg->cb;
14565
14566 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14567 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014568 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014569 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014570 }
14571
David S. Miller9360ffd2012-03-29 04:41:26 -040014572 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014573 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014574 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014575
Johannes Berg5b97f492014-11-26 12:37:43 +010014576 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014577 goto nla_put_failure;
14578
Johannes Berg5b97f492014-11-26 12:37:43 +010014579 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14580 if (!cb[1])
14581 goto nla_put_failure;
14582
14583 cb[2] = rdev;
14584
14585 return msg;
14586 nla_put_failure:
14587 nlmsg_free(msg);
14588 return NULL;
14589}
14590
14591static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14592{
14593 void **cb = (void **)msg->cb;
14594 struct cfg80211_registered_device *rdev = cb[2];
14595
14596 nla_nest_end(msg, cb[1]);
14597 genlmsg_end(msg, cb[0]);
14598
14599 memset(msg->cb, 0, sizeof(msg->cb));
14600
14601 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14602 NL80211_MCGRP_MLME, gfp);
14603}
14604
14605void cfg80211_cqm_rssi_notify(struct net_device *dev,
14606 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014607 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014608{
14609 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014610 struct wireless_dev *wdev = dev->ieee80211_ptr;
14611 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014612
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014613 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014614
Johannes Berg98f03342014-11-26 12:42:02 +010014615 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14616 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14617 return;
14618
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014619 if (wdev->cqm_config) {
14620 wdev->cqm_config->last_rssi_event_value = rssi_level;
14621
14622 cfg80211_cqm_rssi_update(rdev, dev);
14623
14624 if (rssi_level == 0)
14625 rssi_level = wdev->cqm_config->last_rssi_event_value;
14626 }
14627
Johannes Berg5b97f492014-11-26 12:37:43 +010014628 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14629 if (!msg)
14630 return;
14631
David S. Miller9360ffd2012-03-29 04:41:26 -040014632 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14633 rssi_event))
14634 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014635
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014636 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14637 rssi_level))
14638 goto nla_put_failure;
14639
Johannes Berg5b97f492014-11-26 12:37:43 +010014640 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014641
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014642 return;
14643
14644 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014645 nlmsg_free(msg);
14646}
Johannes Berg947add32013-02-22 22:05:20 +010014647EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014648
Johannes Berg5b97f492014-11-26 12:37:43 +010014649void cfg80211_cqm_txe_notify(struct net_device *dev,
14650 const u8 *peer, u32 num_packets,
14651 u32 rate, u32 intvl, gfp_t gfp)
14652{
14653 struct sk_buff *msg;
14654
14655 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14656 if (!msg)
14657 return;
14658
14659 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14660 goto nla_put_failure;
14661
14662 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14663 goto nla_put_failure;
14664
14665 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14666 goto nla_put_failure;
14667
14668 cfg80211_send_cqm(msg, gfp);
14669 return;
14670
14671 nla_put_failure:
14672 nlmsg_free(msg);
14673}
14674EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14675
14676void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14677 const u8 *peer, u32 num_packets, gfp_t gfp)
14678{
14679 struct sk_buff *msg;
14680
14681 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14682
14683 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14684 if (!msg)
14685 return;
14686
14687 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14688 goto nla_put_failure;
14689
14690 cfg80211_send_cqm(msg, gfp);
14691 return;
14692
14693 nla_put_failure:
14694 nlmsg_free(msg);
14695}
14696EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14697
Johannes Berg98f03342014-11-26 12:42:02 +010014698void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14699{
14700 struct sk_buff *msg;
14701
14702 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14703 if (!msg)
14704 return;
14705
14706 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14707 goto nla_put_failure;
14708
14709 cfg80211_send_cqm(msg, gfp);
14710 return;
14711
14712 nla_put_failure:
14713 nlmsg_free(msg);
14714}
14715EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14716
Johannes Berg947add32013-02-22 22:05:20 +010014717static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14718 struct net_device *netdev, const u8 *bssid,
14719 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014720{
14721 struct sk_buff *msg;
14722 struct nlattr *rekey_attr;
14723 void *hdr;
14724
Thomas Graf58050fc2012-06-28 03:57:45 +000014725 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014726 if (!msg)
14727 return;
14728
14729 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14730 if (!hdr) {
14731 nlmsg_free(msg);
14732 return;
14733 }
14734
David S. Miller9360ffd2012-03-29 04:41:26 -040014735 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14736 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14737 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14738 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014739
14740 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14741 if (!rekey_attr)
14742 goto nla_put_failure;
14743
David S. Miller9360ffd2012-03-29 04:41:26 -040014744 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14745 NL80211_REPLAY_CTR_LEN, replay_ctr))
14746 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014747
14748 nla_nest_end(msg, rekey_attr);
14749
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014750 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014751
Johannes Berg68eb5502013-11-19 15:19:38 +010014752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014753 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014754 return;
14755
14756 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020014757 nlmsg_free(msg);
14758}
14759
Johannes Berg947add32013-02-22 22:05:20 +010014760void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14761 const u8 *replay_ctr, gfp_t gfp)
14762{
14763 struct wireless_dev *wdev = dev->ieee80211_ptr;
14764 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014765 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014766
14767 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14768 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14769}
14770EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14771
14772static void
14773nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14774 struct net_device *netdev, int index,
14775 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014776{
14777 struct sk_buff *msg;
14778 struct nlattr *attr;
14779 void *hdr;
14780
Thomas Graf58050fc2012-06-28 03:57:45 +000014781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014782 if (!msg)
14783 return;
14784
14785 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14786 if (!hdr) {
14787 nlmsg_free(msg);
14788 return;
14789 }
14790
David S. Miller9360ffd2012-03-29 04:41:26 -040014791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14792 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14793 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014794
14795 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14796 if (!attr)
14797 goto nla_put_failure;
14798
David S. Miller9360ffd2012-03-29 04:41:26 -040014799 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14800 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14801 (preauth &&
14802 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14803 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014804
14805 nla_nest_end(msg, attr);
14806
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014807 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014808
Johannes Berg68eb5502013-11-19 15:19:38 +010014809 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014810 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014811 return;
14812
14813 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014814 nlmsg_free(msg);
14815}
14816
Johannes Berg947add32013-02-22 22:05:20 +010014817void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14818 const u8 *bssid, bool preauth, gfp_t gfp)
14819{
14820 struct wireless_dev *wdev = dev->ieee80211_ptr;
14821 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014822 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014823
14824 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14825 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14826}
14827EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14828
14829static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14830 struct net_device *netdev,
14831 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014832 gfp_t gfp,
14833 enum nl80211_commands notif,
14834 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014835{
14836 struct sk_buff *msg;
14837 void *hdr;
14838
Thomas Graf58050fc2012-06-28 03:57:45 +000014839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014840 if (!msg)
14841 return;
14842
Luciano Coelhof8d75522014-11-07 14:31:35 +020014843 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014844 if (!hdr) {
14845 nlmsg_free(msg);
14846 return;
14847 }
14848
Johannes Berg683b6d32012-11-08 21:25:48 +010014849 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14850 goto nla_put_failure;
14851
14852 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014853 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014854
Luciano Coelhof8d75522014-11-07 14:31:35 +020014855 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14856 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14857 goto nla_put_failure;
14858
Thomas Pedersen53145262012-04-06 13:35:47 -070014859 genlmsg_end(msg, hdr);
14860
Johannes Berg68eb5502013-11-19 15:19:38 +010014861 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014862 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014863 return;
14864
14865 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070014866 nlmsg_free(msg);
14867}
14868
Johannes Berg947add32013-02-22 22:05:20 +010014869void cfg80211_ch_switch_notify(struct net_device *dev,
14870 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014871{
Johannes Berg947add32013-02-22 22:05:20 +010014872 struct wireless_dev *wdev = dev->ieee80211_ptr;
14873 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014874 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014875
Simon Wunderliche487eae2013-11-21 18:19:51 +010014876 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014877
Simon Wunderliche487eae2013-11-21 18:19:51 +010014878 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014879
Michal Kazior9e0e2962014-01-29 14:22:27 +010014880 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014881 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014882 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14883 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014884}
14885EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14886
Luciano Coelhof8d75522014-11-07 14:31:35 +020014887void cfg80211_ch_switch_started_notify(struct net_device *dev,
14888 struct cfg80211_chan_def *chandef,
14889 u8 count)
14890{
14891 struct wireless_dev *wdev = dev->ieee80211_ptr;
14892 struct wiphy *wiphy = wdev->wiphy;
14893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14894
14895 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14896
14897 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14898 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14899}
14900EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14901
Thomas Pedersen84f10702012-07-12 16:17:33 -070014902void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014903nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014904 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014905 enum nl80211_radar_event event,
14906 struct net_device *netdev, gfp_t gfp)
14907{
14908 struct sk_buff *msg;
14909 void *hdr;
14910
14911 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14912 if (!msg)
14913 return;
14914
14915 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14916 if (!hdr) {
14917 nlmsg_free(msg);
14918 return;
14919 }
14920
14921 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14922 goto nla_put_failure;
14923
14924 /* NOP and radar events don't need a netdev parameter */
14925 if (netdev) {
14926 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14927
14928 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014929 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14930 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014931 goto nla_put_failure;
14932 }
14933
14934 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14935 goto nla_put_failure;
14936
14937 if (nl80211_send_chandef(msg, chandef))
14938 goto nla_put_failure;
14939
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014940 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014941
Johannes Berg68eb5502013-11-19 15:19:38 +010014942 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014943 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014944 return;
14945
14946 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010014947 nlmsg_free(msg);
14948}
14949
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053014950void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
14951 struct sta_opmode_info *sta_opmode,
14952 gfp_t gfp)
14953{
14954 struct sk_buff *msg;
14955 struct wireless_dev *wdev = dev->ieee80211_ptr;
14956 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14957 void *hdr;
14958
14959 if (WARN_ON(!mac))
14960 return;
14961
14962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14963 if (!msg)
14964 return;
14965
14966 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
14967 if (!hdr) {
14968 nlmsg_free(msg);
14969 return;
14970 }
14971
14972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14973 goto nla_put_failure;
14974
14975 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14976 goto nla_put_failure;
14977
14978 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
14979 goto nla_put_failure;
14980
14981 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
14982 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
14983 goto nla_put_failure;
14984
14985 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
14986 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
14987 goto nla_put_failure;
14988
14989 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
14990 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
14991 goto nla_put_failure;
14992
14993 genlmsg_end(msg, hdr);
14994
14995 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14996 NL80211_MCGRP_MLME, gfp);
14997
14998 return;
14999
15000nla_put_failure:
15001 nlmsg_free(msg);
15002}
15003EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
15004
Johannes Berg7f6cf312011-11-04 11:18:15 +010015005void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015006 u64 cookie, bool acked, s32 ack_signal,
15007 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010015008{
15009 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015010 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015011 struct sk_buff *msg;
15012 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015013
Beni Lev4ee3e062012-08-27 12:49:39 +030015014 trace_cfg80211_probe_status(dev, addr, cookie, acked);
15015
Thomas Graf58050fc2012-06-28 03:57:45 +000015016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030015017
Johannes Berg7f6cf312011-11-04 11:18:15 +010015018 if (!msg)
15019 return;
15020
15021 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
15022 if (!hdr) {
15023 nlmsg_free(msg);
15024 return;
15025 }
15026
David S. Miller9360ffd2012-03-29 04:41:26 -040015027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15028 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15029 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015030 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15031 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053015032 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
15033 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
15034 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015035 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010015036
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015037 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015038
Johannes Berg68eb5502013-11-19 15:19:38 +010015039 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015040 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010015041 return;
15042
15043 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010015044 nlmsg_free(msg);
15045}
15046EXPORT_SYMBOL(cfg80211_probe_status);
15047
Johannes Berg5e760232011-11-04 11:18:17 +010015048void cfg80211_report_obss_beacon(struct wiphy *wiphy,
15049 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070015050 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010015051{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015052 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010015053 struct sk_buff *msg;
15054 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070015055 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010015056
Beni Lev4ee3e062012-08-27 12:49:39 +030015057 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
15058
Ben Greear37c73b52012-10-26 14:49:25 -070015059 spin_lock_bh(&rdev->beacon_registrations_lock);
15060 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
15061 msg = nlmsg_new(len + 100, GFP_ATOMIC);
15062 if (!msg) {
15063 spin_unlock_bh(&rdev->beacon_registrations_lock);
15064 return;
15065 }
Johannes Berg5e760232011-11-04 11:18:17 +010015066
Ben Greear37c73b52012-10-26 14:49:25 -070015067 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15068 if (!hdr)
15069 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010015070
Ben Greear37c73b52012-10-26 14:49:25 -070015071 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15072 (freq &&
15073 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
15074 (sig_dbm &&
15075 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15076 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
15077 goto nla_put_failure;
15078
15079 genlmsg_end(msg, hdr);
15080
15081 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010015082 }
Ben Greear37c73b52012-10-26 14:49:25 -070015083 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015084 return;
15085
15086 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070015087 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015088 nlmsg_free(msg);
15089}
15090EXPORT_SYMBOL(cfg80211_report_obss_beacon);
15091
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015092#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015093static int cfg80211_net_detect_results(struct sk_buff *msg,
15094 struct cfg80211_wowlan_wakeup *wakeup)
15095{
15096 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
15097 struct nlattr *nl_results, *nl_match, *nl_freqs;
15098 int i, j;
15099
15100 nl_results = nla_nest_start(
15101 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15102 if (!nl_results)
15103 return -EMSGSIZE;
15104
15105 for (i = 0; i < nd->n_matches; i++) {
15106 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15107
15108 nl_match = nla_nest_start(msg, i);
15109 if (!nl_match)
15110 break;
15111
15112 /* The SSID attribute is optional in nl80211, but for
15113 * simplicity reasons it's always present in the
15114 * cfg80211 structure. If a driver can't pass the
15115 * SSID, that needs to be changed. A zero length SSID
15116 * is still a valid SSID (wildcard), so it cannot be
15117 * used for this purpose.
15118 */
15119 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
15120 match->ssid.ssid)) {
15121 nla_nest_cancel(msg, nl_match);
15122 goto out;
15123 }
15124
15125 if (match->n_channels) {
15126 nl_freqs = nla_nest_start(
15127 msg, NL80211_ATTR_SCAN_FREQUENCIES);
15128 if (!nl_freqs) {
15129 nla_nest_cancel(msg, nl_match);
15130 goto out;
15131 }
15132
15133 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020015134 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015135 nla_nest_cancel(msg, nl_freqs);
15136 nla_nest_cancel(msg, nl_match);
15137 goto out;
15138 }
15139 }
15140
15141 nla_nest_end(msg, nl_freqs);
15142 }
15143
15144 nla_nest_end(msg, nl_match);
15145 }
15146
15147out:
15148 nla_nest_end(msg, nl_results);
15149 return 0;
15150}
15151
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015152void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15153 struct cfg80211_wowlan_wakeup *wakeup,
15154 gfp_t gfp)
15155{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015156 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015157 struct sk_buff *msg;
15158 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015159 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015160
15161 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15162
15163 if (wakeup)
15164 size += wakeup->packet_present_len;
15165
15166 msg = nlmsg_new(size, gfp);
15167 if (!msg)
15168 return;
15169
15170 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15171 if (!hdr)
15172 goto free_msg;
15173
15174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015175 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15176 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015177 goto free_msg;
15178
15179 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15180 wdev->netdev->ifindex))
15181 goto free_msg;
15182
15183 if (wakeup) {
15184 struct nlattr *reasons;
15185
15186 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015187 if (!reasons)
15188 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015189
15190 if (wakeup->disconnect &&
15191 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15192 goto free_msg;
15193 if (wakeup->magic_pkt &&
15194 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15195 goto free_msg;
15196 if (wakeup->gtk_rekey_failure &&
15197 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15198 goto free_msg;
15199 if (wakeup->eap_identity_req &&
15200 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15201 goto free_msg;
15202 if (wakeup->four_way_handshake &&
15203 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15204 goto free_msg;
15205 if (wakeup->rfkill_release &&
15206 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15207 goto free_msg;
15208
15209 if (wakeup->pattern_idx >= 0 &&
15210 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15211 wakeup->pattern_idx))
15212 goto free_msg;
15213
Johannes Bergae917c92013-10-25 11:05:22 +020015214 if (wakeup->tcp_match &&
15215 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15216 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015217
Johannes Bergae917c92013-10-25 11:05:22 +020015218 if (wakeup->tcp_connlost &&
15219 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15220 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015221
Johannes Bergae917c92013-10-25 11:05:22 +020015222 if (wakeup->tcp_nomoretokens &&
15223 nla_put_flag(msg,
15224 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15225 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015226
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015227 if (wakeup->packet) {
15228 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15229 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15230
15231 if (!wakeup->packet_80211) {
15232 pkt_attr =
15233 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15234 len_attr =
15235 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15236 }
15237
15238 if (wakeup->packet_len &&
15239 nla_put_u32(msg, len_attr, wakeup->packet_len))
15240 goto free_msg;
15241
15242 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15243 wakeup->packet))
15244 goto free_msg;
15245 }
15246
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015247 if (wakeup->net_detect &&
15248 cfg80211_net_detect_results(msg, wakeup))
15249 goto free_msg;
15250
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015251 nla_nest_end(msg, reasons);
15252 }
15253
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015254 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015255
Johannes Berg68eb5502013-11-19 15:19:38 +010015256 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015257 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015258 return;
15259
15260 free_msg:
15261 nlmsg_free(msg);
15262}
15263EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15264#endif
15265
Jouni Malinen3475b092012-11-16 22:49:57 +020015266void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15267 enum nl80211_tdls_operation oper,
15268 u16 reason_code, gfp_t gfp)
15269{
15270 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015272 struct sk_buff *msg;
15273 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015274
15275 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15276 reason_code);
15277
15278 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15279 if (!msg)
15280 return;
15281
15282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15283 if (!hdr) {
15284 nlmsg_free(msg);
15285 return;
15286 }
15287
15288 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15289 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15290 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15291 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15292 (reason_code > 0 &&
15293 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15294 goto nla_put_failure;
15295
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015296 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015297
Johannes Berg68eb5502013-11-19 15:19:38 +010015298 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015299 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015300 return;
15301
15302 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020015303 nlmsg_free(msg);
15304}
15305EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15306
Jouni Malinen026331c2010-02-15 12:53:10 +020015307static int nl80211_netlink_notify(struct notifier_block * nb,
15308 unsigned long state,
15309 void *_notify)
15310{
15311 struct netlink_notify *notify = _notify;
15312 struct cfg80211_registered_device *rdev;
15313 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015314 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015315
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015316 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015317 return NOTIFY_DONE;
15318
15319 rcu_read_lock();
15320
Johannes Berg5e760232011-11-04 11:18:17 +010015321 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015322 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015323
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015324 list_for_each_entry_rcu(sched_scan_req,
15325 &rdev->sched_scan_req_list,
15326 list) {
15327 if (sched_scan_req->owner_nlportid == notify->portid) {
15328 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015329 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015330 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015331 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015332
Johannes Berg53873f12016-05-03 16:52:04 +030015333 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015334 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015335
Johannes Bergab810072017-04-26 07:43:41 +020015336 if (wdev->owner_nlportid == notify->portid) {
15337 wdev->nl_owner_dead = true;
15338 schedule_work(&rdev->destroy_work);
15339 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015340 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015341 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015342 }
15343
Ben Greear37c73b52012-10-26 14:49:25 -070015344 spin_lock_bh(&rdev->beacon_registrations_lock);
15345 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15346 list) {
15347 if (reg->nlportid == notify->portid) {
15348 list_del(&reg->list);
15349 kfree(reg);
15350 break;
15351 }
15352 }
15353 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015354 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015355
15356 rcu_read_unlock();
15357
Ilan peer05050752015-03-04 00:32:06 -050015358 /*
15359 * It is possible that the user space process that is controlling the
15360 * indoor setting disappeared, so notify the regulatory core.
15361 */
15362 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015363 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015364}
15365
15366static struct notifier_block nl80211_netlink_notifier = {
15367 .notifier_call = nl80211_netlink_notify,
15368};
15369
Jouni Malinen355199e2013-02-27 17:14:27 +020015370void cfg80211_ft_event(struct net_device *netdev,
15371 struct cfg80211_ft_event_params *ft_event)
15372{
15373 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015374 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015375 struct sk_buff *msg;
15376 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015377
15378 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15379
15380 if (!ft_event->target_ap)
15381 return;
15382
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015383 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015384 if (!msg)
15385 return;
15386
15387 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015388 if (!hdr)
15389 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015390
Johannes Bergae917c92013-10-25 11:05:22 +020015391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15393 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15394 goto out;
15395
15396 if (ft_event->ies &&
15397 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15398 goto out;
15399 if (ft_event->ric_ies &&
15400 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15401 ft_event->ric_ies))
15402 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015403
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015404 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015405
Johannes Berg68eb5502013-11-19 15:19:38 +010015406 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015407 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015408 return;
15409 out:
15410 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015411}
15412EXPORT_SYMBOL(cfg80211_ft_event);
15413
Arend van Spriel5de17982013-04-18 15:49:00 +020015414void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15415{
15416 struct cfg80211_registered_device *rdev;
15417 struct sk_buff *msg;
15418 void *hdr;
15419 u32 nlportid;
15420
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015421 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015422 if (!rdev->crit_proto_nlportid)
15423 return;
15424
15425 nlportid = rdev->crit_proto_nlportid;
15426 rdev->crit_proto_nlportid = 0;
15427
15428 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15429 if (!msg)
15430 return;
15431
15432 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15433 if (!hdr)
15434 goto nla_put_failure;
15435
15436 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015437 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15438 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015439 goto nla_put_failure;
15440
15441 genlmsg_end(msg, hdr);
15442
15443 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15444 return;
15445
15446 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020015447 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015448}
15449EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15450
Johannes Berg348baf02014-01-24 14:06:29 +010015451void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15452{
15453 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015454 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015455 struct sk_buff *msg;
15456 void *hdr;
15457
15458 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15459 if (!msg)
15460 return;
15461
15462 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15463 if (!hdr)
15464 goto out;
15465
15466 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15467 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015468 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15469 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015470 goto out;
15471
15472 genlmsg_end(msg, hdr);
15473
15474 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15475 NL80211_MCGRP_MLME, GFP_KERNEL);
15476 return;
15477 out:
15478 nlmsg_free(msg);
15479}
15480
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015481int cfg80211_external_auth_request(struct net_device *dev,
15482 struct cfg80211_external_auth_params *params,
15483 gfp_t gfp)
15484{
15485 struct wireless_dev *wdev = dev->ieee80211_ptr;
15486 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15487 struct sk_buff *msg;
15488 void *hdr;
15489
15490 if (!wdev->conn_owner_nlportid)
15491 return -EINVAL;
15492
15493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15494 if (!msg)
15495 return -ENOMEM;
15496
15497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
15498 if (!hdr)
15499 goto nla_put_failure;
15500
15501 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15502 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15503 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
15504 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
15505 params->action) ||
15506 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
15507 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
15508 params->ssid.ssid))
15509 goto nla_put_failure;
15510
15511 genlmsg_end(msg, hdr);
15512 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
15513 wdev->conn_owner_nlportid);
15514 return 0;
15515
15516 nla_put_failure:
15517 nlmsg_free(msg);
15518 return -ENOBUFS;
15519}
15520EXPORT_SYMBOL(cfg80211_external_auth_request);
15521
Johannes Berg55682962007-09-20 13:09:35 -040015522/* initialisation/exit functions */
15523
Johannes Berg56989f62016-10-24 14:40:05 +020015524int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015525{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015526 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015527
Johannes Berg489111e2016-10-24 14:40:03 +020015528 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015529 if (err)
15530 return err;
15531
Jouni Malinen026331c2010-02-15 12:53:10 +020015532 err = netlink_register_notifier(&nl80211_netlink_notifier);
15533 if (err)
15534 goto err_out;
15535
Johannes Berg55682962007-09-20 13:09:35 -040015536 return 0;
15537 err_out:
15538 genl_unregister_family(&nl80211_fam);
15539 return err;
15540}
15541
15542void nl80211_exit(void)
15543{
Jouni Malinen026331c2010-02-15 12:53:10 +020015544 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015545 genl_unregister_family(&nl80211_fam);
15546}