blob: a0e1951227fab1297ee8929dddb3a4a911ef2a56 [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>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Berg55682962007-09-20 13:09:35 -040035/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020036static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040037
Johannes Berg2a94fe42013-11-19 15:19:39 +010038/* multicast groups */
39enum nl80211_multicast_groups {
40 NL80211_MCGRP_CONFIG,
41 NL80211_MCGRP_SCAN,
42 NL80211_MCGRP_REGULATORY,
43 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010044 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030045 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010046 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
47};
48
49static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010050 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
51 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
52 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
53 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
54 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030055 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010056#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010057 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#endif
59};
60
Johannes Berg89a54e42012-06-15 14:33:17 +020061/* returns ERR_PTR values */
62static struct wireless_dev *
63__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040064{
Johannes Berg89a54e42012-06-15 14:33:17 +020065 struct cfg80211_registered_device *rdev;
66 struct wireless_dev *result = NULL;
67 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
68 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
69 u64 wdev_id;
70 int wiphy_idx = -1;
71 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040072
Johannes Berg5fe231e2013-05-08 21:45:15 +020073 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg89a54e42012-06-15 14:33:17 +020075 if (!have_ifidx && !have_wdev_id)
76 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (have_ifidx)
79 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
80 if (have_wdev_id) {
81 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
82 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040083 }
84
Johannes Berg89a54e42012-06-15 14:33:17 +020085 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
86 struct wireless_dev *wdev;
87
88 if (wiphy_net(&rdev->wiphy) != netns)
89 continue;
90
91 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
92 continue;
93
Johannes Berg53873f12016-05-03 16:52:04 +030094 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020095 if (have_ifidx && wdev->netdev &&
96 wdev->netdev->ifindex == ifidx) {
97 result = wdev;
98 break;
99 }
100 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
101 result = wdev;
102 break;
103 }
104 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200105
106 if (result)
107 break;
108 }
109
110 if (result)
111 return result;
112 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400113}
114
Johannes Berga9455402012-06-15 13:32:49 +0200115static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200116__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200117{
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 struct cfg80211_registered_device *rdev = NULL, *tmp;
119 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg5fe231e2013-05-08 21:45:15 +0200121 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg878d9ec2012-06-15 14:18:32 +0200123 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200124 !attrs[NL80211_ATTR_IFINDEX] &&
125 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 return ERR_PTR(-EINVAL);
127
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 if (attrs[NL80211_ATTR_WDEV]) {
133 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
134 struct wireless_dev *wdev;
135 bool found = false;
136
137 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
138 if (tmp) {
139 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300140 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200141 if (wdev->identifier != (u32)wdev_id)
142 continue;
143 found = true;
144 break;
145 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200146
147 if (!found)
148 tmp = NULL;
149
150 if (rdev && tmp != rdev)
151 return ERR_PTR(-EINVAL);
152 rdev = tmp;
153 }
154 }
155
Johannes Berg878d9ec2012-06-15 14:18:32 +0200156 if (attrs[NL80211_ATTR_IFINDEX]) {
157 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700158
Ying Xue7f2b8562014-01-15 10:23:45 +0800159 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200160 if (netdev) {
161 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800162 tmp = wiphy_to_rdev(
163 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200164 else
165 tmp = NULL;
166
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 /* not wireless device -- return error */
168 if (!tmp)
169 return ERR_PTR(-EINVAL);
170
171 /* mismatch -- return error */
172 if (rdev && tmp != rdev)
173 return ERR_PTR(-EINVAL);
174
175 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200176 }
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
178
Johannes Berg4f7eff12012-06-15 14:14:22 +0200179 if (!rdev)
180 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (netns != wiphy_net(&rdev->wiphy))
183 return ERR_PTR(-ENODEV);
184
185 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200186}
187
188/*
189 * This function returns a pointer to the driver
190 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200191 *
192 * The result of this can be a PTR_ERR and hence must
193 * be checked with IS_ERR() for errors.
194 */
195static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200197{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200198 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200199}
200
Johannes Berg55682962007-09-20 13:09:35 -0400201/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300202static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400203 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
204 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700205 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200206 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100207
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200208 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530209 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100210 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
211 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200214 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
215 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
217 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100218 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200219 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400220
221 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
222 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100224
Eliad Pellere007b852011-11-24 18:13:56 +0200225 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
226 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100227
Johannes Bergb9454e82009-07-08 13:29:08 +0200228 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100229 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
230 .len = WLAN_MAX_KEY_LEN },
231 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
232 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
233 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200234 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200235 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100236
237 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
238 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
239 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
240 .len = IEEE80211_MAX_DATA_LEN },
241 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100243 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
244 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
245 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
247 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100248 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100249 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200250 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100251 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800252 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700255 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
256 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
257
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300258 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
259 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200261 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100263 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300264
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800265 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700266 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700267
Johannes Berg6c739412011-11-03 09:27:01 +0100268 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200269
270 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
271 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100273 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200275
276 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_SSID_LEN },
278 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
279 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200280 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300281 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300282 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300283 [NL80211_ATTR_STA_FLAGS2] = {
284 .len = sizeof(struct nl80211_sta_flag_update),
285 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300286 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300287 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
288 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200289 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
290 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
291 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200292 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100293 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300294 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100295 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
296 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200297 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200298 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
299 .len = IEEE80211_MAX_DATA_LEN },
300 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200301 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200302 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300303 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200304 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300305 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
306 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200307 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900308 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
309 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100310 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100311 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100312 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200313 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700314 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300315 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200316 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200317 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300318 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300319 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
320 .len = IEEE80211_MAX_DATA_LEN },
321 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
322 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530323 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300324 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530325 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300326 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
327 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
330 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300331 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100332 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200333 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700335 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800336 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
337 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
338 .len = NL80211_HT_CAPABILITY_LEN
339 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100340 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530341 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530342 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200343 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700344 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300345 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000346 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700347 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100348 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
349 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasari8feb69c2017-07-07 01:43:41 +0300350 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200401 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200408 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
409 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
410 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
411 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200412 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300413 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
414 .len = FILS_ERP_MAX_USERNAME_LEN },
415 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
416 .len = FILS_ERP_MAX_REALM_LEN },
417 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
418 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
419 .len = FILS_ERP_MAX_RRK_LEN },
420 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
421 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100422 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400423};
424
Johannes Berge31b8212010-10-05 19:39:30 +0200425/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000426static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200427 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200428 [NL80211_KEY_IDX] = { .type = NLA_U8 },
429 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200430 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
432 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200433 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
435};
436
437/* policy for the key default flags */
438static const struct nla_policy
439nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
440 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
441 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200442};
443
Johannes Bergf83ace32016-10-17 08:04:07 +0200444#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200445/* policy for WoWLAN attributes */
446static const struct nla_policy
447nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
448 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
449 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
450 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200452 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
453 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
454 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100456 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300457 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100458};
459
460static const struct nla_policy
461nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
462 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
464 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
465 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
466 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
467 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
468 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
469 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
470 },
471 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
472 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
473 },
474 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
475 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
476 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200477};
Johannes Bergf83ace32016-10-17 08:04:07 +0200478#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200479
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700480/* policy for coalesce rule attributes */
481static const struct nla_policy
482nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
483 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
484 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
485 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
486};
487
Johannes Berge5497d72011-07-05 16:35:40 +0200488/* policy for GTK rekey offload attributes */
489static const struct nla_policy
490nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
491 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
492 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
493 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
494};
495
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300496static const struct nla_policy
497nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200498 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300499 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100500 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700501 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300502};
503
Avraham Stern3b06d272015-10-12 09:51:34 +0300504static const struct nla_policy
505nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
506 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
507 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
508};
509
Arend van Spriel38de03d2016-03-02 20:37:18 +0100510static const struct nla_policy
511nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
512 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
513 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
514 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
515 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
516 },
517};
518
Ayala Bekera442b762016-09-20 17:31:15 +0300519/* policy for NAN function attributes */
520static const struct nla_policy
521nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
522 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300523 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300524 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
525 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
526 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
527 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
528 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
529 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
530 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
531 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
532 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
533 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
534 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
535 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
536 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
537 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
538 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
539 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
540};
541
542/* policy for Service Response Filter attributes */
543static const struct nla_policy
544nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
545 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
546 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
547 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
548 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
549 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
550};
551
Peng Xuad670232017-10-03 23:21:51 +0300552/* policy for packet pattern attributes */
553static const struct nla_policy
554nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
555 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
556 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
557 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
558};
559
Johannes Berg97990a02013-04-19 01:02:55 +0200560static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
561 struct netlink_callback *cb,
562 struct cfg80211_registered_device **rdev,
563 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100564{
Johannes Berg67748892010-10-04 21:14:06 +0200565 int err;
566
Johannes Berg97990a02013-04-19 01:02:55 +0200567 if (!cb->args[0]) {
568 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200569 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200570 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200571 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100572 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200573
Johannes Bergc90c39d2016-10-24 14:40:01 +0200574 *wdev = __cfg80211_wdev_from_attrs(
575 sock_net(skb->sk),
576 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100577 if (IS_ERR(*wdev))
578 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800579 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200580 /* 0 is the first index - add 1 to parse only once */
581 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200582 cb->args[1] = (*wdev)->identifier;
583 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200584 /* subtract the 1 again here */
585 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200586 struct wireless_dev *tmp;
587
Johannes Bergea90e0d2017-03-15 14:26:04 +0100588 if (!wiphy)
589 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800590 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200591 *wdev = NULL;
592
Johannes Berg53873f12016-05-03 16:52:04 +0300593 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200594 if (tmp->identifier == cb->args[1]) {
595 *wdev = tmp;
596 break;
597 }
598 }
Johannes Berg97990a02013-04-19 01:02:55 +0200599
Johannes Bergea90e0d2017-03-15 14:26:04 +0100600 if (!*wdev)
601 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200602 }
603
Johannes Berg67748892010-10-04 21:14:06 +0200604 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200605}
606
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100607/* IE validation */
608static bool is_valid_ie_attr(const struct nlattr *attr)
609{
610 const u8 *pos;
611 int len;
612
613 if (!attr)
614 return true;
615
616 pos = nla_data(attr);
617 len = nla_len(attr);
618
619 while (len) {
620 u8 elemlen;
621
622 if (len < 2)
623 return false;
624 len -= 2;
625
626 elemlen = pos[1];
627 if (elemlen > len)
628 return false;
629
630 len -= elemlen;
631 pos += 2 + elemlen;
632 }
633
634 return true;
635}
636
Johannes Berg55682962007-09-20 13:09:35 -0400637/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000638static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400639 int flags, u8 cmd)
640{
641 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000642 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400643}
644
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100646 struct ieee80211_channel *chan,
647 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400648{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200649 /* Some channels must be completely excluded from the
650 * list to protect old user-space tools from breaking
651 */
652 if (!large && chan->flags &
653 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
654 return 0;
655
David S. Miller9360ffd2012-03-29 04:41:26 -0400656 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
657 chan->center_freq))
658 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400659
David S. Miller9360ffd2012-03-29 04:41:26 -0400660 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
662 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200663 if (chan->flags & IEEE80211_CHAN_NO_IR) {
664 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
665 goto nla_put_failure;
666 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
667 goto nla_put_failure;
668 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100669 if (chan->flags & IEEE80211_CHAN_RADAR) {
670 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
671 goto nla_put_failure;
672 if (large) {
673 u32 time;
674
675 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
676
677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
678 chan->dfs_state))
679 goto nla_put_failure;
680 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
681 time))
682 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100683 if (nla_put_u32(msg,
684 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
685 chan->dfs_cac_ms))
686 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100687 }
688 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400689
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100690 if (large) {
691 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
692 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
693 goto nla_put_failure;
694 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
695 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
696 goto nla_put_failure;
697 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
698 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
699 goto nla_put_failure;
700 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
701 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
702 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200703 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
704 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
705 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300706 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200708 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200709 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
710 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
711 goto nla_put_failure;
712 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
713 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
714 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100715 }
716
David S. Miller9360ffd2012-03-29 04:41:26 -0400717 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
718 DBM_TO_MBM(chan->max_power)))
719 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400720
721 return 0;
722
723 nla_put_failure:
724 return -ENOBUFS;
725}
726
Johannes Berg55682962007-09-20 13:09:35 -0400727/* netlink command implementations */
728
Johannes Bergb9454e82009-07-08 13:29:08 +0200729struct key_parse {
730 struct key_params p;
731 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200732 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200733 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100734 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200735};
736
737static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
738{
739 struct nlattr *tb[NL80211_KEY_MAX + 1];
740 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Bergfceb6432017-04-12 14:34:07 +0200741 nl80211_key_policy, NULL);
Johannes Bergb9454e82009-07-08 13:29:08 +0200742 if (err)
743 return err;
744
745 k->def = !!tb[NL80211_KEY_DEFAULT];
746 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
747
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100748 if (k->def) {
749 k->def_uni = true;
750 k->def_multi = true;
751 }
752 if (k->defmgmt)
753 k->def_multi = true;
754
Johannes Bergb9454e82009-07-08 13:29:08 +0200755 if (tb[NL80211_KEY_IDX])
756 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
757
758 if (tb[NL80211_KEY_DATA]) {
759 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
760 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
761 }
762
763 if (tb[NL80211_KEY_SEQ]) {
764 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
765 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
766 }
767
768 if (tb[NL80211_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
770
Johannes Berge31b8212010-10-05 19:39:30 +0200771 if (tb[NL80211_KEY_TYPE]) {
772 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
773 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
774 return -EINVAL;
775 }
776
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100777 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
778 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700779
Johannes Berg2da8f412012-01-20 13:52:37 +0100780 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
781 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Bergfceb6432017-04-12 14:34:07 +0200782 nl80211_key_default_policy, NULL);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (err)
784 return err;
785
786 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
787 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
788 }
789
Johannes Bergb9454e82009-07-08 13:29:08 +0200790 return 0;
791}
792
793static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
794{
795 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
796 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
797 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
798 }
799
800 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
801 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
802 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
803 }
804
805 if (info->attrs[NL80211_ATTR_KEY_IDX])
806 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
807
808 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
809 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
810
811 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
812 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
813
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100814 if (k->def) {
815 k->def_uni = true;
816 k->def_multi = true;
817 }
818 if (k->defmgmt)
819 k->def_multi = true;
820
Johannes Berge31b8212010-10-05 19:39:30 +0200821 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
822 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
823 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
824 return -EINVAL;
825 }
826
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100827 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
828 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200829 int err = nla_parse_nested(kdt,
830 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
831 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200832 nl80211_key_default_policy,
833 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100834 if (err)
835 return err;
836
837 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
838 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
839 }
840
Johannes Bergb9454e82009-07-08 13:29:08 +0200841 return 0;
842}
843
844static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
845{
846 int err;
847
848 memset(k, 0, sizeof(*k));
849 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200850 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200851
852 if (info->attrs[NL80211_ATTR_KEY])
853 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
854 else
855 err = nl80211_parse_key_old(info, k);
856
857 if (err)
858 return err;
859
860 if (k->def && k->defmgmt)
861 return -EINVAL;
862
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100863 if (k->defmgmt) {
864 if (k->def_uni || !k->def_multi)
865 return -EINVAL;
866 }
867
Johannes Bergb9454e82009-07-08 13:29:08 +0200868 if (k->idx != -1) {
869 if (k->defmgmt) {
870 if (k->idx < 4 || k->idx > 5)
871 return -EINVAL;
872 } else if (k->def) {
873 if (k->idx < 0 || k->idx > 3)
874 return -EINVAL;
875 } else {
876 if (k->idx < 0 || k->idx > 5)
877 return -EINVAL;
878 }
879 }
880
881 return 0;
882}
883
Johannes Bergfffd0932009-07-08 14:22:54 +0200884static struct cfg80211_cached_keys *
885nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530886 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200887{
888 struct key_parse parse;
889 struct nlattr *key;
890 struct cfg80211_cached_keys *result;
891 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200892 bool have_key = false;
893
894 nla_for_each_nested(key, keys, rem) {
895 have_key = true;
896 break;
897 }
898
899 if (!have_key)
900 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200901
902 result = kzalloc(sizeof(*result), GFP_KERNEL);
903 if (!result)
904 return ERR_PTR(-ENOMEM);
905
906 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200907
908 nla_for_each_nested(key, keys, rem) {
909 memset(&parse, 0, sizeof(parse));
910 parse.idx = -1;
911
912 err = nl80211_parse_key_new(key, &parse);
913 if (err)
914 goto error;
915 err = -EINVAL;
916 if (!parse.p.key)
917 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200918 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200919 goto error;
920 if (parse.def) {
921 if (def)
922 goto error;
923 def = 1;
924 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100925 if (!parse.def_uni || !parse.def_multi)
926 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200927 } else if (parse.defmgmt)
928 goto error;
929 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200930 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200931 if (err)
932 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200933 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
934 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
935 err = -EINVAL;
936 goto error;
937 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200938 result->params[parse.idx].cipher = parse.p.cipher;
939 result->params[parse.idx].key_len = parse.p.key_len;
940 result->params[parse.idx].key = result->data[parse.idx];
941 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530942
Johannes Berg386b1f22016-09-13 16:10:02 +0200943 /* must be WEP key if we got here */
944 if (no_ht)
945 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200946 }
947
Johannes Bergf1c1f172016-09-13 17:08:23 +0200948 if (result->def < 0) {
949 err = -EINVAL;
950 goto error;
951 }
952
Johannes Bergfffd0932009-07-08 14:22:54 +0200953 return result;
954 error:
955 kfree(result);
956 return ERR_PTR(err);
957}
958
959static int nl80211_key_allowed(struct wireless_dev *wdev)
960{
961 ASSERT_WDEV_LOCK(wdev);
962
Johannes Bergfffd0932009-07-08 14:22:54 +0200963 switch (wdev->iftype) {
964 case NL80211_IFTYPE_AP:
965 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200966 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700967 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200968 break;
969 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200970 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200971 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200972 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200973 return -ENOLINK;
974 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100975 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100976 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100977 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300978 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100979 case NL80211_IFTYPE_P2P_DEVICE:
980 case NL80211_IFTYPE_WDS:
981 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200982 return -EINVAL;
983 }
984
985 return 0;
986}
987
Jouni Malinen664834d2014-01-15 00:01:44 +0200988static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
989 struct nlattr *tb)
990{
991 struct ieee80211_channel *chan;
992
993 if (tb == NULL)
994 return NULL;
995 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
996 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
997 return NULL;
998 return chan;
999}
1000
Johannes Berg7527a782011-05-13 10:58:57 +02001001static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1002{
1003 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1004 int i;
1005
1006 if (!nl_modes)
1007 goto nla_put_failure;
1008
1009 i = 0;
1010 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001011 if ((ifmodes & 1) && nla_put_flag(msg, i))
1012 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001013 ifmodes >>= 1;
1014 i++;
1015 }
1016
1017 nla_nest_end(msg, nl_modes);
1018 return 0;
1019
1020nla_put_failure:
1021 return -ENOBUFS;
1022}
1023
1024static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001025 struct sk_buff *msg,
1026 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001027{
1028 struct nlattr *nl_combis;
1029 int i, j;
1030
1031 nl_combis = nla_nest_start(msg,
1032 NL80211_ATTR_INTERFACE_COMBINATIONS);
1033 if (!nl_combis)
1034 goto nla_put_failure;
1035
1036 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1037 const struct ieee80211_iface_combination *c;
1038 struct nlattr *nl_combi, *nl_limits;
1039
1040 c = &wiphy->iface_combinations[i];
1041
1042 nl_combi = nla_nest_start(msg, i + 1);
1043 if (!nl_combi)
1044 goto nla_put_failure;
1045
1046 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1047 if (!nl_limits)
1048 goto nla_put_failure;
1049
1050 for (j = 0; j < c->n_limits; j++) {
1051 struct nlattr *nl_limit;
1052
1053 nl_limit = nla_nest_start(msg, j + 1);
1054 if (!nl_limit)
1055 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001056 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1057 c->limits[j].max))
1058 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001059 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1060 c->limits[j].types))
1061 goto nla_put_failure;
1062 nla_nest_end(msg, nl_limit);
1063 }
1064
1065 nla_nest_end(msg, nl_limits);
1066
David S. Miller9360ffd2012-03-29 04:41:26 -04001067 if (c->beacon_int_infra_match &&
1068 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1069 goto nla_put_failure;
1070 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1071 c->num_different_channels) ||
1072 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1073 c->max_interfaces))
1074 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001075 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001076 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1077 c->radar_detect_widths) ||
1078 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1079 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001080 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301081 if (c->beacon_int_min_gcd &&
1082 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1083 c->beacon_int_min_gcd))
1084 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001085
1086 nla_nest_end(msg, nl_combi);
1087 }
1088
1089 nla_nest_end(msg, nl_combis);
1090
1091 return 0;
1092nla_put_failure:
1093 return -ENOBUFS;
1094}
1095
Johannes Berg3713b4e2013-02-14 16:19:38 +01001096#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001097static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1098 struct sk_buff *msg)
1099{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001100 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001101 struct nlattr *nl_tcp;
1102
1103 if (!tcp)
1104 return 0;
1105
1106 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1107 if (!nl_tcp)
1108 return -ENOBUFS;
1109
1110 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1111 tcp->data_payload_max))
1112 return -ENOBUFS;
1113
1114 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1115 tcp->data_payload_max))
1116 return -ENOBUFS;
1117
1118 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1119 return -ENOBUFS;
1120
1121 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1122 sizeof(*tcp->tok), tcp->tok))
1123 return -ENOBUFS;
1124
1125 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1126 tcp->data_interval_max))
1127 return -ENOBUFS;
1128
1129 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1130 tcp->wake_payload_max))
1131 return -ENOBUFS;
1132
1133 nla_nest_end(msg, nl_tcp);
1134 return 0;
1135}
1136
Johannes Berg3713b4e2013-02-14 16:19:38 +01001137static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001139 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001140{
1141 struct nlattr *nl_wowlan;
1142
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001143 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001144 return 0;
1145
1146 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1147 if (!nl_wowlan)
1148 return -ENOBUFS;
1149
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001152 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001153 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001156 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001157 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001158 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001160 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001162 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001163 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001164 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001165 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1166 return -ENOBUFS;
1167
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001168 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001169 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001170 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1171 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1172 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1173 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001174 };
1175
1176 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1177 sizeof(pat), &pat))
1178 return -ENOBUFS;
1179 }
1180
Luciano Coelho75453cc2015-01-09 14:06:37 +02001181 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1182 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1183 rdev->wiphy.wowlan->max_nd_match_sets))
1184 return -ENOBUFS;
1185
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001186 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001187 return -ENOBUFS;
1188
Johannes Berg3713b4e2013-02-14 16:19:38 +01001189 nla_nest_end(msg, nl_wowlan);
1190
1191 return 0;
1192}
1193#endif
1194
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001195static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001196 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001197{
1198 struct nl80211_coalesce_rule_support rule;
1199
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001200 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001201 return 0;
1202
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001203 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1204 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1205 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1206 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1207 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1208 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001209
1210 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1211 return -ENOBUFS;
1212
1213 return 0;
1214}
1215
Johannes Berg3713b4e2013-02-14 16:19:38 +01001216static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1217 struct ieee80211_supported_band *sband)
1218{
1219 struct nlattr *nl_rates, *nl_rate;
1220 struct ieee80211_rate *rate;
1221 int i;
1222
1223 /* add HT info */
1224 if (sband->ht_cap.ht_supported &&
1225 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1226 sizeof(sband->ht_cap.mcs),
1227 &sband->ht_cap.mcs) ||
1228 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1229 sband->ht_cap.cap) ||
1230 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1231 sband->ht_cap.ampdu_factor) ||
1232 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1233 sband->ht_cap.ampdu_density)))
1234 return -ENOBUFS;
1235
1236 /* add VHT info */
1237 if (sband->vht_cap.vht_supported &&
1238 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1239 sizeof(sband->vht_cap.vht_mcs),
1240 &sband->vht_cap.vht_mcs) ||
1241 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1242 sband->vht_cap.cap)))
1243 return -ENOBUFS;
1244
1245 /* add bitrates */
1246 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1247 if (!nl_rates)
1248 return -ENOBUFS;
1249
1250 for (i = 0; i < sband->n_bitrates; i++) {
1251 nl_rate = nla_nest_start(msg, i);
1252 if (!nl_rate)
1253 return -ENOBUFS;
1254
1255 rate = &sband->bitrates[i];
1256 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1257 rate->bitrate))
1258 return -ENOBUFS;
1259 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1260 nla_put_flag(msg,
1261 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1262 return -ENOBUFS;
1263
1264 nla_nest_end(msg, nl_rate);
1265 }
1266
1267 nla_nest_end(msg, nl_rates);
1268
1269 return 0;
1270}
1271
1272static int
1273nl80211_send_mgmt_stypes(struct sk_buff *msg,
1274 const struct ieee80211_txrx_stypes *mgmt_stypes)
1275{
1276 u16 stypes;
1277 struct nlattr *nl_ftypes, *nl_ifs;
1278 enum nl80211_iftype ift;
1279 int i;
1280
1281 if (!mgmt_stypes)
1282 return 0;
1283
1284 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1285 if (!nl_ifs)
1286 return -ENOBUFS;
1287
1288 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1289 nl_ftypes = nla_nest_start(msg, ift);
1290 if (!nl_ftypes)
1291 return -ENOBUFS;
1292 i = 0;
1293 stypes = mgmt_stypes[ift].tx;
1294 while (stypes) {
1295 if ((stypes & 1) &&
1296 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1297 (i << 4) | IEEE80211_FTYPE_MGMT))
1298 return -ENOBUFS;
1299 stypes >>= 1;
1300 i++;
1301 }
1302 nla_nest_end(msg, nl_ftypes);
1303 }
1304
1305 nla_nest_end(msg, nl_ifs);
1306
1307 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1308 if (!nl_ifs)
1309 return -ENOBUFS;
1310
1311 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1312 nl_ftypes = nla_nest_start(msg, ift);
1313 if (!nl_ftypes)
1314 return -ENOBUFS;
1315 i = 0;
1316 stypes = mgmt_stypes[ift].rx;
1317 while (stypes) {
1318 if ((stypes & 1) &&
1319 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1320 (i << 4) | IEEE80211_FTYPE_MGMT))
1321 return -ENOBUFS;
1322 stypes >>= 1;
1323 i++;
1324 }
1325 nla_nest_end(msg, nl_ftypes);
1326 }
1327 nla_nest_end(msg, nl_ifs);
1328
1329 return 0;
1330}
1331
Johannes Berg17948992016-10-26 11:42:04 +02001332#define CMD(op, n) \
1333 do { \
1334 if (rdev->ops->op) { \
1335 i++; \
1336 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1337 goto nla_put_failure; \
1338 } \
1339 } while (0)
1340
1341static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1342 struct sk_buff *msg)
1343{
1344 int i = 0;
1345
1346 /*
1347 * do *NOT* add anything into this function, new things need to be
1348 * advertised only to new versions of userspace that can deal with
1349 * the split (and they can't possibly care about new features...
1350 */
1351 CMD(add_virtual_intf, NEW_INTERFACE);
1352 CMD(change_virtual_intf, SET_INTERFACE);
1353 CMD(add_key, NEW_KEY);
1354 CMD(start_ap, START_AP);
1355 CMD(add_station, NEW_STATION);
1356 CMD(add_mpath, NEW_MPATH);
1357 CMD(update_mesh_config, SET_MESH_CONFIG);
1358 CMD(change_bss, SET_BSS);
1359 CMD(auth, AUTHENTICATE);
1360 CMD(assoc, ASSOCIATE);
1361 CMD(deauth, DEAUTHENTICATE);
1362 CMD(disassoc, DISASSOCIATE);
1363 CMD(join_ibss, JOIN_IBSS);
1364 CMD(join_mesh, JOIN_MESH);
1365 CMD(set_pmksa, SET_PMKSA);
1366 CMD(del_pmksa, DEL_PMKSA);
1367 CMD(flush_pmksa, FLUSH_PMKSA);
1368 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1369 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1370 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1371 CMD(mgmt_tx, FRAME);
1372 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1373 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1374 i++;
1375 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1376 goto nla_put_failure;
1377 }
1378 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1379 rdev->ops->join_mesh) {
1380 i++;
1381 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1382 goto nla_put_failure;
1383 }
1384 CMD(set_wds_peer, SET_WDS_PEER);
1385 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1386 CMD(tdls_mgmt, TDLS_MGMT);
1387 CMD(tdls_oper, TDLS_OPER);
1388 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001389 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001390 CMD(sched_scan_start, START_SCHED_SCAN);
1391 CMD(probe_client, PROBE_CLIENT);
1392 CMD(set_noack_map, SET_NOACK_MAP);
1393 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1394 i++;
1395 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1396 goto nla_put_failure;
1397 }
1398 CMD(start_p2p_device, START_P2P_DEVICE);
1399 CMD(set_mcast_rate, SET_MCAST_RATE);
1400#ifdef CONFIG_NL80211_TESTMODE
1401 CMD(testmode_cmd, TESTMODE);
1402#endif
1403
1404 if (rdev->ops->connect || rdev->ops->auth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1407 goto nla_put_failure;
1408 }
1409
1410 if (rdev->ops->disconnect || rdev->ops->deauth) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1413 goto nla_put_failure;
1414 }
1415
1416 return i;
1417 nla_put_failure:
1418 return -ENOBUFS;
1419}
1420
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421struct nl80211_dump_wiphy_state {
1422 s64 filter_wiphy;
1423 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301424 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 bool split;
1426};
1427
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001428static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001429 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001432{
1433 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001434 struct nlattr *nl_bands, *nl_band;
1435 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001436 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001437 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001438 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001439 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001440 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001441 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001442 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001443
Johannes Berg3bb20552014-05-26 13:52:25 +02001444 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001445 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 return -ENOBUFS;
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (WARN_ON(!state))
1449 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001450
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001451 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001453 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001454 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001456 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001457
Johannes Berg3bb20552014-05-26 13:52:25 +02001458 if (cmd != NL80211_CMD_NEW_WIPHY)
1459 goto finish;
1460
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 case 0:
1463 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001464 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001472 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001480 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001482 rdev->wiphy.max_match_sets) ||
1483 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1484 rdev->wiphy.max_sched_scan_plans) ||
1485 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1486 rdev->wiphy.max_sched_scan_plan_interval) ||
1487 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1488 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001489 goto nla_put_failure;
1490
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1493 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1496 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1499 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1502 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1505 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001508 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 state->split_start++;
1510 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 break;
1512 case 1:
1513 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1515 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001516 goto nla_put_failure;
1517
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001520 goto nla_put_failure;
1521
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1524 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001525
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001531
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001536
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001537 if ((rdev->wiphy.available_antennas_tx ||
1538 rdev->wiphy.available_antennas_rx) &&
1539 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 u32 tx_ant = 0, rx_ant = 0;
1541 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001542
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001543 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 if (!res) {
1545 if (nla_put_u32(msg,
1546 NL80211_ATTR_WIPHY_ANTENNA_TX,
1547 tx_ant) ||
1548 nla_put_u32(msg,
1549 NL80211_ATTR_WIPHY_ANTENNA_RX,
1550 rx_ant))
1551 goto nla_put_failure;
1552 }
Johannes Bergee688b002008-01-24 19:38:39 +01001553 }
1554
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
1556 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 break;
1558 case 2:
1559 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001560 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562 state->split_start++;
1563 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 3:
1566 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1567 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001568 goto nla_put_failure;
1569
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001571 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 struct ieee80211_supported_band *sband;
1573
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575
1576 if (!sband)
1577 continue;
1578
1579 nl_band = nla_nest_start(msg, band);
1580 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001581 goto nla_put_failure;
1582
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 case 0:
1585 if (nl80211_send_band_rateinfo(msg, sband))
1586 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001587 state->chan_start++;
1588 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 break;
1590 default:
1591 /* add frequencies */
1592 nl_freqs = nla_nest_start(
1593 msg, NL80211_BAND_ATTR_FREQS);
1594 if (!nl_freqs)
1595 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001596
Johannes Berg86e8cf92013-06-19 10:57:22 +02001597 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 i < sband->n_channels;
1599 i++) {
1600 nl_freq = nla_nest_start(msg, i);
1601 if (!nl_freq)
1602 goto nla_put_failure;
1603
1604 chan = &sband->channels[i];
1605
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 if (nl80211_msg_put_channel(
1607 msg, chan,
1608 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 goto nla_put_failure;
1610
1611 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 break;
1614 }
1615 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001616 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 nla_nest_end(msg, nl_freqs);
1620 }
1621
1622 nla_nest_end(msg, nl_band);
1623
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001625 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001626 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 band--;
1628 break;
1629 }
Johannes Bergee688b002008-01-24 19:38:39 +01001630 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001632
Johannes Berg57fbcce2016-04-12 15:56:15 +02001633 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001636 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001637
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->band_start == 0 && state->chan_start == 0)
1640 state->split_start++;
1641 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 break;
1643 case 4:
1644 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1645 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001646 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647
Johannes Berg17948992016-10-26 11:42:04 +02001648 i = nl80211_add_commands_unsplit(rdev, msg);
1649 if (i < 0)
1650 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001651 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001652 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1653 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001655 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001656 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001657 if (rdev->wiphy.features &
1658 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001659 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001660 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001661 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001662 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001663#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001664
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
1667 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 break;
1669 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 if (rdev->ops->remain_on_channel &&
1671 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 nla_put_u32(msg,
1673 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001675 goto nla_put_failure;
1676
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001677 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001678 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1679 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001680
Johannes Berg3713b4e2013-02-14 16:19:38 +01001681 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1682 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001683 state->split_start++;
1684 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 break;
1686 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001687#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001690 state->split_start++;
1691 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692 break;
1693#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695#endif
1696 case 7:
1697 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001698 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001699 goto nla_put_failure;
1700
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001701 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001702 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001704
Johannes Berg86e8cf92013-06-19 10:57:22 +02001705 state->split_start++;
1706 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 break;
1708 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001709 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001710 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001712 goto nla_put_failure;
1713
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001714 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001715 /*
1716 * We can only add the per-channel limit information if the
1717 * dump is split, otherwise it makes it too big. Therefore
1718 * only advertise it in that case.
1719 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001720 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001721 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1722 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 goto nla_put_failure;
1724
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001725 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001726 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1728 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 goto nla_put_failure;
1730
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001731 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1732 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001733 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001734 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 goto nla_put_failure;
1736
1737 /*
1738 * Any information below this point is only available to
1739 * applications that can deal with it being split. This
1740 * helps ensure that newly added capabilities don't break
1741 * older tools by overrunning their buffers.
1742 *
1743 * We still increment split_start so that in the split
1744 * case we'll continue with more data in the next round,
1745 * but break unconditionally so unsplit data stops here.
1746 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001748 break;
1749 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001750 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001751 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001752 rdev->wiphy.extended_capabilities_len,
1753 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001754 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 rdev->wiphy.extended_capabilities_len,
1756 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001757 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001758
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001759 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001760 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001761 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1762 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001763 goto nla_put_failure;
1764
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001765 state->split_start++;
1766 break;
1767 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001768 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001769 goto nla_put_failure;
1770
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001772 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1773 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1774 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001775
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001776 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001777 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001779 goto nla_put_failure;
1780
Johannes Bergad7e7182013-11-13 13:37:47 +01001781 state->split_start++;
1782 break;
1783 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001785 const struct nl80211_vendor_cmd_info *info;
1786 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001787
Johannes Berg567ffc32013-12-18 14:43:31 +01001788 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1789 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001790 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001791
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001792 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1793 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001794 if (nla_put(msg, i + 1, sizeof(*info), info))
1795 goto nla_put_failure;
1796 }
1797 nla_nest_end(msg, nested);
1798 }
1799
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001800 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001801 const struct nl80211_vendor_cmd_info *info;
1802 struct nlattr *nested;
1803
1804 nested = nla_nest_start(msg,
1805 NL80211_ATTR_VENDOR_EVENTS);
1806 if (!nested)
1807 goto nla_put_failure;
1808
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001809 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1810 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001811 if (nla_put(msg, i + 1, sizeof(*info), info))
1812 goto nla_put_failure;
1813 }
1814 nla_nest_end(msg, nested);
1815 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001816 state->split_start++;
1817 break;
1818 case 12:
1819 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1820 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1821 rdev->wiphy.max_num_csa_counters))
1822 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001823
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001824 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1825 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1826 goto nla_put_failure;
1827
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001828 if (rdev->wiphy.max_sched_scan_reqs &&
1829 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1830 rdev->wiphy.max_sched_scan_reqs))
1831 goto nla_put_failure;
1832
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001833 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1834 sizeof(rdev->wiphy.ext_features),
1835 rdev->wiphy.ext_features))
1836 goto nla_put_failure;
1837
Arend van Spriel38de03d2016-03-02 20:37:18 +01001838 if (rdev->wiphy.bss_select_support) {
1839 struct nlattr *nested;
1840 u32 bss_select_support = rdev->wiphy.bss_select_support;
1841
1842 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1843 if (!nested)
1844 goto nla_put_failure;
1845
1846 i = 0;
1847 while (bss_select_support) {
1848 if ((bss_select_support & 1) &&
1849 nla_put_flag(msg, i))
1850 goto nla_put_failure;
1851 i++;
1852 bss_select_support >>= 1;
1853 }
1854 nla_nest_end(msg, nested);
1855 }
1856
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301857 state->split_start++;
1858 break;
1859 case 13:
1860 if (rdev->wiphy.num_iftype_ext_capab &&
1861 rdev->wiphy.iftype_ext_capab) {
1862 struct nlattr *nested_ext_capab, *nested;
1863
1864 nested = nla_nest_start(msg,
1865 NL80211_ATTR_IFTYPE_EXT_CAPA);
1866 if (!nested)
1867 goto nla_put_failure;
1868
1869 for (i = state->capa_start;
1870 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1871 const struct wiphy_iftype_ext_capab *capab;
1872
1873 capab = &rdev->wiphy.iftype_ext_capab[i];
1874
1875 nested_ext_capab = nla_nest_start(msg, i);
1876 if (!nested_ext_capab ||
1877 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1878 capab->iftype) ||
1879 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1880 capab->extended_capabilities_len,
1881 capab->extended_capabilities) ||
1882 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1883 capab->extended_capabilities_len,
1884 capab->extended_capabilities_mask))
1885 goto nla_put_failure;
1886
1887 nla_nest_end(msg, nested_ext_capab);
1888 if (state->split)
1889 break;
1890 }
1891 nla_nest_end(msg, nested);
1892 if (i < rdev->wiphy.num_iftype_ext_capab) {
1893 state->capa_start = i + 1;
1894 break;
1895 }
1896 }
1897
Luca Coelho85859892017-02-08 15:00:34 +02001898 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1899 rdev->wiphy.nan_supported_bands))
1900 goto nla_put_failure;
1901
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001903 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001904 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001905 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001906 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001907 genlmsg_end(msg, hdr);
1908 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001909
1910 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001911 genlmsg_cancel(msg, hdr);
1912 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001913}
1914
Johannes Berg86e8cf92013-06-19 10:57:22 +02001915static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1916 struct netlink_callback *cb,
1917 struct nl80211_dump_wiphy_state *state)
1918{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001919 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02001920 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
1921 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 /* ignore parse errors for backward compatibility */
1923 if (ret)
1924 return 0;
1925
1926 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1927 if (tb[NL80211_ATTR_WIPHY])
1928 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1929 if (tb[NL80211_ATTR_WDEV])
1930 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1931 if (tb[NL80211_ATTR_IFINDEX]) {
1932 struct net_device *netdev;
1933 struct cfg80211_registered_device *rdev;
1934 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1935
Ying Xue7f2b8562014-01-15 10:23:45 +08001936 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001937 if (!netdev)
1938 return -ENODEV;
1939 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001940 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001941 netdev->ieee80211_ptr->wiphy);
1942 state->filter_wiphy = rdev->wiphy_idx;
1943 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 }
1945
1946 return 0;
1947}
1948
Johannes Berg55682962007-09-20 13:09:35 -04001949static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1950{
Johannes Berg645e77d2013-03-01 14:03:49 +01001951 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001952 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001953 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001954
Johannes Berg5fe231e2013-05-08 21:45:15 +02001955 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001956 if (!state) {
1957 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001958 if (!state) {
1959 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001960 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001961 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001962 state->filter_wiphy = -1;
1963 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1964 if (ret) {
1965 kfree(state);
1966 rtnl_unlock();
1967 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001968 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001969 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001970 }
1971
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001972 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1973 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001974 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001975 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001976 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001977 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001978 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001979 continue;
1980 /* attempt to fit multiple wiphy data chunks into the skb */
1981 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001982 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1983 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001984 NETLINK_CB(cb->skb).portid,
1985 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001986 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001987 if (ret < 0) {
1988 /*
1989 * If sending the wiphy data didn't fit (ENOBUFS
1990 * or EMSGSIZE returned), this SKB is still
1991 * empty (so it's not too big because another
1992 * wiphy dataset is already in the skb) and
1993 * we've not tried to adjust the dump allocation
1994 * yet ... then adjust the alloc size to be
1995 * bigger, and return 1 but with the empty skb.
1996 * This results in an empty message being RX'ed
1997 * in userspace, but that is ignored.
1998 *
1999 * We can then retry with the larger buffer.
2000 */
2001 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002002 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002003 cb->min_dump_alloc < 4096) {
2004 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002005 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002006 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002007 return 1;
2008 }
2009 idx--;
2010 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002011 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002012 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002013 break;
Johannes Berg55682962007-09-20 13:09:35 -04002014 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002015 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002016
Johannes Berg86e8cf92013-06-19 10:57:22 +02002017 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002018
2019 return skb->len;
2020}
2021
Johannes Berg86e8cf92013-06-19 10:57:22 +02002022static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2023{
2024 kfree((void *)cb->args[0]);
2025 return 0;
2026}
2027
Johannes Berg55682962007-09-20 13:09:35 -04002028static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2029{
2030 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002032 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002033
Johannes Berg645e77d2013-03-01 14:03:49 +01002034 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002035 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002036 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002037
Johannes Berg3bb20552014-05-26 13:52:25 +02002038 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2039 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002040 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002041 nlmsg_free(msg);
2042 return -ENOBUFS;
2043 }
Johannes Berg55682962007-09-20 13:09:35 -04002044
Johannes Berg134e6372009-07-10 09:51:34 +00002045 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002046}
2047
Jouni Malinen31888482008-10-30 16:59:24 +02002048static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2049 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2050 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2051 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2052 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2053 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2054};
2055
2056static int parse_txq_params(struct nlattr *tb[],
2057 struct ieee80211_txq_params *txq_params)
2058{
Johannes Berga3304b02012-03-28 11:04:24 +02002059 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002060 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2061 !tb[NL80211_TXQ_ATTR_AIFS])
2062 return -EINVAL;
2063
Johannes Berga3304b02012-03-28 11:04:24 +02002064 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002065 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2066 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2067 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2068 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2069
Johannes Berga3304b02012-03-28 11:04:24 +02002070 if (txq_params->ac >= NL80211_NUM_ACS)
2071 return -EINVAL;
2072
Jouni Malinen31888482008-10-30 16:59:24 +02002073 return 0;
2074}
2075
Johannes Bergf444de02010-05-05 15:25:02 +02002076static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2077{
2078 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002079 * You can only set the channel explicitly for WDS interfaces,
2080 * all others have their channel managed via their respective
2081 * "establish a connection" command (connect, join, ...)
2082 *
2083 * For AP/GO and mesh mode, the channel can be set with the
2084 * channel userspace API, but is only stored and passed to the
2085 * low-level driver when the AP starts or the mesh is joined.
2086 * This is for backward compatibility, userspace can also give
2087 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002088 *
2089 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002090 * whatever else is going on, so they have their own special
2091 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002092 */
2093 return !wdev ||
2094 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002095 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002096 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2097 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002098}
2099
Johannes Berg683b6d32012-11-08 21:25:48 +01002100static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2101 struct genl_info *info,
2102 struct cfg80211_chan_def *chandef)
2103{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302104 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002105
2106 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2107 return -EINVAL;
2108
2109 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2110
2111 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002112 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2113 chandef->center_freq1 = control_freq;
2114 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002115
2116 /* Primary channel not allowed */
2117 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2118 return -EINVAL;
2119
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002120 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2121 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002122
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002123 chantype = nla_get_u32(
2124 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2125
2126 switch (chantype) {
2127 case NL80211_CHAN_NO_HT:
2128 case NL80211_CHAN_HT20:
2129 case NL80211_CHAN_HT40PLUS:
2130 case NL80211_CHAN_HT40MINUS:
2131 cfg80211_chandef_create(chandef, chandef->chan,
2132 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002133 /* user input for center_freq is incorrect */
2134 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2135 chandef->center_freq1 != nla_get_u32(
2136 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2137 return -EINVAL;
2138 /* center_freq2 must be zero */
2139 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2140 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2141 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002142 break;
2143 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002144 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002145 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002146 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2147 chandef->width =
2148 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2149 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2150 chandef->center_freq1 =
2151 nla_get_u32(
2152 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2153 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2154 chandef->center_freq2 =
2155 nla_get_u32(
2156 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2157 }
2158
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002159 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002160 return -EINVAL;
2161
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002162 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2163 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002164 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002165
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002166 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2167 chandef->width == NL80211_CHAN_WIDTH_10) &&
2168 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2169 return -EINVAL;
2170
Johannes Berg683b6d32012-11-08 21:25:48 +01002171 return 0;
2172}
2173
Johannes Bergf444de02010-05-05 15:25:02 +02002174static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002175 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002176 struct genl_info *info)
2177{
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002179 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002180 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002181 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002182
Jouni Malinene16821b2014-04-28 11:22:08 +03002183 if (dev)
2184 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002185 if (!nl80211_can_set_dev_channel(wdev))
2186 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002187 if (wdev)
2188 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002189
Johannes Berg683b6d32012-11-08 21:25:48 +01002190 result = nl80211_parse_chandef(rdev, info, &chandef);
2191 if (result)
2192 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002193
Johannes Berge8c9bd52012-06-06 08:18:22 +02002194 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002195 case NL80211_IFTYPE_AP:
2196 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002197 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2198 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002199 result = -EINVAL;
2200 break;
2201 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002202 if (wdev->beacon_interval) {
2203 if (!dev || !rdev->ops->set_ap_chanwidth ||
2204 !(rdev->wiphy.features &
2205 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2206 result = -EBUSY;
2207 break;
2208 }
2209
2210 /* Only allow dynamic channel width changes */
2211 if (chandef.chan != wdev->preset_chandef.chan) {
2212 result = -EBUSY;
2213 break;
2214 }
2215 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2216 if (result)
2217 break;
2218 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002219 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002220 result = 0;
2221 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002222 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002223 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002224 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002225 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002226 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002227 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002228 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002229 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002230 }
Johannes Bergf444de02010-05-05 15:25:02 +02002231
2232 return result;
2233}
2234
2235static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2236{
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2238 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002239
Jouni Malinene16821b2014-04-28 11:22:08 +03002240 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002241}
2242
Bill Jordane8347eb2010-10-01 13:54:28 -04002243static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2244{
Johannes Berg43b19952010-10-07 13:10:30 +02002245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2246 struct net_device *dev = info->user_ptr[1];
2247 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002248 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002249
2250 if (!info->attrs[NL80211_ATTR_MAC])
2251 return -EINVAL;
2252
Johannes Berg43b19952010-10-07 13:10:30 +02002253 if (netif_running(dev))
2254 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002255
Johannes Berg43b19952010-10-07 13:10:30 +02002256 if (!rdev->ops->set_wds_peer)
2257 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002258
Johannes Berg43b19952010-10-07 13:10:30 +02002259 if (wdev->iftype != NL80211_IFTYPE_WDS)
2260 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002261
2262 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002263 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002264}
2265
Johannes Berg55682962007-09-20 13:09:35 -04002266static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2267{
2268 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002269 struct net_device *netdev = NULL;
2270 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002271 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002272 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002273 u32 changed;
2274 u8 retry_short = 0, retry_long = 0;
2275 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002277
Johannes Berg5fe231e2013-05-08 21:45:15 +02002278 ASSERT_RTNL();
2279
Johannes Bergf444de02010-05-05 15:25:02 +02002280 /*
2281 * Try to find the wiphy and netdev. Normally this
2282 * function shouldn't need the netdev, but this is
2283 * done for backward compatibility -- previously
2284 * setting the channel was done per wiphy, but now
2285 * it is per netdev. Previous userland like hostapd
2286 * also passed a netdev to set_wiphy, so that it is
2287 * possible to let that go to the right netdev!
2288 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002289
Johannes Bergf444de02010-05-05 15:25:02 +02002290 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2291 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2292
Ying Xue7f2b8562014-01-15 10:23:45 +08002293 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002294 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002295 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002296 else
Johannes Bergf444de02010-05-05 15:25:02 +02002297 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002298 }
2299
Johannes Bergf444de02010-05-05 15:25:02 +02002300 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002301 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2302 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002303 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002304 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002305 wdev = NULL;
2306 netdev = NULL;
2307 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002308 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002309 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002310
2311 /*
2312 * end workaround code, by now the rdev is available
2313 * and locked, and wdev may or may not be NULL.
2314 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002315
2316 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002317 result = cfg80211_dev_rename(
2318 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002319
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002322
Jouni Malinen31888482008-10-30 16:59:24 +02002323 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2324 struct ieee80211_txq_params txq_params;
2325 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2326
Ying Xue7f2b8562014-01-15 10:23:45 +08002327 if (!rdev->ops->set_txq_params)
2328 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002329
Ying Xue7f2b8562014-01-15 10:23:45 +08002330 if (!netdev)
2331 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002332
Johannes Berg133a3ff2011-11-03 14:50:13 +01002333 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2335 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002336
Ying Xue7f2b8562014-01-15 10:23:45 +08002337 if (!netif_running(netdev))
2338 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002339
Jouni Malinen31888482008-10-30 16:59:24 +02002340 nla_for_each_nested(nl_txq_params,
2341 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2342 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002343 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2344 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002345 txq_params_policy,
2346 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002347 if (result)
2348 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002349 result = parse_txq_params(tb, &txq_params);
2350 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002351 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002352
Hila Gonene35e4d22012-06-27 17:19:42 +03002353 result = rdev_set_txq_params(rdev, netdev,
2354 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002355 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002356 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002357 }
2358 }
2359
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002360 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002361 result = __nl80211_set_channel(
2362 rdev,
2363 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2364 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002365 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002366 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002367 }
2368
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002369 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002370 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002371 enum nl80211_tx_power_setting type;
2372 int idx, mbm = 0;
2373
Johannes Bergc8442112012-10-24 10:17:18 +02002374 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2375 txp_wdev = NULL;
2376
Ying Xue7f2b8562014-01-15 10:23:45 +08002377 if (!rdev->ops->set_tx_power)
2378 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002379
2380 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2381 type = nla_get_u32(info->attrs[idx]);
2382
2383 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002384 (type != NL80211_TX_POWER_AUTOMATIC))
2385 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002386
2387 if (type != NL80211_TX_POWER_AUTOMATIC) {
2388 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2389 mbm = nla_get_u32(info->attrs[idx]);
2390 }
2391
Johannes Bergc8442112012-10-24 10:17:18 +02002392 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002393 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002394 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002395 }
2396
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002397 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2398 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2399 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002400
Bruno Randolf7f531e02010-12-16 11:30:22 +09002401 if ((!rdev->wiphy.available_antennas_tx &&
2402 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002403 !rdev->ops->set_antenna)
2404 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002405
2406 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2407 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2408
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002409 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002410 * available antenna masks, except for the "all" mask */
2411 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002412 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2413 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002414
Bruno Randolf7f531e02010-12-16 11:30:22 +09002415 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2416 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002417
Hila Gonene35e4d22012-06-27 17:19:42 +03002418 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002419 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002420 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002421 }
2422
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002423 changed = 0;
2424
2425 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2426 retry_short = nla_get_u8(
2427 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002428 if (retry_short == 0)
2429 return -EINVAL;
2430
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002431 changed |= WIPHY_PARAM_RETRY_SHORT;
2432 }
2433
2434 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2435 retry_long = nla_get_u8(
2436 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002437 if (retry_long == 0)
2438 return -EINVAL;
2439
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002440 changed |= WIPHY_PARAM_RETRY_LONG;
2441 }
2442
2443 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2444 frag_threshold = nla_get_u32(
2445 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002446 if (frag_threshold < 256)
2447 return -EINVAL;
2448
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002449 if (frag_threshold != (u32) -1) {
2450 /*
2451 * Fragments (apart from the last one) are required to
2452 * have even length. Make the fragmentation code
2453 * simpler by stripping LSB should someone try to use
2454 * odd threshold value.
2455 */
2456 frag_threshold &= ~0x1;
2457 }
2458 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2459 }
2460
2461 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2462 rts_threshold = nla_get_u32(
2463 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2464 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2465 }
2466
Lukáš Turek81077e82009-12-21 22:50:47 +01002467 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002468 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2469 return -EINVAL;
2470
Lukáš Turek81077e82009-12-21 22:50:47 +01002471 coverage_class = nla_get_u8(
2472 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2473 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2474 }
2475
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002476 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2477 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2478 return -EOPNOTSUPP;
2479
2480 changed |= WIPHY_PARAM_DYN_ACK;
2481 }
2482
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002483 if (changed) {
2484 u8 old_retry_short, old_retry_long;
2485 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002486 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002487
Ying Xue7f2b8562014-01-15 10:23:45 +08002488 if (!rdev->ops->set_wiphy_params)
2489 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002490
2491 old_retry_short = rdev->wiphy.retry_short;
2492 old_retry_long = rdev->wiphy.retry_long;
2493 old_frag_threshold = rdev->wiphy.frag_threshold;
2494 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002495 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002496
2497 if (changed & WIPHY_PARAM_RETRY_SHORT)
2498 rdev->wiphy.retry_short = retry_short;
2499 if (changed & WIPHY_PARAM_RETRY_LONG)
2500 rdev->wiphy.retry_long = retry_long;
2501 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2502 rdev->wiphy.frag_threshold = frag_threshold;
2503 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2504 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002505 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2506 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002507
Hila Gonene35e4d22012-06-27 17:19:42 +03002508 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002509 if (result) {
2510 rdev->wiphy.retry_short = old_retry_short;
2511 rdev->wiphy.retry_long = old_retry_long;
2512 rdev->wiphy.frag_threshold = old_frag_threshold;
2513 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002514 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002515 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002516 }
2517 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002518 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002519}
2520
Johannes Berg71bbc992012-06-15 15:30:18 +02002521static inline u64 wdev_id(struct wireless_dev *wdev)
2522{
2523 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002524 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002525}
Johannes Berg55682962007-09-20 13:09:35 -04002526
Johannes Berg683b6d32012-11-08 21:25:48 +01002527static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002528 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002529{
Johannes Berg601555c2014-11-27 17:26:56 +01002530 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2531 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002532
Johannes Berg683b6d32012-11-08 21:25:48 +01002533 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2534 chandef->chan->center_freq))
2535 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002536 switch (chandef->width) {
2537 case NL80211_CHAN_WIDTH_20_NOHT:
2538 case NL80211_CHAN_WIDTH_20:
2539 case NL80211_CHAN_WIDTH_40:
2540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2541 cfg80211_get_chandef_type(chandef)))
2542 return -ENOBUFS;
2543 break;
2544 default:
2545 break;
2546 }
2547 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2548 return -ENOBUFS;
2549 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2550 return -ENOBUFS;
2551 if (chandef->center_freq2 &&
2552 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002553 return -ENOBUFS;
2554 return 0;
2555}
2556
Eric W. Biederman15e47302012-09-07 20:12:54 +00002557static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002558 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002559 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002560{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002561 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002562 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002563 void *hdr;
2564
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002565 if (removal)
2566 cmd = NL80211_CMD_DEL_INTERFACE;
2567
2568 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002569 if (!hdr)
2570 return -1;
2571
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002572 if (dev &&
2573 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002574 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002575 goto nla_put_failure;
2576
2577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2578 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002579 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2580 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002581 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002582 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2583 rdev->devlist_generation ^
2584 (cfg80211_rdev_list_generation << 2)))
2585 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002586
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002587 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002588 int ret;
2589 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002590
Johannes Berg683b6d32012-11-08 21:25:48 +01002591 ret = rdev_get_channel(rdev, wdev, &chandef);
2592 if (ret == 0) {
2593 if (nl80211_send_chandef(msg, &chandef))
2594 goto nla_put_failure;
2595 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002596 }
2597
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002598 if (rdev->ops->get_tx_power) {
2599 int dbm, ret;
2600
2601 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2602 if (ret == 0 &&
2603 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2604 DBM_TO_MBM(dbm)))
2605 goto nla_put_failure;
2606 }
2607
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002608 if (wdev->ssid_len) {
2609 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2610 goto nla_put_failure;
2611 }
2612
Johannes Berg053c0952015-01-16 22:09:00 +01002613 genlmsg_end(msg, hdr);
2614 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002615
2616 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002617 genlmsg_cancel(msg, hdr);
2618 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002619}
2620
2621static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2622{
2623 int wp_idx = 0;
2624 int if_idx = 0;
2625 int wp_start = cb->args[0];
2626 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002627 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002628 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002629 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002630 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002631
Johannes Berg5fe231e2013-05-08 21:45:15 +02002632 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002633 if (!cb->args[2]) {
2634 struct nl80211_dump_wiphy_state state = {
2635 .filter_wiphy = -1,
2636 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002637
2638 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2639 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002640 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002641
2642 filter_wiphy = state.filter_wiphy;
2643
2644 /*
2645 * if filtering, set cb->args[2] to +1 since 0 is the default
2646 * value needed to determine that parsing is necessary.
2647 */
2648 if (filter_wiphy >= 0)
2649 cb->args[2] = filter_wiphy + 1;
2650 else
2651 cb->args[2] = -1;
2652 } else if (cb->args[2] > 0) {
2653 filter_wiphy = cb->args[2] - 1;
2654 }
2655
Johannes Bergf5ea9122009-08-07 16:17:38 +02002656 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2657 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002658 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002659 if (wp_idx < wp_start) {
2660 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002661 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002662 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002663
2664 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2665 continue;
2666
Johannes Berg55682962007-09-20 13:09:35 -04002667 if_idx = 0;
2668
Johannes Berg53873f12016-05-03 16:52:04 +03002669 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002670 if (if_idx < if_start) {
2671 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002672 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002673 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002674 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002675 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002676 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002677 goto out;
2678 }
2679 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002680 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002681
2682 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002683 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002684 out:
Johannes Berg55682962007-09-20 13:09:35 -04002685 cb->args[0] = wp_idx;
2686 cb->args[1] = if_idx;
2687
Johannes Bergea90e0d2017-03-15 14:26:04 +01002688 ret = skb->len;
2689 out_unlock:
2690 rtnl_unlock();
2691
2692 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002693}
2694
2695static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2696{
2697 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002699 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002700
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002702 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002703 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002704
Eric W. Biederman15e47302012-09-07 20:12:54 +00002705 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002706 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002707 nlmsg_free(msg);
2708 return -ENOBUFS;
2709 }
Johannes Berg55682962007-09-20 13:09:35 -04002710
Johannes Berg134e6372009-07-10 09:51:34 +00002711 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002712}
2713
Michael Wu66f7ac52008-01-31 19:48:22 +01002714static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2715 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2716 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2717 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2718 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2719 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002720 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002721};
2722
2723static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2724{
2725 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2726 int flag;
2727
2728 *mntrflags = 0;
2729
2730 if (!nla)
2731 return -EINVAL;
2732
Johannes Bergfceb6432017-04-12 14:34:07 +02002733 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2734 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002735 return -EINVAL;
2736
2737 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2738 if (flags[flag])
2739 *mntrflags |= (1<<flag);
2740
Johannes Berg818a9862017-04-12 11:23:28 +02002741 *mntrflags |= MONITOR_FLAG_CHANGED;
2742
Michael Wu66f7ac52008-01-31 19:48:22 +01002743 return 0;
2744}
2745
Johannes Berg1db77592017-04-12 11:36:31 +02002746static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2747 enum nl80211_iftype type,
2748 struct genl_info *info,
2749 struct vif_params *params)
2750{
2751 bool change = false;
2752 int err;
2753
2754 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2755 if (type != NL80211_IFTYPE_MONITOR)
2756 return -EINVAL;
2757
2758 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2759 &params->flags);
2760 if (err)
2761 return err;
2762
2763 change = true;
2764 }
2765
2766 if (params->flags & MONITOR_FLAG_ACTIVE &&
2767 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2768 return -EOPNOTSUPP;
2769
2770 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2771 const u8 *mumimo_groups;
2772 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2773
2774 if (type != NL80211_IFTYPE_MONITOR)
2775 return -EINVAL;
2776
2777 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2778 return -EOPNOTSUPP;
2779
2780 mumimo_groups =
2781 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2782
2783 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002784 if ((mumimo_groups[0] & BIT(0)) ||
2785 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002786 return -EINVAL;
2787
2788 params->vht_mumimo_groups = mumimo_groups;
2789 change = true;
2790 }
2791
2792 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2793 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2794
2795 if (type != NL80211_IFTYPE_MONITOR)
2796 return -EINVAL;
2797
2798 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2799 return -EOPNOTSUPP;
2800
2801 params->vht_mumimo_follow_addr =
2802 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2803 change = true;
2804 }
2805
2806 return change ? 1 : 0;
2807}
2808
Johannes Berg9bc383d2009-11-19 11:55:19 +01002809static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002810 struct net_device *netdev, u8 use_4addr,
2811 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002812{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002813 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002814 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002815 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002816 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002817 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002818
2819 switch (iftype) {
2820 case NL80211_IFTYPE_AP_VLAN:
2821 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2822 return 0;
2823 break;
2824 case NL80211_IFTYPE_STATION:
2825 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2826 return 0;
2827 break;
2828 default:
2829 break;
2830 }
2831
2832 return -EOPNOTSUPP;
2833}
2834
Johannes Berg55682962007-09-20 13:09:35 -04002835static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2836{
Johannes Berg4c476992010-10-04 21:36:35 +02002837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002838 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002839 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002840 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002842 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002843
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002844 memset(&params, 0, sizeof(params));
2845
Johannes Berg04a773a2009-04-19 21:24:32 +02002846 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002847
Johannes Berg723b0382008-09-16 20:22:09 +02002848 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002849 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002850 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002851 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002852 if (ntype > NL80211_IFTYPE_MAX)
2853 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002854 }
2855
Johannes Berg92ffe052008-09-16 20:39:36 +02002856 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002857 struct wireless_dev *wdev = dev->ieee80211_ptr;
2858
Johannes Berg4c476992010-10-04 21:36:35 +02002859 if (ntype != NL80211_IFTYPE_MESH_POINT)
2860 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002861 if (netif_running(dev))
2862 return -EBUSY;
2863
2864 wdev_lock(wdev);
2865 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2866 IEEE80211_MAX_MESH_ID_LEN);
2867 wdev->mesh_id_up_len =
2868 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2869 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2870 wdev->mesh_id_up_len);
2871 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002872 }
2873
Felix Fietkau8b787642009-11-10 18:53:10 +01002874 if (info->attrs[NL80211_ATTR_4ADDR]) {
2875 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2876 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002877 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002878 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002879 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002880 } else {
2881 params.use_4addr = -1;
2882 }
2883
Johannes Berg1db77592017-04-12 11:36:31 +02002884 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2885 if (err < 0)
2886 return err;
2887 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002888 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002889
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002890 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002891 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002892 else
2893 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002894
Johannes Berg9bc383d2009-11-19 11:55:19 +01002895 if (!err && params.use_4addr != -1)
2896 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2897
Johannes Berg55682962007-09-20 13:09:35 -04002898 return err;
2899}
2900
2901static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2902{
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002904 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002905 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002906 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002907 int err;
2908 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2909
Johannes Berg78f22b62014-03-24 17:57:27 +01002910 /* to avoid failing a new interface creation due to pending removal */
2911 cfg80211_destroy_ifaces(rdev);
2912
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002913 memset(&params, 0, sizeof(params));
2914
Johannes Berg55682962007-09-20 13:09:35 -04002915 if (!info->attrs[NL80211_ATTR_IFNAME])
2916 return -EINVAL;
2917
2918 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2919 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2920 if (type > NL80211_IFTYPE_MAX)
2921 return -EINVAL;
2922 }
2923
Johannes Berg79c97e92009-07-07 03:56:12 +02002924 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002925 !(rdev->wiphy.interface_modes & (1 << type)))
2926 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002927
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002928 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002929 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2930 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002931 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2932 ETH_ALEN);
2933 if (!is_valid_ether_addr(params.macaddr))
2934 return -EADDRNOTAVAIL;
2935 }
2936
Johannes Berg9bc383d2009-11-19 11:55:19 +01002937 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002938 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002939 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002940 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002941 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002942 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002943
Johannes Berg1db77592017-04-12 11:36:31 +02002944 err = nl80211_parse_mon_options(rdev, type, info, &params);
2945 if (err < 0)
2946 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002947
Johannes Berga18c7192015-02-24 10:56:42 +01002948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2949 if (!msg)
2950 return -ENOMEM;
2951
Hila Gonene35e4d22012-06-27 17:19:42 +03002952 wdev = rdev_add_virtual_intf(rdev,
2953 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02002954 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002955 if (WARN_ON(!wdev)) {
2956 nlmsg_free(msg);
2957 return -EPROTO;
2958 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002959 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002960 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002961 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002962
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002963 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002964 wdev->owner_nlportid = info->snd_portid;
2965
Johannes Berg98104fde2012-06-16 00:19:54 +02002966 switch (type) {
2967 case NL80211_IFTYPE_MESH_POINT:
2968 if (!info->attrs[NL80211_ATTR_MESH_ID])
2969 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002970 wdev_lock(wdev);
2971 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2972 IEEE80211_MAX_MESH_ID_LEN);
2973 wdev->mesh_id_up_len =
2974 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2975 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2976 wdev->mesh_id_up_len);
2977 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002978 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002979 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002980 case NL80211_IFTYPE_P2P_DEVICE:
2981 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002982 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002983 * through the netdev notifier and must be added here
2984 */
2985 mutex_init(&wdev->mtx);
2986 INIT_LIST_HEAD(&wdev->event_list);
2987 spin_lock_init(&wdev->event_lock);
2988 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2989 spin_lock_init(&wdev->mgmt_registrations_lock);
2990
Johannes Berg98104fde2012-06-16 00:19:54 +02002991 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002992 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002993 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002994 break;
2995 default:
2996 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002997 }
2998
Eric W. Biederman15e47302012-09-07 20:12:54 +00002999 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003000 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003001 nlmsg_free(msg);
3002 return -ENOBUFS;
3003 }
3004
Denis Kenzior896ff062016-08-03 16:58:33 -05003005 /*
3006 * For wdevs which have no associated netdev object (e.g. of type
3007 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3008 * For all other types, the event will be generated from the
3009 * netdev notifier
3010 */
3011 if (!wdev->netdev)
3012 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003013
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003014 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003015}
3016
3017static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3018{
Johannes Berg4c476992010-10-04 21:36:35 +02003019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003020 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003021
Johannes Berg4c476992010-10-04 21:36:35 +02003022 if (!rdev->ops->del_virtual_intf)
3023 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003024
Johannes Berg84efbb82012-06-16 00:00:26 +02003025 /*
3026 * If we remove a wireless device without a netdev then clear
3027 * user_ptr[1] so that nl80211_post_doit won't dereference it
3028 * to check if it needs to do dev_put(). Otherwise it crashes
3029 * since the wdev has been freed, unlike with a netdev where
3030 * we need the dev_put() for the netdev to really be freed.
3031 */
3032 if (!wdev->netdev)
3033 info->user_ptr[1] = NULL;
3034
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003035 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003036}
3037
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003038static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3039{
3040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3041 struct net_device *dev = info->user_ptr[1];
3042 u16 noack_map;
3043
3044 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3045 return -EINVAL;
3046
3047 if (!rdev->ops->set_noack_map)
3048 return -EOPNOTSUPP;
3049
3050 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3051
Hila Gonene35e4d22012-06-27 17:19:42 +03003052 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003053}
3054
Johannes Berg41ade002007-12-19 02:03:29 +01003055struct get_key_cookie {
3056 struct sk_buff *msg;
3057 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003058 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003059};
3060
3061static void get_key_callback(void *c, struct key_params *params)
3062{
Johannes Bergb9454e82009-07-08 13:29:08 +02003063 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003064 struct get_key_cookie *cookie = c;
3065
David S. Miller9360ffd2012-03-29 04:41:26 -04003066 if ((params->key &&
3067 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3068 params->key_len, params->key)) ||
3069 (params->seq &&
3070 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3071 params->seq_len, params->seq)) ||
3072 (params->cipher &&
3073 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3074 params->cipher)))
3075 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003076
Johannes Bergb9454e82009-07-08 13:29:08 +02003077 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3078 if (!key)
3079 goto nla_put_failure;
3080
David S. Miller9360ffd2012-03-29 04:41:26 -04003081 if ((params->key &&
3082 nla_put(cookie->msg, NL80211_KEY_DATA,
3083 params->key_len, params->key)) ||
3084 (params->seq &&
3085 nla_put(cookie->msg, NL80211_KEY_SEQ,
3086 params->seq_len, params->seq)) ||
3087 (params->cipher &&
3088 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3089 params->cipher)))
3090 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003091
David S. Miller9360ffd2012-03-29 04:41:26 -04003092 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3093 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003094
3095 nla_nest_end(cookie->msg, key);
3096
Johannes Berg41ade002007-12-19 02:03:29 +01003097 return;
3098 nla_put_failure:
3099 cookie->error = 1;
3100}
3101
3102static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3103{
Johannes Berg4c476992010-10-04 21:36:35 +02003104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003105 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003106 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003107 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003108 const u8 *mac_addr = NULL;
3109 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003110 struct get_key_cookie cookie = {
3111 .error = 0,
3112 };
3113 void *hdr;
3114 struct sk_buff *msg;
3115
3116 if (info->attrs[NL80211_ATTR_KEY_IDX])
3117 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3118
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003119 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003120 return -EINVAL;
3121
3122 if (info->attrs[NL80211_ATTR_MAC])
3123 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3124
Johannes Berge31b8212010-10-05 19:39:30 +02003125 pairwise = !!mac_addr;
3126 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3127 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003128
Johannes Berge31b8212010-10-05 19:39:30 +02003129 if (kt >= NUM_NL80211_KEYTYPES)
3130 return -EINVAL;
3131 if (kt != NL80211_KEYTYPE_GROUP &&
3132 kt != NL80211_KEYTYPE_PAIRWISE)
3133 return -EINVAL;
3134 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3135 }
3136
Johannes Berg4c476992010-10-04 21:36:35 +02003137 if (!rdev->ops->get_key)
3138 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003139
Johannes Berg0fa7b392015-01-23 11:10:12 +01003140 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3141 return -ENOENT;
3142
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003144 if (!msg)
3145 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003146
Eric W. Biederman15e47302012-09-07 20:12:54 +00003147 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003148 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003149 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003150 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003151
3152 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003153 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003154
David S. Miller9360ffd2012-03-29 04:41:26 -04003155 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3156 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3157 goto nla_put_failure;
3158 if (mac_addr &&
3159 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3160 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003161
Hila Gonene35e4d22012-06-27 17:19:42 +03003162 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3163 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003164
3165 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003166 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003167
3168 if (cookie.error)
3169 goto nla_put_failure;
3170
3171 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003172 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003173
3174 nla_put_failure:
3175 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003176 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003177 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003178 return err;
3179}
3180
3181static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3182{
Johannes Berg4c476992010-10-04 21:36:35 +02003183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003184 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003185 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003186 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003187
Johannes Bergb9454e82009-07-08 13:29:08 +02003188 err = nl80211_parse_key(info, &key);
3189 if (err)
3190 return err;
3191
3192 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003193 return -EINVAL;
3194
Johannes Bergb9454e82009-07-08 13:29:08 +02003195 /* only support setting default key */
3196 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003197 return -EINVAL;
3198
Johannes Bergfffd0932009-07-08 14:22:54 +02003199 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003200
3201 if (key.def) {
3202 if (!rdev->ops->set_default_key) {
3203 err = -EOPNOTSUPP;
3204 goto out;
3205 }
3206
3207 err = nl80211_key_allowed(dev->ieee80211_ptr);
3208 if (err)
3209 goto out;
3210
Hila Gonene35e4d22012-06-27 17:19:42 +03003211 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003212 key.def_uni, key.def_multi);
3213
3214 if (err)
3215 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003216
Johannes Berg3d23e342009-09-29 23:27:28 +02003217#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003218 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003219#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003220 } else {
3221 if (key.def_uni || !key.def_multi) {
3222 err = -EINVAL;
3223 goto out;
3224 }
3225
3226 if (!rdev->ops->set_default_mgmt_key) {
3227 err = -EOPNOTSUPP;
3228 goto out;
3229 }
3230
3231 err = nl80211_key_allowed(dev->ieee80211_ptr);
3232 if (err)
3233 goto out;
3234
Hila Gonene35e4d22012-06-27 17:19:42 +03003235 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003236 if (err)
3237 goto out;
3238
3239#ifdef CONFIG_CFG80211_WEXT
3240 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3241#endif
3242 }
3243
3244 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003245 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003246
Johannes Berg41ade002007-12-19 02:03:29 +01003247 return err;
3248}
3249
3250static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3251{
Johannes Berg4c476992010-10-04 21:36:35 +02003252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003253 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003254 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003255 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003256 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003257
Johannes Bergb9454e82009-07-08 13:29:08 +02003258 err = nl80211_parse_key(info, &key);
3259 if (err)
3260 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003261
Johannes Bergb9454e82009-07-08 13:29:08 +02003262 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003263 return -EINVAL;
3264
Johannes Berg41ade002007-12-19 02:03:29 +01003265 if (info->attrs[NL80211_ATTR_MAC])
3266 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3267
Johannes Berge31b8212010-10-05 19:39:30 +02003268 if (key.type == -1) {
3269 if (mac_addr)
3270 key.type = NL80211_KEYTYPE_PAIRWISE;
3271 else
3272 key.type = NL80211_KEYTYPE_GROUP;
3273 }
3274
3275 /* for now */
3276 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3277 key.type != NL80211_KEYTYPE_GROUP)
3278 return -EINVAL;
3279
Johannes Berg4c476992010-10-04 21:36:35 +02003280 if (!rdev->ops->add_key)
3281 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003282
Johannes Berge31b8212010-10-05 19:39:30 +02003283 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3284 key.type == NL80211_KEYTYPE_PAIRWISE,
3285 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003286 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003287
3288 wdev_lock(dev->ieee80211_ptr);
3289 err = nl80211_key_allowed(dev->ieee80211_ptr);
3290 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003291 err = rdev_add_key(rdev, dev, key.idx,
3292 key.type == NL80211_KEYTYPE_PAIRWISE,
3293 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003294 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003295
Johannes Berg41ade002007-12-19 02:03:29 +01003296 return err;
3297}
3298
3299static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3300{
Johannes Berg4c476992010-10-04 21:36:35 +02003301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003302 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003303 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003304 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003305 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003306
Johannes Bergb9454e82009-07-08 13:29:08 +02003307 err = nl80211_parse_key(info, &key);
3308 if (err)
3309 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003310
3311 if (info->attrs[NL80211_ATTR_MAC])
3312 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3313
Johannes Berge31b8212010-10-05 19:39:30 +02003314 if (key.type == -1) {
3315 if (mac_addr)
3316 key.type = NL80211_KEYTYPE_PAIRWISE;
3317 else
3318 key.type = NL80211_KEYTYPE_GROUP;
3319 }
3320
3321 /* for now */
3322 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3323 key.type != NL80211_KEYTYPE_GROUP)
3324 return -EINVAL;
3325
Johannes Berg4c476992010-10-04 21:36:35 +02003326 if (!rdev->ops->del_key)
3327 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003328
Johannes Bergfffd0932009-07-08 14:22:54 +02003329 wdev_lock(dev->ieee80211_ptr);
3330 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003331
Johannes Berg0fa7b392015-01-23 11:10:12 +01003332 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003333 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3334 err = -ENOENT;
3335
Johannes Bergfffd0932009-07-08 14:22:54 +02003336 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003337 err = rdev_del_key(rdev, dev, key.idx,
3338 key.type == NL80211_KEYTYPE_PAIRWISE,
3339 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003340
Johannes Berg3d23e342009-09-29 23:27:28 +02003341#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003342 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003343 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003344 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003345 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003346 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3347 }
3348#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003349 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003350
Johannes Berg41ade002007-12-19 02:03:29 +01003351 return err;
3352}
3353
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303354/* This function returns an error or the number of nested attributes */
3355static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3356{
3357 struct nlattr *attr;
3358 int n_entries = 0, tmp;
3359
3360 nla_for_each_nested(attr, nl_attr, tmp) {
3361 if (nla_len(attr) != ETH_ALEN)
3362 return -EINVAL;
3363
3364 n_entries++;
3365 }
3366
3367 return n_entries;
3368}
3369
3370/*
3371 * This function parses ACL information and allocates memory for ACL data.
3372 * On successful return, the calling function is responsible to free the
3373 * ACL buffer returned by this function.
3374 */
3375static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3376 struct genl_info *info)
3377{
3378 enum nl80211_acl_policy acl_policy;
3379 struct nlattr *attr;
3380 struct cfg80211_acl_data *acl;
3381 int i = 0, n_entries, tmp;
3382
3383 if (!wiphy->max_acl_mac_addrs)
3384 return ERR_PTR(-EOPNOTSUPP);
3385
3386 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3387 return ERR_PTR(-EINVAL);
3388
3389 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3390 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3391 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3392 return ERR_PTR(-EINVAL);
3393
3394 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3395 return ERR_PTR(-EINVAL);
3396
3397 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3398 if (n_entries < 0)
3399 return ERR_PTR(n_entries);
3400
3401 if (n_entries > wiphy->max_acl_mac_addrs)
3402 return ERR_PTR(-ENOTSUPP);
3403
3404 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3405 GFP_KERNEL);
3406 if (!acl)
3407 return ERR_PTR(-ENOMEM);
3408
3409 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3410 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3411 i++;
3412 }
3413
3414 acl->n_acl_entries = n_entries;
3415 acl->acl_policy = acl_policy;
3416
3417 return acl;
3418}
3419
3420static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3421{
3422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3423 struct net_device *dev = info->user_ptr[1];
3424 struct cfg80211_acl_data *acl;
3425 int err;
3426
3427 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3428 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3429 return -EOPNOTSUPP;
3430
3431 if (!dev->ieee80211_ptr->beacon_interval)
3432 return -EINVAL;
3433
3434 acl = parse_acl_data(&rdev->wiphy, info);
3435 if (IS_ERR(acl))
3436 return PTR_ERR(acl);
3437
3438 err = rdev_set_mac_acl(rdev, dev, acl);
3439
3440 kfree(acl);
3441
3442 return err;
3443}
3444
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303445static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3446 u8 *rates, u8 rates_len)
3447{
3448 u8 i;
3449 u32 mask = 0;
3450
3451 for (i = 0; i < rates_len; i++) {
3452 int rate = (rates[i] & 0x7f) * 5;
3453 int ridx;
3454
3455 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3456 struct ieee80211_rate *srate =
3457 &sband->bitrates[ridx];
3458 if (rate == srate->bitrate) {
3459 mask |= 1 << ridx;
3460 break;
3461 }
3462 }
3463 if (ridx == sband->n_bitrates)
3464 return 0; /* rate not found */
3465 }
3466
3467 return mask;
3468}
3469
3470static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3471 u8 *rates, u8 rates_len,
3472 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3473{
3474 u8 i;
3475
3476 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3477
3478 for (i = 0; i < rates_len; i++) {
3479 int ridx, rbit;
3480
3481 ridx = rates[i] / 8;
3482 rbit = BIT(rates[i] % 8);
3483
3484 /* check validity */
3485 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3486 return false;
3487
3488 /* check availability */
3489 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3490 mcs[ridx] |= rbit;
3491 else
3492 return false;
3493 }
3494
3495 return true;
3496}
3497
3498static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3499{
3500 u16 mcs_mask = 0;
3501
3502 switch (vht_mcs_map) {
3503 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3504 break;
3505 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3506 mcs_mask = 0x00FF;
3507 break;
3508 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3509 mcs_mask = 0x01FF;
3510 break;
3511 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3512 mcs_mask = 0x03FF;
3513 break;
3514 default:
3515 break;
3516 }
3517
3518 return mcs_mask;
3519}
3520
3521static void vht_build_mcs_mask(u16 vht_mcs_map,
3522 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3523{
3524 u8 nss;
3525
3526 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3527 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3528 vht_mcs_map >>= 2;
3529 }
3530}
3531
3532static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3533 struct nl80211_txrate_vht *txrate,
3534 u16 mcs[NL80211_VHT_NSS_MAX])
3535{
3536 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3537 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3538 u8 i;
3539
3540 if (!sband->vht_cap.vht_supported)
3541 return false;
3542
3543 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3544
3545 /* Build vht_mcs_mask from VHT capabilities */
3546 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3547
3548 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3549 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3550 mcs[i] = txrate->mcs[i];
3551 else
3552 return false;
3553 }
3554
3555 return true;
3556}
3557
3558static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3559 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3560 .len = NL80211_MAX_SUPP_RATES },
3561 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3562 .len = NL80211_MAX_SUPP_HT_RATES },
3563 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3564 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3565};
3566
3567static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3568 struct cfg80211_bitrate_mask *mask)
3569{
3570 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3572 int rem, i;
3573 struct nlattr *tx_rates;
3574 struct ieee80211_supported_band *sband;
3575 u16 vht_tx_mcs_map;
3576
3577 memset(mask, 0, sizeof(*mask));
3578 /* Default to all rates enabled */
3579 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3580 sband = rdev->wiphy.bands[i];
3581
3582 if (!sband)
3583 continue;
3584
3585 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3586 memcpy(mask->control[i].ht_mcs,
3587 sband->ht_cap.mcs.rx_mask,
3588 sizeof(mask->control[i].ht_mcs));
3589
3590 if (!sband->vht_cap.vht_supported)
3591 continue;
3592
3593 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3594 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3595 }
3596
3597 /* if no rates are given set it back to the defaults */
3598 if (!info->attrs[NL80211_ATTR_TX_RATES])
3599 goto out;
3600
3601 /* The nested attribute uses enum nl80211_band as the index. This maps
3602 * directly to the enum nl80211_band values used in cfg80211.
3603 */
3604 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3605 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3606 enum nl80211_band band = nla_type(tx_rates);
3607 int err;
3608
3609 if (band < 0 || band >= NUM_NL80211_BANDS)
3610 return -EINVAL;
3611 sband = rdev->wiphy.bands[band];
3612 if (sband == NULL)
3613 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003614 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003615 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303616 if (err)
3617 return err;
3618 if (tb[NL80211_TXRATE_LEGACY]) {
3619 mask->control[band].legacy = rateset_to_mask(
3620 sband,
3621 nla_data(tb[NL80211_TXRATE_LEGACY]),
3622 nla_len(tb[NL80211_TXRATE_LEGACY]));
3623 if ((mask->control[band].legacy == 0) &&
3624 nla_len(tb[NL80211_TXRATE_LEGACY]))
3625 return -EINVAL;
3626 }
3627 if (tb[NL80211_TXRATE_HT]) {
3628 if (!ht_rateset_to_mask(
3629 sband,
3630 nla_data(tb[NL80211_TXRATE_HT]),
3631 nla_len(tb[NL80211_TXRATE_HT]),
3632 mask->control[band].ht_mcs))
3633 return -EINVAL;
3634 }
3635 if (tb[NL80211_TXRATE_VHT]) {
3636 if (!vht_set_mcs_mask(
3637 sband,
3638 nla_data(tb[NL80211_TXRATE_VHT]),
3639 mask->control[band].vht_mcs))
3640 return -EINVAL;
3641 }
3642 if (tb[NL80211_TXRATE_GI]) {
3643 mask->control[band].gi =
3644 nla_get_u8(tb[NL80211_TXRATE_GI]);
3645 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3646 return -EINVAL;
3647 }
3648
3649 if (mask->control[band].legacy == 0) {
3650 /* don't allow empty legacy rates if HT or VHT
3651 * are not even supported.
3652 */
3653 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3654 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3655 return -EINVAL;
3656
3657 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3658 if (mask->control[band].ht_mcs[i])
3659 goto out;
3660
3661 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3662 if (mask->control[band].vht_mcs[i])
3663 goto out;
3664
3665 /* legacy and mcs rates may not be both empty */
3666 return -EINVAL;
3667 }
3668 }
3669
3670out:
3671 return 0;
3672}
3673
Johannes Berg8564e382016-09-19 09:44:44 +02003674static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3675 enum nl80211_band band,
3676 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303677{
Johannes Berg8564e382016-09-19 09:44:44 +02003678 u32 count_ht, count_vht, i;
3679 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303680
3681 /* Allow only one rate */
3682 if (hweight32(rate) > 1)
3683 return -EINVAL;
3684
3685 count_ht = 0;
3686 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003687 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303688 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003689 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303690 count_ht++;
3691 if (count_ht > 1)
3692 return -EINVAL;
3693 }
3694 if (count_ht && rate)
3695 return -EINVAL;
3696 }
3697
3698 count_vht = 0;
3699 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003700 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303701 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003702 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303703 count_vht++;
3704 if (count_vht > 1)
3705 return -EINVAL;
3706 }
3707 if (count_vht && rate)
3708 return -EINVAL;
3709 }
3710
3711 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3712 return -EINVAL;
3713
Johannes Berg8564e382016-09-19 09:44:44 +02003714 if (rate &&
3715 !wiphy_ext_feature_isset(&rdev->wiphy,
3716 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3717 return -EINVAL;
3718 if (count_ht &&
3719 !wiphy_ext_feature_isset(&rdev->wiphy,
3720 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3721 return -EINVAL;
3722 if (count_vht &&
3723 !wiphy_ext_feature_isset(&rdev->wiphy,
3724 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3725 return -EINVAL;
3726
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303727 return 0;
3728}
3729
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003730static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003731 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003732{
Johannes Berg88600202012-02-13 15:17:18 +01003733 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003734
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003735 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3736 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3737 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3738 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003739 return -EINVAL;
3740
Johannes Berg88600202012-02-13 15:17:18 +01003741 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003742
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003743 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3744 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3745 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003746 if (!bcn->head_len)
3747 return -EINVAL;
3748 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003749 }
3750
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003751 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3752 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3753 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003754 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003755 }
3756
Johannes Berg4c476992010-10-04 21:36:35 +02003757 if (!haveinfo)
3758 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003759
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003760 if (attrs[NL80211_ATTR_IE]) {
3761 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3762 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003763 }
3764
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003765 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003766 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003767 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003768 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003769 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003770 }
3771
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003772 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003773 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003774 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003775 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003776 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003777 }
3778
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003779 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3780 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3781 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003782 }
3783
Johannes Berg88600202012-02-13 15:17:18 +01003784 return 0;
3785}
3786
Johannes Berg66cd7942017-02-07 22:40:44 +02003787static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3788 const u8 *rates)
3789{
3790 int i;
3791
3792 if (!rates)
3793 return;
3794
3795 for (i = 0; i < rates[1]; i++) {
3796 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3797 params->ht_required = true;
3798 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3799 params->vht_required = true;
3800 }
3801}
3802
3803/*
3804 * Since the nl80211 API didn't include, from the beginning, attributes about
3805 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3806 * benefit of drivers that rebuild IEs in the firmware.
3807 */
3808static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3809{
3810 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07003811 size_t ies_len = bcn->tail_len;
3812 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02003813 const u8 *rates;
3814 const u8 *cap;
3815
3816 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3817 nl80211_check_ap_rate_selectors(params, rates);
3818
3819 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3820 nl80211_check_ap_rate_selectors(params, rates);
3821
3822 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3823 if (cap && cap[1] >= sizeof(*params->ht_cap))
3824 params->ht_cap = (void *)(cap + 2);
3825 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3826 if (cap && cap[1] >= sizeof(*params->vht_cap))
3827 params->vht_cap = (void *)(cap + 2);
3828}
3829
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003830static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3831 struct cfg80211_ap_settings *params)
3832{
3833 struct wireless_dev *wdev;
3834 bool ret = false;
3835
Johannes Berg53873f12016-05-03 16:52:04 +03003836 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003837 if (wdev->iftype != NL80211_IFTYPE_AP &&
3838 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3839 continue;
3840
Johannes Berg683b6d32012-11-08 21:25:48 +01003841 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003842 continue;
3843
Johannes Berg683b6d32012-11-08 21:25:48 +01003844 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003845 ret = true;
3846 break;
3847 }
3848
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003849 return ret;
3850}
3851
Jouni Malinene39e5b52012-09-30 19:29:39 +03003852static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3853 enum nl80211_auth_type auth_type,
3854 enum nl80211_commands cmd)
3855{
3856 if (auth_type > NL80211_AUTHTYPE_MAX)
3857 return false;
3858
3859 switch (cmd) {
3860 case NL80211_CMD_AUTHENTICATE:
3861 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3862 auth_type == NL80211_AUTHTYPE_SAE)
3863 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003864 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3865 NL80211_EXT_FEATURE_FILS_STA) &&
3866 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3867 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3868 auth_type == NL80211_AUTHTYPE_FILS_PK))
3869 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003870 return true;
3871 case NL80211_CMD_CONNECT:
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003872 /* SAE not supported yet */
3873 if (auth_type == NL80211_AUTHTYPE_SAE)
3874 return false;
3875 /* FILS with SK PFS or PK not supported yet */
3876 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3877 auth_type == NL80211_AUTHTYPE_FILS_PK)
3878 return false;
3879 if (!wiphy_ext_feature_isset(
3880 &rdev->wiphy,
3881 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3882 auth_type == NL80211_AUTHTYPE_FILS_SK)
3883 return false;
3884 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003885 case NL80211_CMD_START_AP:
3886 /* SAE not supported yet */
3887 if (auth_type == NL80211_AUTHTYPE_SAE)
3888 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003889 /* FILS not supported yet */
3890 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3891 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3892 auth_type == NL80211_AUTHTYPE_FILS_PK)
3893 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003894 return true;
3895 default:
3896 return false;
3897 }
3898}
3899
Johannes Berg88600202012-02-13 15:17:18 +01003900static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3901{
3902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3903 struct net_device *dev = info->user_ptr[1];
3904 struct wireless_dev *wdev = dev->ieee80211_ptr;
3905 struct cfg80211_ap_settings params;
3906 int err;
3907
3908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3909 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3910 return -EOPNOTSUPP;
3911
3912 if (!rdev->ops->start_ap)
3913 return -EOPNOTSUPP;
3914
3915 if (wdev->beacon_interval)
3916 return -EALREADY;
3917
3918 memset(&params, 0, sizeof(params));
3919
3920 /* these are required for START_AP */
3921 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3922 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3923 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3924 return -EINVAL;
3925
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003926 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003927 if (err)
3928 return err;
3929
3930 params.beacon_interval =
3931 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3932 params.dtim_period =
3933 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3934
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303935 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3936 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003937 if (err)
3938 return err;
3939
3940 /*
3941 * In theory, some of these attributes should be required here
3942 * but since they were not used when the command was originally
3943 * added, keep them optional for old user space programs to let
3944 * them continue to work with drivers that do not need the
3945 * additional information -- drivers must check!
3946 */
3947 if (info->attrs[NL80211_ATTR_SSID]) {
3948 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3949 params.ssid_len =
3950 nla_len(info->attrs[NL80211_ATTR_SSID]);
3951 if (params.ssid_len == 0 ||
3952 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3953 return -EINVAL;
3954 }
3955
3956 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3957 params.hidden_ssid = nla_get_u32(
3958 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3959 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3960 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3961 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3962 return -EINVAL;
3963 }
3964
3965 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3966
3967 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3968 params.auth_type = nla_get_u32(
3969 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003970 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3971 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003972 return -EINVAL;
3973 } else
3974 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3975
3976 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3977 NL80211_MAX_NR_CIPHER_SUITES);
3978 if (err)
3979 return err;
3980
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303981 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3982 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3983 return -EOPNOTSUPP;
3984 params.inactivity_timeout = nla_get_u16(
3985 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3986 }
3987
Johannes Berg53cabad2012-11-14 15:17:28 +01003988 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3989 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3990 return -EINVAL;
3991 params.p2p_ctwindow =
3992 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3993 if (params.p2p_ctwindow > 127)
3994 return -EINVAL;
3995 if (params.p2p_ctwindow != 0 &&
3996 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3997 return -EINVAL;
3998 }
3999
4000 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4001 u8 tmp;
4002
4003 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4004 return -EINVAL;
4005 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4006 if (tmp > 1)
4007 return -EINVAL;
4008 params.p2p_opp_ps = tmp;
4009 if (params.p2p_opp_ps != 0 &&
4010 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4011 return -EINVAL;
4012 }
4013
Johannes Bergaa430da2012-05-16 23:50:18 +02004014 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004015 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4016 if (err)
4017 return err;
4018 } else if (wdev->preset_chandef.chan) {
4019 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004020 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004021 return -EINVAL;
4022
Arik Nemtsov923b3522015-07-08 15:41:44 +03004023 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4024 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004025 return -EINVAL;
4026
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304027 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4028 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4029 if (err)
4030 return err;
4031
Johannes Berg8564e382016-09-19 09:44:44 +02004032 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4033 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304034 if (err)
4035 return err;
4036 }
4037
Eliad Peller18998c32014-09-10 14:07:34 +03004038 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4039 params.smps_mode =
4040 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4041 switch (params.smps_mode) {
4042 case NL80211_SMPS_OFF:
4043 break;
4044 case NL80211_SMPS_STATIC:
4045 if (!(rdev->wiphy.features &
4046 NL80211_FEATURE_STATIC_SMPS))
4047 return -EINVAL;
4048 break;
4049 case NL80211_SMPS_DYNAMIC:
4050 if (!(rdev->wiphy.features &
4051 NL80211_FEATURE_DYNAMIC_SMPS))
4052 return -EINVAL;
4053 break;
4054 default:
4055 return -EINVAL;
4056 }
4057 } else {
4058 params.smps_mode = NL80211_SMPS_OFF;
4059 }
4060
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304061 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4062 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4063 return -EOPNOTSUPP;
4064
Ola Olsson4baf6be2015-10-29 07:04:58 +01004065 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4066 params.acl = parse_acl_data(&rdev->wiphy, info);
4067 if (IS_ERR(params.acl))
4068 return PTR_ERR(params.acl);
4069 }
4070
Johannes Berg66cd7942017-02-07 22:40:44 +02004071 nl80211_calculate_ap_params(&params);
4072
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004073 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004074 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004075 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004076 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004077 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004078 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004079 wdev->ssid_len = params.ssid_len;
4080 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004081 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004082 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304083
4084 kfree(params.acl);
4085
Johannes Berg56d18932011-05-09 18:41:15 +02004086 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004087}
4088
Johannes Berg88600202012-02-13 15:17:18 +01004089static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4090{
4091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4092 struct net_device *dev = info->user_ptr[1];
4093 struct wireless_dev *wdev = dev->ieee80211_ptr;
4094 struct cfg80211_beacon_data params;
4095 int err;
4096
4097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4099 return -EOPNOTSUPP;
4100
4101 if (!rdev->ops->change_beacon)
4102 return -EOPNOTSUPP;
4103
4104 if (!wdev->beacon_interval)
4105 return -EINVAL;
4106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004107 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004108 if (err)
4109 return err;
4110
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004111 wdev_lock(wdev);
4112 err = rdev_change_beacon(rdev, dev, &params);
4113 wdev_unlock(wdev);
4114
4115 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004116}
4117
4118static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004119{
Johannes Berg4c476992010-10-04 21:36:35 +02004120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4121 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004122
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004123 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004124}
4125
Johannes Berg5727ef12007-12-19 02:03:34 +01004126static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4127 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4128 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4129 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004130 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004131 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004132 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004133};
4134
Johannes Bergeccb8e82009-05-11 21:57:56 +03004135static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004136 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004137 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004138{
4139 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004140 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004141 int flag;
4142
Johannes Bergeccb8e82009-05-11 21:57:56 +03004143 /*
4144 * Try parsing the new attribute first so userspace
4145 * can specify both for older kernels.
4146 */
4147 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4148 if (nla) {
4149 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004150
Johannes Bergeccb8e82009-05-11 21:57:56 +03004151 sta_flags = nla_data(nla);
4152 params->sta_flags_mask = sta_flags->mask;
4153 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004154 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004155 if ((params->sta_flags_mask |
4156 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4157 return -EINVAL;
4158 return 0;
4159 }
4160
4161 /* if present, parse the old attribute */
4162
4163 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004164 if (!nla)
4165 return 0;
4166
Johannes Bergfceb6432017-04-12 14:34:07 +02004167 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004168 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004169 return -EINVAL;
4170
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004171 /*
4172 * Only allow certain flags for interface types so that
4173 * other attributes are silently ignored. Remember that
4174 * this is backward compatibility code with old userspace
4175 * and shouldn't be hit in other cases anyway.
4176 */
4177 switch (iftype) {
4178 case NL80211_IFTYPE_AP:
4179 case NL80211_IFTYPE_AP_VLAN:
4180 case NL80211_IFTYPE_P2P_GO:
4181 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4182 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4183 BIT(NL80211_STA_FLAG_WME) |
4184 BIT(NL80211_STA_FLAG_MFP);
4185 break;
4186 case NL80211_IFTYPE_P2P_CLIENT:
4187 case NL80211_IFTYPE_STATION:
4188 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4189 BIT(NL80211_STA_FLAG_TDLS_PEER);
4190 break;
4191 case NL80211_IFTYPE_MESH_POINT:
4192 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4193 BIT(NL80211_STA_FLAG_MFP) |
4194 BIT(NL80211_STA_FLAG_AUTHORIZED);
4195 default:
4196 return -EINVAL;
4197 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004198
Johannes Berg3383b5a2012-05-10 20:14:43 +02004199 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4200 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004201 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004202
Johannes Berg3383b5a2012-05-10 20:14:43 +02004203 /* no longer support new API additions in old API */
4204 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4205 return -EINVAL;
4206 }
4207 }
4208
Johannes Berg5727ef12007-12-19 02:03:34 +01004209 return 0;
4210}
4211
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004212static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4213 int attr)
4214{
4215 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004216 u32 bitrate;
4217 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004218 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004219
4220 rate = nla_nest_start(msg, attr);
4221 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004222 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004223
4224 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4225 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004226 /* report 16-bit bitrate only if we can */
4227 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004228 if (bitrate > 0 &&
4229 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4230 return false;
4231 if (bitrate_compat > 0 &&
4232 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4233 return false;
4234
Johannes Bergb51f3be2015-01-15 16:14:02 +01004235 switch (info->bw) {
4236 case RATE_INFO_BW_5:
4237 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4238 break;
4239 case RATE_INFO_BW_10:
4240 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4241 break;
4242 default:
4243 WARN_ON(1);
4244 /* fall through */
4245 case RATE_INFO_BW_20:
4246 rate_flg = 0;
4247 break;
4248 case RATE_INFO_BW_40:
4249 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4250 break;
4251 case RATE_INFO_BW_80:
4252 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4253 break;
4254 case RATE_INFO_BW_160:
4255 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4256 break;
4257 }
4258
4259 if (rate_flg && nla_put_flag(msg, rate_flg))
4260 return false;
4261
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004262 if (info->flags & RATE_INFO_FLAGS_MCS) {
4263 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4264 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004265 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4266 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4267 return false;
4268 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4269 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4270 return false;
4271 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4272 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004273 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4274 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4275 return false;
4276 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004277
4278 nla_nest_end(msg, rate);
4279 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004280}
4281
Felix Fietkau119363c2013-04-22 16:29:30 +02004282static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4283 int id)
4284{
4285 void *attr;
4286 int i = 0;
4287
4288 if (!mask)
4289 return true;
4290
4291 attr = nla_nest_start(msg, id);
4292 if (!attr)
4293 return false;
4294
4295 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4296 if (!(mask & BIT(i)))
4297 continue;
4298
4299 if (nla_put_u8(msg, i, signal[i]))
4300 return false;
4301 }
4302
4303 nla_nest_end(msg, attr);
4304
4305 return true;
4306}
4307
Johannes Bergcf5ead82014-11-14 17:14:00 +01004308static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4309 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004310 struct cfg80211_registered_device *rdev,
4311 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004312 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004313{
4314 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004315 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004316
Johannes Bergcf5ead82014-11-14 17:14:00 +01004317 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004318 if (!hdr)
4319 return -1;
4320
David S. Miller9360ffd2012-03-29 04:41:26 -04004321 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4322 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4323 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4324 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004325
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004326 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4327 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004328 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004329
4330#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004331 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304332 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004333 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4334 sinfo->memb)) \
4335 goto nla_put_failure; \
4336 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004337#define PUT_SINFO_U64(attr, memb) do { \
4338 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4339 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4340 sinfo->memb, NL80211_STA_INFO_PAD)) \
4341 goto nla_put_failure; \
4342 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004343
4344 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4345 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4346
4347 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4348 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004349 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004350 (u32)sinfo->rx_bytes))
4351 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004352
4353 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4354 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004355 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4356 (u32)sinfo->tx_bytes))
4357 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004358
Johannes Bergd686b922016-04-26 09:54:11 +02004359 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4360 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004361 PUT_SINFO(LLID, llid, u16);
4362 PUT_SINFO(PLID, plid, u16);
4363 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004364 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004365
John W. Linville66266b32012-03-15 13:25:41 -04004366 switch (rdev->wiphy.signal_type) {
4367 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004368 PUT_SINFO(SIGNAL, signal, u8);
4369 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004370 break;
4371 default:
4372 break;
4373 }
Johannes Berg319090b2014-11-17 14:08:11 +01004374 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004375 if (!nl80211_put_signal(msg, sinfo->chains,
4376 sinfo->chain_signal,
4377 NL80211_STA_INFO_CHAIN_SIGNAL))
4378 goto nla_put_failure;
4379 }
Johannes Berg319090b2014-11-17 14:08:11 +01004380 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004381 if (!nl80211_put_signal(msg, sinfo->chains,
4382 sinfo->chain_signal_avg,
4383 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4384 goto nla_put_failure;
4385 }
Johannes Berg319090b2014-11-17 14:08:11 +01004386 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004387 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4388 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004389 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004390 }
Johannes Berg319090b2014-11-17 14:08:11 +01004391 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004392 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4393 NL80211_STA_INFO_RX_BITRATE))
4394 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004395 }
Johannes Berg319090b2014-11-17 14:08:11 +01004396
4397 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4398 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4399 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4400 PUT_SINFO(TX_FAILED, tx_failed, u32);
4401 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4402 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4403 PUT_SINFO(LOCAL_PM, local_pm, u32);
4404 PUT_SINFO(PEER_PM, peer_pm, u32);
4405 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4406
4407 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004408 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4409 if (!bss_param)
4410 goto nla_put_failure;
4411
David S. Miller9360ffd2012-03-29 04:41:26 -04004412 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4413 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4414 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4415 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4416 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4417 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4418 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4419 sinfo->bss_param.dtim_period) ||
4420 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4421 sinfo->bss_param.beacon_interval))
4422 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004423
4424 nla_nest_end(msg, bss_param);
4425 }
Johannes Berg319090b2014-11-17 14:08:11 +01004426 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004427 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4428 sizeof(struct nl80211_sta_flag_update),
4429 &sinfo->sta_flags))
4430 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004431
Johannes Bergd686b922016-04-26 09:54:11 +02004432 PUT_SINFO_U64(T_OFFSET, t_offset);
4433 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4434 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004435 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004436
4437#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004438#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004439
4440 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4441 struct nlattr *tidsattr;
4442 int tid;
4443
4444 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4445 if (!tidsattr)
4446 goto nla_put_failure;
4447
4448 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4449 struct cfg80211_tid_stats *tidstats;
4450 struct nlattr *tidattr;
4451
4452 tidstats = &sinfo->pertid[tid];
4453
4454 if (!tidstats->filled)
4455 continue;
4456
4457 tidattr = nla_nest_start(msg, tid + 1);
4458 if (!tidattr)
4459 goto nla_put_failure;
4460
Johannes Bergd686b922016-04-26 09:54:11 +02004461#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004462 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004463 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4464 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004465 goto nla_put_failure; \
4466 } while (0)
4467
Johannes Bergd686b922016-04-26 09:54:11 +02004468 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4469 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4470 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4471 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004472
Johannes Bergd686b922016-04-26 09:54:11 +02004473#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004474 nla_nest_end(msg, tidattr);
4475 }
4476
4477 nla_nest_end(msg, tidsattr);
4478 }
4479
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004480 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004481
Johannes Berg319090b2014-11-17 14:08:11 +01004482 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004483 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4484 sinfo->assoc_req_ies))
4485 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004486
Johannes Berg053c0952015-01-16 22:09:00 +01004487 genlmsg_end(msg, hdr);
4488 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004489
4490 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004491 genlmsg_cancel(msg, hdr);
4492 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004493}
4494
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004496 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004497{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004498 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004499 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004500 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004501 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004502 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504
Johannes Bergea90e0d2017-03-15 14:26:04 +01004505 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004506 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004507 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004508 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004509
Johannes Berg97990a02013-04-19 01:02:55 +02004510 if (!wdev->netdev) {
4511 err = -EINVAL;
4512 goto out_err;
4513 }
4514
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004515 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004516 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004517 goto out_err;
4518 }
4519
Johannes Bergbba95fe2008-07-29 13:22:51 +02004520 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004521 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004522 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004523 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004524 if (err == -ENOENT)
4525 break;
4526 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004527 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004528
Johannes Bergcf5ead82014-11-14 17:14:00 +01004529 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004530 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004531 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004532 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533 &sinfo) < 0)
4534 goto out;
4535
4536 sta_idx++;
4537 }
4538
Johannes Bergbba95fe2008-07-29 13:22:51 +02004539 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004540 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004541 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004542 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004543 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004544
4545 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004546}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004547
Johannes Berg5727ef12007-12-19 02:03:34 +01004548static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4549{
Johannes Berg4c476992010-10-04 21:36:35 +02004550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4551 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004552 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004553 struct sk_buff *msg;
4554 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004555 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004556
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004558
4559 if (!info->attrs[NL80211_ATTR_MAC])
4560 return -EINVAL;
4561
4562 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4563
Johannes Berg4c476992010-10-04 21:36:35 +02004564 if (!rdev->ops->get_station)
4565 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004566
Hila Gonene35e4d22012-06-27 17:19:42 +03004567 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004568 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004569 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004570
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004572 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004573 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004574
Johannes Bergcf5ead82014-11-14 17:14:00 +01004575 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4576 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004577 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004578 nlmsg_free(msg);
4579 return -ENOBUFS;
4580 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004581
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004583}
4584
Johannes Berg77ee7c82013-02-15 00:48:33 +01004585int cfg80211_check_station_change(struct wiphy *wiphy,
4586 struct station_parameters *params,
4587 enum cfg80211_station_type statype)
4588{
Ayala Bekere4208422015-10-23 11:20:06 +03004589 if (params->listen_interval != -1 &&
4590 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004591 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004592
Ayala Beker17b94242016-03-17 15:41:38 +02004593 if (params->support_p2p_ps != -1 &&
4594 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4595 return -EINVAL;
4596
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004597 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004598 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4599 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004600 return -EINVAL;
4601
4602 /* When you run into this, adjust the code below for the new flag */
4603 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4604
4605 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004606 case CFG80211_STA_MESH_PEER_KERNEL:
4607 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004608 /*
4609 * No ignoring the TDLS flag here -- the userspace mesh
4610 * code doesn't have the bug of including TDLS in the
4611 * mask everywhere.
4612 */
4613 if (params->sta_flags_mask &
4614 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4615 BIT(NL80211_STA_FLAG_MFP) |
4616 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4617 return -EINVAL;
4618 break;
4619 case CFG80211_STA_TDLS_PEER_SETUP:
4620 case CFG80211_STA_TDLS_PEER_ACTIVE:
4621 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4622 return -EINVAL;
4623 /* ignore since it can't change */
4624 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4625 break;
4626 default:
4627 /* disallow mesh-specific things */
4628 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4629 return -EINVAL;
4630 if (params->local_pm)
4631 return -EINVAL;
4632 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4633 return -EINVAL;
4634 }
4635
4636 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4637 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4638 /* TDLS can't be set, ... */
4639 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4640 return -EINVAL;
4641 /*
4642 * ... but don't bother the driver with it. This works around
4643 * a hostapd/wpa_supplicant issue -- it always includes the
4644 * TLDS_PEER flag in the mask even for AP mode.
4645 */
4646 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4647 }
4648
Ayala Beker47edb112015-09-21 15:49:53 +03004649 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4650 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004651 /* reject other things that can't change */
4652 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4653 return -EINVAL;
4654 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4655 return -EINVAL;
4656 if (params->supported_rates)
4657 return -EINVAL;
4658 if (params->ext_capab || params->ht_capa || params->vht_capa)
4659 return -EINVAL;
4660 }
4661
Ayala Beker47edb112015-09-21 15:49:53 +03004662 if (statype != CFG80211_STA_AP_CLIENT &&
4663 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004664 if (params->vlan)
4665 return -EINVAL;
4666 }
4667
4668 switch (statype) {
4669 case CFG80211_STA_AP_MLME_CLIENT:
4670 /* Use this only for authorizing/unauthorizing a station */
4671 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4672 return -EOPNOTSUPP;
4673 break;
4674 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004675 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004676 /* accept only the listed bits */
4677 if (params->sta_flags_mask &
4678 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4679 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4680 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4681 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4682 BIT(NL80211_STA_FLAG_WME) |
4683 BIT(NL80211_STA_FLAG_MFP)))
4684 return -EINVAL;
4685
4686 /* but authenticated/associated only if driver handles it */
4687 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4688 params->sta_flags_mask &
4689 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4690 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4691 return -EINVAL;
4692 break;
4693 case CFG80211_STA_IBSS:
4694 case CFG80211_STA_AP_STA:
4695 /* reject any changes other than AUTHORIZED */
4696 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4697 return -EINVAL;
4698 break;
4699 case CFG80211_STA_TDLS_PEER_SETUP:
4700 /* reject any changes other than AUTHORIZED or WME */
4701 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4702 BIT(NL80211_STA_FLAG_WME)))
4703 return -EINVAL;
4704 /* force (at least) rates when authorizing */
4705 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4706 !params->supported_rates)
4707 return -EINVAL;
4708 break;
4709 case CFG80211_STA_TDLS_PEER_ACTIVE:
4710 /* reject any changes */
4711 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004712 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004713 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4714 return -EINVAL;
4715 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004716 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004717 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4718 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004719 return -EINVAL;
4720 break;
4721 }
4722
Beni Lev06f7c882016-07-19 19:28:56 +03004723 /*
4724 * Older kernel versions ignored this attribute entirely, so don't
4725 * reject attempts to update it but mark it as unused instead so the
4726 * driver won't look at the data.
4727 */
4728 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4729 statype != CFG80211_STA_TDLS_PEER_SETUP)
4730 params->opmode_notif_used = false;
4731
Johannes Berg77ee7c82013-02-15 00:48:33 +01004732 return 0;
4733}
4734EXPORT_SYMBOL(cfg80211_check_station_change);
4735
Johannes Berg5727ef12007-12-19 02:03:34 +01004736/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004737 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004738 */
Johannes Berg80b99892011-11-18 16:23:01 +01004739static struct net_device *get_vlan(struct genl_info *info,
4740 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004741{
Johannes Berg463d0182009-07-14 00:33:35 +02004742 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004743 struct net_device *v;
4744 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004745
Johannes Berg80b99892011-11-18 16:23:01 +01004746 if (!vlanattr)
4747 return NULL;
4748
4749 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4750 if (!v)
4751 return ERR_PTR(-ENODEV);
4752
4753 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4754 ret = -EINVAL;
4755 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004756 }
Johannes Berg80b99892011-11-18 16:23:01 +01004757
Johannes Berg77ee7c82013-02-15 00:48:33 +01004758 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4759 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4761 ret = -EINVAL;
4762 goto error;
4763 }
4764
Johannes Berg80b99892011-11-18 16:23:01 +01004765 if (!netif_running(v)) {
4766 ret = -ENETDOWN;
4767 goto error;
4768 }
4769
4770 return v;
4771 error:
4772 dev_put(v);
4773 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004774}
4775
Johannes Berg94e860f2014-01-20 23:58:15 +01004776static const struct nla_policy
4777nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004778 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4779 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4780};
4781
Johannes Bergff276692013-02-15 00:09:01 +01004782static int nl80211_parse_sta_wme(struct genl_info *info,
4783 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004784{
Jouni Malinendf881292013-02-14 21:10:54 +02004785 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4786 struct nlattr *nla;
4787 int err;
4788
Jouni Malinendf881292013-02-14 21:10:54 +02004789 /* parse WME attributes if present */
4790 if (!info->attrs[NL80211_ATTR_STA_WME])
4791 return 0;
4792
4793 nla = info->attrs[NL80211_ATTR_STA_WME];
4794 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004795 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004796 if (err)
4797 return err;
4798
4799 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4800 params->uapsd_queues = nla_get_u8(
4801 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4802 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4803 return -EINVAL;
4804
4805 if (tb[NL80211_STA_WME_MAX_SP])
4806 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4807
4808 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4809 return -EINVAL;
4810
4811 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4812
4813 return 0;
4814}
4815
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304816static int nl80211_parse_sta_channel_info(struct genl_info *info,
4817 struct station_parameters *params)
4818{
4819 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4820 params->supported_channels =
4821 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4822 params->supported_channels_len =
4823 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4824 /*
4825 * Need to include at least one (first channel, number of
4826 * channels) tuple for each subband, and must have proper
4827 * tuples for the rest of the data as well.
4828 */
4829 if (params->supported_channels_len < 2)
4830 return -EINVAL;
4831 if (params->supported_channels_len % 2)
4832 return -EINVAL;
4833 }
4834
4835 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4836 params->supported_oper_classes =
4837 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4838 params->supported_oper_classes_len =
4839 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4840 /*
4841 * The value of the Length field of the Supported Operating
4842 * Classes element is between 2 and 253.
4843 */
4844 if (params->supported_oper_classes_len < 2 ||
4845 params->supported_oper_classes_len > 253)
4846 return -EINVAL;
4847 }
4848 return 0;
4849}
4850
Johannes Bergff276692013-02-15 00:09:01 +01004851static int nl80211_set_station_tdls(struct genl_info *info,
4852 struct station_parameters *params)
4853{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304854 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004855 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004856 if (info->attrs[NL80211_ATTR_PEER_AID])
4857 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004858 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4859 params->ht_capa =
4860 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4861 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4862 params->vht_capa =
4863 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4864
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304865 err = nl80211_parse_sta_channel_info(info, params);
4866 if (err)
4867 return err;
4868
Johannes Bergff276692013-02-15 00:09:01 +01004869 return nl80211_parse_sta_wme(info, params);
4870}
4871
Johannes Berg5727ef12007-12-19 02:03:34 +01004872static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4873{
Johannes Berg4c476992010-10-04 21:36:35 +02004874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004875 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004876 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004877 u8 *mac_addr;
4878 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004879
4880 memset(&params, 0, sizeof(params));
4881
Johannes Berg77ee7c82013-02-15 00:48:33 +01004882 if (!rdev->ops->change_station)
4883 return -EOPNOTSUPP;
4884
Ayala Bekere4208422015-10-23 11:20:06 +03004885 /*
4886 * AID and listen_interval properties can be set only for unassociated
4887 * station. Include these parameters here and will check them in
4888 * cfg80211_check_station_change().
4889 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004890 if (info->attrs[NL80211_ATTR_STA_AID])
4891 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004892
4893 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4894 params.listen_interval =
4895 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4896 else
4897 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004898
Ayala Beker17b94242016-03-17 15:41:38 +02004899 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4900 u8 tmp;
4901
4902 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4903 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4904 return -EINVAL;
4905
4906 params.support_p2p_ps = tmp;
4907 } else {
4908 params.support_p2p_ps = -1;
4909 }
4910
Johannes Berg5727ef12007-12-19 02:03:34 +01004911 if (!info->attrs[NL80211_ATTR_MAC])
4912 return -EINVAL;
4913
4914 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4915
4916 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4917 params.supported_rates =
4918 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4919 params.supported_rates_len =
4920 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4921 }
4922
Jouni Malinen9d62a982013-02-14 21:10:13 +02004923 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4924 params.capability =
4925 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4926 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4927 }
4928
4929 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4930 params.ext_capab =
4931 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4932 params.ext_capab_len =
4933 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4934 }
4935
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004936 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004937 return -EINVAL;
4938
Johannes Bergf8bacc22013-02-14 23:27:01 +01004939 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004940 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004941 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4942 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4943 return -EINVAL;
4944 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004945
Johannes Bergf8bacc22013-02-14 23:27:01 +01004946 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004947 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004948 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4949 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4950 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004951 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4952 params.peer_aid = nla_get_u16(
4953 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4954 if (params.peer_aid > IEEE80211_MAX_AID)
4955 return -EINVAL;
4956 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004957 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4958 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004959
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004960 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4961 enum nl80211_mesh_power_mode pm = nla_get_u32(
4962 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4963
4964 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4965 pm > NL80211_MESH_POWER_MAX)
4966 return -EINVAL;
4967
4968 params.local_pm = pm;
4969 }
4970
Beni Lev06f7c882016-07-19 19:28:56 +03004971 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4972 params.opmode_notif_used = true;
4973 params.opmode_notif =
4974 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4975 }
4976
Johannes Berg77ee7c82013-02-15 00:48:33 +01004977 /* Include parameters for TDLS peer (will check later) */
4978 err = nl80211_set_station_tdls(info, &params);
4979 if (err)
4980 return err;
4981
4982 params.vlan = get_vlan(info, rdev);
4983 if (IS_ERR(params.vlan))
4984 return PTR_ERR(params.vlan);
4985
Johannes Berga97f4422009-06-18 17:23:43 +02004986 switch (dev->ieee80211_ptr->iftype) {
4987 case NL80211_IFTYPE_AP:
4988 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004989 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004990 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004991 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004992 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004993 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004994 break;
4995 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004996 err = -EOPNOTSUPP;
4997 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004998 }
4999
Johannes Berg77ee7c82013-02-15 00:48:33 +01005000 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005001 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005002
Johannes Berg77ee7c82013-02-15 00:48:33 +01005003 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005004 if (params.vlan)
5005 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005006
Johannes Berg5727ef12007-12-19 02:03:34 +01005007 return err;
5008}
5009
5010static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5011{
Johannes Berg4c476992010-10-04 21:36:35 +02005012 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005013 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005014 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005015 struct station_parameters params;
5016 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005017 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5018 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005019
5020 memset(&params, 0, sizeof(params));
5021
Johannes Berg984c3112013-02-14 23:43:25 +01005022 if (!rdev->ops->add_station)
5023 return -EOPNOTSUPP;
5024
Johannes Berg5727ef12007-12-19 02:03:34 +01005025 if (!info->attrs[NL80211_ATTR_MAC])
5026 return -EINVAL;
5027
Johannes Berg5727ef12007-12-19 02:03:34 +01005028 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5029 return -EINVAL;
5030
5031 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5032 return -EINVAL;
5033
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005034 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5035 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005036 return -EINVAL;
5037
Johannes Berg5727ef12007-12-19 02:03:34 +01005038 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5039 params.supported_rates =
5040 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5041 params.supported_rates_len =
5042 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5043 params.listen_interval =
5044 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005045
Ayala Beker17b94242016-03-17 15:41:38 +02005046 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5047 u8 tmp;
5048
5049 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5050 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5051 return -EINVAL;
5052
5053 params.support_p2p_ps = tmp;
5054 } else {
5055 /*
5056 * if not specified, assume it's supported for P2P GO interface,
5057 * and is NOT supported for AP interface
5058 */
5059 params.support_p2p_ps =
5060 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5061 }
5062
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005063 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005064 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005065 else
5066 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005067 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5068 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005069
Jouni Malinen9d62a982013-02-14 21:10:13 +02005070 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5071 params.capability =
5072 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5073 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5074 }
5075
5076 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5077 params.ext_capab =
5078 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5079 params.ext_capab_len =
5080 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5081 }
5082
Jouni Malinen36aedc92008-08-25 11:58:58 +03005083 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5084 params.ht_capa =
5085 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005086
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005087 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5088 params.vht_capa =
5089 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5090
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005091 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5092 params.opmode_notif_used = true;
5093 params.opmode_notif =
5094 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5095 }
5096
Johannes Bergf8bacc22013-02-14 23:27:01 +01005097 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005098 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005099 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5100 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5101 return -EINVAL;
5102 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005103
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305104 err = nl80211_parse_sta_channel_info(info, &params);
5105 if (err)
5106 return err;
5107
Johannes Bergff276692013-02-15 00:09:01 +01005108 err = nl80211_parse_sta_wme(info, &params);
5109 if (err)
5110 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005111
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005112 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005113 return -EINVAL;
5114
Johannes Berg496fcc22015-03-12 08:53:27 +02005115 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5116 * as userspace might just pass through the capabilities from the IEs
5117 * directly, rather than enforcing this restriction and returning an
5118 * error in this case.
5119 */
5120 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5121 params.ht_capa = NULL;
5122 params.vht_capa = NULL;
5123 }
5124
Johannes Berg77ee7c82013-02-15 00:48:33 +01005125 /* When you run into this, adjust the code below for the new flag */
5126 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5127
Johannes Bergbdd90d52011-12-14 12:20:27 +01005128 switch (dev->ieee80211_ptr->iftype) {
5129 case NL80211_IFTYPE_AP:
5130 case NL80211_IFTYPE_AP_VLAN:
5131 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005132 /* ignore WME attributes if iface/sta is not capable */
5133 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5134 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5135 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005136
Johannes Bergbdd90d52011-12-14 12:20:27 +01005137 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005138 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5139 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005140 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005141 /* but don't bother the driver with it */
5142 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005143
Johannes Bergd582cff2012-10-26 17:53:44 +02005144 /* allow authenticated/associated only if driver handles it */
5145 if (!(rdev->wiphy.features &
5146 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005147 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005148 return -EINVAL;
5149
Johannes Bergbda95eb2015-11-26 16:26:13 +01005150 /* Older userspace, or userspace wanting to be compatible with
5151 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5152 * and assoc flags in the mask, but assumes the station will be
5153 * added as associated anyway since this was the required driver
5154 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5155 * introduced.
5156 * In order to not bother drivers with this quirk in the API
5157 * set the flags in both the mask and set for new stations in
5158 * this case.
5159 */
5160 if (!(params.sta_flags_mask & auth_assoc)) {
5161 params.sta_flags_mask |= auth_assoc;
5162 params.sta_flags_set |= auth_assoc;
5163 }
5164
Johannes Bergbdd90d52011-12-14 12:20:27 +01005165 /* must be last in here for error handling */
5166 params.vlan = get_vlan(info, rdev);
5167 if (IS_ERR(params.vlan))
5168 return PTR_ERR(params.vlan);
5169 break;
5170 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005171 /* ignore uAPSD data */
5172 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5173
Johannes Bergd582cff2012-10-26 17:53:44 +02005174 /* associated is disallowed */
5175 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5176 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005177 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005178 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5179 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005180 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005181 break;
5182 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005183 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005184 /* ignore uAPSD data */
5185 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5186
Johannes Berg77ee7c82013-02-15 00:48:33 +01005187 /* these are disallowed */
5188 if (params.sta_flags_mask &
5189 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5190 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005191 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005192 /* Only TDLS peers can be added */
5193 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5194 return -EINVAL;
5195 /* Can only add if TDLS ... */
5196 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5197 return -EOPNOTSUPP;
5198 /* ... with external setup is supported */
5199 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5200 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005201 /*
5202 * Older wpa_supplicant versions always mark the TDLS peer
5203 * as authorized, but it shouldn't yet be.
5204 */
5205 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005206 break;
5207 default:
5208 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005209 }
5210
Johannes Bergbdd90d52011-12-14 12:20:27 +01005211 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005212
Hila Gonene35e4d22012-06-27 17:19:42 +03005213 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005214
Johannes Berg5727ef12007-12-19 02:03:34 +01005215 if (params.vlan)
5216 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005217 return err;
5218}
5219
5220static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5221{
Johannes Berg4c476992010-10-04 21:36:35 +02005222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5223 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005224 struct station_del_parameters params;
5225
5226 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005227
5228 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005229 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005230
Johannes Berge80cf852009-05-11 14:43:13 +02005231 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005232 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005233 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005234 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5235 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005236
Johannes Berg4c476992010-10-04 21:36:35 +02005237 if (!rdev->ops->del_station)
5238 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005239
Jouni Malinen98856862014-10-20 13:20:45 +03005240 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5241 params.subtype =
5242 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5243 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5244 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5245 return -EINVAL;
5246 } else {
5247 /* Default to Deauthentication frame */
5248 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5249 }
5250
5251 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5252 params.reason_code =
5253 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5254 if (params.reason_code == 0)
5255 return -EINVAL; /* 0 is reserved */
5256 } else {
5257 /* Default to reason code 2 */
5258 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5259 }
5260
Jouni Malinen89c771e2014-10-10 20:52:40 +03005261 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005262}
5263
Eric W. Biederman15e47302012-09-07 20:12:54 +00005264static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005265 int flags, struct net_device *dev,
5266 u8 *dst, u8 *next_hop,
5267 struct mpath_info *pinfo)
5268{
5269 void *hdr;
5270 struct nlattr *pinfoattr;
5271
Henning Rogge1ef4c852014-11-04 16:14:58 +01005272 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005273 if (!hdr)
5274 return -1;
5275
David S. Miller9360ffd2012-03-29 04:41:26 -04005276 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5277 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5278 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5279 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5280 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005281
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005282 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5283 if (!pinfoattr)
5284 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005285 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5286 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5287 pinfo->frame_qlen))
5288 goto nla_put_failure;
5289 if (((pinfo->filled & MPATH_INFO_SN) &&
5290 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5291 ((pinfo->filled & MPATH_INFO_METRIC) &&
5292 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5293 pinfo->metric)) ||
5294 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5295 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5296 pinfo->exptime)) ||
5297 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5298 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5299 pinfo->flags)) ||
5300 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5301 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5302 pinfo->discovery_timeout)) ||
5303 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5304 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5305 pinfo->discovery_retries)))
5306 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005307
5308 nla_nest_end(msg, pinfoattr);
5309
Johannes Berg053c0952015-01-16 22:09:00 +01005310 genlmsg_end(msg, hdr);
5311 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005312
5313 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005314 genlmsg_cancel(msg, hdr);
5315 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005316}
5317
5318static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005319 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005320{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005321 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005322 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005323 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005324 u8 dst[ETH_ALEN];
5325 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005326 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005327 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005328
Johannes Bergea90e0d2017-03-15 14:26:04 +01005329 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005330 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005331 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005332 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005334 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005335 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005336 goto out_err;
5337 }
5338
Johannes Berg97990a02013-04-19 01:02:55 +02005339 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005340 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005341 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005342 }
5343
Johannes Bergbba95fe2008-07-29 13:22:51 +02005344 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005345 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005346 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005347 if (err == -ENOENT)
5348 break;
5349 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005350 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005351
Eric W. Biederman15e47302012-09-07 20:12:54 +00005352 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005353 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005354 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005355 &pinfo) < 0)
5356 goto out;
5357
5358 path_idx++;
5359 }
5360
Johannes Bergbba95fe2008-07-29 13:22:51 +02005361 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005362 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005363 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005364 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005365 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005366 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005367}
5368
5369static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5370{
Johannes Berg4c476992010-10-04 21:36:35 +02005371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005372 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005373 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005374 struct mpath_info pinfo;
5375 struct sk_buff *msg;
5376 u8 *dst = NULL;
5377 u8 next_hop[ETH_ALEN];
5378
5379 memset(&pinfo, 0, sizeof(pinfo));
5380
5381 if (!info->attrs[NL80211_ATTR_MAC])
5382 return -EINVAL;
5383
5384 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5385
Johannes Berg4c476992010-10-04 21:36:35 +02005386 if (!rdev->ops->get_mpath)
5387 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005388
Johannes Berg4c476992010-10-04 21:36:35 +02005389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5390 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005391
Hila Gonene35e4d22012-06-27 17:19:42 +03005392 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005393 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005394 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005395
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005396 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005397 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005398 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005399
Eric W. Biederman15e47302012-09-07 20:12:54 +00005400 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005401 dev, dst, next_hop, &pinfo) < 0) {
5402 nlmsg_free(msg);
5403 return -ENOBUFS;
5404 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005405
Johannes Berg4c476992010-10-04 21:36:35 +02005406 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005407}
5408
5409static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5410{
Johannes Berg4c476992010-10-04 21:36:35 +02005411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5412 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005413 u8 *dst = NULL;
5414 u8 *next_hop = NULL;
5415
5416 if (!info->attrs[NL80211_ATTR_MAC])
5417 return -EINVAL;
5418
5419 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5420 return -EINVAL;
5421
5422 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5423 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5424
Johannes Berg4c476992010-10-04 21:36:35 +02005425 if (!rdev->ops->change_mpath)
5426 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005427
Johannes Berg4c476992010-10-04 21:36:35 +02005428 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5429 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005430
Hila Gonene35e4d22012-06-27 17:19:42 +03005431 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005432}
Johannes Berg4c476992010-10-04 21:36:35 +02005433
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005434static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5435{
Johannes Berg4c476992010-10-04 21:36:35 +02005436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5437 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005438 u8 *dst = NULL;
5439 u8 *next_hop = NULL;
5440
5441 if (!info->attrs[NL80211_ATTR_MAC])
5442 return -EINVAL;
5443
5444 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5445 return -EINVAL;
5446
5447 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5448 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5449
Johannes Berg4c476992010-10-04 21:36:35 +02005450 if (!rdev->ops->add_mpath)
5451 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005452
Johannes Berg4c476992010-10-04 21:36:35 +02005453 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5454 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005455
Hila Gonene35e4d22012-06-27 17:19:42 +03005456 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005457}
5458
5459static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5460{
Johannes Berg4c476992010-10-04 21:36:35 +02005461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5462 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005463 u8 *dst = NULL;
5464
5465 if (info->attrs[NL80211_ATTR_MAC])
5466 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5467
Johannes Berg4c476992010-10-04 21:36:35 +02005468 if (!rdev->ops->del_mpath)
5469 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005470
Hila Gonene35e4d22012-06-27 17:19:42 +03005471 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005472}
5473
Henning Rogge66be7d22014-09-12 08:58:49 +02005474static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5475{
5476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5477 int err;
5478 struct net_device *dev = info->user_ptr[1];
5479 struct mpath_info pinfo;
5480 struct sk_buff *msg;
5481 u8 *dst = NULL;
5482 u8 mpp[ETH_ALEN];
5483
5484 memset(&pinfo, 0, sizeof(pinfo));
5485
5486 if (!info->attrs[NL80211_ATTR_MAC])
5487 return -EINVAL;
5488
5489 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5490
5491 if (!rdev->ops->get_mpp)
5492 return -EOPNOTSUPP;
5493
5494 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5495 return -EOPNOTSUPP;
5496
5497 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5498 if (err)
5499 return err;
5500
5501 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5502 if (!msg)
5503 return -ENOMEM;
5504
5505 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5506 dev, dst, mpp, &pinfo) < 0) {
5507 nlmsg_free(msg);
5508 return -ENOBUFS;
5509 }
5510
5511 return genlmsg_reply(msg, info);
5512}
5513
5514static int nl80211_dump_mpp(struct sk_buff *skb,
5515 struct netlink_callback *cb)
5516{
5517 struct mpath_info pinfo;
5518 struct cfg80211_registered_device *rdev;
5519 struct wireless_dev *wdev;
5520 u8 dst[ETH_ALEN];
5521 u8 mpp[ETH_ALEN];
5522 int path_idx = cb->args[2];
5523 int err;
5524
Johannes Bergea90e0d2017-03-15 14:26:04 +01005525 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005526 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5527 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005528 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005529
5530 if (!rdev->ops->dump_mpp) {
5531 err = -EOPNOTSUPP;
5532 goto out_err;
5533 }
5534
5535 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5536 err = -EOPNOTSUPP;
5537 goto out_err;
5538 }
5539
5540 while (1) {
5541 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5542 mpp, &pinfo);
5543 if (err == -ENOENT)
5544 break;
5545 if (err)
5546 goto out_err;
5547
5548 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5549 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5550 wdev->netdev, dst, mpp,
5551 &pinfo) < 0)
5552 goto out;
5553
5554 path_idx++;
5555 }
5556
5557 out:
5558 cb->args[2] = path_idx;
5559 err = skb->len;
5560 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005561 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005562 return err;
5563}
5564
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005565static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5566{
Johannes Berg4c476992010-10-04 21:36:35 +02005567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5568 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005570 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005571 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005572
5573 memset(&params, 0, sizeof(params));
5574 /* default to not changing parameters */
5575 params.use_cts_prot = -1;
5576 params.use_short_preamble = -1;
5577 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005578 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005579 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005580 params.p2p_ctwindow = -1;
5581 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005582
5583 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5584 params.use_cts_prot =
5585 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5586 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5587 params.use_short_preamble =
5588 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5589 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5590 params.use_short_slot_time =
5591 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005592 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5593 params.basic_rates =
5594 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5595 params.basic_rates_len =
5596 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5597 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005598 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5599 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005600 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5601 params.ht_opmode =
5602 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005603
Johannes Berg53cabad2012-11-14 15:17:28 +01005604 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5605 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5606 return -EINVAL;
5607 params.p2p_ctwindow =
5608 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5609 if (params.p2p_ctwindow < 0)
5610 return -EINVAL;
5611 if (params.p2p_ctwindow != 0 &&
5612 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5613 return -EINVAL;
5614 }
5615
5616 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5617 u8 tmp;
5618
5619 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5620 return -EINVAL;
5621 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5622 if (tmp > 1)
5623 return -EINVAL;
5624 params.p2p_opp_ps = tmp;
5625 if (params.p2p_opp_ps &&
5626 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5627 return -EINVAL;
5628 }
5629
Johannes Berg4c476992010-10-04 21:36:35 +02005630 if (!rdev->ops->change_bss)
5631 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005632
Johannes Berg074ac8d2010-09-16 14:58:22 +02005633 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005634 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5635 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005636
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005637 wdev_lock(wdev);
5638 err = rdev_change_bss(rdev, dev, &params);
5639 wdev_unlock(wdev);
5640
5641 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005642}
5643
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005644static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5645{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005646 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005647 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005648 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005649 u32 owner_nlportid;
5650
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005651 /*
5652 * You should only get this when cfg80211 hasn't yet initialized
5653 * completely when built-in to the kernel right between the time
5654 * window between nl80211_init() and regulatory_init(), if that is
5655 * even possible.
5656 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005657 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005658 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005659
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005660 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5661 user_reg_hint_type =
5662 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5663 else
5664 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5665
5666 switch (user_reg_hint_type) {
5667 case NL80211_USER_REG_HINT_USER:
5668 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005669 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5670 return -EINVAL;
5671
5672 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5673 return regulatory_hint_user(data, user_reg_hint_type);
5674 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005675 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5676 owner_nlportid = info->snd_portid;
5677 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5678 } else {
5679 owner_nlportid = 0;
5680 is_indoor = true;
5681 }
5682
5683 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005684 default:
5685 return -EINVAL;
5686 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005687}
5688
Johannes Berg1ea4ff32017-09-13 16:07:22 +02005689static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
5690{
5691 return reg_reload_regdb();
5692}
5693
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005694static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005695 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005696{
Johannes Berg4c476992010-10-04 21:36:35 +02005697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005698 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005699 struct wireless_dev *wdev = dev->ieee80211_ptr;
5700 struct mesh_config cur_params;
5701 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005702 void *hdr;
5703 struct nlattr *pinfoattr;
5704 struct sk_buff *msg;
5705
Johannes Berg29cbe682010-12-03 09:20:44 +01005706 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5707 return -EOPNOTSUPP;
5708
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005709 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005710 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005711
Johannes Berg29cbe682010-12-03 09:20:44 +01005712 wdev_lock(wdev);
5713 /* If not connected, get default parameters */
5714 if (!wdev->mesh_id_len)
5715 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5716 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005717 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005718 wdev_unlock(wdev);
5719
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005720 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005721 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005722
5723 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005725 if (!msg)
5726 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005727 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005728 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005729 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005730 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005731 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005732 if (!pinfoattr)
5733 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005734 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5735 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5736 cur_params.dot11MeshRetryTimeout) ||
5737 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5738 cur_params.dot11MeshConfirmTimeout) ||
5739 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5740 cur_params.dot11MeshHoldingTimeout) ||
5741 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5742 cur_params.dot11MeshMaxPeerLinks) ||
5743 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5744 cur_params.dot11MeshMaxRetries) ||
5745 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5746 cur_params.dot11MeshTTL) ||
5747 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5748 cur_params.element_ttl) ||
5749 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5750 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005751 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5752 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005753 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5754 cur_params.dot11MeshHWMPmaxPREQretries) ||
5755 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5756 cur_params.path_refresh_time) ||
5757 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5758 cur_params.min_discovery_timeout) ||
5759 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5760 cur_params.dot11MeshHWMPactivePathTimeout) ||
5761 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5762 cur_params.dot11MeshHWMPpreqMinInterval) ||
5763 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5764 cur_params.dot11MeshHWMPperrMinInterval) ||
5765 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5766 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5767 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5768 cur_params.dot11MeshHWMPRootMode) ||
5769 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5770 cur_params.dot11MeshHWMPRannInterval) ||
5771 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5772 cur_params.dot11MeshGateAnnouncementProtocol) ||
5773 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5774 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005775 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005776 cur_params.rssi_threshold) ||
5777 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005778 cur_params.ht_opmode) ||
5779 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5780 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5781 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005782 cur_params.dot11MeshHWMProotInterval) ||
5783 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005784 cur_params.dot11MeshHWMPconfirmationInterval) ||
5785 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5786 cur_params.power_mode) ||
5787 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005788 cur_params.dot11MeshAwakeWindowDuration) ||
5789 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5790 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005791 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005792 nla_nest_end(msg, pinfoattr);
5793 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005794 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005795
Johannes Berg3b858752009-03-12 09:55:09 +01005796 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005797 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005798 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005799 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005800 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005801}
5802
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005803static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005804 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5805 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5806 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5807 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5808 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5809 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005810 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005811 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005812 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005813 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5814 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5815 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5816 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5817 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005818 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005819 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005820 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005821 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005822 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005823 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005824 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5825 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005826 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5827 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005828 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005829 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5830 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005831 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005832};
5833
Javier Cardonac80d5452010-12-16 17:37:49 -08005834static const struct nla_policy
5835 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005836 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005837 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5838 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005839 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005840 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005841 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005842 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005843 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005844 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005845};
5846
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005847static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5848{
5849 u8 val = nla_get_u8(nla);
5850 if (val < min || val > max)
5851 return -EINVAL;
5852 *out = val;
5853 return 0;
5854}
5855
5856static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5857{
5858 u8 val = nla_get_u8(nla);
5859 if (val < min || val > max)
5860 return -EINVAL;
5861 *out = val;
5862 return 0;
5863}
5864
5865static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5866{
5867 u16 val = nla_get_u16(nla);
5868 if (val < min || val > max)
5869 return -EINVAL;
5870 *out = val;
5871 return 0;
5872}
5873
5874static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5875{
5876 u32 val = nla_get_u32(nla);
5877 if (val < min || val > max)
5878 return -EINVAL;
5879 *out = val;
5880 return 0;
5881}
5882
5883static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5884{
5885 s32 val = nla_get_s32(nla);
5886 if (val < min || val > max)
5887 return -EINVAL;
5888 *out = val;
5889 return 0;
5890}
5891
Johannes Bergff9a71a2016-08-11 14:59:53 +02005892static int nl80211_check_power_mode(const struct nlattr *nla,
5893 enum nl80211_mesh_power_mode min,
5894 enum nl80211_mesh_power_mode max,
5895 enum nl80211_mesh_power_mode *out)
5896{
5897 u32 val = nla_get_u32(nla);
5898 if (val < min || val > max)
5899 return -EINVAL;
5900 *out = val;
5901 return 0;
5902}
5903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005904static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005905 struct mesh_config *cfg,
5906 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005907{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005908 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005909 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005910 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005911
Marco Porschea54fba2013-01-07 16:04:48 +01005912#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5913do { \
5914 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005915 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005916 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005917 mask |= (1 << (attr - 1)); \
5918 } \
5919} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005920
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005921 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005922 return -EINVAL;
5923 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005924 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005925 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005926 return -EINVAL;
5927
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005928 /* This makes sure that there aren't more than 32 mesh config
5929 * parameters (otherwise our bitfield scheme would not work.) */
5930 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5931
5932 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005934 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005935 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005937 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005938 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005940 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005941 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005943 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005944 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005945 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005946 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005947 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005948 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005949 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005951 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005952 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005954 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005955 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5957 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005958 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005959 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005960 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005961 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005962 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005963 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005964 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005965 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005966 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005967 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005968 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005969 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5970 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005971 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005972 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005973 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005974 1, 65535, mask,
5975 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005976 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005978 1, 65535, mask,
5979 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005980 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005981 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005982 dot11MeshHWMPnetDiameterTraversalTime,
5983 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005984 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005985 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005986 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5987 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005988 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005989 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5990 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005991 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005993 dot11MeshGateAnnouncementProtocol, 0, 1,
5994 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005995 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005996 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005997 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005998 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005999 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006000 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006001 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09006002 /*
6003 * Check HT operation mode based on
6004 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6005 */
6006 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6007 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6008
6009 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6010 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6011 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6012 return -EINVAL;
6013
6014 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6015 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6016 return -EINVAL;
6017
6018 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6019 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6020 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6021 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6022 return -EINVAL;
6023 break;
6024 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6025 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6026 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6027 return -EINVAL;
6028 break;
6029 }
6030 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006031 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006032 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006033 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006034 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006035 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006036 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006037 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006038 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006039 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006040 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006041 dot11MeshHWMPconfirmationInterval,
6042 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006043 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006044 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6046 NL80211_MESH_POWER_ACTIVE,
6047 NL80211_MESH_POWER_MAX,
6048 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006049 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006050 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6051 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006052 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006053 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006054 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006055 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006056 if (mask_out)
6057 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006058
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006059 return 0;
6060
6061#undef FILL_IN_MESH_PARAM_IF_SET
6062}
6063
Javier Cardonac80d5452010-12-16 17:37:49 -08006064static int nl80211_parse_mesh_setup(struct genl_info *info,
6065 struct mesh_setup *setup)
6066{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006068 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6069
6070 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6071 return -EINVAL;
6072 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6073 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006074 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006075 return -EINVAL;
6076
Javier Cardonad299a1f2012-03-31 11:31:33 -07006077 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6078 setup->sync_method =
6079 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6080 IEEE80211_SYNC_METHOD_VENDOR :
6081 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6082
Javier Cardonac80d5452010-12-16 17:37:49 -08006083 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6084 setup->path_sel_proto =
6085 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6086 IEEE80211_PATH_PROTOCOL_VENDOR :
6087 IEEE80211_PATH_PROTOCOL_HWMP;
6088
6089 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6090 setup->path_metric =
6091 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6092 IEEE80211_PATH_METRIC_VENDOR :
6093 IEEE80211_PATH_METRIC_AIRTIME;
6094
Javier Cardona581a8b02011-04-07 15:08:27 -07006095 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006096 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006097 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006098 if (!is_valid_ie_attr(ieattr))
6099 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006100 setup->ie = nla_data(ieattr);
6101 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006102 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006103 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6104 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6105 return -EINVAL;
6106 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006107 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6108 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006109 if (setup->is_secure)
6110 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006111
Colleen Twitty6e16d902013-05-08 11:45:59 -07006112 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6113 if (!setup->user_mpm)
6114 return -EINVAL;
6115 setup->auth_id =
6116 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6117 }
6118
Javier Cardonac80d5452010-12-16 17:37:49 -08006119 return 0;
6120}
6121
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006122static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006123 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006124{
6125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6126 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006127 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006128 struct mesh_config cfg;
6129 u32 mask;
6130 int err;
6131
Johannes Berg29cbe682010-12-03 09:20:44 +01006132 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6133 return -EOPNOTSUPP;
6134
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006135 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006136 return -EOPNOTSUPP;
6137
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006138 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006139 if (err)
6140 return err;
6141
Johannes Berg29cbe682010-12-03 09:20:44 +01006142 wdev_lock(wdev);
6143 if (!wdev->mesh_id_len)
6144 err = -ENOLINK;
6145
6146 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006147 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006148
6149 wdev_unlock(wdev);
6150
6151 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006152}
6153
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006154static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6155 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006156{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006157 struct nlattr *nl_reg_rules;
6158 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006159
Johannes Berg458f4f92012-12-06 15:47:38 +01006160 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6161 (regdom->dfs_region &&
6162 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006163 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006164
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006165 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6166 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006167 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006168
Johannes Berg458f4f92012-12-06 15:47:38 +01006169 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006170 struct nlattr *nl_reg_rule;
6171 const struct ieee80211_reg_rule *reg_rule;
6172 const struct ieee80211_freq_range *freq_range;
6173 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006174 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006175
Johannes Berg458f4f92012-12-06 15:47:38 +01006176 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006177 freq_range = &reg_rule->freq_range;
6178 power_rule = &reg_rule->power_rule;
6179
6180 nl_reg_rule = nla_nest_start(msg, i);
6181 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006182 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006183
Janusz Dziedzic97524822014-01-30 09:52:20 +01006184 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6185 if (!max_bandwidth_khz)
6186 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6187 reg_rule);
6188
David S. Miller9360ffd2012-03-29 04:41:26 -04006189 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6190 reg_rule->flags) ||
6191 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6192 freq_range->start_freq_khz) ||
6193 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6194 freq_range->end_freq_khz) ||
6195 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006196 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006197 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6198 power_rule->max_antenna_gain) ||
6199 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006200 power_rule->max_eirp) ||
6201 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6202 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006203 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006204
6205 nla_nest_end(msg, nl_reg_rule);
6206 }
6207
6208 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006209 return 0;
6210
6211nla_put_failure:
6212 return -EMSGSIZE;
6213}
6214
6215static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6216{
6217 const struct ieee80211_regdomain *regdom = NULL;
6218 struct cfg80211_registered_device *rdev;
6219 struct wiphy *wiphy = NULL;
6220 struct sk_buff *msg;
6221 void *hdr;
6222
6223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6224 if (!msg)
6225 return -ENOBUFS;
6226
6227 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6228 NL80211_CMD_GET_REG);
6229 if (!hdr)
6230 goto put_failure;
6231
6232 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006233 bool self_managed;
6234
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006235 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6236 if (IS_ERR(rdev)) {
6237 nlmsg_free(msg);
6238 return PTR_ERR(rdev);
6239 }
6240
6241 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006242 self_managed = wiphy->regulatory_flags &
6243 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006244 regdom = get_wiphy_regdom(wiphy);
6245
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006246 /* a self-managed-reg device must have a private regdom */
6247 if (WARN_ON(!regdom && self_managed)) {
6248 nlmsg_free(msg);
6249 return -EINVAL;
6250 }
6251
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006252 if (regdom &&
6253 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6254 goto nla_put_failure;
6255 }
6256
6257 if (!wiphy && reg_last_request_cell_base() &&
6258 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6259 NL80211_USER_REG_HINT_CELL_BASE))
6260 goto nla_put_failure;
6261
6262 rcu_read_lock();
6263
6264 if (!regdom)
6265 regdom = rcu_dereference(cfg80211_regdomain);
6266
6267 if (nl80211_put_regdom(regdom, msg))
6268 goto nla_put_failure_rcu;
6269
6270 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006271
6272 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006273 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006274
Johannes Berg458f4f92012-12-06 15:47:38 +01006275nla_put_failure_rcu:
6276 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006277nla_put_failure:
6278 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006279put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006280 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006281 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006282}
6283
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006284static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6285 u32 seq, int flags, struct wiphy *wiphy,
6286 const struct ieee80211_regdomain *regdom)
6287{
6288 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6289 NL80211_CMD_GET_REG);
6290
6291 if (!hdr)
6292 return -1;
6293
Michal Kubecek0a833c22017-11-15 13:09:32 +01006294 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006295
6296 if (nl80211_put_regdom(regdom, msg))
6297 goto nla_put_failure;
6298
6299 if (!wiphy && reg_last_request_cell_base() &&
6300 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6301 NL80211_USER_REG_HINT_CELL_BASE))
6302 goto nla_put_failure;
6303
6304 if (wiphy &&
6305 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6306 goto nla_put_failure;
6307
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006308 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6309 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6310 goto nla_put_failure;
6311
Johannes Berg053c0952015-01-16 22:09:00 +01006312 genlmsg_end(msg, hdr);
6313 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006314
6315nla_put_failure:
6316 genlmsg_cancel(msg, hdr);
6317 return -EMSGSIZE;
6318}
6319
6320static int nl80211_get_reg_dump(struct sk_buff *skb,
6321 struct netlink_callback *cb)
6322{
6323 const struct ieee80211_regdomain *regdom = NULL;
6324 struct cfg80211_registered_device *rdev;
6325 int err, reg_idx, start = cb->args[2];
6326
6327 rtnl_lock();
6328
6329 if (cfg80211_regdomain && start == 0) {
6330 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6331 NLM_F_MULTI, NULL,
6332 rtnl_dereference(cfg80211_regdomain));
6333 if (err < 0)
6334 goto out_err;
6335 }
6336
6337 /* the global regdom is idx 0 */
6338 reg_idx = 1;
6339 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6340 regdom = get_wiphy_regdom(&rdev->wiphy);
6341 if (!regdom)
6342 continue;
6343
6344 if (++reg_idx <= start)
6345 continue;
6346
6347 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6348 NLM_F_MULTI, &rdev->wiphy, regdom);
6349 if (err < 0) {
6350 reg_idx--;
6351 break;
6352 }
6353 }
6354
6355 cb->args[2] = reg_idx;
6356 err = skb->len;
6357out_err:
6358 rtnl_unlock();
6359 return err;
6360}
6361
Johannes Bergb6863032015-10-15 09:25:18 +02006362#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6363static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6364 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6365 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6366 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6367 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6368 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6369 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6370 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6371};
6372
6373static int parse_reg_rule(struct nlattr *tb[],
6374 struct ieee80211_reg_rule *reg_rule)
6375{
6376 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6377 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6378
6379 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6380 return -EINVAL;
6381 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6382 return -EINVAL;
6383 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6384 return -EINVAL;
6385 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6386 return -EINVAL;
6387 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6388 return -EINVAL;
6389
6390 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6391
6392 freq_range->start_freq_khz =
6393 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6394 freq_range->end_freq_khz =
6395 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6396 freq_range->max_bandwidth_khz =
6397 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6398
6399 power_rule->max_eirp =
6400 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6401
6402 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6403 power_rule->max_antenna_gain =
6404 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6405
6406 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6407 reg_rule->dfs_cac_ms =
6408 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6409
6410 return 0;
6411}
6412
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006413static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6414{
6415 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6416 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006417 char *alpha2;
6418 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006419 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006420 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006421 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006422
6423 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6424 return -EINVAL;
6425
6426 if (!info->attrs[NL80211_ATTR_REG_RULES])
6427 return -EINVAL;
6428
6429 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6430
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006431 if (info->attrs[NL80211_ATTR_DFS_REGION])
6432 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6433
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006434 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006435 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006436 num_rules++;
6437 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006438 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006439 }
6440
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006441 if (!reg_is_valid_request(alpha2))
6442 return -EINVAL;
6443
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006444 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006445 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006446
6447 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006448 if (!rd)
6449 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006450
6451 rd->n_reg_rules = num_rules;
6452 rd->alpha2[0] = alpha2[0];
6453 rd->alpha2[1] = alpha2[1];
6454
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006455 /*
6456 * Disable DFS master mode if the DFS region was
6457 * not supported or known on this kernel.
6458 */
6459 if (reg_supported_dfs_region(dfs_region))
6460 rd->dfs_region = dfs_region;
6461
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006462 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006463 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006464 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006465 nl_reg_rule, reg_rule_policy,
6466 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006467 if (r)
6468 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006469 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6470 if (r)
6471 goto bad_reg;
6472
6473 rule_idx++;
6474
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006475 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6476 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006477 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006478 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006479 }
6480
Johannes Berg06627992016-06-09 10:40:09 +02006481 /* set_regdom takes ownership of rd */
6482 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006483 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006484 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006485 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006486}
Johannes Bergb6863032015-10-15 09:25:18 +02006487#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006488
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006489static int validate_scan_freqs(struct nlattr *freqs)
6490{
6491 struct nlattr *attr1, *attr2;
6492 int n_channels = 0, tmp1, tmp2;
6493
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006494 nla_for_each_nested(attr1, freqs, tmp1)
6495 if (nla_len(attr1) != sizeof(u32))
6496 return 0;
6497
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006498 nla_for_each_nested(attr1, freqs, tmp1) {
6499 n_channels++;
6500 /*
6501 * Some hardware has a limited channel list for
6502 * scanning, and it is pretty much nonsensical
6503 * to scan for a channel twice, so disallow that
6504 * and don't require drivers to check that the
6505 * channel list they get isn't longer than what
6506 * they can scan, as long as they can scan all
6507 * the channels they registered at once.
6508 */
6509 nla_for_each_nested(attr2, freqs, tmp2)
6510 if (attr1 != attr2 &&
6511 nla_get_u32(attr1) == nla_get_u32(attr2))
6512 return 0;
6513 }
6514
6515 return n_channels;
6516}
6517
Johannes Berg57fbcce2016-04-12 15:56:15 +02006518static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006519{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006520 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006521}
6522
6523static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6524 struct cfg80211_bss_selection *bss_select)
6525{
6526 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6527 struct nlattr *nest;
6528 int err;
6529 bool found = false;
6530 int i;
6531
6532 /* only process one nested attribute */
6533 nest = nla_data(nla);
6534 if (!nla_ok(nest, nla_len(nest)))
6535 return -EINVAL;
6536
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006537 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006538 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006539 if (err)
6540 return err;
6541
6542 /* only one attribute may be given */
6543 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6544 if (attr[i]) {
6545 if (found)
6546 return -EINVAL;
6547 found = true;
6548 }
6549 }
6550
6551 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6552
6553 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6554 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6555
6556 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6557 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6558 bss_select->param.band_pref =
6559 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6560 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6561 return -EINVAL;
6562 }
6563
6564 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6565 struct nl80211_bss_select_rssi_adjust *adj_param;
6566
6567 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6568 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6569 bss_select->param.adjust.band = adj_param->band;
6570 bss_select->param.adjust.delta = adj_param->delta;
6571 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6572 return -EINVAL;
6573 }
6574
6575 /* user-space did not provide behaviour attribute */
6576 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6577 return -EINVAL;
6578
6579 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6580 return -EINVAL;
6581
6582 return 0;
6583}
6584
Johannes Bergad2b26a2014-06-12 21:39:05 +02006585static int nl80211_parse_random_mac(struct nlattr **attrs,
6586 u8 *mac_addr, u8 *mac_addr_mask)
6587{
6588 int i;
6589
6590 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006591 eth_zero_addr(mac_addr);
6592 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006593 mac_addr[0] = 0x2;
6594 mac_addr_mask[0] = 0x3;
6595
6596 return 0;
6597 }
6598
6599 /* need both or none */
6600 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6601 return -EINVAL;
6602
6603 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6604 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6605
6606 /* don't allow or configure an mcast address */
6607 if (!is_multicast_ether_addr(mac_addr_mask) ||
6608 is_multicast_ether_addr(mac_addr))
6609 return -EINVAL;
6610
6611 /*
6612 * allow users to pass a MAC address that has bits set outside
6613 * of the mask, but don't bother drivers with having to deal
6614 * with such bits
6615 */
6616 for (i = 0; i < ETH_ALEN; i++)
6617 mac_addr[i] &= mac_addr_mask[i];
6618
6619 return 0;
6620}
6621
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306622static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6623{
6624 ASSERT_WDEV_LOCK(wdev);
6625
6626 if (!cfg80211_beaconing_iface_active(wdev))
6627 return true;
6628
6629 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6630 return true;
6631
6632 return regulatory_pre_cac_allowed(wdev->wiphy);
6633}
6634
Roee Zamir2d23d072017-08-06 11:38:22 +03006635static int
6636nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6637 void *request, struct nlattr **attrs,
6638 bool is_sched_scan)
6639{
6640 u8 *mac_addr, *mac_addr_mask;
6641 u32 *flags;
6642 enum nl80211_feature_flags randomness_flag;
6643
6644 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6645 return 0;
6646
6647 if (is_sched_scan) {
6648 struct cfg80211_sched_scan_request *req = request;
6649
6650 randomness_flag = wdev ?
6651 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6652 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6653 flags = &req->flags;
6654 mac_addr = req->mac_addr;
6655 mac_addr_mask = req->mac_addr_mask;
6656 } else {
6657 struct cfg80211_scan_request *req = request;
6658
6659 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6660 flags = &req->flags;
6661 mac_addr = req->mac_addr;
6662 mac_addr_mask = req->mac_addr_mask;
6663 }
6664
6665 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
6666
6667 if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6668 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN))
6669 return -EOPNOTSUPP;
6670
6671 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6672 int err;
6673
6674 if (!(wiphy->features & randomness_flag) ||
6675 (wdev && wdev->current_bss))
6676 return -EOPNOTSUPP;
6677
6678 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
6679 if (err)
6680 return err;
6681 }
6682
6683 if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) &&
6684 !wiphy_ext_feature_isset(wiphy,
6685 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME))
6686 return -EOPNOTSUPP;
6687
6688 if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) &&
6689 !wiphy_ext_feature_isset(wiphy,
6690 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP))
6691 return -EOPNOTSUPP;
6692
6693 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
6694 !wiphy_ext_feature_isset(wiphy,
6695 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
6696 return -EOPNOTSUPP;
6697
6698 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) &&
6699 !wiphy_ext_feature_isset(wiphy,
6700 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE))
6701 return -EOPNOTSUPP;
6702
6703 return 0;
6704}
6705
Johannes Berg2a519312009-02-10 21:25:55 +01006706static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6707{
Johannes Berg4c476992010-10-04 21:36:35 +02006708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006709 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006710 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006711 struct nlattr *attr;
6712 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006713 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006714 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006715
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006716 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6717 return -EINVAL;
6718
Johannes Berg79c97e92009-07-07 03:56:12 +02006719 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006720
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006721 if (wdev->iftype == NL80211_IFTYPE_NAN)
6722 return -EOPNOTSUPP;
6723
Johannes Berg4c476992010-10-04 21:36:35 +02006724 if (!rdev->ops->scan)
6725 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006726
Johannes Bergf9d15d12014-01-22 11:14:19 +02006727 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006728 err = -EBUSY;
6729 goto unlock;
6730 }
Johannes Berg2a519312009-02-10 21:25:55 +01006731
6732 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006733 n_channels = validate_scan_freqs(
6734 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006735 if (!n_channels) {
6736 err = -EINVAL;
6737 goto unlock;
6738 }
Johannes Berg2a519312009-02-10 21:25:55 +01006739 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006740 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006741 }
6742
6743 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6744 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6745 n_ssids++;
6746
Johannes Bergf9f47522013-03-19 15:04:07 +01006747 if (n_ssids > wiphy->max_scan_ssids) {
6748 err = -EINVAL;
6749 goto unlock;
6750 }
Johannes Berg2a519312009-02-10 21:25:55 +01006751
Jouni Malinen70692ad2009-02-16 19:39:13 +02006752 if (info->attrs[NL80211_ATTR_IE])
6753 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6754 else
6755 ie_len = 0;
6756
Johannes Bergf9f47522013-03-19 15:04:07 +01006757 if (ie_len > wiphy->max_scan_ie_len) {
6758 err = -EINVAL;
6759 goto unlock;
6760 }
Johannes Berg18a83652009-03-31 12:12:05 +02006761
Johannes Berg2a519312009-02-10 21:25:55 +01006762 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006763 + sizeof(*request->ssids) * n_ssids
6764 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006765 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006766 if (!request) {
6767 err = -ENOMEM;
6768 goto unlock;
6769 }
Johannes Berg2a519312009-02-10 21:25:55 +01006770
Johannes Berg2a519312009-02-10 21:25:55 +01006771 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006772 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006773 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006774 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006775 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006776 request->ie = (void *)(request->ssids + n_ssids);
6777 else
6778 request->ie = (void *)(request->channels + n_channels);
6779 }
Johannes Berg2a519312009-02-10 21:25:55 +01006780
Johannes Berg584991d2009-11-02 13:32:03 +01006781 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006782 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6783 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006784 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006785 struct ieee80211_channel *chan;
6786
6787 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6788
6789 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006790 err = -EINVAL;
6791 goto out_free;
6792 }
Johannes Berg584991d2009-11-02 13:32:03 +01006793
6794 /* ignore disabled channels */
6795 if (chan->flags & IEEE80211_CHAN_DISABLED)
6796 continue;
6797
6798 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006799 i++;
6800 }
6801 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006802 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006803
Johannes Berg2a519312009-02-10 21:25:55 +01006804 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006805 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006806 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006807
Johannes Berg2a519312009-02-10 21:25:55 +01006808 if (!wiphy->bands[band])
6809 continue;
6810 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006811 struct ieee80211_channel *chan;
6812
6813 chan = &wiphy->bands[band]->channels[j];
6814
6815 if (chan->flags & IEEE80211_CHAN_DISABLED)
6816 continue;
6817
6818 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006819 i++;
6820 }
6821 }
6822 }
6823
Johannes Berg584991d2009-11-02 13:32:03 +01006824 if (!i) {
6825 err = -EINVAL;
6826 goto out_free;
6827 }
6828
6829 request->n_channels = i;
6830
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306831 wdev_lock(wdev);
6832 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6833 struct ieee80211_channel *chan;
6834
6835 if (request->n_channels != 1) {
6836 wdev_unlock(wdev);
6837 err = -EBUSY;
6838 goto out_free;
6839 }
6840
6841 chan = request->channels[0];
6842 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6843 wdev_unlock(wdev);
6844 err = -EBUSY;
6845 goto out_free;
6846 }
6847 }
6848 wdev_unlock(wdev);
6849
Johannes Berg2a519312009-02-10 21:25:55 +01006850 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006851 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006852 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006853 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006854 err = -EINVAL;
6855 goto out_free;
6856 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006857 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006858 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006859 i++;
6860 }
6861 }
6862
Jouni Malinen70692ad2009-02-16 19:39:13 +02006863 if (info->attrs[NL80211_ATTR_IE]) {
6864 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006865 memcpy((void *)request->ie,
6866 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006867 request->ie_len);
6868 }
6869
Johannes Berg57fbcce2016-04-12 15:56:15 +02006870 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006871 if (wiphy->bands[i])
6872 request->rates[i] =
6873 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006874
6875 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6876 nla_for_each_nested(attr,
6877 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6878 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006879 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006880
Johannes Berg57fbcce2016-04-12 15:56:15 +02006881 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006882 err = -EINVAL;
6883 goto out_free;
6884 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006885
6886 if (!wiphy->bands[band])
6887 continue;
6888
Johannes Berg34850ab2011-07-18 18:08:35 +02006889 err = ieee80211_get_ratemask(wiphy->bands[band],
6890 nla_data(attr),
6891 nla_len(attr),
6892 &request->rates[band]);
6893 if (err)
6894 goto out_free;
6895 }
6896 }
6897
Avraham Stern1d762502016-07-05 17:10:13 +03006898 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6899 if (!wiphy_ext_feature_isset(wiphy,
6900 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6901 err = -EOPNOTSUPP;
6902 goto out_free;
6903 }
6904
6905 request->duration =
6906 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6907 request->duration_mandatory =
6908 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6909 }
6910
Roee Zamir2d23d072017-08-06 11:38:22 +03006911 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
6912 false);
6913 if (err)
6914 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07006915
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306916 request->no_cck =
6917 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6918
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006919 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6920 * BSSID to scan for. This was problematic because that same attribute
6921 * was already used for another purpose (local random MAC address). The
6922 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6923 * compatibility with older userspace components, also use the
6924 * NL80211_ATTR_MAC value here if it can be determined to be used for
6925 * the specific BSSID use case instead of the random MAC address
6926 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6927 */
6928 if (info->attrs[NL80211_ATTR_BSSID])
6929 memcpy(request->bssid,
6930 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6931 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6932 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006933 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6934 ETH_ALEN);
6935 else
6936 eth_broadcast_addr(request->bssid);
6937
Johannes Bergfd014282012-06-18 19:17:03 +02006938 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006939 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006940 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006941
Johannes Berg79c97e92009-07-07 03:56:12 +02006942 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006943 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006944
Johannes Berg463d0182009-07-14 00:33:35 +02006945 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006946 nl80211_send_scan_start(rdev, wdev);
6947 if (wdev->netdev)
6948 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006949 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006950 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006951 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006952 kfree(request);
6953 }
Johannes Berg3b858752009-03-12 09:55:09 +01006954
Johannes Bergf9f47522013-03-19 15:04:07 +01006955 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006956 return err;
6957}
6958
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306959static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6960{
6961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6962 struct wireless_dev *wdev = info->user_ptr[1];
6963
6964 if (!rdev->ops->abort_scan)
6965 return -EOPNOTSUPP;
6966
6967 if (rdev->scan_msg)
6968 return 0;
6969
6970 if (!rdev->scan_req)
6971 return -ENOENT;
6972
6973 rdev_abort_scan(rdev, wdev);
6974 return 0;
6975}
6976
Avraham Stern3b06d272015-10-12 09:51:34 +03006977static int
6978nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6979 struct cfg80211_sched_scan_request *request,
6980 struct nlattr **attrs)
6981{
6982 int tmp, err, i = 0;
6983 struct nlattr *attr;
6984
6985 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6986 u32 interval;
6987
6988 /*
6989 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006990 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006991 * case one scan plan will be set with the specified scan
6992 * interval and infinite number of iterations.
6993 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006994 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6995 if (!interval)
6996 return -EINVAL;
6997
6998 request->scan_plans[0].interval =
6999 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7000 if (!request->scan_plans[0].interval)
7001 return -EINVAL;
7002
7003 if (request->scan_plans[0].interval >
7004 wiphy->max_sched_scan_plan_interval)
7005 request->scan_plans[0].interval =
7006 wiphy->max_sched_scan_plan_interval;
7007
7008 return 0;
7009 }
7010
7011 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7012 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7013
7014 if (WARN_ON(i >= n_plans))
7015 return -EINVAL;
7016
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007017 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007018 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007019 if (err)
7020 return err;
7021
7022 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7023 return -EINVAL;
7024
7025 request->scan_plans[i].interval =
7026 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7027 if (!request->scan_plans[i].interval ||
7028 request->scan_plans[i].interval >
7029 wiphy->max_sched_scan_plan_interval)
7030 return -EINVAL;
7031
7032 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7033 request->scan_plans[i].iterations =
7034 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7035 if (!request->scan_plans[i].iterations ||
7036 (request->scan_plans[i].iterations >
7037 wiphy->max_sched_scan_plan_iterations))
7038 return -EINVAL;
7039 } else if (i < n_plans - 1) {
7040 /*
7041 * All scan plans but the last one must specify
7042 * a finite number of iterations
7043 */
7044 return -EINVAL;
7045 }
7046
7047 i++;
7048 }
7049
7050 /*
7051 * The last scan plan must not specify the number of
7052 * iterations, it is supposed to run infinitely
7053 */
7054 if (request->scan_plans[n_plans - 1].iterations)
7055 return -EINVAL;
7056
7057 return 0;
7058}
7059
Luciano Coelho256da022014-11-10 16:13:46 +02007060static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007061nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007062 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007063{
7064 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007065 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007066 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007067 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007068 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007069 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007070 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007071
Luciano Coelho256da022014-11-10 16:13:46 +02007072 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7073 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007074
Luciano Coelho256da022014-11-10 16:13:46 +02007075 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007076 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007077 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007078 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007079 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007080 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007081 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007082 }
7083
Luciano Coelho256da022014-11-10 16:13:46 +02007084 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7085 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007086 tmp)
7087 n_ssids++;
7088
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007089 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007090 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007091
Johannes Bergea73cbc2014-01-24 10:53:53 +01007092 /*
7093 * First, count the number of 'real' matchsets. Due to an issue with
7094 * the old implementation, matchsets containing only the RSSI attribute
7095 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7096 * RSSI for all matchsets, rather than their own matchset for reporting
7097 * all APs with a strong RSSI. This is needed to be compatible with
7098 * older userspace that treated a matchset with only the RSSI as the
7099 * global RSSI for all other matchsets - if there are other matchsets.
7100 */
Luciano Coelho256da022014-11-10 16:13:46 +02007101 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007102 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007103 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007104 tmp) {
7105 struct nlattr *rssi;
7106
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007107 err = nla_parse_nested(tb,
7108 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007109 attr, nl80211_match_policy,
7110 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007111 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007112 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007113
7114 /* SSID and BSSID are mutually exclusive */
7115 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7116 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7117 return ERR_PTR(-EINVAL);
7118
Johannes Bergea73cbc2014-01-24 10:53:53 +01007119 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007120 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7121 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007122 n_match_sets++;
7123 continue;
7124 }
7125 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7126 if (rssi)
7127 default_match_rssi = nla_get_s32(rssi);
7128 }
7129 }
7130
7131 /* However, if there's no other matchset, add the RSSI one */
7132 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7133 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007134
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007135 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007136 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007137
Luciano Coelho256da022014-11-10 16:13:46 +02007138 if (attrs[NL80211_ATTR_IE])
7139 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007140 else
7141 ie_len = 0;
7142
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007143 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007144 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007145
Avraham Stern3b06d272015-10-12 09:51:34 +03007146 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7147 /*
7148 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7149 * each scan plan already specifies its own interval
7150 */
7151 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7152 return ERR_PTR(-EINVAL);
7153
7154 nla_for_each_nested(attr,
7155 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7156 n_plans++;
7157 } else {
7158 /*
7159 * The scan interval attribute is kept for backward
7160 * compatibility. If no scan plans are specified and sched scan
7161 * interval is specified, one scan plan will be set with this
7162 * scan interval and infinite number of iterations.
7163 */
7164 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7165 return ERR_PTR(-EINVAL);
7166
7167 n_plans = 1;
7168 }
7169
7170 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7171 return ERR_PTR(-EINVAL);
7172
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007173 if (!wiphy_ext_feature_isset(
7174 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7175 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7176 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7177 return ERR_PTR(-EINVAL);
7178
Luciano Coelho807f8a82011-05-11 17:09:35 +03007179 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007180 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007181 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007182 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007183 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007184 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007185 if (!request)
7186 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007187
7188 if (n_ssids)
7189 request->ssids = (void *)&request->channels[n_channels];
7190 request->n_ssids = n_ssids;
7191 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007192 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007193 request->ie = (void *)(request->ssids + n_ssids);
7194 else
7195 request->ie = (void *)(request->channels + n_channels);
7196 }
7197
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007198 if (n_match_sets) {
7199 if (request->ie)
7200 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007201 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007202 request->match_sets =
7203 (void *)(request->ssids + n_ssids);
7204 else
7205 request->match_sets =
7206 (void *)(request->channels + n_channels);
7207 }
7208 request->n_match_sets = n_match_sets;
7209
Avraham Stern3b06d272015-10-12 09:51:34 +03007210 if (n_match_sets)
7211 request->scan_plans = (void *)(request->match_sets +
7212 n_match_sets);
7213 else if (request->ie)
7214 request->scan_plans = (void *)(request->ie + ie_len);
7215 else if (n_ssids)
7216 request->scan_plans = (void *)(request->ssids + n_ssids);
7217 else
7218 request->scan_plans = (void *)(request->channels + n_channels);
7219
7220 request->n_scan_plans = n_plans;
7221
Luciano Coelho807f8a82011-05-11 17:09:35 +03007222 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007223 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007224 /* user specified, bail out if channel not found */
7225 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007226 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007227 tmp) {
7228 struct ieee80211_channel *chan;
7229
7230 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7231
7232 if (!chan) {
7233 err = -EINVAL;
7234 goto out_free;
7235 }
7236
7237 /* ignore disabled channels */
7238 if (chan->flags & IEEE80211_CHAN_DISABLED)
7239 continue;
7240
7241 request->channels[i] = chan;
7242 i++;
7243 }
7244 } else {
7245 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007246 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007247 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007248
Luciano Coelho807f8a82011-05-11 17:09:35 +03007249 if (!wiphy->bands[band])
7250 continue;
7251 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7252 struct ieee80211_channel *chan;
7253
7254 chan = &wiphy->bands[band]->channels[j];
7255
7256 if (chan->flags & IEEE80211_CHAN_DISABLED)
7257 continue;
7258
7259 request->channels[i] = chan;
7260 i++;
7261 }
7262 }
7263 }
7264
7265 if (!i) {
7266 err = -EINVAL;
7267 goto out_free;
7268 }
7269
7270 request->n_channels = i;
7271
7272 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007273 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007274 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007275 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007276 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007277 err = -EINVAL;
7278 goto out_free;
7279 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007280 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007281 memcpy(request->ssids[i].ssid, nla_data(attr),
7282 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007283 i++;
7284 }
7285 }
7286
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007287 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007288 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007289 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007290 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007291 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007292 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007293
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007294 err = nla_parse_nested(tb,
7295 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007296 attr, nl80211_match_policy,
7297 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007298 if (err)
7299 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007300 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007301 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7302 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007303 if (WARN_ON(i >= n_match_sets)) {
7304 /* this indicates a programming error,
7305 * the loop above should have verified
7306 * things properly
7307 */
7308 err = -EINVAL;
7309 goto out_free;
7310 }
7311
Arend Van Spriel3007e352017-04-21 13:05:01 +01007312 if (ssid) {
7313 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7314 err = -EINVAL;
7315 goto out_free;
7316 }
7317 memcpy(request->match_sets[i].ssid.ssid,
7318 nla_data(ssid), nla_len(ssid));
7319 request->match_sets[i].ssid.ssid_len =
7320 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007321 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007322 if (bssid) {
7323 if (nla_len(bssid) != ETH_ALEN) {
7324 err = -EINVAL;
7325 goto out_free;
7326 }
7327 memcpy(request->match_sets[i].bssid,
7328 nla_data(bssid), ETH_ALEN);
7329 }
7330
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007331 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007332 request->match_sets[i].rssi_thold =
7333 default_match_rssi;
7334 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7335 if (rssi)
7336 request->match_sets[i].rssi_thold =
7337 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007338 }
7339 i++;
7340 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007341
7342 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007343 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007344 request->match_sets[0].rssi_thold = default_match_rssi;
7345
7346 request->min_rssi_thold = INT_MAX;
7347 for (i = 0; i < n_match_sets; i++)
7348 request->min_rssi_thold =
7349 min(request->match_sets[i].rssi_thold,
7350 request->min_rssi_thold);
7351 } else {
7352 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007353 }
7354
Johannes Berg9900e482014-02-04 21:01:25 +01007355 if (ie_len) {
7356 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007357 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007358 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007359 request->ie_len);
7360 }
7361
Roee Zamir2d23d072017-08-06 11:38:22 +03007362 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7363 if (err)
7364 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007365
Luciano Coelho9c748932015-01-16 16:04:09 +02007366 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7367 request->delay =
7368 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7369
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007370 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7371 request->relative_rssi = nla_get_s8(
7372 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7373 request->relative_rssi_set = true;
7374 }
7375
7376 if (request->relative_rssi_set &&
7377 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7378 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7379
7380 rssi_adjust = nla_data(
7381 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7382 request->rssi_adjust.band = rssi_adjust->band;
7383 request->rssi_adjust.delta = rssi_adjust->delta;
7384 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7385 err = -EINVAL;
7386 goto out_free;
7387 }
7388 }
7389
Avraham Stern3b06d272015-10-12 09:51:34 +03007390 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7391 if (err)
7392 goto out_free;
7393
Sam Leffler15d60302012-10-11 21:03:34 -07007394 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007395
Luciano Coelho256da022014-11-10 16:13:46 +02007396 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007397
7398out_free:
7399 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007400 return ERR_PTR(err);
7401}
7402
7403static int nl80211_start_sched_scan(struct sk_buff *skb,
7404 struct genl_info *info)
7405{
7406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7407 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007408 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007409 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007410 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007411 int err;
7412
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007413 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007414 return -EOPNOTSUPP;
7415
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007416 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7417 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7418 if (err)
7419 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007420
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007421 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007422 info->attrs,
7423 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007424
7425 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007426 if (err)
7427 goto out_err;
7428
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007429 /* leave request id zero for legacy request
7430 * or if driver does not support multi-scheduled scan
7431 */
7432 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7433 while (!sched_scan_req->reqid)
7434 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7435 }
7436
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007437 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007438 if (err)
7439 goto out_free;
7440
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007441 sched_scan_req->dev = dev;
7442 sched_scan_req->wiphy = &rdev->wiphy;
7443
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007444 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7445 sched_scan_req->owner_nlportid = info->snd_portid;
7446
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007447 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007448
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007449 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007450 return 0;
7451
7452out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007453 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007454out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007455 return err;
7456}
7457
7458static int nl80211_stop_sched_scan(struct sk_buff *skb,
7459 struct genl_info *info)
7460{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007461 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007463 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007464
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007465 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007466 return -EOPNOTSUPP;
7467
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007468 if (info->attrs[NL80211_ATTR_COOKIE]) {
7469 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7470 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7471 }
7472
7473 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7474 struct cfg80211_sched_scan_request,
7475 list);
7476 if (!req || req->reqid ||
7477 (req->owner_nlportid &&
7478 req->owner_nlportid != info->snd_portid))
7479 return -ENOENT;
7480
7481 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007482}
7483
Simon Wunderlich04f39042013-02-08 18:16:19 +01007484static int nl80211_start_radar_detection(struct sk_buff *skb,
7485 struct genl_info *info)
7486{
7487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7488 struct net_device *dev = info->user_ptr[1];
7489 struct wireless_dev *wdev = dev->ieee80211_ptr;
7490 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007491 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007492 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007493 int err;
7494
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007495 dfs_region = reg_get_dfs_region(wdev->wiphy);
7496 if (dfs_region == NL80211_DFS_UNSET)
7497 return -EINVAL;
7498
Simon Wunderlich04f39042013-02-08 18:16:19 +01007499 err = nl80211_parse_chandef(rdev, info, &chandef);
7500 if (err)
7501 return err;
7502
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007503 if (netif_carrier_ok(dev))
7504 return -EBUSY;
7505
Simon Wunderlich04f39042013-02-08 18:16:19 +01007506 if (wdev->cac_started)
7507 return -EBUSY;
7508
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007509 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007510 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007511 if (err < 0)
7512 return err;
7513
7514 if (err == 0)
7515 return -EINVAL;
7516
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007517 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007518 return -EINVAL;
7519
7520 if (!rdev->ops->start_radar_detection)
7521 return -EOPNOTSUPP;
7522
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007523 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7524 if (WARN_ON(!cac_time_ms))
7525 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7526
Ilan Peera1056b12015-10-22 22:27:46 +03007527 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007528 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007529 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007530 wdev->cac_started = true;
7531 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007532 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007533 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007534 return err;
7535}
7536
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007537static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7538{
7539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7540 struct net_device *dev = info->user_ptr[1];
7541 struct wireless_dev *wdev = dev->ieee80211_ptr;
7542 struct cfg80211_csa_settings params;
7543 /* csa_attrs is defined static to avoid waste of stack size - this
7544 * function is called under RTNL lock, so this should not be a problem.
7545 */
7546 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007547 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007548 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007549 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007550 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007551 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007552
7553 if (!rdev->ops->channel_switch ||
7554 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7555 return -EOPNOTSUPP;
7556
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007557 switch (dev->ieee80211_ptr->iftype) {
7558 case NL80211_IFTYPE_AP:
7559 case NL80211_IFTYPE_P2P_GO:
7560 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007561 /* For all modes except AP the handle_dfs flag needs to be
7562 * supplied to tell the kernel that userspace will handle radar
7563 * events when they happen. Otherwise a switch to a channel
7564 * requiring DFS will be rejected.
7565 */
7566 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007567
7568 /* useless if AP is not running */
7569 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007570 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007571 break;
7572 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007573 if (!wdev->ssid_len)
7574 return -ENOTCONN;
7575 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007576 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007577 if (!wdev->mesh_id_len)
7578 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007579 break;
7580 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007581 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007582 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007583
7584 memset(&params, 0, sizeof(params));
7585
7586 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7587 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7588 return -EINVAL;
7589
7590 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007591 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007592 return -EINVAL;
7593
Luciano Coelho252e07c2014-10-08 09:48:34 +03007594 /* Even though the attribute is u32, the specification says
7595 * u8, so let's make sure we don't overflow.
7596 */
7597 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7598 if (cs_count > 255)
7599 return -EINVAL;
7600
7601 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007602
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007603 if (!need_new_beacon)
7604 goto skip_beacons;
7605
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007606 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7607 if (err)
7608 return err;
7609
7610 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7611 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007612 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007613 if (err)
7614 return err;
7615
7616 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7617 if (err)
7618 return err;
7619
7620 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7621 return -EINVAL;
7622
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007623 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7624 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007625 return -EINVAL;
7626
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007627 params.n_counter_offsets_beacon = len / sizeof(u16);
7628 if (rdev->wiphy.max_num_csa_counters &&
7629 (params.n_counter_offsets_beacon >
7630 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007631 return -EINVAL;
7632
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007633 params.counter_offsets_beacon =
7634 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7635
7636 /* sanity checks - counters should fit and be the same */
7637 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7638 u16 offset = params.counter_offsets_beacon[i];
7639
7640 if (offset >= params.beacon_csa.tail_len)
7641 return -EINVAL;
7642
7643 if (params.beacon_csa.tail[offset] != params.count)
7644 return -EINVAL;
7645 }
7646
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007647 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007648 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7649 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007650 return -EINVAL;
7651
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007652 params.n_counter_offsets_presp = len / sizeof(u16);
7653 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007654 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007655 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007656 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007657
7658 params.counter_offsets_presp =
7659 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7660
7661 /* sanity checks - counters should fit and be the same */
7662 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7663 u16 offset = params.counter_offsets_presp[i];
7664
7665 if (offset >= params.beacon_csa.probe_resp_len)
7666 return -EINVAL;
7667
7668 if (params.beacon_csa.probe_resp[offset] !=
7669 params.count)
7670 return -EINVAL;
7671 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007672 }
7673
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007674skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007675 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7676 if (err)
7677 return err;
7678
Arik Nemtsov923b3522015-07-08 15:41:44 +03007679 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7680 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007681 return -EINVAL;
7682
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007683 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7684 &params.chandef,
7685 wdev->iftype);
7686 if (err < 0)
7687 return err;
7688
Benjamin Berg8d9de162017-05-16 11:23:12 +02007689 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007690 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007691 if (need_handle_dfs_flag &&
7692 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7693 return -EINVAL;
7694 }
7695 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007696
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007697 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7698 params.block_tx = true;
7699
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007700 wdev_lock(wdev);
7701 err = rdev_channel_switch(rdev, dev, &params);
7702 wdev_unlock(wdev);
7703
7704 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007705}
7706
Johannes Berg9720bb32011-06-21 09:45:33 +02007707static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7708 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007709 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007710 struct wireless_dev *wdev,
7711 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007712{
Johannes Berg48ab9052009-07-10 18:42:31 +02007713 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007714 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007715 void *hdr;
7716 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007717
7718 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007719
Eric W. Biederman15e47302012-09-07 20:12:54 +00007720 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007721 NL80211_CMD_NEW_SCAN_RESULTS);
7722 if (!hdr)
7723 return -1;
7724
Michal Kubecek0a833c22017-11-15 13:09:32 +01007725 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02007726
Johannes Berg97990a02013-04-19 01:02:55 +02007727 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7728 goto nla_put_failure;
7729 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007730 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7731 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007732 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7733 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007734 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007735
7736 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7737 if (!bss)
7738 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007739 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007740 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007742
7743 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007744 /* indicate whether we have probe response data or not */
7745 if (rcu_access_pointer(res->proberesp_ies) &&
7746 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7747 goto fail_unlock_rcu;
7748
7749 /* this pointer prefers to be pointed to probe response data
7750 * but is always valid
7751 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007752 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007753 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007754 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7755 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007756 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007757 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7758 ies->len, ies->data))
7759 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007760 }
Johannes Berg0e227082014-08-12 20:34:30 +02007761
7762 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007763 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007764 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007765 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7766 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007767 goto fail_unlock_rcu;
7768 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7769 ies->len, ies->data))
7770 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007771 }
7772 rcu_read_unlock();
7773
David S. Miller9360ffd2012-03-29 04:41:26 -04007774 if (res->beacon_interval &&
7775 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7776 goto nla_put_failure;
7777 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7778 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007779 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007780 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7781 jiffies_to_msecs(jiffies - intbss->ts)))
7782 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007783
Avraham Stern1d762502016-07-05 17:10:13 +03007784 if (intbss->parent_tsf &&
7785 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7786 intbss->parent_tsf, NL80211_BSS_PAD) ||
7787 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7788 intbss->parent_bssid)))
7789 goto nla_put_failure;
7790
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007791 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007792 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7793 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007794 goto nla_put_failure;
7795
Johannes Berg77965c92009-02-18 18:45:06 +01007796 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007797 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007798 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7799 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007800 break;
7801 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007802 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7803 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007804 break;
7805 default:
7806 break;
7807 }
7808
Johannes Berg48ab9052009-07-10 18:42:31 +02007809 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007810 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007811 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007812 if (intbss == wdev->current_bss &&
7813 nla_put_u32(msg, NL80211_BSS_STATUS,
7814 NL80211_BSS_STATUS_ASSOCIATED))
7815 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007816 break;
7817 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007818 if (intbss == wdev->current_bss &&
7819 nla_put_u32(msg, NL80211_BSS_STATUS,
7820 NL80211_BSS_STATUS_IBSS_JOINED))
7821 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007822 break;
7823 default:
7824 break;
7825 }
7826
Johannes Berg2a519312009-02-10 21:25:55 +01007827 nla_nest_end(msg, bss);
7828
Johannes Berg053c0952015-01-16 22:09:00 +01007829 genlmsg_end(msg, hdr);
7830 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007831
Johannes Berg8cef2c92013-02-05 16:54:31 +01007832 fail_unlock_rcu:
7833 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007834 nla_put_failure:
7835 genlmsg_cancel(msg, hdr);
7836 return -EMSGSIZE;
7837}
7838
Johannes Berg97990a02013-04-19 01:02:55 +02007839static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007840{
Johannes Berg48ab9052009-07-10 18:42:31 +02007841 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007842 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007843 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007844 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007845 int err;
7846
Johannes Bergea90e0d2017-03-15 14:26:04 +01007847 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007848 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007849 if (err) {
7850 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007851 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007852 }
Johannes Berg2a519312009-02-10 21:25:55 +01007853
Johannes Berg48ab9052009-07-10 18:42:31 +02007854 wdev_lock(wdev);
7855 spin_lock_bh(&rdev->bss_lock);
7856 cfg80211_bss_expire(rdev);
7857
Johannes Berg9720bb32011-06-21 09:45:33 +02007858 cb->seq = rdev->bss_generation;
7859
Johannes Berg48ab9052009-07-10 18:42:31 +02007860 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007861 if (++idx <= start)
7862 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007863 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007864 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007865 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007866 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007867 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007868 }
7869 }
7870
Johannes Berg48ab9052009-07-10 18:42:31 +02007871 spin_unlock_bh(&rdev->bss_lock);
7872 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007873
Johannes Berg97990a02013-04-19 01:02:55 +02007874 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007875 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007876
Johannes Berg67748892010-10-04 21:14:06 +02007877 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007878}
7879
Eric W. Biederman15e47302012-09-07 20:12:54 +00007880static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007881 int flags, struct net_device *dev,
7882 bool allow_radio_stats,
7883 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007884{
7885 void *hdr;
7886 struct nlattr *infoattr;
7887
Johannes Berg11f78ac2014-11-14 16:43:50 +01007888 /* skip radio stats if userspace didn't request them */
7889 if (!survey->channel && !allow_radio_stats)
7890 return 0;
7891
Eric W. Biederman15e47302012-09-07 20:12:54 +00007892 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007893 NL80211_CMD_NEW_SURVEY_RESULTS);
7894 if (!hdr)
7895 return -ENOMEM;
7896
David S. Miller9360ffd2012-03-29 04:41:26 -04007897 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7898 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007899
7900 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7901 if (!infoattr)
7902 goto nla_put_failure;
7903
Johannes Berg11f78ac2014-11-14 16:43:50 +01007904 if (survey->channel &&
7905 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007906 survey->channel->center_freq))
7907 goto nla_put_failure;
7908
7909 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7910 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7911 goto nla_put_failure;
7912 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7913 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7914 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007915 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007916 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7917 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007918 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007919 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007920 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7921 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007922 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007923 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007924 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7925 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007926 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007927 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007928 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7929 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007930 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007931 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007932 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7933 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007934 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007935 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007936 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7937 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007938 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007939
7940 nla_nest_end(msg, infoattr);
7941
Johannes Berg053c0952015-01-16 22:09:00 +01007942 genlmsg_end(msg, hdr);
7943 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007944
7945 nla_put_failure:
7946 genlmsg_cancel(msg, hdr);
7947 return -EMSGSIZE;
7948}
7949
Johannes Berg11f78ac2014-11-14 16:43:50 +01007950static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007951{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007952 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007953 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007954 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007955 struct wireless_dev *wdev;
7956 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007957 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007958 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007959
Johannes Bergea90e0d2017-03-15 14:26:04 +01007960 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007961 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007962 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007963 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007964
Johannes Berg11f78ac2014-11-14 16:43:50 +01007965 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007966 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007967
Johannes Berg97990a02013-04-19 01:02:55 +02007968 if (!wdev->netdev) {
7969 res = -EINVAL;
7970 goto out_err;
7971 }
7972
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007973 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007974 res = -EOPNOTSUPP;
7975 goto out_err;
7976 }
7977
7978 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007979 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007980 if (res == -ENOENT)
7981 break;
7982 if (res)
7983 goto out_err;
7984
Johannes Berg11f78ac2014-11-14 16:43:50 +01007985 /* don't send disabled channels, but do send non-channel data */
7986 if (survey.channel &&
7987 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007988 survey_idx++;
7989 continue;
7990 }
7991
Holger Schurig61fa7132009-11-11 12:25:40 +01007992 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007993 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007994 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007995 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007996 goto out;
7997 survey_idx++;
7998 }
7999
8000 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008001 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008002 res = skb->len;
8003 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008004 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008005 return res;
8006}
8007
Samuel Ortizb23aa672009-07-01 21:26:54 +02008008static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8009{
8010 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8011 NL80211_WPA_VERSION_2));
8012}
8013
Jouni Malinen636a5d32009-03-19 13:39:22 +02008014static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8015{
Johannes Berg4c476992010-10-04 21:36:35 +02008016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8017 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008018 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008019 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8020 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008021 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008022 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008023 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008024
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008025 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8026 return -EINVAL;
8027
8028 if (!info->attrs[NL80211_ATTR_MAC])
8029 return -EINVAL;
8030
Jouni Malinen17780922009-03-27 20:52:47 +02008031 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8032 return -EINVAL;
8033
Johannes Berg19957bb2009-07-02 17:20:43 +02008034 if (!info->attrs[NL80211_ATTR_SSID])
8035 return -EINVAL;
8036
8037 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8038 return -EINVAL;
8039
Johannes Bergfffd0932009-07-08 14:22:54 +02008040 err = nl80211_parse_key(info, &key);
8041 if (err)
8042 return err;
8043
8044 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008045 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8046 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008047 if (!key.p.key || !key.p.key_len)
8048 return -EINVAL;
8049 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8050 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8051 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8052 key.p.key_len != WLAN_KEY_LEN_WEP104))
8053 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008054 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008055 return -EINVAL;
8056 } else {
8057 key.p.key_len = 0;
8058 key.p.key = NULL;
8059 }
8060
Johannes Bergafea0b72010-08-10 09:46:42 +02008061 if (key.idx >= 0) {
8062 int i;
8063 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008064
Johannes Bergafea0b72010-08-10 09:46:42 +02008065 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8066 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8067 ok = true;
8068 break;
8069 }
8070 }
Johannes Berg4c476992010-10-04 21:36:35 +02008071 if (!ok)
8072 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008073 }
8074
Johannes Berg4c476992010-10-04 21:36:35 +02008075 if (!rdev->ops->auth)
8076 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008077
Johannes Berg074ac8d2010-09-16 14:58:22 +02008078 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008079 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8080 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008081
Johannes Berg19957bb2009-07-02 17:20:43 +02008082 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008083 chan = nl80211_get_valid_chan(&rdev->wiphy,
8084 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8085 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008086 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008087
Johannes Berg19957bb2009-07-02 17:20:43 +02008088 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8089 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8090
8091 if (info->attrs[NL80211_ATTR_IE]) {
8092 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8093 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8094 }
8095
8096 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008097 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008098 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008099
Jouni Malinen63181062016-10-27 00:42:02 +03008100 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8101 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8102 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8103 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008104 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008105 return -EINVAL;
8106
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008107 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008108 if (auth_type != NL80211_AUTHTYPE_SAE &&
8109 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8110 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8111 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008112 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008113 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8114 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008115 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008116 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008117 return -EINVAL;
8118 }
8119
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008120 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8121
Johannes Berg95de8172012-01-20 13:55:25 +01008122 /*
8123 * Since we no longer track auth state, ignore
8124 * requests to only change local state.
8125 */
8126 if (local_state_change)
8127 return 0;
8128
Johannes Berg91bf9b22013-05-15 17:44:01 +02008129 wdev_lock(dev->ieee80211_ptr);
8130 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8131 ssid, ssid_len, ie, ie_len,
8132 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008133 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008134 wdev_unlock(dev->ieee80211_ptr);
8135 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008136}
8137
Johannes Bergc0692b82010-08-27 14:26:53 +03008138static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8139 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008140 struct cfg80211_crypto_settings *settings,
8141 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008142{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008143 memset(settings, 0, sizeof(*settings));
8144
Samuel Ortizb23aa672009-07-01 21:26:54 +02008145 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8146
Johannes Bergc0692b82010-08-27 14:26:53 +03008147 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8148 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008149
Johannes Bergc0692b82010-08-27 14:26:53 +03008150 proto = nla_get_u16(
8151 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8152 settings->control_port_ethertype = cpu_to_be16(proto);
8153 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8154 proto != ETH_P_PAE)
8155 return -EINVAL;
8156 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8157 settings->control_port_no_encrypt = true;
8158 } else
8159 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8160
Samuel Ortizb23aa672009-07-01 21:26:54 +02008161 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8162 void *data;
8163 int len, i;
8164
8165 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8166 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8167 settings->n_ciphers_pairwise = len / sizeof(u32);
8168
8169 if (len % sizeof(u32))
8170 return -EINVAL;
8171
Johannes Berg3dc27d22009-07-02 21:36:37 +02008172 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008173 return -EINVAL;
8174
8175 memcpy(settings->ciphers_pairwise, data, len);
8176
8177 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008178 if (!cfg80211_supported_cipher_suite(
8179 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180 settings->ciphers_pairwise[i]))
8181 return -EINVAL;
8182 }
8183
8184 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8185 settings->cipher_group =
8186 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008187 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8188 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008189 return -EINVAL;
8190 }
8191
8192 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8193 settings->wpa_versions =
8194 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8195 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8196 return -EINVAL;
8197 }
8198
8199 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8200 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008201 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008202
8203 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8204 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8205 settings->n_akm_suites = len / sizeof(u32);
8206
8207 if (len % sizeof(u32))
8208 return -EINVAL;
8209
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008210 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8211 return -EINVAL;
8212
Samuel Ortizb23aa672009-07-01 21:26:54 +02008213 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008214 }
8215
Eliad Peller91b5ab62017-06-09 13:08:42 +01008216 if (info->attrs[NL80211_ATTR_PMK]) {
8217 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8218 return -EINVAL;
8219 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8220 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8221 return -EINVAL;
8222 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8223 }
8224
Samuel Ortizb23aa672009-07-01 21:26:54 +02008225 return 0;
8226}
8227
Jouni Malinen636a5d32009-03-19 13:39:22 +02008228static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8229{
Johannes Berg4c476992010-10-04 21:36:35 +02008230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8231 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008232 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008233 struct cfg80211_assoc_request req = {};
8234 const u8 *bssid, *ssid;
8235 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008236
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008237 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8238 return -EINVAL;
8239
8240 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008241 !info->attrs[NL80211_ATTR_SSID] ||
8242 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008243 return -EINVAL;
8244
Johannes Berg4c476992010-10-04 21:36:35 +02008245 if (!rdev->ops->assoc)
8246 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008247
Johannes Berg074ac8d2010-09-16 14:58:22 +02008248 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008249 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8250 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008251
Johannes Berg19957bb2009-07-02 17:20:43 +02008252 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008253
Jouni Malinen664834d2014-01-15 00:01:44 +02008254 chan = nl80211_get_valid_chan(&rdev->wiphy,
8255 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8256 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008257 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008258
Johannes Berg19957bb2009-07-02 17:20:43 +02008259 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8260 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008261
8262 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008263 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8264 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008265 }
8266
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008267 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008268 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008269 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008270 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008271 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008272 else if (mfp != NL80211_MFP_NO)
8273 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008274 }
8275
Johannes Berg3e5d7642009-07-07 14:37:26 +02008276 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008277 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008278
Ben Greear7e7c8922011-11-18 11:31:59 -08008279 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008280 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008281
8282 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008283 memcpy(&req.ht_capa_mask,
8284 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8285 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008286
8287 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008288 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008289 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008290 memcpy(&req.ht_capa,
8291 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8292 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008293 }
8294
Johannes Bergee2aca32013-02-21 17:36:01 +01008295 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008296 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008297
8298 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008299 memcpy(&req.vht_capa_mask,
8300 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8301 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008302
8303 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008304 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008305 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008306 memcpy(&req.vht_capa,
8307 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8308 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008309 }
8310
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008311 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008312 if (!((rdev->wiphy.features &
8313 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8314 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8315 !wiphy_ext_feature_isset(&rdev->wiphy,
8316 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008317 return -EINVAL;
8318 req.flags |= ASSOC_REQ_USE_RRM;
8319 }
8320
Jouni Malinen348bd452016-10-27 00:42:03 +03008321 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8322 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8323 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8324 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8325 return -EINVAL;
8326 req.fils_nonces =
8327 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8328 }
8329
Johannes Bergf62fab72013-02-21 20:09:09 +01008330 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008331 if (!err) {
8332 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008333
Johannes Bergf62fab72013-02-21 20:09:09 +01008334 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8335 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008336
8337 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8338 dev->ieee80211_ptr->conn_owner_nlportid =
8339 info->snd_portid;
8340 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8341 bssid, ETH_ALEN);
8342 }
8343
Johannes Berg91bf9b22013-05-15 17:44:01 +02008344 wdev_unlock(dev->ieee80211_ptr);
8345 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008346
Jouni Malinen636a5d32009-03-19 13:39:22 +02008347 return err;
8348}
8349
8350static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8351{
Johannes Berg4c476992010-10-04 21:36:35 +02008352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8353 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008354 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008355 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008356 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008357 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008358
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008359 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8360 return -EINVAL;
8361
8362 if (!info->attrs[NL80211_ATTR_MAC])
8363 return -EINVAL;
8364
8365 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8366 return -EINVAL;
8367
Johannes Berg4c476992010-10-04 21:36:35 +02008368 if (!rdev->ops->deauth)
8369 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008370
Johannes Berg074ac8d2010-09-16 14:58:22 +02008371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008374
Johannes Berg19957bb2009-07-02 17:20:43 +02008375 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008376
Johannes Berg19957bb2009-07-02 17:20:43 +02008377 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8378 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008379 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008380 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008381 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008382
8383 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008384 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8385 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008386 }
8387
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008388 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8389
Johannes Berg91bf9b22013-05-15 17:44:01 +02008390 wdev_lock(dev->ieee80211_ptr);
8391 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8392 local_state_change);
8393 wdev_unlock(dev->ieee80211_ptr);
8394 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008395}
8396
8397static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8398{
Johannes Berg4c476992010-10-04 21:36:35 +02008399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8400 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008401 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008402 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008403 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008404 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008405
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008406 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8407 return -EINVAL;
8408
8409 if (!info->attrs[NL80211_ATTR_MAC])
8410 return -EINVAL;
8411
8412 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8413 return -EINVAL;
8414
Johannes Berg4c476992010-10-04 21:36:35 +02008415 if (!rdev->ops->disassoc)
8416 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008417
Johannes Berg074ac8d2010-09-16 14:58:22 +02008418 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008419 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8420 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008421
Johannes Berg19957bb2009-07-02 17:20:43 +02008422 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008423
Johannes Berg19957bb2009-07-02 17:20:43 +02008424 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8425 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008426 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008427 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008428 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008429
8430 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008431 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8432 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008433 }
8434
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008435 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8436
Johannes Berg91bf9b22013-05-15 17:44:01 +02008437 wdev_lock(dev->ieee80211_ptr);
8438 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8439 local_state_change);
8440 wdev_unlock(dev->ieee80211_ptr);
8441 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008442}
8443
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008444static bool
8445nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008446 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008447 int rateval)
8448{
8449 struct wiphy *wiphy = &rdev->wiphy;
8450 bool found = false;
8451 int band, i;
8452
Johannes Berg57fbcce2016-04-12 15:56:15 +02008453 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008454 struct ieee80211_supported_band *sband;
8455
8456 sband = wiphy->bands[band];
8457 if (!sband)
8458 continue;
8459
8460 for (i = 0; i < sband->n_bitrates; i++) {
8461 if (sband->bitrates[i].bitrate == rateval) {
8462 mcast_rate[band] = i + 1;
8463 found = true;
8464 break;
8465 }
8466 }
8467 }
8468
8469 return found;
8470}
8471
Johannes Berg04a773a2009-04-19 21:24:32 +02008472static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8473{
Johannes Berg4c476992010-10-04 21:36:35 +02008474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8475 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008476 struct cfg80211_ibss_params ibss;
8477 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008478 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008479 int err;
8480
Johannes Berg8e30bc52009-04-22 17:45:38 +02008481 memset(&ibss, 0, sizeof(ibss));
8482
Johannes Berg04a773a2009-04-19 21:24:32 +02008483 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8484 return -EINVAL;
8485
Johannes Berg683b6d32012-11-08 21:25:48 +01008486 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008487 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8488 return -EINVAL;
8489
Johannes Berg8e30bc52009-04-22 17:45:38 +02008490 ibss.beacon_interval = 100;
8491
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308492 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008493 ibss.beacon_interval =
8494 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308495
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308496 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8497 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308498 if (err)
8499 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008500
Johannes Berg4c476992010-10-04 21:36:35 +02008501 if (!rdev->ops->join_ibss)
8502 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008503
Johannes Berg4c476992010-10-04 21:36:35 +02008504 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8505 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008506
Johannes Berg79c97e92009-07-07 03:56:12 +02008507 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008508
Johannes Berg39193492011-09-16 13:45:25 +02008509 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008510 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008511
8512 if (!is_valid_ether_addr(ibss.bssid))
8513 return -EINVAL;
8514 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008515 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8516 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8517
8518 if (info->attrs[NL80211_ATTR_IE]) {
8519 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8520 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8521 }
8522
Johannes Berg683b6d32012-11-08 21:25:48 +01008523 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8524 if (err)
8525 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008526
Ilan Peer174e0cd2014-02-23 09:13:01 +02008527 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8528 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008529 return -EINVAL;
8530
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008531 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008532 case NL80211_CHAN_WIDTH_5:
8533 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008534 case NL80211_CHAN_WIDTH_20_NOHT:
8535 break;
8536 case NL80211_CHAN_WIDTH_20:
8537 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008538 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8539 return -EINVAL;
8540 break;
8541 case NL80211_CHAN_WIDTH_80:
8542 case NL80211_CHAN_WIDTH_80P80:
8543 case NL80211_CHAN_WIDTH_160:
8544 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8545 return -EINVAL;
8546 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8547 NL80211_EXT_FEATURE_VHT_IBSS))
8548 return -EINVAL;
8549 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008550 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008551 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008552 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008553
Johannes Berg04a773a2009-04-19 21:24:32 +02008554 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008555 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008556
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008557 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8558 u8 *rates =
8559 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8560 int n_rates =
8561 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8562 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008563 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008564
Johannes Berg34850ab2011-07-18 18:08:35 +02008565 err = ieee80211_get_ratemask(sband, rates, n_rates,
8566 &ibss.basic_rates);
8567 if (err)
8568 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008569 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008570
Simon Wunderlich803768f2013-06-28 10:39:58 +02008571 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8572 memcpy(&ibss.ht_capa_mask,
8573 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8574 sizeof(ibss.ht_capa_mask));
8575
8576 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8577 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8578 return -EINVAL;
8579 memcpy(&ibss.ht_capa,
8580 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8581 sizeof(ibss.ht_capa));
8582 }
8583
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008584 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8585 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8586 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8587 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008588
Johannes Berg4c476992010-10-04 21:36:35 +02008589 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308590 bool no_ht = false;
8591
Johannes Berg4c476992010-10-04 21:36:35 +02008592 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308593 info->attrs[NL80211_ATTR_KEYS],
8594 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008595 if (IS_ERR(connkeys))
8596 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308597
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008598 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8599 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008600 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308601 return -EINVAL;
8602 }
Johannes Berg4c476992010-10-04 21:36:35 +02008603 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008604
Antonio Quartulli267335d2012-01-31 20:25:47 +01008605 ibss.control_port =
8606 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8607
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008608 ibss.userspace_handles_dfs =
8609 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8610
Johannes Berg4c476992010-10-04 21:36:35 +02008611 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008612 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008613 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008614 return err;
8615}
8616
8617static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8618{
Johannes Berg4c476992010-10-04 21:36:35 +02008619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8620 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008621
Johannes Berg4c476992010-10-04 21:36:35 +02008622 if (!rdev->ops->leave_ibss)
8623 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008624
Johannes Berg4c476992010-10-04 21:36:35 +02008625 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8626 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008627
Johannes Berg4c476992010-10-04 21:36:35 +02008628 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008629}
8630
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008631static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8632{
8633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8634 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008635 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008636 u32 nla_rate;
8637 int err;
8638
8639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008640 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8641 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008642 return -EOPNOTSUPP;
8643
8644 if (!rdev->ops->set_mcast_rate)
8645 return -EOPNOTSUPP;
8646
8647 memset(mcast_rate, 0, sizeof(mcast_rate));
8648
8649 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8650 return -EINVAL;
8651
8652 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8653 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8654 return -EINVAL;
8655
Ilan Peera1056b12015-10-22 22:27:46 +03008656 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008657
8658 return err;
8659}
8660
Johannes Bergad7e7182013-11-13 13:37:47 +01008661static struct sk_buff *
8662__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008663 struct wireless_dev *wdev, int approxlen,
8664 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008665 enum nl80211_attrs attr,
8666 const struct nl80211_vendor_cmd_info *info,
8667 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008668{
8669 struct sk_buff *skb;
8670 void *hdr;
8671 struct nlattr *data;
8672
8673 skb = nlmsg_new(approxlen + 100, gfp);
8674 if (!skb)
8675 return NULL;
8676
8677 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8678 if (!hdr) {
8679 kfree_skb(skb);
8680 return NULL;
8681 }
8682
8683 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8684 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008685
8686 if (info) {
8687 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8688 info->vendor_id))
8689 goto nla_put_failure;
8690 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8691 info->subcmd))
8692 goto nla_put_failure;
8693 }
8694
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008695 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008696 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8697 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008698 goto nla_put_failure;
8699 if (wdev->netdev &&
8700 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8701 wdev->netdev->ifindex))
8702 goto nla_put_failure;
8703 }
8704
Johannes Bergad7e7182013-11-13 13:37:47 +01008705 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008706 if (!data)
8707 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008708
8709 ((void **)skb->cb)[0] = rdev;
8710 ((void **)skb->cb)[1] = hdr;
8711 ((void **)skb->cb)[2] = data;
8712
8713 return skb;
8714
8715 nla_put_failure:
8716 kfree_skb(skb);
8717 return NULL;
8718}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008719
Johannes Berge03ad6e2014-01-01 17:22:30 +01008720struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008721 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008722 enum nl80211_commands cmd,
8723 enum nl80211_attrs attr,
8724 int vendor_event_idx,
8725 int approxlen, gfp_t gfp)
8726{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008727 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008728 const struct nl80211_vendor_cmd_info *info;
8729
8730 switch (cmd) {
8731 case NL80211_CMD_TESTMODE:
8732 if (WARN_ON(vendor_event_idx != -1))
8733 return NULL;
8734 info = NULL;
8735 break;
8736 case NL80211_CMD_VENDOR:
8737 if (WARN_ON(vendor_event_idx < 0 ||
8738 vendor_event_idx >= wiphy->n_vendor_events))
8739 return NULL;
8740 info = &wiphy->vendor_events[vendor_event_idx];
8741 break;
8742 default:
8743 WARN_ON(1);
8744 return NULL;
8745 }
8746
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008747 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008748 cmd, attr, info, gfp);
8749}
8750EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8751
8752void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8753{
8754 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8755 void *hdr = ((void **)skb->cb)[1];
8756 struct nlattr *data = ((void **)skb->cb)[2];
8757 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8758
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008759 /* clear CB data for netlink core to own from now on */
8760 memset(skb->cb, 0, sizeof(skb->cb));
8761
Johannes Berge03ad6e2014-01-01 17:22:30 +01008762 nla_nest_end(skb, data);
8763 genlmsg_end(skb, hdr);
8764
8765 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8766 mcgrp = NL80211_MCGRP_VENDOR;
8767
8768 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8769 mcgrp, gfp);
8770}
8771EXPORT_SYMBOL(__cfg80211_send_event_skb);
8772
Johannes Bergaff89a92009-07-01 21:26:51 +02008773#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008774static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8775{
Johannes Berg4c476992010-10-04 21:36:35 +02008776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008777 struct wireless_dev *wdev =
8778 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008779 int err;
8780
David Spinadelfc73f112013-07-31 18:04:15 +03008781 if (!rdev->ops->testmode_cmd)
8782 return -EOPNOTSUPP;
8783
8784 if (IS_ERR(wdev)) {
8785 err = PTR_ERR(wdev);
8786 if (err != -EINVAL)
8787 return err;
8788 wdev = NULL;
8789 } else if (wdev->wiphy != &rdev->wiphy) {
8790 return -EINVAL;
8791 }
8792
Johannes Bergaff89a92009-07-01 21:26:51 +02008793 if (!info->attrs[NL80211_ATTR_TESTDATA])
8794 return -EINVAL;
8795
Johannes Bergad7e7182013-11-13 13:37:47 +01008796 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008797 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008798 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8799 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008800 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008801
Johannes Bergaff89a92009-07-01 21:26:51 +02008802 return err;
8803}
8804
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008805static int nl80211_testmode_dump(struct sk_buff *skb,
8806 struct netlink_callback *cb)
8807{
Johannes Berg00918d32011-12-13 17:22:05 +01008808 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008809 int err;
8810 long phy_idx;
8811 void *data = NULL;
8812 int data_len = 0;
8813
Johannes Berg5fe231e2013-05-08 21:45:15 +02008814 rtnl_lock();
8815
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008816 if (cb->args[0]) {
8817 /*
8818 * 0 is a valid index, but not valid for args[0],
8819 * so we need to offset by 1.
8820 */
8821 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008822
8823 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8824 if (!rdev) {
8825 err = -ENOENT;
8826 goto out_err;
8827 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008828 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008829 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8830
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008831 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008832 attrbuf, nl80211_fam.maxattr,
8833 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008834 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008835 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008836
Johannes Bergc90c39d2016-10-24 14:40:01 +02008837 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008838 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008839 err = PTR_ERR(rdev);
8840 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008841 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008842 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008843
Johannes Bergc90c39d2016-10-24 14:40:01 +02008844 if (attrbuf[NL80211_ATTR_TESTDATA])
8845 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008846 }
8847
8848 if (cb->args[1]) {
8849 data = nla_data((void *)cb->args[1]);
8850 data_len = nla_len((void *)cb->args[1]);
8851 }
8852
Johannes Berg00918d32011-12-13 17:22:05 +01008853 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008854 err = -EOPNOTSUPP;
8855 goto out_err;
8856 }
8857
8858 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008859 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008860 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8861 NL80211_CMD_TESTMODE);
8862 struct nlattr *tmdata;
8863
Dan Carpentercb35fba2013-08-14 14:50:01 +03008864 if (!hdr)
8865 break;
8866
David S. Miller9360ffd2012-03-29 04:41:26 -04008867 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008868 genlmsg_cancel(skb, hdr);
8869 break;
8870 }
8871
8872 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8873 if (!tmdata) {
8874 genlmsg_cancel(skb, hdr);
8875 break;
8876 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008877 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008878 nla_nest_end(skb, tmdata);
8879
8880 if (err == -ENOBUFS || err == -ENOENT) {
8881 genlmsg_cancel(skb, hdr);
8882 break;
8883 } else if (err) {
8884 genlmsg_cancel(skb, hdr);
8885 goto out_err;
8886 }
8887
8888 genlmsg_end(skb, hdr);
8889 }
8890
8891 err = skb->len;
8892 /* see above */
8893 cb->args[0] = phy_idx + 1;
8894 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008895 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008896 return err;
8897}
Johannes Bergaff89a92009-07-01 21:26:51 +02008898#endif
8899
Samuel Ortizb23aa672009-07-01 21:26:54 +02008900static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8901{
Johannes Berg4c476992010-10-04 21:36:35 +02008902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8903 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008904 struct cfg80211_connect_params connect;
8905 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008906 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008907 int err;
8908
8909 memset(&connect, 0, sizeof(connect));
8910
8911 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8912 return -EINVAL;
8913
8914 if (!info->attrs[NL80211_ATTR_SSID] ||
8915 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8916 return -EINVAL;
8917
8918 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8919 connect.auth_type =
8920 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008921 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8922 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008923 return -EINVAL;
8924 } else
8925 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8926
8927 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8928
Avraham Stern3a00df52017-06-09 13:08:43 +01008929 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8930 !wiphy_ext_feature_isset(&rdev->wiphy,
8931 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8932 return -EINVAL;
8933 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8934
Johannes Bergc0692b82010-08-27 14:26:53 +03008935 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008936 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008937 if (err)
8938 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008939
Johannes Berg074ac8d2010-09-16 14:58:22 +02008940 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8942 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008943
Johannes Berg79c97e92009-07-07 03:56:12 +02008944 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008945
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308946 connect.bg_scan_period = -1;
8947 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8948 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8949 connect.bg_scan_period =
8950 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8951 }
8952
Samuel Ortizb23aa672009-07-01 21:26:54 +02008953 if (info->attrs[NL80211_ATTR_MAC])
8954 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008955 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8956 connect.bssid_hint =
8957 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008958 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8959 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8960
8961 if (info->attrs[NL80211_ATTR_IE]) {
8962 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8963 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8964 }
8965
Jouni Malinencee00a92013-01-15 17:15:57 +02008966 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8967 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008968 if (connect.mfp == NL80211_MFP_OPTIONAL &&
8969 !wiphy_ext_feature_isset(&rdev->wiphy,
8970 NL80211_EXT_FEATURE_MFP_OPTIONAL))
8971 return -EOPNOTSUPP;
8972
Jouni Malinencee00a92013-01-15 17:15:57 +02008973 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008974 connect.mfp != NL80211_MFP_NO &&
8975 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02008976 return -EINVAL;
8977 } else {
8978 connect.mfp = NL80211_MFP_NO;
8979 }
8980
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008981 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8982 connect.prev_bssid =
8983 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8984
Samuel Ortizb23aa672009-07-01 21:26:54 +02008985 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008986 connect.channel = nl80211_get_valid_chan(
8987 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8988 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008989 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008990 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008991 connect.channel_hint = nl80211_get_valid_chan(
8992 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8993 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008994 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008995 }
8996
Johannes Bergfffd0932009-07-08 14:22:54 +02008997 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8998 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308999 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009000 if (IS_ERR(connkeys))
9001 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009002 }
9003
Ben Greear7e7c8922011-11-18 11:31:59 -08009004 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9005 connect.flags |= ASSOC_REQ_DISABLE_HT;
9006
9007 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9008 memcpy(&connect.ht_capa_mask,
9009 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9010 sizeof(connect.ht_capa_mask));
9011
9012 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009013 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009014 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009015 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009016 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009017 memcpy(&connect.ht_capa,
9018 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9019 sizeof(connect.ht_capa));
9020 }
9021
Johannes Bergee2aca32013-02-21 17:36:01 +01009022 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9023 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9024
9025 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9026 memcpy(&connect.vht_capa_mask,
9027 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9028 sizeof(connect.vht_capa_mask));
9029
9030 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9031 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009032 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009033 return -EINVAL;
9034 }
9035 memcpy(&connect.vht_capa,
9036 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9037 sizeof(connect.vht_capa));
9038 }
9039
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009040 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009041 if (!((rdev->wiphy.features &
9042 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9043 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9044 !wiphy_ext_feature_isset(&rdev->wiphy,
9045 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009046 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009047 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009048 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009049 connect.flags |= ASSOC_REQ_USE_RRM;
9050 }
9051
Lior David34d50512016-01-28 10:58:25 +02009052 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009053 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009054 kzfree(connkeys);
9055 return -EOPNOTSUPP;
9056 }
9057
Arend van Spriel38de03d2016-03-02 20:37:18 +01009058 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9059 /* bss selection makes no sense if bssid is set */
9060 if (connect.bssid) {
9061 kzfree(connkeys);
9062 return -EINVAL;
9063 }
9064
9065 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9066 wiphy, &connect.bss_select);
9067 if (err) {
9068 kzfree(connkeys);
9069 return err;
9070 }
9071 }
9072
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009073 if (wiphy_ext_feature_isset(&rdev->wiphy,
9074 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9075 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9076 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9077 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9078 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9079 connect.fils_erp_username =
9080 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9081 connect.fils_erp_username_len =
9082 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9083 connect.fils_erp_realm =
9084 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9085 connect.fils_erp_realm_len =
9086 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9087 connect.fils_erp_next_seq_num =
9088 nla_get_u16(
9089 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9090 connect.fils_erp_rrk =
9091 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9092 connect.fils_erp_rrk_len =
9093 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9094 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9095 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9096 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9097 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9098 kzfree(connkeys);
9099 return -EINVAL;
9100 }
9101
Johannes Berg83739b02013-05-15 17:44:01 +02009102 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009103
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009104 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9105 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009106 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009107 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009108
9109 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9110 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9111 if (connect.bssid)
9112 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9113 connect.bssid, ETH_ALEN);
9114 else
9115 memset(dev->ieee80211_ptr->disconnect_bssid,
9116 0, ETH_ALEN);
9117 }
9118
9119 wdev_unlock(dev->ieee80211_ptr);
9120
Samuel Ortizb23aa672009-07-01 21:26:54 +02009121 return err;
9122}
9123
vamsi krishna088e8df2016-10-27 16:51:11 +03009124static int nl80211_update_connect_params(struct sk_buff *skb,
9125 struct genl_info *info)
9126{
9127 struct cfg80211_connect_params connect = {};
9128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9129 struct net_device *dev = info->user_ptr[1];
9130 struct wireless_dev *wdev = dev->ieee80211_ptr;
9131 u32 changed = 0;
9132 int ret;
9133
9134 if (!rdev->ops->update_connect_params)
9135 return -EOPNOTSUPP;
9136
9137 if (info->attrs[NL80211_ATTR_IE]) {
9138 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9139 return -EINVAL;
9140 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9141 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9142 changed |= UPDATE_ASSOC_IES;
9143 }
9144
9145 wdev_lock(dev->ieee80211_ptr);
9146 if (!wdev->current_bss)
9147 ret = -ENOLINK;
9148 else
9149 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9150 wdev_unlock(dev->ieee80211_ptr);
9151
9152 return ret;
9153}
9154
Samuel Ortizb23aa672009-07-01 21:26:54 +02009155static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9156{
Johannes Berg4c476992010-10-04 21:36:35 +02009157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9158 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009159 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009160 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009161
9162 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9163 reason = WLAN_REASON_DEAUTH_LEAVING;
9164 else
9165 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9166
9167 if (reason == 0)
9168 return -EINVAL;
9169
Johannes Berg074ac8d2010-09-16 14:58:22 +02009170 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009171 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9172 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009173
Johannes Berg83739b02013-05-15 17:44:01 +02009174 wdev_lock(dev->ieee80211_ptr);
9175 ret = cfg80211_disconnect(rdev, dev, reason, true);
9176 wdev_unlock(dev->ieee80211_ptr);
9177 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009178}
9179
Johannes Berg463d0182009-07-14 00:33:35 +02009180static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9181{
Johannes Berg4c476992010-10-04 21:36:35 +02009182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009183 struct net *net;
9184 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009185
Vadim Kochan4b681c82015-01-12 16:34:05 +02009186 if (info->attrs[NL80211_ATTR_PID]) {
9187 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9188
9189 net = get_net_ns_by_pid(pid);
9190 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9191 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9192
9193 net = get_net_ns_by_fd(fd);
9194 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009195 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009196 }
Johannes Berg463d0182009-07-14 00:33:35 +02009197
Johannes Berg4c476992010-10-04 21:36:35 +02009198 if (IS_ERR(net))
9199 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009200
9201 err = 0;
9202
9203 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009204 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9205 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009206
Johannes Berg463d0182009-07-14 00:33:35 +02009207 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009208 return err;
9209}
9210
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009211static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9212{
Johannes Berg4c476992010-10-04 21:36:35 +02009213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009214 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9215 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009216 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009217 struct cfg80211_pmksa pmksa;
9218
9219 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9220
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009221 if (!info->attrs[NL80211_ATTR_PMKID])
9222 return -EINVAL;
9223
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009224 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009225
9226 if (info->attrs[NL80211_ATTR_MAC]) {
9227 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9228 } else if (info->attrs[NL80211_ATTR_SSID] &&
9229 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9230 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9231 info->attrs[NL80211_ATTR_PMK])) {
9232 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9233 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9234 pmksa.cache_id =
9235 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9236 } else {
9237 return -EINVAL;
9238 }
9239 if (info->attrs[NL80211_ATTR_PMK]) {
9240 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9241 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9242 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009243
Johannes Berg074ac8d2010-09-16 14:58:22 +02009244 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009245 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9246 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009247
9248 switch (info->genlhdr->cmd) {
9249 case NL80211_CMD_SET_PMKSA:
9250 rdev_ops = rdev->ops->set_pmksa;
9251 break;
9252 case NL80211_CMD_DEL_PMKSA:
9253 rdev_ops = rdev->ops->del_pmksa;
9254 break;
9255 default:
9256 WARN_ON(1);
9257 break;
9258 }
9259
Johannes Berg4c476992010-10-04 21:36:35 +02009260 if (!rdev_ops)
9261 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009262
Johannes Berg4c476992010-10-04 21:36:35 +02009263 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009264}
9265
9266static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9267{
Johannes Berg4c476992010-10-04 21:36:35 +02009268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9269 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009270
Johannes Berg074ac8d2010-09-16 14:58:22 +02009271 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009272 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9273 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009274
Johannes Berg4c476992010-10-04 21:36:35 +02009275 if (!rdev->ops->flush_pmksa)
9276 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009277
Hila Gonene35e4d22012-06-27 17:19:42 +03009278 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009279}
9280
Arik Nemtsov109086c2011-09-28 14:12:50 +03009281static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9282{
9283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9284 struct net_device *dev = info->user_ptr[1];
9285 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309286 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009287 u16 status_code;
9288 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009289 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009290
9291 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9292 !rdev->ops->tdls_mgmt)
9293 return -EOPNOTSUPP;
9294
9295 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9296 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9297 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9298 !info->attrs[NL80211_ATTR_IE] ||
9299 !info->attrs[NL80211_ATTR_MAC])
9300 return -EINVAL;
9301
9302 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9303 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9304 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9305 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009306 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309307 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9308 peer_capability =
9309 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009310
Hila Gonene35e4d22012-06-27 17:19:42 +03009311 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309312 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009313 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009314 nla_data(info->attrs[NL80211_ATTR_IE]),
9315 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009316}
9317
9318static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9319{
9320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9321 struct net_device *dev = info->user_ptr[1];
9322 enum nl80211_tdls_operation operation;
9323 u8 *peer;
9324
9325 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9326 !rdev->ops->tdls_oper)
9327 return -EOPNOTSUPP;
9328
9329 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9330 !info->attrs[NL80211_ATTR_MAC])
9331 return -EINVAL;
9332
9333 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9334 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9335
Hila Gonene35e4d22012-06-27 17:19:42 +03009336 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009337}
9338
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009339static int nl80211_remain_on_channel(struct sk_buff *skb,
9340 struct genl_info *info)
9341{
Johannes Berg4c476992010-10-04 21:36:35 +02009342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009343 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009344 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309345 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009346 struct sk_buff *msg;
9347 void *hdr;
9348 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009349 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009350 int err;
9351
9352 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9353 !info->attrs[NL80211_ATTR_DURATION])
9354 return -EINVAL;
9355
9356 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9357
Johannes Berg7c4ef712011-11-18 15:33:48 +01009358 if (!rdev->ops->remain_on_channel ||
9359 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009360 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009361
Johannes Bergebf348f2012-06-01 12:50:54 +02009362 /*
9363 * We should be on that channel for at least a minimum amount of
9364 * time (10ms) but no longer than the driver supports.
9365 */
9366 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9367 duration > rdev->wiphy.max_remain_on_channel_duration)
9368 return -EINVAL;
9369
Johannes Berg683b6d32012-11-08 21:25:48 +01009370 err = nl80211_parse_chandef(rdev, info, &chandef);
9371 if (err)
9372 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009373
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309374 wdev_lock(wdev);
9375 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9376 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9377 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9378 &chandef);
9379 if (compat_chandef != &chandef) {
9380 wdev_unlock(wdev);
9381 return -EBUSY;
9382 }
9383 }
9384 wdev_unlock(wdev);
9385
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009387 if (!msg)
9388 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009389
Eric W. Biederman15e47302012-09-07 20:12:54 +00009390 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009391 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009392 if (!hdr) {
9393 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009394 goto free_msg;
9395 }
9396
Johannes Berg683b6d32012-11-08 21:25:48 +01009397 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9398 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009399
9400 if (err)
9401 goto free_msg;
9402
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009403 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9404 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009405 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009406
9407 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009408
9409 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009410
9411 nla_put_failure:
9412 err = -ENOBUFS;
9413 free_msg:
9414 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009415 return err;
9416}
9417
9418static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9419 struct genl_info *info)
9420{
Johannes Berg4c476992010-10-04 21:36:35 +02009421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009422 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009423 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009424
9425 if (!info->attrs[NL80211_ATTR_COOKIE])
9426 return -EINVAL;
9427
Johannes Berg4c476992010-10-04 21:36:35 +02009428 if (!rdev->ops->cancel_remain_on_channel)
9429 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009430
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009431 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9432
Hila Gonene35e4d22012-06-27 17:19:42 +03009433 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009434}
9435
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009436static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9437 struct genl_info *info)
9438{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009439 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009441 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309442 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009443
Johannes Berg4c476992010-10-04 21:36:35 +02009444 if (!rdev->ops->set_bitrate_mask)
9445 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009446
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309447 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9448 if (err)
9449 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009450
Hila Gonene35e4d22012-06-27 17:19:42 +03009451 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009452}
9453
Johannes Berg2e161f72010-08-12 15:38:38 +02009454static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009455{
Johannes Berg4c476992010-10-04 21:36:35 +02009456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009457 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009458 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009459
9460 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9461 return -EINVAL;
9462
Johannes Berg2e161f72010-08-12 15:38:38 +02009463 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9464 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009465
Johannes Berg71bbc992012-06-15 15:30:18 +02009466 switch (wdev->iftype) {
9467 case NL80211_IFTYPE_STATION:
9468 case NL80211_IFTYPE_ADHOC:
9469 case NL80211_IFTYPE_P2P_CLIENT:
9470 case NL80211_IFTYPE_AP:
9471 case NL80211_IFTYPE_AP_VLAN:
9472 case NL80211_IFTYPE_MESH_POINT:
9473 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009474 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009475 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009476 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009477 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009478 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009479 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009480
9481 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009482 if (!rdev->ops->mgmt_tx)
9483 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009484
Eric W. Biederman15e47302012-09-07 20:12:54 +00009485 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009486 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9487 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009488}
9489
Johannes Berg2e161f72010-08-12 15:38:38 +02009490static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009491{
Johannes Berg4c476992010-10-04 21:36:35 +02009492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009493 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009494 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009495 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009496 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009497 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009498 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009499 struct cfg80211_mgmt_tx_params params = {
9500 .dont_wait_for_ack =
9501 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9502 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009503
Johannes Berg683b6d32012-11-08 21:25:48 +01009504 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009505 return -EINVAL;
9506
Johannes Berg4c476992010-10-04 21:36:35 +02009507 if (!rdev->ops->mgmt_tx)
9508 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009509
Johannes Berg71bbc992012-06-15 15:30:18 +02009510 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009511 case NL80211_IFTYPE_P2P_DEVICE:
9512 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9513 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009514 case NL80211_IFTYPE_STATION:
9515 case NL80211_IFTYPE_ADHOC:
9516 case NL80211_IFTYPE_P2P_CLIENT:
9517 case NL80211_IFTYPE_AP:
9518 case NL80211_IFTYPE_AP_VLAN:
9519 case NL80211_IFTYPE_MESH_POINT:
9520 case NL80211_IFTYPE_P2P_GO:
9521 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009522 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009523 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009524 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009525 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009526
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009527 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009528 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009529 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009530 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009531
9532 /*
9533 * We should wait on the channel for at least a minimum amount
9534 * of time (10ms) but no longer than the driver supports.
9535 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009536 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9537 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009538 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009539 }
9540
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009541 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009542
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009543 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009544 return -EINVAL;
9545
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009546 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309547
Antonio Quartulliea141b752013-06-11 14:20:03 +02009548 /* get the channel if any has been specified, otherwise pass NULL to
9549 * the driver. The latter will use the current one
9550 */
9551 chandef.chan = NULL;
9552 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9553 err = nl80211_parse_chandef(rdev, info, &chandef);
9554 if (err)
9555 return err;
9556 }
9557
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009558 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009559 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009560
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309561 wdev_lock(wdev);
9562 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9563 wdev_unlock(wdev);
9564 return -EBUSY;
9565 }
9566 wdev_unlock(wdev);
9567
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009568 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9569 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9570
9571 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9572 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9573 int i;
9574
9575 if (len % sizeof(u16))
9576 return -EINVAL;
9577
9578 params.n_csa_offsets = len / sizeof(u16);
9579 params.csa_offsets =
9580 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9581
9582 /* check that all the offsets fit the frame */
9583 for (i = 0; i < params.n_csa_offsets; i++) {
9584 if (params.csa_offsets[i] >= params.len)
9585 return -EINVAL;
9586 }
9587 }
9588
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009589 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9591 if (!msg)
9592 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009593
Eric W. Biederman15e47302012-09-07 20:12:54 +00009594 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009595 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009596 if (!hdr) {
9597 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009598 goto free_msg;
9599 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009600 }
Johannes Berge247bd902011-11-04 11:18:21 +01009601
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009602 params.chan = chandef.chan;
9603 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009604 if (err)
9605 goto free_msg;
9606
Johannes Berge247bd902011-11-04 11:18:21 +01009607 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009608 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9609 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009610 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009611
Johannes Berge247bd902011-11-04 11:18:21 +01009612 genlmsg_end(msg, hdr);
9613 return genlmsg_reply(msg, info);
9614 }
9615
9616 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009617
9618 nla_put_failure:
9619 err = -ENOBUFS;
9620 free_msg:
9621 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009622 return err;
9623}
9624
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009625static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9626{
9627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009628 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009629 u64 cookie;
9630
9631 if (!info->attrs[NL80211_ATTR_COOKIE])
9632 return -EINVAL;
9633
9634 if (!rdev->ops->mgmt_tx_cancel_wait)
9635 return -EOPNOTSUPP;
9636
Johannes Berg71bbc992012-06-15 15:30:18 +02009637 switch (wdev->iftype) {
9638 case NL80211_IFTYPE_STATION:
9639 case NL80211_IFTYPE_ADHOC:
9640 case NL80211_IFTYPE_P2P_CLIENT:
9641 case NL80211_IFTYPE_AP:
9642 case NL80211_IFTYPE_AP_VLAN:
9643 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009644 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009645 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009646 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009647 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009648 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009649 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009650
9651 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9652
Hila Gonene35e4d22012-06-27 17:19:42 +03009653 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009654}
9655
Kalle Valoffb9eb32010-02-17 17:58:10 +02009656static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9657{
Johannes Berg4c476992010-10-04 21:36:35 +02009658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009659 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009660 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009661 u8 ps_state;
9662 bool state;
9663 int err;
9664
Johannes Berg4c476992010-10-04 21:36:35 +02009665 if (!info->attrs[NL80211_ATTR_PS_STATE])
9666 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009667
9668 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9669
Johannes Berg4c476992010-10-04 21:36:35 +02009670 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9671 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009672
9673 wdev = dev->ieee80211_ptr;
9674
Johannes Berg4c476992010-10-04 21:36:35 +02009675 if (!rdev->ops->set_power_mgmt)
9676 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009677
9678 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9679
9680 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009681 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009682
Hila Gonene35e4d22012-06-27 17:19:42 +03009683 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009684 if (!err)
9685 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009686 return err;
9687}
9688
9689static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9690{
Johannes Berg4c476992010-10-04 21:36:35 +02009691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009692 enum nl80211_ps_state ps_state;
9693 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009694 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009695 struct sk_buff *msg;
9696 void *hdr;
9697 int err;
9698
Kalle Valoffb9eb32010-02-17 17:58:10 +02009699 wdev = dev->ieee80211_ptr;
9700
Johannes Berg4c476992010-10-04 21:36:35 +02009701 if (!rdev->ops->set_power_mgmt)
9702 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009703
9704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009705 if (!msg)
9706 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009707
Eric W. Biederman15e47302012-09-07 20:12:54 +00009708 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009709 NL80211_CMD_GET_POWER_SAVE);
9710 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009711 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009712 goto free_msg;
9713 }
9714
9715 if (wdev->ps)
9716 ps_state = NL80211_PS_ENABLED;
9717 else
9718 ps_state = NL80211_PS_DISABLED;
9719
David S. Miller9360ffd2012-03-29 04:41:26 -04009720 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9721 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009722
9723 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009724 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009725
Johannes Berg4c476992010-10-04 21:36:35 +02009726 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009727 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009728 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009729 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009730 return err;
9731}
9732
Johannes Berg94e860f2014-01-20 23:58:15 +01009733static const struct nla_policy
9734nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009735 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009736 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9737 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009738 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9739 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9740 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009741 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009742};
9743
Thomas Pedersen84f10702012-07-12 16:17:33 -07009744static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009745 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009746{
9747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009748 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009749 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009750
Johannes Bergd9d8b012012-11-26 12:51:52 +01009751 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009752 return -EINVAL;
9753
Thomas Pedersen84f10702012-07-12 16:17:33 -07009754 if (!rdev->ops->set_cqm_txe_config)
9755 return -EOPNOTSUPP;
9756
9757 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9758 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9759 return -EOPNOTSUPP;
9760
Hila Gonene35e4d22012-06-27 17:19:42 +03009761 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009762}
9763
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009764static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9765 struct net_device *dev)
9766{
9767 struct wireless_dev *wdev = dev->ieee80211_ptr;
9768 s32 last, low, high;
9769 u32 hyst;
9770 int i, n;
9771 int err;
9772
9773 /* RSSI reporting disabled? */
9774 if (!wdev->cqm_config)
9775 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9776
9777 /*
9778 * Obtain current RSSI value if possible, if not and no RSSI threshold
9779 * event has been received yet, we should receive an event after a
9780 * connection is established and enough beacons received to calculate
9781 * the average.
9782 */
9783 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9784 rdev->ops->get_station) {
9785 struct station_info sinfo;
9786 u8 *mac_addr;
9787
9788 mac_addr = wdev->current_bss->pub.bssid;
9789
9790 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9791 if (err)
9792 return err;
9793
9794 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9795 wdev->cqm_config->last_rssi_event_value =
9796 (s8) sinfo.rx_beacon_signal_avg;
9797 }
9798
9799 last = wdev->cqm_config->last_rssi_event_value;
9800 hyst = wdev->cqm_config->rssi_hyst;
9801 n = wdev->cqm_config->n_rssi_thresholds;
9802
9803 for (i = 0; i < n; i++)
9804 if (last < wdev->cqm_config->rssi_thresholds[i])
9805 break;
9806
9807 low = i > 0 ?
9808 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9809 high = i < n ?
9810 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9811
9812 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9813}
9814
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009815static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009816 const s32 *thresholds, int n_thresholds,
9817 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009818{
Johannes Berg4c476992010-10-04 21:36:35 +02009819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009820 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009821 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009822 int i, err;
9823 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009824
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009825 /* Check all values negative and sorted */
9826 for (i = 0; i < n_thresholds; i++) {
9827 if (thresholds[i] > 0 || thresholds[i] <= prev)
9828 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009829
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009830 prev = thresholds[i];
9831 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009832
Johannes Berg074ac8d2010-09-16 14:58:22 +02009833 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009834 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9835 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009836
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009837 wdev_lock(wdev);
9838 cfg80211_cqm_config_free(wdev);
9839 wdev_unlock(wdev);
9840
9841 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9842 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9843 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9844
9845 return rdev_set_cqm_rssi_config(rdev, dev,
9846 thresholds[0], hysteresis);
9847 }
9848
9849 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9850 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9851 return -EOPNOTSUPP;
9852
9853 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9854 n_thresholds = 0;
9855
9856 wdev_lock(wdev);
9857 if (n_thresholds) {
9858 struct cfg80211_cqm_config *cqm_config;
9859
9860 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9861 n_thresholds * sizeof(s32), GFP_KERNEL);
9862 if (!cqm_config) {
9863 err = -ENOMEM;
9864 goto unlock;
9865 }
9866
9867 cqm_config->rssi_hyst = hysteresis;
9868 cqm_config->n_rssi_thresholds = n_thresholds;
9869 memcpy(cqm_config->rssi_thresholds, thresholds,
9870 n_thresholds * sizeof(s32));
9871
9872 wdev->cqm_config = cqm_config;
9873 }
9874
9875 err = cfg80211_cqm_rssi_update(rdev, dev);
9876
9877unlock:
9878 wdev_unlock(wdev);
9879
9880 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009881}
9882
9883static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9884{
9885 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9886 struct nlattr *cqm;
9887 int err;
9888
9889 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009890 if (!cqm)
9891 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009892
9893 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009894 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009895 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009896 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009897
9898 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9899 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009900 const s32 *thresholds =
9901 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9902 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009903 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009904
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009905 if (len % 4)
9906 return -EINVAL;
9907
9908 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9909 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009910 }
9911
9912 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9913 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9914 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9915 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9916 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9917 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9918
9919 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9920 }
9921
9922 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009923}
9924
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009925static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9926{
9927 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9928 struct net_device *dev = info->user_ptr[1];
9929 struct ocb_setup setup = {};
9930 int err;
9931
9932 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9933 if (err)
9934 return err;
9935
9936 return cfg80211_join_ocb(rdev, dev, &setup);
9937}
9938
9939static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9940{
9941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9942 struct net_device *dev = info->user_ptr[1];
9943
9944 return cfg80211_leave_ocb(rdev, dev);
9945}
9946
Johannes Berg29cbe682010-12-03 09:20:44 +01009947static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9948{
9949 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9950 struct net_device *dev = info->user_ptr[1];
9951 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009952 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009953 int err;
9954
9955 /* start with default */
9956 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009957 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009958
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009959 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009960 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009961 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009962 if (err)
9963 return err;
9964 }
9965
9966 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9967 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9968 return -EINVAL;
9969
Javier Cardonac80d5452010-12-16 17:37:49 -08009970 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9971 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9972
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009973 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9974 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9975 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9976 return -EINVAL;
9977
Marco Porsch9bdbf042013-01-07 16:04:51 +01009978 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9979 setup.beacon_interval =
9980 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309981
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309982 err = cfg80211_validate_beacon_int(rdev,
9983 NL80211_IFTYPE_MESH_POINT,
9984 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309985 if (err)
9986 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009987 }
9988
9989 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9990 setup.dtim_period =
9991 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9992 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9993 return -EINVAL;
9994 }
9995
Javier Cardonac80d5452010-12-16 17:37:49 -08009996 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9997 /* parse additional setup parameters if given */
9998 err = nl80211_parse_mesh_setup(info, &setup);
9999 if (err)
10000 return err;
10001 }
10002
Thomas Pedersend37bb182013-03-04 13:06:13 -080010003 if (setup.user_mpm)
10004 cfg.auto_open_plinks = false;
10005
Johannes Bergcc1d2802012-05-16 23:50:20 +020010006 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010007 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10008 if (err)
10009 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010010 } else {
10011 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010012 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010013 }
10014
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010015 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10016 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10017 int n_rates =
10018 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10019 struct ieee80211_supported_band *sband;
10020
10021 if (!setup.chandef.chan)
10022 return -EINVAL;
10023
10024 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10025
10026 err = ieee80211_get_ratemask(sband, rates, n_rates,
10027 &setup.basic_rates);
10028 if (err)
10029 return err;
10030 }
10031
Johannes Berg8564e382016-09-19 09:44:44 +020010032 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10033 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10034 if (err)
10035 return err;
10036
Johannes Berg265698d2017-09-18 22:46:36 +020010037 if (!setup.chandef.chan)
10038 return -EINVAL;
10039
Johannes Berg8564e382016-09-19 09:44:44 +020010040 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10041 &setup.beacon_rate);
10042 if (err)
10043 return err;
10044 }
10045
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010046 setup.userspace_handles_dfs =
10047 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10048
Javier Cardonac80d5452010-12-16 17:37:49 -080010049 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +010010050}
10051
10052static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10053{
10054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10055 struct net_device *dev = info->user_ptr[1];
10056
10057 return cfg80211_leave_mesh(rdev, dev);
10058}
10059
Johannes Bergdfb89c52012-06-27 09:23:48 +020010060#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010061static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10062 struct cfg80211_registered_device *rdev)
10063{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010064 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010065 struct nlattr *nl_pats, *nl_pat;
10066 int i, pat_len;
10067
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010068 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010069 return 0;
10070
10071 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10072 if (!nl_pats)
10073 return -ENOBUFS;
10074
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010075 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010076 nl_pat = nla_nest_start(msg, i + 1);
10077 if (!nl_pat)
10078 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010079 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010080 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010081 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010082 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10083 wowlan->patterns[i].pattern) ||
10084 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010085 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010086 return -ENOBUFS;
10087 nla_nest_end(msg, nl_pat);
10088 }
10089 nla_nest_end(msg, nl_pats);
10090
10091 return 0;
10092}
10093
Johannes Berg2a0e0472013-01-23 22:57:40 +010010094static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10095 struct cfg80211_wowlan_tcp *tcp)
10096{
10097 struct nlattr *nl_tcp;
10098
10099 if (!tcp)
10100 return 0;
10101
10102 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10103 if (!nl_tcp)
10104 return -ENOBUFS;
10105
Jiri Benc930345e2015-03-29 16:59:25 +020010106 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10107 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010108 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10109 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10110 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10111 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10112 tcp->payload_len, tcp->payload) ||
10113 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10114 tcp->data_interval) ||
10115 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10116 tcp->wake_len, tcp->wake_data) ||
10117 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10118 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10119 return -ENOBUFS;
10120
10121 if (tcp->payload_seq.len &&
10122 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10123 sizeof(tcp->payload_seq), &tcp->payload_seq))
10124 return -ENOBUFS;
10125
10126 if (tcp->payload_tok.len &&
10127 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10128 sizeof(tcp->payload_tok) + tcp->tokens_size,
10129 &tcp->payload_tok))
10130 return -ENOBUFS;
10131
Johannes Berge248ad32013-05-16 10:24:28 +020010132 nla_nest_end(msg, nl_tcp);
10133
Johannes Berg2a0e0472013-01-23 22:57:40 +010010134 return 0;
10135}
10136
Luciano Coelho75453cc2015-01-09 14:06:37 +020010137static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10138 struct cfg80211_sched_scan_request *req)
10139{
Avraham Stern3b06d272015-10-12 09:51:34 +030010140 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010141 int i;
10142
10143 if (!req)
10144 return 0;
10145
10146 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10147 if (!nd)
10148 return -ENOBUFS;
10149
Avraham Stern3b06d272015-10-12 09:51:34 +030010150 if (req->n_scan_plans == 1 &&
10151 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10152 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010153 return -ENOBUFS;
10154
Luciano Coelho21fea562015-03-17 16:36:01 +020010155 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10156 return -ENOBUFS;
10157
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010158 if (req->relative_rssi_set) {
10159 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10160
10161 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10162 req->relative_rssi))
10163 return -ENOBUFS;
10164
10165 rssi_adjust.band = req->rssi_adjust.band;
10166 rssi_adjust.delta = req->rssi_adjust.delta;
10167 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10168 sizeof(rssi_adjust), &rssi_adjust))
10169 return -ENOBUFS;
10170 }
10171
Luciano Coelho75453cc2015-01-09 14:06:37 +020010172 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10173 if (!freqs)
10174 return -ENOBUFS;
10175
Johannes Berg53b18982016-09-14 09:59:21 +020010176 for (i = 0; i < req->n_channels; i++) {
10177 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10178 return -ENOBUFS;
10179 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010180
10181 nla_nest_end(msg, freqs);
10182
10183 if (req->n_match_sets) {
10184 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010185 if (!matches)
10186 return -ENOBUFS;
10187
Luciano Coelho75453cc2015-01-09 14:06:37 +020010188 for (i = 0; i < req->n_match_sets; i++) {
10189 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010190 if (!match)
10191 return -ENOBUFS;
10192
Johannes Berg53b18982016-09-14 09:59:21 +020010193 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10194 req->match_sets[i].ssid.ssid_len,
10195 req->match_sets[i].ssid.ssid))
10196 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010197 nla_nest_end(msg, match);
10198 }
10199 nla_nest_end(msg, matches);
10200 }
10201
Avraham Stern3b06d272015-10-12 09:51:34 +030010202 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10203 if (!scan_plans)
10204 return -ENOBUFS;
10205
10206 for (i = 0; i < req->n_scan_plans; i++) {
10207 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010208 if (!scan_plan)
10209 return -ENOBUFS;
10210
Avraham Stern3b06d272015-10-12 09:51:34 +030010211 if (!scan_plan ||
10212 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10213 req->scan_plans[i].interval) ||
10214 (req->scan_plans[i].iterations &&
10215 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10216 req->scan_plans[i].iterations)))
10217 return -ENOBUFS;
10218 nla_nest_end(msg, scan_plan);
10219 }
10220 nla_nest_end(msg, scan_plans);
10221
Luciano Coelho75453cc2015-01-09 14:06:37 +020010222 nla_nest_end(msg, nd);
10223
10224 return 0;
10225}
10226
Johannes Bergff1b6e62011-05-04 15:37:28 +020010227static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10228{
10229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10230 struct sk_buff *msg;
10231 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010232 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010233
Johannes Berg964dc9e2013-06-03 17:25:34 +020010234 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010235 return -EOPNOTSUPP;
10236
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010237 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010238 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010239 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10240 rdev->wiphy.wowlan_config->tcp->payload_len +
10241 rdev->wiphy.wowlan_config->tcp->wake_len +
10242 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010243 }
10244
10245 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010246 if (!msg)
10247 return -ENOMEM;
10248
Eric W. Biederman15e47302012-09-07 20:12:54 +000010249 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010250 NL80211_CMD_GET_WOWLAN);
10251 if (!hdr)
10252 goto nla_put_failure;
10253
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010254 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010255 struct nlattr *nl_wowlan;
10256
10257 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10258 if (!nl_wowlan)
10259 goto nla_put_failure;
10260
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010261 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010262 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010263 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010265 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010267 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010268 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010269 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010271 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010273 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10275 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010276
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010277 if (nl80211_send_wowlan_patterns(msg, rdev))
10278 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010279
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010280 if (nl80211_send_wowlan_tcp(msg,
10281 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010282 goto nla_put_failure;
10283
Luciano Coelho75453cc2015-01-09 14:06:37 +020010284 if (nl80211_send_wowlan_nd(
10285 msg,
10286 rdev->wiphy.wowlan_config->nd_config))
10287 goto nla_put_failure;
10288
Johannes Bergff1b6e62011-05-04 15:37:28 +020010289 nla_nest_end(msg, nl_wowlan);
10290 }
10291
10292 genlmsg_end(msg, hdr);
10293 return genlmsg_reply(msg, info);
10294
10295nla_put_failure:
10296 nlmsg_free(msg);
10297 return -ENOBUFS;
10298}
10299
Johannes Berg2a0e0472013-01-23 22:57:40 +010010300static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10301 struct nlattr *attr,
10302 struct cfg80211_wowlan *trig)
10303{
10304 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10305 struct cfg80211_wowlan_tcp *cfg;
10306 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10307 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10308 u32 size;
10309 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10310 int err, port;
10311
Johannes Berg964dc9e2013-06-03 17:25:34 +020010312 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010313 return -EINVAL;
10314
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010315 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010316 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010317 if (err)
10318 return err;
10319
10320 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10321 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10322 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10323 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10324 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10325 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10326 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10327 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10328 return -EINVAL;
10329
10330 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010331 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010332 return -EINVAL;
10333
10334 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010335 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010336 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010337 return -EINVAL;
10338
10339 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010340 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010341 return -EINVAL;
10342
10343 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10344 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10345 return -EINVAL;
10346
10347 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10348 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10349
10350 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10351 tokens_size = tokln - sizeof(*tok);
10352
10353 if (!tok->len || tokens_size % tok->len)
10354 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010355 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010356 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010357 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010358 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010359 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010360 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010361 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010362 return -EINVAL;
10363 if (tok->offset + tok->len > data_size)
10364 return -EINVAL;
10365 }
10366
10367 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10368 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010369 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010370 return -EINVAL;
10371 if (seq->len == 0 || seq->len > 4)
10372 return -EINVAL;
10373 if (seq->len + seq->offset > data_size)
10374 return -EINVAL;
10375 }
10376
10377 size = sizeof(*cfg);
10378 size += data_size;
10379 size += wake_size + wake_mask_size;
10380 size += tokens_size;
10381
10382 cfg = kzalloc(size, GFP_KERNEL);
10383 if (!cfg)
10384 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010385 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10386 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010387 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10388 ETH_ALEN);
10389 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10390 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10391 else
10392 port = 0;
10393#ifdef CONFIG_INET
10394 /* allocate a socket and port for it and use it */
10395 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10396 IPPROTO_TCP, &cfg->sock, 1);
10397 if (err) {
10398 kfree(cfg);
10399 return err;
10400 }
10401 if (inet_csk_get_port(cfg->sock->sk, port)) {
10402 sock_release(cfg->sock);
10403 kfree(cfg);
10404 return -EADDRINUSE;
10405 }
10406 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10407#else
10408 if (!port) {
10409 kfree(cfg);
10410 return -EINVAL;
10411 }
10412 cfg->src_port = port;
10413#endif
10414
10415 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10416 cfg->payload_len = data_size;
10417 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10418 memcpy((void *)cfg->payload,
10419 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10420 data_size);
10421 if (seq)
10422 cfg->payload_seq = *seq;
10423 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10424 cfg->wake_len = wake_size;
10425 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10426 memcpy((void *)cfg->wake_data,
10427 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10428 wake_size);
10429 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10430 data_size + wake_size;
10431 memcpy((void *)cfg->wake_mask,
10432 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10433 wake_mask_size);
10434 if (tok) {
10435 cfg->tokens_size = tokens_size;
10436 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10437 }
10438
10439 trig->tcp = cfg;
10440
10441 return 0;
10442}
10443
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010444static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10445 const struct wiphy_wowlan_support *wowlan,
10446 struct nlattr *attr,
10447 struct cfg80211_wowlan *trig)
10448{
10449 struct nlattr **tb;
10450 int err;
10451
10452 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10453 if (!tb)
10454 return -ENOMEM;
10455
10456 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10457 err = -EOPNOTSUPP;
10458 goto out;
10459 }
10460
Johannes Bergfceb6432017-04-12 14:34:07 +020010461 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10462 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010463 if (err)
10464 goto out;
10465
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010466 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10467 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010468 err = PTR_ERR_OR_ZERO(trig->nd_config);
10469 if (err)
10470 trig->nd_config = NULL;
10471
10472out:
10473 kfree(tb);
10474 return err;
10475}
10476
Johannes Bergff1b6e62011-05-04 15:37:28 +020010477static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10478{
10479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10480 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010481 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010482 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010483 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010484 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010485 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010486 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010487
Johannes Berg964dc9e2013-06-03 17:25:34 +020010488 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010489 return -EOPNOTSUPP;
10490
Johannes Bergae33bd82012-07-12 16:25:02 +020010491 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10492 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010493 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010494 goto set_wakeup;
10495 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010496
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010497 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10498 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010499 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010500 if (err)
10501 return err;
10502
10503 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10504 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10505 return -EINVAL;
10506 new_triggers.any = true;
10507 }
10508
10509 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10510 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10511 return -EINVAL;
10512 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010513 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010514 }
10515
10516 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10517 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10518 return -EINVAL;
10519 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010520 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010521 }
10522
Johannes Berg77dbbb12011-07-13 10:48:55 +020010523 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10524 return -EINVAL;
10525
10526 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10527 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10528 return -EINVAL;
10529 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010530 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010531 }
10532
10533 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10534 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10535 return -EINVAL;
10536 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010537 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010538 }
10539
10540 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10541 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10542 return -EINVAL;
10543 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010544 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010545 }
10546
10547 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10548 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10549 return -EINVAL;
10550 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010551 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010552 }
10553
Johannes Bergff1b6e62011-05-04 15:37:28 +020010554 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10555 struct nlattr *pat;
10556 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010557 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010558 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010559
Johannes Berg98fc4382015-03-01 09:10:13 +020010560 regular = true;
10561
Johannes Bergff1b6e62011-05-04 15:37:28 +020010562 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10563 rem)
10564 n_patterns++;
10565 if (n_patterns > wowlan->n_patterns)
10566 return -EINVAL;
10567
10568 new_triggers.patterns = kcalloc(n_patterns,
10569 sizeof(new_triggers.patterns[0]),
10570 GFP_KERNEL);
10571 if (!new_triggers.patterns)
10572 return -ENOMEM;
10573
10574 new_triggers.n_patterns = n_patterns;
10575 i = 0;
10576
10577 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10578 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010579 u8 *mask_pat;
10580
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010581 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030010582 nl80211_packet_pattern_policy,
10583 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010584 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010585 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10586 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010587 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010588 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010589 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010590 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010591 goto error;
10592 if (pat_len > wowlan->pattern_max_len ||
10593 pat_len < wowlan->pattern_min_len)
10594 goto error;
10595
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010596 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010597 pkt_offset = 0;
10598 else
10599 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010600 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010601 if (pkt_offset > wowlan->max_pkt_offset)
10602 goto error;
10603 new_triggers.patterns[i].pkt_offset = pkt_offset;
10604
Johannes Berg922bd802014-05-19 17:59:50 +020010605 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10606 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010607 err = -ENOMEM;
10608 goto error;
10609 }
Johannes Berg922bd802014-05-19 17:59:50 +020010610 new_triggers.patterns[i].mask = mask_pat;
10611 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010612 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010613 mask_pat += mask_len;
10614 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010615 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010616 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010617 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010618 pat_len);
10619 i++;
10620 }
10621 }
10622
Johannes Berg2a0e0472013-01-23 22:57:40 +010010623 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010624 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010625 err = nl80211_parse_wowlan_tcp(
10626 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10627 &new_triggers);
10628 if (err)
10629 goto error;
10630 }
10631
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010632 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010633 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010634 err = nl80211_parse_wowlan_nd(
10635 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10636 &new_triggers);
10637 if (err)
10638 goto error;
10639 }
10640
Johannes Berg98fc4382015-03-01 09:10:13 +020010641 /* The 'any' trigger means the device continues operating more or less
10642 * as in its normal operation mode and wakes up the host on most of the
10643 * normal interrupts (like packet RX, ...)
10644 * It therefore makes little sense to combine with the more constrained
10645 * wakeup trigger modes.
10646 */
10647 if (new_triggers.any && regular) {
10648 err = -EINVAL;
10649 goto error;
10650 }
10651
Johannes Bergae33bd82012-07-12 16:25:02 +020010652 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10653 if (!ntrig) {
10654 err = -ENOMEM;
10655 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010656 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010657 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010658 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010659
Johannes Bergae33bd82012-07-12 16:25:02 +020010660 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010661 if (rdev->ops->set_wakeup &&
10662 prev_enabled != !!rdev->wiphy.wowlan_config)
10663 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010664
Johannes Bergff1b6e62011-05-04 15:37:28 +020010665 return 0;
10666 error:
10667 for (i = 0; i < new_triggers.n_patterns; i++)
10668 kfree(new_triggers.patterns[i].mask);
10669 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010670 if (new_triggers.tcp && new_triggers.tcp->sock)
10671 sock_release(new_triggers.tcp->sock);
10672 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010673 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010674 return err;
10675}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010676#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010677
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010678static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10679 struct cfg80211_registered_device *rdev)
10680{
10681 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10682 int i, j, pat_len;
10683 struct cfg80211_coalesce_rules *rule;
10684
10685 if (!rdev->coalesce->n_rules)
10686 return 0;
10687
10688 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10689 if (!nl_rules)
10690 return -ENOBUFS;
10691
10692 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10693 nl_rule = nla_nest_start(msg, i + 1);
10694 if (!nl_rule)
10695 return -ENOBUFS;
10696
10697 rule = &rdev->coalesce->rules[i];
10698 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10699 rule->delay))
10700 return -ENOBUFS;
10701
10702 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10703 rule->condition))
10704 return -ENOBUFS;
10705
10706 nl_pats = nla_nest_start(msg,
10707 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10708 if (!nl_pats)
10709 return -ENOBUFS;
10710
10711 for (j = 0; j < rule->n_patterns; j++) {
10712 nl_pat = nla_nest_start(msg, j + 1);
10713 if (!nl_pat)
10714 return -ENOBUFS;
10715 pat_len = rule->patterns[j].pattern_len;
10716 if (nla_put(msg, NL80211_PKTPAT_MASK,
10717 DIV_ROUND_UP(pat_len, 8),
10718 rule->patterns[j].mask) ||
10719 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10720 rule->patterns[j].pattern) ||
10721 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10722 rule->patterns[j].pkt_offset))
10723 return -ENOBUFS;
10724 nla_nest_end(msg, nl_pat);
10725 }
10726 nla_nest_end(msg, nl_pats);
10727 nla_nest_end(msg, nl_rule);
10728 }
10729 nla_nest_end(msg, nl_rules);
10730
10731 return 0;
10732}
10733
10734static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10735{
10736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10737 struct sk_buff *msg;
10738 void *hdr;
10739
10740 if (!rdev->wiphy.coalesce)
10741 return -EOPNOTSUPP;
10742
10743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10744 if (!msg)
10745 return -ENOMEM;
10746
10747 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10748 NL80211_CMD_GET_COALESCE);
10749 if (!hdr)
10750 goto nla_put_failure;
10751
10752 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10753 goto nla_put_failure;
10754
10755 genlmsg_end(msg, hdr);
10756 return genlmsg_reply(msg, info);
10757
10758nla_put_failure:
10759 nlmsg_free(msg);
10760 return -ENOBUFS;
10761}
10762
10763void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10764{
10765 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10766 int i, j;
10767 struct cfg80211_coalesce_rules *rule;
10768
10769 if (!coalesce)
10770 return;
10771
10772 for (i = 0; i < coalesce->n_rules; i++) {
10773 rule = &coalesce->rules[i];
10774 for (j = 0; j < rule->n_patterns; j++)
10775 kfree(rule->patterns[j].mask);
10776 kfree(rule->patterns);
10777 }
10778 kfree(coalesce->rules);
10779 kfree(coalesce);
10780 rdev->coalesce = NULL;
10781}
10782
10783static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10784 struct nlattr *rule,
10785 struct cfg80211_coalesce_rules *new_rule)
10786{
10787 int err, i;
10788 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10789 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10790 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10791 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10792
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010793 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010794 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010795 if (err)
10796 return err;
10797
10798 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10799 new_rule->delay =
10800 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10801 if (new_rule->delay > coalesce->max_delay)
10802 return -EINVAL;
10803
10804 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10805 new_rule->condition =
10806 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10807 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10808 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10809 return -EINVAL;
10810
10811 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10812 return -EINVAL;
10813
10814 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10815 rem)
10816 n_patterns++;
10817 if (n_patterns > coalesce->n_patterns)
10818 return -EINVAL;
10819
10820 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10821 GFP_KERNEL);
10822 if (!new_rule->patterns)
10823 return -ENOMEM;
10824
10825 new_rule->n_patterns = n_patterns;
10826 i = 0;
10827
10828 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10829 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010830 u8 *mask_pat;
10831
Peng Xuad670232017-10-03 23:21:51 +030010832 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10833 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010834 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10835 !pat_tb[NL80211_PKTPAT_PATTERN])
10836 return -EINVAL;
10837 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10838 mask_len = DIV_ROUND_UP(pat_len, 8);
10839 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10840 return -EINVAL;
10841 if (pat_len > coalesce->pattern_max_len ||
10842 pat_len < coalesce->pattern_min_len)
10843 return -EINVAL;
10844
10845 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10846 pkt_offset = 0;
10847 else
10848 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10849 if (pkt_offset > coalesce->max_pkt_offset)
10850 return -EINVAL;
10851 new_rule->patterns[i].pkt_offset = pkt_offset;
10852
Johannes Berg922bd802014-05-19 17:59:50 +020010853 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10854 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010855 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010856
10857 new_rule->patterns[i].mask = mask_pat;
10858 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10859 mask_len);
10860
10861 mask_pat += mask_len;
10862 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010863 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010864 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10865 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010866 i++;
10867 }
10868
10869 return 0;
10870}
10871
10872static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10873{
10874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10875 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10876 struct cfg80211_coalesce new_coalesce = {};
10877 struct cfg80211_coalesce *n_coalesce;
10878 int err, rem_rule, n_rules = 0, i, j;
10879 struct nlattr *rule;
10880 struct cfg80211_coalesce_rules *tmp_rule;
10881
10882 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10883 return -EOPNOTSUPP;
10884
10885 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10886 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010887 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010888 return 0;
10889 }
10890
10891 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10892 rem_rule)
10893 n_rules++;
10894 if (n_rules > coalesce->n_rules)
10895 return -EINVAL;
10896
10897 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10898 GFP_KERNEL);
10899 if (!new_coalesce.rules)
10900 return -ENOMEM;
10901
10902 new_coalesce.n_rules = n_rules;
10903 i = 0;
10904
10905 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10906 rem_rule) {
10907 err = nl80211_parse_coalesce_rule(rdev, rule,
10908 &new_coalesce.rules[i]);
10909 if (err)
10910 goto error;
10911
10912 i++;
10913 }
10914
Ilan Peera1056b12015-10-22 22:27:46 +030010915 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010916 if (err)
10917 goto error;
10918
10919 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10920 if (!n_coalesce) {
10921 err = -ENOMEM;
10922 goto error;
10923 }
10924 cfg80211_rdev_free_coalesce(rdev);
10925 rdev->coalesce = n_coalesce;
10926
10927 return 0;
10928error:
10929 for (i = 0; i < new_coalesce.n_rules; i++) {
10930 tmp_rule = &new_coalesce.rules[i];
10931 for (j = 0; j < tmp_rule->n_patterns; j++)
10932 kfree(tmp_rule->patterns[j].mask);
10933 kfree(tmp_rule->patterns);
10934 }
10935 kfree(new_coalesce.rules);
10936
10937 return err;
10938}
10939
Johannes Berge5497d72011-07-05 16:35:40 +020010940static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10941{
10942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10943 struct net_device *dev = info->user_ptr[1];
10944 struct wireless_dev *wdev = dev->ieee80211_ptr;
10945 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10946 struct cfg80211_gtk_rekey_data rekey_data;
10947 int err;
10948
10949 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10950 return -EINVAL;
10951
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010952 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10953 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020010954 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020010955 if (err)
10956 return err;
10957
Vladis Dronove785fa02017-09-13 00:21:21 +020010958 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
10959 !tb[NL80211_REKEY_DATA_KCK])
10960 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020010961 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10962 return -ERANGE;
10963 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10964 return -ERANGE;
10965 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10966 return -ERANGE;
10967
Johannes Berg78f686c2014-09-10 22:28:06 +030010968 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10969 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10970 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010971
10972 wdev_lock(wdev);
10973 if (!wdev->current_bss) {
10974 err = -ENOTCONN;
10975 goto out;
10976 }
10977
10978 if (!rdev->ops->set_rekey_data) {
10979 err = -EOPNOTSUPP;
10980 goto out;
10981 }
10982
Hila Gonene35e4d22012-06-27 17:19:42 +030010983 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010984 out:
10985 wdev_unlock(wdev);
10986 return err;
10987}
10988
Johannes Berg28946da2011-11-04 11:18:12 +010010989static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10990 struct genl_info *info)
10991{
10992 struct net_device *dev = info->user_ptr[1];
10993 struct wireless_dev *wdev = dev->ieee80211_ptr;
10994
10995 if (wdev->iftype != NL80211_IFTYPE_AP &&
10996 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10997 return -EINVAL;
10998
Eric W. Biederman15e47302012-09-07 20:12:54 +000010999 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011000 return -EBUSY;
11001
Eric W. Biederman15e47302012-09-07 20:12:54 +000011002 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011003 return 0;
11004}
11005
Johannes Berg7f6cf312011-11-04 11:18:15 +010011006static int nl80211_probe_client(struct sk_buff *skb,
11007 struct genl_info *info)
11008{
11009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11010 struct net_device *dev = info->user_ptr[1];
11011 struct wireless_dev *wdev = dev->ieee80211_ptr;
11012 struct sk_buff *msg;
11013 void *hdr;
11014 const u8 *addr;
11015 u64 cookie;
11016 int err;
11017
11018 if (wdev->iftype != NL80211_IFTYPE_AP &&
11019 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11020 return -EOPNOTSUPP;
11021
11022 if (!info->attrs[NL80211_ATTR_MAC])
11023 return -EINVAL;
11024
11025 if (!rdev->ops->probe_client)
11026 return -EOPNOTSUPP;
11027
11028 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11029 if (!msg)
11030 return -ENOMEM;
11031
Eric W. Biederman15e47302012-09-07 20:12:54 +000011032 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011033 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011034 if (!hdr) {
11035 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011036 goto free_msg;
11037 }
11038
11039 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11040
Hila Gonene35e4d22012-06-27 17:19:42 +030011041 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011042 if (err)
11043 goto free_msg;
11044
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011045 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11046 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011047 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011048
11049 genlmsg_end(msg, hdr);
11050
11051 return genlmsg_reply(msg, info);
11052
11053 nla_put_failure:
11054 err = -ENOBUFS;
11055 free_msg:
11056 nlmsg_free(msg);
11057 return err;
11058}
11059
Johannes Berg5e760232011-11-04 11:18:17 +010011060static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11061{
11062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011063 struct cfg80211_beacon_registration *reg, *nreg;
11064 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011065
11066 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11067 return -EOPNOTSUPP;
11068
Ben Greear37c73b52012-10-26 14:49:25 -070011069 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11070 if (!nreg)
11071 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011072
Ben Greear37c73b52012-10-26 14:49:25 -070011073 /* First, check if already registered. */
11074 spin_lock_bh(&rdev->beacon_registrations_lock);
11075 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11076 if (reg->nlportid == info->snd_portid) {
11077 rv = -EALREADY;
11078 goto out_err;
11079 }
11080 }
11081 /* Add it to the list */
11082 nreg->nlportid = info->snd_portid;
11083 list_add(&nreg->list, &rdev->beacon_registrations);
11084
11085 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011086
11087 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011088out_err:
11089 spin_unlock_bh(&rdev->beacon_registrations_lock);
11090 kfree(nreg);
11091 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011092}
11093
Johannes Berg98104fde2012-06-16 00:19:54 +020011094static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11095{
11096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11097 struct wireless_dev *wdev = info->user_ptr[1];
11098 int err;
11099
11100 if (!rdev->ops->start_p2p_device)
11101 return -EOPNOTSUPP;
11102
11103 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11104 return -EOPNOTSUPP;
11105
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011106 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011107 return 0;
11108
Luciano Coelhob6a55012014-02-27 11:07:21 +020011109 if (rfkill_blocked(rdev->rfkill))
11110 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011111
Johannes Bergeeb126e2012-10-23 15:16:50 +020011112 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011113 if (err)
11114 return err;
11115
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011116 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011117 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011118
11119 return 0;
11120}
11121
11122static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11123{
11124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11125 struct wireless_dev *wdev = info->user_ptr[1];
11126
11127 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11128 return -EOPNOTSUPP;
11129
11130 if (!rdev->ops->stop_p2p_device)
11131 return -EOPNOTSUPP;
11132
Johannes Bergf9f47522013-03-19 15:04:07 +010011133 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011134
11135 return 0;
11136}
11137
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011138static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11139{
11140 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11141 struct wireless_dev *wdev = info->user_ptr[1];
11142 struct cfg80211_nan_conf conf = {};
11143 int err;
11144
11145 if (wdev->iftype != NL80211_IFTYPE_NAN)
11146 return -EOPNOTSUPP;
11147
Johannes Bergeeb04a92016-11-21 13:55:48 +010011148 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011149 return -EEXIST;
11150
11151 if (rfkill_blocked(rdev->rfkill))
11152 return -ERFKILL;
11153
11154 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11155 return -EINVAL;
11156
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011157 conf.master_pref =
11158 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11159 if (!conf.master_pref)
11160 return -EINVAL;
11161
Luca Coelho85859892017-02-08 15:00:34 +020011162 if (info->attrs[NL80211_ATTR_BANDS]) {
11163 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11164
11165 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11166 return -EOPNOTSUPP;
11167
11168 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11169 return -EINVAL;
11170
11171 conf.bands = bands;
11172 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011173
11174 err = rdev_start_nan(rdev, wdev, &conf);
11175 if (err)
11176 return err;
11177
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011178 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011179 rdev->opencount++;
11180
11181 return 0;
11182}
11183
11184static int nl80211_stop_nan(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
11189 if (wdev->iftype != NL80211_IFTYPE_NAN)
11190 return -EOPNOTSUPP;
11191
11192 cfg80211_stop_nan(rdev, wdev);
11193
11194 return 0;
11195}
11196
Ayala Bekera442b762016-09-20 17:31:15 +030011197static int validate_nan_filter(struct nlattr *filter_attr)
11198{
11199 struct nlattr *attr;
11200 int len = 0, n_entries = 0, rem;
11201
11202 nla_for_each_nested(attr, filter_attr, rem) {
11203 len += nla_len(attr);
11204 n_entries++;
11205 }
11206
11207 if (len >= U8_MAX)
11208 return -EINVAL;
11209
11210 return n_entries;
11211}
11212
11213static int handle_nan_filter(struct nlattr *attr_filter,
11214 struct cfg80211_nan_func *func,
11215 bool tx)
11216{
11217 struct nlattr *attr;
11218 int n_entries, rem, i;
11219 struct cfg80211_nan_func_filter *filter;
11220
11221 n_entries = validate_nan_filter(attr_filter);
11222 if (n_entries < 0)
11223 return n_entries;
11224
11225 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11226
11227 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11228 if (!filter)
11229 return -ENOMEM;
11230
11231 i = 0;
11232 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011233 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011234 filter[i].len = nla_len(attr);
11235 i++;
11236 }
11237 if (tx) {
11238 func->num_tx_filters = n_entries;
11239 func->tx_filters = filter;
11240 } else {
11241 func->num_rx_filters = n_entries;
11242 func->rx_filters = filter;
11243 }
11244
11245 return 0;
11246}
11247
11248static int nl80211_nan_add_func(struct sk_buff *skb,
11249 struct genl_info *info)
11250{
11251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11252 struct wireless_dev *wdev = info->user_ptr[1];
11253 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11254 struct cfg80211_nan_func *func;
11255 struct sk_buff *msg = NULL;
11256 void *hdr = NULL;
11257 int err = 0;
11258
11259 if (wdev->iftype != NL80211_IFTYPE_NAN)
11260 return -EOPNOTSUPP;
11261
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011262 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011263 return -ENOTCONN;
11264
11265 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11266 return -EINVAL;
11267
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011268 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11269 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011270 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011271 if (err)
11272 return err;
11273
11274 func = kzalloc(sizeof(*func), GFP_KERNEL);
11275 if (!func)
11276 return -ENOMEM;
11277
11278 func->cookie = wdev->wiphy->cookie_counter++;
11279
11280 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11281 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11282 err = -EINVAL;
11283 goto out;
11284 }
11285
11286
11287 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11288
11289 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11290 err = -EINVAL;
11291 goto out;
11292 }
11293
11294 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11295 sizeof(func->service_id));
11296
11297 func->close_range =
11298 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11299
11300 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11301 func->serv_spec_info_len =
11302 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11303 func->serv_spec_info =
11304 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11305 func->serv_spec_info_len,
11306 GFP_KERNEL);
11307 if (!func->serv_spec_info) {
11308 err = -ENOMEM;
11309 goto out;
11310 }
11311 }
11312
11313 if (tb[NL80211_NAN_FUNC_TTL])
11314 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11315
11316 switch (func->type) {
11317 case NL80211_NAN_FUNC_PUBLISH:
11318 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11319 err = -EINVAL;
11320 goto out;
11321 }
11322
11323 func->publish_type =
11324 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11325 func->publish_bcast =
11326 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11327
11328 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11329 func->publish_bcast) {
11330 err = -EINVAL;
11331 goto out;
11332 }
11333 break;
11334 case NL80211_NAN_FUNC_SUBSCRIBE:
11335 func->subscribe_active =
11336 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11337 break;
11338 case NL80211_NAN_FUNC_FOLLOW_UP:
11339 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11340 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11341 err = -EINVAL;
11342 goto out;
11343 }
11344
11345 func->followup_id =
11346 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11347 func->followup_reqid =
11348 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11349 memcpy(func->followup_dest.addr,
11350 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11351 sizeof(func->followup_dest.addr));
11352 if (func->ttl) {
11353 err = -EINVAL;
11354 goto out;
11355 }
11356 break;
11357 default:
11358 err = -EINVAL;
11359 goto out;
11360 }
11361
11362 if (tb[NL80211_NAN_FUNC_SRF]) {
11363 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11364
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011365 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11366 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011367 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011368 if (err)
11369 goto out;
11370
11371 func->srf_include =
11372 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11373
11374 if (srf_tb[NL80211_NAN_SRF_BF]) {
11375 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11376 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11377 err = -EINVAL;
11378 goto out;
11379 }
11380
11381 func->srf_bf_len =
11382 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11383 func->srf_bf =
11384 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11385 func->srf_bf_len, GFP_KERNEL);
11386 if (!func->srf_bf) {
11387 err = -ENOMEM;
11388 goto out;
11389 }
11390
11391 func->srf_bf_idx =
11392 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11393 } else {
11394 struct nlattr *attr, *mac_attr =
11395 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11396 int n_entries, rem, i = 0;
11397
11398 if (!mac_attr) {
11399 err = -EINVAL;
11400 goto out;
11401 }
11402
11403 n_entries = validate_acl_mac_addrs(mac_attr);
11404 if (n_entries <= 0) {
11405 err = -EINVAL;
11406 goto out;
11407 }
11408
11409 func->srf_num_macs = n_entries;
11410 func->srf_macs =
11411 kzalloc(sizeof(*func->srf_macs) * n_entries,
11412 GFP_KERNEL);
11413 if (!func->srf_macs) {
11414 err = -ENOMEM;
11415 goto out;
11416 }
11417
11418 nla_for_each_nested(attr, mac_attr, rem)
11419 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11420 sizeof(*func->srf_macs));
11421 }
11422 }
11423
11424 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11425 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11426 func, true);
11427 if (err)
11428 goto out;
11429 }
11430
11431 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11432 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11433 func, false);
11434 if (err)
11435 goto out;
11436 }
11437
11438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11439 if (!msg) {
11440 err = -ENOMEM;
11441 goto out;
11442 }
11443
11444 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11445 NL80211_CMD_ADD_NAN_FUNCTION);
11446 /* This can't really happen - we just allocated 4KB */
11447 if (WARN_ON(!hdr)) {
11448 err = -ENOMEM;
11449 goto out;
11450 }
11451
11452 err = rdev_add_nan_func(rdev, wdev, func);
11453out:
11454 if (err < 0) {
11455 cfg80211_free_nan_func(func);
11456 nlmsg_free(msg);
11457 return err;
11458 }
11459
11460 /* propagate the instance id and cookie to userspace */
11461 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11462 NL80211_ATTR_PAD))
11463 goto nla_put_failure;
11464
11465 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11466 if (!func_attr)
11467 goto nla_put_failure;
11468
11469 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11470 func->instance_id))
11471 goto nla_put_failure;
11472
11473 nla_nest_end(msg, func_attr);
11474
11475 genlmsg_end(msg, hdr);
11476 return genlmsg_reply(msg, info);
11477
11478nla_put_failure:
11479 nlmsg_free(msg);
11480 return -ENOBUFS;
11481}
11482
11483static int nl80211_nan_del_func(struct sk_buff *skb,
11484 struct genl_info *info)
11485{
11486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11487 struct wireless_dev *wdev = info->user_ptr[1];
11488 u64 cookie;
11489
11490 if (wdev->iftype != NL80211_IFTYPE_NAN)
11491 return -EOPNOTSUPP;
11492
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011493 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011494 return -ENOTCONN;
11495
11496 if (!info->attrs[NL80211_ATTR_COOKIE])
11497 return -EINVAL;
11498
Ayala Bekera442b762016-09-20 17:31:15 +030011499 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11500
11501 rdev_del_nan_func(rdev, wdev, cookie);
11502
11503 return 0;
11504}
11505
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011506static int nl80211_nan_change_config(struct sk_buff *skb,
11507 struct genl_info *info)
11508{
11509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11510 struct wireless_dev *wdev = info->user_ptr[1];
11511 struct cfg80211_nan_conf conf = {};
11512 u32 changed = 0;
11513
11514 if (wdev->iftype != NL80211_IFTYPE_NAN)
11515 return -EOPNOTSUPP;
11516
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011517 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011518 return -ENOTCONN;
11519
11520 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11521 conf.master_pref =
11522 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11523 if (conf.master_pref <= 1 || conf.master_pref == 255)
11524 return -EINVAL;
11525
11526 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11527 }
11528
Luca Coelho85859892017-02-08 15:00:34 +020011529 if (info->attrs[NL80211_ATTR_BANDS]) {
11530 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11531
11532 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11533 return -EOPNOTSUPP;
11534
11535 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11536 return -EINVAL;
11537
11538 conf.bands = bands;
11539 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011540 }
11541
11542 if (!changed)
11543 return -EINVAL;
11544
11545 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11546}
11547
Ayala Beker50bcd312016-09-20 17:31:17 +030011548void cfg80211_nan_match(struct wireless_dev *wdev,
11549 struct cfg80211_nan_match_params *match, gfp_t gfp)
11550{
11551 struct wiphy *wiphy = wdev->wiphy;
11552 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11553 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11554 struct sk_buff *msg;
11555 void *hdr;
11556
11557 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11558 return;
11559
11560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11561 if (!msg)
11562 return;
11563
11564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11565 if (!hdr) {
11566 nlmsg_free(msg);
11567 return;
11568 }
11569
11570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11571 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11572 wdev->netdev->ifindex)) ||
11573 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11574 NL80211_ATTR_PAD))
11575 goto nla_put_failure;
11576
11577 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11578 NL80211_ATTR_PAD) ||
11579 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11580 goto nla_put_failure;
11581
11582 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11583 if (!match_attr)
11584 goto nla_put_failure;
11585
11586 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11587 if (!local_func_attr)
11588 goto nla_put_failure;
11589
11590 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11591 goto nla_put_failure;
11592
11593 nla_nest_end(msg, local_func_attr);
11594
11595 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11596 if (!peer_func_attr)
11597 goto nla_put_failure;
11598
11599 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11600 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11601 goto nla_put_failure;
11602
11603 if (match->info && match->info_len &&
11604 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11605 match->info))
11606 goto nla_put_failure;
11607
11608 nla_nest_end(msg, peer_func_attr);
11609 nla_nest_end(msg, match_attr);
11610 genlmsg_end(msg, hdr);
11611
11612 if (!wdev->owner_nlportid)
11613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11614 msg, 0, NL80211_MCGRP_NAN, gfp);
11615 else
11616 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11617 wdev->owner_nlportid);
11618
11619 return;
11620
11621nla_put_failure:
11622 nlmsg_free(msg);
11623}
11624EXPORT_SYMBOL(cfg80211_nan_match);
11625
Ayala Beker368e5a72016-09-20 17:31:18 +030011626void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11627 u8 inst_id,
11628 enum nl80211_nan_func_term_reason reason,
11629 u64 cookie, gfp_t gfp)
11630{
11631 struct wiphy *wiphy = wdev->wiphy;
11632 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11633 struct sk_buff *msg;
11634 struct nlattr *func_attr;
11635 void *hdr;
11636
11637 if (WARN_ON(!inst_id))
11638 return;
11639
11640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11641 if (!msg)
11642 return;
11643
11644 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11645 if (!hdr) {
11646 nlmsg_free(msg);
11647 return;
11648 }
11649
11650 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11651 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11652 wdev->netdev->ifindex)) ||
11653 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11654 NL80211_ATTR_PAD))
11655 goto nla_put_failure;
11656
11657 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11658 NL80211_ATTR_PAD))
11659 goto nla_put_failure;
11660
11661 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11662 if (!func_attr)
11663 goto nla_put_failure;
11664
11665 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11666 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11667 goto nla_put_failure;
11668
11669 nla_nest_end(msg, func_attr);
11670 genlmsg_end(msg, hdr);
11671
11672 if (!wdev->owner_nlportid)
11673 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11674 msg, 0, NL80211_MCGRP_NAN, gfp);
11675 else
11676 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11677 wdev->owner_nlportid);
11678
11679 return;
11680
11681nla_put_failure:
11682 nlmsg_free(msg);
11683}
11684EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11685
Johannes Berg3713b4e2013-02-14 16:19:38 +010011686static int nl80211_get_protocol_features(struct sk_buff *skb,
11687 struct genl_info *info)
11688{
11689 void *hdr;
11690 struct sk_buff *msg;
11691
11692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11693 if (!msg)
11694 return -ENOMEM;
11695
11696 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11697 NL80211_CMD_GET_PROTOCOL_FEATURES);
11698 if (!hdr)
11699 goto nla_put_failure;
11700
11701 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11702 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11703 goto nla_put_failure;
11704
11705 genlmsg_end(msg, hdr);
11706 return genlmsg_reply(msg, info);
11707
11708 nla_put_failure:
11709 kfree_skb(msg);
11710 return -ENOBUFS;
11711}
11712
Jouni Malinen355199e2013-02-27 17:14:27 +020011713static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11714{
11715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11716 struct cfg80211_update_ft_ies_params ft_params;
11717 struct net_device *dev = info->user_ptr[1];
11718
11719 if (!rdev->ops->update_ft_ies)
11720 return -EOPNOTSUPP;
11721
11722 if (!info->attrs[NL80211_ATTR_MDID] ||
11723 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11724 return -EINVAL;
11725
11726 memset(&ft_params, 0, sizeof(ft_params));
11727 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11728 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11729 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11730
11731 return rdev_update_ft_ies(rdev, dev, &ft_params);
11732}
11733
Arend van Spriel5de17982013-04-18 15:49:00 +020011734static int nl80211_crit_protocol_start(struct sk_buff *skb,
11735 struct genl_info *info)
11736{
11737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11738 struct wireless_dev *wdev = info->user_ptr[1];
11739 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11740 u16 duration;
11741 int ret;
11742
11743 if (!rdev->ops->crit_proto_start)
11744 return -EOPNOTSUPP;
11745
11746 if (WARN_ON(!rdev->ops->crit_proto_stop))
11747 return -EINVAL;
11748
11749 if (rdev->crit_proto_nlportid)
11750 return -EBUSY;
11751
11752 /* determine protocol if provided */
11753 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11754 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11755
11756 if (proto >= NUM_NL80211_CRIT_PROTO)
11757 return -EINVAL;
11758
11759 /* timeout must be provided */
11760 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11761 return -EINVAL;
11762
11763 duration =
11764 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11765
11766 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11767 return -ERANGE;
11768
11769 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11770 if (!ret)
11771 rdev->crit_proto_nlportid = info->snd_portid;
11772
11773 return ret;
11774}
11775
11776static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11777 struct genl_info *info)
11778{
11779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11780 struct wireless_dev *wdev = info->user_ptr[1];
11781
11782 if (!rdev->ops->crit_proto_stop)
11783 return -EOPNOTSUPP;
11784
11785 if (rdev->crit_proto_nlportid) {
11786 rdev->crit_proto_nlportid = 0;
11787 rdev_crit_proto_stop(rdev, wdev);
11788 }
11789 return 0;
11790}
11791
Johannes Bergad7e7182013-11-13 13:37:47 +010011792static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11793{
11794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11795 struct wireless_dev *wdev =
11796 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11797 int i, err;
11798 u32 vid, subcmd;
11799
11800 if (!rdev->wiphy.vendor_commands)
11801 return -EOPNOTSUPP;
11802
11803 if (IS_ERR(wdev)) {
11804 err = PTR_ERR(wdev);
11805 if (err != -EINVAL)
11806 return err;
11807 wdev = NULL;
11808 } else if (wdev->wiphy != &rdev->wiphy) {
11809 return -EINVAL;
11810 }
11811
11812 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11813 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11814 return -EINVAL;
11815
11816 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11817 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11818 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11819 const struct wiphy_vendor_command *vcmd;
11820 void *data = NULL;
11821 int len = 0;
11822
11823 vcmd = &rdev->wiphy.vendor_commands[i];
11824
11825 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11826 continue;
11827
11828 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11829 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11830 if (!wdev)
11831 return -EINVAL;
11832 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11833 !wdev->netdev)
11834 return -EINVAL;
11835
11836 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011837 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011838 return -ENETDOWN;
11839 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011840
11841 if (!vcmd->doit)
11842 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011843 } else {
11844 wdev = NULL;
11845 }
11846
11847 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11848 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11849 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11850 }
11851
11852 rdev->cur_cmd_info = info;
11853 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11854 data, len);
11855 rdev->cur_cmd_info = NULL;
11856 return err;
11857 }
11858
11859 return -EOPNOTSUPP;
11860}
11861
Johannes Berg7bdbe402015-08-15 22:39:49 +030011862static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11863 struct netlink_callback *cb,
11864 struct cfg80211_registered_device **rdev,
11865 struct wireless_dev **wdev)
11866{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011867 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011868 u32 vid, subcmd;
11869 unsigned int i;
11870 int vcmd_idx = -1;
11871 int err;
11872 void *data = NULL;
11873 unsigned int data_len = 0;
11874
Johannes Berg7bdbe402015-08-15 22:39:49 +030011875 if (cb->args[0]) {
11876 /* subtract the 1 again here */
11877 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11878 struct wireless_dev *tmp;
11879
Johannes Bergea90e0d2017-03-15 14:26:04 +010011880 if (!wiphy)
11881 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011882 *rdev = wiphy_to_rdev(wiphy);
11883 *wdev = NULL;
11884
11885 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011886 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011887 if (tmp->identifier == cb->args[1] - 1) {
11888 *wdev = tmp;
11889 break;
11890 }
11891 }
11892 }
11893
11894 /* keep rtnl locked in successful case */
11895 return 0;
11896 }
11897
Johannes Bergfceb6432017-04-12 14:34:07 +020011898 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11899 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011900 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011901 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011902
Johannes Bergc90c39d2016-10-24 14:40:01 +020011903 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011904 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11905 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011906
Johannes Bergc90c39d2016-10-24 14:40:01 +020011907 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011908 if (IS_ERR(*wdev))
11909 *wdev = NULL;
11910
Johannes Bergc90c39d2016-10-24 14:40:01 +020011911 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011912 if (IS_ERR(*rdev))
11913 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011914
Johannes Bergc90c39d2016-10-24 14:40:01 +020011915 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11916 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011917
11918 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11919 const struct wiphy_vendor_command *vcmd;
11920
11921 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11922
11923 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11924 continue;
11925
Johannes Bergea90e0d2017-03-15 14:26:04 +010011926 if (!vcmd->dumpit)
11927 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011928
11929 vcmd_idx = i;
11930 break;
11931 }
11932
Johannes Bergea90e0d2017-03-15 14:26:04 +010011933 if (vcmd_idx < 0)
11934 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011935
Johannes Bergc90c39d2016-10-24 14:40:01 +020011936 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11937 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11938 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011939 }
11940
11941 /* 0 is the first index - add 1 to parse only once */
11942 cb->args[0] = (*rdev)->wiphy_idx + 1;
11943 /* add 1 to know if it was NULL */
11944 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11945 cb->args[2] = vcmd_idx;
11946 cb->args[3] = (unsigned long)data;
11947 cb->args[4] = data_len;
11948
11949 /* keep rtnl locked in successful case */
11950 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011951}
11952
11953static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11954 struct netlink_callback *cb)
11955{
11956 struct cfg80211_registered_device *rdev;
11957 struct wireless_dev *wdev;
11958 unsigned int vcmd_idx;
11959 const struct wiphy_vendor_command *vcmd;
11960 void *data;
11961 int data_len;
11962 int err;
11963 struct nlattr *vendor_data;
11964
Johannes Bergea90e0d2017-03-15 14:26:04 +010011965 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011966 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11967 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011968 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011969
11970 vcmd_idx = cb->args[2];
11971 data = (void *)cb->args[3];
11972 data_len = cb->args[4];
11973 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11974
11975 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11976 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011977 if (!wdev) {
11978 err = -EINVAL;
11979 goto out;
11980 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011981 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010011982 !wdev->netdev) {
11983 err = -EINVAL;
11984 goto out;
11985 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011986
11987 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011988 if (!wdev_running(wdev)) {
11989 err = -ENETDOWN;
11990 goto out;
11991 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011992 }
11993 }
11994
11995 while (1) {
11996 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11997 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11998 NL80211_CMD_VENDOR);
11999 if (!hdr)
12000 break;
12001
12002 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012003 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12004 wdev_id(wdev),
12005 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012006 genlmsg_cancel(skb, hdr);
12007 break;
12008 }
12009
12010 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12011 if (!vendor_data) {
12012 genlmsg_cancel(skb, hdr);
12013 break;
12014 }
12015
12016 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12017 (unsigned long *)&cb->args[5]);
12018 nla_nest_end(skb, vendor_data);
12019
12020 if (err == -ENOBUFS || err == -ENOENT) {
12021 genlmsg_cancel(skb, hdr);
12022 break;
12023 } else if (err) {
12024 genlmsg_cancel(skb, hdr);
12025 goto out;
12026 }
12027
12028 genlmsg_end(skb, hdr);
12029 }
12030
12031 err = skb->len;
12032 out:
12033 rtnl_unlock();
12034 return err;
12035}
12036
Johannes Bergad7e7182013-11-13 13:37:47 +010012037struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12038 enum nl80211_commands cmd,
12039 enum nl80211_attrs attr,
12040 int approxlen)
12041{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012042 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012043
12044 if (WARN_ON(!rdev->cur_cmd_info))
12045 return NULL;
12046
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012047 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012048 rdev->cur_cmd_info->snd_portid,
12049 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012050 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012051}
12052EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12053
12054int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12055{
12056 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12057 void *hdr = ((void **)skb->cb)[1];
12058 struct nlattr *data = ((void **)skb->cb)[2];
12059
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012060 /* clear CB data for netlink core to own from now on */
12061 memset(skb->cb, 0, sizeof(skb->cb));
12062
Johannes Bergad7e7182013-11-13 13:37:47 +010012063 if (WARN_ON(!rdev->cur_cmd_info)) {
12064 kfree_skb(skb);
12065 return -EINVAL;
12066 }
12067
12068 nla_nest_end(skb, data);
12069 genlmsg_end(skb, hdr);
12070 return genlmsg_reply(skb, rdev->cur_cmd_info);
12071}
12072EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12073
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012074static int nl80211_set_qos_map(struct sk_buff *skb,
12075 struct genl_info *info)
12076{
12077 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12078 struct cfg80211_qos_map *qos_map = NULL;
12079 struct net_device *dev = info->user_ptr[1];
12080 u8 *pos, len, num_des, des_len, des;
12081 int ret;
12082
12083 if (!rdev->ops->set_qos_map)
12084 return -EOPNOTSUPP;
12085
12086 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12087 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12088 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12089
12090 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12091 len > IEEE80211_QOS_MAP_LEN_MAX)
12092 return -EINVAL;
12093
12094 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12095 if (!qos_map)
12096 return -ENOMEM;
12097
12098 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12099 if (num_des) {
12100 des_len = num_des *
12101 sizeof(struct cfg80211_dscp_exception);
12102 memcpy(qos_map->dscp_exception, pos, des_len);
12103 qos_map->num_des = num_des;
12104 for (des = 0; des < num_des; des++) {
12105 if (qos_map->dscp_exception[des].up > 7) {
12106 kfree(qos_map);
12107 return -EINVAL;
12108 }
12109 }
12110 pos += des_len;
12111 }
12112 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12113 }
12114
12115 wdev_lock(dev->ieee80211_ptr);
12116 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12117 if (!ret)
12118 ret = rdev_set_qos_map(rdev, dev, qos_map);
12119 wdev_unlock(dev->ieee80211_ptr);
12120
12121 kfree(qos_map);
12122 return ret;
12123}
12124
Johannes Berg960d01a2014-09-09 22:55:35 +030012125static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12126{
12127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12128 struct net_device *dev = info->user_ptr[1];
12129 struct wireless_dev *wdev = dev->ieee80211_ptr;
12130 const u8 *peer;
12131 u8 tsid, up;
12132 u16 admitted_time = 0;
12133 int err;
12134
Johannes Berg723e73a2014-10-22 09:25:06 +020012135 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012136 return -EOPNOTSUPP;
12137
12138 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12139 !info->attrs[NL80211_ATTR_USER_PRIO])
12140 return -EINVAL;
12141
12142 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12143 if (tsid >= IEEE80211_NUM_TIDS)
12144 return -EINVAL;
12145
12146 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12147 if (up >= IEEE80211_NUM_UPS)
12148 return -EINVAL;
12149
12150 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012151 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012152 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012153 * need more attributes for that (e.g. BA session requirement);
12154 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012155 */
12156 return -EINVAL;
12157 }
12158
12159 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12160
12161 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12162 admitted_time =
12163 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12164 if (!admitted_time)
12165 return -EINVAL;
12166 }
12167
12168 wdev_lock(wdev);
12169 switch (wdev->iftype) {
12170 case NL80211_IFTYPE_STATION:
12171 case NL80211_IFTYPE_P2P_CLIENT:
12172 if (wdev->current_bss)
12173 break;
12174 err = -ENOTCONN;
12175 goto out;
12176 default:
12177 err = -EOPNOTSUPP;
12178 goto out;
12179 }
12180
12181 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12182
12183 out:
12184 wdev_unlock(wdev);
12185 return err;
12186}
12187
12188static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12189{
12190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12191 struct net_device *dev = info->user_ptr[1];
12192 struct wireless_dev *wdev = dev->ieee80211_ptr;
12193 const u8 *peer;
12194 u8 tsid;
12195 int err;
12196
12197 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12198 return -EINVAL;
12199
12200 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12201 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12202
12203 wdev_lock(wdev);
12204 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12205 wdev_unlock(wdev);
12206
12207 return err;
12208}
12209
Arik Nemtsov1057d352014-11-19 12:54:26 +020012210static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12211 struct genl_info *info)
12212{
12213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12214 struct net_device *dev = info->user_ptr[1];
12215 struct wireless_dev *wdev = dev->ieee80211_ptr;
12216 struct cfg80211_chan_def chandef = {};
12217 const u8 *addr;
12218 u8 oper_class;
12219 int err;
12220
12221 if (!rdev->ops->tdls_channel_switch ||
12222 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12223 return -EOPNOTSUPP;
12224
12225 switch (dev->ieee80211_ptr->iftype) {
12226 case NL80211_IFTYPE_STATION:
12227 case NL80211_IFTYPE_P2P_CLIENT:
12228 break;
12229 default:
12230 return -EOPNOTSUPP;
12231 }
12232
12233 if (!info->attrs[NL80211_ATTR_MAC] ||
12234 !info->attrs[NL80211_ATTR_OPER_CLASS])
12235 return -EINVAL;
12236
12237 err = nl80211_parse_chandef(rdev, info, &chandef);
12238 if (err)
12239 return err;
12240
12241 /*
12242 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12243 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12244 * specification is not defined for them.
12245 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012246 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012247 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12248 chandef.width != NL80211_CHAN_WIDTH_20)
12249 return -EINVAL;
12250
12251 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012252 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12253 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012254 return -EINVAL;
12255
12256 /* don't allow switching to DFS channels */
12257 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12258 return -EINVAL;
12259
12260 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12261 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12262
12263 wdev_lock(wdev);
12264 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12265 wdev_unlock(wdev);
12266
12267 return err;
12268}
12269
12270static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12271 struct genl_info *info)
12272{
12273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12274 struct net_device *dev = info->user_ptr[1];
12275 struct wireless_dev *wdev = dev->ieee80211_ptr;
12276 const u8 *addr;
12277
12278 if (!rdev->ops->tdls_channel_switch ||
12279 !rdev->ops->tdls_cancel_channel_switch ||
12280 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12281 return -EOPNOTSUPP;
12282
12283 switch (dev->ieee80211_ptr->iftype) {
12284 case NL80211_IFTYPE_STATION:
12285 case NL80211_IFTYPE_P2P_CLIENT:
12286 break;
12287 default:
12288 return -EOPNOTSUPP;
12289 }
12290
12291 if (!info->attrs[NL80211_ATTR_MAC])
12292 return -EINVAL;
12293
12294 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12295
12296 wdev_lock(wdev);
12297 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12298 wdev_unlock(wdev);
12299
12300 return 0;
12301}
12302
Michael Braunce0ce132016-10-10 19:12:22 +020012303static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12304 struct genl_info *info)
12305{
12306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12307 struct net_device *dev = info->user_ptr[1];
12308 struct wireless_dev *wdev = dev->ieee80211_ptr;
12309 const struct nlattr *nla;
12310 bool enabled;
12311
Michael Braunce0ce132016-10-10 19:12:22 +020012312 if (!rdev->ops->set_multicast_to_unicast)
12313 return -EOPNOTSUPP;
12314
12315 if (wdev->iftype != NL80211_IFTYPE_AP &&
12316 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12317 return -EOPNOTSUPP;
12318
12319 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12320 enabled = nla_get_flag(nla);
12321
12322 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12323}
12324
Avraham Stern3a00df52017-06-09 13:08:43 +010012325static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12326{
12327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12328 struct net_device *dev = info->user_ptr[1];
12329 struct wireless_dev *wdev = dev->ieee80211_ptr;
12330 struct cfg80211_pmk_conf pmk_conf = {};
12331 int ret;
12332
12333 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12334 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12335 return -EOPNOTSUPP;
12336
12337 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12338 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12339 return -EOPNOTSUPP;
12340
12341 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12342 return -EINVAL;
12343
12344 wdev_lock(wdev);
12345 if (!wdev->current_bss) {
12346 ret = -ENOTCONN;
12347 goto out;
12348 }
12349
12350 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12351 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12352 ret = -EINVAL;
12353 goto out;
12354 }
12355
12356 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12357 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12358 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12359 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12360 ret = -EINVAL;
12361 goto out;
12362 }
12363
12364 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12365 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12366
12367 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12368 ret = -EINVAL;
12369 goto out;
12370 }
12371
12372 pmk_conf.pmk_r0_name =
12373 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12374 }
12375
12376 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12377out:
12378 wdev_unlock(wdev);
12379 return ret;
12380}
12381
12382static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12383{
12384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12385 struct net_device *dev = info->user_ptr[1];
12386 struct wireless_dev *wdev = dev->ieee80211_ptr;
12387 const u8 *aa;
12388 int ret;
12389
12390 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12391 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12392 return -EOPNOTSUPP;
12393
12394 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12395 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12396 return -EOPNOTSUPP;
12397
12398 if (!info->attrs[NL80211_ATTR_MAC])
12399 return -EINVAL;
12400
12401 wdev_lock(wdev);
12402 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12403 ret = rdev_del_pmk(rdev, dev, aa);
12404 wdev_unlock(wdev);
12405
12406 return ret;
12407}
12408
Johannes Berg4c476992010-10-04 21:36:35 +020012409#define NL80211_FLAG_NEED_WIPHY 0x01
12410#define NL80211_FLAG_NEED_NETDEV 0x02
12411#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012412#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12413#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12414 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012415#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012416/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012417#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12418 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012419#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012420
Johannes Bergf84f7712013-11-14 17:14:45 +010012421static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012422 struct genl_info *info)
12423{
12424 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012425 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012426 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012427 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12428
12429 if (rtnl)
12430 rtnl_lock();
12431
12432 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012433 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012434 if (IS_ERR(rdev)) {
12435 if (rtnl)
12436 rtnl_unlock();
12437 return PTR_ERR(rdev);
12438 }
12439 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012440 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12441 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012442 ASSERT_RTNL();
12443
Johannes Berg89a54e42012-06-15 14:33:17 +020012444 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12445 info->attrs);
12446 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012447 if (rtnl)
12448 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012449 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012450 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012451
Johannes Berg89a54e42012-06-15 14:33:17 +020012452 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012453 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012454
Johannes Berg1bf614e2012-06-15 15:23:36 +020012455 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12456 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012457 if (rtnl)
12458 rtnl_unlock();
12459 return -EINVAL;
12460 }
12461
12462 info->user_ptr[1] = dev;
12463 } else {
12464 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012465 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012466
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012467 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12468 !wdev_running(wdev)) {
12469 if (rtnl)
12470 rtnl_unlock();
12471 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012472 }
12473
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012474 if (dev)
12475 dev_hold(dev);
12476
Johannes Berg4c476992010-10-04 21:36:35 +020012477 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012478 }
12479
12480 return 0;
12481}
12482
Johannes Bergf84f7712013-11-14 17:14:45 +010012483static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012484 struct genl_info *info)
12485{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012486 if (info->user_ptr[1]) {
12487 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12488 struct wireless_dev *wdev = info->user_ptr[1];
12489
12490 if (wdev->netdev)
12491 dev_put(wdev->netdev);
12492 } else {
12493 dev_put(info->user_ptr[1]);
12494 }
12495 }
Johannes Berg5393b912014-09-10 15:00:16 +030012496
Johannes Berg4c476992010-10-04 21:36:35 +020012497 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12498 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012499
12500 /* If needed, clear the netlink message payload from the SKB
12501 * as it might contain key data that shouldn't stick around on
12502 * the heap after the SKB is freed. The netlink message header
12503 * is still needed for further processing, so leave it intact.
12504 */
12505 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12506 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12507
12508 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12509 }
Johannes Berg4c476992010-10-04 21:36:35 +020012510}
12511
Johannes Berg4534de82013-11-14 17:14:46 +010012512static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012513 {
12514 .cmd = NL80211_CMD_GET_WIPHY,
12515 .doit = nl80211_get_wiphy,
12516 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012517 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012518 .policy = nl80211_policy,
12519 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012520 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12521 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012522 },
12523 {
12524 .cmd = NL80211_CMD_SET_WIPHY,
12525 .doit = nl80211_set_wiphy,
12526 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012527 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012528 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012529 },
12530 {
12531 .cmd = NL80211_CMD_GET_INTERFACE,
12532 .doit = nl80211_get_interface,
12533 .dumpit = nl80211_dump_interface,
12534 .policy = nl80211_policy,
12535 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012536 .internal_flags = NL80211_FLAG_NEED_WDEV |
12537 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012538 },
12539 {
12540 .cmd = NL80211_CMD_SET_INTERFACE,
12541 .doit = nl80211_set_interface,
12542 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012543 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012544 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12545 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012546 },
12547 {
12548 .cmd = NL80211_CMD_NEW_INTERFACE,
12549 .doit = nl80211_new_interface,
12550 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012551 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012552 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12553 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012554 },
12555 {
12556 .cmd = NL80211_CMD_DEL_INTERFACE,
12557 .doit = nl80211_del_interface,
12558 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012559 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012560 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012561 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012562 },
Johannes Berg41ade002007-12-19 02:03:29 +010012563 {
12564 .cmd = NL80211_CMD_GET_KEY,
12565 .doit = nl80211_get_key,
12566 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012567 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012568 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012569 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012570 },
12571 {
12572 .cmd = NL80211_CMD_SET_KEY,
12573 .doit = nl80211_set_key,
12574 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012575 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012576 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012577 NL80211_FLAG_NEED_RTNL |
12578 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012579 },
12580 {
12581 .cmd = NL80211_CMD_NEW_KEY,
12582 .doit = nl80211_new_key,
12583 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012584 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012586 NL80211_FLAG_NEED_RTNL |
12587 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012588 },
12589 {
12590 .cmd = NL80211_CMD_DEL_KEY,
12591 .doit = nl80211_del_key,
12592 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012593 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012595 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012596 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012597 {
12598 .cmd = NL80211_CMD_SET_BEACON,
12599 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012600 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012601 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012603 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012604 },
12605 {
Johannes Berg88600202012-02-13 15:17:18 +010012606 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012607 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012608 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012609 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012611 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012612 },
12613 {
Johannes Berg88600202012-02-13 15:17:18 +010012614 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012615 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012616 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012617 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012619 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012620 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012621 {
12622 .cmd = NL80211_CMD_GET_STATION,
12623 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012624 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012625 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012626 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12627 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012628 },
12629 {
12630 .cmd = NL80211_CMD_SET_STATION,
12631 .doit = nl80211_set_station,
12632 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012633 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012635 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012636 },
12637 {
12638 .cmd = NL80211_CMD_NEW_STATION,
12639 .doit = nl80211_new_station,
12640 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012641 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012643 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012644 },
12645 {
12646 .cmd = NL80211_CMD_DEL_STATION,
12647 .doit = nl80211_del_station,
12648 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012649 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012650 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012651 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012652 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012653 {
12654 .cmd = NL80211_CMD_GET_MPATH,
12655 .doit = nl80211_get_mpath,
12656 .dumpit = nl80211_dump_mpath,
12657 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012658 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012659 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012660 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012661 },
12662 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012663 .cmd = NL80211_CMD_GET_MPP,
12664 .doit = nl80211_get_mpp,
12665 .dumpit = nl80211_dump_mpp,
12666 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012667 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12669 NL80211_FLAG_NEED_RTNL,
12670 },
12671 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012672 .cmd = NL80211_CMD_SET_MPATH,
12673 .doit = nl80211_set_mpath,
12674 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012675 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012677 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012678 },
12679 {
12680 .cmd = NL80211_CMD_NEW_MPATH,
12681 .doit = nl80211_new_mpath,
12682 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012683 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012685 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012686 },
12687 {
12688 .cmd = NL80211_CMD_DEL_MPATH,
12689 .doit = nl80211_del_mpath,
12690 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012691 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012693 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012694 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012695 {
12696 .cmd = NL80211_CMD_SET_BSS,
12697 .doit = nl80211_set_bss,
12698 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012699 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012701 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012702 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012703 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012704 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012705 .doit = nl80211_get_reg_do,
12706 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012707 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012708 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012709 /* can be retrieved by unprivileged users */
12710 },
Johannes Bergb6863032015-10-15 09:25:18 +020012711#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012712 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012713 .cmd = NL80211_CMD_SET_REG,
12714 .doit = nl80211_set_reg,
12715 .policy = nl80211_policy,
12716 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012717 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012718 },
Johannes Bergb6863032015-10-15 09:25:18 +020012719#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012720 {
12721 .cmd = NL80211_CMD_REQ_SET_REG,
12722 .doit = nl80211_req_set_reg,
12723 .policy = nl80211_policy,
12724 .flags = GENL_ADMIN_PERM,
12725 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012726 {
Johannes Berg1ea4ff32017-09-13 16:07:22 +020012727 .cmd = NL80211_CMD_RELOAD_REGDB,
12728 .doit = nl80211_reload_regdb,
12729 .policy = nl80211_policy,
12730 .flags = GENL_ADMIN_PERM,
12731 },
12732 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012733 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12734 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012735 .policy = nl80211_policy,
12736 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012738 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012739 },
12740 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012741 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12742 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012743 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012744 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012746 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012747 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012748 {
Johannes Berg2a519312009-02-10 21:25:55 +010012749 .cmd = NL80211_CMD_TRIGGER_SCAN,
12750 .doit = nl80211_trigger_scan,
12751 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012752 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012753 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012754 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012755 },
12756 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012757 .cmd = NL80211_CMD_ABORT_SCAN,
12758 .doit = nl80211_abort_scan,
12759 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012760 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012761 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12762 NL80211_FLAG_NEED_RTNL,
12763 },
12764 {
Johannes Berg2a519312009-02-10 21:25:55 +010012765 .cmd = NL80211_CMD_GET_SCAN,
12766 .policy = nl80211_policy,
12767 .dumpit = nl80211_dump_scan,
12768 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012769 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012770 .cmd = NL80211_CMD_START_SCHED_SCAN,
12771 .doit = nl80211_start_sched_scan,
12772 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012773 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012774 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12775 NL80211_FLAG_NEED_RTNL,
12776 },
12777 {
12778 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12779 .doit = nl80211_stop_sched_scan,
12780 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012781 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012782 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12783 NL80211_FLAG_NEED_RTNL,
12784 },
12785 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012786 .cmd = NL80211_CMD_AUTHENTICATE,
12787 .doit = nl80211_authenticate,
12788 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012789 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012790 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012791 NL80211_FLAG_NEED_RTNL |
12792 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012793 },
12794 {
12795 .cmd = NL80211_CMD_ASSOCIATE,
12796 .doit = nl80211_associate,
12797 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012798 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012799 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012800 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012801 },
12802 {
12803 .cmd = NL80211_CMD_DEAUTHENTICATE,
12804 .doit = nl80211_deauthenticate,
12805 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012806 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012807 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012808 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012809 },
12810 {
12811 .cmd = NL80211_CMD_DISASSOCIATE,
12812 .doit = nl80211_disassociate,
12813 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012814 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012816 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012817 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012818 {
12819 .cmd = NL80211_CMD_JOIN_IBSS,
12820 .doit = nl80211_join_ibss,
12821 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012822 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012824 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012825 },
12826 {
12827 .cmd = NL80211_CMD_LEAVE_IBSS,
12828 .doit = nl80211_leave_ibss,
12829 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012830 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012832 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012833 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012834#ifdef CONFIG_NL80211_TESTMODE
12835 {
12836 .cmd = NL80211_CMD_TESTMODE,
12837 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012838 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012839 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012840 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012841 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12842 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012843 },
12844#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012845 {
12846 .cmd = NL80211_CMD_CONNECT,
12847 .doit = nl80211_connect,
12848 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012849 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012851 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012852 },
12853 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012854 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12855 .doit = nl80211_update_connect_params,
12856 .policy = nl80211_policy,
12857 .flags = GENL_ADMIN_PERM,
12858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12859 NL80211_FLAG_NEED_RTNL,
12860 },
12861 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012862 .cmd = NL80211_CMD_DISCONNECT,
12863 .doit = nl80211_disconnect,
12864 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012865 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012867 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012868 },
Johannes Berg463d0182009-07-14 00:33:35 +020012869 {
12870 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12871 .doit = nl80211_wiphy_netns,
12872 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012873 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012874 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12875 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012876 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012877 {
12878 .cmd = NL80211_CMD_GET_SURVEY,
12879 .policy = nl80211_policy,
12880 .dumpit = nl80211_dump_survey,
12881 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012882 {
12883 .cmd = NL80211_CMD_SET_PMKSA,
12884 .doit = nl80211_setdel_pmksa,
12885 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012886 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012888 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012889 },
12890 {
12891 .cmd = NL80211_CMD_DEL_PMKSA,
12892 .doit = nl80211_setdel_pmksa,
12893 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012894 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012895 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012896 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012897 },
12898 {
12899 .cmd = NL80211_CMD_FLUSH_PMKSA,
12900 .doit = nl80211_flush_pmksa,
12901 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012902 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012903 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012904 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012905 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012906 {
12907 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12908 .doit = nl80211_remain_on_channel,
12909 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012910 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012911 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012912 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012913 },
12914 {
12915 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12916 .doit = nl80211_cancel_remain_on_channel,
12917 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012918 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012919 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012920 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012921 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012922 {
12923 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12924 .doit = nl80211_set_tx_bitrate_mask,
12925 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012926 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012927 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12928 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012929 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012930 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012931 .cmd = NL80211_CMD_REGISTER_FRAME,
12932 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012933 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012934 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012935 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012936 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012937 },
12938 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012939 .cmd = NL80211_CMD_FRAME,
12940 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012941 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012942 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012943 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012944 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012945 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012946 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012947 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12948 .doit = nl80211_tx_mgmt_cancel_wait,
12949 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012950 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012951 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012952 NL80211_FLAG_NEED_RTNL,
12953 },
12954 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012955 .cmd = NL80211_CMD_SET_POWER_SAVE,
12956 .doit = nl80211_set_power_save,
12957 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012958 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012959 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12960 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012961 },
12962 {
12963 .cmd = NL80211_CMD_GET_POWER_SAVE,
12964 .doit = nl80211_get_power_save,
12965 .policy = nl80211_policy,
12966 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012967 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12968 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012969 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012970 {
12971 .cmd = NL80211_CMD_SET_CQM,
12972 .doit = nl80211_set_cqm,
12973 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012974 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012975 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12976 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012977 },
Johannes Bergf444de02010-05-05 15:25:02 +020012978 {
12979 .cmd = NL80211_CMD_SET_CHANNEL,
12980 .doit = nl80211_set_channel,
12981 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012982 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012983 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12984 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012985 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012986 {
12987 .cmd = NL80211_CMD_SET_WDS_PEER,
12988 .doit = nl80211_set_wds_peer,
12989 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012990 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012991 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12992 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012993 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012994 {
12995 .cmd = NL80211_CMD_JOIN_MESH,
12996 .doit = nl80211_join_mesh,
12997 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012998 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13000 NL80211_FLAG_NEED_RTNL,
13001 },
13002 {
13003 .cmd = NL80211_CMD_LEAVE_MESH,
13004 .doit = nl80211_leave_mesh,
13005 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013006 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13008 NL80211_FLAG_NEED_RTNL,
13009 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013010 {
13011 .cmd = NL80211_CMD_JOIN_OCB,
13012 .doit = nl80211_join_ocb,
13013 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013014 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13016 NL80211_FLAG_NEED_RTNL,
13017 },
13018 {
13019 .cmd = NL80211_CMD_LEAVE_OCB,
13020 .doit = nl80211_leave_ocb,
13021 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013022 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13024 NL80211_FLAG_NEED_RTNL,
13025 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013026#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013027 {
13028 .cmd = NL80211_CMD_GET_WOWLAN,
13029 .doit = nl80211_get_wowlan,
13030 .policy = nl80211_policy,
13031 /* can be retrieved by unprivileged users */
13032 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13033 NL80211_FLAG_NEED_RTNL,
13034 },
13035 {
13036 .cmd = NL80211_CMD_SET_WOWLAN,
13037 .doit = nl80211_set_wowlan,
13038 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013039 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013040 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13041 NL80211_FLAG_NEED_RTNL,
13042 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013043#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013044 {
13045 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13046 .doit = nl80211_set_rekey_data,
13047 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013048 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013050 NL80211_FLAG_NEED_RTNL |
13051 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013052 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013053 {
13054 .cmd = NL80211_CMD_TDLS_MGMT,
13055 .doit = nl80211_tdls_mgmt,
13056 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013057 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013058 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13059 NL80211_FLAG_NEED_RTNL,
13060 },
13061 {
13062 .cmd = NL80211_CMD_TDLS_OPER,
13063 .doit = nl80211_tdls_oper,
13064 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013065 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013066 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13067 NL80211_FLAG_NEED_RTNL,
13068 },
Johannes Berg28946da2011-11-04 11:18:12 +010013069 {
13070 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13071 .doit = nl80211_register_unexpected_frame,
13072 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013073 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013074 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13075 NL80211_FLAG_NEED_RTNL,
13076 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013077 {
13078 .cmd = NL80211_CMD_PROBE_CLIENT,
13079 .doit = nl80211_probe_client,
13080 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013081 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013083 NL80211_FLAG_NEED_RTNL,
13084 },
Johannes Berg5e760232011-11-04 11:18:17 +010013085 {
13086 .cmd = NL80211_CMD_REGISTER_BEACONS,
13087 .doit = nl80211_register_beacons,
13088 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013089 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013090 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13091 NL80211_FLAG_NEED_RTNL,
13092 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013093 {
13094 .cmd = NL80211_CMD_SET_NOACK_MAP,
13095 .doit = nl80211_set_noack_map,
13096 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013097 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013098 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13099 NL80211_FLAG_NEED_RTNL,
13100 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013101 {
13102 .cmd = NL80211_CMD_START_P2P_DEVICE,
13103 .doit = nl80211_start_p2p_device,
13104 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013105 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013106 .internal_flags = NL80211_FLAG_NEED_WDEV |
13107 NL80211_FLAG_NEED_RTNL,
13108 },
13109 {
13110 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13111 .doit = nl80211_stop_p2p_device,
13112 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013113 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013114 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13115 NL80211_FLAG_NEED_RTNL,
13116 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013117 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013118 .cmd = NL80211_CMD_START_NAN,
13119 .doit = nl80211_start_nan,
13120 .policy = nl80211_policy,
13121 .flags = GENL_ADMIN_PERM,
13122 .internal_flags = NL80211_FLAG_NEED_WDEV |
13123 NL80211_FLAG_NEED_RTNL,
13124 },
13125 {
13126 .cmd = NL80211_CMD_STOP_NAN,
13127 .doit = nl80211_stop_nan,
13128 .policy = nl80211_policy,
13129 .flags = GENL_ADMIN_PERM,
13130 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13131 NL80211_FLAG_NEED_RTNL,
13132 },
13133 {
Ayala Bekera442b762016-09-20 17:31:15 +030013134 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13135 .doit = nl80211_nan_add_func,
13136 .policy = nl80211_policy,
13137 .flags = GENL_ADMIN_PERM,
13138 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13139 NL80211_FLAG_NEED_RTNL,
13140 },
13141 {
13142 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13143 .doit = nl80211_nan_del_func,
13144 .policy = nl80211_policy,
13145 .flags = GENL_ADMIN_PERM,
13146 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13147 NL80211_FLAG_NEED_RTNL,
13148 },
13149 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013150 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13151 .doit = nl80211_nan_change_config,
13152 .policy = nl80211_policy,
13153 .flags = GENL_ADMIN_PERM,
13154 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13155 NL80211_FLAG_NEED_RTNL,
13156 },
13157 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013158 .cmd = NL80211_CMD_SET_MCAST_RATE,
13159 .doit = nl80211_set_mcast_rate,
13160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013161 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013162 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13163 NL80211_FLAG_NEED_RTNL,
13164 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013165 {
13166 .cmd = NL80211_CMD_SET_MAC_ACL,
13167 .doit = nl80211_set_mac_acl,
13168 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013169 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013170 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13171 NL80211_FLAG_NEED_RTNL,
13172 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013173 {
13174 .cmd = NL80211_CMD_RADAR_DETECT,
13175 .doit = nl80211_start_radar_detection,
13176 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013177 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13179 NL80211_FLAG_NEED_RTNL,
13180 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013181 {
13182 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13183 .doit = nl80211_get_protocol_features,
13184 .policy = nl80211_policy,
13185 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013186 {
13187 .cmd = NL80211_CMD_UPDATE_FT_IES,
13188 .doit = nl80211_update_ft_ies,
13189 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013190 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13192 NL80211_FLAG_NEED_RTNL,
13193 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013194 {
13195 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13196 .doit = nl80211_crit_protocol_start,
13197 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013198 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013199 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13200 NL80211_FLAG_NEED_RTNL,
13201 },
13202 {
13203 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13204 .doit = nl80211_crit_protocol_stop,
13205 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013206 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013207 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13208 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013209 },
13210 {
13211 .cmd = NL80211_CMD_GET_COALESCE,
13212 .doit = nl80211_get_coalesce,
13213 .policy = nl80211_policy,
13214 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13215 NL80211_FLAG_NEED_RTNL,
13216 },
13217 {
13218 .cmd = NL80211_CMD_SET_COALESCE,
13219 .doit = nl80211_set_coalesce,
13220 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013221 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013222 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13223 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013224 },
13225 {
13226 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13227 .doit = nl80211_channel_switch,
13228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013229 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13231 NL80211_FLAG_NEED_RTNL,
13232 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013233 {
13234 .cmd = NL80211_CMD_VENDOR,
13235 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013236 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013237 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013238 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013239 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13240 NL80211_FLAG_NEED_RTNL,
13241 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013242 {
13243 .cmd = NL80211_CMD_SET_QOS_MAP,
13244 .doit = nl80211_set_qos_map,
13245 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013246 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013247 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13248 NL80211_FLAG_NEED_RTNL,
13249 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013250 {
13251 .cmd = NL80211_CMD_ADD_TX_TS,
13252 .doit = nl80211_add_tx_ts,
13253 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013254 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013255 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13256 NL80211_FLAG_NEED_RTNL,
13257 },
13258 {
13259 .cmd = NL80211_CMD_DEL_TX_TS,
13260 .doit = nl80211_del_tx_ts,
13261 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013262 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013263 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13264 NL80211_FLAG_NEED_RTNL,
13265 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013266 {
13267 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13268 .doit = nl80211_tdls_channel_switch,
13269 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013270 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13272 NL80211_FLAG_NEED_RTNL,
13273 },
13274 {
13275 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13276 .doit = nl80211_tdls_cancel_channel_switch,
13277 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013278 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13280 NL80211_FLAG_NEED_RTNL,
13281 },
Michael Braunce0ce132016-10-10 19:12:22 +020013282 {
13283 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13284 .doit = nl80211_set_multicast_to_unicast,
13285 .policy = nl80211_policy,
13286 .flags = GENL_UNS_ADMIN_PERM,
13287 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13288 NL80211_FLAG_NEED_RTNL,
13289 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013290 {
13291 .cmd = NL80211_CMD_SET_PMK,
13292 .doit = nl80211_set_pmk,
13293 .policy = nl80211_policy,
13294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13295 NL80211_FLAG_NEED_RTNL,
13296 },
13297 {
13298 .cmd = NL80211_CMD_DEL_PMK,
13299 .doit = nl80211_del_pmk,
13300 .policy = nl80211_policy,
13301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13302 NL80211_FLAG_NEED_RTNL,
13303 },
13304
Johannes Berg55682962007-09-20 13:09:35 -040013305};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013306
Johannes Berg56989f62016-10-24 14:40:05 +020013307static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013308 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13309 .hdrsize = 0, /* no private header */
13310 .version = 1, /* no particular meaning now */
13311 .maxattr = NL80211_ATTR_MAX,
13312 .netnsok = true,
13313 .pre_doit = nl80211_pre_doit,
13314 .post_doit = nl80211_post_doit,
13315 .module = THIS_MODULE,
13316 .ops = nl80211_ops,
13317 .n_ops = ARRAY_SIZE(nl80211_ops),
13318 .mcgrps = nl80211_mcgrps,
13319 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13320};
13321
Johannes Berg55682962007-09-20 13:09:35 -040013322/* notification functions */
13323
Johannes Berg3bb20552014-05-26 13:52:25 +020013324void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13325 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013326{
13327 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013328 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013329
Johannes Berg3bb20552014-05-26 13:52:25 +020013330 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13331 cmd != NL80211_CMD_DEL_WIPHY);
13332
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013333 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013334 if (!msg)
13335 return;
13336
Johannes Berg3bb20552014-05-26 13:52:25 +020013337 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013338 nlmsg_free(msg);
13339 return;
13340 }
13341
Johannes Berg68eb5502013-11-19 15:19:38 +010013342 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013343 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013344}
13345
Denis Kenzior896ff062016-08-03 16:58:33 -050013346void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13347 struct wireless_dev *wdev,
13348 enum nl80211_commands cmd)
13349{
13350 struct sk_buff *msg;
13351
13352 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13353 cmd != NL80211_CMD_DEL_INTERFACE);
13354
13355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13356 if (!msg)
13357 return;
13358
13359 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13360 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13361 nlmsg_free(msg);
13362 return;
13363 }
13364
13365 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13366 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13367}
13368
Johannes Berg362a4152009-05-24 16:43:15 +020013369static int nl80211_add_scan_req(struct sk_buff *msg,
13370 struct cfg80211_registered_device *rdev)
13371{
13372 struct cfg80211_scan_request *req = rdev->scan_req;
13373 struct nlattr *nest;
13374 int i;
13375
13376 if (WARN_ON(!req))
13377 return 0;
13378
13379 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13380 if (!nest)
13381 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013382 for (i = 0; i < req->n_ssids; i++) {
13383 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13384 goto nla_put_failure;
13385 }
Johannes Berg362a4152009-05-24 16:43:15 +020013386 nla_nest_end(msg, nest);
13387
13388 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13389 if (!nest)
13390 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013391 for (i = 0; i < req->n_channels; i++) {
13392 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13393 goto nla_put_failure;
13394 }
Johannes Berg362a4152009-05-24 16:43:15 +020013395 nla_nest_end(msg, nest);
13396
David S. Miller9360ffd2012-03-29 04:41:26 -040013397 if (req->ie &&
13398 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13399 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013400
Johannes Bergae917c92013-10-25 11:05:22 +020013401 if (req->flags &&
13402 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13403 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013404
Avraham Stern1d762502016-07-05 17:10:13 +030013405 if (req->info.scan_start_tsf &&
13406 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13407 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13408 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13409 req->info.tsf_bssid)))
13410 goto nla_put_failure;
13411
Johannes Berg362a4152009-05-24 16:43:15 +020013412 return 0;
13413 nla_put_failure:
13414 return -ENOBUFS;
13415}
13416
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013417static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013418 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013419 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013420 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013421 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013422{
13423 void *hdr;
13424
Eric W. Biederman15e47302012-09-07 20:12:54 +000013425 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013426 if (!hdr)
13427 return -1;
13428
David S. Miller9360ffd2012-03-29 04:41:26 -040013429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013430 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13431 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13433 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013434 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013435
Johannes Berg362a4152009-05-24 16:43:15 +020013436 /* ignore errors and send incomplete event anyway */
13437 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013438
Johannes Berg053c0952015-01-16 22:09:00 +010013439 genlmsg_end(msg, hdr);
13440 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013441
13442 nla_put_failure:
13443 genlmsg_cancel(msg, hdr);
13444 return -EMSGSIZE;
13445}
13446
Luciano Coelho807f8a82011-05-11 17:09:35 +030013447static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013448nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013449 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013450{
13451 void *hdr;
13452
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013453 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013454 if (!hdr)
13455 return -1;
13456
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13458 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13459 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13460 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13461 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013462 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013463
Johannes Berg053c0952015-01-16 22:09:00 +010013464 genlmsg_end(msg, hdr);
13465 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013466
13467 nla_put_failure:
13468 genlmsg_cancel(msg, hdr);
13469 return -EMSGSIZE;
13470}
13471
Johannes Berga538e2d2009-06-16 19:56:42 +020013472void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013473 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013474{
13475 struct sk_buff *msg;
13476
Thomas Graf58050fc2012-06-28 03:57:45 +000013477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013478 if (!msg)
13479 return;
13480
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013481 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013482 NL80211_CMD_TRIGGER_SCAN) < 0) {
13483 nlmsg_free(msg);
13484 return;
13485 }
13486
Johannes Berg68eb5502013-11-19 15:19:38 +010013487 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013488 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013489}
13490
Johannes Bergf9d15d12014-01-22 11:14:19 +020013491struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13492 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013493{
13494 struct sk_buff *msg;
13495
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013496 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013497 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013498 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013499
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013500 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013501 aborted ? NL80211_CMD_SCAN_ABORTED :
13502 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013503 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013504 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013505 }
13506
Johannes Bergf9d15d12014-01-22 11:14:19 +020013507 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013508}
13509
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013510/* send message created by nl80211_build_scan_msg() */
13511void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13512 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013513{
Johannes Berg2a519312009-02-10 21:25:55 +010013514 if (!msg)
13515 return;
13516
Johannes Berg68eb5502013-11-19 15:19:38 +010013517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013518 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013519}
13520
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013521void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013522{
13523 struct sk_buff *msg;
13524
Thomas Graf58050fc2012-06-28 03:57:45 +000013525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013526 if (!msg)
13527 return;
13528
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013529 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013530 nlmsg_free(msg);
13531 return;
13532 }
13533
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013534 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013535 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013536}
13537
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013538static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13539 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013540{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013541 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013542 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13543 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013544
David S. Miller9360ffd2012-03-29 04:41:26 -040013545 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13546 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13547 NL80211_REGDOM_TYPE_WORLD))
13548 goto nla_put_failure;
13549 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13550 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13551 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13552 goto nla_put_failure;
13553 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13554 request->intersect) {
13555 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13556 NL80211_REGDOM_TYPE_INTERSECTION))
13557 goto nla_put_failure;
13558 } else {
13559 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13560 NL80211_REGDOM_TYPE_COUNTRY) ||
13561 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13562 request->alpha2))
13563 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013564 }
13565
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013566 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13567 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13568
13569 if (wiphy &&
13570 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13571 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013572
13573 if (wiphy &&
13574 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13575 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13576 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013577 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013578
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013579 return true;
13580
13581nla_put_failure:
13582 return false;
13583}
13584
13585/*
13586 * This can happen on global regulatory changes or device specific settings
13587 * based on custom regulatory domains.
13588 */
13589void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13590 struct regulatory_request *request)
13591{
13592 struct sk_buff *msg;
13593 void *hdr;
13594
13595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13596 if (!msg)
13597 return;
13598
13599 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13600 if (!hdr) {
13601 nlmsg_free(msg);
13602 return;
13603 }
13604
13605 if (nl80211_reg_change_event_fill(msg, request) == false)
13606 goto nla_put_failure;
13607
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013608 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013609
Johannes Bergbc43b282009-07-25 10:54:13 +020013610 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013611 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013612 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013613 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013614
13615 return;
13616
13617nla_put_failure:
13618 genlmsg_cancel(msg, hdr);
13619 nlmsg_free(msg);
13620}
13621
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013622static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13623 struct net_device *netdev,
13624 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013625 enum nl80211_commands cmd, gfp_t gfp,
13626 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013627{
13628 struct sk_buff *msg;
13629 void *hdr;
13630
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013631 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013632 if (!msg)
13633 return;
13634
13635 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13636 if (!hdr) {
13637 nlmsg_free(msg);
13638 return;
13639 }
13640
David S. Miller9360ffd2012-03-29 04:41:26 -040013641 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13642 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13643 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13644 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013645
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013646 if (uapsd_queues >= 0) {
13647 struct nlattr *nla_wmm =
13648 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13649 if (!nla_wmm)
13650 goto nla_put_failure;
13651
13652 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13653 uapsd_queues))
13654 goto nla_put_failure;
13655
13656 nla_nest_end(msg, nla_wmm);
13657 }
13658
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013659 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013660
Johannes Berg68eb5502013-11-19 15:19:38 +010013661 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013662 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013663 return;
13664
13665 nla_put_failure:
13666 genlmsg_cancel(msg, hdr);
13667 nlmsg_free(msg);
13668}
13669
13670void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013671 struct net_device *netdev, const u8 *buf,
13672 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013673{
13674 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013675 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013676}
13677
13678void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13679 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013680 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013681{
Johannes Berge6d6e342009-07-01 21:26:47 +020013682 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013683 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013684}
13685
Jouni Malinen53b46b82009-03-27 20:53:56 +020013686void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013687 struct net_device *netdev, const u8 *buf,
13688 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013689{
13690 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013691 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013692}
13693
Jouni Malinen53b46b82009-03-27 20:53:56 +020013694void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13695 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013696 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013697{
13698 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013699 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013700}
13701
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013702void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13703 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013704{
Johannes Berg947add32013-02-22 22:05:20 +010013705 struct wireless_dev *wdev = dev->ieee80211_ptr;
13706 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013707 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013708 const struct ieee80211_mgmt *mgmt = (void *)buf;
13709 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013710
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013711 if (WARN_ON(len < 2))
13712 return;
13713
13714 if (ieee80211_is_deauth(mgmt->frame_control))
13715 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13716 else
13717 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13718
13719 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013720 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013721}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013722EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013723
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013724static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13725 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013726 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013727{
13728 struct sk_buff *msg;
13729 void *hdr;
13730
Johannes Berge6d6e342009-07-01 21:26:47 +020013731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013732 if (!msg)
13733 return;
13734
13735 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13736 if (!hdr) {
13737 nlmsg_free(msg);
13738 return;
13739 }
13740
David S. Miller9360ffd2012-03-29 04:41:26 -040013741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13742 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13743 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13744 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13745 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013746
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013747 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013748
Johannes Berg68eb5502013-11-19 15:19:38 +010013749 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013750 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013751 return;
13752
13753 nla_put_failure:
13754 genlmsg_cancel(msg, hdr);
13755 nlmsg_free(msg);
13756}
13757
13758void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013759 struct net_device *netdev, const u8 *addr,
13760 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013761{
13762 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013763 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013764}
13765
13766void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013767 struct net_device *netdev, const u8 *addr,
13768 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013769{
Johannes Berge6d6e342009-07-01 21:26:47 +020013770 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13771 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013772}
13773
Samuel Ortizb23aa672009-07-01 21:26:54 +020013774void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013775 struct net_device *netdev,
13776 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013777 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013778{
13779 struct sk_buff *msg;
13780 void *hdr;
13781
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013782 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13783 cr->fils_kek_len + cr->pmk_len +
13784 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013785 if (!msg)
13786 return;
13787
13788 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13789 if (!hdr) {
13790 nlmsg_free(msg);
13791 return;
13792 }
13793
David S. Miller9360ffd2012-03-29 04:41:26 -040013794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13795 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013796 (cr->bssid &&
13797 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013798 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013799 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13800 cr->status) ||
13801 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013802 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013803 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13804 cr->timeout_reason))) ||
13805 (cr->req_ie &&
13806 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13807 (cr->resp_ie &&
13808 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013809 cr->resp_ie)) ||
13810 (cr->update_erp_next_seq_num &&
13811 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13812 cr->fils_erp_next_seq_num)) ||
13813 (cr->status == WLAN_STATUS_SUCCESS &&
13814 ((cr->fils_kek &&
13815 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13816 cr->fils_kek)) ||
13817 (cr->pmk &&
13818 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13819 (cr->pmkid &&
13820 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013821 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013822
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013823 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013824
Johannes Berg68eb5502013-11-19 15:19:38 +010013825 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013826 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013827 return;
13828
13829 nla_put_failure:
13830 genlmsg_cancel(msg, hdr);
13831 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013832}
13833
13834void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013835 struct net_device *netdev,
13836 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013837{
13838 struct sk_buff *msg;
13839 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013840 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013841
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013842 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013843 if (!msg)
13844 return;
13845
13846 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13847 if (!hdr) {
13848 nlmsg_free(msg);
13849 return;
13850 }
13851
David S. Miller9360ffd2012-03-29 04:41:26 -040013852 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13853 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13854 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013855 (info->req_ie &&
13856 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13857 info->req_ie)) ||
13858 (info->resp_ie &&
13859 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern503c1fb2017-09-29 14:21:49 +020013860 info->resp_ie)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013861 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013862
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013863 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013864
Johannes Berg68eb5502013-11-19 15:19:38 +010013865 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013866 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013867 return;
13868
13869 nla_put_failure:
13870 genlmsg_cancel(msg, hdr);
13871 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013872}
13873
Avraham Stern503c1fb2017-09-29 14:21:49 +020013874void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
13875 struct net_device *netdev, const u8 *bssid)
13876{
13877 struct sk_buff *msg;
13878 void *hdr;
13879
13880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13881 if (!msg)
13882 return;
13883
13884 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
13885 if (!hdr) {
13886 nlmsg_free(msg);
13887 return;
13888 }
13889
13890 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13891 goto nla_put_failure;
13892
13893 genlmsg_end(msg, hdr);
13894
13895 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13896 NL80211_MCGRP_MLME, GFP_KERNEL);
13897 return;
13898
13899 nla_put_failure:
13900 genlmsg_cancel(msg, hdr);
13901 nlmsg_free(msg);
13902}
13903
Samuel Ortizb23aa672009-07-01 21:26:54 +020013904void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13905 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013906 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013907{
13908 struct sk_buff *msg;
13909 void *hdr;
13910
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013911 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013912 if (!msg)
13913 return;
13914
13915 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13916 if (!hdr) {
13917 nlmsg_free(msg);
13918 return;
13919 }
13920
David S. Miller9360ffd2012-03-29 04:41:26 -040013921 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13922 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13923 (from_ap && reason &&
13924 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13925 (from_ap &&
13926 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13927 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13928 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013929
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013930 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013931
Johannes Berg68eb5502013-11-19 15:19:38 +010013932 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013933 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013934 return;
13935
13936 nla_put_failure:
13937 genlmsg_cancel(msg, hdr);
13938 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013939}
13940
Johannes Berg04a773a2009-04-19 21:24:32 +020013941void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13942 struct net_device *netdev, const u8 *bssid,
13943 gfp_t gfp)
13944{
13945 struct sk_buff *msg;
13946 void *hdr;
13947
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013949 if (!msg)
13950 return;
13951
13952 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13953 if (!hdr) {
13954 nlmsg_free(msg);
13955 return;
13956 }
13957
David S. Miller9360ffd2012-03-29 04:41:26 -040013958 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13960 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13961 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013962
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013963 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013964
Johannes Berg68eb5502013-11-19 15:19:38 +010013965 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013966 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013967 return;
13968
13969 nla_put_failure:
13970 genlmsg_cancel(msg, hdr);
13971 nlmsg_free(msg);
13972}
13973
Johannes Berg947add32013-02-22 22:05:20 +010013974void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13975 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013976{
Johannes Berg947add32013-02-22 22:05:20 +010013977 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013978 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013979 struct sk_buff *msg;
13980 void *hdr;
13981
Johannes Berg947add32013-02-22 22:05:20 +010013982 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13983 return;
13984
13985 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13986
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013987 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013988 if (!msg)
13989 return;
13990
13991 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13992 if (!hdr) {
13993 nlmsg_free(msg);
13994 return;
13995 }
13996
David S. Miller9360ffd2012-03-29 04:41:26 -040013997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13999 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014000 (ie_len && ie &&
14001 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14002 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014003
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014004 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014005
Johannes Berg68eb5502013-11-19 15:19:38 +010014006 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014007 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014008 return;
14009
14010 nla_put_failure:
14011 genlmsg_cancel(msg, hdr);
14012 nlmsg_free(msg);
14013}
Johannes Berg947add32013-02-22 22:05:20 +010014014EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014015
Jouni Malinena3b8b052009-03-27 21:59:49 +020014016void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14017 struct net_device *netdev, const u8 *addr,
14018 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014019 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014020{
14021 struct sk_buff *msg;
14022 void *hdr;
14023
Johannes Berge6d6e342009-07-01 21:26:47 +020014024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014025 if (!msg)
14026 return;
14027
14028 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14029 if (!hdr) {
14030 nlmsg_free(msg);
14031 return;
14032 }
14033
David S. Miller9360ffd2012-03-29 04:41:26 -040014034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14035 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14036 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14037 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14038 (key_id != -1 &&
14039 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14040 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14041 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014042
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014043 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014044
Johannes Berg68eb5502013-11-19 15:19:38 +010014045 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014046 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014047 return;
14048
14049 nla_put_failure:
14050 genlmsg_cancel(msg, hdr);
14051 nlmsg_free(msg);
14052}
14053
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014054void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14055 struct ieee80211_channel *channel_before,
14056 struct ieee80211_channel *channel_after)
14057{
14058 struct sk_buff *msg;
14059 void *hdr;
14060 struct nlattr *nl_freq;
14061
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014062 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014063 if (!msg)
14064 return;
14065
14066 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14067 if (!hdr) {
14068 nlmsg_free(msg);
14069 return;
14070 }
14071
14072 /*
14073 * Since we are applying the beacon hint to a wiphy we know its
14074 * wiphy_idx is valid
14075 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014076 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14077 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014078
14079 /* Before */
14080 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14081 if (!nl_freq)
14082 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014083 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014084 goto nla_put_failure;
14085 nla_nest_end(msg, nl_freq);
14086
14087 /* After */
14088 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14089 if (!nl_freq)
14090 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014091 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014092 goto nla_put_failure;
14093 nla_nest_end(msg, nl_freq);
14094
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014095 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014096
Johannes Berg463d0182009-07-14 00:33:35 +020014097 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014098 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014099 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014100 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014101
14102 return;
14103
14104nla_put_failure:
14105 genlmsg_cancel(msg, hdr);
14106 nlmsg_free(msg);
14107}
14108
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014109static void nl80211_send_remain_on_chan_event(
14110 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014111 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014112 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014113 unsigned int duration, gfp_t gfp)
14114{
14115 struct sk_buff *msg;
14116 void *hdr;
14117
14118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14119 if (!msg)
14120 return;
14121
14122 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14123 if (!hdr) {
14124 nlmsg_free(msg);
14125 return;
14126 }
14127
David S. Miller9360ffd2012-03-29 04:41:26 -040014128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014129 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14130 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014131 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14132 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014133 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014134 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14135 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014136 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14137 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014138 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014139
David S. Miller9360ffd2012-03-29 04:41:26 -040014140 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14141 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14142 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014143
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014144 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014145
Johannes Berg68eb5502013-11-19 15:19:38 +010014146 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014147 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014148 return;
14149
14150 nla_put_failure:
14151 genlmsg_cancel(msg, hdr);
14152 nlmsg_free(msg);
14153}
14154
Johannes Berg947add32013-02-22 22:05:20 +010014155void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14156 struct ieee80211_channel *chan,
14157 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014158{
Johannes Berg947add32013-02-22 22:05:20 +010014159 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014161
14162 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014163 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014164 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014165 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014166}
Johannes Berg947add32013-02-22 22:05:20 +010014167EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014168
Johannes Berg947add32013-02-22 22:05:20 +010014169void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14170 struct ieee80211_channel *chan,
14171 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014172{
Johannes Berg947add32013-02-22 22:05:20 +010014173 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014175
14176 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014177 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014178 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014179}
Johannes Berg947add32013-02-22 22:05:20 +010014180EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014181
Johannes Berg947add32013-02-22 22:05:20 +010014182void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14183 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014184{
Johannes Berg947add32013-02-22 22:05:20 +010014185 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014186 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014187 struct sk_buff *msg;
14188
Johannes Berg947add32013-02-22 22:05:20 +010014189 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14190
Thomas Graf58050fc2012-06-28 03:57:45 +000014191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014192 if (!msg)
14193 return;
14194
Johannes Bergcf5ead82014-11-14 17:14:00 +010014195 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014196 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014197 nlmsg_free(msg);
14198 return;
14199 }
14200
Johannes Berg68eb5502013-11-19 15:19:38 +010014201 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014202 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014203}
Johannes Berg947add32013-02-22 22:05:20 +010014204EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014205
Johannes Bergcf5ead82014-11-14 17:14:00 +010014206void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14207 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014208{
Johannes Berg947add32013-02-22 22:05:20 +010014209 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014210 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014211 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014212 struct station_info empty_sinfo = {};
14213
14214 if (!sinfo)
14215 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014216
Johannes Berg947add32013-02-22 22:05:20 +010014217 trace_cfg80211_del_sta(dev, mac_addr);
14218
Thomas Graf58050fc2012-06-28 03:57:45 +000014219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014220 if (!msg)
14221 return;
14222
Johannes Bergcf5ead82014-11-14 17:14:00 +010014223 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014224 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014225 nlmsg_free(msg);
14226 return;
14227 }
14228
Johannes Berg68eb5502013-11-19 15:19:38 +010014229 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014230 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014231}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014232EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014233
Johannes Berg947add32013-02-22 22:05:20 +010014234void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14235 enum nl80211_connect_failed_reason reason,
14236 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014237{
Johannes Berg947add32013-02-22 22:05:20 +010014238 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014239 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014240 struct sk_buff *msg;
14241 void *hdr;
14242
14243 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14244 if (!msg)
14245 return;
14246
14247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14248 if (!hdr) {
14249 nlmsg_free(msg);
14250 return;
14251 }
14252
14253 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14254 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14255 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14256 goto nla_put_failure;
14257
14258 genlmsg_end(msg, hdr);
14259
Johannes Berg68eb5502013-11-19 15:19:38 +010014260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014261 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014262 return;
14263
14264 nla_put_failure:
14265 genlmsg_cancel(msg, hdr);
14266 nlmsg_free(msg);
14267}
Johannes Berg947add32013-02-22 22:05:20 +010014268EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014269
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014270static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14271 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014272{
14273 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014274 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014275 struct sk_buff *msg;
14276 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014277 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014278
Eric W. Biederman15e47302012-09-07 20:12:54 +000014279 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014280 return false;
14281
14282 msg = nlmsg_new(100, gfp);
14283 if (!msg)
14284 return true;
14285
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014286 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014287 if (!hdr) {
14288 nlmsg_free(msg);
14289 return true;
14290 }
14291
David S. Miller9360ffd2012-03-29 04:41:26 -040014292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14294 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14295 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014296
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014297 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014298 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014299 return true;
14300
14301 nla_put_failure:
14302 genlmsg_cancel(msg, hdr);
14303 nlmsg_free(msg);
14304 return true;
14305}
14306
Johannes Berg947add32013-02-22 22:05:20 +010014307bool cfg80211_rx_spurious_frame(struct net_device *dev,
14308 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014309{
Johannes Berg947add32013-02-22 22:05:20 +010014310 struct wireless_dev *wdev = dev->ieee80211_ptr;
14311 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014312
Johannes Berg947add32013-02-22 22:05:20 +010014313 trace_cfg80211_rx_spurious_frame(dev, addr);
14314
14315 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14316 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14317 trace_cfg80211_return_bool(false);
14318 return false;
14319 }
14320 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14321 addr, gfp);
14322 trace_cfg80211_return_bool(ret);
14323 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014324}
Johannes Berg947add32013-02-22 22:05:20 +010014325EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14326
14327bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14328 const u8 *addr, gfp_t gfp)
14329{
14330 struct wireless_dev *wdev = dev->ieee80211_ptr;
14331 bool ret;
14332
14333 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14334
14335 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14336 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14337 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14338 trace_cfg80211_return_bool(false);
14339 return false;
14340 }
14341 ret = __nl80211_unexpected_frame(dev,
14342 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14343 addr, gfp);
14344 trace_cfg80211_return_bool(ret);
14345 return ret;
14346}
14347EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014348
Johannes Berg2e161f72010-08-12 15:38:38 +020014349int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014350 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014351 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014352 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014353{
Johannes Berg71bbc992012-06-15 15:30:18 +020014354 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014355 struct sk_buff *msg;
14356 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014357
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014358 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014359 if (!msg)
14360 return -ENOMEM;
14361
Johannes Berg2e161f72010-08-12 15:38:38 +020014362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014363 if (!hdr) {
14364 nlmsg_free(msg);
14365 return -ENOMEM;
14366 }
14367
David S. Miller9360ffd2012-03-29 04:41:26 -040014368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014369 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14370 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014371 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14372 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014373 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14374 (sig_dbm &&
14375 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014376 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14377 (flags &&
14378 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014379 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014380
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014381 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014382
Eric W. Biederman15e47302012-09-07 20:12:54 +000014383 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014384
14385 nla_put_failure:
14386 genlmsg_cancel(msg, hdr);
14387 nlmsg_free(msg);
14388 return -ENOBUFS;
14389}
14390
Johannes Berg947add32013-02-22 22:05:20 +010014391void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14392 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014393{
Johannes Berg947add32013-02-22 22:05:20 +010014394 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014396 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014397 struct sk_buff *msg;
14398 void *hdr;
14399
Johannes Berg947add32013-02-22 22:05:20 +010014400 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14401
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014402 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014403 if (!msg)
14404 return;
14405
Johannes Berg2e161f72010-08-12 15:38:38 +020014406 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014407 if (!hdr) {
14408 nlmsg_free(msg);
14409 return;
14410 }
14411
David S. Miller9360ffd2012-03-29 04:41:26 -040014412 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014413 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14414 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014415 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14416 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014417 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014418 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14419 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014420 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14421 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014422
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014423 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014424
Johannes Berg68eb5502013-11-19 15:19:38 +010014425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014426 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014427 return;
14428
14429 nla_put_failure:
14430 genlmsg_cancel(msg, hdr);
14431 nlmsg_free(msg);
14432}
Johannes Berg947add32013-02-22 22:05:20 +010014433EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014434
Johannes Berg5b97f492014-11-26 12:37:43 +010014435static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14436 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014437{
Johannes Berg947add32013-02-22 22:05:20 +010014438 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14440 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14441 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014442
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014443 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014444 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014445
Johannes Berg5b97f492014-11-26 12:37:43 +010014446 cb = (void **)msg->cb;
14447
14448 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14449 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014450 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014451 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014452 }
14453
David S. Miller9360ffd2012-03-29 04:41:26 -040014454 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014455 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014456 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014457
Johannes Berg5b97f492014-11-26 12:37:43 +010014458 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014459 goto nla_put_failure;
14460
Johannes Berg5b97f492014-11-26 12:37:43 +010014461 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14462 if (!cb[1])
14463 goto nla_put_failure;
14464
14465 cb[2] = rdev;
14466
14467 return msg;
14468 nla_put_failure:
14469 nlmsg_free(msg);
14470 return NULL;
14471}
14472
14473static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14474{
14475 void **cb = (void **)msg->cb;
14476 struct cfg80211_registered_device *rdev = cb[2];
14477
14478 nla_nest_end(msg, cb[1]);
14479 genlmsg_end(msg, cb[0]);
14480
14481 memset(msg->cb, 0, sizeof(msg->cb));
14482
14483 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14484 NL80211_MCGRP_MLME, gfp);
14485}
14486
14487void cfg80211_cqm_rssi_notify(struct net_device *dev,
14488 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014489 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014490{
14491 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014492 struct wireless_dev *wdev = dev->ieee80211_ptr;
14493 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014494
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014495 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014496
Johannes Berg98f03342014-11-26 12:42:02 +010014497 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14498 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14499 return;
14500
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014501 if (wdev->cqm_config) {
14502 wdev->cqm_config->last_rssi_event_value = rssi_level;
14503
14504 cfg80211_cqm_rssi_update(rdev, dev);
14505
14506 if (rssi_level == 0)
14507 rssi_level = wdev->cqm_config->last_rssi_event_value;
14508 }
14509
Johannes Berg5b97f492014-11-26 12:37:43 +010014510 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14511 if (!msg)
14512 return;
14513
David S. Miller9360ffd2012-03-29 04:41:26 -040014514 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14515 rssi_event))
14516 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014517
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014518 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14519 rssi_level))
14520 goto nla_put_failure;
14521
Johannes Berg5b97f492014-11-26 12:37:43 +010014522 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014523
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014524 return;
14525
14526 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014527 nlmsg_free(msg);
14528}
Johannes Berg947add32013-02-22 22:05:20 +010014529EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014530
Johannes Berg5b97f492014-11-26 12:37:43 +010014531void cfg80211_cqm_txe_notify(struct net_device *dev,
14532 const u8 *peer, u32 num_packets,
14533 u32 rate, u32 intvl, gfp_t gfp)
14534{
14535 struct sk_buff *msg;
14536
14537 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14538 if (!msg)
14539 return;
14540
14541 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14542 goto nla_put_failure;
14543
14544 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14545 goto nla_put_failure;
14546
14547 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14548 goto nla_put_failure;
14549
14550 cfg80211_send_cqm(msg, gfp);
14551 return;
14552
14553 nla_put_failure:
14554 nlmsg_free(msg);
14555}
14556EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14557
14558void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14559 const u8 *peer, u32 num_packets, gfp_t gfp)
14560{
14561 struct sk_buff *msg;
14562
14563 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14564
14565 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14566 if (!msg)
14567 return;
14568
14569 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14570 goto nla_put_failure;
14571
14572 cfg80211_send_cqm(msg, gfp);
14573 return;
14574
14575 nla_put_failure:
14576 nlmsg_free(msg);
14577}
14578EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14579
Johannes Berg98f03342014-11-26 12:42:02 +010014580void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14581{
14582 struct sk_buff *msg;
14583
14584 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14585 if (!msg)
14586 return;
14587
14588 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14589 goto nla_put_failure;
14590
14591 cfg80211_send_cqm(msg, gfp);
14592 return;
14593
14594 nla_put_failure:
14595 nlmsg_free(msg);
14596}
14597EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14598
Johannes Berg947add32013-02-22 22:05:20 +010014599static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14600 struct net_device *netdev, const u8 *bssid,
14601 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014602{
14603 struct sk_buff *msg;
14604 struct nlattr *rekey_attr;
14605 void *hdr;
14606
Thomas Graf58050fc2012-06-28 03:57:45 +000014607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014608 if (!msg)
14609 return;
14610
14611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14612 if (!hdr) {
14613 nlmsg_free(msg);
14614 return;
14615 }
14616
David S. Miller9360ffd2012-03-29 04:41:26 -040014617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14620 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014621
14622 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14623 if (!rekey_attr)
14624 goto nla_put_failure;
14625
David S. Miller9360ffd2012-03-29 04:41:26 -040014626 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14627 NL80211_REPLAY_CTR_LEN, replay_ctr))
14628 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014629
14630 nla_nest_end(msg, rekey_attr);
14631
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014632 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014633
Johannes Berg68eb5502013-11-19 15:19:38 +010014634 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014635 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014636 return;
14637
14638 nla_put_failure:
14639 genlmsg_cancel(msg, hdr);
14640 nlmsg_free(msg);
14641}
14642
Johannes Berg947add32013-02-22 22:05:20 +010014643void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14644 const u8 *replay_ctr, gfp_t gfp)
14645{
14646 struct wireless_dev *wdev = dev->ieee80211_ptr;
14647 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014648 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014649
14650 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14651 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14652}
14653EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14654
14655static void
14656nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14657 struct net_device *netdev, int index,
14658 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014659{
14660 struct sk_buff *msg;
14661 struct nlattr *attr;
14662 void *hdr;
14663
Thomas Graf58050fc2012-06-28 03:57:45 +000014664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014665 if (!msg)
14666 return;
14667
14668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14669 if (!hdr) {
14670 nlmsg_free(msg);
14671 return;
14672 }
14673
David S. Miller9360ffd2012-03-29 04:41:26 -040014674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14676 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014677
14678 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14679 if (!attr)
14680 goto nla_put_failure;
14681
David S. Miller9360ffd2012-03-29 04:41:26 -040014682 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14683 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14684 (preauth &&
14685 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14686 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014687
14688 nla_nest_end(msg, attr);
14689
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014690 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014691
Johannes Berg68eb5502013-11-19 15:19:38 +010014692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014693 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014694 return;
14695
14696 nla_put_failure:
14697 genlmsg_cancel(msg, hdr);
14698 nlmsg_free(msg);
14699}
14700
Johannes Berg947add32013-02-22 22:05:20 +010014701void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14702 const u8 *bssid, bool preauth, gfp_t gfp)
14703{
14704 struct wireless_dev *wdev = dev->ieee80211_ptr;
14705 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014706 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014707
14708 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14709 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14710}
14711EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14712
14713static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14714 struct net_device *netdev,
14715 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014716 gfp_t gfp,
14717 enum nl80211_commands notif,
14718 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014719{
14720 struct sk_buff *msg;
14721 void *hdr;
14722
Thomas Graf58050fc2012-06-28 03:57:45 +000014723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014724 if (!msg)
14725 return;
14726
Luciano Coelhof8d75522014-11-07 14:31:35 +020014727 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014728 if (!hdr) {
14729 nlmsg_free(msg);
14730 return;
14731 }
14732
Johannes Berg683b6d32012-11-08 21:25:48 +010014733 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14734 goto nla_put_failure;
14735
14736 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014737 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014738
Luciano Coelhof8d75522014-11-07 14:31:35 +020014739 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14740 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14741 goto nla_put_failure;
14742
Thomas Pedersen53145262012-04-06 13:35:47 -070014743 genlmsg_end(msg, hdr);
14744
Johannes Berg68eb5502013-11-19 15:19:38 +010014745 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014746 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014747 return;
14748
14749 nla_put_failure:
14750 genlmsg_cancel(msg, hdr);
14751 nlmsg_free(msg);
14752}
14753
Johannes Berg947add32013-02-22 22:05:20 +010014754void cfg80211_ch_switch_notify(struct net_device *dev,
14755 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014756{
Johannes Berg947add32013-02-22 22:05:20 +010014757 struct wireless_dev *wdev = dev->ieee80211_ptr;
14758 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014759 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014760
Simon Wunderliche487eae2013-11-21 18:19:51 +010014761 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014762
Simon Wunderliche487eae2013-11-21 18:19:51 +010014763 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014764
Michal Kazior9e0e2962014-01-29 14:22:27 +010014765 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014766 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014767 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14768 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014769}
14770EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14771
Luciano Coelhof8d75522014-11-07 14:31:35 +020014772void cfg80211_ch_switch_started_notify(struct net_device *dev,
14773 struct cfg80211_chan_def *chandef,
14774 u8 count)
14775{
14776 struct wireless_dev *wdev = dev->ieee80211_ptr;
14777 struct wiphy *wiphy = wdev->wiphy;
14778 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14779
14780 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14781
14782 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14783 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14784}
14785EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14786
Thomas Pedersen84f10702012-07-12 16:17:33 -070014787void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014788nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014789 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014790 enum nl80211_radar_event event,
14791 struct net_device *netdev, gfp_t gfp)
14792{
14793 struct sk_buff *msg;
14794 void *hdr;
14795
14796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14797 if (!msg)
14798 return;
14799
14800 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14801 if (!hdr) {
14802 nlmsg_free(msg);
14803 return;
14804 }
14805
14806 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14807 goto nla_put_failure;
14808
14809 /* NOP and radar events don't need a netdev parameter */
14810 if (netdev) {
14811 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14812
14813 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014814 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14815 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014816 goto nla_put_failure;
14817 }
14818
14819 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14820 goto nla_put_failure;
14821
14822 if (nl80211_send_chandef(msg, chandef))
14823 goto nla_put_failure;
14824
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014825 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014826
Johannes Berg68eb5502013-11-19 15:19:38 +010014827 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014828 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014829 return;
14830
14831 nla_put_failure:
14832 genlmsg_cancel(msg, hdr);
14833 nlmsg_free(msg);
14834}
14835
Johannes Berg7f6cf312011-11-04 11:18:15 +010014836void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14837 u64 cookie, bool acked, gfp_t gfp)
14838{
14839 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014840 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014841 struct sk_buff *msg;
14842 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014843
Beni Lev4ee3e062012-08-27 12:49:39 +030014844 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14845
Thomas Graf58050fc2012-06-28 03:57:45 +000014846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014847
Johannes Berg7f6cf312011-11-04 11:18:15 +010014848 if (!msg)
14849 return;
14850
14851 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14852 if (!hdr) {
14853 nlmsg_free(msg);
14854 return;
14855 }
14856
David S. Miller9360ffd2012-03-29 04:41:26 -040014857 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14858 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14859 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014860 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14861 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014862 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14863 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014864
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014865 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014866
Johannes Berg68eb5502013-11-19 15:19:38 +010014867 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014868 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014869 return;
14870
14871 nla_put_failure:
14872 genlmsg_cancel(msg, hdr);
14873 nlmsg_free(msg);
14874}
14875EXPORT_SYMBOL(cfg80211_probe_status);
14876
Johannes Berg5e760232011-11-04 11:18:17 +010014877void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14878 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014879 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014880{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014881 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014882 struct sk_buff *msg;
14883 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014884 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014885
Beni Lev4ee3e062012-08-27 12:49:39 +030014886 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14887
Ben Greear37c73b52012-10-26 14:49:25 -070014888 spin_lock_bh(&rdev->beacon_registrations_lock);
14889 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14890 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14891 if (!msg) {
14892 spin_unlock_bh(&rdev->beacon_registrations_lock);
14893 return;
14894 }
Johannes Berg5e760232011-11-04 11:18:17 +010014895
Ben Greear37c73b52012-10-26 14:49:25 -070014896 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14897 if (!hdr)
14898 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014899
Ben Greear37c73b52012-10-26 14:49:25 -070014900 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14901 (freq &&
14902 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14903 (sig_dbm &&
14904 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14905 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14906 goto nla_put_failure;
14907
14908 genlmsg_end(msg, hdr);
14909
14910 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014911 }
Ben Greear37c73b52012-10-26 14:49:25 -070014912 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014913 return;
14914
14915 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014916 spin_unlock_bh(&rdev->beacon_registrations_lock);
14917 if (hdr)
14918 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014919 nlmsg_free(msg);
14920}
14921EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14922
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014923#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014924static int cfg80211_net_detect_results(struct sk_buff *msg,
14925 struct cfg80211_wowlan_wakeup *wakeup)
14926{
14927 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14928 struct nlattr *nl_results, *nl_match, *nl_freqs;
14929 int i, j;
14930
14931 nl_results = nla_nest_start(
14932 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14933 if (!nl_results)
14934 return -EMSGSIZE;
14935
14936 for (i = 0; i < nd->n_matches; i++) {
14937 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14938
14939 nl_match = nla_nest_start(msg, i);
14940 if (!nl_match)
14941 break;
14942
14943 /* The SSID attribute is optional in nl80211, but for
14944 * simplicity reasons it's always present in the
14945 * cfg80211 structure. If a driver can't pass the
14946 * SSID, that needs to be changed. A zero length SSID
14947 * is still a valid SSID (wildcard), so it cannot be
14948 * used for this purpose.
14949 */
14950 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14951 match->ssid.ssid)) {
14952 nla_nest_cancel(msg, nl_match);
14953 goto out;
14954 }
14955
14956 if (match->n_channels) {
14957 nl_freqs = nla_nest_start(
14958 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14959 if (!nl_freqs) {
14960 nla_nest_cancel(msg, nl_match);
14961 goto out;
14962 }
14963
14964 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014965 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014966 nla_nest_cancel(msg, nl_freqs);
14967 nla_nest_cancel(msg, nl_match);
14968 goto out;
14969 }
14970 }
14971
14972 nla_nest_end(msg, nl_freqs);
14973 }
14974
14975 nla_nest_end(msg, nl_match);
14976 }
14977
14978out:
14979 nla_nest_end(msg, nl_results);
14980 return 0;
14981}
14982
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014983void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14984 struct cfg80211_wowlan_wakeup *wakeup,
14985 gfp_t gfp)
14986{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014987 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014988 struct sk_buff *msg;
14989 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014990 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014991
14992 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14993
14994 if (wakeup)
14995 size += wakeup->packet_present_len;
14996
14997 msg = nlmsg_new(size, gfp);
14998 if (!msg)
14999 return;
15000
15001 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15002 if (!hdr)
15003 goto free_msg;
15004
15005 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015006 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15007 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015008 goto free_msg;
15009
15010 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15011 wdev->netdev->ifindex))
15012 goto free_msg;
15013
15014 if (wakeup) {
15015 struct nlattr *reasons;
15016
15017 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015018 if (!reasons)
15019 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015020
15021 if (wakeup->disconnect &&
15022 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15023 goto free_msg;
15024 if (wakeup->magic_pkt &&
15025 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15026 goto free_msg;
15027 if (wakeup->gtk_rekey_failure &&
15028 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15029 goto free_msg;
15030 if (wakeup->eap_identity_req &&
15031 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15032 goto free_msg;
15033 if (wakeup->four_way_handshake &&
15034 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15035 goto free_msg;
15036 if (wakeup->rfkill_release &&
15037 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15038 goto free_msg;
15039
15040 if (wakeup->pattern_idx >= 0 &&
15041 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15042 wakeup->pattern_idx))
15043 goto free_msg;
15044
Johannes Bergae917c92013-10-25 11:05:22 +020015045 if (wakeup->tcp_match &&
15046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15047 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015048
Johannes Bergae917c92013-10-25 11:05:22 +020015049 if (wakeup->tcp_connlost &&
15050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15051 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015052
Johannes Bergae917c92013-10-25 11:05:22 +020015053 if (wakeup->tcp_nomoretokens &&
15054 nla_put_flag(msg,
15055 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15056 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015057
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015058 if (wakeup->packet) {
15059 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15060 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15061
15062 if (!wakeup->packet_80211) {
15063 pkt_attr =
15064 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15065 len_attr =
15066 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15067 }
15068
15069 if (wakeup->packet_len &&
15070 nla_put_u32(msg, len_attr, wakeup->packet_len))
15071 goto free_msg;
15072
15073 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15074 wakeup->packet))
15075 goto free_msg;
15076 }
15077
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015078 if (wakeup->net_detect &&
15079 cfg80211_net_detect_results(msg, wakeup))
15080 goto free_msg;
15081
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015082 nla_nest_end(msg, reasons);
15083 }
15084
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015085 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015086
Johannes Berg68eb5502013-11-19 15:19:38 +010015087 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015088 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015089 return;
15090
15091 free_msg:
15092 nlmsg_free(msg);
15093}
15094EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15095#endif
15096
Jouni Malinen3475b092012-11-16 22:49:57 +020015097void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15098 enum nl80211_tdls_operation oper,
15099 u16 reason_code, gfp_t gfp)
15100{
15101 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015102 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015103 struct sk_buff *msg;
15104 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015105
15106 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15107 reason_code);
15108
15109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15110 if (!msg)
15111 return;
15112
15113 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15114 if (!hdr) {
15115 nlmsg_free(msg);
15116 return;
15117 }
15118
15119 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15120 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15121 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15123 (reason_code > 0 &&
15124 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15125 goto nla_put_failure;
15126
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015127 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015128
Johannes Berg68eb5502013-11-19 15:19:38 +010015129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015130 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015131 return;
15132
15133 nla_put_failure:
15134 genlmsg_cancel(msg, hdr);
15135 nlmsg_free(msg);
15136}
15137EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15138
Jouni Malinen026331c2010-02-15 12:53:10 +020015139static int nl80211_netlink_notify(struct notifier_block * nb,
15140 unsigned long state,
15141 void *_notify)
15142{
15143 struct netlink_notify *notify = _notify;
15144 struct cfg80211_registered_device *rdev;
15145 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015146 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015147
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015148 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015149 return NOTIFY_DONE;
15150
15151 rcu_read_lock();
15152
Johannes Berg5e760232011-11-04 11:18:17 +010015153 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015154 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015155
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015156 list_for_each_entry_rcu(sched_scan_req,
15157 &rdev->sched_scan_req_list,
15158 list) {
15159 if (sched_scan_req->owner_nlportid == notify->portid) {
15160 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015161 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015162 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015163 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015164
Johannes Berg53873f12016-05-03 16:52:04 +030015165 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015166 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015167
Johannes Bergab810072017-04-26 07:43:41 +020015168 if (wdev->owner_nlportid == notify->portid) {
15169 wdev->nl_owner_dead = true;
15170 schedule_work(&rdev->destroy_work);
15171 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015172 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015173 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015174 }
15175
Ben Greear37c73b52012-10-26 14:49:25 -070015176 spin_lock_bh(&rdev->beacon_registrations_lock);
15177 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15178 list) {
15179 if (reg->nlportid == notify->portid) {
15180 list_del(&reg->list);
15181 kfree(reg);
15182 break;
15183 }
15184 }
15185 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015186 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015187
15188 rcu_read_unlock();
15189
Ilan peer05050752015-03-04 00:32:06 -050015190 /*
15191 * It is possible that the user space process that is controlling the
15192 * indoor setting disappeared, so notify the regulatory core.
15193 */
15194 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015195 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015196}
15197
15198static struct notifier_block nl80211_netlink_notifier = {
15199 .notifier_call = nl80211_netlink_notify,
15200};
15201
Jouni Malinen355199e2013-02-27 17:14:27 +020015202void cfg80211_ft_event(struct net_device *netdev,
15203 struct cfg80211_ft_event_params *ft_event)
15204{
15205 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015206 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015207 struct sk_buff *msg;
15208 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015209
15210 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15211
15212 if (!ft_event->target_ap)
15213 return;
15214
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015215 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015216 if (!msg)
15217 return;
15218
15219 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015220 if (!hdr)
15221 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015222
Johannes Bergae917c92013-10-25 11:05:22 +020015223 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15224 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15225 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15226 goto out;
15227
15228 if (ft_event->ies &&
15229 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15230 goto out;
15231 if (ft_event->ric_ies &&
15232 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15233 ft_event->ric_ies))
15234 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015235
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015236 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015237
Johannes Berg68eb5502013-11-19 15:19:38 +010015238 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015239 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015240 return;
15241 out:
15242 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015243}
15244EXPORT_SYMBOL(cfg80211_ft_event);
15245
Arend van Spriel5de17982013-04-18 15:49:00 +020015246void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15247{
15248 struct cfg80211_registered_device *rdev;
15249 struct sk_buff *msg;
15250 void *hdr;
15251 u32 nlportid;
15252
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015253 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015254 if (!rdev->crit_proto_nlportid)
15255 return;
15256
15257 nlportid = rdev->crit_proto_nlportid;
15258 rdev->crit_proto_nlportid = 0;
15259
15260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15261 if (!msg)
15262 return;
15263
15264 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15265 if (!hdr)
15266 goto nla_put_failure;
15267
15268 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015269 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15270 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015271 goto nla_put_failure;
15272
15273 genlmsg_end(msg, hdr);
15274
15275 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15276 return;
15277
15278 nla_put_failure:
15279 if (hdr)
15280 genlmsg_cancel(msg, hdr);
15281 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015282}
15283EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15284
Johannes Berg348baf02014-01-24 14:06:29 +010015285void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15286{
15287 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015288 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015289 struct sk_buff *msg;
15290 void *hdr;
15291
15292 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15293 if (!msg)
15294 return;
15295
15296 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15297 if (!hdr)
15298 goto out;
15299
15300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15301 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015302 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15303 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015304 goto out;
15305
15306 genlmsg_end(msg, hdr);
15307
15308 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15309 NL80211_MCGRP_MLME, GFP_KERNEL);
15310 return;
15311 out:
15312 nlmsg_free(msg);
15313}
15314
Johannes Berg55682962007-09-20 13:09:35 -040015315/* initialisation/exit functions */
15316
Johannes Berg56989f62016-10-24 14:40:05 +020015317int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015318{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015319 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015320
Johannes Berg489111e2016-10-24 14:40:03 +020015321 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015322 if (err)
15323 return err;
15324
Jouni Malinen026331c2010-02-15 12:53:10 +020015325 err = netlink_register_notifier(&nl80211_netlink_notifier);
15326 if (err)
15327 goto err_out;
15328
Johannes Berg55682962007-09-20 13:09:35 -040015329 return 0;
15330 err_out:
15331 genl_unregister_family(&nl80211_fam);
15332 return err;
15333}
15334
15335void nl80211_exit(void)
15336{
Jouni Malinen026331c2010-02-15 12:53:10 +020015337 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015338 genl_unregister_family(&nl80211_fam);
15339}