blob: eb866647a27ac3847f2a6eca3709945808dd70e6 [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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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);
2133 break;
2134 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002135 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002136 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002137 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2138 chandef->width =
2139 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2140 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2141 chandef->center_freq1 =
2142 nla_get_u32(
2143 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2144 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2145 chandef->center_freq2 =
2146 nla_get_u32(
2147 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2148 }
2149
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002150 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002151 return -EINVAL;
2152
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002153 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2154 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002155 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002156
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002157 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2158 chandef->width == NL80211_CHAN_WIDTH_10) &&
2159 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2160 return -EINVAL;
2161
Johannes Berg683b6d32012-11-08 21:25:48 +01002162 return 0;
2163}
2164
Johannes Bergf444de02010-05-05 15:25:02 +02002165static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002166 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002167 struct genl_info *info)
2168{
Johannes Berg683b6d32012-11-08 21:25:48 +01002169 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002170 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002171 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002172 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002173
Jouni Malinene16821b2014-04-28 11:22:08 +03002174 if (dev)
2175 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002176 if (!nl80211_can_set_dev_channel(wdev))
2177 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002178 if (wdev)
2179 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002180
Johannes Berg683b6d32012-11-08 21:25:48 +01002181 result = nl80211_parse_chandef(rdev, info, &chandef);
2182 if (result)
2183 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002184
Johannes Berge8c9bd52012-06-06 08:18:22 +02002185 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002186 case NL80211_IFTYPE_AP:
2187 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002188 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2189 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002190 result = -EINVAL;
2191 break;
2192 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002193 if (wdev->beacon_interval) {
2194 if (!dev || !rdev->ops->set_ap_chanwidth ||
2195 !(rdev->wiphy.features &
2196 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2197 result = -EBUSY;
2198 break;
2199 }
2200
2201 /* Only allow dynamic channel width changes */
2202 if (chandef.chan != wdev->preset_chandef.chan) {
2203 result = -EBUSY;
2204 break;
2205 }
2206 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2207 if (result)
2208 break;
2209 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002210 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002211 result = 0;
2212 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002213 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002214 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002215 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002216 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002217 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002218 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002219 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002220 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002221 }
Johannes Bergf444de02010-05-05 15:25:02 +02002222
2223 return result;
2224}
2225
2226static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2227{
Johannes Berg4c476992010-10-04 21:36:35 +02002228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2229 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002230
Jouni Malinene16821b2014-04-28 11:22:08 +03002231 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002232}
2233
Bill Jordane8347eb2010-10-01 13:54:28 -04002234static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2235{
Johannes Berg43b19952010-10-07 13:10:30 +02002236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2237 struct net_device *dev = info->user_ptr[1];
2238 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002239 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002240
2241 if (!info->attrs[NL80211_ATTR_MAC])
2242 return -EINVAL;
2243
Johannes Berg43b19952010-10-07 13:10:30 +02002244 if (netif_running(dev))
2245 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002246
Johannes Berg43b19952010-10-07 13:10:30 +02002247 if (!rdev->ops->set_wds_peer)
2248 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002249
Johannes Berg43b19952010-10-07 13:10:30 +02002250 if (wdev->iftype != NL80211_IFTYPE_WDS)
2251 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002252
2253 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002254 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002255}
2256
Johannes Berg55682962007-09-20 13:09:35 -04002257static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2258{
2259 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002260 struct net_device *netdev = NULL;
2261 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002262 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002263 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002264 u32 changed;
2265 u8 retry_short = 0, retry_long = 0;
2266 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002267 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002268
Johannes Berg5fe231e2013-05-08 21:45:15 +02002269 ASSERT_RTNL();
2270
Johannes Bergf444de02010-05-05 15:25:02 +02002271 /*
2272 * Try to find the wiphy and netdev. Normally this
2273 * function shouldn't need the netdev, but this is
2274 * done for backward compatibility -- previously
2275 * setting the channel was done per wiphy, but now
2276 * it is per netdev. Previous userland like hostapd
2277 * also passed a netdev to set_wiphy, so that it is
2278 * possible to let that go to the right netdev!
2279 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002280
Johannes Bergf444de02010-05-05 15:25:02 +02002281 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2282 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2283
Ying Xue7f2b8562014-01-15 10:23:45 +08002284 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002285 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002286 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002287 else
Johannes Bergf444de02010-05-05 15:25:02 +02002288 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002289 }
2290
Johannes Bergf444de02010-05-05 15:25:02 +02002291 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002292 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2293 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002294 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002295 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002296 wdev = NULL;
2297 netdev = NULL;
2298 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002299 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002300 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002301
2302 /*
2303 * end workaround code, by now the rdev is available
2304 * and locked, and wdev may or may not be NULL.
2305 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002306
2307 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002308 result = cfg80211_dev_rename(
2309 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002310
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002311 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002312 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002313
Jouni Malinen31888482008-10-30 16:59:24 +02002314 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2315 struct ieee80211_txq_params txq_params;
2316 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2317
Ying Xue7f2b8562014-01-15 10:23:45 +08002318 if (!rdev->ops->set_txq_params)
2319 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002320
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 if (!netdev)
2322 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002323
Johannes Berg133a3ff2011-11-03 14:50:13 +01002324 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002325 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2326 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002327
Ying Xue7f2b8562014-01-15 10:23:45 +08002328 if (!netif_running(netdev))
2329 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002330
Jouni Malinen31888482008-10-30 16:59:24 +02002331 nla_for_each_nested(nl_txq_params,
2332 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2333 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002334 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2335 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002336 txq_params_policy,
2337 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002338 if (result)
2339 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002340 result = parse_txq_params(tb, &txq_params);
2341 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002342 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002343
Hila Gonene35e4d22012-06-27 17:19:42 +03002344 result = rdev_set_txq_params(rdev, netdev,
2345 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002346 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002347 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002348 }
2349 }
2350
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002351 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002352 result = __nl80211_set_channel(
2353 rdev,
2354 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2355 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002356 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002357 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002358 }
2359
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002360 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002361 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002362 enum nl80211_tx_power_setting type;
2363 int idx, mbm = 0;
2364
Johannes Bergc8442112012-10-24 10:17:18 +02002365 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2366 txp_wdev = NULL;
2367
Ying Xue7f2b8562014-01-15 10:23:45 +08002368 if (!rdev->ops->set_tx_power)
2369 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002370
2371 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2372 type = nla_get_u32(info->attrs[idx]);
2373
2374 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002375 (type != NL80211_TX_POWER_AUTOMATIC))
2376 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002377
2378 if (type != NL80211_TX_POWER_AUTOMATIC) {
2379 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2380 mbm = nla_get_u32(info->attrs[idx]);
2381 }
2382
Johannes Bergc8442112012-10-24 10:17:18 +02002383 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002384 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002385 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002386 }
2387
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002388 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2389 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2390 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002391
Bruno Randolf7f531e02010-12-16 11:30:22 +09002392 if ((!rdev->wiphy.available_antennas_tx &&
2393 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002394 !rdev->ops->set_antenna)
2395 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002396
2397 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2398 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2399
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002400 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002401 * available antenna masks, except for the "all" mask */
2402 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002403 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2404 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002405
Bruno Randolf7f531e02010-12-16 11:30:22 +09002406 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2407 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002408
Hila Gonene35e4d22012-06-27 17:19:42 +03002409 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002410 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002411 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002412 }
2413
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002414 changed = 0;
2415
2416 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2417 retry_short = nla_get_u8(
2418 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002419 if (retry_short == 0)
2420 return -EINVAL;
2421
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002422 changed |= WIPHY_PARAM_RETRY_SHORT;
2423 }
2424
2425 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2426 retry_long = nla_get_u8(
2427 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002428 if (retry_long == 0)
2429 return -EINVAL;
2430
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002431 changed |= WIPHY_PARAM_RETRY_LONG;
2432 }
2433
2434 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2435 frag_threshold = nla_get_u32(
2436 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002437 if (frag_threshold < 256)
2438 return -EINVAL;
2439
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002440 if (frag_threshold != (u32) -1) {
2441 /*
2442 * Fragments (apart from the last one) are required to
2443 * have even length. Make the fragmentation code
2444 * simpler by stripping LSB should someone try to use
2445 * odd threshold value.
2446 */
2447 frag_threshold &= ~0x1;
2448 }
2449 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2450 }
2451
2452 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2453 rts_threshold = nla_get_u32(
2454 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2455 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2456 }
2457
Lukáš Turek81077e82009-12-21 22:50:47 +01002458 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002459 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2460 return -EINVAL;
2461
Lukáš Turek81077e82009-12-21 22:50:47 +01002462 coverage_class = nla_get_u8(
2463 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2464 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2465 }
2466
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002467 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2468 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2469 return -EOPNOTSUPP;
2470
2471 changed |= WIPHY_PARAM_DYN_ACK;
2472 }
2473
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002474 if (changed) {
2475 u8 old_retry_short, old_retry_long;
2476 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002477 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002478
Ying Xue7f2b8562014-01-15 10:23:45 +08002479 if (!rdev->ops->set_wiphy_params)
2480 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002481
2482 old_retry_short = rdev->wiphy.retry_short;
2483 old_retry_long = rdev->wiphy.retry_long;
2484 old_frag_threshold = rdev->wiphy.frag_threshold;
2485 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002486 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002487
2488 if (changed & WIPHY_PARAM_RETRY_SHORT)
2489 rdev->wiphy.retry_short = retry_short;
2490 if (changed & WIPHY_PARAM_RETRY_LONG)
2491 rdev->wiphy.retry_long = retry_long;
2492 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2493 rdev->wiphy.frag_threshold = frag_threshold;
2494 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2495 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002496 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2497 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002498
Hila Gonene35e4d22012-06-27 17:19:42 +03002499 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002500 if (result) {
2501 rdev->wiphy.retry_short = old_retry_short;
2502 rdev->wiphy.retry_long = old_retry_long;
2503 rdev->wiphy.frag_threshold = old_frag_threshold;
2504 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002505 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002506 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002507 }
2508 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002509 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002510}
2511
Johannes Berg71bbc992012-06-15 15:30:18 +02002512static inline u64 wdev_id(struct wireless_dev *wdev)
2513{
2514 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002515 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002516}
Johannes Berg55682962007-09-20 13:09:35 -04002517
Johannes Berg683b6d32012-11-08 21:25:48 +01002518static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002519 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002520{
Johannes Berg601555c2014-11-27 17:26:56 +01002521 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2522 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002523
Johannes Berg683b6d32012-11-08 21:25:48 +01002524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2525 chandef->chan->center_freq))
2526 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002527 switch (chandef->width) {
2528 case NL80211_CHAN_WIDTH_20_NOHT:
2529 case NL80211_CHAN_WIDTH_20:
2530 case NL80211_CHAN_WIDTH_40:
2531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2532 cfg80211_get_chandef_type(chandef)))
2533 return -ENOBUFS;
2534 break;
2535 default:
2536 break;
2537 }
2538 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2539 return -ENOBUFS;
2540 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2541 return -ENOBUFS;
2542 if (chandef->center_freq2 &&
2543 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002544 return -ENOBUFS;
2545 return 0;
2546}
2547
Eric W. Biederman15e47302012-09-07 20:12:54 +00002548static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002549 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002550 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002551{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002552 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002553 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002554 void *hdr;
2555
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002556 if (removal)
2557 cmd = NL80211_CMD_DEL_INTERFACE;
2558
2559 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002560 if (!hdr)
2561 return -1;
2562
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002563 if (dev &&
2564 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002565 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002566 goto nla_put_failure;
2567
2568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2569 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002570 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2571 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002572 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002573 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2574 rdev->devlist_generation ^
2575 (cfg80211_rdev_list_generation << 2)))
2576 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002577
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002578 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002579 int ret;
2580 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002581
Johannes Berg683b6d32012-11-08 21:25:48 +01002582 ret = rdev_get_channel(rdev, wdev, &chandef);
2583 if (ret == 0) {
2584 if (nl80211_send_chandef(msg, &chandef))
2585 goto nla_put_failure;
2586 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002587 }
2588
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002589 if (rdev->ops->get_tx_power) {
2590 int dbm, ret;
2591
2592 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2593 if (ret == 0 &&
2594 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2595 DBM_TO_MBM(dbm)))
2596 goto nla_put_failure;
2597 }
2598
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002599 if (wdev->ssid_len) {
2600 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2601 goto nla_put_failure;
2602 }
2603
Johannes Berg053c0952015-01-16 22:09:00 +01002604 genlmsg_end(msg, hdr);
2605 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002606
2607 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002608 genlmsg_cancel(msg, hdr);
2609 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002610}
2611
2612static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2613{
2614 int wp_idx = 0;
2615 int if_idx = 0;
2616 int wp_start = cb->args[0];
2617 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002618 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002619 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002620 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002621 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002622
Johannes Berg5fe231e2013-05-08 21:45:15 +02002623 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002624 if (!cb->args[2]) {
2625 struct nl80211_dump_wiphy_state state = {
2626 .filter_wiphy = -1,
2627 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002628
2629 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2630 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002631 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002632
2633 filter_wiphy = state.filter_wiphy;
2634
2635 /*
2636 * if filtering, set cb->args[2] to +1 since 0 is the default
2637 * value needed to determine that parsing is necessary.
2638 */
2639 if (filter_wiphy >= 0)
2640 cb->args[2] = filter_wiphy + 1;
2641 else
2642 cb->args[2] = -1;
2643 } else if (cb->args[2] > 0) {
2644 filter_wiphy = cb->args[2] - 1;
2645 }
2646
Johannes Bergf5ea9122009-08-07 16:17:38 +02002647 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2648 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002649 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002650 if (wp_idx < wp_start) {
2651 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002652 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002653 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002654
2655 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2656 continue;
2657
Johannes Berg55682962007-09-20 13:09:35 -04002658 if_idx = 0;
2659
Johannes Berg53873f12016-05-03 16:52:04 +03002660 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002661 if (if_idx < if_start) {
2662 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002663 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002664 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002665 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002666 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002667 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002668 goto out;
2669 }
2670 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002671 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002672
2673 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002674 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002675 out:
Johannes Berg55682962007-09-20 13:09:35 -04002676 cb->args[0] = wp_idx;
2677 cb->args[1] = if_idx;
2678
Johannes Bergea90e0d2017-03-15 14:26:04 +01002679 ret = skb->len;
2680 out_unlock:
2681 rtnl_unlock();
2682
2683 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002684}
2685
2686static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2687{
2688 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002690 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002691
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002693 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002694 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002695
Eric W. Biederman15e47302012-09-07 20:12:54 +00002696 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002697 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002698 nlmsg_free(msg);
2699 return -ENOBUFS;
2700 }
Johannes Berg55682962007-09-20 13:09:35 -04002701
Johannes Berg134e6372009-07-10 09:51:34 +00002702 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002703}
2704
Michael Wu66f7ac52008-01-31 19:48:22 +01002705static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2706 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2707 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2708 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2709 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2710 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002711 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002712};
2713
2714static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2715{
2716 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2717 int flag;
2718
2719 *mntrflags = 0;
2720
2721 if (!nla)
2722 return -EINVAL;
2723
Johannes Bergfceb6432017-04-12 14:34:07 +02002724 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2725 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002726 return -EINVAL;
2727
2728 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2729 if (flags[flag])
2730 *mntrflags |= (1<<flag);
2731
Johannes Berg818a9862017-04-12 11:23:28 +02002732 *mntrflags |= MONITOR_FLAG_CHANGED;
2733
Michael Wu66f7ac52008-01-31 19:48:22 +01002734 return 0;
2735}
2736
Johannes Berg1db77592017-04-12 11:36:31 +02002737static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2738 enum nl80211_iftype type,
2739 struct genl_info *info,
2740 struct vif_params *params)
2741{
2742 bool change = false;
2743 int err;
2744
2745 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2746 if (type != NL80211_IFTYPE_MONITOR)
2747 return -EINVAL;
2748
2749 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2750 &params->flags);
2751 if (err)
2752 return err;
2753
2754 change = true;
2755 }
2756
2757 if (params->flags & MONITOR_FLAG_ACTIVE &&
2758 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2759 return -EOPNOTSUPP;
2760
2761 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2762 const u8 *mumimo_groups;
2763 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2764
2765 if (type != NL80211_IFTYPE_MONITOR)
2766 return -EINVAL;
2767
2768 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2769 return -EOPNOTSUPP;
2770
2771 mumimo_groups =
2772 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2773
2774 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002775 if ((mumimo_groups[0] & BIT(0)) ||
2776 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002777 return -EINVAL;
2778
2779 params->vht_mumimo_groups = mumimo_groups;
2780 change = true;
2781 }
2782
2783 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2784 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2785
2786 if (type != NL80211_IFTYPE_MONITOR)
2787 return -EINVAL;
2788
2789 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2790 return -EOPNOTSUPP;
2791
2792 params->vht_mumimo_follow_addr =
2793 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2794 change = true;
2795 }
2796
2797 return change ? 1 : 0;
2798}
2799
Johannes Berg9bc383d2009-11-19 11:55:19 +01002800static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002801 struct net_device *netdev, u8 use_4addr,
2802 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002803{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002804 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002805 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002806 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002807 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002808 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002809
2810 switch (iftype) {
2811 case NL80211_IFTYPE_AP_VLAN:
2812 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2813 return 0;
2814 break;
2815 case NL80211_IFTYPE_STATION:
2816 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2817 return 0;
2818 break;
2819 default:
2820 break;
2821 }
2822
2823 return -EOPNOTSUPP;
2824}
2825
Johannes Berg55682962007-09-20 13:09:35 -04002826static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2827{
Johannes Berg4c476992010-10-04 21:36:35 +02002828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002829 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002830 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002831 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002832 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002833 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002834
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002835 memset(&params, 0, sizeof(params));
2836
Johannes Berg04a773a2009-04-19 21:24:32 +02002837 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002838
Johannes Berg723b0382008-09-16 20:22:09 +02002839 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002840 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002841 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002842 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002843 if (ntype > NL80211_IFTYPE_MAX)
2844 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002845 }
2846
Johannes Berg92ffe052008-09-16 20:39:36 +02002847 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002848 struct wireless_dev *wdev = dev->ieee80211_ptr;
2849
Johannes Berg4c476992010-10-04 21:36:35 +02002850 if (ntype != NL80211_IFTYPE_MESH_POINT)
2851 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002852 if (netif_running(dev))
2853 return -EBUSY;
2854
2855 wdev_lock(wdev);
2856 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2857 IEEE80211_MAX_MESH_ID_LEN);
2858 wdev->mesh_id_up_len =
2859 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2860 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2861 wdev->mesh_id_up_len);
2862 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002863 }
2864
Felix Fietkau8b787642009-11-10 18:53:10 +01002865 if (info->attrs[NL80211_ATTR_4ADDR]) {
2866 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2867 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002868 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002869 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002870 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002871 } else {
2872 params.use_4addr = -1;
2873 }
2874
Johannes Berg1db77592017-04-12 11:36:31 +02002875 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2876 if (err < 0)
2877 return err;
2878 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002879 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002880
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002881 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002882 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002883 else
2884 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002885
Johannes Berg9bc383d2009-11-19 11:55:19 +01002886 if (!err && params.use_4addr != -1)
2887 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2888
Johannes Berg55682962007-09-20 13:09:35 -04002889 return err;
2890}
2891
2892static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2893{
Johannes Berg4c476992010-10-04 21:36:35 +02002894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002895 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002896 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002897 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002898 int err;
2899 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2900
Johannes Berg78f22b62014-03-24 17:57:27 +01002901 /* to avoid failing a new interface creation due to pending removal */
2902 cfg80211_destroy_ifaces(rdev);
2903
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002904 memset(&params, 0, sizeof(params));
2905
Johannes Berg55682962007-09-20 13:09:35 -04002906 if (!info->attrs[NL80211_ATTR_IFNAME])
2907 return -EINVAL;
2908
2909 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2910 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2911 if (type > NL80211_IFTYPE_MAX)
2912 return -EINVAL;
2913 }
2914
Johannes Berg79c97e92009-07-07 03:56:12 +02002915 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002916 !(rdev->wiphy.interface_modes & (1 << type)))
2917 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002918
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002919 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002920 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2921 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002922 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2923 ETH_ALEN);
2924 if (!is_valid_ether_addr(params.macaddr))
2925 return -EADDRNOTAVAIL;
2926 }
2927
Johannes Berg9bc383d2009-11-19 11:55:19 +01002928 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002929 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002930 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002931 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002932 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002933 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002934
Johannes Berg1db77592017-04-12 11:36:31 +02002935 err = nl80211_parse_mon_options(rdev, type, info, &params);
2936 if (err < 0)
2937 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002938
Johannes Berga18c7192015-02-24 10:56:42 +01002939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2940 if (!msg)
2941 return -ENOMEM;
2942
Hila Gonene35e4d22012-06-27 17:19:42 +03002943 wdev = rdev_add_virtual_intf(rdev,
2944 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02002945 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002946 if (WARN_ON(!wdev)) {
2947 nlmsg_free(msg);
2948 return -EPROTO;
2949 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002950 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002951 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002952 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002953
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002954 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002955 wdev->owner_nlportid = info->snd_portid;
2956
Johannes Berg98104fde2012-06-16 00:19:54 +02002957 switch (type) {
2958 case NL80211_IFTYPE_MESH_POINT:
2959 if (!info->attrs[NL80211_ATTR_MESH_ID])
2960 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002961 wdev_lock(wdev);
2962 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2963 IEEE80211_MAX_MESH_ID_LEN);
2964 wdev->mesh_id_up_len =
2965 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2966 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2967 wdev->mesh_id_up_len);
2968 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002969 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002970 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002971 case NL80211_IFTYPE_P2P_DEVICE:
2972 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002973 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002974 * through the netdev notifier and must be added here
2975 */
2976 mutex_init(&wdev->mtx);
2977 INIT_LIST_HEAD(&wdev->event_list);
2978 spin_lock_init(&wdev->event_lock);
2979 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2980 spin_lock_init(&wdev->mgmt_registrations_lock);
2981
Johannes Berg98104fde2012-06-16 00:19:54 +02002982 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002983 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002984 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002985 break;
2986 default:
2987 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002988 }
2989
Eric W. Biederman15e47302012-09-07 20:12:54 +00002990 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002991 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002992 nlmsg_free(msg);
2993 return -ENOBUFS;
2994 }
2995
Denis Kenzior896ff062016-08-03 16:58:33 -05002996 /*
2997 * For wdevs which have no associated netdev object (e.g. of type
2998 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2999 * For all other types, the event will be generated from the
3000 * netdev notifier
3001 */
3002 if (!wdev->netdev)
3003 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003004
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003005 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003006}
3007
3008static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3009{
Johannes Berg4c476992010-10-04 21:36:35 +02003010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003011 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003012
Johannes Berg4c476992010-10-04 21:36:35 +02003013 if (!rdev->ops->del_virtual_intf)
3014 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003015
Johannes Berg84efbb82012-06-16 00:00:26 +02003016 /*
3017 * If we remove a wireless device without a netdev then clear
3018 * user_ptr[1] so that nl80211_post_doit won't dereference it
3019 * to check if it needs to do dev_put(). Otherwise it crashes
3020 * since the wdev has been freed, unlike with a netdev where
3021 * we need the dev_put() for the netdev to really be freed.
3022 */
3023 if (!wdev->netdev)
3024 info->user_ptr[1] = NULL;
3025
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003026 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003027}
3028
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003029static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3030{
3031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3032 struct net_device *dev = info->user_ptr[1];
3033 u16 noack_map;
3034
3035 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3036 return -EINVAL;
3037
3038 if (!rdev->ops->set_noack_map)
3039 return -EOPNOTSUPP;
3040
3041 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3042
Hila Gonene35e4d22012-06-27 17:19:42 +03003043 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003044}
3045
Johannes Berg41ade002007-12-19 02:03:29 +01003046struct get_key_cookie {
3047 struct sk_buff *msg;
3048 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003049 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003050};
3051
3052static void get_key_callback(void *c, struct key_params *params)
3053{
Johannes Bergb9454e82009-07-08 13:29:08 +02003054 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003055 struct get_key_cookie *cookie = c;
3056
David S. Miller9360ffd2012-03-29 04:41:26 -04003057 if ((params->key &&
3058 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3059 params->key_len, params->key)) ||
3060 (params->seq &&
3061 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3062 params->seq_len, params->seq)) ||
3063 (params->cipher &&
3064 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3065 params->cipher)))
3066 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003067
Johannes Bergb9454e82009-07-08 13:29:08 +02003068 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3069 if (!key)
3070 goto nla_put_failure;
3071
David S. Miller9360ffd2012-03-29 04:41:26 -04003072 if ((params->key &&
3073 nla_put(cookie->msg, NL80211_KEY_DATA,
3074 params->key_len, params->key)) ||
3075 (params->seq &&
3076 nla_put(cookie->msg, NL80211_KEY_SEQ,
3077 params->seq_len, params->seq)) ||
3078 (params->cipher &&
3079 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3080 params->cipher)))
3081 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003082
David S. Miller9360ffd2012-03-29 04:41:26 -04003083 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3084 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003085
3086 nla_nest_end(cookie->msg, key);
3087
Johannes Berg41ade002007-12-19 02:03:29 +01003088 return;
3089 nla_put_failure:
3090 cookie->error = 1;
3091}
3092
3093static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3094{
Johannes Berg4c476992010-10-04 21:36:35 +02003095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003096 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003097 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003098 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003099 const u8 *mac_addr = NULL;
3100 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003101 struct get_key_cookie cookie = {
3102 .error = 0,
3103 };
3104 void *hdr;
3105 struct sk_buff *msg;
3106
3107 if (info->attrs[NL80211_ATTR_KEY_IDX])
3108 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3109
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003110 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003111 return -EINVAL;
3112
3113 if (info->attrs[NL80211_ATTR_MAC])
3114 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3115
Johannes Berge31b8212010-10-05 19:39:30 +02003116 pairwise = !!mac_addr;
3117 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3118 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003119
Johannes Berge31b8212010-10-05 19:39:30 +02003120 if (kt >= NUM_NL80211_KEYTYPES)
3121 return -EINVAL;
3122 if (kt != NL80211_KEYTYPE_GROUP &&
3123 kt != NL80211_KEYTYPE_PAIRWISE)
3124 return -EINVAL;
3125 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3126 }
3127
Johannes Berg4c476992010-10-04 21:36:35 +02003128 if (!rdev->ops->get_key)
3129 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003130
Johannes Berg0fa7b392015-01-23 11:10:12 +01003131 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3132 return -ENOENT;
3133
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003135 if (!msg)
3136 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003137
Eric W. Biederman15e47302012-09-07 20:12:54 +00003138 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003139 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003140 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003141 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003142
3143 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003144 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003145
David S. Miller9360ffd2012-03-29 04:41:26 -04003146 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3147 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3148 goto nla_put_failure;
3149 if (mac_addr &&
3150 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3151 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003152
Hila Gonene35e4d22012-06-27 17:19:42 +03003153 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3154 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003155
3156 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003157 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003158
3159 if (cookie.error)
3160 goto nla_put_failure;
3161
3162 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003163 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003164
3165 nla_put_failure:
3166 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003167 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003168 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003169 return err;
3170}
3171
3172static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3173{
Johannes Berg4c476992010-10-04 21:36:35 +02003174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003175 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003176 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003177 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003178
Johannes Bergb9454e82009-07-08 13:29:08 +02003179 err = nl80211_parse_key(info, &key);
3180 if (err)
3181 return err;
3182
3183 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003184 return -EINVAL;
3185
Johannes Bergb9454e82009-07-08 13:29:08 +02003186 /* only support setting default key */
3187 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003188 return -EINVAL;
3189
Johannes Bergfffd0932009-07-08 14:22:54 +02003190 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003191
3192 if (key.def) {
3193 if (!rdev->ops->set_default_key) {
3194 err = -EOPNOTSUPP;
3195 goto out;
3196 }
3197
3198 err = nl80211_key_allowed(dev->ieee80211_ptr);
3199 if (err)
3200 goto out;
3201
Hila Gonene35e4d22012-06-27 17:19:42 +03003202 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003203 key.def_uni, key.def_multi);
3204
3205 if (err)
3206 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003207
Johannes Berg3d23e342009-09-29 23:27:28 +02003208#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003209 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003210#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003211 } else {
3212 if (key.def_uni || !key.def_multi) {
3213 err = -EINVAL;
3214 goto out;
3215 }
3216
3217 if (!rdev->ops->set_default_mgmt_key) {
3218 err = -EOPNOTSUPP;
3219 goto out;
3220 }
3221
3222 err = nl80211_key_allowed(dev->ieee80211_ptr);
3223 if (err)
3224 goto out;
3225
Hila Gonene35e4d22012-06-27 17:19:42 +03003226 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003227 if (err)
3228 goto out;
3229
3230#ifdef CONFIG_CFG80211_WEXT
3231 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3232#endif
3233 }
3234
3235 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003236 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003237
Johannes Berg41ade002007-12-19 02:03:29 +01003238 return err;
3239}
3240
3241static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3242{
Johannes Berg4c476992010-10-04 21:36:35 +02003243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003244 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003245 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003246 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003247 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003248
Johannes Bergb9454e82009-07-08 13:29:08 +02003249 err = nl80211_parse_key(info, &key);
3250 if (err)
3251 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003252
Johannes Bergb9454e82009-07-08 13:29:08 +02003253 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003254 return -EINVAL;
3255
Johannes Berg41ade002007-12-19 02:03:29 +01003256 if (info->attrs[NL80211_ATTR_MAC])
3257 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3258
Johannes Berge31b8212010-10-05 19:39:30 +02003259 if (key.type == -1) {
3260 if (mac_addr)
3261 key.type = NL80211_KEYTYPE_PAIRWISE;
3262 else
3263 key.type = NL80211_KEYTYPE_GROUP;
3264 }
3265
3266 /* for now */
3267 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3268 key.type != NL80211_KEYTYPE_GROUP)
3269 return -EINVAL;
3270
Johannes Berg4c476992010-10-04 21:36:35 +02003271 if (!rdev->ops->add_key)
3272 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003273
Johannes Berge31b8212010-10-05 19:39:30 +02003274 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3275 key.type == NL80211_KEYTYPE_PAIRWISE,
3276 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003277 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003278
3279 wdev_lock(dev->ieee80211_ptr);
3280 err = nl80211_key_allowed(dev->ieee80211_ptr);
3281 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003282 err = rdev_add_key(rdev, dev, key.idx,
3283 key.type == NL80211_KEYTYPE_PAIRWISE,
3284 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003285 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003286
Johannes Berg41ade002007-12-19 02:03:29 +01003287 return err;
3288}
3289
3290static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3291{
Johannes Berg4c476992010-10-04 21:36:35 +02003292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003293 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003294 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003295 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003296 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003297
Johannes Bergb9454e82009-07-08 13:29:08 +02003298 err = nl80211_parse_key(info, &key);
3299 if (err)
3300 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003301
3302 if (info->attrs[NL80211_ATTR_MAC])
3303 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3304
Johannes Berge31b8212010-10-05 19:39:30 +02003305 if (key.type == -1) {
3306 if (mac_addr)
3307 key.type = NL80211_KEYTYPE_PAIRWISE;
3308 else
3309 key.type = NL80211_KEYTYPE_GROUP;
3310 }
3311
3312 /* for now */
3313 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3314 key.type != NL80211_KEYTYPE_GROUP)
3315 return -EINVAL;
3316
Johannes Berg4c476992010-10-04 21:36:35 +02003317 if (!rdev->ops->del_key)
3318 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003319
Johannes Bergfffd0932009-07-08 14:22:54 +02003320 wdev_lock(dev->ieee80211_ptr);
3321 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003322
Johannes Berg0fa7b392015-01-23 11:10:12 +01003323 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003324 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3325 err = -ENOENT;
3326
Johannes Bergfffd0932009-07-08 14:22:54 +02003327 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003328 err = rdev_del_key(rdev, dev, key.idx,
3329 key.type == NL80211_KEYTYPE_PAIRWISE,
3330 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003331
Johannes Berg3d23e342009-09-29 23:27:28 +02003332#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003333 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003334 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003335 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003336 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003337 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3338 }
3339#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003340 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003341
Johannes Berg41ade002007-12-19 02:03:29 +01003342 return err;
3343}
3344
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303345/* This function returns an error or the number of nested attributes */
3346static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3347{
3348 struct nlattr *attr;
3349 int n_entries = 0, tmp;
3350
3351 nla_for_each_nested(attr, nl_attr, tmp) {
3352 if (nla_len(attr) != ETH_ALEN)
3353 return -EINVAL;
3354
3355 n_entries++;
3356 }
3357
3358 return n_entries;
3359}
3360
3361/*
3362 * This function parses ACL information and allocates memory for ACL data.
3363 * On successful return, the calling function is responsible to free the
3364 * ACL buffer returned by this function.
3365 */
3366static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3367 struct genl_info *info)
3368{
3369 enum nl80211_acl_policy acl_policy;
3370 struct nlattr *attr;
3371 struct cfg80211_acl_data *acl;
3372 int i = 0, n_entries, tmp;
3373
3374 if (!wiphy->max_acl_mac_addrs)
3375 return ERR_PTR(-EOPNOTSUPP);
3376
3377 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3378 return ERR_PTR(-EINVAL);
3379
3380 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3381 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3382 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3383 return ERR_PTR(-EINVAL);
3384
3385 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3386 return ERR_PTR(-EINVAL);
3387
3388 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3389 if (n_entries < 0)
3390 return ERR_PTR(n_entries);
3391
3392 if (n_entries > wiphy->max_acl_mac_addrs)
3393 return ERR_PTR(-ENOTSUPP);
3394
3395 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3396 GFP_KERNEL);
3397 if (!acl)
3398 return ERR_PTR(-ENOMEM);
3399
3400 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3401 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3402 i++;
3403 }
3404
3405 acl->n_acl_entries = n_entries;
3406 acl->acl_policy = acl_policy;
3407
3408 return acl;
3409}
3410
3411static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3412{
3413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3414 struct net_device *dev = info->user_ptr[1];
3415 struct cfg80211_acl_data *acl;
3416 int err;
3417
3418 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3419 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3420 return -EOPNOTSUPP;
3421
3422 if (!dev->ieee80211_ptr->beacon_interval)
3423 return -EINVAL;
3424
3425 acl = parse_acl_data(&rdev->wiphy, info);
3426 if (IS_ERR(acl))
3427 return PTR_ERR(acl);
3428
3429 err = rdev_set_mac_acl(rdev, dev, acl);
3430
3431 kfree(acl);
3432
3433 return err;
3434}
3435
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303436static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3437 u8 *rates, u8 rates_len)
3438{
3439 u8 i;
3440 u32 mask = 0;
3441
3442 for (i = 0; i < rates_len; i++) {
3443 int rate = (rates[i] & 0x7f) * 5;
3444 int ridx;
3445
3446 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3447 struct ieee80211_rate *srate =
3448 &sband->bitrates[ridx];
3449 if (rate == srate->bitrate) {
3450 mask |= 1 << ridx;
3451 break;
3452 }
3453 }
3454 if (ridx == sband->n_bitrates)
3455 return 0; /* rate not found */
3456 }
3457
3458 return mask;
3459}
3460
3461static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3462 u8 *rates, u8 rates_len,
3463 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3464{
3465 u8 i;
3466
3467 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3468
3469 for (i = 0; i < rates_len; i++) {
3470 int ridx, rbit;
3471
3472 ridx = rates[i] / 8;
3473 rbit = BIT(rates[i] % 8);
3474
3475 /* check validity */
3476 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3477 return false;
3478
3479 /* check availability */
3480 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3481 mcs[ridx] |= rbit;
3482 else
3483 return false;
3484 }
3485
3486 return true;
3487}
3488
3489static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3490{
3491 u16 mcs_mask = 0;
3492
3493 switch (vht_mcs_map) {
3494 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3495 break;
3496 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3497 mcs_mask = 0x00FF;
3498 break;
3499 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3500 mcs_mask = 0x01FF;
3501 break;
3502 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3503 mcs_mask = 0x03FF;
3504 break;
3505 default:
3506 break;
3507 }
3508
3509 return mcs_mask;
3510}
3511
3512static void vht_build_mcs_mask(u16 vht_mcs_map,
3513 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3514{
3515 u8 nss;
3516
3517 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3518 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3519 vht_mcs_map >>= 2;
3520 }
3521}
3522
3523static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3524 struct nl80211_txrate_vht *txrate,
3525 u16 mcs[NL80211_VHT_NSS_MAX])
3526{
3527 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3528 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3529 u8 i;
3530
3531 if (!sband->vht_cap.vht_supported)
3532 return false;
3533
3534 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3535
3536 /* Build vht_mcs_mask from VHT capabilities */
3537 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3538
3539 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3540 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3541 mcs[i] = txrate->mcs[i];
3542 else
3543 return false;
3544 }
3545
3546 return true;
3547}
3548
3549static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3550 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3551 .len = NL80211_MAX_SUPP_RATES },
3552 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3553 .len = NL80211_MAX_SUPP_HT_RATES },
3554 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3555 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3556};
3557
3558static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3559 struct cfg80211_bitrate_mask *mask)
3560{
3561 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3563 int rem, i;
3564 struct nlattr *tx_rates;
3565 struct ieee80211_supported_band *sband;
3566 u16 vht_tx_mcs_map;
3567
3568 memset(mask, 0, sizeof(*mask));
3569 /* Default to all rates enabled */
3570 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3571 sband = rdev->wiphy.bands[i];
3572
3573 if (!sband)
3574 continue;
3575
3576 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3577 memcpy(mask->control[i].ht_mcs,
3578 sband->ht_cap.mcs.rx_mask,
3579 sizeof(mask->control[i].ht_mcs));
3580
3581 if (!sband->vht_cap.vht_supported)
3582 continue;
3583
3584 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3585 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3586 }
3587
3588 /* if no rates are given set it back to the defaults */
3589 if (!info->attrs[NL80211_ATTR_TX_RATES])
3590 goto out;
3591
3592 /* The nested attribute uses enum nl80211_band as the index. This maps
3593 * directly to the enum nl80211_band values used in cfg80211.
3594 */
3595 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3596 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3597 enum nl80211_band band = nla_type(tx_rates);
3598 int err;
3599
3600 if (band < 0 || band >= NUM_NL80211_BANDS)
3601 return -EINVAL;
3602 sband = rdev->wiphy.bands[band];
3603 if (sband == NULL)
3604 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003605 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003606 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303607 if (err)
3608 return err;
3609 if (tb[NL80211_TXRATE_LEGACY]) {
3610 mask->control[band].legacy = rateset_to_mask(
3611 sband,
3612 nla_data(tb[NL80211_TXRATE_LEGACY]),
3613 nla_len(tb[NL80211_TXRATE_LEGACY]));
3614 if ((mask->control[band].legacy == 0) &&
3615 nla_len(tb[NL80211_TXRATE_LEGACY]))
3616 return -EINVAL;
3617 }
3618 if (tb[NL80211_TXRATE_HT]) {
3619 if (!ht_rateset_to_mask(
3620 sband,
3621 nla_data(tb[NL80211_TXRATE_HT]),
3622 nla_len(tb[NL80211_TXRATE_HT]),
3623 mask->control[band].ht_mcs))
3624 return -EINVAL;
3625 }
3626 if (tb[NL80211_TXRATE_VHT]) {
3627 if (!vht_set_mcs_mask(
3628 sband,
3629 nla_data(tb[NL80211_TXRATE_VHT]),
3630 mask->control[band].vht_mcs))
3631 return -EINVAL;
3632 }
3633 if (tb[NL80211_TXRATE_GI]) {
3634 mask->control[band].gi =
3635 nla_get_u8(tb[NL80211_TXRATE_GI]);
3636 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3637 return -EINVAL;
3638 }
3639
3640 if (mask->control[band].legacy == 0) {
3641 /* don't allow empty legacy rates if HT or VHT
3642 * are not even supported.
3643 */
3644 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3645 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3646 return -EINVAL;
3647
3648 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3649 if (mask->control[band].ht_mcs[i])
3650 goto out;
3651
3652 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3653 if (mask->control[band].vht_mcs[i])
3654 goto out;
3655
3656 /* legacy and mcs rates may not be both empty */
3657 return -EINVAL;
3658 }
3659 }
3660
3661out:
3662 return 0;
3663}
3664
Johannes Berg8564e382016-09-19 09:44:44 +02003665static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3666 enum nl80211_band band,
3667 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303668{
Johannes Berg8564e382016-09-19 09:44:44 +02003669 u32 count_ht, count_vht, i;
3670 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303671
3672 /* Allow only one rate */
3673 if (hweight32(rate) > 1)
3674 return -EINVAL;
3675
3676 count_ht = 0;
3677 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003678 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303679 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003680 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303681 count_ht++;
3682 if (count_ht > 1)
3683 return -EINVAL;
3684 }
3685 if (count_ht && rate)
3686 return -EINVAL;
3687 }
3688
3689 count_vht = 0;
3690 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003691 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303692 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003693 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303694 count_vht++;
3695 if (count_vht > 1)
3696 return -EINVAL;
3697 }
3698 if (count_vht && rate)
3699 return -EINVAL;
3700 }
3701
3702 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3703 return -EINVAL;
3704
Johannes Berg8564e382016-09-19 09:44:44 +02003705 if (rate &&
3706 !wiphy_ext_feature_isset(&rdev->wiphy,
3707 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3708 return -EINVAL;
3709 if (count_ht &&
3710 !wiphy_ext_feature_isset(&rdev->wiphy,
3711 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3712 return -EINVAL;
3713 if (count_vht &&
3714 !wiphy_ext_feature_isset(&rdev->wiphy,
3715 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3716 return -EINVAL;
3717
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303718 return 0;
3719}
3720
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003721static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003722 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003723{
Johannes Berg88600202012-02-13 15:17:18 +01003724 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003725
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003726 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3727 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3728 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3729 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003730 return -EINVAL;
3731
Johannes Berg88600202012-02-13 15:17:18 +01003732 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003733
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003734 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3735 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3736 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003737 if (!bcn->head_len)
3738 return -EINVAL;
3739 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003740 }
3741
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003742 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3743 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3744 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003745 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003746 }
3747
Johannes Berg4c476992010-10-04 21:36:35 +02003748 if (!haveinfo)
3749 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003750
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003751 if (attrs[NL80211_ATTR_IE]) {
3752 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3753 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003754 }
3755
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003756 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003757 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003758 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003759 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003760 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003761 }
3762
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003763 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003764 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003765 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003766 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003767 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003768 }
3769
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003770 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3771 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3772 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003773 }
3774
Johannes Berg88600202012-02-13 15:17:18 +01003775 return 0;
3776}
3777
Johannes Berg66cd7942017-02-07 22:40:44 +02003778static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3779 const u8 *rates)
3780{
3781 int i;
3782
3783 if (!rates)
3784 return;
3785
3786 for (i = 0; i < rates[1]; i++) {
3787 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3788 params->ht_required = true;
3789 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3790 params->vht_required = true;
3791 }
3792}
3793
3794/*
3795 * Since the nl80211 API didn't include, from the beginning, attributes about
3796 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3797 * benefit of drivers that rebuild IEs in the firmware.
3798 */
3799static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3800{
3801 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07003802 size_t ies_len = bcn->tail_len;
3803 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02003804 const u8 *rates;
3805 const u8 *cap;
3806
3807 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3808 nl80211_check_ap_rate_selectors(params, rates);
3809
3810 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3811 nl80211_check_ap_rate_selectors(params, rates);
3812
3813 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3814 if (cap && cap[1] >= sizeof(*params->ht_cap))
3815 params->ht_cap = (void *)(cap + 2);
3816 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3817 if (cap && cap[1] >= sizeof(*params->vht_cap))
3818 params->vht_cap = (void *)(cap + 2);
3819}
3820
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003821static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3822 struct cfg80211_ap_settings *params)
3823{
3824 struct wireless_dev *wdev;
3825 bool ret = false;
3826
Johannes Berg53873f12016-05-03 16:52:04 +03003827 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003828 if (wdev->iftype != NL80211_IFTYPE_AP &&
3829 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3830 continue;
3831
Johannes Berg683b6d32012-11-08 21:25:48 +01003832 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003833 continue;
3834
Johannes Berg683b6d32012-11-08 21:25:48 +01003835 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003836 ret = true;
3837 break;
3838 }
3839
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003840 return ret;
3841}
3842
Jouni Malinene39e5b52012-09-30 19:29:39 +03003843static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3844 enum nl80211_auth_type auth_type,
3845 enum nl80211_commands cmd)
3846{
3847 if (auth_type > NL80211_AUTHTYPE_MAX)
3848 return false;
3849
3850 switch (cmd) {
3851 case NL80211_CMD_AUTHENTICATE:
3852 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3853 auth_type == NL80211_AUTHTYPE_SAE)
3854 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003855 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3856 NL80211_EXT_FEATURE_FILS_STA) &&
3857 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3858 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3859 auth_type == NL80211_AUTHTYPE_FILS_PK))
3860 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003861 return true;
3862 case NL80211_CMD_CONNECT:
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003863 /* SAE not supported yet */
3864 if (auth_type == NL80211_AUTHTYPE_SAE)
3865 return false;
3866 /* FILS with SK PFS or PK not supported yet */
3867 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3868 auth_type == NL80211_AUTHTYPE_FILS_PK)
3869 return false;
3870 if (!wiphy_ext_feature_isset(
3871 &rdev->wiphy,
3872 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3873 auth_type == NL80211_AUTHTYPE_FILS_SK)
3874 return false;
3875 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003876 case NL80211_CMD_START_AP:
3877 /* SAE not supported yet */
3878 if (auth_type == NL80211_AUTHTYPE_SAE)
3879 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003880 /* FILS not supported yet */
3881 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3882 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3883 auth_type == NL80211_AUTHTYPE_FILS_PK)
3884 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003885 return true;
3886 default:
3887 return false;
3888 }
3889}
3890
Johannes Berg88600202012-02-13 15:17:18 +01003891static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3892{
3893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3894 struct net_device *dev = info->user_ptr[1];
3895 struct wireless_dev *wdev = dev->ieee80211_ptr;
3896 struct cfg80211_ap_settings params;
3897 int err;
3898
3899 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3900 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3901 return -EOPNOTSUPP;
3902
3903 if (!rdev->ops->start_ap)
3904 return -EOPNOTSUPP;
3905
3906 if (wdev->beacon_interval)
3907 return -EALREADY;
3908
3909 memset(&params, 0, sizeof(params));
3910
3911 /* these are required for START_AP */
3912 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3913 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3914 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3915 return -EINVAL;
3916
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003917 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003918 if (err)
3919 return err;
3920
3921 params.beacon_interval =
3922 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3923 params.dtim_period =
3924 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3925
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303926 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3927 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003928 if (err)
3929 return err;
3930
3931 /*
3932 * In theory, some of these attributes should be required here
3933 * but since they were not used when the command was originally
3934 * added, keep them optional for old user space programs to let
3935 * them continue to work with drivers that do not need the
3936 * additional information -- drivers must check!
3937 */
3938 if (info->attrs[NL80211_ATTR_SSID]) {
3939 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3940 params.ssid_len =
3941 nla_len(info->attrs[NL80211_ATTR_SSID]);
3942 if (params.ssid_len == 0 ||
3943 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3944 return -EINVAL;
3945 }
3946
3947 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3948 params.hidden_ssid = nla_get_u32(
3949 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3950 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3951 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3952 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3953 return -EINVAL;
3954 }
3955
3956 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3957
3958 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3959 params.auth_type = nla_get_u32(
3960 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003961 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3962 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003963 return -EINVAL;
3964 } else
3965 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3966
3967 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3968 NL80211_MAX_NR_CIPHER_SUITES);
3969 if (err)
3970 return err;
3971
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303972 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3973 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3974 return -EOPNOTSUPP;
3975 params.inactivity_timeout = nla_get_u16(
3976 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3977 }
3978
Johannes Berg53cabad2012-11-14 15:17:28 +01003979 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3980 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3981 return -EINVAL;
3982 params.p2p_ctwindow =
3983 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3984 if (params.p2p_ctwindow > 127)
3985 return -EINVAL;
3986 if (params.p2p_ctwindow != 0 &&
3987 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3988 return -EINVAL;
3989 }
3990
3991 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3992 u8 tmp;
3993
3994 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3995 return -EINVAL;
3996 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3997 if (tmp > 1)
3998 return -EINVAL;
3999 params.p2p_opp_ps = tmp;
4000 if (params.p2p_opp_ps != 0 &&
4001 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4002 return -EINVAL;
4003 }
4004
Johannes Bergaa430da2012-05-16 23:50:18 +02004005 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004006 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4007 if (err)
4008 return err;
4009 } else if (wdev->preset_chandef.chan) {
4010 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004011 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004012 return -EINVAL;
4013
Arik Nemtsov923b3522015-07-08 15:41:44 +03004014 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4015 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004016 return -EINVAL;
4017
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304018 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4019 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4020 if (err)
4021 return err;
4022
Johannes Berg8564e382016-09-19 09:44:44 +02004023 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4024 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304025 if (err)
4026 return err;
4027 }
4028
Eliad Peller18998c32014-09-10 14:07:34 +03004029 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4030 params.smps_mode =
4031 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4032 switch (params.smps_mode) {
4033 case NL80211_SMPS_OFF:
4034 break;
4035 case NL80211_SMPS_STATIC:
4036 if (!(rdev->wiphy.features &
4037 NL80211_FEATURE_STATIC_SMPS))
4038 return -EINVAL;
4039 break;
4040 case NL80211_SMPS_DYNAMIC:
4041 if (!(rdev->wiphy.features &
4042 NL80211_FEATURE_DYNAMIC_SMPS))
4043 return -EINVAL;
4044 break;
4045 default:
4046 return -EINVAL;
4047 }
4048 } else {
4049 params.smps_mode = NL80211_SMPS_OFF;
4050 }
4051
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304052 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4053 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4054 return -EOPNOTSUPP;
4055
Ola Olsson4baf6be2015-10-29 07:04:58 +01004056 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4057 params.acl = parse_acl_data(&rdev->wiphy, info);
4058 if (IS_ERR(params.acl))
4059 return PTR_ERR(params.acl);
4060 }
4061
Johannes Berg66cd7942017-02-07 22:40:44 +02004062 nl80211_calculate_ap_params(&params);
4063
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004064 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004065 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004066 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004067 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004068 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004069 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004070 wdev->ssid_len = params.ssid_len;
4071 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004072 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004073 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304074
4075 kfree(params.acl);
4076
Johannes Berg56d18932011-05-09 18:41:15 +02004077 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004078}
4079
Johannes Berg88600202012-02-13 15:17:18 +01004080static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4081{
4082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4083 struct net_device *dev = info->user_ptr[1];
4084 struct wireless_dev *wdev = dev->ieee80211_ptr;
4085 struct cfg80211_beacon_data params;
4086 int err;
4087
4088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4089 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4090 return -EOPNOTSUPP;
4091
4092 if (!rdev->ops->change_beacon)
4093 return -EOPNOTSUPP;
4094
4095 if (!wdev->beacon_interval)
4096 return -EINVAL;
4097
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004098 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004099 if (err)
4100 return err;
4101
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004102 wdev_lock(wdev);
4103 err = rdev_change_beacon(rdev, dev, &params);
4104 wdev_unlock(wdev);
4105
4106 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004107}
4108
4109static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004110{
Johannes Berg4c476992010-10-04 21:36:35 +02004111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4112 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004113
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004114 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004115}
4116
Johannes Berg5727ef12007-12-19 02:03:34 +01004117static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4118 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4119 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4120 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004121 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004122 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004123 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004124};
4125
Johannes Bergeccb8e82009-05-11 21:57:56 +03004126static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004127 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004128 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004129{
4130 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004131 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004132 int flag;
4133
Johannes Bergeccb8e82009-05-11 21:57:56 +03004134 /*
4135 * Try parsing the new attribute first so userspace
4136 * can specify both for older kernels.
4137 */
4138 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4139 if (nla) {
4140 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004141
Johannes Bergeccb8e82009-05-11 21:57:56 +03004142 sta_flags = nla_data(nla);
4143 params->sta_flags_mask = sta_flags->mask;
4144 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004145 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004146 if ((params->sta_flags_mask |
4147 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4148 return -EINVAL;
4149 return 0;
4150 }
4151
4152 /* if present, parse the old attribute */
4153
4154 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004155 if (!nla)
4156 return 0;
4157
Johannes Bergfceb6432017-04-12 14:34:07 +02004158 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004159 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004160 return -EINVAL;
4161
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004162 /*
4163 * Only allow certain flags for interface types so that
4164 * other attributes are silently ignored. Remember that
4165 * this is backward compatibility code with old userspace
4166 * and shouldn't be hit in other cases anyway.
4167 */
4168 switch (iftype) {
4169 case NL80211_IFTYPE_AP:
4170 case NL80211_IFTYPE_AP_VLAN:
4171 case NL80211_IFTYPE_P2P_GO:
4172 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4173 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4174 BIT(NL80211_STA_FLAG_WME) |
4175 BIT(NL80211_STA_FLAG_MFP);
4176 break;
4177 case NL80211_IFTYPE_P2P_CLIENT:
4178 case NL80211_IFTYPE_STATION:
4179 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4180 BIT(NL80211_STA_FLAG_TDLS_PEER);
4181 break;
4182 case NL80211_IFTYPE_MESH_POINT:
4183 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4184 BIT(NL80211_STA_FLAG_MFP) |
4185 BIT(NL80211_STA_FLAG_AUTHORIZED);
4186 default:
4187 return -EINVAL;
4188 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004189
Johannes Berg3383b5a2012-05-10 20:14:43 +02004190 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4191 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004192 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004193
Johannes Berg3383b5a2012-05-10 20:14:43 +02004194 /* no longer support new API additions in old API */
4195 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4196 return -EINVAL;
4197 }
4198 }
4199
Johannes Berg5727ef12007-12-19 02:03:34 +01004200 return 0;
4201}
4202
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004203static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4204 int attr)
4205{
4206 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004207 u32 bitrate;
4208 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004209 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004210
4211 rate = nla_nest_start(msg, attr);
4212 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004213 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004214
4215 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4216 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004217 /* report 16-bit bitrate only if we can */
4218 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004219 if (bitrate > 0 &&
4220 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4221 return false;
4222 if (bitrate_compat > 0 &&
4223 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4224 return false;
4225
Johannes Bergb51f3be2015-01-15 16:14:02 +01004226 switch (info->bw) {
4227 case RATE_INFO_BW_5:
4228 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4229 break;
4230 case RATE_INFO_BW_10:
4231 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4232 break;
4233 default:
4234 WARN_ON(1);
4235 /* fall through */
4236 case RATE_INFO_BW_20:
4237 rate_flg = 0;
4238 break;
4239 case RATE_INFO_BW_40:
4240 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4241 break;
4242 case RATE_INFO_BW_80:
4243 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4244 break;
4245 case RATE_INFO_BW_160:
4246 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4247 break;
4248 }
4249
4250 if (rate_flg && nla_put_flag(msg, rate_flg))
4251 return false;
4252
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004253 if (info->flags & RATE_INFO_FLAGS_MCS) {
4254 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4255 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004256 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4257 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4258 return false;
4259 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4260 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4261 return false;
4262 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4263 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004264 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4265 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4266 return false;
4267 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004268
4269 nla_nest_end(msg, rate);
4270 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004271}
4272
Felix Fietkau119363c2013-04-22 16:29:30 +02004273static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4274 int id)
4275{
4276 void *attr;
4277 int i = 0;
4278
4279 if (!mask)
4280 return true;
4281
4282 attr = nla_nest_start(msg, id);
4283 if (!attr)
4284 return false;
4285
4286 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4287 if (!(mask & BIT(i)))
4288 continue;
4289
4290 if (nla_put_u8(msg, i, signal[i]))
4291 return false;
4292 }
4293
4294 nla_nest_end(msg, attr);
4295
4296 return true;
4297}
4298
Johannes Bergcf5ead82014-11-14 17:14:00 +01004299static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4300 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004301 struct cfg80211_registered_device *rdev,
4302 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004303 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004304{
4305 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004306 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004307
Johannes Bergcf5ead82014-11-14 17:14:00 +01004308 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004309 if (!hdr)
4310 return -1;
4311
David S. Miller9360ffd2012-03-29 04:41:26 -04004312 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4313 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4314 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4315 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004316
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004317 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4318 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004319 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004320
4321#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004322 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304323 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004324 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4325 sinfo->memb)) \
4326 goto nla_put_failure; \
4327 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004328#define PUT_SINFO_U64(attr, memb) do { \
4329 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4330 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4331 sinfo->memb, NL80211_STA_INFO_PAD)) \
4332 goto nla_put_failure; \
4333 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004334
4335 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4336 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4337
4338 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4339 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004340 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004341 (u32)sinfo->rx_bytes))
4342 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004343
4344 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4345 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004346 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4347 (u32)sinfo->tx_bytes))
4348 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004349
Johannes Bergd686b922016-04-26 09:54:11 +02004350 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4351 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004352 PUT_SINFO(LLID, llid, u16);
4353 PUT_SINFO(PLID, plid, u16);
4354 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004355 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004356
John W. Linville66266b32012-03-15 13:25:41 -04004357 switch (rdev->wiphy.signal_type) {
4358 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004359 PUT_SINFO(SIGNAL, signal, u8);
4360 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004361 break;
4362 default:
4363 break;
4364 }
Johannes Berg319090b2014-11-17 14:08:11 +01004365 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004366 if (!nl80211_put_signal(msg, sinfo->chains,
4367 sinfo->chain_signal,
4368 NL80211_STA_INFO_CHAIN_SIGNAL))
4369 goto nla_put_failure;
4370 }
Johannes Berg319090b2014-11-17 14:08:11 +01004371 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004372 if (!nl80211_put_signal(msg, sinfo->chains,
4373 sinfo->chain_signal_avg,
4374 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4375 goto nla_put_failure;
4376 }
Johannes Berg319090b2014-11-17 14:08:11 +01004377 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004378 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4379 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004380 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004381 }
Johannes Berg319090b2014-11-17 14:08:11 +01004382 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004383 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4384 NL80211_STA_INFO_RX_BITRATE))
4385 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004386 }
Johannes Berg319090b2014-11-17 14:08:11 +01004387
4388 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4389 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4390 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4391 PUT_SINFO(TX_FAILED, tx_failed, u32);
4392 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4393 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4394 PUT_SINFO(LOCAL_PM, local_pm, u32);
4395 PUT_SINFO(PEER_PM, peer_pm, u32);
4396 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4397
4398 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004399 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4400 if (!bss_param)
4401 goto nla_put_failure;
4402
David S. Miller9360ffd2012-03-29 04:41:26 -04004403 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4404 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4405 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4406 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4407 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4408 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4409 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4410 sinfo->bss_param.dtim_period) ||
4411 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4412 sinfo->bss_param.beacon_interval))
4413 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004414
4415 nla_nest_end(msg, bss_param);
4416 }
Johannes Berg319090b2014-11-17 14:08:11 +01004417 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004418 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4419 sizeof(struct nl80211_sta_flag_update),
4420 &sinfo->sta_flags))
4421 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004422
Johannes Bergd686b922016-04-26 09:54:11 +02004423 PUT_SINFO_U64(T_OFFSET, t_offset);
4424 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4425 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004426 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004427
4428#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004429#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004430
4431 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4432 struct nlattr *tidsattr;
4433 int tid;
4434
4435 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4436 if (!tidsattr)
4437 goto nla_put_failure;
4438
4439 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4440 struct cfg80211_tid_stats *tidstats;
4441 struct nlattr *tidattr;
4442
4443 tidstats = &sinfo->pertid[tid];
4444
4445 if (!tidstats->filled)
4446 continue;
4447
4448 tidattr = nla_nest_start(msg, tid + 1);
4449 if (!tidattr)
4450 goto nla_put_failure;
4451
Johannes Bergd686b922016-04-26 09:54:11 +02004452#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004453 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004454 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4455 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004456 goto nla_put_failure; \
4457 } while (0)
4458
Johannes Bergd686b922016-04-26 09:54:11 +02004459 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4460 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4461 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4462 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004463
Johannes Bergd686b922016-04-26 09:54:11 +02004464#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004465 nla_nest_end(msg, tidattr);
4466 }
4467
4468 nla_nest_end(msg, tidsattr);
4469 }
4470
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004471 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004472
Johannes Berg319090b2014-11-17 14:08:11 +01004473 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004474 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4475 sinfo->assoc_req_ies))
4476 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004477
Johannes Berg053c0952015-01-16 22:09:00 +01004478 genlmsg_end(msg, hdr);
4479 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004480
4481 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004482 genlmsg_cancel(msg, hdr);
4483 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004484}
4485
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004487 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004488{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004489 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004490 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004491 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004492 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004493 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004494 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495
Johannes Bergea90e0d2017-03-15 14:26:04 +01004496 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004497 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004498 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004499 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004500
Johannes Berg97990a02013-04-19 01:02:55 +02004501 if (!wdev->netdev) {
4502 err = -EINVAL;
4503 goto out_err;
4504 }
4505
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004506 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004507 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004508 goto out_err;
4509 }
4510
Johannes Bergbba95fe2008-07-29 13:22:51 +02004511 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004512 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004513 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004514 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004515 if (err == -ENOENT)
4516 break;
4517 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004518 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004519
Johannes Bergcf5ead82014-11-14 17:14:00 +01004520 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004521 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004522 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004523 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004524 &sinfo) < 0)
4525 goto out;
4526
4527 sta_idx++;
4528 }
4529
Johannes Bergbba95fe2008-07-29 13:22:51 +02004530 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004531 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004532 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004534 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004535
4536 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004537}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004538
Johannes Berg5727ef12007-12-19 02:03:34 +01004539static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4540{
Johannes Berg4c476992010-10-04 21:36:35 +02004541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4542 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004544 struct sk_buff *msg;
4545 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004546 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004547
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004549
4550 if (!info->attrs[NL80211_ATTR_MAC])
4551 return -EINVAL;
4552
4553 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4554
Johannes Berg4c476992010-10-04 21:36:35 +02004555 if (!rdev->ops->get_station)
4556 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004557
Hila Gonene35e4d22012-06-27 17:19:42 +03004558 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004559 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004560 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004561
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004562 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004563 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004564 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004565
Johannes Bergcf5ead82014-11-14 17:14:00 +01004566 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4567 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004568 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004569 nlmsg_free(msg);
4570 return -ENOBUFS;
4571 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004572
Johannes Berg4c476992010-10-04 21:36:35 +02004573 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004574}
4575
Johannes Berg77ee7c82013-02-15 00:48:33 +01004576int cfg80211_check_station_change(struct wiphy *wiphy,
4577 struct station_parameters *params,
4578 enum cfg80211_station_type statype)
4579{
Ayala Bekere4208422015-10-23 11:20:06 +03004580 if (params->listen_interval != -1 &&
4581 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004582 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004583
Ayala Beker17b94242016-03-17 15:41:38 +02004584 if (params->support_p2p_ps != -1 &&
4585 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4586 return -EINVAL;
4587
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004588 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004589 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4590 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004591 return -EINVAL;
4592
4593 /* When you run into this, adjust the code below for the new flag */
4594 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4595
4596 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004597 case CFG80211_STA_MESH_PEER_KERNEL:
4598 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004599 /*
4600 * No ignoring the TDLS flag here -- the userspace mesh
4601 * code doesn't have the bug of including TDLS in the
4602 * mask everywhere.
4603 */
4604 if (params->sta_flags_mask &
4605 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4606 BIT(NL80211_STA_FLAG_MFP) |
4607 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4608 return -EINVAL;
4609 break;
4610 case CFG80211_STA_TDLS_PEER_SETUP:
4611 case CFG80211_STA_TDLS_PEER_ACTIVE:
4612 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4613 return -EINVAL;
4614 /* ignore since it can't change */
4615 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4616 break;
4617 default:
4618 /* disallow mesh-specific things */
4619 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4620 return -EINVAL;
4621 if (params->local_pm)
4622 return -EINVAL;
4623 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4624 return -EINVAL;
4625 }
4626
4627 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4628 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4629 /* TDLS can't be set, ... */
4630 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4631 return -EINVAL;
4632 /*
4633 * ... but don't bother the driver with it. This works around
4634 * a hostapd/wpa_supplicant issue -- it always includes the
4635 * TLDS_PEER flag in the mask even for AP mode.
4636 */
4637 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4638 }
4639
Ayala Beker47edb112015-09-21 15:49:53 +03004640 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4641 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004642 /* reject other things that can't change */
4643 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4644 return -EINVAL;
4645 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4646 return -EINVAL;
4647 if (params->supported_rates)
4648 return -EINVAL;
4649 if (params->ext_capab || params->ht_capa || params->vht_capa)
4650 return -EINVAL;
4651 }
4652
Ayala Beker47edb112015-09-21 15:49:53 +03004653 if (statype != CFG80211_STA_AP_CLIENT &&
4654 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004655 if (params->vlan)
4656 return -EINVAL;
4657 }
4658
4659 switch (statype) {
4660 case CFG80211_STA_AP_MLME_CLIENT:
4661 /* Use this only for authorizing/unauthorizing a station */
4662 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4663 return -EOPNOTSUPP;
4664 break;
4665 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004666 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004667 /* accept only the listed bits */
4668 if (params->sta_flags_mask &
4669 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4670 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4671 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4672 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4673 BIT(NL80211_STA_FLAG_WME) |
4674 BIT(NL80211_STA_FLAG_MFP)))
4675 return -EINVAL;
4676
4677 /* but authenticated/associated only if driver handles it */
4678 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4679 params->sta_flags_mask &
4680 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4681 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4682 return -EINVAL;
4683 break;
4684 case CFG80211_STA_IBSS:
4685 case CFG80211_STA_AP_STA:
4686 /* reject any changes other than AUTHORIZED */
4687 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4688 return -EINVAL;
4689 break;
4690 case CFG80211_STA_TDLS_PEER_SETUP:
4691 /* reject any changes other than AUTHORIZED or WME */
4692 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4693 BIT(NL80211_STA_FLAG_WME)))
4694 return -EINVAL;
4695 /* force (at least) rates when authorizing */
4696 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4697 !params->supported_rates)
4698 return -EINVAL;
4699 break;
4700 case CFG80211_STA_TDLS_PEER_ACTIVE:
4701 /* reject any changes */
4702 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004703 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004704 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4705 return -EINVAL;
4706 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004707 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004708 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4709 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004710 return -EINVAL;
4711 break;
4712 }
4713
Beni Lev06f7c882016-07-19 19:28:56 +03004714 /*
4715 * Older kernel versions ignored this attribute entirely, so don't
4716 * reject attempts to update it but mark it as unused instead so the
4717 * driver won't look at the data.
4718 */
4719 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4720 statype != CFG80211_STA_TDLS_PEER_SETUP)
4721 params->opmode_notif_used = false;
4722
Johannes Berg77ee7c82013-02-15 00:48:33 +01004723 return 0;
4724}
4725EXPORT_SYMBOL(cfg80211_check_station_change);
4726
Johannes Berg5727ef12007-12-19 02:03:34 +01004727/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004728 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004729 */
Johannes Berg80b99892011-11-18 16:23:01 +01004730static struct net_device *get_vlan(struct genl_info *info,
4731 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004732{
Johannes Berg463d0182009-07-14 00:33:35 +02004733 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004734 struct net_device *v;
4735 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004736
Johannes Berg80b99892011-11-18 16:23:01 +01004737 if (!vlanattr)
4738 return NULL;
4739
4740 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4741 if (!v)
4742 return ERR_PTR(-ENODEV);
4743
4744 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4745 ret = -EINVAL;
4746 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004747 }
Johannes Berg80b99892011-11-18 16:23:01 +01004748
Johannes Berg77ee7c82013-02-15 00:48:33 +01004749 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4750 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4751 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4752 ret = -EINVAL;
4753 goto error;
4754 }
4755
Johannes Berg80b99892011-11-18 16:23:01 +01004756 if (!netif_running(v)) {
4757 ret = -ENETDOWN;
4758 goto error;
4759 }
4760
4761 return v;
4762 error:
4763 dev_put(v);
4764 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004765}
4766
Johannes Berg94e860f2014-01-20 23:58:15 +01004767static const struct nla_policy
4768nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004769 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4770 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4771};
4772
Johannes Bergff276692013-02-15 00:09:01 +01004773static int nl80211_parse_sta_wme(struct genl_info *info,
4774 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004775{
Jouni Malinendf881292013-02-14 21:10:54 +02004776 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4777 struct nlattr *nla;
4778 int err;
4779
Jouni Malinendf881292013-02-14 21:10:54 +02004780 /* parse WME attributes if present */
4781 if (!info->attrs[NL80211_ATTR_STA_WME])
4782 return 0;
4783
4784 nla = info->attrs[NL80211_ATTR_STA_WME];
4785 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004786 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004787 if (err)
4788 return err;
4789
4790 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4791 params->uapsd_queues = nla_get_u8(
4792 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4793 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4794 return -EINVAL;
4795
4796 if (tb[NL80211_STA_WME_MAX_SP])
4797 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4798
4799 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4800 return -EINVAL;
4801
4802 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4803
4804 return 0;
4805}
4806
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304807static int nl80211_parse_sta_channel_info(struct genl_info *info,
4808 struct station_parameters *params)
4809{
4810 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4811 params->supported_channels =
4812 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4813 params->supported_channels_len =
4814 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4815 /*
4816 * Need to include at least one (first channel, number of
4817 * channels) tuple for each subband, and must have proper
4818 * tuples for the rest of the data as well.
4819 */
4820 if (params->supported_channels_len < 2)
4821 return -EINVAL;
4822 if (params->supported_channels_len % 2)
4823 return -EINVAL;
4824 }
4825
4826 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4827 params->supported_oper_classes =
4828 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4829 params->supported_oper_classes_len =
4830 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4831 /*
4832 * The value of the Length field of the Supported Operating
4833 * Classes element is between 2 and 253.
4834 */
4835 if (params->supported_oper_classes_len < 2 ||
4836 params->supported_oper_classes_len > 253)
4837 return -EINVAL;
4838 }
4839 return 0;
4840}
4841
Johannes Bergff276692013-02-15 00:09:01 +01004842static int nl80211_set_station_tdls(struct genl_info *info,
4843 struct station_parameters *params)
4844{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304845 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004846 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004847 if (info->attrs[NL80211_ATTR_PEER_AID])
4848 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004849 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4850 params->ht_capa =
4851 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4852 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4853 params->vht_capa =
4854 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4855
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304856 err = nl80211_parse_sta_channel_info(info, params);
4857 if (err)
4858 return err;
4859
Johannes Bergff276692013-02-15 00:09:01 +01004860 return nl80211_parse_sta_wme(info, params);
4861}
4862
Johannes Berg5727ef12007-12-19 02:03:34 +01004863static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4864{
Johannes Berg4c476992010-10-04 21:36:35 +02004865 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004866 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004867 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004868 u8 *mac_addr;
4869 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004870
4871 memset(&params, 0, sizeof(params));
4872
Johannes Berg77ee7c82013-02-15 00:48:33 +01004873 if (!rdev->ops->change_station)
4874 return -EOPNOTSUPP;
4875
Ayala Bekere4208422015-10-23 11:20:06 +03004876 /*
4877 * AID and listen_interval properties can be set only for unassociated
4878 * station. Include these parameters here and will check them in
4879 * cfg80211_check_station_change().
4880 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004881 if (info->attrs[NL80211_ATTR_STA_AID])
4882 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004883
4884 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4885 params.listen_interval =
4886 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4887 else
4888 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004889
Ayala Beker17b94242016-03-17 15:41:38 +02004890 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4891 u8 tmp;
4892
4893 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4894 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4895 return -EINVAL;
4896
4897 params.support_p2p_ps = tmp;
4898 } else {
4899 params.support_p2p_ps = -1;
4900 }
4901
Johannes Berg5727ef12007-12-19 02:03:34 +01004902 if (!info->attrs[NL80211_ATTR_MAC])
4903 return -EINVAL;
4904
4905 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4906
4907 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4908 params.supported_rates =
4909 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4910 params.supported_rates_len =
4911 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4912 }
4913
Jouni Malinen9d62a982013-02-14 21:10:13 +02004914 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4915 params.capability =
4916 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4917 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4918 }
4919
4920 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4921 params.ext_capab =
4922 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4923 params.ext_capab_len =
4924 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4925 }
4926
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004927 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004928 return -EINVAL;
4929
Johannes Bergf8bacc22013-02-14 23:27:01 +01004930 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004931 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004932 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4933 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4934 return -EINVAL;
4935 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004936
Johannes Bergf8bacc22013-02-14 23:27:01 +01004937 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004938 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004939 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4940 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4941 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004942 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4943 params.peer_aid = nla_get_u16(
4944 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4945 if (params.peer_aid > IEEE80211_MAX_AID)
4946 return -EINVAL;
4947 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004948 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4949 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004950
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004951 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4952 enum nl80211_mesh_power_mode pm = nla_get_u32(
4953 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4954
4955 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4956 pm > NL80211_MESH_POWER_MAX)
4957 return -EINVAL;
4958
4959 params.local_pm = pm;
4960 }
4961
Beni Lev06f7c882016-07-19 19:28:56 +03004962 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4963 params.opmode_notif_used = true;
4964 params.opmode_notif =
4965 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4966 }
4967
Johannes Berg77ee7c82013-02-15 00:48:33 +01004968 /* Include parameters for TDLS peer (will check later) */
4969 err = nl80211_set_station_tdls(info, &params);
4970 if (err)
4971 return err;
4972
4973 params.vlan = get_vlan(info, rdev);
4974 if (IS_ERR(params.vlan))
4975 return PTR_ERR(params.vlan);
4976
Johannes Berga97f4422009-06-18 17:23:43 +02004977 switch (dev->ieee80211_ptr->iftype) {
4978 case NL80211_IFTYPE_AP:
4979 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004980 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004981 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004982 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004983 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004984 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004985 break;
4986 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004987 err = -EOPNOTSUPP;
4988 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004989 }
4990
Johannes Berg77ee7c82013-02-15 00:48:33 +01004991 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004992 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004993
Johannes Berg77ee7c82013-02-15 00:48:33 +01004994 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004995 if (params.vlan)
4996 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004997
Johannes Berg5727ef12007-12-19 02:03:34 +01004998 return err;
4999}
5000
5001static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5002{
Johannes Berg4c476992010-10-04 21:36:35 +02005003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005004 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005005 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005006 struct station_parameters params;
5007 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005008 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5009 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005010
5011 memset(&params, 0, sizeof(params));
5012
Johannes Berg984c3112013-02-14 23:43:25 +01005013 if (!rdev->ops->add_station)
5014 return -EOPNOTSUPP;
5015
Johannes Berg5727ef12007-12-19 02:03:34 +01005016 if (!info->attrs[NL80211_ATTR_MAC])
5017 return -EINVAL;
5018
Johannes Berg5727ef12007-12-19 02:03:34 +01005019 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5020 return -EINVAL;
5021
5022 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5023 return -EINVAL;
5024
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005025 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5026 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005027 return -EINVAL;
5028
Johannes Berg5727ef12007-12-19 02:03:34 +01005029 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5030 params.supported_rates =
5031 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5032 params.supported_rates_len =
5033 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5034 params.listen_interval =
5035 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005036
Ayala Beker17b94242016-03-17 15:41:38 +02005037 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5038 u8 tmp;
5039
5040 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5041 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5042 return -EINVAL;
5043
5044 params.support_p2p_ps = tmp;
5045 } else {
5046 /*
5047 * if not specified, assume it's supported for P2P GO interface,
5048 * and is NOT supported for AP interface
5049 */
5050 params.support_p2p_ps =
5051 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5052 }
5053
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005054 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005055 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005056 else
5057 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005058 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5059 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005060
Jouni Malinen9d62a982013-02-14 21:10:13 +02005061 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5062 params.capability =
5063 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5064 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5065 }
5066
5067 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5068 params.ext_capab =
5069 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5070 params.ext_capab_len =
5071 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5072 }
5073
Jouni Malinen36aedc92008-08-25 11:58:58 +03005074 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5075 params.ht_capa =
5076 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005077
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005078 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5079 params.vht_capa =
5080 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5081
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005082 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5083 params.opmode_notif_used = true;
5084 params.opmode_notif =
5085 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5086 }
5087
Johannes Bergf8bacc22013-02-14 23:27:01 +01005088 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005089 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005090 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5091 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5092 return -EINVAL;
5093 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005094
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305095 err = nl80211_parse_sta_channel_info(info, &params);
5096 if (err)
5097 return err;
5098
Johannes Bergff276692013-02-15 00:09:01 +01005099 err = nl80211_parse_sta_wme(info, &params);
5100 if (err)
5101 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005102
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005103 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005104 return -EINVAL;
5105
Johannes Berg496fcc22015-03-12 08:53:27 +02005106 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5107 * as userspace might just pass through the capabilities from the IEs
5108 * directly, rather than enforcing this restriction and returning an
5109 * error in this case.
5110 */
5111 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5112 params.ht_capa = NULL;
5113 params.vht_capa = NULL;
5114 }
5115
Johannes Berg77ee7c82013-02-15 00:48:33 +01005116 /* When you run into this, adjust the code below for the new flag */
5117 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5118
Johannes Bergbdd90d52011-12-14 12:20:27 +01005119 switch (dev->ieee80211_ptr->iftype) {
5120 case NL80211_IFTYPE_AP:
5121 case NL80211_IFTYPE_AP_VLAN:
5122 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005123 /* ignore WME attributes if iface/sta is not capable */
5124 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5125 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5126 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005127
Johannes Bergbdd90d52011-12-14 12:20:27 +01005128 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005129 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5130 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005131 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005132 /* but don't bother the driver with it */
5133 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005134
Johannes Bergd582cff2012-10-26 17:53:44 +02005135 /* allow authenticated/associated only if driver handles it */
5136 if (!(rdev->wiphy.features &
5137 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005138 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005139 return -EINVAL;
5140
Johannes Bergbda95eb2015-11-26 16:26:13 +01005141 /* Older userspace, or userspace wanting to be compatible with
5142 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5143 * and assoc flags in the mask, but assumes the station will be
5144 * added as associated anyway since this was the required driver
5145 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5146 * introduced.
5147 * In order to not bother drivers with this quirk in the API
5148 * set the flags in both the mask and set for new stations in
5149 * this case.
5150 */
5151 if (!(params.sta_flags_mask & auth_assoc)) {
5152 params.sta_flags_mask |= auth_assoc;
5153 params.sta_flags_set |= auth_assoc;
5154 }
5155
Johannes Bergbdd90d52011-12-14 12:20:27 +01005156 /* must be last in here for error handling */
5157 params.vlan = get_vlan(info, rdev);
5158 if (IS_ERR(params.vlan))
5159 return PTR_ERR(params.vlan);
5160 break;
5161 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005162 /* ignore uAPSD data */
5163 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5164
Johannes Bergd582cff2012-10-26 17:53:44 +02005165 /* associated is disallowed */
5166 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5167 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005168 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005169 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5170 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005171 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005172 break;
5173 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005174 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005175 /* ignore uAPSD data */
5176 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5177
Johannes Berg77ee7c82013-02-15 00:48:33 +01005178 /* these are disallowed */
5179 if (params.sta_flags_mask &
5180 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5181 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005182 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005183 /* Only TDLS peers can be added */
5184 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5185 return -EINVAL;
5186 /* Can only add if TDLS ... */
5187 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5188 return -EOPNOTSUPP;
5189 /* ... with external setup is supported */
5190 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5191 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005192 /*
5193 * Older wpa_supplicant versions always mark the TDLS peer
5194 * as authorized, but it shouldn't yet be.
5195 */
5196 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005197 break;
5198 default:
5199 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005200 }
5201
Johannes Bergbdd90d52011-12-14 12:20:27 +01005202 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005203
Hila Gonene35e4d22012-06-27 17:19:42 +03005204 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005205
Johannes Berg5727ef12007-12-19 02:03:34 +01005206 if (params.vlan)
5207 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005208 return err;
5209}
5210
5211static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5212{
Johannes Berg4c476992010-10-04 21:36:35 +02005213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5214 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005215 struct station_del_parameters params;
5216
5217 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005218
5219 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005220 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005221
Johannes Berge80cf852009-05-11 14:43:13 +02005222 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005223 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005224 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005225 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5226 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005227
Johannes Berg4c476992010-10-04 21:36:35 +02005228 if (!rdev->ops->del_station)
5229 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005230
Jouni Malinen98856862014-10-20 13:20:45 +03005231 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5232 params.subtype =
5233 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5234 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5235 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5236 return -EINVAL;
5237 } else {
5238 /* Default to Deauthentication frame */
5239 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5240 }
5241
5242 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5243 params.reason_code =
5244 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5245 if (params.reason_code == 0)
5246 return -EINVAL; /* 0 is reserved */
5247 } else {
5248 /* Default to reason code 2 */
5249 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5250 }
5251
Jouni Malinen89c771e2014-10-10 20:52:40 +03005252 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005253}
5254
Eric W. Biederman15e47302012-09-07 20:12:54 +00005255static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005256 int flags, struct net_device *dev,
5257 u8 *dst, u8 *next_hop,
5258 struct mpath_info *pinfo)
5259{
5260 void *hdr;
5261 struct nlattr *pinfoattr;
5262
Henning Rogge1ef4c852014-11-04 16:14:58 +01005263 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005264 if (!hdr)
5265 return -1;
5266
David S. Miller9360ffd2012-03-29 04:41:26 -04005267 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5268 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5269 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5270 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5271 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005272
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005273 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5274 if (!pinfoattr)
5275 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005276 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5277 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5278 pinfo->frame_qlen))
5279 goto nla_put_failure;
5280 if (((pinfo->filled & MPATH_INFO_SN) &&
5281 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5282 ((pinfo->filled & MPATH_INFO_METRIC) &&
5283 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5284 pinfo->metric)) ||
5285 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5286 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5287 pinfo->exptime)) ||
5288 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5289 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5290 pinfo->flags)) ||
5291 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5292 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5293 pinfo->discovery_timeout)) ||
5294 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5295 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5296 pinfo->discovery_retries)))
5297 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005298
5299 nla_nest_end(msg, pinfoattr);
5300
Johannes Berg053c0952015-01-16 22:09:00 +01005301 genlmsg_end(msg, hdr);
5302 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005303
5304 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005305 genlmsg_cancel(msg, hdr);
5306 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005307}
5308
5309static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005310 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005311{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005312 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005313 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005314 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005315 u8 dst[ETH_ALEN];
5316 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005317 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005318 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005319
Johannes Bergea90e0d2017-03-15 14:26:04 +01005320 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005321 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005322 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005323 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005324
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005325 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005326 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005327 goto out_err;
5328 }
5329
Johannes Berg97990a02013-04-19 01:02:55 +02005330 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005331 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005332 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005333 }
5334
Johannes Bergbba95fe2008-07-29 13:22:51 +02005335 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005336 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005337 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005338 if (err == -ENOENT)
5339 break;
5340 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005341 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005342
Eric W. Biederman15e47302012-09-07 20:12:54 +00005343 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005344 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005345 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005346 &pinfo) < 0)
5347 goto out;
5348
5349 path_idx++;
5350 }
5351
Johannes Bergbba95fe2008-07-29 13:22:51 +02005352 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005353 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005354 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005355 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005356 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005357 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005358}
5359
5360static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5361{
Johannes Berg4c476992010-10-04 21:36:35 +02005362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005363 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005364 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005365 struct mpath_info pinfo;
5366 struct sk_buff *msg;
5367 u8 *dst = NULL;
5368 u8 next_hop[ETH_ALEN];
5369
5370 memset(&pinfo, 0, sizeof(pinfo));
5371
5372 if (!info->attrs[NL80211_ATTR_MAC])
5373 return -EINVAL;
5374
5375 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5376
Johannes Berg4c476992010-10-04 21:36:35 +02005377 if (!rdev->ops->get_mpath)
5378 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005379
Johannes Berg4c476992010-10-04 21:36:35 +02005380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5381 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005382
Hila Gonene35e4d22012-06-27 17:19:42 +03005383 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005384 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005385 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005386
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005387 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005388 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005389 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005390
Eric W. Biederman15e47302012-09-07 20:12:54 +00005391 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005392 dev, dst, next_hop, &pinfo) < 0) {
5393 nlmsg_free(msg);
5394 return -ENOBUFS;
5395 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005396
Johannes Berg4c476992010-10-04 21:36:35 +02005397 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005398}
5399
5400static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5401{
Johannes Berg4c476992010-10-04 21:36:35 +02005402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5403 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005404 u8 *dst = NULL;
5405 u8 *next_hop = NULL;
5406
5407 if (!info->attrs[NL80211_ATTR_MAC])
5408 return -EINVAL;
5409
5410 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5411 return -EINVAL;
5412
5413 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5414 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5415
Johannes Berg4c476992010-10-04 21:36:35 +02005416 if (!rdev->ops->change_mpath)
5417 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005418
Johannes Berg4c476992010-10-04 21:36:35 +02005419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5420 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005421
Hila Gonene35e4d22012-06-27 17:19:42 +03005422 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005423}
Johannes Berg4c476992010-10-04 21:36:35 +02005424
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005425static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5426{
Johannes Berg4c476992010-10-04 21:36:35 +02005427 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5428 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005429 u8 *dst = NULL;
5430 u8 *next_hop = NULL;
5431
5432 if (!info->attrs[NL80211_ATTR_MAC])
5433 return -EINVAL;
5434
5435 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5436 return -EINVAL;
5437
5438 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5439 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5440
Johannes Berg4c476992010-10-04 21:36:35 +02005441 if (!rdev->ops->add_mpath)
5442 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005443
Johannes Berg4c476992010-10-04 21:36:35 +02005444 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5445 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005446
Hila Gonene35e4d22012-06-27 17:19:42 +03005447 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005448}
5449
5450static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5451{
Johannes Berg4c476992010-10-04 21:36:35 +02005452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5453 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005454 u8 *dst = NULL;
5455
5456 if (info->attrs[NL80211_ATTR_MAC])
5457 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5458
Johannes Berg4c476992010-10-04 21:36:35 +02005459 if (!rdev->ops->del_mpath)
5460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005461
Hila Gonene35e4d22012-06-27 17:19:42 +03005462 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005463}
5464
Henning Rogge66be7d22014-09-12 08:58:49 +02005465static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5466{
5467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5468 int err;
5469 struct net_device *dev = info->user_ptr[1];
5470 struct mpath_info pinfo;
5471 struct sk_buff *msg;
5472 u8 *dst = NULL;
5473 u8 mpp[ETH_ALEN];
5474
5475 memset(&pinfo, 0, sizeof(pinfo));
5476
5477 if (!info->attrs[NL80211_ATTR_MAC])
5478 return -EINVAL;
5479
5480 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5481
5482 if (!rdev->ops->get_mpp)
5483 return -EOPNOTSUPP;
5484
5485 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5486 return -EOPNOTSUPP;
5487
5488 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5489 if (err)
5490 return err;
5491
5492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5493 if (!msg)
5494 return -ENOMEM;
5495
5496 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5497 dev, dst, mpp, &pinfo) < 0) {
5498 nlmsg_free(msg);
5499 return -ENOBUFS;
5500 }
5501
5502 return genlmsg_reply(msg, info);
5503}
5504
5505static int nl80211_dump_mpp(struct sk_buff *skb,
5506 struct netlink_callback *cb)
5507{
5508 struct mpath_info pinfo;
5509 struct cfg80211_registered_device *rdev;
5510 struct wireless_dev *wdev;
5511 u8 dst[ETH_ALEN];
5512 u8 mpp[ETH_ALEN];
5513 int path_idx = cb->args[2];
5514 int err;
5515
Johannes Bergea90e0d2017-03-15 14:26:04 +01005516 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005517 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5518 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005519 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005520
5521 if (!rdev->ops->dump_mpp) {
5522 err = -EOPNOTSUPP;
5523 goto out_err;
5524 }
5525
5526 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5527 err = -EOPNOTSUPP;
5528 goto out_err;
5529 }
5530
5531 while (1) {
5532 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5533 mpp, &pinfo);
5534 if (err == -ENOENT)
5535 break;
5536 if (err)
5537 goto out_err;
5538
5539 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5540 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5541 wdev->netdev, dst, mpp,
5542 &pinfo) < 0)
5543 goto out;
5544
5545 path_idx++;
5546 }
5547
5548 out:
5549 cb->args[2] = path_idx;
5550 err = skb->len;
5551 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005552 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005553 return err;
5554}
5555
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005556static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5557{
Johannes Berg4c476992010-10-04 21:36:35 +02005558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5559 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005560 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005561 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005562 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005563
5564 memset(&params, 0, sizeof(params));
5565 /* default to not changing parameters */
5566 params.use_cts_prot = -1;
5567 params.use_short_preamble = -1;
5568 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005569 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005570 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005571 params.p2p_ctwindow = -1;
5572 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005573
5574 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5575 params.use_cts_prot =
5576 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5577 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5578 params.use_short_preamble =
5579 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5580 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5581 params.use_short_slot_time =
5582 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005583 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5584 params.basic_rates =
5585 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5586 params.basic_rates_len =
5587 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5588 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005589 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5590 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005591 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5592 params.ht_opmode =
5593 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005594
Johannes Berg53cabad2012-11-14 15:17:28 +01005595 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5596 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5597 return -EINVAL;
5598 params.p2p_ctwindow =
5599 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5600 if (params.p2p_ctwindow < 0)
5601 return -EINVAL;
5602 if (params.p2p_ctwindow != 0 &&
5603 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5604 return -EINVAL;
5605 }
5606
5607 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5608 u8 tmp;
5609
5610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5611 return -EINVAL;
5612 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5613 if (tmp > 1)
5614 return -EINVAL;
5615 params.p2p_opp_ps = tmp;
5616 if (params.p2p_opp_ps &&
5617 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5618 return -EINVAL;
5619 }
5620
Johannes Berg4c476992010-10-04 21:36:35 +02005621 if (!rdev->ops->change_bss)
5622 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005623
Johannes Berg074ac8d2010-09-16 14:58:22 +02005624 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005625 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5626 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005627
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005628 wdev_lock(wdev);
5629 err = rdev_change_bss(rdev, dev, &params);
5630 wdev_unlock(wdev);
5631
5632 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005633}
5634
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005635static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5636{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005637 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005638 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005639 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005640 u32 owner_nlportid;
5641
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005642 /*
5643 * You should only get this when cfg80211 hasn't yet initialized
5644 * completely when built-in to the kernel right between the time
5645 * window between nl80211_init() and regulatory_init(), if that is
5646 * even possible.
5647 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005648 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005649 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005650
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005651 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5652 user_reg_hint_type =
5653 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5654 else
5655 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5656
5657 switch (user_reg_hint_type) {
5658 case NL80211_USER_REG_HINT_USER:
5659 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005660 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5661 return -EINVAL;
5662
5663 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5664 return regulatory_hint_user(data, user_reg_hint_type);
5665 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005666 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5667 owner_nlportid = info->snd_portid;
5668 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5669 } else {
5670 owner_nlportid = 0;
5671 is_indoor = true;
5672 }
5673
5674 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005675 default:
5676 return -EINVAL;
5677 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005678}
5679
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005680static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005681 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005682{
Johannes Berg4c476992010-10-04 21:36:35 +02005683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005684 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005685 struct wireless_dev *wdev = dev->ieee80211_ptr;
5686 struct mesh_config cur_params;
5687 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005688 void *hdr;
5689 struct nlattr *pinfoattr;
5690 struct sk_buff *msg;
5691
Johannes Berg29cbe682010-12-03 09:20:44 +01005692 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5693 return -EOPNOTSUPP;
5694
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005695 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005696 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005697
Johannes Berg29cbe682010-12-03 09:20:44 +01005698 wdev_lock(wdev);
5699 /* If not connected, get default parameters */
5700 if (!wdev->mesh_id_len)
5701 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5702 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005703 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005704 wdev_unlock(wdev);
5705
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005706 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005707 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005708
5709 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005711 if (!msg)
5712 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005713 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005714 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005715 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005716 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005717 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005718 if (!pinfoattr)
5719 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005720 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5721 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5722 cur_params.dot11MeshRetryTimeout) ||
5723 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5724 cur_params.dot11MeshConfirmTimeout) ||
5725 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5726 cur_params.dot11MeshHoldingTimeout) ||
5727 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5728 cur_params.dot11MeshMaxPeerLinks) ||
5729 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5730 cur_params.dot11MeshMaxRetries) ||
5731 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5732 cur_params.dot11MeshTTL) ||
5733 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5734 cur_params.element_ttl) ||
5735 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5736 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005737 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5738 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005739 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5740 cur_params.dot11MeshHWMPmaxPREQretries) ||
5741 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5742 cur_params.path_refresh_time) ||
5743 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5744 cur_params.min_discovery_timeout) ||
5745 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5746 cur_params.dot11MeshHWMPactivePathTimeout) ||
5747 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5748 cur_params.dot11MeshHWMPpreqMinInterval) ||
5749 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5750 cur_params.dot11MeshHWMPperrMinInterval) ||
5751 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5752 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5753 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5754 cur_params.dot11MeshHWMPRootMode) ||
5755 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5756 cur_params.dot11MeshHWMPRannInterval) ||
5757 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5758 cur_params.dot11MeshGateAnnouncementProtocol) ||
5759 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5760 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005761 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005762 cur_params.rssi_threshold) ||
5763 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005764 cur_params.ht_opmode) ||
5765 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5766 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5767 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005768 cur_params.dot11MeshHWMProotInterval) ||
5769 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005770 cur_params.dot11MeshHWMPconfirmationInterval) ||
5771 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5772 cur_params.power_mode) ||
5773 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005774 cur_params.dot11MeshAwakeWindowDuration) ||
5775 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5776 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005777 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005778 nla_nest_end(msg, pinfoattr);
5779 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005780 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005781
Johannes Berg3b858752009-03-12 09:55:09 +01005782 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005783 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005784 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005785 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005786 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005787}
5788
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005789static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005790 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5791 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5792 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5793 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5794 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5795 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005796 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005797 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005798 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005799 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5800 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5801 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5802 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5803 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005804 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005806 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005807 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005808 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005809 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005810 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5811 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005812 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5813 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005814 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005815 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5816 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005817 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005818};
5819
Javier Cardonac80d5452010-12-16 17:37:49 -08005820static const struct nla_policy
5821 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005822 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005823 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5824 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005825 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005826 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005827 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005828 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005829 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005830 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005831};
5832
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005833static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5834{
5835 u8 val = nla_get_u8(nla);
5836 if (val < min || val > max)
5837 return -EINVAL;
5838 *out = val;
5839 return 0;
5840}
5841
5842static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5843{
5844 u8 val = nla_get_u8(nla);
5845 if (val < min || val > max)
5846 return -EINVAL;
5847 *out = val;
5848 return 0;
5849}
5850
5851static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5852{
5853 u16 val = nla_get_u16(nla);
5854 if (val < min || val > max)
5855 return -EINVAL;
5856 *out = val;
5857 return 0;
5858}
5859
5860static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5861{
5862 u32 val = nla_get_u32(nla);
5863 if (val < min || val > max)
5864 return -EINVAL;
5865 *out = val;
5866 return 0;
5867}
5868
5869static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5870{
5871 s32 val = nla_get_s32(nla);
5872 if (val < min || val > max)
5873 return -EINVAL;
5874 *out = val;
5875 return 0;
5876}
5877
Johannes Bergff9a71a2016-08-11 14:59:53 +02005878static int nl80211_check_power_mode(const struct nlattr *nla,
5879 enum nl80211_mesh_power_mode min,
5880 enum nl80211_mesh_power_mode max,
5881 enum nl80211_mesh_power_mode *out)
5882{
5883 u32 val = nla_get_u32(nla);
5884 if (val < min || val > max)
5885 return -EINVAL;
5886 *out = val;
5887 return 0;
5888}
5889
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005890static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005891 struct mesh_config *cfg,
5892 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005893{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005894 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005895 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005896 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005897
Marco Porschea54fba2013-01-07 16:04:48 +01005898#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5899do { \
5900 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005901 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005902 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005903 mask |= (1 << (attr - 1)); \
5904 } \
5905} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005906
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005907 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005908 return -EINVAL;
5909 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005910 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005911 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005912 return -EINVAL;
5913
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005914 /* This makes sure that there aren't more than 32 mesh config
5915 * parameters (otherwise our bitfield scheme would not work.) */
5916 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5917
5918 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005919 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005920 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005921 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005922 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005923 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005924 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005925 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005926 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005927 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005929 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005930 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005932 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005933 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005935 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005937 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005938 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005940 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005941 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5943 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005944 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005945 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005947 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005948 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005950 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005951 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005952 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005953 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005954 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005955 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5956 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005957 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005958 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005960 1, 65535, mask,
5961 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005962 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005963 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005964 1, 65535, mask,
5965 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005966 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005968 dot11MeshHWMPnetDiameterTraversalTime,
5969 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005970 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005971 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5973 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005974 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005975 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5976 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005977 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005978 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005979 dot11MeshGateAnnouncementProtocol, 0, 1,
5980 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005981 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005983 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005984 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005986 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005987 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005988 /*
5989 * Check HT operation mode based on
5990 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5991 */
5992 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5993 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5994
5995 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5996 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5997 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5998 return -EINVAL;
5999
6000 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6001 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6002 return -EINVAL;
6003
6004 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6005 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6006 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6007 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6008 return -EINVAL;
6009 break;
6010 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6011 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6012 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6013 return -EINVAL;
6014 break;
6015 }
6016 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006017 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006018 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006019 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006020 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006021 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006022 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006024 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006025 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006026 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006027 dot11MeshHWMPconfirmationInterval,
6028 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006029 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006030 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006031 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6032 NL80211_MESH_POWER_ACTIVE,
6033 NL80211_MESH_POWER_MAX,
6034 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006035 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6037 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006038 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006039 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006040 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006041 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006042 if (mask_out)
6043 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006044
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006045 return 0;
6046
6047#undef FILL_IN_MESH_PARAM_IF_SET
6048}
6049
Javier Cardonac80d5452010-12-16 17:37:49 -08006050static int nl80211_parse_mesh_setup(struct genl_info *info,
6051 struct mesh_setup *setup)
6052{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006054 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6055
6056 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6057 return -EINVAL;
6058 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6059 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006060 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006061 return -EINVAL;
6062
Javier Cardonad299a1f2012-03-31 11:31:33 -07006063 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6064 setup->sync_method =
6065 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6066 IEEE80211_SYNC_METHOD_VENDOR :
6067 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6068
Javier Cardonac80d5452010-12-16 17:37:49 -08006069 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6070 setup->path_sel_proto =
6071 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6072 IEEE80211_PATH_PROTOCOL_VENDOR :
6073 IEEE80211_PATH_PROTOCOL_HWMP;
6074
6075 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6076 setup->path_metric =
6077 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6078 IEEE80211_PATH_METRIC_VENDOR :
6079 IEEE80211_PATH_METRIC_AIRTIME;
6080
Javier Cardona581a8b02011-04-07 15:08:27 -07006081 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006082 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006083 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006084 if (!is_valid_ie_attr(ieattr))
6085 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006086 setup->ie = nla_data(ieattr);
6087 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006088 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006089 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6090 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6091 return -EINVAL;
6092 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006093 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6094 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006095 if (setup->is_secure)
6096 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006097
Colleen Twitty6e16d902013-05-08 11:45:59 -07006098 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6099 if (!setup->user_mpm)
6100 return -EINVAL;
6101 setup->auth_id =
6102 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6103 }
6104
Javier Cardonac80d5452010-12-16 17:37:49 -08006105 return 0;
6106}
6107
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006108static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006109 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006110{
6111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6112 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006113 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006114 struct mesh_config cfg;
6115 u32 mask;
6116 int err;
6117
Johannes Berg29cbe682010-12-03 09:20:44 +01006118 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6119 return -EOPNOTSUPP;
6120
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006121 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006122 return -EOPNOTSUPP;
6123
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006124 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006125 if (err)
6126 return err;
6127
Johannes Berg29cbe682010-12-03 09:20:44 +01006128 wdev_lock(wdev);
6129 if (!wdev->mesh_id_len)
6130 err = -ENOLINK;
6131
6132 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006133 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006134
6135 wdev_unlock(wdev);
6136
6137 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006138}
6139
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006140static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6141 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006142{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006143 struct nlattr *nl_reg_rules;
6144 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006145
Johannes Berg458f4f92012-12-06 15:47:38 +01006146 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6147 (regdom->dfs_region &&
6148 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006149 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006150
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006151 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6152 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006153 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006154
Johannes Berg458f4f92012-12-06 15:47:38 +01006155 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006156 struct nlattr *nl_reg_rule;
6157 const struct ieee80211_reg_rule *reg_rule;
6158 const struct ieee80211_freq_range *freq_range;
6159 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006160 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006161
Johannes Berg458f4f92012-12-06 15:47:38 +01006162 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006163 freq_range = &reg_rule->freq_range;
6164 power_rule = &reg_rule->power_rule;
6165
6166 nl_reg_rule = nla_nest_start(msg, i);
6167 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006168 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006169
Janusz Dziedzic97524822014-01-30 09:52:20 +01006170 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6171 if (!max_bandwidth_khz)
6172 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6173 reg_rule);
6174
David S. Miller9360ffd2012-03-29 04:41:26 -04006175 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6176 reg_rule->flags) ||
6177 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6178 freq_range->start_freq_khz) ||
6179 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6180 freq_range->end_freq_khz) ||
6181 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006182 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006183 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6184 power_rule->max_antenna_gain) ||
6185 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006186 power_rule->max_eirp) ||
6187 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6188 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006189 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006190
6191 nla_nest_end(msg, nl_reg_rule);
6192 }
6193
6194 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006195 return 0;
6196
6197nla_put_failure:
6198 return -EMSGSIZE;
6199}
6200
6201static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6202{
6203 const struct ieee80211_regdomain *regdom = NULL;
6204 struct cfg80211_registered_device *rdev;
6205 struct wiphy *wiphy = NULL;
6206 struct sk_buff *msg;
6207 void *hdr;
6208
6209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6210 if (!msg)
6211 return -ENOBUFS;
6212
6213 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6214 NL80211_CMD_GET_REG);
6215 if (!hdr)
6216 goto put_failure;
6217
6218 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006219 bool self_managed;
6220
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006221 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6222 if (IS_ERR(rdev)) {
6223 nlmsg_free(msg);
6224 return PTR_ERR(rdev);
6225 }
6226
6227 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006228 self_managed = wiphy->regulatory_flags &
6229 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006230 regdom = get_wiphy_regdom(wiphy);
6231
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006232 /* a self-managed-reg device must have a private regdom */
6233 if (WARN_ON(!regdom && self_managed)) {
6234 nlmsg_free(msg);
6235 return -EINVAL;
6236 }
6237
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006238 if (regdom &&
6239 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6240 goto nla_put_failure;
6241 }
6242
6243 if (!wiphy && reg_last_request_cell_base() &&
6244 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6245 NL80211_USER_REG_HINT_CELL_BASE))
6246 goto nla_put_failure;
6247
6248 rcu_read_lock();
6249
6250 if (!regdom)
6251 regdom = rcu_dereference(cfg80211_regdomain);
6252
6253 if (nl80211_put_regdom(regdom, msg))
6254 goto nla_put_failure_rcu;
6255
6256 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006257
6258 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006259 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006260
Johannes Berg458f4f92012-12-06 15:47:38 +01006261nla_put_failure_rcu:
6262 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006263nla_put_failure:
6264 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006265put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006266 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006267 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006268}
6269
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006270static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6271 u32 seq, int flags, struct wiphy *wiphy,
6272 const struct ieee80211_regdomain *regdom)
6273{
6274 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6275 NL80211_CMD_GET_REG);
6276
6277 if (!hdr)
6278 return -1;
6279
6280 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6281
6282 if (nl80211_put_regdom(regdom, msg))
6283 goto nla_put_failure;
6284
6285 if (!wiphy && reg_last_request_cell_base() &&
6286 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6287 NL80211_USER_REG_HINT_CELL_BASE))
6288 goto nla_put_failure;
6289
6290 if (wiphy &&
6291 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6292 goto nla_put_failure;
6293
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006294 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6295 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6296 goto nla_put_failure;
6297
Johannes Berg053c0952015-01-16 22:09:00 +01006298 genlmsg_end(msg, hdr);
6299 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006300
6301nla_put_failure:
6302 genlmsg_cancel(msg, hdr);
6303 return -EMSGSIZE;
6304}
6305
6306static int nl80211_get_reg_dump(struct sk_buff *skb,
6307 struct netlink_callback *cb)
6308{
6309 const struct ieee80211_regdomain *regdom = NULL;
6310 struct cfg80211_registered_device *rdev;
6311 int err, reg_idx, start = cb->args[2];
6312
6313 rtnl_lock();
6314
6315 if (cfg80211_regdomain && start == 0) {
6316 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6317 NLM_F_MULTI, NULL,
6318 rtnl_dereference(cfg80211_regdomain));
6319 if (err < 0)
6320 goto out_err;
6321 }
6322
6323 /* the global regdom is idx 0 */
6324 reg_idx = 1;
6325 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6326 regdom = get_wiphy_regdom(&rdev->wiphy);
6327 if (!regdom)
6328 continue;
6329
6330 if (++reg_idx <= start)
6331 continue;
6332
6333 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6334 NLM_F_MULTI, &rdev->wiphy, regdom);
6335 if (err < 0) {
6336 reg_idx--;
6337 break;
6338 }
6339 }
6340
6341 cb->args[2] = reg_idx;
6342 err = skb->len;
6343out_err:
6344 rtnl_unlock();
6345 return err;
6346}
6347
Johannes Bergb6863032015-10-15 09:25:18 +02006348#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6349static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6350 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6351 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6352 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6353 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6354 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6355 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6356 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6357};
6358
6359static int parse_reg_rule(struct nlattr *tb[],
6360 struct ieee80211_reg_rule *reg_rule)
6361{
6362 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6363 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6364
6365 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6366 return -EINVAL;
6367 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6368 return -EINVAL;
6369 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6370 return -EINVAL;
6371 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6372 return -EINVAL;
6373 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6374 return -EINVAL;
6375
6376 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6377
6378 freq_range->start_freq_khz =
6379 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6380 freq_range->end_freq_khz =
6381 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6382 freq_range->max_bandwidth_khz =
6383 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6384
6385 power_rule->max_eirp =
6386 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6387
6388 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6389 power_rule->max_antenna_gain =
6390 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6391
6392 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6393 reg_rule->dfs_cac_ms =
6394 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6395
6396 return 0;
6397}
6398
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006399static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6400{
6401 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6402 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006403 char *alpha2;
6404 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006405 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006406 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006407 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006408
6409 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6410 return -EINVAL;
6411
6412 if (!info->attrs[NL80211_ATTR_REG_RULES])
6413 return -EINVAL;
6414
6415 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6416
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006417 if (info->attrs[NL80211_ATTR_DFS_REGION])
6418 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6419
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006420 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006421 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006422 num_rules++;
6423 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006424 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006425 }
6426
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006427 if (!reg_is_valid_request(alpha2))
6428 return -EINVAL;
6429
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006430 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006431 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006432
6433 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006434 if (!rd)
6435 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006436
6437 rd->n_reg_rules = num_rules;
6438 rd->alpha2[0] = alpha2[0];
6439 rd->alpha2[1] = alpha2[1];
6440
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006441 /*
6442 * Disable DFS master mode if the DFS region was
6443 * not supported or known on this kernel.
6444 */
6445 if (reg_supported_dfs_region(dfs_region))
6446 rd->dfs_region = dfs_region;
6447
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006448 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006449 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006450 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006451 nl_reg_rule, reg_rule_policy,
6452 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006453 if (r)
6454 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006455 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6456 if (r)
6457 goto bad_reg;
6458
6459 rule_idx++;
6460
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006461 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6462 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006463 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006464 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006465 }
6466
Johannes Berg06627992016-06-09 10:40:09 +02006467 /* set_regdom takes ownership of rd */
6468 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006469 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006470 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006471 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006472}
Johannes Bergb6863032015-10-15 09:25:18 +02006473#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006474
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006475static int validate_scan_freqs(struct nlattr *freqs)
6476{
6477 struct nlattr *attr1, *attr2;
6478 int n_channels = 0, tmp1, tmp2;
6479
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006480 nla_for_each_nested(attr1, freqs, tmp1)
6481 if (nla_len(attr1) != sizeof(u32))
6482 return 0;
6483
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006484 nla_for_each_nested(attr1, freqs, tmp1) {
6485 n_channels++;
6486 /*
6487 * Some hardware has a limited channel list for
6488 * scanning, and it is pretty much nonsensical
6489 * to scan for a channel twice, so disallow that
6490 * and don't require drivers to check that the
6491 * channel list they get isn't longer than what
6492 * they can scan, as long as they can scan all
6493 * the channels they registered at once.
6494 */
6495 nla_for_each_nested(attr2, freqs, tmp2)
6496 if (attr1 != attr2 &&
6497 nla_get_u32(attr1) == nla_get_u32(attr2))
6498 return 0;
6499 }
6500
6501 return n_channels;
6502}
6503
Johannes Berg57fbcce2016-04-12 15:56:15 +02006504static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006505{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006506 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006507}
6508
6509static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6510 struct cfg80211_bss_selection *bss_select)
6511{
6512 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6513 struct nlattr *nest;
6514 int err;
6515 bool found = false;
6516 int i;
6517
6518 /* only process one nested attribute */
6519 nest = nla_data(nla);
6520 if (!nla_ok(nest, nla_len(nest)))
6521 return -EINVAL;
6522
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006523 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006524 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006525 if (err)
6526 return err;
6527
6528 /* only one attribute may be given */
6529 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6530 if (attr[i]) {
6531 if (found)
6532 return -EINVAL;
6533 found = true;
6534 }
6535 }
6536
6537 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6538
6539 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6540 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6541
6542 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6543 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6544 bss_select->param.band_pref =
6545 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6546 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6547 return -EINVAL;
6548 }
6549
6550 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6551 struct nl80211_bss_select_rssi_adjust *adj_param;
6552
6553 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6554 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6555 bss_select->param.adjust.band = adj_param->band;
6556 bss_select->param.adjust.delta = adj_param->delta;
6557 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6558 return -EINVAL;
6559 }
6560
6561 /* user-space did not provide behaviour attribute */
6562 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6563 return -EINVAL;
6564
6565 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6566 return -EINVAL;
6567
6568 return 0;
6569}
6570
Johannes Bergad2b26a2014-06-12 21:39:05 +02006571static int nl80211_parse_random_mac(struct nlattr **attrs,
6572 u8 *mac_addr, u8 *mac_addr_mask)
6573{
6574 int i;
6575
6576 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006577 eth_zero_addr(mac_addr);
6578 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006579 mac_addr[0] = 0x2;
6580 mac_addr_mask[0] = 0x3;
6581
6582 return 0;
6583 }
6584
6585 /* need both or none */
6586 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6587 return -EINVAL;
6588
6589 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6590 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6591
6592 /* don't allow or configure an mcast address */
6593 if (!is_multicast_ether_addr(mac_addr_mask) ||
6594 is_multicast_ether_addr(mac_addr))
6595 return -EINVAL;
6596
6597 /*
6598 * allow users to pass a MAC address that has bits set outside
6599 * of the mask, but don't bother drivers with having to deal
6600 * with such bits
6601 */
6602 for (i = 0; i < ETH_ALEN; i++)
6603 mac_addr[i] &= mac_addr_mask[i];
6604
6605 return 0;
6606}
6607
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306608static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6609{
6610 ASSERT_WDEV_LOCK(wdev);
6611
6612 if (!cfg80211_beaconing_iface_active(wdev))
6613 return true;
6614
6615 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6616 return true;
6617
6618 return regulatory_pre_cac_allowed(wdev->wiphy);
6619}
6620
Johannes Berg2a519312009-02-10 21:25:55 +01006621static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6622{
Johannes Berg4c476992010-10-04 21:36:35 +02006623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006624 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006625 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006626 struct nlattr *attr;
6627 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006628 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006629 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006630
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006631 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6632 return -EINVAL;
6633
Johannes Berg79c97e92009-07-07 03:56:12 +02006634 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006635
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006636 if (wdev->iftype == NL80211_IFTYPE_NAN)
6637 return -EOPNOTSUPP;
6638
Johannes Berg4c476992010-10-04 21:36:35 +02006639 if (!rdev->ops->scan)
6640 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006641
Johannes Bergf9d15d12014-01-22 11:14:19 +02006642 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006643 err = -EBUSY;
6644 goto unlock;
6645 }
Johannes Berg2a519312009-02-10 21:25:55 +01006646
6647 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006648 n_channels = validate_scan_freqs(
6649 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006650 if (!n_channels) {
6651 err = -EINVAL;
6652 goto unlock;
6653 }
Johannes Berg2a519312009-02-10 21:25:55 +01006654 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006655 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006656 }
6657
6658 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6659 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6660 n_ssids++;
6661
Johannes Bergf9f47522013-03-19 15:04:07 +01006662 if (n_ssids > wiphy->max_scan_ssids) {
6663 err = -EINVAL;
6664 goto unlock;
6665 }
Johannes Berg2a519312009-02-10 21:25:55 +01006666
Jouni Malinen70692ad2009-02-16 19:39:13 +02006667 if (info->attrs[NL80211_ATTR_IE])
6668 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6669 else
6670 ie_len = 0;
6671
Johannes Bergf9f47522013-03-19 15:04:07 +01006672 if (ie_len > wiphy->max_scan_ie_len) {
6673 err = -EINVAL;
6674 goto unlock;
6675 }
Johannes Berg18a83652009-03-31 12:12:05 +02006676
Johannes Berg2a519312009-02-10 21:25:55 +01006677 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006678 + sizeof(*request->ssids) * n_ssids
6679 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006680 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006681 if (!request) {
6682 err = -ENOMEM;
6683 goto unlock;
6684 }
Johannes Berg2a519312009-02-10 21:25:55 +01006685
Johannes Berg2a519312009-02-10 21:25:55 +01006686 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006687 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006688 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006689 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006690 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006691 request->ie = (void *)(request->ssids + n_ssids);
6692 else
6693 request->ie = (void *)(request->channels + n_channels);
6694 }
Johannes Berg2a519312009-02-10 21:25:55 +01006695
Johannes Berg584991d2009-11-02 13:32:03 +01006696 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006697 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6698 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006699 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006700 struct ieee80211_channel *chan;
6701
6702 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6703
6704 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006705 err = -EINVAL;
6706 goto out_free;
6707 }
Johannes Berg584991d2009-11-02 13:32:03 +01006708
6709 /* ignore disabled channels */
6710 if (chan->flags & IEEE80211_CHAN_DISABLED)
6711 continue;
6712
6713 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006714 i++;
6715 }
6716 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006717 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006718
Johannes Berg2a519312009-02-10 21:25:55 +01006719 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006720 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006721 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006722
Johannes Berg2a519312009-02-10 21:25:55 +01006723 if (!wiphy->bands[band])
6724 continue;
6725 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006726 struct ieee80211_channel *chan;
6727
6728 chan = &wiphy->bands[band]->channels[j];
6729
6730 if (chan->flags & IEEE80211_CHAN_DISABLED)
6731 continue;
6732
6733 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006734 i++;
6735 }
6736 }
6737 }
6738
Johannes Berg584991d2009-11-02 13:32:03 +01006739 if (!i) {
6740 err = -EINVAL;
6741 goto out_free;
6742 }
6743
6744 request->n_channels = i;
6745
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306746 wdev_lock(wdev);
6747 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6748 struct ieee80211_channel *chan;
6749
6750 if (request->n_channels != 1) {
6751 wdev_unlock(wdev);
6752 err = -EBUSY;
6753 goto out_free;
6754 }
6755
6756 chan = request->channels[0];
6757 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6758 wdev_unlock(wdev);
6759 err = -EBUSY;
6760 goto out_free;
6761 }
6762 }
6763 wdev_unlock(wdev);
6764
Johannes Berg2a519312009-02-10 21:25:55 +01006765 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006766 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006767 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006768 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006769 err = -EINVAL;
6770 goto out_free;
6771 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006772 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006773 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006774 i++;
6775 }
6776 }
6777
Jouni Malinen70692ad2009-02-16 19:39:13 +02006778 if (info->attrs[NL80211_ATTR_IE]) {
6779 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006780 memcpy((void *)request->ie,
6781 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006782 request->ie_len);
6783 }
6784
Johannes Berg57fbcce2016-04-12 15:56:15 +02006785 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006786 if (wiphy->bands[i])
6787 request->rates[i] =
6788 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006789
6790 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6791 nla_for_each_nested(attr,
6792 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6793 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006794 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006795
Johannes Berg57fbcce2016-04-12 15:56:15 +02006796 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006797 err = -EINVAL;
6798 goto out_free;
6799 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006800
6801 if (!wiphy->bands[band])
6802 continue;
6803
Johannes Berg34850ab2011-07-18 18:08:35 +02006804 err = ieee80211_get_ratemask(wiphy->bands[band],
6805 nla_data(attr),
6806 nla_len(attr),
6807 &request->rates[band]);
6808 if (err)
6809 goto out_free;
6810 }
6811 }
6812
Avraham Stern1d762502016-07-05 17:10:13 +03006813 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6814 if (!wiphy_ext_feature_isset(wiphy,
6815 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6816 err = -EOPNOTSUPP;
6817 goto out_free;
6818 }
6819
6820 request->duration =
6821 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6822 request->duration_mandatory =
6823 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6824 }
6825
Sam Leffler46856bb2012-10-11 21:03:32 -07006826 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006827 request->flags = nla_get_u32(
6828 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006829 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6830 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006831 err = -EOPNOTSUPP;
6832 goto out_free;
6833 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006834
6835 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6836 if (!(wiphy->features &
6837 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6838 err = -EOPNOTSUPP;
6839 goto out_free;
6840 }
6841
6842 if (wdev->current_bss) {
6843 err = -EOPNOTSUPP;
6844 goto out_free;
6845 }
6846
6847 err = nl80211_parse_random_mac(info->attrs,
6848 request->mac_addr,
6849 request->mac_addr_mask);
6850 if (err)
6851 goto out_free;
6852 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006853 }
Sam Lefflered4737712012-10-11 21:03:31 -07006854
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306855 request->no_cck =
6856 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6857
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006858 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6859 * BSSID to scan for. This was problematic because that same attribute
6860 * was already used for another purpose (local random MAC address). The
6861 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6862 * compatibility with older userspace components, also use the
6863 * NL80211_ATTR_MAC value here if it can be determined to be used for
6864 * the specific BSSID use case instead of the random MAC address
6865 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6866 */
6867 if (info->attrs[NL80211_ATTR_BSSID])
6868 memcpy(request->bssid,
6869 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6870 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6871 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006872 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6873 ETH_ALEN);
6874 else
6875 eth_broadcast_addr(request->bssid);
6876
Johannes Bergfd014282012-06-18 19:17:03 +02006877 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006878 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006879 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006880
Johannes Berg79c97e92009-07-07 03:56:12 +02006881 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006882 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006883
Johannes Berg463d0182009-07-14 00:33:35 +02006884 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006885 nl80211_send_scan_start(rdev, wdev);
6886 if (wdev->netdev)
6887 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006888 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006889 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006890 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006891 kfree(request);
6892 }
Johannes Berg3b858752009-03-12 09:55:09 +01006893
Johannes Bergf9f47522013-03-19 15:04:07 +01006894 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006895 return err;
6896}
6897
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306898static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6899{
6900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6901 struct wireless_dev *wdev = info->user_ptr[1];
6902
6903 if (!rdev->ops->abort_scan)
6904 return -EOPNOTSUPP;
6905
6906 if (rdev->scan_msg)
6907 return 0;
6908
6909 if (!rdev->scan_req)
6910 return -ENOENT;
6911
6912 rdev_abort_scan(rdev, wdev);
6913 return 0;
6914}
6915
Avraham Stern3b06d272015-10-12 09:51:34 +03006916static int
6917nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6918 struct cfg80211_sched_scan_request *request,
6919 struct nlattr **attrs)
6920{
6921 int tmp, err, i = 0;
6922 struct nlattr *attr;
6923
6924 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6925 u32 interval;
6926
6927 /*
6928 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006929 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006930 * case one scan plan will be set with the specified scan
6931 * interval and infinite number of iterations.
6932 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006933 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6934 if (!interval)
6935 return -EINVAL;
6936
6937 request->scan_plans[0].interval =
6938 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6939 if (!request->scan_plans[0].interval)
6940 return -EINVAL;
6941
6942 if (request->scan_plans[0].interval >
6943 wiphy->max_sched_scan_plan_interval)
6944 request->scan_plans[0].interval =
6945 wiphy->max_sched_scan_plan_interval;
6946
6947 return 0;
6948 }
6949
6950 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6951 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6952
6953 if (WARN_ON(i >= n_plans))
6954 return -EINVAL;
6955
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006956 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02006957 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03006958 if (err)
6959 return err;
6960
6961 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6962 return -EINVAL;
6963
6964 request->scan_plans[i].interval =
6965 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6966 if (!request->scan_plans[i].interval ||
6967 request->scan_plans[i].interval >
6968 wiphy->max_sched_scan_plan_interval)
6969 return -EINVAL;
6970
6971 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6972 request->scan_plans[i].iterations =
6973 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6974 if (!request->scan_plans[i].iterations ||
6975 (request->scan_plans[i].iterations >
6976 wiphy->max_sched_scan_plan_iterations))
6977 return -EINVAL;
6978 } else if (i < n_plans - 1) {
6979 /*
6980 * All scan plans but the last one must specify
6981 * a finite number of iterations
6982 */
6983 return -EINVAL;
6984 }
6985
6986 i++;
6987 }
6988
6989 /*
6990 * The last scan plan must not specify the number of
6991 * iterations, it is supposed to run infinitely
6992 */
6993 if (request->scan_plans[n_plans - 1].iterations)
6994 return -EINVAL;
6995
6996 return 0;
6997}
6998
Luciano Coelho256da022014-11-10 16:13:46 +02006999static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007000nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007001 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007002{
7003 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007004 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007005 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007006 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007007 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007008 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007009 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007010
Luciano Coelho256da022014-11-10 16:13:46 +02007011 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7012 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007013
Luciano Coelho256da022014-11-10 16:13:46 +02007014 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007015 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007016 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007017 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007018 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007019 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007020 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007021 }
7022
Luciano Coelho256da022014-11-10 16:13:46 +02007023 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7024 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007025 tmp)
7026 n_ssids++;
7027
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007028 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007029 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007030
Johannes Bergea73cbc2014-01-24 10:53:53 +01007031 /*
7032 * First, count the number of 'real' matchsets. Due to an issue with
7033 * the old implementation, matchsets containing only the RSSI attribute
7034 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7035 * RSSI for all matchsets, rather than their own matchset for reporting
7036 * all APs with a strong RSSI. This is needed to be compatible with
7037 * older userspace that treated a matchset with only the RSSI as the
7038 * global RSSI for all other matchsets - if there are other matchsets.
7039 */
Luciano Coelho256da022014-11-10 16:13:46 +02007040 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007041 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007042 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007043 tmp) {
7044 struct nlattr *rssi;
7045
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007046 err = nla_parse_nested(tb,
7047 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007048 attr, nl80211_match_policy,
7049 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007050 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007051 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007052
7053 /* SSID and BSSID are mutually exclusive */
7054 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7055 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7056 return ERR_PTR(-EINVAL);
7057
Johannes Bergea73cbc2014-01-24 10:53:53 +01007058 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007059 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7060 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007061 n_match_sets++;
7062 continue;
7063 }
7064 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7065 if (rssi)
7066 default_match_rssi = nla_get_s32(rssi);
7067 }
7068 }
7069
7070 /* However, if there's no other matchset, add the RSSI one */
7071 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7072 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007073
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007074 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007075 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007076
Luciano Coelho256da022014-11-10 16:13:46 +02007077 if (attrs[NL80211_ATTR_IE])
7078 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007079 else
7080 ie_len = 0;
7081
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007082 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007083 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007084
Avraham Stern3b06d272015-10-12 09:51:34 +03007085 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7086 /*
7087 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7088 * each scan plan already specifies its own interval
7089 */
7090 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7091 return ERR_PTR(-EINVAL);
7092
7093 nla_for_each_nested(attr,
7094 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7095 n_plans++;
7096 } else {
7097 /*
7098 * The scan interval attribute is kept for backward
7099 * compatibility. If no scan plans are specified and sched scan
7100 * interval is specified, one scan plan will be set with this
7101 * scan interval and infinite number of iterations.
7102 */
7103 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7104 return ERR_PTR(-EINVAL);
7105
7106 n_plans = 1;
7107 }
7108
7109 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7110 return ERR_PTR(-EINVAL);
7111
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007112 if (!wiphy_ext_feature_isset(
7113 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7114 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7115 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7116 return ERR_PTR(-EINVAL);
7117
Luciano Coelho807f8a82011-05-11 17:09:35 +03007118 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007119 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007120 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007121 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007122 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007123 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007124 if (!request)
7125 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007126
7127 if (n_ssids)
7128 request->ssids = (void *)&request->channels[n_channels];
7129 request->n_ssids = n_ssids;
7130 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007131 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007132 request->ie = (void *)(request->ssids + n_ssids);
7133 else
7134 request->ie = (void *)(request->channels + n_channels);
7135 }
7136
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007137 if (n_match_sets) {
7138 if (request->ie)
7139 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007140 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007141 request->match_sets =
7142 (void *)(request->ssids + n_ssids);
7143 else
7144 request->match_sets =
7145 (void *)(request->channels + n_channels);
7146 }
7147 request->n_match_sets = n_match_sets;
7148
Avraham Stern3b06d272015-10-12 09:51:34 +03007149 if (n_match_sets)
7150 request->scan_plans = (void *)(request->match_sets +
7151 n_match_sets);
7152 else if (request->ie)
7153 request->scan_plans = (void *)(request->ie + ie_len);
7154 else if (n_ssids)
7155 request->scan_plans = (void *)(request->ssids + n_ssids);
7156 else
7157 request->scan_plans = (void *)(request->channels + n_channels);
7158
7159 request->n_scan_plans = n_plans;
7160
Luciano Coelho807f8a82011-05-11 17:09:35 +03007161 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007162 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007163 /* user specified, bail out if channel not found */
7164 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007165 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007166 tmp) {
7167 struct ieee80211_channel *chan;
7168
7169 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7170
7171 if (!chan) {
7172 err = -EINVAL;
7173 goto out_free;
7174 }
7175
7176 /* ignore disabled channels */
7177 if (chan->flags & IEEE80211_CHAN_DISABLED)
7178 continue;
7179
7180 request->channels[i] = chan;
7181 i++;
7182 }
7183 } else {
7184 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007185 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007186 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007187
Luciano Coelho807f8a82011-05-11 17:09:35 +03007188 if (!wiphy->bands[band])
7189 continue;
7190 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7191 struct ieee80211_channel *chan;
7192
7193 chan = &wiphy->bands[band]->channels[j];
7194
7195 if (chan->flags & IEEE80211_CHAN_DISABLED)
7196 continue;
7197
7198 request->channels[i] = chan;
7199 i++;
7200 }
7201 }
7202 }
7203
7204 if (!i) {
7205 err = -EINVAL;
7206 goto out_free;
7207 }
7208
7209 request->n_channels = i;
7210
7211 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007212 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007213 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007214 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007215 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007216 err = -EINVAL;
7217 goto out_free;
7218 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007219 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007220 memcpy(request->ssids[i].ssid, nla_data(attr),
7221 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007222 i++;
7223 }
7224 }
7225
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007226 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007227 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007228 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007229 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007230 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007231 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007232
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007233 err = nla_parse_nested(tb,
7234 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007235 attr, nl80211_match_policy,
7236 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007237 if (err)
7238 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007239 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007240 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7241 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007242 if (WARN_ON(i >= n_match_sets)) {
7243 /* this indicates a programming error,
7244 * the loop above should have verified
7245 * things properly
7246 */
7247 err = -EINVAL;
7248 goto out_free;
7249 }
7250
Arend Van Spriel3007e352017-04-21 13:05:01 +01007251 if (ssid) {
7252 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7253 err = -EINVAL;
7254 goto out_free;
7255 }
7256 memcpy(request->match_sets[i].ssid.ssid,
7257 nla_data(ssid), nla_len(ssid));
7258 request->match_sets[i].ssid.ssid_len =
7259 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007260 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007261 if (bssid) {
7262 if (nla_len(bssid) != ETH_ALEN) {
7263 err = -EINVAL;
7264 goto out_free;
7265 }
7266 memcpy(request->match_sets[i].bssid,
7267 nla_data(bssid), ETH_ALEN);
7268 }
7269
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007270 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007271 request->match_sets[i].rssi_thold =
7272 default_match_rssi;
7273 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7274 if (rssi)
7275 request->match_sets[i].rssi_thold =
7276 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007277 }
7278 i++;
7279 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007280
7281 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007282 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007283 request->match_sets[0].rssi_thold = default_match_rssi;
7284
7285 request->min_rssi_thold = INT_MAX;
7286 for (i = 0; i < n_match_sets; i++)
7287 request->min_rssi_thold =
7288 min(request->match_sets[i].rssi_thold,
7289 request->min_rssi_thold);
7290 } else {
7291 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007292 }
7293
Johannes Berg9900e482014-02-04 21:01:25 +01007294 if (ie_len) {
7295 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007296 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007297 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007298 request->ie_len);
7299 }
7300
Luciano Coelho256da022014-11-10 16:13:46 +02007301 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007302 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007303 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007304 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7305 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007306 err = -EOPNOTSUPP;
7307 goto out_free;
7308 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007309
7310 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7311 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7312
7313 if (!wdev) /* must be net-detect */
7314 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7315
7316 if (!(wiphy->features & flg)) {
7317 err = -EOPNOTSUPP;
7318 goto out_free;
7319 }
7320
7321 if (wdev && wdev->current_bss) {
7322 err = -EOPNOTSUPP;
7323 goto out_free;
7324 }
7325
7326 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7327 request->mac_addr_mask);
7328 if (err)
7329 goto out_free;
7330 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007331 }
Sam Lefflered4737712012-10-11 21:03:31 -07007332
Luciano Coelho9c748932015-01-16 16:04:09 +02007333 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7334 request->delay =
7335 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7336
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007337 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7338 request->relative_rssi = nla_get_s8(
7339 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7340 request->relative_rssi_set = true;
7341 }
7342
7343 if (request->relative_rssi_set &&
7344 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7345 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7346
7347 rssi_adjust = nla_data(
7348 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7349 request->rssi_adjust.band = rssi_adjust->band;
7350 request->rssi_adjust.delta = rssi_adjust->delta;
7351 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7352 err = -EINVAL;
7353 goto out_free;
7354 }
7355 }
7356
Avraham Stern3b06d272015-10-12 09:51:34 +03007357 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7358 if (err)
7359 goto out_free;
7360
Sam Leffler15d60302012-10-11 21:03:34 -07007361 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007362
Luciano Coelho256da022014-11-10 16:13:46 +02007363 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007364
7365out_free:
7366 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007367 return ERR_PTR(err);
7368}
7369
7370static int nl80211_start_sched_scan(struct sk_buff *skb,
7371 struct genl_info *info)
7372{
7373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7374 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007375 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007376 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007377 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007378 int err;
7379
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007380 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007381 return -EOPNOTSUPP;
7382
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007383 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7384 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7385 if (err)
7386 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007387
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007388 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007389 info->attrs,
7390 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007391
7392 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007393 if (err)
7394 goto out_err;
7395
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007396 /* leave request id zero for legacy request
7397 * or if driver does not support multi-scheduled scan
7398 */
7399 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7400 while (!sched_scan_req->reqid)
7401 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7402 }
7403
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007404 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007405 if (err)
7406 goto out_free;
7407
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007408 sched_scan_req->dev = dev;
7409 sched_scan_req->wiphy = &rdev->wiphy;
7410
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007411 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7412 sched_scan_req->owner_nlportid = info->snd_portid;
7413
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007414 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007415
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007416 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007417 return 0;
7418
7419out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007420 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007421out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007422 return err;
7423}
7424
7425static int nl80211_stop_sched_scan(struct sk_buff *skb,
7426 struct genl_info *info)
7427{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007428 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007430 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007431
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007432 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007433 return -EOPNOTSUPP;
7434
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007435 if (info->attrs[NL80211_ATTR_COOKIE]) {
7436 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7437 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7438 }
7439
7440 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7441 struct cfg80211_sched_scan_request,
7442 list);
7443 if (!req || req->reqid ||
7444 (req->owner_nlportid &&
7445 req->owner_nlportid != info->snd_portid))
7446 return -ENOENT;
7447
7448 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007449}
7450
Simon Wunderlich04f39042013-02-08 18:16:19 +01007451static int nl80211_start_radar_detection(struct sk_buff *skb,
7452 struct genl_info *info)
7453{
7454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7455 struct net_device *dev = info->user_ptr[1];
7456 struct wireless_dev *wdev = dev->ieee80211_ptr;
7457 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007458 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007459 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007460 int err;
7461
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007462 dfs_region = reg_get_dfs_region(wdev->wiphy);
7463 if (dfs_region == NL80211_DFS_UNSET)
7464 return -EINVAL;
7465
Simon Wunderlich04f39042013-02-08 18:16:19 +01007466 err = nl80211_parse_chandef(rdev, info, &chandef);
7467 if (err)
7468 return err;
7469
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007470 if (netif_carrier_ok(dev))
7471 return -EBUSY;
7472
Simon Wunderlich04f39042013-02-08 18:16:19 +01007473 if (wdev->cac_started)
7474 return -EBUSY;
7475
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007476 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007477 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007478 if (err < 0)
7479 return err;
7480
7481 if (err == 0)
7482 return -EINVAL;
7483
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007484 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007485 return -EINVAL;
7486
7487 if (!rdev->ops->start_radar_detection)
7488 return -EOPNOTSUPP;
7489
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007490 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7491 if (WARN_ON(!cac_time_ms))
7492 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7493
Ilan Peera1056b1b2015-10-22 22:27:46 +03007494 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007495 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007496 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007497 wdev->cac_started = true;
7498 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007499 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007500 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007501 return err;
7502}
7503
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007504static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7505{
7506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7507 struct net_device *dev = info->user_ptr[1];
7508 struct wireless_dev *wdev = dev->ieee80211_ptr;
7509 struct cfg80211_csa_settings params;
7510 /* csa_attrs is defined static to avoid waste of stack size - this
7511 * function is called under RTNL lock, so this should not be a problem.
7512 */
7513 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007514 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007515 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007516 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007517 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007518 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007519
7520 if (!rdev->ops->channel_switch ||
7521 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7522 return -EOPNOTSUPP;
7523
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007524 switch (dev->ieee80211_ptr->iftype) {
7525 case NL80211_IFTYPE_AP:
7526 case NL80211_IFTYPE_P2P_GO:
7527 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007528 /* For all modes except AP the handle_dfs flag needs to be
7529 * supplied to tell the kernel that userspace will handle radar
7530 * events when they happen. Otherwise a switch to a channel
7531 * requiring DFS will be rejected.
7532 */
7533 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007534
7535 /* useless if AP is not running */
7536 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007537 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007538 break;
7539 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007540 if (!wdev->ssid_len)
7541 return -ENOTCONN;
7542 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007543 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007544 if (!wdev->mesh_id_len)
7545 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007546 break;
7547 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007548 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007549 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007550
7551 memset(&params, 0, sizeof(params));
7552
7553 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7554 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7555 return -EINVAL;
7556
7557 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007558 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007559 return -EINVAL;
7560
Luciano Coelho252e07c2014-10-08 09:48:34 +03007561 /* Even though the attribute is u32, the specification says
7562 * u8, so let's make sure we don't overflow.
7563 */
7564 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7565 if (cs_count > 255)
7566 return -EINVAL;
7567
7568 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007569
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007570 if (!need_new_beacon)
7571 goto skip_beacons;
7572
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007573 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7574 if (err)
7575 return err;
7576
7577 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7578 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007579 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007580 if (err)
7581 return err;
7582
7583 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7584 if (err)
7585 return err;
7586
7587 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7588 return -EINVAL;
7589
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007590 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7591 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007592 return -EINVAL;
7593
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007594 params.n_counter_offsets_beacon = len / sizeof(u16);
7595 if (rdev->wiphy.max_num_csa_counters &&
7596 (params.n_counter_offsets_beacon >
7597 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007598 return -EINVAL;
7599
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007600 params.counter_offsets_beacon =
7601 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7602
7603 /* sanity checks - counters should fit and be the same */
7604 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7605 u16 offset = params.counter_offsets_beacon[i];
7606
7607 if (offset >= params.beacon_csa.tail_len)
7608 return -EINVAL;
7609
7610 if (params.beacon_csa.tail[offset] != params.count)
7611 return -EINVAL;
7612 }
7613
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007614 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007615 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7616 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007617 return -EINVAL;
7618
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007619 params.n_counter_offsets_presp = len / sizeof(u16);
7620 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007621 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007622 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007623 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007624
7625 params.counter_offsets_presp =
7626 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7627
7628 /* sanity checks - counters should fit and be the same */
7629 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7630 u16 offset = params.counter_offsets_presp[i];
7631
7632 if (offset >= params.beacon_csa.probe_resp_len)
7633 return -EINVAL;
7634
7635 if (params.beacon_csa.probe_resp[offset] !=
7636 params.count)
7637 return -EINVAL;
7638 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007639 }
7640
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007641skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007642 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7643 if (err)
7644 return err;
7645
Arik Nemtsov923b3522015-07-08 15:41:44 +03007646 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7647 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007648 return -EINVAL;
7649
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007650 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7651 &params.chandef,
7652 wdev->iftype);
7653 if (err < 0)
7654 return err;
7655
Benjamin Berg8d9de162017-05-16 11:23:12 +02007656 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007657 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007658 if (need_handle_dfs_flag &&
7659 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7660 return -EINVAL;
7661 }
7662 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007663
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007664 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7665 params.block_tx = true;
7666
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007667 wdev_lock(wdev);
7668 err = rdev_channel_switch(rdev, dev, &params);
7669 wdev_unlock(wdev);
7670
7671 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007672}
7673
Johannes Berg9720bb32011-06-21 09:45:33 +02007674static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7675 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007676 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007677 struct wireless_dev *wdev,
7678 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007679{
Johannes Berg48ab9052009-07-10 18:42:31 +02007680 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007681 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007682 void *hdr;
7683 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007684
7685 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007686
Eric W. Biederman15e47302012-09-07 20:12:54 +00007687 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007688 NL80211_CMD_NEW_SCAN_RESULTS);
7689 if (!hdr)
7690 return -1;
7691
Johannes Berg9720bb32011-06-21 09:45:33 +02007692 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7693
Johannes Berg97990a02013-04-19 01:02:55 +02007694 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7695 goto nla_put_failure;
7696 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7698 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007699 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7700 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007701 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007702
7703 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7704 if (!bss)
7705 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007706 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007707 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007708 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007709
7710 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007711 /* indicate whether we have probe response data or not */
7712 if (rcu_access_pointer(res->proberesp_ies) &&
7713 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7714 goto fail_unlock_rcu;
7715
7716 /* this pointer prefers to be pointed to probe response data
7717 * but is always valid
7718 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007719 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007720 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007721 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7722 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007723 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007724 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7725 ies->len, ies->data))
7726 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007727 }
Johannes Berg0e227082014-08-12 20:34:30 +02007728
7729 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007730 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007731 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007732 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7733 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007734 goto fail_unlock_rcu;
7735 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7736 ies->len, ies->data))
7737 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007738 }
7739 rcu_read_unlock();
7740
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 if (res->beacon_interval &&
7742 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7743 goto nla_put_failure;
7744 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7745 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007746 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007747 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7748 jiffies_to_msecs(jiffies - intbss->ts)))
7749 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007750
Avraham Stern1d762502016-07-05 17:10:13 +03007751 if (intbss->parent_tsf &&
7752 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7753 intbss->parent_tsf, NL80211_BSS_PAD) ||
7754 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7755 intbss->parent_bssid)))
7756 goto nla_put_failure;
7757
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007758 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007759 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7760 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007761 goto nla_put_failure;
7762
Johannes Berg77965c92009-02-18 18:45:06 +01007763 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007764 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007765 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7766 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007767 break;
7768 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007769 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7770 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007771 break;
7772 default:
7773 break;
7774 }
7775
Johannes Berg48ab9052009-07-10 18:42:31 +02007776 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007777 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007778 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007779 if (intbss == wdev->current_bss &&
7780 nla_put_u32(msg, NL80211_BSS_STATUS,
7781 NL80211_BSS_STATUS_ASSOCIATED))
7782 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007783 break;
7784 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007785 if (intbss == wdev->current_bss &&
7786 nla_put_u32(msg, NL80211_BSS_STATUS,
7787 NL80211_BSS_STATUS_IBSS_JOINED))
7788 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007789 break;
7790 default:
7791 break;
7792 }
7793
Johannes Berg2a519312009-02-10 21:25:55 +01007794 nla_nest_end(msg, bss);
7795
Johannes Berg053c0952015-01-16 22:09:00 +01007796 genlmsg_end(msg, hdr);
7797 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007798
Johannes Berg8cef2c92013-02-05 16:54:31 +01007799 fail_unlock_rcu:
7800 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007801 nla_put_failure:
7802 genlmsg_cancel(msg, hdr);
7803 return -EMSGSIZE;
7804}
7805
Johannes Berg97990a02013-04-19 01:02:55 +02007806static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007807{
Johannes Berg48ab9052009-07-10 18:42:31 +02007808 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007809 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007810 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007811 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007812 int err;
7813
Johannes Bergea90e0d2017-03-15 14:26:04 +01007814 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007815 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007816 if (err) {
7817 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007818 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007819 }
Johannes Berg2a519312009-02-10 21:25:55 +01007820
Johannes Berg48ab9052009-07-10 18:42:31 +02007821 wdev_lock(wdev);
7822 spin_lock_bh(&rdev->bss_lock);
7823 cfg80211_bss_expire(rdev);
7824
Johannes Berg9720bb32011-06-21 09:45:33 +02007825 cb->seq = rdev->bss_generation;
7826
Johannes Berg48ab9052009-07-10 18:42:31 +02007827 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007828 if (++idx <= start)
7829 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007830 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007831 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007832 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007833 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007834 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007835 }
7836 }
7837
Johannes Berg48ab9052009-07-10 18:42:31 +02007838 spin_unlock_bh(&rdev->bss_lock);
7839 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007840
Johannes Berg97990a02013-04-19 01:02:55 +02007841 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007842 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007843
Johannes Berg67748892010-10-04 21:14:06 +02007844 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007845}
7846
Eric W. Biederman15e47302012-09-07 20:12:54 +00007847static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007848 int flags, struct net_device *dev,
7849 bool allow_radio_stats,
7850 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007851{
7852 void *hdr;
7853 struct nlattr *infoattr;
7854
Johannes Berg11f78ac2014-11-14 16:43:50 +01007855 /* skip radio stats if userspace didn't request them */
7856 if (!survey->channel && !allow_radio_stats)
7857 return 0;
7858
Eric W. Biederman15e47302012-09-07 20:12:54 +00007859 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007860 NL80211_CMD_NEW_SURVEY_RESULTS);
7861 if (!hdr)
7862 return -ENOMEM;
7863
David S. Miller9360ffd2012-03-29 04:41:26 -04007864 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7865 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007866
7867 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7868 if (!infoattr)
7869 goto nla_put_failure;
7870
Johannes Berg11f78ac2014-11-14 16:43:50 +01007871 if (survey->channel &&
7872 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007873 survey->channel->center_freq))
7874 goto nla_put_failure;
7875
7876 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7877 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7878 goto nla_put_failure;
7879 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7880 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7881 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007882 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007883 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7884 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007885 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007886 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007887 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7888 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007889 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007890 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007891 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7892 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007893 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007894 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007895 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7896 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007897 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007898 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007899 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7900 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007901 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007902 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007903 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7904 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007905 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007906
7907 nla_nest_end(msg, infoattr);
7908
Johannes Berg053c0952015-01-16 22:09:00 +01007909 genlmsg_end(msg, hdr);
7910 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007911
7912 nla_put_failure:
7913 genlmsg_cancel(msg, hdr);
7914 return -EMSGSIZE;
7915}
7916
Johannes Berg11f78ac2014-11-14 16:43:50 +01007917static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007918{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007919 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007920 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007921 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007922 struct wireless_dev *wdev;
7923 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007924 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007925 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007926
Johannes Bergea90e0d2017-03-15 14:26:04 +01007927 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007928 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007929 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007930 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007931
Johannes Berg11f78ac2014-11-14 16:43:50 +01007932 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007933 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007934
Johannes Berg97990a02013-04-19 01:02:55 +02007935 if (!wdev->netdev) {
7936 res = -EINVAL;
7937 goto out_err;
7938 }
7939
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007940 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007941 res = -EOPNOTSUPP;
7942 goto out_err;
7943 }
7944
7945 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007946 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007947 if (res == -ENOENT)
7948 break;
7949 if (res)
7950 goto out_err;
7951
Johannes Berg11f78ac2014-11-14 16:43:50 +01007952 /* don't send disabled channels, but do send non-channel data */
7953 if (survey.channel &&
7954 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007955 survey_idx++;
7956 continue;
7957 }
7958
Holger Schurig61fa7132009-11-11 12:25:40 +01007959 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007960 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007961 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007962 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007963 goto out;
7964 survey_idx++;
7965 }
7966
7967 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007968 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007969 res = skb->len;
7970 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01007971 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007972 return res;
7973}
7974
Samuel Ortizb23aa672009-07-01 21:26:54 +02007975static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7976{
7977 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7978 NL80211_WPA_VERSION_2));
7979}
7980
Jouni Malinen636a5d32009-03-19 13:39:22 +02007981static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7982{
Johannes Berg4c476992010-10-04 21:36:35 +02007983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7984 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007985 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007986 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7987 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007988 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007989 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007990 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007991
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007992 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7993 return -EINVAL;
7994
7995 if (!info->attrs[NL80211_ATTR_MAC])
7996 return -EINVAL;
7997
Jouni Malinen17780922009-03-27 20:52:47 +02007998 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7999 return -EINVAL;
8000
Johannes Berg19957bb2009-07-02 17:20:43 +02008001 if (!info->attrs[NL80211_ATTR_SSID])
8002 return -EINVAL;
8003
8004 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8005 return -EINVAL;
8006
Johannes Bergfffd0932009-07-08 14:22:54 +02008007 err = nl80211_parse_key(info, &key);
8008 if (err)
8009 return err;
8010
8011 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008012 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8013 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008014 if (!key.p.key || !key.p.key_len)
8015 return -EINVAL;
8016 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8017 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8018 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8019 key.p.key_len != WLAN_KEY_LEN_WEP104))
8020 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008021 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008022 return -EINVAL;
8023 } else {
8024 key.p.key_len = 0;
8025 key.p.key = NULL;
8026 }
8027
Johannes Bergafea0b72010-08-10 09:46:42 +02008028 if (key.idx >= 0) {
8029 int i;
8030 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008031
Johannes Bergafea0b72010-08-10 09:46:42 +02008032 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8033 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8034 ok = true;
8035 break;
8036 }
8037 }
Johannes Berg4c476992010-10-04 21:36:35 +02008038 if (!ok)
8039 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008040 }
8041
Johannes Berg4c476992010-10-04 21:36:35 +02008042 if (!rdev->ops->auth)
8043 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008044
Johannes Berg074ac8d2010-09-16 14:58:22 +02008045 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008046 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8047 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008048
Johannes Berg19957bb2009-07-02 17:20:43 +02008049 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008050 chan = nl80211_get_valid_chan(&rdev->wiphy,
8051 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8052 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008053 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008054
Johannes Berg19957bb2009-07-02 17:20:43 +02008055 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8056 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8057
8058 if (info->attrs[NL80211_ATTR_IE]) {
8059 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8060 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8061 }
8062
8063 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008064 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008065 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008066
Jouni Malinen63181062016-10-27 00:42:02 +03008067 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8068 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8069 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8070 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008071 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008072 return -EINVAL;
8073
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008074 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008075 if (auth_type != NL80211_AUTHTYPE_SAE &&
8076 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8077 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8078 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008079 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008080 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8081 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008082 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008083 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008084 return -EINVAL;
8085 }
8086
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008087 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8088
Johannes Berg95de8172012-01-20 13:55:25 +01008089 /*
8090 * Since we no longer track auth state, ignore
8091 * requests to only change local state.
8092 */
8093 if (local_state_change)
8094 return 0;
8095
Johannes Berg91bf9b22013-05-15 17:44:01 +02008096 wdev_lock(dev->ieee80211_ptr);
8097 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8098 ssid, ssid_len, ie, ie_len,
8099 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008100 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008101 wdev_unlock(dev->ieee80211_ptr);
8102 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008103}
8104
Johannes Bergc0692b82010-08-27 14:26:53 +03008105static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8106 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008107 struct cfg80211_crypto_settings *settings,
8108 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008109{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008110 memset(settings, 0, sizeof(*settings));
8111
Samuel Ortizb23aa672009-07-01 21:26:54 +02008112 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8113
Johannes Bergc0692b82010-08-27 14:26:53 +03008114 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8115 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008116
Johannes Bergc0692b82010-08-27 14:26:53 +03008117 proto = nla_get_u16(
8118 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8119 settings->control_port_ethertype = cpu_to_be16(proto);
8120 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8121 proto != ETH_P_PAE)
8122 return -EINVAL;
8123 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8124 settings->control_port_no_encrypt = true;
8125 } else
8126 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8127
Samuel Ortizb23aa672009-07-01 21:26:54 +02008128 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8129 void *data;
8130 int len, i;
8131
8132 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8133 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8134 settings->n_ciphers_pairwise = len / sizeof(u32);
8135
8136 if (len % sizeof(u32))
8137 return -EINVAL;
8138
Johannes Berg3dc27d22009-07-02 21:36:37 +02008139 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008140 return -EINVAL;
8141
8142 memcpy(settings->ciphers_pairwise, data, len);
8143
8144 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008145 if (!cfg80211_supported_cipher_suite(
8146 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008147 settings->ciphers_pairwise[i]))
8148 return -EINVAL;
8149 }
8150
8151 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8152 settings->cipher_group =
8153 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008154 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8155 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008156 return -EINVAL;
8157 }
8158
8159 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8160 settings->wpa_versions =
8161 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8162 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8163 return -EINVAL;
8164 }
8165
8166 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8167 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008168 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008169
8170 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8171 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8172 settings->n_akm_suites = len / sizeof(u32);
8173
8174 if (len % sizeof(u32))
8175 return -EINVAL;
8176
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008177 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8178 return -EINVAL;
8179
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008181 }
8182
Eliad Peller91b5ab62017-06-09 13:08:42 +01008183 if (info->attrs[NL80211_ATTR_PMK]) {
8184 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8185 return -EINVAL;
8186 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8187 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8188 return -EINVAL;
8189 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8190 }
8191
Samuel Ortizb23aa672009-07-01 21:26:54 +02008192 return 0;
8193}
8194
Jouni Malinen636a5d32009-03-19 13:39:22 +02008195static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8196{
Johannes Berg4c476992010-10-04 21:36:35 +02008197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8198 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008199 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008200 struct cfg80211_assoc_request req = {};
8201 const u8 *bssid, *ssid;
8202 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008203
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008204 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8205 return -EINVAL;
8206
8207 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008208 !info->attrs[NL80211_ATTR_SSID] ||
8209 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008210 return -EINVAL;
8211
Johannes Berg4c476992010-10-04 21:36:35 +02008212 if (!rdev->ops->assoc)
8213 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008214
Johannes Berg074ac8d2010-09-16 14:58:22 +02008215 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008216 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8217 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008218
Johannes Berg19957bb2009-07-02 17:20:43 +02008219 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008220
Jouni Malinen664834d2014-01-15 00:01:44 +02008221 chan = nl80211_get_valid_chan(&rdev->wiphy,
8222 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8223 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008224 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008225
Johannes Berg19957bb2009-07-02 17:20:43 +02008226 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8227 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008228
8229 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008230 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8231 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008232 }
8233
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008234 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008235 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008236 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008237 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008238 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008239 else if (mfp != NL80211_MFP_NO)
8240 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008241 }
8242
Johannes Berg3e5d7642009-07-07 14:37:26 +02008243 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008244 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008245
Ben Greear7e7c8922011-11-18 11:31:59 -08008246 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008247 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008248
8249 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008250 memcpy(&req.ht_capa_mask,
8251 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8252 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008253
8254 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008255 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008256 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008257 memcpy(&req.ht_capa,
8258 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8259 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008260 }
8261
Johannes Bergee2aca32013-02-21 17:36:01 +01008262 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008263 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008264
8265 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008266 memcpy(&req.vht_capa_mask,
8267 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8268 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008269
8270 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008271 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008272 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008273 memcpy(&req.vht_capa,
8274 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8275 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008276 }
8277
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008278 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008279 if (!((rdev->wiphy.features &
8280 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8281 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8282 !wiphy_ext_feature_isset(&rdev->wiphy,
8283 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008284 return -EINVAL;
8285 req.flags |= ASSOC_REQ_USE_RRM;
8286 }
8287
Jouni Malinen348bd452016-10-27 00:42:03 +03008288 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8289 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8290 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8291 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8292 return -EINVAL;
8293 req.fils_nonces =
8294 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8295 }
8296
Johannes Bergf62fab72013-02-21 20:09:09 +01008297 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008298 if (!err) {
8299 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008300
Johannes Bergf62fab72013-02-21 20:09:09 +01008301 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8302 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008303
8304 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8305 dev->ieee80211_ptr->conn_owner_nlportid =
8306 info->snd_portid;
8307 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8308 bssid, ETH_ALEN);
8309 }
8310
Johannes Berg91bf9b22013-05-15 17:44:01 +02008311 wdev_unlock(dev->ieee80211_ptr);
8312 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008313
Jouni Malinen636a5d32009-03-19 13:39:22 +02008314 return err;
8315}
8316
8317static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8318{
Johannes Berg4c476992010-10-04 21:36:35 +02008319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8320 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008321 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008322 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008323 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008324 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008325
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008326 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8327 return -EINVAL;
8328
8329 if (!info->attrs[NL80211_ATTR_MAC])
8330 return -EINVAL;
8331
8332 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8333 return -EINVAL;
8334
Johannes Berg4c476992010-10-04 21:36:35 +02008335 if (!rdev->ops->deauth)
8336 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008337
Johannes Berg074ac8d2010-09-16 14:58:22 +02008338 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008339 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8340 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008341
Johannes Berg19957bb2009-07-02 17:20:43 +02008342 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008343
Johannes Berg19957bb2009-07-02 17:20:43 +02008344 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8345 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008346 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008347 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008348 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008349
8350 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008351 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8352 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008353 }
8354
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008355 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8356
Johannes Berg91bf9b22013-05-15 17:44:01 +02008357 wdev_lock(dev->ieee80211_ptr);
8358 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8359 local_state_change);
8360 wdev_unlock(dev->ieee80211_ptr);
8361 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008362}
8363
8364static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8365{
Johannes Berg4c476992010-10-04 21:36:35 +02008366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8367 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008368 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008369 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008370 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008371 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008372
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008373 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8374 return -EINVAL;
8375
8376 if (!info->attrs[NL80211_ATTR_MAC])
8377 return -EINVAL;
8378
8379 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8380 return -EINVAL;
8381
Johannes Berg4c476992010-10-04 21:36:35 +02008382 if (!rdev->ops->disassoc)
8383 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008384
Johannes Berg074ac8d2010-09-16 14:58:22 +02008385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008386 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8387 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008388
Johannes Berg19957bb2009-07-02 17:20:43 +02008389 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008390
Johannes Berg19957bb2009-07-02 17:20:43 +02008391 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8392 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008393 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008394 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008395 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008396
8397 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008398 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8399 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008400 }
8401
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008402 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8403
Johannes Berg91bf9b22013-05-15 17:44:01 +02008404 wdev_lock(dev->ieee80211_ptr);
8405 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8406 local_state_change);
8407 wdev_unlock(dev->ieee80211_ptr);
8408 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008409}
8410
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008411static bool
8412nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008413 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008414 int rateval)
8415{
8416 struct wiphy *wiphy = &rdev->wiphy;
8417 bool found = false;
8418 int band, i;
8419
Johannes Berg57fbcce2016-04-12 15:56:15 +02008420 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008421 struct ieee80211_supported_band *sband;
8422
8423 sband = wiphy->bands[band];
8424 if (!sband)
8425 continue;
8426
8427 for (i = 0; i < sband->n_bitrates; i++) {
8428 if (sband->bitrates[i].bitrate == rateval) {
8429 mcast_rate[band] = i + 1;
8430 found = true;
8431 break;
8432 }
8433 }
8434 }
8435
8436 return found;
8437}
8438
Johannes Berg04a773a2009-04-19 21:24:32 +02008439static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8440{
Johannes Berg4c476992010-10-04 21:36:35 +02008441 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8442 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008443 struct cfg80211_ibss_params ibss;
8444 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008445 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008446 int err;
8447
Johannes Berg8e30bc52009-04-22 17:45:38 +02008448 memset(&ibss, 0, sizeof(ibss));
8449
Johannes Berg04a773a2009-04-19 21:24:32 +02008450 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8451 return -EINVAL;
8452
Johannes Berg683b6d32012-11-08 21:25:48 +01008453 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008454 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8455 return -EINVAL;
8456
Johannes Berg8e30bc52009-04-22 17:45:38 +02008457 ibss.beacon_interval = 100;
8458
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308459 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008460 ibss.beacon_interval =
8461 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308462
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308463 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8464 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308465 if (err)
8466 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008467
Johannes Berg4c476992010-10-04 21:36:35 +02008468 if (!rdev->ops->join_ibss)
8469 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008470
Johannes Berg4c476992010-10-04 21:36:35 +02008471 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8472 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008473
Johannes Berg79c97e92009-07-07 03:56:12 +02008474 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008475
Johannes Berg39193492011-09-16 13:45:25 +02008476 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008477 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008478
8479 if (!is_valid_ether_addr(ibss.bssid))
8480 return -EINVAL;
8481 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008482 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8483 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8484
8485 if (info->attrs[NL80211_ATTR_IE]) {
8486 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8487 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8488 }
8489
Johannes Berg683b6d32012-11-08 21:25:48 +01008490 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8491 if (err)
8492 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008493
Ilan Peer174e0cd2014-02-23 09:13:01 +02008494 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8495 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008496 return -EINVAL;
8497
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008498 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008499 case NL80211_CHAN_WIDTH_5:
8500 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008501 case NL80211_CHAN_WIDTH_20_NOHT:
8502 break;
8503 case NL80211_CHAN_WIDTH_20:
8504 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008505 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8506 return -EINVAL;
8507 break;
8508 case NL80211_CHAN_WIDTH_80:
8509 case NL80211_CHAN_WIDTH_80P80:
8510 case NL80211_CHAN_WIDTH_160:
8511 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8512 return -EINVAL;
8513 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8514 NL80211_EXT_FEATURE_VHT_IBSS))
8515 return -EINVAL;
8516 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008517 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008518 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008519 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008520
Johannes Berg04a773a2009-04-19 21:24:32 +02008521 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008522 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008523
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008524 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8525 u8 *rates =
8526 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8527 int n_rates =
8528 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8529 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008530 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008531
Johannes Berg34850ab2011-07-18 18:08:35 +02008532 err = ieee80211_get_ratemask(sband, rates, n_rates,
8533 &ibss.basic_rates);
8534 if (err)
8535 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008536 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008537
Simon Wunderlich803768f2013-06-28 10:39:58 +02008538 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8539 memcpy(&ibss.ht_capa_mask,
8540 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8541 sizeof(ibss.ht_capa_mask));
8542
8543 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8544 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8545 return -EINVAL;
8546 memcpy(&ibss.ht_capa,
8547 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8548 sizeof(ibss.ht_capa));
8549 }
8550
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008551 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8552 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8553 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8554 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008555
Johannes Berg4c476992010-10-04 21:36:35 +02008556 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308557 bool no_ht = false;
8558
Johannes Berg4c476992010-10-04 21:36:35 +02008559 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308560 info->attrs[NL80211_ATTR_KEYS],
8561 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008562 if (IS_ERR(connkeys))
8563 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308564
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008565 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8566 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008567 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308568 return -EINVAL;
8569 }
Johannes Berg4c476992010-10-04 21:36:35 +02008570 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008571
Antonio Quartulli267335d2012-01-31 20:25:47 +01008572 ibss.control_port =
8573 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8574
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008575 ibss.userspace_handles_dfs =
8576 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8577
Johannes Berg4c476992010-10-04 21:36:35 +02008578 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008579 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008580 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008581 return err;
8582}
8583
8584static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8585{
Johannes Berg4c476992010-10-04 21:36:35 +02008586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8587 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008588
Johannes Berg4c476992010-10-04 21:36:35 +02008589 if (!rdev->ops->leave_ibss)
8590 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008591
Johannes Berg4c476992010-10-04 21:36:35 +02008592 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8593 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008594
Johannes Berg4c476992010-10-04 21:36:35 +02008595 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008596}
8597
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008598static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8599{
8600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8601 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008602 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008603 u32 nla_rate;
8604 int err;
8605
8606 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008607 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8608 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008609 return -EOPNOTSUPP;
8610
8611 if (!rdev->ops->set_mcast_rate)
8612 return -EOPNOTSUPP;
8613
8614 memset(mcast_rate, 0, sizeof(mcast_rate));
8615
8616 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8617 return -EINVAL;
8618
8619 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8620 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8621 return -EINVAL;
8622
Ilan Peera1056b1b2015-10-22 22:27:46 +03008623 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008624
8625 return err;
8626}
8627
Johannes Bergad7e7182013-11-13 13:37:47 +01008628static struct sk_buff *
8629__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008630 struct wireless_dev *wdev, int approxlen,
8631 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008632 enum nl80211_attrs attr,
8633 const struct nl80211_vendor_cmd_info *info,
8634 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008635{
8636 struct sk_buff *skb;
8637 void *hdr;
8638 struct nlattr *data;
8639
8640 skb = nlmsg_new(approxlen + 100, gfp);
8641 if (!skb)
8642 return NULL;
8643
8644 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8645 if (!hdr) {
8646 kfree_skb(skb);
8647 return NULL;
8648 }
8649
8650 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8651 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008652
8653 if (info) {
8654 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8655 info->vendor_id))
8656 goto nla_put_failure;
8657 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8658 info->subcmd))
8659 goto nla_put_failure;
8660 }
8661
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008662 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008663 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8664 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008665 goto nla_put_failure;
8666 if (wdev->netdev &&
8667 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8668 wdev->netdev->ifindex))
8669 goto nla_put_failure;
8670 }
8671
Johannes Bergad7e7182013-11-13 13:37:47 +01008672 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008673 if (!data)
8674 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008675
8676 ((void **)skb->cb)[0] = rdev;
8677 ((void **)skb->cb)[1] = hdr;
8678 ((void **)skb->cb)[2] = data;
8679
8680 return skb;
8681
8682 nla_put_failure:
8683 kfree_skb(skb);
8684 return NULL;
8685}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008686
Johannes Berge03ad6e2014-01-01 17:22:30 +01008687struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008688 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008689 enum nl80211_commands cmd,
8690 enum nl80211_attrs attr,
8691 int vendor_event_idx,
8692 int approxlen, gfp_t gfp)
8693{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008694 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008695 const struct nl80211_vendor_cmd_info *info;
8696
8697 switch (cmd) {
8698 case NL80211_CMD_TESTMODE:
8699 if (WARN_ON(vendor_event_idx != -1))
8700 return NULL;
8701 info = NULL;
8702 break;
8703 case NL80211_CMD_VENDOR:
8704 if (WARN_ON(vendor_event_idx < 0 ||
8705 vendor_event_idx >= wiphy->n_vendor_events))
8706 return NULL;
8707 info = &wiphy->vendor_events[vendor_event_idx];
8708 break;
8709 default:
8710 WARN_ON(1);
8711 return NULL;
8712 }
8713
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008714 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008715 cmd, attr, info, gfp);
8716}
8717EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8718
8719void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8720{
8721 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8722 void *hdr = ((void **)skb->cb)[1];
8723 struct nlattr *data = ((void **)skb->cb)[2];
8724 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8725
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008726 /* clear CB data for netlink core to own from now on */
8727 memset(skb->cb, 0, sizeof(skb->cb));
8728
Johannes Berge03ad6e2014-01-01 17:22:30 +01008729 nla_nest_end(skb, data);
8730 genlmsg_end(skb, hdr);
8731
8732 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8733 mcgrp = NL80211_MCGRP_VENDOR;
8734
8735 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8736 mcgrp, gfp);
8737}
8738EXPORT_SYMBOL(__cfg80211_send_event_skb);
8739
Johannes Bergaff89a92009-07-01 21:26:51 +02008740#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008741static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8742{
Johannes Berg4c476992010-10-04 21:36:35 +02008743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008744 struct wireless_dev *wdev =
8745 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008746 int err;
8747
David Spinadelfc73f112013-07-31 18:04:15 +03008748 if (!rdev->ops->testmode_cmd)
8749 return -EOPNOTSUPP;
8750
8751 if (IS_ERR(wdev)) {
8752 err = PTR_ERR(wdev);
8753 if (err != -EINVAL)
8754 return err;
8755 wdev = NULL;
8756 } else if (wdev->wiphy != &rdev->wiphy) {
8757 return -EINVAL;
8758 }
8759
Johannes Bergaff89a92009-07-01 21:26:51 +02008760 if (!info->attrs[NL80211_ATTR_TESTDATA])
8761 return -EINVAL;
8762
Johannes Bergad7e7182013-11-13 13:37:47 +01008763 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008764 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008765 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8766 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008767 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008768
Johannes Bergaff89a92009-07-01 21:26:51 +02008769 return err;
8770}
8771
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008772static int nl80211_testmode_dump(struct sk_buff *skb,
8773 struct netlink_callback *cb)
8774{
Johannes Berg00918d32011-12-13 17:22:05 +01008775 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008776 int err;
8777 long phy_idx;
8778 void *data = NULL;
8779 int data_len = 0;
8780
Johannes Berg5fe231e2013-05-08 21:45:15 +02008781 rtnl_lock();
8782
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008783 if (cb->args[0]) {
8784 /*
8785 * 0 is a valid index, but not valid for args[0],
8786 * so we need to offset by 1.
8787 */
8788 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008789
8790 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8791 if (!rdev) {
8792 err = -ENOENT;
8793 goto out_err;
8794 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008795 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008796 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8797
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008798 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008799 attrbuf, nl80211_fam.maxattr,
8800 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008801 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008802 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008803
Johannes Bergc90c39d2016-10-24 14:40:01 +02008804 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008805 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008806 err = PTR_ERR(rdev);
8807 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008808 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008809 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008810
Johannes Bergc90c39d2016-10-24 14:40:01 +02008811 if (attrbuf[NL80211_ATTR_TESTDATA])
8812 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008813 }
8814
8815 if (cb->args[1]) {
8816 data = nla_data((void *)cb->args[1]);
8817 data_len = nla_len((void *)cb->args[1]);
8818 }
8819
Johannes Berg00918d32011-12-13 17:22:05 +01008820 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008821 err = -EOPNOTSUPP;
8822 goto out_err;
8823 }
8824
8825 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008826 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008827 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8828 NL80211_CMD_TESTMODE);
8829 struct nlattr *tmdata;
8830
Dan Carpentercb35fba2013-08-14 14:50:01 +03008831 if (!hdr)
8832 break;
8833
David S. Miller9360ffd2012-03-29 04:41:26 -04008834 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008835 genlmsg_cancel(skb, hdr);
8836 break;
8837 }
8838
8839 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8840 if (!tmdata) {
8841 genlmsg_cancel(skb, hdr);
8842 break;
8843 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008844 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008845 nla_nest_end(skb, tmdata);
8846
8847 if (err == -ENOBUFS || err == -ENOENT) {
8848 genlmsg_cancel(skb, hdr);
8849 break;
8850 } else if (err) {
8851 genlmsg_cancel(skb, hdr);
8852 goto out_err;
8853 }
8854
8855 genlmsg_end(skb, hdr);
8856 }
8857
8858 err = skb->len;
8859 /* see above */
8860 cb->args[0] = phy_idx + 1;
8861 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008862 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008863 return err;
8864}
Johannes Bergaff89a92009-07-01 21:26:51 +02008865#endif
8866
Samuel Ortizb23aa672009-07-01 21:26:54 +02008867static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8868{
Johannes Berg4c476992010-10-04 21:36:35 +02008869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8870 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008871 struct cfg80211_connect_params connect;
8872 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008873 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008874 int err;
8875
8876 memset(&connect, 0, sizeof(connect));
8877
8878 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8879 return -EINVAL;
8880
8881 if (!info->attrs[NL80211_ATTR_SSID] ||
8882 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8883 return -EINVAL;
8884
8885 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8886 connect.auth_type =
8887 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008888 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8889 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008890 return -EINVAL;
8891 } else
8892 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8893
8894 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8895
Avraham Stern3a00df52017-06-09 13:08:43 +01008896 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8897 !wiphy_ext_feature_isset(&rdev->wiphy,
8898 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8899 return -EINVAL;
8900 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8901
Johannes Bergc0692b82010-08-27 14:26:53 +03008902 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008903 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008904 if (err)
8905 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008906
Johannes Berg074ac8d2010-09-16 14:58:22 +02008907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008908 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8909 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008910
Johannes Berg79c97e92009-07-07 03:56:12 +02008911 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008912
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308913 connect.bg_scan_period = -1;
8914 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8915 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8916 connect.bg_scan_period =
8917 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8918 }
8919
Samuel Ortizb23aa672009-07-01 21:26:54 +02008920 if (info->attrs[NL80211_ATTR_MAC])
8921 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008922 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8923 connect.bssid_hint =
8924 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008925 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8926 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8927
8928 if (info->attrs[NL80211_ATTR_IE]) {
8929 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8930 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8931 }
8932
Jouni Malinencee00a92013-01-15 17:15:57 +02008933 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8934 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8935 if (connect.mfp != NL80211_MFP_REQUIRED &&
8936 connect.mfp != NL80211_MFP_NO)
8937 return -EINVAL;
8938 } else {
8939 connect.mfp = NL80211_MFP_NO;
8940 }
8941
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008942 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8943 connect.prev_bssid =
8944 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8945
Samuel Ortizb23aa672009-07-01 21:26:54 +02008946 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008947 connect.channel = nl80211_get_valid_chan(
8948 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8949 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008950 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008951 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008952 connect.channel_hint = nl80211_get_valid_chan(
8953 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8954 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008955 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008956 }
8957
Johannes Bergfffd0932009-07-08 14:22:54 +02008958 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8959 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308960 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008961 if (IS_ERR(connkeys))
8962 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008963 }
8964
Ben Greear7e7c8922011-11-18 11:31:59 -08008965 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8966 connect.flags |= ASSOC_REQ_DISABLE_HT;
8967
8968 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8969 memcpy(&connect.ht_capa_mask,
8970 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8971 sizeof(connect.ht_capa_mask));
8972
8973 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008974 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008975 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008976 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008977 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008978 memcpy(&connect.ht_capa,
8979 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8980 sizeof(connect.ht_capa));
8981 }
8982
Johannes Bergee2aca32013-02-21 17:36:01 +01008983 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8984 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8985
8986 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8987 memcpy(&connect.vht_capa_mask,
8988 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8989 sizeof(connect.vht_capa_mask));
8990
8991 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8992 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008993 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008994 return -EINVAL;
8995 }
8996 memcpy(&connect.vht_capa,
8997 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8998 sizeof(connect.vht_capa));
8999 }
9000
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009001 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009002 if (!((rdev->wiphy.features &
9003 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9004 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9005 !wiphy_ext_feature_isset(&rdev->wiphy,
9006 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009007 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009008 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009009 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009010 connect.flags |= ASSOC_REQ_USE_RRM;
9011 }
9012
Lior David34d50512016-01-28 10:58:25 +02009013 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009014 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009015 kzfree(connkeys);
9016 return -EOPNOTSUPP;
9017 }
9018
Arend van Spriel38de03d2016-03-02 20:37:18 +01009019 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9020 /* bss selection makes no sense if bssid is set */
9021 if (connect.bssid) {
9022 kzfree(connkeys);
9023 return -EINVAL;
9024 }
9025
9026 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9027 wiphy, &connect.bss_select);
9028 if (err) {
9029 kzfree(connkeys);
9030 return err;
9031 }
9032 }
9033
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009034 if (wiphy_ext_feature_isset(&rdev->wiphy,
9035 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9036 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9037 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9038 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9039 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9040 connect.fils_erp_username =
9041 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9042 connect.fils_erp_username_len =
9043 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9044 connect.fils_erp_realm =
9045 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9046 connect.fils_erp_realm_len =
9047 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9048 connect.fils_erp_next_seq_num =
9049 nla_get_u16(
9050 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9051 connect.fils_erp_rrk =
9052 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9053 connect.fils_erp_rrk_len =
9054 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9055 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9056 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9057 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9058 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9059 kzfree(connkeys);
9060 return -EINVAL;
9061 }
9062
Johannes Berg83739b02013-05-15 17:44:01 +02009063 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009064
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +03009065 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9066 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009067 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009068 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009069
9070 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9071 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9072 if (connect.bssid)
9073 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9074 connect.bssid, ETH_ALEN);
9075 else
9076 memset(dev->ieee80211_ptr->disconnect_bssid,
9077 0, ETH_ALEN);
9078 }
9079
9080 wdev_unlock(dev->ieee80211_ptr);
9081
Samuel Ortizb23aa672009-07-01 21:26:54 +02009082 return err;
9083}
9084
vamsi krishna088e8df2016-10-27 16:51:11 +03009085static int nl80211_update_connect_params(struct sk_buff *skb,
9086 struct genl_info *info)
9087{
9088 struct cfg80211_connect_params connect = {};
9089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9090 struct net_device *dev = info->user_ptr[1];
9091 struct wireless_dev *wdev = dev->ieee80211_ptr;
9092 u32 changed = 0;
9093 int ret;
9094
9095 if (!rdev->ops->update_connect_params)
9096 return -EOPNOTSUPP;
9097
9098 if (info->attrs[NL80211_ATTR_IE]) {
9099 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9100 return -EINVAL;
9101 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9102 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9103 changed |= UPDATE_ASSOC_IES;
9104 }
9105
9106 wdev_lock(dev->ieee80211_ptr);
9107 if (!wdev->current_bss)
9108 ret = -ENOLINK;
9109 else
9110 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9111 wdev_unlock(dev->ieee80211_ptr);
9112
9113 return ret;
9114}
9115
Samuel Ortizb23aa672009-07-01 21:26:54 +02009116static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9117{
Johannes Berg4c476992010-10-04 21:36:35 +02009118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9119 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009120 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009121 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009122
9123 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9124 reason = WLAN_REASON_DEAUTH_LEAVING;
9125 else
9126 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9127
9128 if (reason == 0)
9129 return -EINVAL;
9130
Johannes Berg074ac8d2010-09-16 14:58:22 +02009131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009132 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9133 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009134
Johannes Berg83739b02013-05-15 17:44:01 +02009135 wdev_lock(dev->ieee80211_ptr);
9136 ret = cfg80211_disconnect(rdev, dev, reason, true);
9137 wdev_unlock(dev->ieee80211_ptr);
9138 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009139}
9140
Johannes Berg463d0182009-07-14 00:33:35 +02009141static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9142{
Johannes Berg4c476992010-10-04 21:36:35 +02009143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009144 struct net *net;
9145 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009146
Vadim Kochan4b681c82015-01-12 16:34:05 +02009147 if (info->attrs[NL80211_ATTR_PID]) {
9148 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9149
9150 net = get_net_ns_by_pid(pid);
9151 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9152 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9153
9154 net = get_net_ns_by_fd(fd);
9155 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009156 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009157 }
Johannes Berg463d0182009-07-14 00:33:35 +02009158
Johannes Berg4c476992010-10-04 21:36:35 +02009159 if (IS_ERR(net))
9160 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009161
9162 err = 0;
9163
9164 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009165 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9166 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009167
Johannes Berg463d0182009-07-14 00:33:35 +02009168 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009169 return err;
9170}
9171
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009172static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9173{
Johannes Berg4c476992010-10-04 21:36:35 +02009174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009175 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9176 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009177 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009178 struct cfg80211_pmksa pmksa;
9179
9180 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9181
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009182 if (!info->attrs[NL80211_ATTR_PMKID])
9183 return -EINVAL;
9184
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009185 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009186
9187 if (info->attrs[NL80211_ATTR_MAC]) {
9188 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9189 } else if (info->attrs[NL80211_ATTR_SSID] &&
9190 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9191 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9192 info->attrs[NL80211_ATTR_PMK])) {
9193 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9194 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9195 pmksa.cache_id =
9196 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9197 } else {
9198 return -EINVAL;
9199 }
9200 if (info->attrs[NL80211_ATTR_PMK]) {
9201 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9202 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9203 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009204
Johannes Berg074ac8d2010-09-16 14:58:22 +02009205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9207 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009208
9209 switch (info->genlhdr->cmd) {
9210 case NL80211_CMD_SET_PMKSA:
9211 rdev_ops = rdev->ops->set_pmksa;
9212 break;
9213 case NL80211_CMD_DEL_PMKSA:
9214 rdev_ops = rdev->ops->del_pmksa;
9215 break;
9216 default:
9217 WARN_ON(1);
9218 break;
9219 }
9220
Johannes Berg4c476992010-10-04 21:36:35 +02009221 if (!rdev_ops)
9222 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009223
Johannes Berg4c476992010-10-04 21:36:35 +02009224 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009225}
9226
9227static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9228{
Johannes Berg4c476992010-10-04 21:36:35 +02009229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9230 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009231
Johannes Berg074ac8d2010-09-16 14:58:22 +02009232 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009233 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9234 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009235
Johannes Berg4c476992010-10-04 21:36:35 +02009236 if (!rdev->ops->flush_pmksa)
9237 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009238
Hila Gonene35e4d22012-06-27 17:19:42 +03009239 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009240}
9241
Arik Nemtsov109086c2011-09-28 14:12:50 +03009242static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9243{
9244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9245 struct net_device *dev = info->user_ptr[1];
9246 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309247 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009248 u16 status_code;
9249 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009250 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009251
9252 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9253 !rdev->ops->tdls_mgmt)
9254 return -EOPNOTSUPP;
9255
9256 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9257 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9258 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9259 !info->attrs[NL80211_ATTR_IE] ||
9260 !info->attrs[NL80211_ATTR_MAC])
9261 return -EINVAL;
9262
9263 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9264 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9265 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9266 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009267 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309268 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9269 peer_capability =
9270 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009271
Hila Gonene35e4d22012-06-27 17:19:42 +03009272 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309273 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009274 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009275 nla_data(info->attrs[NL80211_ATTR_IE]),
9276 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009277}
9278
9279static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9280{
9281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9282 struct net_device *dev = info->user_ptr[1];
9283 enum nl80211_tdls_operation operation;
9284 u8 *peer;
9285
9286 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9287 !rdev->ops->tdls_oper)
9288 return -EOPNOTSUPP;
9289
9290 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9291 !info->attrs[NL80211_ATTR_MAC])
9292 return -EINVAL;
9293
9294 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9295 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9296
Hila Gonene35e4d22012-06-27 17:19:42 +03009297 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009298}
9299
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009300static int nl80211_remain_on_channel(struct sk_buff *skb,
9301 struct genl_info *info)
9302{
Johannes Berg4c476992010-10-04 21:36:35 +02009303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009304 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009305 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309306 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009307 struct sk_buff *msg;
9308 void *hdr;
9309 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009310 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009311 int err;
9312
9313 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9314 !info->attrs[NL80211_ATTR_DURATION])
9315 return -EINVAL;
9316
9317 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9318
Johannes Berg7c4ef712011-11-18 15:33:48 +01009319 if (!rdev->ops->remain_on_channel ||
9320 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009321 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009322
Johannes Bergebf348f2012-06-01 12:50:54 +02009323 /*
9324 * We should be on that channel for at least a minimum amount of
9325 * time (10ms) but no longer than the driver supports.
9326 */
9327 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9328 duration > rdev->wiphy.max_remain_on_channel_duration)
9329 return -EINVAL;
9330
Johannes Berg683b6d32012-11-08 21:25:48 +01009331 err = nl80211_parse_chandef(rdev, info, &chandef);
9332 if (err)
9333 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009334
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309335 wdev_lock(wdev);
9336 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9337 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9338 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9339 &chandef);
9340 if (compat_chandef != &chandef) {
9341 wdev_unlock(wdev);
9342 return -EBUSY;
9343 }
9344 }
9345 wdev_unlock(wdev);
9346
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009347 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009348 if (!msg)
9349 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009350
Eric W. Biederman15e47302012-09-07 20:12:54 +00009351 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009352 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009353 if (!hdr) {
9354 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009355 goto free_msg;
9356 }
9357
Johannes Berg683b6d32012-11-08 21:25:48 +01009358 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9359 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009360
9361 if (err)
9362 goto free_msg;
9363
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009364 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9365 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009366 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009367
9368 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009369
9370 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009371
9372 nla_put_failure:
9373 err = -ENOBUFS;
9374 free_msg:
9375 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009376 return err;
9377}
9378
9379static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9380 struct genl_info *info)
9381{
Johannes Berg4c476992010-10-04 21:36:35 +02009382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009383 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009384 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009385
9386 if (!info->attrs[NL80211_ATTR_COOKIE])
9387 return -EINVAL;
9388
Johannes Berg4c476992010-10-04 21:36:35 +02009389 if (!rdev->ops->cancel_remain_on_channel)
9390 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009391
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009392 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9393
Hila Gonene35e4d22012-06-27 17:19:42 +03009394 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009395}
9396
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009397static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9398 struct genl_info *info)
9399{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009400 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009402 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309403 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009404
Johannes Berg4c476992010-10-04 21:36:35 +02009405 if (!rdev->ops->set_bitrate_mask)
9406 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009407
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309408 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9409 if (err)
9410 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009411
Hila Gonene35e4d22012-06-27 17:19:42 +03009412 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009413}
9414
Johannes Berg2e161f72010-08-12 15:38:38 +02009415static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009416{
Johannes Berg4c476992010-10-04 21:36:35 +02009417 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009418 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009419 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009420
9421 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9422 return -EINVAL;
9423
Johannes Berg2e161f72010-08-12 15:38:38 +02009424 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9425 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009426
Johannes Berg71bbc992012-06-15 15:30:18 +02009427 switch (wdev->iftype) {
9428 case NL80211_IFTYPE_STATION:
9429 case NL80211_IFTYPE_ADHOC:
9430 case NL80211_IFTYPE_P2P_CLIENT:
9431 case NL80211_IFTYPE_AP:
9432 case NL80211_IFTYPE_AP_VLAN:
9433 case NL80211_IFTYPE_MESH_POINT:
9434 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009435 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009436 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009437 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009438 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009439 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009440 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009441
9442 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009443 if (!rdev->ops->mgmt_tx)
9444 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009445
Eric W. Biederman15e47302012-09-07 20:12:54 +00009446 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009447 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9448 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009449}
9450
Johannes Berg2e161f72010-08-12 15:38:38 +02009451static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009452{
Johannes Berg4c476992010-10-04 21:36:35 +02009453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009454 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009455 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009456 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009457 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009458 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009459 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009460 struct cfg80211_mgmt_tx_params params = {
9461 .dont_wait_for_ack =
9462 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9463 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009464
Johannes Berg683b6d32012-11-08 21:25:48 +01009465 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009466 return -EINVAL;
9467
Johannes Berg4c476992010-10-04 21:36:35 +02009468 if (!rdev->ops->mgmt_tx)
9469 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009470
Johannes Berg71bbc992012-06-15 15:30:18 +02009471 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009472 case NL80211_IFTYPE_P2P_DEVICE:
9473 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9474 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009475 case NL80211_IFTYPE_STATION:
9476 case NL80211_IFTYPE_ADHOC:
9477 case NL80211_IFTYPE_P2P_CLIENT:
9478 case NL80211_IFTYPE_AP:
9479 case NL80211_IFTYPE_AP_VLAN:
9480 case NL80211_IFTYPE_MESH_POINT:
9481 case NL80211_IFTYPE_P2P_GO:
9482 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009483 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009484 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009485 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009486 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009487
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009488 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009489 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009490 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009491 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009492
9493 /*
9494 * We should wait on the channel for at least a minimum amount
9495 * of time (10ms) but no longer than the driver supports.
9496 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009497 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9498 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009499 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009500 }
9501
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009502 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009503
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009504 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009505 return -EINVAL;
9506
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009507 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309508
Antonio Quartulliea141b752013-06-11 14:20:03 +02009509 /* get the channel if any has been specified, otherwise pass NULL to
9510 * the driver. The latter will use the current one
9511 */
9512 chandef.chan = NULL;
9513 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9514 err = nl80211_parse_chandef(rdev, info, &chandef);
9515 if (err)
9516 return err;
9517 }
9518
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009519 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009520 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009521
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309522 wdev_lock(wdev);
9523 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9524 wdev_unlock(wdev);
9525 return -EBUSY;
9526 }
9527 wdev_unlock(wdev);
9528
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009529 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9530 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9531
9532 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9533 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9534 int i;
9535
9536 if (len % sizeof(u16))
9537 return -EINVAL;
9538
9539 params.n_csa_offsets = len / sizeof(u16);
9540 params.csa_offsets =
9541 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9542
9543 /* check that all the offsets fit the frame */
9544 for (i = 0; i < params.n_csa_offsets; i++) {
9545 if (params.csa_offsets[i] >= params.len)
9546 return -EINVAL;
9547 }
9548 }
9549
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009550 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009551 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9552 if (!msg)
9553 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009554
Eric W. Biederman15e47302012-09-07 20:12:54 +00009555 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009556 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009557 if (!hdr) {
9558 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009559 goto free_msg;
9560 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009561 }
Johannes Berge247bd902011-11-04 11:18:21 +01009562
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009563 params.chan = chandef.chan;
9564 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009565 if (err)
9566 goto free_msg;
9567
Johannes Berge247bd902011-11-04 11:18:21 +01009568 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009569 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9570 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009571 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009572
Johannes Berge247bd902011-11-04 11:18:21 +01009573 genlmsg_end(msg, hdr);
9574 return genlmsg_reply(msg, info);
9575 }
9576
9577 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009578
9579 nla_put_failure:
9580 err = -ENOBUFS;
9581 free_msg:
9582 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009583 return err;
9584}
9585
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009586static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9587{
9588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009589 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009590 u64 cookie;
9591
9592 if (!info->attrs[NL80211_ATTR_COOKIE])
9593 return -EINVAL;
9594
9595 if (!rdev->ops->mgmt_tx_cancel_wait)
9596 return -EOPNOTSUPP;
9597
Johannes Berg71bbc992012-06-15 15:30:18 +02009598 switch (wdev->iftype) {
9599 case NL80211_IFTYPE_STATION:
9600 case NL80211_IFTYPE_ADHOC:
9601 case NL80211_IFTYPE_P2P_CLIENT:
9602 case NL80211_IFTYPE_AP:
9603 case NL80211_IFTYPE_AP_VLAN:
9604 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009605 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009606 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009607 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009608 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009609 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009610 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009611
9612 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9613
Hila Gonene35e4d22012-06-27 17:19:42 +03009614 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009615}
9616
Kalle Valoffb9eb32010-02-17 17:58:10 +02009617static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9618{
Johannes Berg4c476992010-10-04 21:36:35 +02009619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009620 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009621 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009622 u8 ps_state;
9623 bool state;
9624 int err;
9625
Johannes Berg4c476992010-10-04 21:36:35 +02009626 if (!info->attrs[NL80211_ATTR_PS_STATE])
9627 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009628
9629 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9630
Johannes Berg4c476992010-10-04 21:36:35 +02009631 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9632 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009633
9634 wdev = dev->ieee80211_ptr;
9635
Johannes Berg4c476992010-10-04 21:36:35 +02009636 if (!rdev->ops->set_power_mgmt)
9637 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009638
9639 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9640
9641 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009642 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009643
Hila Gonene35e4d22012-06-27 17:19:42 +03009644 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009645 if (!err)
9646 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009647 return err;
9648}
9649
9650static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9651{
Johannes Berg4c476992010-10-04 21:36:35 +02009652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009653 enum nl80211_ps_state ps_state;
9654 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009655 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009656 struct sk_buff *msg;
9657 void *hdr;
9658 int err;
9659
Kalle Valoffb9eb32010-02-17 17:58:10 +02009660 wdev = dev->ieee80211_ptr;
9661
Johannes Berg4c476992010-10-04 21:36:35 +02009662 if (!rdev->ops->set_power_mgmt)
9663 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009664
9665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009666 if (!msg)
9667 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009668
Eric W. Biederman15e47302012-09-07 20:12:54 +00009669 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009670 NL80211_CMD_GET_POWER_SAVE);
9671 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009672 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009673 goto free_msg;
9674 }
9675
9676 if (wdev->ps)
9677 ps_state = NL80211_PS_ENABLED;
9678 else
9679 ps_state = NL80211_PS_DISABLED;
9680
David S. Miller9360ffd2012-03-29 04:41:26 -04009681 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9682 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009683
9684 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009685 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009686
Johannes Berg4c476992010-10-04 21:36:35 +02009687 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009688 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009689 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009690 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009691 return err;
9692}
9693
Johannes Berg94e860f2014-01-20 23:58:15 +01009694static const struct nla_policy
9695nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009696 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009697 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9698 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009699 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9700 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9701 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009702 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009703};
9704
Thomas Pedersen84f10702012-07-12 16:17:33 -07009705static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009706 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009707{
9708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009709 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009710 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009711
Johannes Bergd9d8b012012-11-26 12:51:52 +01009712 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009713 return -EINVAL;
9714
Thomas Pedersen84f10702012-07-12 16:17:33 -07009715 if (!rdev->ops->set_cqm_txe_config)
9716 return -EOPNOTSUPP;
9717
9718 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9719 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9720 return -EOPNOTSUPP;
9721
Hila Gonene35e4d22012-06-27 17:19:42 +03009722 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009723}
9724
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009725static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9726 struct net_device *dev)
9727{
9728 struct wireless_dev *wdev = dev->ieee80211_ptr;
9729 s32 last, low, high;
9730 u32 hyst;
9731 int i, n;
9732 int err;
9733
9734 /* RSSI reporting disabled? */
9735 if (!wdev->cqm_config)
9736 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9737
9738 /*
9739 * Obtain current RSSI value if possible, if not and no RSSI threshold
9740 * event has been received yet, we should receive an event after a
9741 * connection is established and enough beacons received to calculate
9742 * the average.
9743 */
9744 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9745 rdev->ops->get_station) {
9746 struct station_info sinfo;
9747 u8 *mac_addr;
9748
9749 mac_addr = wdev->current_bss->pub.bssid;
9750
9751 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9752 if (err)
9753 return err;
9754
9755 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9756 wdev->cqm_config->last_rssi_event_value =
9757 (s8) sinfo.rx_beacon_signal_avg;
9758 }
9759
9760 last = wdev->cqm_config->last_rssi_event_value;
9761 hyst = wdev->cqm_config->rssi_hyst;
9762 n = wdev->cqm_config->n_rssi_thresholds;
9763
9764 for (i = 0; i < n; i++)
9765 if (last < wdev->cqm_config->rssi_thresholds[i])
9766 break;
9767
9768 low = i > 0 ?
9769 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9770 high = i < n ?
9771 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9772
9773 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9774}
9775
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009776static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009777 const s32 *thresholds, int n_thresholds,
9778 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009779{
Johannes Berg4c476992010-10-04 21:36:35 +02009780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009781 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009782 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009783 int i, err;
9784 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009785
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009786 /* Check all values negative and sorted */
9787 for (i = 0; i < n_thresholds; i++) {
9788 if (thresholds[i] > 0 || thresholds[i] <= prev)
9789 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009790
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009791 prev = thresholds[i];
9792 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009793
Johannes Berg074ac8d2010-09-16 14:58:22 +02009794 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009795 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9796 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009797
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009798 wdev_lock(wdev);
9799 cfg80211_cqm_config_free(wdev);
9800 wdev_unlock(wdev);
9801
9802 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9803 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9804 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9805
9806 return rdev_set_cqm_rssi_config(rdev, dev,
9807 thresholds[0], hysteresis);
9808 }
9809
9810 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9811 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9812 return -EOPNOTSUPP;
9813
9814 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9815 n_thresholds = 0;
9816
9817 wdev_lock(wdev);
9818 if (n_thresholds) {
9819 struct cfg80211_cqm_config *cqm_config;
9820
9821 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9822 n_thresholds * sizeof(s32), GFP_KERNEL);
9823 if (!cqm_config) {
9824 err = -ENOMEM;
9825 goto unlock;
9826 }
9827
9828 cqm_config->rssi_hyst = hysteresis;
9829 cqm_config->n_rssi_thresholds = n_thresholds;
9830 memcpy(cqm_config->rssi_thresholds, thresholds,
9831 n_thresholds * sizeof(s32));
9832
9833 wdev->cqm_config = cqm_config;
9834 }
9835
9836 err = cfg80211_cqm_rssi_update(rdev, dev);
9837
9838unlock:
9839 wdev_unlock(wdev);
9840
9841 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009842}
9843
9844static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9845{
9846 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9847 struct nlattr *cqm;
9848 int err;
9849
9850 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009851 if (!cqm)
9852 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009853
9854 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009855 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009856 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009857 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009858
9859 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9860 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009861 const s32 *thresholds =
9862 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9863 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009864 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009865
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009866 if (len % 4)
9867 return -EINVAL;
9868
9869 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9870 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009871 }
9872
9873 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9874 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9875 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9876 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9877 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9878 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9879
9880 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9881 }
9882
9883 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009884}
9885
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009886static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9887{
9888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9889 struct net_device *dev = info->user_ptr[1];
9890 struct ocb_setup setup = {};
9891 int err;
9892
9893 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9894 if (err)
9895 return err;
9896
9897 return cfg80211_join_ocb(rdev, dev, &setup);
9898}
9899
9900static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9901{
9902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9903 struct net_device *dev = info->user_ptr[1];
9904
9905 return cfg80211_leave_ocb(rdev, dev);
9906}
9907
Johannes Berg29cbe682010-12-03 09:20:44 +01009908static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9909{
9910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9911 struct net_device *dev = info->user_ptr[1];
9912 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009913 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009914 int err;
9915
9916 /* start with default */
9917 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009918 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009919
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009920 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009921 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009922 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009923 if (err)
9924 return err;
9925 }
9926
9927 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9928 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9929 return -EINVAL;
9930
Javier Cardonac80d5452010-12-16 17:37:49 -08009931 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9932 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9933
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009934 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9935 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9936 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9937 return -EINVAL;
9938
Marco Porsch9bdbf042013-01-07 16:04:51 +01009939 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9940 setup.beacon_interval =
9941 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309942
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309943 err = cfg80211_validate_beacon_int(rdev,
9944 NL80211_IFTYPE_MESH_POINT,
9945 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309946 if (err)
9947 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009948 }
9949
9950 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9951 setup.dtim_period =
9952 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9953 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9954 return -EINVAL;
9955 }
9956
Javier Cardonac80d5452010-12-16 17:37:49 -08009957 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9958 /* parse additional setup parameters if given */
9959 err = nl80211_parse_mesh_setup(info, &setup);
9960 if (err)
9961 return err;
9962 }
9963
Thomas Pedersend37bb182013-03-04 13:06:13 -08009964 if (setup.user_mpm)
9965 cfg.auto_open_plinks = false;
9966
Johannes Bergcc1d2802012-05-16 23:50:20 +02009967 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009968 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9969 if (err)
9970 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009971 } else {
9972 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009973 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009974 }
9975
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009976 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9977 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9978 int n_rates =
9979 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9980 struct ieee80211_supported_band *sband;
9981
9982 if (!setup.chandef.chan)
9983 return -EINVAL;
9984
9985 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9986
9987 err = ieee80211_get_ratemask(sband, rates, n_rates,
9988 &setup.basic_rates);
9989 if (err)
9990 return err;
9991 }
9992
Johannes Berg8564e382016-09-19 09:44:44 +02009993 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9994 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9995 if (err)
9996 return err;
9997
Johannes Berg265698d2017-09-18 22:46:36 +02009998 if (!setup.chandef.chan)
9999 return -EINVAL;
10000
Johannes Berg8564e382016-09-19 09:44:44 +020010001 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10002 &setup.beacon_rate);
10003 if (err)
10004 return err;
10005 }
10006
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010007 setup.userspace_handles_dfs =
10008 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10009
Javier Cardonac80d5452010-12-16 17:37:49 -080010010 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +010010011}
10012
10013static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10014{
10015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10016 struct net_device *dev = info->user_ptr[1];
10017
10018 return cfg80211_leave_mesh(rdev, dev);
10019}
10020
Johannes Bergdfb89c52012-06-27 09:23:48 +020010021#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010022static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10023 struct cfg80211_registered_device *rdev)
10024{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010025 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010026 struct nlattr *nl_pats, *nl_pat;
10027 int i, pat_len;
10028
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010029 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010030 return 0;
10031
10032 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10033 if (!nl_pats)
10034 return -ENOBUFS;
10035
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010036 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010037 nl_pat = nla_nest_start(msg, i + 1);
10038 if (!nl_pat)
10039 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010040 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010041 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010042 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010043 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10044 wowlan->patterns[i].pattern) ||
10045 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010046 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010047 return -ENOBUFS;
10048 nla_nest_end(msg, nl_pat);
10049 }
10050 nla_nest_end(msg, nl_pats);
10051
10052 return 0;
10053}
10054
Johannes Berg2a0e0472013-01-23 22:57:40 +010010055static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10056 struct cfg80211_wowlan_tcp *tcp)
10057{
10058 struct nlattr *nl_tcp;
10059
10060 if (!tcp)
10061 return 0;
10062
10063 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10064 if (!nl_tcp)
10065 return -ENOBUFS;
10066
Jiri Benc930345e2015-03-29 16:59:25 +020010067 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10068 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010069 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10070 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10071 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10072 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10073 tcp->payload_len, tcp->payload) ||
10074 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10075 tcp->data_interval) ||
10076 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10077 tcp->wake_len, tcp->wake_data) ||
10078 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10079 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10080 return -ENOBUFS;
10081
10082 if (tcp->payload_seq.len &&
10083 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10084 sizeof(tcp->payload_seq), &tcp->payload_seq))
10085 return -ENOBUFS;
10086
10087 if (tcp->payload_tok.len &&
10088 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10089 sizeof(tcp->payload_tok) + tcp->tokens_size,
10090 &tcp->payload_tok))
10091 return -ENOBUFS;
10092
Johannes Berge248ad32013-05-16 10:24:28 +020010093 nla_nest_end(msg, nl_tcp);
10094
Johannes Berg2a0e0472013-01-23 22:57:40 +010010095 return 0;
10096}
10097
Luciano Coelho75453cc2015-01-09 14:06:37 +020010098static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10099 struct cfg80211_sched_scan_request *req)
10100{
Avraham Stern3b06d272015-10-12 09:51:34 +030010101 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010102 int i;
10103
10104 if (!req)
10105 return 0;
10106
10107 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10108 if (!nd)
10109 return -ENOBUFS;
10110
Avraham Stern3b06d272015-10-12 09:51:34 +030010111 if (req->n_scan_plans == 1 &&
10112 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10113 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010114 return -ENOBUFS;
10115
Luciano Coelho21fea562015-03-17 16:36:01 +020010116 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10117 return -ENOBUFS;
10118
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010119 if (req->relative_rssi_set) {
10120 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10121
10122 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10123 req->relative_rssi))
10124 return -ENOBUFS;
10125
10126 rssi_adjust.band = req->rssi_adjust.band;
10127 rssi_adjust.delta = req->rssi_adjust.delta;
10128 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10129 sizeof(rssi_adjust), &rssi_adjust))
10130 return -ENOBUFS;
10131 }
10132
Luciano Coelho75453cc2015-01-09 14:06:37 +020010133 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10134 if (!freqs)
10135 return -ENOBUFS;
10136
Johannes Berg53b18982016-09-14 09:59:21 +020010137 for (i = 0; i < req->n_channels; i++) {
10138 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10139 return -ENOBUFS;
10140 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010141
10142 nla_nest_end(msg, freqs);
10143
10144 if (req->n_match_sets) {
10145 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010146 if (!matches)
10147 return -ENOBUFS;
10148
Luciano Coelho75453cc2015-01-09 14:06:37 +020010149 for (i = 0; i < req->n_match_sets; i++) {
10150 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010151 if (!match)
10152 return -ENOBUFS;
10153
Johannes Berg53b18982016-09-14 09:59:21 +020010154 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10155 req->match_sets[i].ssid.ssid_len,
10156 req->match_sets[i].ssid.ssid))
10157 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010158 nla_nest_end(msg, match);
10159 }
10160 nla_nest_end(msg, matches);
10161 }
10162
Avraham Stern3b06d272015-10-12 09:51:34 +030010163 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10164 if (!scan_plans)
10165 return -ENOBUFS;
10166
10167 for (i = 0; i < req->n_scan_plans; i++) {
10168 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010169 if (!scan_plan)
10170 return -ENOBUFS;
10171
Avraham Stern3b06d272015-10-12 09:51:34 +030010172 if (!scan_plan ||
10173 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10174 req->scan_plans[i].interval) ||
10175 (req->scan_plans[i].iterations &&
10176 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10177 req->scan_plans[i].iterations)))
10178 return -ENOBUFS;
10179 nla_nest_end(msg, scan_plan);
10180 }
10181 nla_nest_end(msg, scan_plans);
10182
Luciano Coelho75453cc2015-01-09 14:06:37 +020010183 nla_nest_end(msg, nd);
10184
10185 return 0;
10186}
10187
Johannes Bergff1b6e62011-05-04 15:37:28 +020010188static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10189{
10190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10191 struct sk_buff *msg;
10192 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010193 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010194
Johannes Berg964dc9e2013-06-03 17:25:34 +020010195 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010196 return -EOPNOTSUPP;
10197
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010198 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010199 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010200 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10201 rdev->wiphy.wowlan_config->tcp->payload_len +
10202 rdev->wiphy.wowlan_config->tcp->wake_len +
10203 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010204 }
10205
10206 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010207 if (!msg)
10208 return -ENOMEM;
10209
Eric W. Biederman15e47302012-09-07 20:12:54 +000010210 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010211 NL80211_CMD_GET_WOWLAN);
10212 if (!hdr)
10213 goto nla_put_failure;
10214
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010215 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010216 struct nlattr *nl_wowlan;
10217
10218 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10219 if (!nl_wowlan)
10220 goto nla_put_failure;
10221
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010222 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010223 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010224 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010225 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010226 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010227 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010228 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010229 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010230 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010231 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010232 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010233 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010234 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010235 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10236 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010237
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010238 if (nl80211_send_wowlan_patterns(msg, rdev))
10239 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010240
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010241 if (nl80211_send_wowlan_tcp(msg,
10242 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010243 goto nla_put_failure;
10244
Luciano Coelho75453cc2015-01-09 14:06:37 +020010245 if (nl80211_send_wowlan_nd(
10246 msg,
10247 rdev->wiphy.wowlan_config->nd_config))
10248 goto nla_put_failure;
10249
Johannes Bergff1b6e62011-05-04 15:37:28 +020010250 nla_nest_end(msg, nl_wowlan);
10251 }
10252
10253 genlmsg_end(msg, hdr);
10254 return genlmsg_reply(msg, info);
10255
10256nla_put_failure:
10257 nlmsg_free(msg);
10258 return -ENOBUFS;
10259}
10260
Johannes Berg2a0e0472013-01-23 22:57:40 +010010261static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10262 struct nlattr *attr,
10263 struct cfg80211_wowlan *trig)
10264{
10265 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10266 struct cfg80211_wowlan_tcp *cfg;
10267 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10268 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10269 u32 size;
10270 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10271 int err, port;
10272
Johannes Berg964dc9e2013-06-03 17:25:34 +020010273 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010274 return -EINVAL;
10275
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010276 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010277 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010278 if (err)
10279 return err;
10280
10281 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10282 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10283 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10284 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10285 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10286 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10287 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10288 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10289 return -EINVAL;
10290
10291 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010292 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010293 return -EINVAL;
10294
10295 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010296 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010297 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010298 return -EINVAL;
10299
10300 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010301 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010302 return -EINVAL;
10303
10304 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10305 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10306 return -EINVAL;
10307
10308 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10309 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10310
10311 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10312 tokens_size = tokln - sizeof(*tok);
10313
10314 if (!tok->len || tokens_size % tok->len)
10315 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010316 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010317 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010318 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010319 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010320 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010321 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010322 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010323 return -EINVAL;
10324 if (tok->offset + tok->len > data_size)
10325 return -EINVAL;
10326 }
10327
10328 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10329 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010330 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010331 return -EINVAL;
10332 if (seq->len == 0 || seq->len > 4)
10333 return -EINVAL;
10334 if (seq->len + seq->offset > data_size)
10335 return -EINVAL;
10336 }
10337
10338 size = sizeof(*cfg);
10339 size += data_size;
10340 size += wake_size + wake_mask_size;
10341 size += tokens_size;
10342
10343 cfg = kzalloc(size, GFP_KERNEL);
10344 if (!cfg)
10345 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010346 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10347 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010348 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10349 ETH_ALEN);
10350 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10351 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10352 else
10353 port = 0;
10354#ifdef CONFIG_INET
10355 /* allocate a socket and port for it and use it */
10356 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10357 IPPROTO_TCP, &cfg->sock, 1);
10358 if (err) {
10359 kfree(cfg);
10360 return err;
10361 }
10362 if (inet_csk_get_port(cfg->sock->sk, port)) {
10363 sock_release(cfg->sock);
10364 kfree(cfg);
10365 return -EADDRINUSE;
10366 }
10367 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10368#else
10369 if (!port) {
10370 kfree(cfg);
10371 return -EINVAL;
10372 }
10373 cfg->src_port = port;
10374#endif
10375
10376 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10377 cfg->payload_len = data_size;
10378 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10379 memcpy((void *)cfg->payload,
10380 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10381 data_size);
10382 if (seq)
10383 cfg->payload_seq = *seq;
10384 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10385 cfg->wake_len = wake_size;
10386 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10387 memcpy((void *)cfg->wake_data,
10388 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10389 wake_size);
10390 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10391 data_size + wake_size;
10392 memcpy((void *)cfg->wake_mask,
10393 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10394 wake_mask_size);
10395 if (tok) {
10396 cfg->tokens_size = tokens_size;
10397 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10398 }
10399
10400 trig->tcp = cfg;
10401
10402 return 0;
10403}
10404
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010405static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10406 const struct wiphy_wowlan_support *wowlan,
10407 struct nlattr *attr,
10408 struct cfg80211_wowlan *trig)
10409{
10410 struct nlattr **tb;
10411 int err;
10412
10413 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10414 if (!tb)
10415 return -ENOMEM;
10416
10417 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10418 err = -EOPNOTSUPP;
10419 goto out;
10420 }
10421
Johannes Bergfceb6432017-04-12 14:34:07 +020010422 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10423 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010424 if (err)
10425 goto out;
10426
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010427 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10428 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010429 err = PTR_ERR_OR_ZERO(trig->nd_config);
10430 if (err)
10431 trig->nd_config = NULL;
10432
10433out:
10434 kfree(tb);
10435 return err;
10436}
10437
Johannes Bergff1b6e62011-05-04 15:37:28 +020010438static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10439{
10440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10441 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010442 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010443 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010444 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010445 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010446 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010447 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010448
Johannes Berg964dc9e2013-06-03 17:25:34 +020010449 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010450 return -EOPNOTSUPP;
10451
Johannes Bergae33bd82012-07-12 16:25:02 +020010452 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10453 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010454 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010455 goto set_wakeup;
10456 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010457
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010458 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10459 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010460 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010461 if (err)
10462 return err;
10463
10464 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10465 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10466 return -EINVAL;
10467 new_triggers.any = true;
10468 }
10469
10470 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10471 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10472 return -EINVAL;
10473 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010474 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010475 }
10476
10477 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10478 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10479 return -EINVAL;
10480 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010481 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010482 }
10483
Johannes Berg77dbbb12011-07-13 10:48:55 +020010484 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10485 return -EINVAL;
10486
10487 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10488 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10489 return -EINVAL;
10490 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010491 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010492 }
10493
10494 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10495 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10496 return -EINVAL;
10497 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010498 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010499 }
10500
10501 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10502 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10503 return -EINVAL;
10504 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010505 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010506 }
10507
10508 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10509 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10510 return -EINVAL;
10511 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010512 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010513 }
10514
Johannes Bergff1b6e62011-05-04 15:37:28 +020010515 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10516 struct nlattr *pat;
10517 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010518 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010519 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010520
Johannes Berg98fc4382015-03-01 09:10:13 +020010521 regular = true;
10522
Johannes Bergff1b6e62011-05-04 15:37:28 +020010523 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10524 rem)
10525 n_patterns++;
10526 if (n_patterns > wowlan->n_patterns)
10527 return -EINVAL;
10528
10529 new_triggers.patterns = kcalloc(n_patterns,
10530 sizeof(new_triggers.patterns[0]),
10531 GFP_KERNEL);
10532 if (!new_triggers.patterns)
10533 return -ENOMEM;
10534
10535 new_triggers.n_patterns = n_patterns;
10536 i = 0;
10537
10538 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10539 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010540 u8 *mask_pat;
10541
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010542 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030010543 nl80211_packet_pattern_policy,
10544 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010545 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010546 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10547 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010548 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010549 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010550 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010551 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010552 goto error;
10553 if (pat_len > wowlan->pattern_max_len ||
10554 pat_len < wowlan->pattern_min_len)
10555 goto error;
10556
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010557 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010558 pkt_offset = 0;
10559 else
10560 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010561 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010562 if (pkt_offset > wowlan->max_pkt_offset)
10563 goto error;
10564 new_triggers.patterns[i].pkt_offset = pkt_offset;
10565
Johannes Berg922bd802014-05-19 17:59:50 +020010566 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10567 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010568 err = -ENOMEM;
10569 goto error;
10570 }
Johannes Berg922bd802014-05-19 17:59:50 +020010571 new_triggers.patterns[i].mask = mask_pat;
10572 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010573 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010574 mask_pat += mask_len;
10575 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010576 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010577 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010578 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010579 pat_len);
10580 i++;
10581 }
10582 }
10583
Johannes Berg2a0e0472013-01-23 22:57:40 +010010584 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010585 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010586 err = nl80211_parse_wowlan_tcp(
10587 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10588 &new_triggers);
10589 if (err)
10590 goto error;
10591 }
10592
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010593 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010594 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010595 err = nl80211_parse_wowlan_nd(
10596 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10597 &new_triggers);
10598 if (err)
10599 goto error;
10600 }
10601
Johannes Berg98fc4382015-03-01 09:10:13 +020010602 /* The 'any' trigger means the device continues operating more or less
10603 * as in its normal operation mode and wakes up the host on most of the
10604 * normal interrupts (like packet RX, ...)
10605 * It therefore makes little sense to combine with the more constrained
10606 * wakeup trigger modes.
10607 */
10608 if (new_triggers.any && regular) {
10609 err = -EINVAL;
10610 goto error;
10611 }
10612
Johannes Bergae33bd82012-07-12 16:25:02 +020010613 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10614 if (!ntrig) {
10615 err = -ENOMEM;
10616 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010617 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010618 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010619 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010620
Johannes Bergae33bd82012-07-12 16:25:02 +020010621 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010622 if (rdev->ops->set_wakeup &&
10623 prev_enabled != !!rdev->wiphy.wowlan_config)
10624 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010625
Johannes Bergff1b6e62011-05-04 15:37:28 +020010626 return 0;
10627 error:
10628 for (i = 0; i < new_triggers.n_patterns; i++)
10629 kfree(new_triggers.patterns[i].mask);
10630 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010631 if (new_triggers.tcp && new_triggers.tcp->sock)
10632 sock_release(new_triggers.tcp->sock);
10633 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010634 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010635 return err;
10636}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010637#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010638
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010639static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10640 struct cfg80211_registered_device *rdev)
10641{
10642 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10643 int i, j, pat_len;
10644 struct cfg80211_coalesce_rules *rule;
10645
10646 if (!rdev->coalesce->n_rules)
10647 return 0;
10648
10649 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10650 if (!nl_rules)
10651 return -ENOBUFS;
10652
10653 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10654 nl_rule = nla_nest_start(msg, i + 1);
10655 if (!nl_rule)
10656 return -ENOBUFS;
10657
10658 rule = &rdev->coalesce->rules[i];
10659 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10660 rule->delay))
10661 return -ENOBUFS;
10662
10663 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10664 rule->condition))
10665 return -ENOBUFS;
10666
10667 nl_pats = nla_nest_start(msg,
10668 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10669 if (!nl_pats)
10670 return -ENOBUFS;
10671
10672 for (j = 0; j < rule->n_patterns; j++) {
10673 nl_pat = nla_nest_start(msg, j + 1);
10674 if (!nl_pat)
10675 return -ENOBUFS;
10676 pat_len = rule->patterns[j].pattern_len;
10677 if (nla_put(msg, NL80211_PKTPAT_MASK,
10678 DIV_ROUND_UP(pat_len, 8),
10679 rule->patterns[j].mask) ||
10680 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10681 rule->patterns[j].pattern) ||
10682 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10683 rule->patterns[j].pkt_offset))
10684 return -ENOBUFS;
10685 nla_nest_end(msg, nl_pat);
10686 }
10687 nla_nest_end(msg, nl_pats);
10688 nla_nest_end(msg, nl_rule);
10689 }
10690 nla_nest_end(msg, nl_rules);
10691
10692 return 0;
10693}
10694
10695static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10696{
10697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10698 struct sk_buff *msg;
10699 void *hdr;
10700
10701 if (!rdev->wiphy.coalesce)
10702 return -EOPNOTSUPP;
10703
10704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10705 if (!msg)
10706 return -ENOMEM;
10707
10708 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10709 NL80211_CMD_GET_COALESCE);
10710 if (!hdr)
10711 goto nla_put_failure;
10712
10713 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10714 goto nla_put_failure;
10715
10716 genlmsg_end(msg, hdr);
10717 return genlmsg_reply(msg, info);
10718
10719nla_put_failure:
10720 nlmsg_free(msg);
10721 return -ENOBUFS;
10722}
10723
10724void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10725{
10726 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10727 int i, j;
10728 struct cfg80211_coalesce_rules *rule;
10729
10730 if (!coalesce)
10731 return;
10732
10733 for (i = 0; i < coalesce->n_rules; i++) {
10734 rule = &coalesce->rules[i];
10735 for (j = 0; j < rule->n_patterns; j++)
10736 kfree(rule->patterns[j].mask);
10737 kfree(rule->patterns);
10738 }
10739 kfree(coalesce->rules);
10740 kfree(coalesce);
10741 rdev->coalesce = NULL;
10742}
10743
10744static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10745 struct nlattr *rule,
10746 struct cfg80211_coalesce_rules *new_rule)
10747{
10748 int err, i;
10749 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10750 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10751 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10752 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10753
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010754 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010755 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010756 if (err)
10757 return err;
10758
10759 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10760 new_rule->delay =
10761 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10762 if (new_rule->delay > coalesce->max_delay)
10763 return -EINVAL;
10764
10765 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10766 new_rule->condition =
10767 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10768 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10769 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10770 return -EINVAL;
10771
10772 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10773 return -EINVAL;
10774
10775 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10776 rem)
10777 n_patterns++;
10778 if (n_patterns > coalesce->n_patterns)
10779 return -EINVAL;
10780
10781 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10782 GFP_KERNEL);
10783 if (!new_rule->patterns)
10784 return -ENOMEM;
10785
10786 new_rule->n_patterns = n_patterns;
10787 i = 0;
10788
10789 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10790 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010791 u8 *mask_pat;
10792
Peng Xuad670232017-10-03 23:21:51 +030010793 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10794 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010795 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10796 !pat_tb[NL80211_PKTPAT_PATTERN])
10797 return -EINVAL;
10798 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10799 mask_len = DIV_ROUND_UP(pat_len, 8);
10800 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10801 return -EINVAL;
10802 if (pat_len > coalesce->pattern_max_len ||
10803 pat_len < coalesce->pattern_min_len)
10804 return -EINVAL;
10805
10806 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10807 pkt_offset = 0;
10808 else
10809 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10810 if (pkt_offset > coalesce->max_pkt_offset)
10811 return -EINVAL;
10812 new_rule->patterns[i].pkt_offset = pkt_offset;
10813
Johannes Berg922bd802014-05-19 17:59:50 +020010814 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10815 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010816 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010817
10818 new_rule->patterns[i].mask = mask_pat;
10819 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10820 mask_len);
10821
10822 mask_pat += mask_len;
10823 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010824 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010825 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10826 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010827 i++;
10828 }
10829
10830 return 0;
10831}
10832
10833static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10834{
10835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10836 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10837 struct cfg80211_coalesce new_coalesce = {};
10838 struct cfg80211_coalesce *n_coalesce;
10839 int err, rem_rule, n_rules = 0, i, j;
10840 struct nlattr *rule;
10841 struct cfg80211_coalesce_rules *tmp_rule;
10842
10843 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10844 return -EOPNOTSUPP;
10845
10846 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10847 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010848 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010849 return 0;
10850 }
10851
10852 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10853 rem_rule)
10854 n_rules++;
10855 if (n_rules > coalesce->n_rules)
10856 return -EINVAL;
10857
10858 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10859 GFP_KERNEL);
10860 if (!new_coalesce.rules)
10861 return -ENOMEM;
10862
10863 new_coalesce.n_rules = n_rules;
10864 i = 0;
10865
10866 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10867 rem_rule) {
10868 err = nl80211_parse_coalesce_rule(rdev, rule,
10869 &new_coalesce.rules[i]);
10870 if (err)
10871 goto error;
10872
10873 i++;
10874 }
10875
Ilan Peera1056b1b2015-10-22 22:27:46 +030010876 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010877 if (err)
10878 goto error;
10879
10880 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10881 if (!n_coalesce) {
10882 err = -ENOMEM;
10883 goto error;
10884 }
10885 cfg80211_rdev_free_coalesce(rdev);
10886 rdev->coalesce = n_coalesce;
10887
10888 return 0;
10889error:
10890 for (i = 0; i < new_coalesce.n_rules; i++) {
10891 tmp_rule = &new_coalesce.rules[i];
10892 for (j = 0; j < tmp_rule->n_patterns; j++)
10893 kfree(tmp_rule->patterns[j].mask);
10894 kfree(tmp_rule->patterns);
10895 }
10896 kfree(new_coalesce.rules);
10897
10898 return err;
10899}
10900
Johannes Berge5497d72011-07-05 16:35:40 +020010901static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10902{
10903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10904 struct net_device *dev = info->user_ptr[1];
10905 struct wireless_dev *wdev = dev->ieee80211_ptr;
10906 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10907 struct cfg80211_gtk_rekey_data rekey_data;
10908 int err;
10909
10910 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10911 return -EINVAL;
10912
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010913 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10914 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020010915 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020010916 if (err)
10917 return err;
10918
Vladis Dronove785fa02017-09-13 00:21:21 +020010919 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
10920 !tb[NL80211_REKEY_DATA_KCK])
10921 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020010922 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10923 return -ERANGE;
10924 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10925 return -ERANGE;
10926 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10927 return -ERANGE;
10928
Johannes Berg78f686c2014-09-10 22:28:06 +030010929 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10930 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10931 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010932
10933 wdev_lock(wdev);
10934 if (!wdev->current_bss) {
10935 err = -ENOTCONN;
10936 goto out;
10937 }
10938
10939 if (!rdev->ops->set_rekey_data) {
10940 err = -EOPNOTSUPP;
10941 goto out;
10942 }
10943
Hila Gonene35e4d22012-06-27 17:19:42 +030010944 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010945 out:
10946 wdev_unlock(wdev);
10947 return err;
10948}
10949
Johannes Berg28946da2011-11-04 11:18:12 +010010950static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10951 struct genl_info *info)
10952{
10953 struct net_device *dev = info->user_ptr[1];
10954 struct wireless_dev *wdev = dev->ieee80211_ptr;
10955
10956 if (wdev->iftype != NL80211_IFTYPE_AP &&
10957 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10958 return -EINVAL;
10959
Eric W. Biederman15e47302012-09-07 20:12:54 +000010960 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010961 return -EBUSY;
10962
Eric W. Biederman15e47302012-09-07 20:12:54 +000010963 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010964 return 0;
10965}
10966
Johannes Berg7f6cf312011-11-04 11:18:15 +010010967static int nl80211_probe_client(struct sk_buff *skb,
10968 struct genl_info *info)
10969{
10970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10971 struct net_device *dev = info->user_ptr[1];
10972 struct wireless_dev *wdev = dev->ieee80211_ptr;
10973 struct sk_buff *msg;
10974 void *hdr;
10975 const u8 *addr;
10976 u64 cookie;
10977 int err;
10978
10979 if (wdev->iftype != NL80211_IFTYPE_AP &&
10980 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10981 return -EOPNOTSUPP;
10982
10983 if (!info->attrs[NL80211_ATTR_MAC])
10984 return -EINVAL;
10985
10986 if (!rdev->ops->probe_client)
10987 return -EOPNOTSUPP;
10988
10989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10990 if (!msg)
10991 return -ENOMEM;
10992
Eric W. Biederman15e47302012-09-07 20:12:54 +000010993 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010994 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010995 if (!hdr) {
10996 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010997 goto free_msg;
10998 }
10999
11000 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11001
Hila Gonene35e4d22012-06-27 17:19:42 +030011002 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011003 if (err)
11004 goto free_msg;
11005
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011006 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11007 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011008 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011009
11010 genlmsg_end(msg, hdr);
11011
11012 return genlmsg_reply(msg, info);
11013
11014 nla_put_failure:
11015 err = -ENOBUFS;
11016 free_msg:
11017 nlmsg_free(msg);
11018 return err;
11019}
11020
Johannes Berg5e760232011-11-04 11:18:17 +010011021static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11022{
11023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011024 struct cfg80211_beacon_registration *reg, *nreg;
11025 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011026
11027 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11028 return -EOPNOTSUPP;
11029
Ben Greear37c73b52012-10-26 14:49:25 -070011030 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11031 if (!nreg)
11032 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011033
Ben Greear37c73b52012-10-26 14:49:25 -070011034 /* First, check if already registered. */
11035 spin_lock_bh(&rdev->beacon_registrations_lock);
11036 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11037 if (reg->nlportid == info->snd_portid) {
11038 rv = -EALREADY;
11039 goto out_err;
11040 }
11041 }
11042 /* Add it to the list */
11043 nreg->nlportid = info->snd_portid;
11044 list_add(&nreg->list, &rdev->beacon_registrations);
11045
11046 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011047
11048 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011049out_err:
11050 spin_unlock_bh(&rdev->beacon_registrations_lock);
11051 kfree(nreg);
11052 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011053}
11054
Johannes Berg98104fde2012-06-16 00:19:54 +020011055static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11056{
11057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11058 struct wireless_dev *wdev = info->user_ptr[1];
11059 int err;
11060
11061 if (!rdev->ops->start_p2p_device)
11062 return -EOPNOTSUPP;
11063
11064 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11065 return -EOPNOTSUPP;
11066
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011067 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011068 return 0;
11069
Luciano Coelhob6a55012014-02-27 11:07:21 +020011070 if (rfkill_blocked(rdev->rfkill))
11071 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011072
Johannes Bergeeb126e2012-10-23 15:16:50 +020011073 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011074 if (err)
11075 return err;
11076
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011077 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011078 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011079
11080 return 0;
11081}
11082
11083static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11084{
11085 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11086 struct wireless_dev *wdev = info->user_ptr[1];
11087
11088 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11089 return -EOPNOTSUPP;
11090
11091 if (!rdev->ops->stop_p2p_device)
11092 return -EOPNOTSUPP;
11093
Johannes Bergf9f47522013-03-19 15:04:07 +010011094 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011095
11096 return 0;
11097}
11098
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011099static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11100{
11101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11102 struct wireless_dev *wdev = info->user_ptr[1];
11103 struct cfg80211_nan_conf conf = {};
11104 int err;
11105
11106 if (wdev->iftype != NL80211_IFTYPE_NAN)
11107 return -EOPNOTSUPP;
11108
Johannes Bergeeb04a92016-11-21 13:55:48 +010011109 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011110 return -EEXIST;
11111
11112 if (rfkill_blocked(rdev->rfkill))
11113 return -ERFKILL;
11114
11115 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11116 return -EINVAL;
11117
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011118 conf.master_pref =
11119 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11120 if (!conf.master_pref)
11121 return -EINVAL;
11122
Luca Coelho85859892017-02-08 15:00:34 +020011123 if (info->attrs[NL80211_ATTR_BANDS]) {
11124 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11125
11126 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11127 return -EOPNOTSUPP;
11128
11129 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11130 return -EINVAL;
11131
11132 conf.bands = bands;
11133 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011134
11135 err = rdev_start_nan(rdev, wdev, &conf);
11136 if (err)
11137 return err;
11138
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011139 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011140 rdev->opencount++;
11141
11142 return 0;
11143}
11144
11145static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11146{
11147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11148 struct wireless_dev *wdev = info->user_ptr[1];
11149
11150 if (wdev->iftype != NL80211_IFTYPE_NAN)
11151 return -EOPNOTSUPP;
11152
11153 cfg80211_stop_nan(rdev, wdev);
11154
11155 return 0;
11156}
11157
Ayala Bekera442b762016-09-20 17:31:15 +030011158static int validate_nan_filter(struct nlattr *filter_attr)
11159{
11160 struct nlattr *attr;
11161 int len = 0, n_entries = 0, rem;
11162
11163 nla_for_each_nested(attr, filter_attr, rem) {
11164 len += nla_len(attr);
11165 n_entries++;
11166 }
11167
11168 if (len >= U8_MAX)
11169 return -EINVAL;
11170
11171 return n_entries;
11172}
11173
11174static int handle_nan_filter(struct nlattr *attr_filter,
11175 struct cfg80211_nan_func *func,
11176 bool tx)
11177{
11178 struct nlattr *attr;
11179 int n_entries, rem, i;
11180 struct cfg80211_nan_func_filter *filter;
11181
11182 n_entries = validate_nan_filter(attr_filter);
11183 if (n_entries < 0)
11184 return n_entries;
11185
11186 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11187
11188 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11189 if (!filter)
11190 return -ENOMEM;
11191
11192 i = 0;
11193 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011194 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011195 filter[i].len = nla_len(attr);
11196 i++;
11197 }
11198 if (tx) {
11199 func->num_tx_filters = n_entries;
11200 func->tx_filters = filter;
11201 } else {
11202 func->num_rx_filters = n_entries;
11203 func->rx_filters = filter;
11204 }
11205
11206 return 0;
11207}
11208
11209static int nl80211_nan_add_func(struct sk_buff *skb,
11210 struct genl_info *info)
11211{
11212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11213 struct wireless_dev *wdev = info->user_ptr[1];
11214 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11215 struct cfg80211_nan_func *func;
11216 struct sk_buff *msg = NULL;
11217 void *hdr = NULL;
11218 int err = 0;
11219
11220 if (wdev->iftype != NL80211_IFTYPE_NAN)
11221 return -EOPNOTSUPP;
11222
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011223 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011224 return -ENOTCONN;
11225
11226 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11227 return -EINVAL;
11228
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011229 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11230 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011231 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011232 if (err)
11233 return err;
11234
11235 func = kzalloc(sizeof(*func), GFP_KERNEL);
11236 if (!func)
11237 return -ENOMEM;
11238
11239 func->cookie = wdev->wiphy->cookie_counter++;
11240
11241 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11242 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11243 err = -EINVAL;
11244 goto out;
11245 }
11246
11247
11248 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11249
11250 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11251 err = -EINVAL;
11252 goto out;
11253 }
11254
11255 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11256 sizeof(func->service_id));
11257
11258 func->close_range =
11259 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11260
11261 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11262 func->serv_spec_info_len =
11263 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11264 func->serv_spec_info =
11265 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11266 func->serv_spec_info_len,
11267 GFP_KERNEL);
11268 if (!func->serv_spec_info) {
11269 err = -ENOMEM;
11270 goto out;
11271 }
11272 }
11273
11274 if (tb[NL80211_NAN_FUNC_TTL])
11275 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11276
11277 switch (func->type) {
11278 case NL80211_NAN_FUNC_PUBLISH:
11279 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11280 err = -EINVAL;
11281 goto out;
11282 }
11283
11284 func->publish_type =
11285 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11286 func->publish_bcast =
11287 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11288
11289 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11290 func->publish_bcast) {
11291 err = -EINVAL;
11292 goto out;
11293 }
11294 break;
11295 case NL80211_NAN_FUNC_SUBSCRIBE:
11296 func->subscribe_active =
11297 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11298 break;
11299 case NL80211_NAN_FUNC_FOLLOW_UP:
11300 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11301 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11302 err = -EINVAL;
11303 goto out;
11304 }
11305
11306 func->followup_id =
11307 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11308 func->followup_reqid =
11309 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11310 memcpy(func->followup_dest.addr,
11311 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11312 sizeof(func->followup_dest.addr));
11313 if (func->ttl) {
11314 err = -EINVAL;
11315 goto out;
11316 }
11317 break;
11318 default:
11319 err = -EINVAL;
11320 goto out;
11321 }
11322
11323 if (tb[NL80211_NAN_FUNC_SRF]) {
11324 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11325
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011326 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11327 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011328 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011329 if (err)
11330 goto out;
11331
11332 func->srf_include =
11333 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11334
11335 if (srf_tb[NL80211_NAN_SRF_BF]) {
11336 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11337 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11338 err = -EINVAL;
11339 goto out;
11340 }
11341
11342 func->srf_bf_len =
11343 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11344 func->srf_bf =
11345 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11346 func->srf_bf_len, GFP_KERNEL);
11347 if (!func->srf_bf) {
11348 err = -ENOMEM;
11349 goto out;
11350 }
11351
11352 func->srf_bf_idx =
11353 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11354 } else {
11355 struct nlattr *attr, *mac_attr =
11356 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11357 int n_entries, rem, i = 0;
11358
11359 if (!mac_attr) {
11360 err = -EINVAL;
11361 goto out;
11362 }
11363
11364 n_entries = validate_acl_mac_addrs(mac_attr);
11365 if (n_entries <= 0) {
11366 err = -EINVAL;
11367 goto out;
11368 }
11369
11370 func->srf_num_macs = n_entries;
11371 func->srf_macs =
11372 kzalloc(sizeof(*func->srf_macs) * n_entries,
11373 GFP_KERNEL);
11374 if (!func->srf_macs) {
11375 err = -ENOMEM;
11376 goto out;
11377 }
11378
11379 nla_for_each_nested(attr, mac_attr, rem)
11380 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11381 sizeof(*func->srf_macs));
11382 }
11383 }
11384
11385 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11386 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11387 func, true);
11388 if (err)
11389 goto out;
11390 }
11391
11392 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11393 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11394 func, false);
11395 if (err)
11396 goto out;
11397 }
11398
11399 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11400 if (!msg) {
11401 err = -ENOMEM;
11402 goto out;
11403 }
11404
11405 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11406 NL80211_CMD_ADD_NAN_FUNCTION);
11407 /* This can't really happen - we just allocated 4KB */
11408 if (WARN_ON(!hdr)) {
11409 err = -ENOMEM;
11410 goto out;
11411 }
11412
11413 err = rdev_add_nan_func(rdev, wdev, func);
11414out:
11415 if (err < 0) {
11416 cfg80211_free_nan_func(func);
11417 nlmsg_free(msg);
11418 return err;
11419 }
11420
11421 /* propagate the instance id and cookie to userspace */
11422 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11423 NL80211_ATTR_PAD))
11424 goto nla_put_failure;
11425
11426 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11427 if (!func_attr)
11428 goto nla_put_failure;
11429
11430 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11431 func->instance_id))
11432 goto nla_put_failure;
11433
11434 nla_nest_end(msg, func_attr);
11435
11436 genlmsg_end(msg, hdr);
11437 return genlmsg_reply(msg, info);
11438
11439nla_put_failure:
11440 nlmsg_free(msg);
11441 return -ENOBUFS;
11442}
11443
11444static int nl80211_nan_del_func(struct sk_buff *skb,
11445 struct genl_info *info)
11446{
11447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11448 struct wireless_dev *wdev = info->user_ptr[1];
11449 u64 cookie;
11450
11451 if (wdev->iftype != NL80211_IFTYPE_NAN)
11452 return -EOPNOTSUPP;
11453
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011454 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011455 return -ENOTCONN;
11456
11457 if (!info->attrs[NL80211_ATTR_COOKIE])
11458 return -EINVAL;
11459
Ayala Bekera442b762016-09-20 17:31:15 +030011460 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11461
11462 rdev_del_nan_func(rdev, wdev, cookie);
11463
11464 return 0;
11465}
11466
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011467static int nl80211_nan_change_config(struct sk_buff *skb,
11468 struct genl_info *info)
11469{
11470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11471 struct wireless_dev *wdev = info->user_ptr[1];
11472 struct cfg80211_nan_conf conf = {};
11473 u32 changed = 0;
11474
11475 if (wdev->iftype != NL80211_IFTYPE_NAN)
11476 return -EOPNOTSUPP;
11477
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011478 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011479 return -ENOTCONN;
11480
11481 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11482 conf.master_pref =
11483 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11484 if (conf.master_pref <= 1 || conf.master_pref == 255)
11485 return -EINVAL;
11486
11487 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11488 }
11489
Luca Coelho85859892017-02-08 15:00:34 +020011490 if (info->attrs[NL80211_ATTR_BANDS]) {
11491 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11492
11493 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11494 return -EOPNOTSUPP;
11495
11496 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11497 return -EINVAL;
11498
11499 conf.bands = bands;
11500 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011501 }
11502
11503 if (!changed)
11504 return -EINVAL;
11505
11506 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11507}
11508
Ayala Beker50bcd312016-09-20 17:31:17 +030011509void cfg80211_nan_match(struct wireless_dev *wdev,
11510 struct cfg80211_nan_match_params *match, gfp_t gfp)
11511{
11512 struct wiphy *wiphy = wdev->wiphy;
11513 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11514 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11515 struct sk_buff *msg;
11516 void *hdr;
11517
11518 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11519 return;
11520
11521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11522 if (!msg)
11523 return;
11524
11525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11526 if (!hdr) {
11527 nlmsg_free(msg);
11528 return;
11529 }
11530
11531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11532 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11533 wdev->netdev->ifindex)) ||
11534 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11535 NL80211_ATTR_PAD))
11536 goto nla_put_failure;
11537
11538 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11539 NL80211_ATTR_PAD) ||
11540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11541 goto nla_put_failure;
11542
11543 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11544 if (!match_attr)
11545 goto nla_put_failure;
11546
11547 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11548 if (!local_func_attr)
11549 goto nla_put_failure;
11550
11551 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11552 goto nla_put_failure;
11553
11554 nla_nest_end(msg, local_func_attr);
11555
11556 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11557 if (!peer_func_attr)
11558 goto nla_put_failure;
11559
11560 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11561 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11562 goto nla_put_failure;
11563
11564 if (match->info && match->info_len &&
11565 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11566 match->info))
11567 goto nla_put_failure;
11568
11569 nla_nest_end(msg, peer_func_attr);
11570 nla_nest_end(msg, match_attr);
11571 genlmsg_end(msg, hdr);
11572
11573 if (!wdev->owner_nlportid)
11574 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11575 msg, 0, NL80211_MCGRP_NAN, gfp);
11576 else
11577 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11578 wdev->owner_nlportid);
11579
11580 return;
11581
11582nla_put_failure:
11583 nlmsg_free(msg);
11584}
11585EXPORT_SYMBOL(cfg80211_nan_match);
11586
Ayala Beker368e5a72016-09-20 17:31:18 +030011587void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11588 u8 inst_id,
11589 enum nl80211_nan_func_term_reason reason,
11590 u64 cookie, gfp_t gfp)
11591{
11592 struct wiphy *wiphy = wdev->wiphy;
11593 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11594 struct sk_buff *msg;
11595 struct nlattr *func_attr;
11596 void *hdr;
11597
11598 if (WARN_ON(!inst_id))
11599 return;
11600
11601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11602 if (!msg)
11603 return;
11604
11605 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11606 if (!hdr) {
11607 nlmsg_free(msg);
11608 return;
11609 }
11610
11611 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11612 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11613 wdev->netdev->ifindex)) ||
11614 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11615 NL80211_ATTR_PAD))
11616 goto nla_put_failure;
11617
11618 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11619 NL80211_ATTR_PAD))
11620 goto nla_put_failure;
11621
11622 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11623 if (!func_attr)
11624 goto nla_put_failure;
11625
11626 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11627 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11628 goto nla_put_failure;
11629
11630 nla_nest_end(msg, func_attr);
11631 genlmsg_end(msg, hdr);
11632
11633 if (!wdev->owner_nlportid)
11634 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11635 msg, 0, NL80211_MCGRP_NAN, gfp);
11636 else
11637 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11638 wdev->owner_nlportid);
11639
11640 return;
11641
11642nla_put_failure:
11643 nlmsg_free(msg);
11644}
11645EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11646
Johannes Berg3713b4e2013-02-14 16:19:38 +010011647static int nl80211_get_protocol_features(struct sk_buff *skb,
11648 struct genl_info *info)
11649{
11650 void *hdr;
11651 struct sk_buff *msg;
11652
11653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11654 if (!msg)
11655 return -ENOMEM;
11656
11657 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11658 NL80211_CMD_GET_PROTOCOL_FEATURES);
11659 if (!hdr)
11660 goto nla_put_failure;
11661
11662 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11663 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11664 goto nla_put_failure;
11665
11666 genlmsg_end(msg, hdr);
11667 return genlmsg_reply(msg, info);
11668
11669 nla_put_failure:
11670 kfree_skb(msg);
11671 return -ENOBUFS;
11672}
11673
Jouni Malinen355199e2013-02-27 17:14:27 +020011674static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11675{
11676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11677 struct cfg80211_update_ft_ies_params ft_params;
11678 struct net_device *dev = info->user_ptr[1];
11679
11680 if (!rdev->ops->update_ft_ies)
11681 return -EOPNOTSUPP;
11682
11683 if (!info->attrs[NL80211_ATTR_MDID] ||
11684 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11685 return -EINVAL;
11686
11687 memset(&ft_params, 0, sizeof(ft_params));
11688 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11689 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11690 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11691
11692 return rdev_update_ft_ies(rdev, dev, &ft_params);
11693}
11694
Arend van Spriel5de17982013-04-18 15:49:00 +020011695static int nl80211_crit_protocol_start(struct sk_buff *skb,
11696 struct genl_info *info)
11697{
11698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11699 struct wireless_dev *wdev = info->user_ptr[1];
11700 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11701 u16 duration;
11702 int ret;
11703
11704 if (!rdev->ops->crit_proto_start)
11705 return -EOPNOTSUPP;
11706
11707 if (WARN_ON(!rdev->ops->crit_proto_stop))
11708 return -EINVAL;
11709
11710 if (rdev->crit_proto_nlportid)
11711 return -EBUSY;
11712
11713 /* determine protocol if provided */
11714 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11715 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11716
11717 if (proto >= NUM_NL80211_CRIT_PROTO)
11718 return -EINVAL;
11719
11720 /* timeout must be provided */
11721 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11722 return -EINVAL;
11723
11724 duration =
11725 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11726
11727 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11728 return -ERANGE;
11729
11730 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11731 if (!ret)
11732 rdev->crit_proto_nlportid = info->snd_portid;
11733
11734 return ret;
11735}
11736
11737static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11738 struct genl_info *info)
11739{
11740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11741 struct wireless_dev *wdev = info->user_ptr[1];
11742
11743 if (!rdev->ops->crit_proto_stop)
11744 return -EOPNOTSUPP;
11745
11746 if (rdev->crit_proto_nlportid) {
11747 rdev->crit_proto_nlportid = 0;
11748 rdev_crit_proto_stop(rdev, wdev);
11749 }
11750 return 0;
11751}
11752
Johannes Bergad7e7182013-11-13 13:37:47 +010011753static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11754{
11755 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11756 struct wireless_dev *wdev =
11757 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11758 int i, err;
11759 u32 vid, subcmd;
11760
11761 if (!rdev->wiphy.vendor_commands)
11762 return -EOPNOTSUPP;
11763
11764 if (IS_ERR(wdev)) {
11765 err = PTR_ERR(wdev);
11766 if (err != -EINVAL)
11767 return err;
11768 wdev = NULL;
11769 } else if (wdev->wiphy != &rdev->wiphy) {
11770 return -EINVAL;
11771 }
11772
11773 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11774 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11775 return -EINVAL;
11776
11777 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11778 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11779 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11780 const struct wiphy_vendor_command *vcmd;
11781 void *data = NULL;
11782 int len = 0;
11783
11784 vcmd = &rdev->wiphy.vendor_commands[i];
11785
11786 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11787 continue;
11788
11789 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11790 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11791 if (!wdev)
11792 return -EINVAL;
11793 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11794 !wdev->netdev)
11795 return -EINVAL;
11796
11797 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011798 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011799 return -ENETDOWN;
11800 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011801
11802 if (!vcmd->doit)
11803 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011804 } else {
11805 wdev = NULL;
11806 }
11807
11808 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11809 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11810 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11811 }
11812
11813 rdev->cur_cmd_info = info;
11814 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11815 data, len);
11816 rdev->cur_cmd_info = NULL;
11817 return err;
11818 }
11819
11820 return -EOPNOTSUPP;
11821}
11822
Johannes Berg7bdbe402015-08-15 22:39:49 +030011823static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11824 struct netlink_callback *cb,
11825 struct cfg80211_registered_device **rdev,
11826 struct wireless_dev **wdev)
11827{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011828 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011829 u32 vid, subcmd;
11830 unsigned int i;
11831 int vcmd_idx = -1;
11832 int err;
11833 void *data = NULL;
11834 unsigned int data_len = 0;
11835
Johannes Berg7bdbe402015-08-15 22:39:49 +030011836 if (cb->args[0]) {
11837 /* subtract the 1 again here */
11838 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11839 struct wireless_dev *tmp;
11840
Johannes Bergea90e0d2017-03-15 14:26:04 +010011841 if (!wiphy)
11842 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011843 *rdev = wiphy_to_rdev(wiphy);
11844 *wdev = NULL;
11845
11846 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011847 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011848 if (tmp->identifier == cb->args[1] - 1) {
11849 *wdev = tmp;
11850 break;
11851 }
11852 }
11853 }
11854
11855 /* keep rtnl locked in successful case */
11856 return 0;
11857 }
11858
Johannes Bergfceb6432017-04-12 14:34:07 +020011859 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11860 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011861 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011862 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011863
Johannes Bergc90c39d2016-10-24 14:40:01 +020011864 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011865 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11866 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011867
Johannes Bergc90c39d2016-10-24 14:40:01 +020011868 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011869 if (IS_ERR(*wdev))
11870 *wdev = NULL;
11871
Johannes Bergc90c39d2016-10-24 14:40:01 +020011872 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011873 if (IS_ERR(*rdev))
11874 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011875
Johannes Bergc90c39d2016-10-24 14:40:01 +020011876 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11877 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011878
11879 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11880 const struct wiphy_vendor_command *vcmd;
11881
11882 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11883
11884 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11885 continue;
11886
Johannes Bergea90e0d2017-03-15 14:26:04 +010011887 if (!vcmd->dumpit)
11888 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011889
11890 vcmd_idx = i;
11891 break;
11892 }
11893
Johannes Bergea90e0d2017-03-15 14:26:04 +010011894 if (vcmd_idx < 0)
11895 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011896
Johannes Bergc90c39d2016-10-24 14:40:01 +020011897 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11898 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11899 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011900 }
11901
11902 /* 0 is the first index - add 1 to parse only once */
11903 cb->args[0] = (*rdev)->wiphy_idx + 1;
11904 /* add 1 to know if it was NULL */
11905 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11906 cb->args[2] = vcmd_idx;
11907 cb->args[3] = (unsigned long)data;
11908 cb->args[4] = data_len;
11909
11910 /* keep rtnl locked in successful case */
11911 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011912}
11913
11914static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11915 struct netlink_callback *cb)
11916{
11917 struct cfg80211_registered_device *rdev;
11918 struct wireless_dev *wdev;
11919 unsigned int vcmd_idx;
11920 const struct wiphy_vendor_command *vcmd;
11921 void *data;
11922 int data_len;
11923 int err;
11924 struct nlattr *vendor_data;
11925
Johannes Bergea90e0d2017-03-15 14:26:04 +010011926 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011927 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11928 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011929 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011930
11931 vcmd_idx = cb->args[2];
11932 data = (void *)cb->args[3];
11933 data_len = cb->args[4];
11934 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11935
11936 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11937 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011938 if (!wdev) {
11939 err = -EINVAL;
11940 goto out;
11941 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011942 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010011943 !wdev->netdev) {
11944 err = -EINVAL;
11945 goto out;
11946 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011947
11948 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011949 if (!wdev_running(wdev)) {
11950 err = -ENETDOWN;
11951 goto out;
11952 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011953 }
11954 }
11955
11956 while (1) {
11957 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11958 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11959 NL80211_CMD_VENDOR);
11960 if (!hdr)
11961 break;
11962
11963 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011964 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11965 wdev_id(wdev),
11966 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011967 genlmsg_cancel(skb, hdr);
11968 break;
11969 }
11970
11971 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11972 if (!vendor_data) {
11973 genlmsg_cancel(skb, hdr);
11974 break;
11975 }
11976
11977 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11978 (unsigned long *)&cb->args[5]);
11979 nla_nest_end(skb, vendor_data);
11980
11981 if (err == -ENOBUFS || err == -ENOENT) {
11982 genlmsg_cancel(skb, hdr);
11983 break;
11984 } else if (err) {
11985 genlmsg_cancel(skb, hdr);
11986 goto out;
11987 }
11988
11989 genlmsg_end(skb, hdr);
11990 }
11991
11992 err = skb->len;
11993 out:
11994 rtnl_unlock();
11995 return err;
11996}
11997
Johannes Bergad7e7182013-11-13 13:37:47 +010011998struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11999 enum nl80211_commands cmd,
12000 enum nl80211_attrs attr,
12001 int approxlen)
12002{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012003 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012004
12005 if (WARN_ON(!rdev->cur_cmd_info))
12006 return NULL;
12007
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012008 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012009 rdev->cur_cmd_info->snd_portid,
12010 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012011 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012012}
12013EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12014
12015int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12016{
12017 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12018 void *hdr = ((void **)skb->cb)[1];
12019 struct nlattr *data = ((void **)skb->cb)[2];
12020
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012021 /* clear CB data for netlink core to own from now on */
12022 memset(skb->cb, 0, sizeof(skb->cb));
12023
Johannes Bergad7e7182013-11-13 13:37:47 +010012024 if (WARN_ON(!rdev->cur_cmd_info)) {
12025 kfree_skb(skb);
12026 return -EINVAL;
12027 }
12028
12029 nla_nest_end(skb, data);
12030 genlmsg_end(skb, hdr);
12031 return genlmsg_reply(skb, rdev->cur_cmd_info);
12032}
12033EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12034
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012035static int nl80211_set_qos_map(struct sk_buff *skb,
12036 struct genl_info *info)
12037{
12038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12039 struct cfg80211_qos_map *qos_map = NULL;
12040 struct net_device *dev = info->user_ptr[1];
12041 u8 *pos, len, num_des, des_len, des;
12042 int ret;
12043
12044 if (!rdev->ops->set_qos_map)
12045 return -EOPNOTSUPP;
12046
12047 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12048 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12049 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12050
12051 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12052 len > IEEE80211_QOS_MAP_LEN_MAX)
12053 return -EINVAL;
12054
12055 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12056 if (!qos_map)
12057 return -ENOMEM;
12058
12059 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12060 if (num_des) {
12061 des_len = num_des *
12062 sizeof(struct cfg80211_dscp_exception);
12063 memcpy(qos_map->dscp_exception, pos, des_len);
12064 qos_map->num_des = num_des;
12065 for (des = 0; des < num_des; des++) {
12066 if (qos_map->dscp_exception[des].up > 7) {
12067 kfree(qos_map);
12068 return -EINVAL;
12069 }
12070 }
12071 pos += des_len;
12072 }
12073 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12074 }
12075
12076 wdev_lock(dev->ieee80211_ptr);
12077 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12078 if (!ret)
12079 ret = rdev_set_qos_map(rdev, dev, qos_map);
12080 wdev_unlock(dev->ieee80211_ptr);
12081
12082 kfree(qos_map);
12083 return ret;
12084}
12085
Johannes Berg960d01a2014-09-09 22:55:35 +030012086static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12087{
12088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12089 struct net_device *dev = info->user_ptr[1];
12090 struct wireless_dev *wdev = dev->ieee80211_ptr;
12091 const u8 *peer;
12092 u8 tsid, up;
12093 u16 admitted_time = 0;
12094 int err;
12095
Johannes Berg723e73a2014-10-22 09:25:06 +020012096 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012097 return -EOPNOTSUPP;
12098
12099 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12100 !info->attrs[NL80211_ATTR_USER_PRIO])
12101 return -EINVAL;
12102
12103 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12104 if (tsid >= IEEE80211_NUM_TIDS)
12105 return -EINVAL;
12106
12107 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12108 if (up >= IEEE80211_NUM_UPS)
12109 return -EINVAL;
12110
12111 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012112 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012113 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012114 * need more attributes for that (e.g. BA session requirement);
12115 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012116 */
12117 return -EINVAL;
12118 }
12119
12120 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12121
12122 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12123 admitted_time =
12124 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12125 if (!admitted_time)
12126 return -EINVAL;
12127 }
12128
12129 wdev_lock(wdev);
12130 switch (wdev->iftype) {
12131 case NL80211_IFTYPE_STATION:
12132 case NL80211_IFTYPE_P2P_CLIENT:
12133 if (wdev->current_bss)
12134 break;
12135 err = -ENOTCONN;
12136 goto out;
12137 default:
12138 err = -EOPNOTSUPP;
12139 goto out;
12140 }
12141
12142 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12143
12144 out:
12145 wdev_unlock(wdev);
12146 return err;
12147}
12148
12149static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12150{
12151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12152 struct net_device *dev = info->user_ptr[1];
12153 struct wireless_dev *wdev = dev->ieee80211_ptr;
12154 const u8 *peer;
12155 u8 tsid;
12156 int err;
12157
12158 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12159 return -EINVAL;
12160
12161 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12162 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12163
12164 wdev_lock(wdev);
12165 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12166 wdev_unlock(wdev);
12167
12168 return err;
12169}
12170
Arik Nemtsov1057d352014-11-19 12:54:26 +020012171static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12172 struct genl_info *info)
12173{
12174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12175 struct net_device *dev = info->user_ptr[1];
12176 struct wireless_dev *wdev = dev->ieee80211_ptr;
12177 struct cfg80211_chan_def chandef = {};
12178 const u8 *addr;
12179 u8 oper_class;
12180 int err;
12181
12182 if (!rdev->ops->tdls_channel_switch ||
12183 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12184 return -EOPNOTSUPP;
12185
12186 switch (dev->ieee80211_ptr->iftype) {
12187 case NL80211_IFTYPE_STATION:
12188 case NL80211_IFTYPE_P2P_CLIENT:
12189 break;
12190 default:
12191 return -EOPNOTSUPP;
12192 }
12193
12194 if (!info->attrs[NL80211_ATTR_MAC] ||
12195 !info->attrs[NL80211_ATTR_OPER_CLASS])
12196 return -EINVAL;
12197
12198 err = nl80211_parse_chandef(rdev, info, &chandef);
12199 if (err)
12200 return err;
12201
12202 /*
12203 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12204 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12205 * specification is not defined for them.
12206 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012207 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012208 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12209 chandef.width != NL80211_CHAN_WIDTH_20)
12210 return -EINVAL;
12211
12212 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012213 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12214 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012215 return -EINVAL;
12216
12217 /* don't allow switching to DFS channels */
12218 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12219 return -EINVAL;
12220
12221 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12222 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12223
12224 wdev_lock(wdev);
12225 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12226 wdev_unlock(wdev);
12227
12228 return err;
12229}
12230
12231static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12232 struct genl_info *info)
12233{
12234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12235 struct net_device *dev = info->user_ptr[1];
12236 struct wireless_dev *wdev = dev->ieee80211_ptr;
12237 const u8 *addr;
12238
12239 if (!rdev->ops->tdls_channel_switch ||
12240 !rdev->ops->tdls_cancel_channel_switch ||
12241 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12242 return -EOPNOTSUPP;
12243
12244 switch (dev->ieee80211_ptr->iftype) {
12245 case NL80211_IFTYPE_STATION:
12246 case NL80211_IFTYPE_P2P_CLIENT:
12247 break;
12248 default:
12249 return -EOPNOTSUPP;
12250 }
12251
12252 if (!info->attrs[NL80211_ATTR_MAC])
12253 return -EINVAL;
12254
12255 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12256
12257 wdev_lock(wdev);
12258 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12259 wdev_unlock(wdev);
12260
12261 return 0;
12262}
12263
Michael Braunce0ce132016-10-10 19:12:22 +020012264static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12265 struct genl_info *info)
12266{
12267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12268 struct net_device *dev = info->user_ptr[1];
12269 struct wireless_dev *wdev = dev->ieee80211_ptr;
12270 const struct nlattr *nla;
12271 bool enabled;
12272
Michael Braunce0ce132016-10-10 19:12:22 +020012273 if (!rdev->ops->set_multicast_to_unicast)
12274 return -EOPNOTSUPP;
12275
12276 if (wdev->iftype != NL80211_IFTYPE_AP &&
12277 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12278 return -EOPNOTSUPP;
12279
12280 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12281 enabled = nla_get_flag(nla);
12282
12283 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12284}
12285
Avraham Stern3a00df52017-06-09 13:08:43 +010012286static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12287{
12288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12289 struct net_device *dev = info->user_ptr[1];
12290 struct wireless_dev *wdev = dev->ieee80211_ptr;
12291 struct cfg80211_pmk_conf pmk_conf = {};
12292 int ret;
12293
12294 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12295 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12296 return -EOPNOTSUPP;
12297
12298 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12299 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12300 return -EOPNOTSUPP;
12301
12302 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12303 return -EINVAL;
12304
12305 wdev_lock(wdev);
12306 if (!wdev->current_bss) {
12307 ret = -ENOTCONN;
12308 goto out;
12309 }
12310
12311 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12312 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12313 ret = -EINVAL;
12314 goto out;
12315 }
12316
12317 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12318 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12319 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12320 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12321 ret = -EINVAL;
12322 goto out;
12323 }
12324
12325 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12326 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12327
12328 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12329 ret = -EINVAL;
12330 goto out;
12331 }
12332
12333 pmk_conf.pmk_r0_name =
12334 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12335 }
12336
12337 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12338out:
12339 wdev_unlock(wdev);
12340 return ret;
12341}
12342
12343static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12344{
12345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12346 struct net_device *dev = info->user_ptr[1];
12347 struct wireless_dev *wdev = dev->ieee80211_ptr;
12348 const u8 *aa;
12349 int ret;
12350
12351 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12352 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12353 return -EOPNOTSUPP;
12354
12355 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12356 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12357 return -EOPNOTSUPP;
12358
12359 if (!info->attrs[NL80211_ATTR_MAC])
12360 return -EINVAL;
12361
12362 wdev_lock(wdev);
12363 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12364 ret = rdev_del_pmk(rdev, dev, aa);
12365 wdev_unlock(wdev);
12366
12367 return ret;
12368}
12369
Johannes Berg4c476992010-10-04 21:36:35 +020012370#define NL80211_FLAG_NEED_WIPHY 0x01
12371#define NL80211_FLAG_NEED_NETDEV 0x02
12372#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012373#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12374#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12375 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012376#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012377/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012378#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12379 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012380#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012381
Johannes Bergf84f7712013-11-14 17:14:45 +010012382static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012383 struct genl_info *info)
12384{
12385 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012386 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012387 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012388 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12389
12390 if (rtnl)
12391 rtnl_lock();
12392
12393 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012394 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012395 if (IS_ERR(rdev)) {
12396 if (rtnl)
12397 rtnl_unlock();
12398 return PTR_ERR(rdev);
12399 }
12400 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012401 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12402 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012403 ASSERT_RTNL();
12404
Johannes Berg89a54e42012-06-15 14:33:17 +020012405 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12406 info->attrs);
12407 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012408 if (rtnl)
12409 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012410 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012411 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012412
Johannes Berg89a54e42012-06-15 14:33:17 +020012413 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012414 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012415
Johannes Berg1bf614e2012-06-15 15:23:36 +020012416 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12417 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012418 if (rtnl)
12419 rtnl_unlock();
12420 return -EINVAL;
12421 }
12422
12423 info->user_ptr[1] = dev;
12424 } else {
12425 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012426 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012427
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012428 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12429 !wdev_running(wdev)) {
12430 if (rtnl)
12431 rtnl_unlock();
12432 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012433 }
12434
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012435 if (dev)
12436 dev_hold(dev);
12437
Johannes Berg4c476992010-10-04 21:36:35 +020012438 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012439 }
12440
12441 return 0;
12442}
12443
Johannes Bergf84f7712013-11-14 17:14:45 +010012444static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012445 struct genl_info *info)
12446{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012447 if (info->user_ptr[1]) {
12448 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12449 struct wireless_dev *wdev = info->user_ptr[1];
12450
12451 if (wdev->netdev)
12452 dev_put(wdev->netdev);
12453 } else {
12454 dev_put(info->user_ptr[1]);
12455 }
12456 }
Johannes Berg5393b912014-09-10 15:00:16 +030012457
Johannes Berg4c476992010-10-04 21:36:35 +020012458 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12459 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012460
12461 /* If needed, clear the netlink message payload from the SKB
12462 * as it might contain key data that shouldn't stick around on
12463 * the heap after the SKB is freed. The netlink message header
12464 * is still needed for further processing, so leave it intact.
12465 */
12466 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12467 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12468
12469 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12470 }
Johannes Berg4c476992010-10-04 21:36:35 +020012471}
12472
Johannes Berg4534de82013-11-14 17:14:46 +010012473static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012474 {
12475 .cmd = NL80211_CMD_GET_WIPHY,
12476 .doit = nl80211_get_wiphy,
12477 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012478 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012479 .policy = nl80211_policy,
12480 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012481 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12482 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012483 },
12484 {
12485 .cmd = NL80211_CMD_SET_WIPHY,
12486 .doit = nl80211_set_wiphy,
12487 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012488 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012489 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012490 },
12491 {
12492 .cmd = NL80211_CMD_GET_INTERFACE,
12493 .doit = nl80211_get_interface,
12494 .dumpit = nl80211_dump_interface,
12495 .policy = nl80211_policy,
12496 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012497 .internal_flags = NL80211_FLAG_NEED_WDEV |
12498 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012499 },
12500 {
12501 .cmd = NL80211_CMD_SET_INTERFACE,
12502 .doit = nl80211_set_interface,
12503 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012504 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012505 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12506 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012507 },
12508 {
12509 .cmd = NL80211_CMD_NEW_INTERFACE,
12510 .doit = nl80211_new_interface,
12511 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012512 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012513 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12514 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012515 },
12516 {
12517 .cmd = NL80211_CMD_DEL_INTERFACE,
12518 .doit = nl80211_del_interface,
12519 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012520 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012521 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012522 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012523 },
Johannes Berg41ade002007-12-19 02:03:29 +010012524 {
12525 .cmd = NL80211_CMD_GET_KEY,
12526 .doit = nl80211_get_key,
12527 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012528 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012529 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012530 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012531 },
12532 {
12533 .cmd = NL80211_CMD_SET_KEY,
12534 .doit = nl80211_set_key,
12535 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012536 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012538 NL80211_FLAG_NEED_RTNL |
12539 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012540 },
12541 {
12542 .cmd = NL80211_CMD_NEW_KEY,
12543 .doit = nl80211_new_key,
12544 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012545 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012547 NL80211_FLAG_NEED_RTNL |
12548 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012549 },
12550 {
12551 .cmd = NL80211_CMD_DEL_KEY,
12552 .doit = nl80211_del_key,
12553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012554 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012556 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012557 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012558 {
12559 .cmd = NL80211_CMD_SET_BEACON,
12560 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012561 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012562 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012564 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012565 },
12566 {
Johannes Berg88600202012-02-13 15:17:18 +010012567 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012568 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012569 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012570 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012572 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012573 },
12574 {
Johannes Berg88600202012-02-13 15:17:18 +010012575 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012576 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012577 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012578 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012580 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012581 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012582 {
12583 .cmd = NL80211_CMD_GET_STATION,
12584 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012585 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012586 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012587 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12588 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012589 },
12590 {
12591 .cmd = NL80211_CMD_SET_STATION,
12592 .doit = nl80211_set_station,
12593 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012594 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012596 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012597 },
12598 {
12599 .cmd = NL80211_CMD_NEW_STATION,
12600 .doit = nl80211_new_station,
12601 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012602 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012604 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012605 },
12606 {
12607 .cmd = NL80211_CMD_DEL_STATION,
12608 .doit = nl80211_del_station,
12609 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012610 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012612 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012613 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012614 {
12615 .cmd = NL80211_CMD_GET_MPATH,
12616 .doit = nl80211_get_mpath,
12617 .dumpit = nl80211_dump_mpath,
12618 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012619 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012620 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012621 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012622 },
12623 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012624 .cmd = NL80211_CMD_GET_MPP,
12625 .doit = nl80211_get_mpp,
12626 .dumpit = nl80211_dump_mpp,
12627 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012628 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12630 NL80211_FLAG_NEED_RTNL,
12631 },
12632 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012633 .cmd = NL80211_CMD_SET_MPATH,
12634 .doit = nl80211_set_mpath,
12635 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012636 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012637 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012638 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012639 },
12640 {
12641 .cmd = NL80211_CMD_NEW_MPATH,
12642 .doit = nl80211_new_mpath,
12643 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012644 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012645 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012646 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012647 },
12648 {
12649 .cmd = NL80211_CMD_DEL_MPATH,
12650 .doit = nl80211_del_mpath,
12651 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012652 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012654 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012655 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012656 {
12657 .cmd = NL80211_CMD_SET_BSS,
12658 .doit = nl80211_set_bss,
12659 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012660 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012662 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012663 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012664 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012665 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012666 .doit = nl80211_get_reg_do,
12667 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012668 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012669 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012670 /* can be retrieved by unprivileged users */
12671 },
Johannes Bergb6863032015-10-15 09:25:18 +020012672#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012673 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012674 .cmd = NL80211_CMD_SET_REG,
12675 .doit = nl80211_set_reg,
12676 .policy = nl80211_policy,
12677 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012678 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012679 },
Johannes Bergb6863032015-10-15 09:25:18 +020012680#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012681 {
12682 .cmd = NL80211_CMD_REQ_SET_REG,
12683 .doit = nl80211_req_set_reg,
12684 .policy = nl80211_policy,
12685 .flags = GENL_ADMIN_PERM,
12686 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012687 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012688 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12689 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012690 .policy = nl80211_policy,
12691 /* can be retrieved by unprivileged users */
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,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012694 },
12695 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012696 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12697 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012698 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012699 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012701 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012702 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012703 {
Johannes Berg2a519312009-02-10 21:25:55 +010012704 .cmd = NL80211_CMD_TRIGGER_SCAN,
12705 .doit = nl80211_trigger_scan,
12706 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012707 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012708 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012709 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012710 },
12711 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012712 .cmd = NL80211_CMD_ABORT_SCAN,
12713 .doit = nl80211_abort_scan,
12714 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012715 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012716 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12717 NL80211_FLAG_NEED_RTNL,
12718 },
12719 {
Johannes Berg2a519312009-02-10 21:25:55 +010012720 .cmd = NL80211_CMD_GET_SCAN,
12721 .policy = nl80211_policy,
12722 .dumpit = nl80211_dump_scan,
12723 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012724 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012725 .cmd = NL80211_CMD_START_SCHED_SCAN,
12726 .doit = nl80211_start_sched_scan,
12727 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012728 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12730 NL80211_FLAG_NEED_RTNL,
12731 },
12732 {
12733 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12734 .doit = nl80211_stop_sched_scan,
12735 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012736 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12738 NL80211_FLAG_NEED_RTNL,
12739 },
12740 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012741 .cmd = NL80211_CMD_AUTHENTICATE,
12742 .doit = nl80211_authenticate,
12743 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012744 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012746 NL80211_FLAG_NEED_RTNL |
12747 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012748 },
12749 {
12750 .cmd = NL80211_CMD_ASSOCIATE,
12751 .doit = nl80211_associate,
12752 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012753 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012755 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012756 },
12757 {
12758 .cmd = NL80211_CMD_DEAUTHENTICATE,
12759 .doit = nl80211_deauthenticate,
12760 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012761 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012762 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012763 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012764 },
12765 {
12766 .cmd = NL80211_CMD_DISASSOCIATE,
12767 .doit = nl80211_disassociate,
12768 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012769 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012771 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012772 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012773 {
12774 .cmd = NL80211_CMD_JOIN_IBSS,
12775 .doit = nl80211_join_ibss,
12776 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012777 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012778 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012779 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012780 },
12781 {
12782 .cmd = NL80211_CMD_LEAVE_IBSS,
12783 .doit = nl80211_leave_ibss,
12784 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012785 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012786 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012787 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012788 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012789#ifdef CONFIG_NL80211_TESTMODE
12790 {
12791 .cmd = NL80211_CMD_TESTMODE,
12792 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012793 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012794 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012795 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012796 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12797 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012798 },
12799#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012800 {
12801 .cmd = NL80211_CMD_CONNECT,
12802 .doit = nl80211_connect,
12803 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012804 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012806 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012807 },
12808 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012809 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12810 .doit = nl80211_update_connect_params,
12811 .policy = nl80211_policy,
12812 .flags = GENL_ADMIN_PERM,
12813 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12814 NL80211_FLAG_NEED_RTNL,
12815 },
12816 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012817 .cmd = NL80211_CMD_DISCONNECT,
12818 .doit = nl80211_disconnect,
12819 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012820 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012822 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012823 },
Johannes Berg463d0182009-07-14 00:33:35 +020012824 {
12825 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12826 .doit = nl80211_wiphy_netns,
12827 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012828 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012829 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12830 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012831 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012832 {
12833 .cmd = NL80211_CMD_GET_SURVEY,
12834 .policy = nl80211_policy,
12835 .dumpit = nl80211_dump_survey,
12836 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012837 {
12838 .cmd = NL80211_CMD_SET_PMKSA,
12839 .doit = nl80211_setdel_pmksa,
12840 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012841 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012843 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012844 },
12845 {
12846 .cmd = NL80211_CMD_DEL_PMKSA,
12847 .doit = nl80211_setdel_pmksa,
12848 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012849 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012851 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012852 },
12853 {
12854 .cmd = NL80211_CMD_FLUSH_PMKSA,
12855 .doit = nl80211_flush_pmksa,
12856 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012857 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012859 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012860 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012861 {
12862 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12863 .doit = nl80211_remain_on_channel,
12864 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012865 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012866 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012867 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012868 },
12869 {
12870 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12871 .doit = nl80211_cancel_remain_on_channel,
12872 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012873 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012874 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012875 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012876 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012877 {
12878 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12879 .doit = nl80211_set_tx_bitrate_mask,
12880 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012881 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012882 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12883 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012884 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012885 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012886 .cmd = NL80211_CMD_REGISTER_FRAME,
12887 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012888 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012889 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012890 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012891 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012892 },
12893 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012894 .cmd = NL80211_CMD_FRAME,
12895 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012896 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012897 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012898 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012899 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012900 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012901 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012902 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12903 .doit = nl80211_tx_mgmt_cancel_wait,
12904 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012905 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012906 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012907 NL80211_FLAG_NEED_RTNL,
12908 },
12909 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012910 .cmd = NL80211_CMD_SET_POWER_SAVE,
12911 .doit = nl80211_set_power_save,
12912 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012913 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012914 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12915 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012916 },
12917 {
12918 .cmd = NL80211_CMD_GET_POWER_SAVE,
12919 .doit = nl80211_get_power_save,
12920 .policy = nl80211_policy,
12921 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012922 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12923 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012924 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012925 {
12926 .cmd = NL80211_CMD_SET_CQM,
12927 .doit = nl80211_set_cqm,
12928 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012929 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012930 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12931 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012932 },
Johannes Bergf444de02010-05-05 15:25:02 +020012933 {
12934 .cmd = NL80211_CMD_SET_CHANNEL,
12935 .doit = nl80211_set_channel,
12936 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012937 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012938 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12939 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012940 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012941 {
12942 .cmd = NL80211_CMD_SET_WDS_PEER,
12943 .doit = nl80211_set_wds_peer,
12944 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012945 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012946 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12947 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012948 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012949 {
12950 .cmd = NL80211_CMD_JOIN_MESH,
12951 .doit = nl80211_join_mesh,
12952 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012953 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12955 NL80211_FLAG_NEED_RTNL,
12956 },
12957 {
12958 .cmd = NL80211_CMD_LEAVE_MESH,
12959 .doit = nl80211_leave_mesh,
12960 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012961 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12963 NL80211_FLAG_NEED_RTNL,
12964 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012965 {
12966 .cmd = NL80211_CMD_JOIN_OCB,
12967 .doit = nl80211_join_ocb,
12968 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012969 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12971 NL80211_FLAG_NEED_RTNL,
12972 },
12973 {
12974 .cmd = NL80211_CMD_LEAVE_OCB,
12975 .doit = nl80211_leave_ocb,
12976 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012977 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12979 NL80211_FLAG_NEED_RTNL,
12980 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012981#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012982 {
12983 .cmd = NL80211_CMD_GET_WOWLAN,
12984 .doit = nl80211_get_wowlan,
12985 .policy = nl80211_policy,
12986 /* can be retrieved by unprivileged users */
12987 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12988 NL80211_FLAG_NEED_RTNL,
12989 },
12990 {
12991 .cmd = NL80211_CMD_SET_WOWLAN,
12992 .doit = nl80211_set_wowlan,
12993 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012994 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012995 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12996 NL80211_FLAG_NEED_RTNL,
12997 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012998#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012999 {
13000 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13001 .doit = nl80211_set_rekey_data,
13002 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013003 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013004 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013005 NL80211_FLAG_NEED_RTNL |
13006 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013007 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013008 {
13009 .cmd = NL80211_CMD_TDLS_MGMT,
13010 .doit = nl80211_tdls_mgmt,
13011 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013012 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13014 NL80211_FLAG_NEED_RTNL,
13015 },
13016 {
13017 .cmd = NL80211_CMD_TDLS_OPER,
13018 .doit = nl80211_tdls_oper,
13019 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013020 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13022 NL80211_FLAG_NEED_RTNL,
13023 },
Johannes Berg28946da2011-11-04 11:18:12 +010013024 {
13025 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13026 .doit = nl80211_register_unexpected_frame,
13027 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013028 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013029 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13030 NL80211_FLAG_NEED_RTNL,
13031 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013032 {
13033 .cmd = NL80211_CMD_PROBE_CLIENT,
13034 .doit = nl80211_probe_client,
13035 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013036 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013038 NL80211_FLAG_NEED_RTNL,
13039 },
Johannes Berg5e760232011-11-04 11:18:17 +010013040 {
13041 .cmd = NL80211_CMD_REGISTER_BEACONS,
13042 .doit = nl80211_register_beacons,
13043 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013044 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013045 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13046 NL80211_FLAG_NEED_RTNL,
13047 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013048 {
13049 .cmd = NL80211_CMD_SET_NOACK_MAP,
13050 .doit = nl80211_set_noack_map,
13051 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013052 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013053 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13054 NL80211_FLAG_NEED_RTNL,
13055 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013056 {
13057 .cmd = NL80211_CMD_START_P2P_DEVICE,
13058 .doit = nl80211_start_p2p_device,
13059 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013060 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013061 .internal_flags = NL80211_FLAG_NEED_WDEV |
13062 NL80211_FLAG_NEED_RTNL,
13063 },
13064 {
13065 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13066 .doit = nl80211_stop_p2p_device,
13067 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013068 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013069 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13070 NL80211_FLAG_NEED_RTNL,
13071 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013072 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013073 .cmd = NL80211_CMD_START_NAN,
13074 .doit = nl80211_start_nan,
13075 .policy = nl80211_policy,
13076 .flags = GENL_ADMIN_PERM,
13077 .internal_flags = NL80211_FLAG_NEED_WDEV |
13078 NL80211_FLAG_NEED_RTNL,
13079 },
13080 {
13081 .cmd = NL80211_CMD_STOP_NAN,
13082 .doit = nl80211_stop_nan,
13083 .policy = nl80211_policy,
13084 .flags = GENL_ADMIN_PERM,
13085 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13086 NL80211_FLAG_NEED_RTNL,
13087 },
13088 {
Ayala Bekera442b762016-09-20 17:31:15 +030013089 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13090 .doit = nl80211_nan_add_func,
13091 .policy = nl80211_policy,
13092 .flags = GENL_ADMIN_PERM,
13093 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13094 NL80211_FLAG_NEED_RTNL,
13095 },
13096 {
13097 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13098 .doit = nl80211_nan_del_func,
13099 .policy = nl80211_policy,
13100 .flags = GENL_ADMIN_PERM,
13101 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13102 NL80211_FLAG_NEED_RTNL,
13103 },
13104 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013105 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13106 .doit = nl80211_nan_change_config,
13107 .policy = nl80211_policy,
13108 .flags = GENL_ADMIN_PERM,
13109 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13110 NL80211_FLAG_NEED_RTNL,
13111 },
13112 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013113 .cmd = NL80211_CMD_SET_MCAST_RATE,
13114 .doit = nl80211_set_mcast_rate,
13115 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013116 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013117 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13118 NL80211_FLAG_NEED_RTNL,
13119 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013120 {
13121 .cmd = NL80211_CMD_SET_MAC_ACL,
13122 .doit = nl80211_set_mac_acl,
13123 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013124 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013125 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13126 NL80211_FLAG_NEED_RTNL,
13127 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013128 {
13129 .cmd = NL80211_CMD_RADAR_DETECT,
13130 .doit = nl80211_start_radar_detection,
13131 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013132 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013133 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13134 NL80211_FLAG_NEED_RTNL,
13135 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013136 {
13137 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13138 .doit = nl80211_get_protocol_features,
13139 .policy = nl80211_policy,
13140 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013141 {
13142 .cmd = NL80211_CMD_UPDATE_FT_IES,
13143 .doit = nl80211_update_ft_ies,
13144 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013145 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013146 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13147 NL80211_FLAG_NEED_RTNL,
13148 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013149 {
13150 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13151 .doit = nl80211_crit_protocol_start,
13152 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013153 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013154 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13155 NL80211_FLAG_NEED_RTNL,
13156 },
13157 {
13158 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13159 .doit = nl80211_crit_protocol_stop,
13160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013161 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013162 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13163 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013164 },
13165 {
13166 .cmd = NL80211_CMD_GET_COALESCE,
13167 .doit = nl80211_get_coalesce,
13168 .policy = nl80211_policy,
13169 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13170 NL80211_FLAG_NEED_RTNL,
13171 },
13172 {
13173 .cmd = NL80211_CMD_SET_COALESCE,
13174 .doit = nl80211_set_coalesce,
13175 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013176 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013177 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13178 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013179 },
13180 {
13181 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13182 .doit = nl80211_channel_switch,
13183 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013184 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013185 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13186 NL80211_FLAG_NEED_RTNL,
13187 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013188 {
13189 .cmd = NL80211_CMD_VENDOR,
13190 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013191 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013192 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013193 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013194 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13195 NL80211_FLAG_NEED_RTNL,
13196 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013197 {
13198 .cmd = NL80211_CMD_SET_QOS_MAP,
13199 .doit = nl80211_set_qos_map,
13200 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013201 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013202 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13203 NL80211_FLAG_NEED_RTNL,
13204 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013205 {
13206 .cmd = NL80211_CMD_ADD_TX_TS,
13207 .doit = nl80211_add_tx_ts,
13208 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013209 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013210 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13211 NL80211_FLAG_NEED_RTNL,
13212 },
13213 {
13214 .cmd = NL80211_CMD_DEL_TX_TS,
13215 .doit = nl80211_del_tx_ts,
13216 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013217 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013218 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13219 NL80211_FLAG_NEED_RTNL,
13220 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013221 {
13222 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13223 .doit = nl80211_tdls_channel_switch,
13224 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013225 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013226 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13227 NL80211_FLAG_NEED_RTNL,
13228 },
13229 {
13230 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13231 .doit = nl80211_tdls_cancel_channel_switch,
13232 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013233 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013234 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13235 NL80211_FLAG_NEED_RTNL,
13236 },
Michael Braunce0ce132016-10-10 19:12:22 +020013237 {
13238 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13239 .doit = nl80211_set_multicast_to_unicast,
13240 .policy = nl80211_policy,
13241 .flags = GENL_UNS_ADMIN_PERM,
13242 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13243 NL80211_FLAG_NEED_RTNL,
13244 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013245 {
13246 .cmd = NL80211_CMD_SET_PMK,
13247 .doit = nl80211_set_pmk,
13248 .policy = nl80211_policy,
13249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13250 NL80211_FLAG_NEED_RTNL,
13251 },
13252 {
13253 .cmd = NL80211_CMD_DEL_PMK,
13254 .doit = nl80211_del_pmk,
13255 .policy = nl80211_policy,
13256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13257 NL80211_FLAG_NEED_RTNL,
13258 },
13259
Johannes Berg55682962007-09-20 13:09:35 -040013260};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013261
Johannes Berg56989f62016-10-24 14:40:05 +020013262static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013263 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13264 .hdrsize = 0, /* no private header */
13265 .version = 1, /* no particular meaning now */
13266 .maxattr = NL80211_ATTR_MAX,
13267 .netnsok = true,
13268 .pre_doit = nl80211_pre_doit,
13269 .post_doit = nl80211_post_doit,
13270 .module = THIS_MODULE,
13271 .ops = nl80211_ops,
13272 .n_ops = ARRAY_SIZE(nl80211_ops),
13273 .mcgrps = nl80211_mcgrps,
13274 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13275};
13276
Johannes Berg55682962007-09-20 13:09:35 -040013277/* notification functions */
13278
Johannes Berg3bb20552014-05-26 13:52:25 +020013279void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13280 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013281{
13282 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013283 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013284
Johannes Berg3bb20552014-05-26 13:52:25 +020013285 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13286 cmd != NL80211_CMD_DEL_WIPHY);
13287
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013289 if (!msg)
13290 return;
13291
Johannes Berg3bb20552014-05-26 13:52:25 +020013292 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013293 nlmsg_free(msg);
13294 return;
13295 }
13296
Johannes Berg68eb5502013-11-19 15:19:38 +010013297 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013298 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013299}
13300
Denis Kenzior896ff062016-08-03 16:58:33 -050013301void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13302 struct wireless_dev *wdev,
13303 enum nl80211_commands cmd)
13304{
13305 struct sk_buff *msg;
13306
13307 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13308 cmd != NL80211_CMD_DEL_INTERFACE);
13309
13310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13311 if (!msg)
13312 return;
13313
13314 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13315 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13316 nlmsg_free(msg);
13317 return;
13318 }
13319
13320 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13321 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13322}
13323
Johannes Berg362a4152009-05-24 16:43:15 +020013324static int nl80211_add_scan_req(struct sk_buff *msg,
13325 struct cfg80211_registered_device *rdev)
13326{
13327 struct cfg80211_scan_request *req = rdev->scan_req;
13328 struct nlattr *nest;
13329 int i;
13330
13331 if (WARN_ON(!req))
13332 return 0;
13333
13334 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13335 if (!nest)
13336 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013337 for (i = 0; i < req->n_ssids; i++) {
13338 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13339 goto nla_put_failure;
13340 }
Johannes Berg362a4152009-05-24 16:43:15 +020013341 nla_nest_end(msg, nest);
13342
13343 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13344 if (!nest)
13345 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013346 for (i = 0; i < req->n_channels; i++) {
13347 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13348 goto nla_put_failure;
13349 }
Johannes Berg362a4152009-05-24 16:43:15 +020013350 nla_nest_end(msg, nest);
13351
David S. Miller9360ffd2012-03-29 04:41:26 -040013352 if (req->ie &&
13353 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13354 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013355
Johannes Bergae917c92013-10-25 11:05:22 +020013356 if (req->flags &&
13357 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13358 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013359
Avraham Stern1d762502016-07-05 17:10:13 +030013360 if (req->info.scan_start_tsf &&
13361 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13362 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13363 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13364 req->info.tsf_bssid)))
13365 goto nla_put_failure;
13366
Johannes Berg362a4152009-05-24 16:43:15 +020013367 return 0;
13368 nla_put_failure:
13369 return -ENOBUFS;
13370}
13371
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013372static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013373 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013374 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013375 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013376 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013377{
13378 void *hdr;
13379
Eric W. Biederman15e47302012-09-07 20:12:54 +000013380 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013381 if (!hdr)
13382 return -1;
13383
David S. Miller9360ffd2012-03-29 04:41:26 -040013384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013385 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13386 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013387 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13388 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013389 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013390
Johannes Berg362a4152009-05-24 16:43:15 +020013391 /* ignore errors and send incomplete event anyway */
13392 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013393
Johannes Berg053c0952015-01-16 22:09:00 +010013394 genlmsg_end(msg, hdr);
13395 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013396
13397 nla_put_failure:
13398 genlmsg_cancel(msg, hdr);
13399 return -EMSGSIZE;
13400}
13401
Luciano Coelho807f8a82011-05-11 17:09:35 +030013402static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013403nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013404 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013405{
13406 void *hdr;
13407
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013408 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013409 if (!hdr)
13410 return -1;
13411
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013412 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13413 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13414 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13415 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13416 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013417 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013418
Johannes Berg053c0952015-01-16 22:09:00 +010013419 genlmsg_end(msg, hdr);
13420 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013421
13422 nla_put_failure:
13423 genlmsg_cancel(msg, hdr);
13424 return -EMSGSIZE;
13425}
13426
Johannes Berga538e2d2009-06-16 19:56:42 +020013427void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013428 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013429{
13430 struct sk_buff *msg;
13431
Thomas Graf58050fc2012-06-28 03:57:45 +000013432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013433 if (!msg)
13434 return;
13435
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013436 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013437 NL80211_CMD_TRIGGER_SCAN) < 0) {
13438 nlmsg_free(msg);
13439 return;
13440 }
13441
Johannes Berg68eb5502013-11-19 15:19:38 +010013442 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013443 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013444}
13445
Johannes Bergf9d15d12014-01-22 11:14:19 +020013446struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13447 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013448{
13449 struct sk_buff *msg;
13450
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013452 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013453 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013454
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013455 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013456 aborted ? NL80211_CMD_SCAN_ABORTED :
13457 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013458 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013459 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013460 }
13461
Johannes Bergf9d15d12014-01-22 11:14:19 +020013462 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013463}
13464
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013465/* send message created by nl80211_build_scan_msg() */
13466void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13467 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013468{
Johannes Berg2a519312009-02-10 21:25:55 +010013469 if (!msg)
13470 return;
13471
Johannes Berg68eb5502013-11-19 15:19:38 +010013472 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013473 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013474}
13475
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013476void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013477{
13478 struct sk_buff *msg;
13479
Thomas Graf58050fc2012-06-28 03:57:45 +000013480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013481 if (!msg)
13482 return;
13483
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013484 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013485 nlmsg_free(msg);
13486 return;
13487 }
13488
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013489 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013490 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013491}
13492
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013493static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13494 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013495{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013496 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013497 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13498 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013499
David S. Miller9360ffd2012-03-29 04:41:26 -040013500 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13501 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13502 NL80211_REGDOM_TYPE_WORLD))
13503 goto nla_put_failure;
13504 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13505 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13506 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13507 goto nla_put_failure;
13508 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13509 request->intersect) {
13510 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13511 NL80211_REGDOM_TYPE_INTERSECTION))
13512 goto nla_put_failure;
13513 } else {
13514 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13515 NL80211_REGDOM_TYPE_COUNTRY) ||
13516 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13517 request->alpha2))
13518 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013519 }
13520
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013521 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13522 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13523
13524 if (wiphy &&
13525 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13526 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013527
13528 if (wiphy &&
13529 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13530 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13531 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013532 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013533
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013534 return true;
13535
13536nla_put_failure:
13537 return false;
13538}
13539
13540/*
13541 * This can happen on global regulatory changes or device specific settings
13542 * based on custom regulatory domains.
13543 */
13544void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13545 struct regulatory_request *request)
13546{
13547 struct sk_buff *msg;
13548 void *hdr;
13549
13550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13551 if (!msg)
13552 return;
13553
13554 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13555 if (!hdr) {
13556 nlmsg_free(msg);
13557 return;
13558 }
13559
13560 if (nl80211_reg_change_event_fill(msg, request) == false)
13561 goto nla_put_failure;
13562
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013563 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013564
Johannes Bergbc43b282009-07-25 10:54:13 +020013565 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013566 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013567 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013568 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013569
13570 return;
13571
13572nla_put_failure:
13573 genlmsg_cancel(msg, hdr);
13574 nlmsg_free(msg);
13575}
13576
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013577static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13578 struct net_device *netdev,
13579 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013580 enum nl80211_commands cmd, gfp_t gfp,
13581 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013582{
13583 struct sk_buff *msg;
13584 void *hdr;
13585
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013586 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013587 if (!msg)
13588 return;
13589
13590 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13591 if (!hdr) {
13592 nlmsg_free(msg);
13593 return;
13594 }
13595
David S. Miller9360ffd2012-03-29 04:41:26 -040013596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13598 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13599 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013600
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013601 if (uapsd_queues >= 0) {
13602 struct nlattr *nla_wmm =
13603 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13604 if (!nla_wmm)
13605 goto nla_put_failure;
13606
13607 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13608 uapsd_queues))
13609 goto nla_put_failure;
13610
13611 nla_nest_end(msg, nla_wmm);
13612 }
13613
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013614 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013615
Johannes Berg68eb5502013-11-19 15:19:38 +010013616 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013617 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013618 return;
13619
13620 nla_put_failure:
13621 genlmsg_cancel(msg, hdr);
13622 nlmsg_free(msg);
13623}
13624
13625void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013626 struct net_device *netdev, const u8 *buf,
13627 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013628{
13629 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013630 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013631}
13632
13633void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13634 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013635 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013636{
Johannes Berge6d6e342009-07-01 21:26:47 +020013637 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013638 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013639}
13640
Jouni Malinen53b46b82009-03-27 20:53:56 +020013641void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013642 struct net_device *netdev, const u8 *buf,
13643 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013644{
13645 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013646 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013647}
13648
Jouni Malinen53b46b82009-03-27 20:53:56 +020013649void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13650 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013651 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013652{
13653 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013654 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013655}
13656
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013657void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13658 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013659{
Johannes Berg947add32013-02-22 22:05:20 +010013660 struct wireless_dev *wdev = dev->ieee80211_ptr;
13661 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013662 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013663 const struct ieee80211_mgmt *mgmt = (void *)buf;
13664 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013665
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013666 if (WARN_ON(len < 2))
13667 return;
13668
13669 if (ieee80211_is_deauth(mgmt->frame_control))
13670 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13671 else
13672 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13673
13674 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013675 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013676}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013677EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013678
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013679static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13680 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013681 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013682{
13683 struct sk_buff *msg;
13684 void *hdr;
13685
Johannes Berge6d6e342009-07-01 21:26:47 +020013686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013687 if (!msg)
13688 return;
13689
13690 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13691 if (!hdr) {
13692 nlmsg_free(msg);
13693 return;
13694 }
13695
David S. Miller9360ffd2012-03-29 04:41:26 -040013696 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13698 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13699 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13700 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013701
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013702 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013703
Johannes Berg68eb5502013-11-19 15:19:38 +010013704 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013705 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013706 return;
13707
13708 nla_put_failure:
13709 genlmsg_cancel(msg, hdr);
13710 nlmsg_free(msg);
13711}
13712
13713void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013714 struct net_device *netdev, const u8 *addr,
13715 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013716{
13717 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013718 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013719}
13720
13721void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013722 struct net_device *netdev, const u8 *addr,
13723 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013724{
Johannes Berge6d6e342009-07-01 21:26:47 +020013725 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13726 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013727}
13728
Samuel Ortizb23aa672009-07-01 21:26:54 +020013729void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013730 struct net_device *netdev,
13731 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013732 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013733{
13734 struct sk_buff *msg;
13735 void *hdr;
13736
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013737 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13738 cr->fils_kek_len + cr->pmk_len +
13739 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013740 if (!msg)
13741 return;
13742
13743 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13744 if (!hdr) {
13745 nlmsg_free(msg);
13746 return;
13747 }
13748
David S. Miller9360ffd2012-03-29 04:41:26 -040013749 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013751 (cr->bssid &&
13752 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013753 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013754 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13755 cr->status) ||
13756 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013757 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013758 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13759 cr->timeout_reason))) ||
13760 (cr->req_ie &&
13761 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13762 (cr->resp_ie &&
13763 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013764 cr->resp_ie)) ||
13765 (cr->update_erp_next_seq_num &&
13766 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13767 cr->fils_erp_next_seq_num)) ||
13768 (cr->status == WLAN_STATUS_SUCCESS &&
13769 ((cr->fils_kek &&
13770 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13771 cr->fils_kek)) ||
13772 (cr->pmk &&
13773 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13774 (cr->pmkid &&
13775 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013776 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013777
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013778 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013779
Johannes Berg68eb5502013-11-19 15:19:38 +010013780 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013781 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013782 return;
13783
13784 nla_put_failure:
13785 genlmsg_cancel(msg, hdr);
13786 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013787}
13788
13789void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013790 struct net_device *netdev,
13791 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013792{
13793 struct sk_buff *msg;
13794 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013795 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013796
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013797 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013798 if (!msg)
13799 return;
13800
13801 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13802 if (!hdr) {
13803 nlmsg_free(msg);
13804 return;
13805 }
13806
David S. Miller9360ffd2012-03-29 04:41:26 -040013807 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13808 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13809 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013810 (info->req_ie &&
13811 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13812 info->req_ie)) ||
13813 (info->resp_ie &&
13814 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Sternf45cbe62017-06-09 13:08:45 +010013815 info->resp_ie)) ||
13816 (info->authorized &&
13817 nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013818 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013819
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013820 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013821
Johannes Berg68eb5502013-11-19 15:19:38 +010013822 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013823 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013824 return;
13825
13826 nla_put_failure:
13827 genlmsg_cancel(msg, hdr);
13828 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013829}
13830
13831void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13832 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013833 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013834{
13835 struct sk_buff *msg;
13836 void *hdr;
13837
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013838 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013839 if (!msg)
13840 return;
13841
13842 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13843 if (!hdr) {
13844 nlmsg_free(msg);
13845 return;
13846 }
13847
David S. Miller9360ffd2012-03-29 04:41:26 -040013848 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13849 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13850 (from_ap && reason &&
13851 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13852 (from_ap &&
13853 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13854 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13855 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013856
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013857 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013858
Johannes Berg68eb5502013-11-19 15:19:38 +010013859 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013860 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013861 return;
13862
13863 nla_put_failure:
13864 genlmsg_cancel(msg, hdr);
13865 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013866}
13867
Johannes Berg04a773a2009-04-19 21:24:32 +020013868void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13869 struct net_device *netdev, const u8 *bssid,
13870 gfp_t gfp)
13871{
13872 struct sk_buff *msg;
13873 void *hdr;
13874
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013876 if (!msg)
13877 return;
13878
13879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13880 if (!hdr) {
13881 nlmsg_free(msg);
13882 return;
13883 }
13884
David S. Miller9360ffd2012-03-29 04:41:26 -040013885 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13886 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13887 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13888 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013889
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013890 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013891
Johannes Berg68eb5502013-11-19 15:19:38 +010013892 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013893 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013894 return;
13895
13896 nla_put_failure:
13897 genlmsg_cancel(msg, hdr);
13898 nlmsg_free(msg);
13899}
13900
Johannes Berg947add32013-02-22 22:05:20 +010013901void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13902 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013903{
Johannes Berg947add32013-02-22 22:05:20 +010013904 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013905 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013906 struct sk_buff *msg;
13907 void *hdr;
13908
Johannes Berg947add32013-02-22 22:05:20 +010013909 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13910 return;
13911
13912 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13913
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013914 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013915 if (!msg)
13916 return;
13917
13918 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13919 if (!hdr) {
13920 nlmsg_free(msg);
13921 return;
13922 }
13923
David S. Miller9360ffd2012-03-29 04:41:26 -040013924 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013925 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13926 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013927 (ie_len && ie &&
13928 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13929 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013930
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013931 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013932
Johannes Berg68eb5502013-11-19 15:19:38 +010013933 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013934 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013935 return;
13936
13937 nla_put_failure:
13938 genlmsg_cancel(msg, hdr);
13939 nlmsg_free(msg);
13940}
Johannes Berg947add32013-02-22 22:05:20 +010013941EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013942
Jouni Malinena3b8b052009-03-27 21:59:49 +020013943void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13944 struct net_device *netdev, const u8 *addr,
13945 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013946 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013947{
13948 struct sk_buff *msg;
13949 void *hdr;
13950
Johannes Berge6d6e342009-07-01 21:26:47 +020013951 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013952 if (!msg)
13953 return;
13954
13955 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13956 if (!hdr) {
13957 nlmsg_free(msg);
13958 return;
13959 }
13960
David S. Miller9360ffd2012-03-29 04:41:26 -040013961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13963 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13964 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13965 (key_id != -1 &&
13966 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13967 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13968 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013969
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013970 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013971
Johannes Berg68eb5502013-11-19 15:19:38 +010013972 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013973 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013974 return;
13975
13976 nla_put_failure:
13977 genlmsg_cancel(msg, hdr);
13978 nlmsg_free(msg);
13979}
13980
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013981void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13982 struct ieee80211_channel *channel_before,
13983 struct ieee80211_channel *channel_after)
13984{
13985 struct sk_buff *msg;
13986 void *hdr;
13987 struct nlattr *nl_freq;
13988
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013990 if (!msg)
13991 return;
13992
13993 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13994 if (!hdr) {
13995 nlmsg_free(msg);
13996 return;
13997 }
13998
13999 /*
14000 * Since we are applying the beacon hint to a wiphy we know its
14001 * wiphy_idx is valid
14002 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014003 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14004 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014005
14006 /* Before */
14007 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14008 if (!nl_freq)
14009 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014010 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014011 goto nla_put_failure;
14012 nla_nest_end(msg, nl_freq);
14013
14014 /* After */
14015 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14016 if (!nl_freq)
14017 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014018 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014019 goto nla_put_failure;
14020 nla_nest_end(msg, nl_freq);
14021
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014022 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014023
Johannes Berg463d0182009-07-14 00:33:35 +020014024 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014025 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014026 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014027 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014028
14029 return;
14030
14031nla_put_failure:
14032 genlmsg_cancel(msg, hdr);
14033 nlmsg_free(msg);
14034}
14035
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014036static void nl80211_send_remain_on_chan_event(
14037 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014038 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014039 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014040 unsigned int duration, gfp_t gfp)
14041{
14042 struct sk_buff *msg;
14043 void *hdr;
14044
14045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14046 if (!msg)
14047 return;
14048
14049 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14050 if (!hdr) {
14051 nlmsg_free(msg);
14052 return;
14053 }
14054
David S. Miller9360ffd2012-03-29 04:41:26 -040014055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014056 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14057 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014058 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14059 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014060 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014061 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14062 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014063 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14064 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014065 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014066
David S. Miller9360ffd2012-03-29 04:41:26 -040014067 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14068 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14069 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014070
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014071 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014072
Johannes Berg68eb5502013-11-19 15:19:38 +010014073 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014074 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014075 return;
14076
14077 nla_put_failure:
14078 genlmsg_cancel(msg, hdr);
14079 nlmsg_free(msg);
14080}
14081
Johannes Berg947add32013-02-22 22:05:20 +010014082void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14083 struct ieee80211_channel *chan,
14084 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014085{
Johannes Berg947add32013-02-22 22:05:20 +010014086 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014087 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014088
14089 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014090 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014091 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014092 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014093}
Johannes Berg947add32013-02-22 22:05:20 +010014094EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014095
Johannes Berg947add32013-02-22 22:05:20 +010014096void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14097 struct ieee80211_channel *chan,
14098 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014099{
Johannes Berg947add32013-02-22 22:05:20 +010014100 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014101 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014102
14103 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014104 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014105 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014106}
Johannes Berg947add32013-02-22 22:05:20 +010014107EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014108
Johannes Berg947add32013-02-22 22:05:20 +010014109void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14110 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014111{
Johannes Berg947add32013-02-22 22:05:20 +010014112 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014113 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014114 struct sk_buff *msg;
14115
Johannes Berg947add32013-02-22 22:05:20 +010014116 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14117
Thomas Graf58050fc2012-06-28 03:57:45 +000014118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014119 if (!msg)
14120 return;
14121
Johannes Bergcf5ead82014-11-14 17:14:00 +010014122 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014123 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014124 nlmsg_free(msg);
14125 return;
14126 }
14127
Johannes Berg68eb5502013-11-19 15:19:38 +010014128 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014129 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014130}
Johannes Berg947add32013-02-22 22:05:20 +010014131EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014132
Johannes Bergcf5ead82014-11-14 17:14:00 +010014133void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14134 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014135{
Johannes Berg947add32013-02-22 22:05:20 +010014136 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014137 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014138 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014139 struct station_info empty_sinfo = {};
14140
14141 if (!sinfo)
14142 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014143
Johannes Berg947add32013-02-22 22:05:20 +010014144 trace_cfg80211_del_sta(dev, mac_addr);
14145
Thomas Graf58050fc2012-06-28 03:57:45 +000014146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014147 if (!msg)
14148 return;
14149
Johannes Bergcf5ead82014-11-14 17:14:00 +010014150 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014151 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014152 nlmsg_free(msg);
14153 return;
14154 }
14155
Johannes Berg68eb5502013-11-19 15:19:38 +010014156 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014157 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014158}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014159EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014160
Johannes Berg947add32013-02-22 22:05:20 +010014161void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14162 enum nl80211_connect_failed_reason reason,
14163 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014164{
Johannes Berg947add32013-02-22 22:05:20 +010014165 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014166 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014167 struct sk_buff *msg;
14168 void *hdr;
14169
14170 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14171 if (!msg)
14172 return;
14173
14174 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14175 if (!hdr) {
14176 nlmsg_free(msg);
14177 return;
14178 }
14179
14180 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14181 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14182 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14183 goto nla_put_failure;
14184
14185 genlmsg_end(msg, hdr);
14186
Johannes Berg68eb5502013-11-19 15:19:38 +010014187 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014188 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014189 return;
14190
14191 nla_put_failure:
14192 genlmsg_cancel(msg, hdr);
14193 nlmsg_free(msg);
14194}
Johannes Berg947add32013-02-22 22:05:20 +010014195EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014196
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014197static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14198 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014199{
14200 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014201 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014202 struct sk_buff *msg;
14203 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014204 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014205
Eric W. Biederman15e47302012-09-07 20:12:54 +000014206 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014207 return false;
14208
14209 msg = nlmsg_new(100, gfp);
14210 if (!msg)
14211 return true;
14212
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014213 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014214 if (!hdr) {
14215 nlmsg_free(msg);
14216 return true;
14217 }
14218
David S. Miller9360ffd2012-03-29 04:41:26 -040014219 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14220 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14221 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14222 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014223
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014224 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014225 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014226 return true;
14227
14228 nla_put_failure:
14229 genlmsg_cancel(msg, hdr);
14230 nlmsg_free(msg);
14231 return true;
14232}
14233
Johannes Berg947add32013-02-22 22:05:20 +010014234bool cfg80211_rx_spurious_frame(struct net_device *dev,
14235 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014236{
Johannes Berg947add32013-02-22 22:05:20 +010014237 struct wireless_dev *wdev = dev->ieee80211_ptr;
14238 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014239
Johannes Berg947add32013-02-22 22:05:20 +010014240 trace_cfg80211_rx_spurious_frame(dev, addr);
14241
14242 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14243 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14244 trace_cfg80211_return_bool(false);
14245 return false;
14246 }
14247 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14248 addr, gfp);
14249 trace_cfg80211_return_bool(ret);
14250 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014251}
Johannes Berg947add32013-02-22 22:05:20 +010014252EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14253
14254bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14255 const u8 *addr, gfp_t gfp)
14256{
14257 struct wireless_dev *wdev = dev->ieee80211_ptr;
14258 bool ret;
14259
14260 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14261
14262 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14263 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14264 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14265 trace_cfg80211_return_bool(false);
14266 return false;
14267 }
14268 ret = __nl80211_unexpected_frame(dev,
14269 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14270 addr, gfp);
14271 trace_cfg80211_return_bool(ret);
14272 return ret;
14273}
14274EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014275
Johannes Berg2e161f72010-08-12 15:38:38 +020014276int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014277 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014278 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014279 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014280{
Johannes Berg71bbc992012-06-15 15:30:18 +020014281 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014282 struct sk_buff *msg;
14283 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014284
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014285 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014286 if (!msg)
14287 return -ENOMEM;
14288
Johannes Berg2e161f72010-08-12 15:38:38 +020014289 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014290 if (!hdr) {
14291 nlmsg_free(msg);
14292 return -ENOMEM;
14293 }
14294
David S. Miller9360ffd2012-03-29 04:41:26 -040014295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014296 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14297 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014298 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14299 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014300 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14301 (sig_dbm &&
14302 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014303 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14304 (flags &&
14305 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014306 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014307
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014308 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014309
Eric W. Biederman15e47302012-09-07 20:12:54 +000014310 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014311
14312 nla_put_failure:
14313 genlmsg_cancel(msg, hdr);
14314 nlmsg_free(msg);
14315 return -ENOBUFS;
14316}
14317
Johannes Berg947add32013-02-22 22:05:20 +010014318void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14319 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014320{
Johannes Berg947add32013-02-22 22:05:20 +010014321 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014322 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014323 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014324 struct sk_buff *msg;
14325 void *hdr;
14326
Johannes Berg947add32013-02-22 22:05:20 +010014327 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14328
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014329 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014330 if (!msg)
14331 return;
14332
Johannes Berg2e161f72010-08-12 15:38:38 +020014333 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014334 if (!hdr) {
14335 nlmsg_free(msg);
14336 return;
14337 }
14338
David S. Miller9360ffd2012-03-29 04:41:26 -040014339 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014340 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14341 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014342 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14343 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014344 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014345 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14346 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014347 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14348 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014349
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014350 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014351
Johannes Berg68eb5502013-11-19 15:19:38 +010014352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014353 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014354 return;
14355
14356 nla_put_failure:
14357 genlmsg_cancel(msg, hdr);
14358 nlmsg_free(msg);
14359}
Johannes Berg947add32013-02-22 22:05:20 +010014360EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014361
Johannes Berg5b97f492014-11-26 12:37:43 +010014362static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14363 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014364{
Johannes Berg947add32013-02-22 22:05:20 +010014365 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014366 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14367 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14368 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014369
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014370 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014371 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014372
Johannes Berg5b97f492014-11-26 12:37:43 +010014373 cb = (void **)msg->cb;
14374
14375 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14376 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014377 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014378 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014379 }
14380
David S. Miller9360ffd2012-03-29 04:41:26 -040014381 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014382 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014383 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014384
Johannes Berg5b97f492014-11-26 12:37:43 +010014385 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014386 goto nla_put_failure;
14387
Johannes Berg5b97f492014-11-26 12:37:43 +010014388 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14389 if (!cb[1])
14390 goto nla_put_failure;
14391
14392 cb[2] = rdev;
14393
14394 return msg;
14395 nla_put_failure:
14396 nlmsg_free(msg);
14397 return NULL;
14398}
14399
14400static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14401{
14402 void **cb = (void **)msg->cb;
14403 struct cfg80211_registered_device *rdev = cb[2];
14404
14405 nla_nest_end(msg, cb[1]);
14406 genlmsg_end(msg, cb[0]);
14407
14408 memset(msg->cb, 0, sizeof(msg->cb));
14409
14410 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14411 NL80211_MCGRP_MLME, gfp);
14412}
14413
14414void cfg80211_cqm_rssi_notify(struct net_device *dev,
14415 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014416 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014417{
14418 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014419 struct wireless_dev *wdev = dev->ieee80211_ptr;
14420 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014421
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014422 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014423
Johannes Berg98f03342014-11-26 12:42:02 +010014424 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14425 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14426 return;
14427
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014428 if (wdev->cqm_config) {
14429 wdev->cqm_config->last_rssi_event_value = rssi_level;
14430
14431 cfg80211_cqm_rssi_update(rdev, dev);
14432
14433 if (rssi_level == 0)
14434 rssi_level = wdev->cqm_config->last_rssi_event_value;
14435 }
14436
Johannes Berg5b97f492014-11-26 12:37:43 +010014437 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14438 if (!msg)
14439 return;
14440
David S. Miller9360ffd2012-03-29 04:41:26 -040014441 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14442 rssi_event))
14443 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014444
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014445 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14446 rssi_level))
14447 goto nla_put_failure;
14448
Johannes Berg5b97f492014-11-26 12:37:43 +010014449 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014450
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014451 return;
14452
14453 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014454 nlmsg_free(msg);
14455}
Johannes Berg947add32013-02-22 22:05:20 +010014456EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014457
Johannes Berg5b97f492014-11-26 12:37:43 +010014458void cfg80211_cqm_txe_notify(struct net_device *dev,
14459 const u8 *peer, u32 num_packets,
14460 u32 rate, u32 intvl, gfp_t gfp)
14461{
14462 struct sk_buff *msg;
14463
14464 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14465 if (!msg)
14466 return;
14467
14468 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14469 goto nla_put_failure;
14470
14471 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14472 goto nla_put_failure;
14473
14474 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14475 goto nla_put_failure;
14476
14477 cfg80211_send_cqm(msg, gfp);
14478 return;
14479
14480 nla_put_failure:
14481 nlmsg_free(msg);
14482}
14483EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14484
14485void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14486 const u8 *peer, u32 num_packets, gfp_t gfp)
14487{
14488 struct sk_buff *msg;
14489
14490 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14491
14492 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14493 if (!msg)
14494 return;
14495
14496 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14497 goto nla_put_failure;
14498
14499 cfg80211_send_cqm(msg, gfp);
14500 return;
14501
14502 nla_put_failure:
14503 nlmsg_free(msg);
14504}
14505EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14506
Johannes Berg98f03342014-11-26 12:42:02 +010014507void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14508{
14509 struct sk_buff *msg;
14510
14511 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14512 if (!msg)
14513 return;
14514
14515 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14516 goto nla_put_failure;
14517
14518 cfg80211_send_cqm(msg, gfp);
14519 return;
14520
14521 nla_put_failure:
14522 nlmsg_free(msg);
14523}
14524EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14525
Johannes Berg947add32013-02-22 22:05:20 +010014526static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14527 struct net_device *netdev, const u8 *bssid,
14528 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014529{
14530 struct sk_buff *msg;
14531 struct nlattr *rekey_attr;
14532 void *hdr;
14533
Thomas Graf58050fc2012-06-28 03:57:45 +000014534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014535 if (!msg)
14536 return;
14537
14538 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14539 if (!hdr) {
14540 nlmsg_free(msg);
14541 return;
14542 }
14543
David S. Miller9360ffd2012-03-29 04:41:26 -040014544 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14545 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14546 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14547 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014548
14549 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14550 if (!rekey_attr)
14551 goto nla_put_failure;
14552
David S. Miller9360ffd2012-03-29 04:41:26 -040014553 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14554 NL80211_REPLAY_CTR_LEN, replay_ctr))
14555 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014556
14557 nla_nest_end(msg, rekey_attr);
14558
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014559 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014560
Johannes Berg68eb5502013-11-19 15:19:38 +010014561 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014562 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014563 return;
14564
14565 nla_put_failure:
14566 genlmsg_cancel(msg, hdr);
14567 nlmsg_free(msg);
14568}
14569
Johannes Berg947add32013-02-22 22:05:20 +010014570void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14571 const u8 *replay_ctr, gfp_t gfp)
14572{
14573 struct wireless_dev *wdev = dev->ieee80211_ptr;
14574 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014575 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014576
14577 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14578 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14579}
14580EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14581
14582static void
14583nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14584 struct net_device *netdev, int index,
14585 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014586{
14587 struct sk_buff *msg;
14588 struct nlattr *attr;
14589 void *hdr;
14590
Thomas Graf58050fc2012-06-28 03:57:45 +000014591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014592 if (!msg)
14593 return;
14594
14595 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14596 if (!hdr) {
14597 nlmsg_free(msg);
14598 return;
14599 }
14600
David S. Miller9360ffd2012-03-29 04:41:26 -040014601 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14603 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014604
14605 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14606 if (!attr)
14607 goto nla_put_failure;
14608
David S. Miller9360ffd2012-03-29 04:41:26 -040014609 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14610 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14611 (preauth &&
14612 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14613 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014614
14615 nla_nest_end(msg, attr);
14616
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014617 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014618
Johannes Berg68eb5502013-11-19 15:19:38 +010014619 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014620 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014621 return;
14622
14623 nla_put_failure:
14624 genlmsg_cancel(msg, hdr);
14625 nlmsg_free(msg);
14626}
14627
Johannes Berg947add32013-02-22 22:05:20 +010014628void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14629 const u8 *bssid, bool preauth, gfp_t gfp)
14630{
14631 struct wireless_dev *wdev = dev->ieee80211_ptr;
14632 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014633 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014634
14635 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14636 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14637}
14638EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14639
14640static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14641 struct net_device *netdev,
14642 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014643 gfp_t gfp,
14644 enum nl80211_commands notif,
14645 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014646{
14647 struct sk_buff *msg;
14648 void *hdr;
14649
Thomas Graf58050fc2012-06-28 03:57:45 +000014650 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014651 if (!msg)
14652 return;
14653
Luciano Coelhof8d75522014-11-07 14:31:35 +020014654 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014655 if (!hdr) {
14656 nlmsg_free(msg);
14657 return;
14658 }
14659
Johannes Berg683b6d32012-11-08 21:25:48 +010014660 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14661 goto nla_put_failure;
14662
14663 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014664 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014665
Luciano Coelhof8d75522014-11-07 14:31:35 +020014666 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14667 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14668 goto nla_put_failure;
14669
Thomas Pedersen53145262012-04-06 13:35:47 -070014670 genlmsg_end(msg, hdr);
14671
Johannes Berg68eb5502013-11-19 15:19:38 +010014672 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014673 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014674 return;
14675
14676 nla_put_failure:
14677 genlmsg_cancel(msg, hdr);
14678 nlmsg_free(msg);
14679}
14680
Johannes Berg947add32013-02-22 22:05:20 +010014681void cfg80211_ch_switch_notify(struct net_device *dev,
14682 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014683{
Johannes Berg947add32013-02-22 22:05:20 +010014684 struct wireless_dev *wdev = dev->ieee80211_ptr;
14685 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014686 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014687
Simon Wunderliche487eae2013-11-21 18:19:51 +010014688 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014689
Simon Wunderliche487eae2013-11-21 18:19:51 +010014690 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014691
Michal Kazior9e0e2962014-01-29 14:22:27 +010014692 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014693 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014694 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14695 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014696}
14697EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14698
Luciano Coelhof8d75522014-11-07 14:31:35 +020014699void cfg80211_ch_switch_started_notify(struct net_device *dev,
14700 struct cfg80211_chan_def *chandef,
14701 u8 count)
14702{
14703 struct wireless_dev *wdev = dev->ieee80211_ptr;
14704 struct wiphy *wiphy = wdev->wiphy;
14705 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14706
14707 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14708
14709 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14710 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14711}
14712EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14713
Thomas Pedersen84f10702012-07-12 16:17:33 -070014714void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014715nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014716 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014717 enum nl80211_radar_event event,
14718 struct net_device *netdev, gfp_t gfp)
14719{
14720 struct sk_buff *msg;
14721 void *hdr;
14722
14723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14724 if (!msg)
14725 return;
14726
14727 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14728 if (!hdr) {
14729 nlmsg_free(msg);
14730 return;
14731 }
14732
14733 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14734 goto nla_put_failure;
14735
14736 /* NOP and radar events don't need a netdev parameter */
14737 if (netdev) {
14738 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14739
14740 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014741 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14742 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014743 goto nla_put_failure;
14744 }
14745
14746 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14747 goto nla_put_failure;
14748
14749 if (nl80211_send_chandef(msg, chandef))
14750 goto nla_put_failure;
14751
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014752 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014753
Johannes Berg68eb5502013-11-19 15:19:38 +010014754 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014755 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014756 return;
14757
14758 nla_put_failure:
14759 genlmsg_cancel(msg, hdr);
14760 nlmsg_free(msg);
14761}
14762
Johannes Berg7f6cf312011-11-04 11:18:15 +010014763void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14764 u64 cookie, bool acked, gfp_t gfp)
14765{
14766 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014767 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014768 struct sk_buff *msg;
14769 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014770
Beni Lev4ee3e062012-08-27 12:49:39 +030014771 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14772
Thomas Graf58050fc2012-06-28 03:57:45 +000014773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014774
Johannes Berg7f6cf312011-11-04 11:18:15 +010014775 if (!msg)
14776 return;
14777
14778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14779 if (!hdr) {
14780 nlmsg_free(msg);
14781 return;
14782 }
14783
David S. Miller9360ffd2012-03-29 04:41:26 -040014784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14785 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014787 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14788 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014789 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14790 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014791
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014792 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014793
Johannes Berg68eb5502013-11-19 15:19:38 +010014794 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014795 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014796 return;
14797
14798 nla_put_failure:
14799 genlmsg_cancel(msg, hdr);
14800 nlmsg_free(msg);
14801}
14802EXPORT_SYMBOL(cfg80211_probe_status);
14803
Johannes Berg5e760232011-11-04 11:18:17 +010014804void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14805 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014806 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014807{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014808 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014809 struct sk_buff *msg;
14810 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014811 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014812
Beni Lev4ee3e062012-08-27 12:49:39 +030014813 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14814
Ben Greear37c73b52012-10-26 14:49:25 -070014815 spin_lock_bh(&rdev->beacon_registrations_lock);
14816 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14817 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14818 if (!msg) {
14819 spin_unlock_bh(&rdev->beacon_registrations_lock);
14820 return;
14821 }
Johannes Berg5e760232011-11-04 11:18:17 +010014822
Ben Greear37c73b52012-10-26 14:49:25 -070014823 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14824 if (!hdr)
14825 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014826
Ben Greear37c73b52012-10-26 14:49:25 -070014827 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14828 (freq &&
14829 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14830 (sig_dbm &&
14831 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14832 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14833 goto nla_put_failure;
14834
14835 genlmsg_end(msg, hdr);
14836
14837 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014838 }
Ben Greear37c73b52012-10-26 14:49:25 -070014839 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014840 return;
14841
14842 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014843 spin_unlock_bh(&rdev->beacon_registrations_lock);
14844 if (hdr)
14845 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014846 nlmsg_free(msg);
14847}
14848EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14849
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014850#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014851static int cfg80211_net_detect_results(struct sk_buff *msg,
14852 struct cfg80211_wowlan_wakeup *wakeup)
14853{
14854 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14855 struct nlattr *nl_results, *nl_match, *nl_freqs;
14856 int i, j;
14857
14858 nl_results = nla_nest_start(
14859 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14860 if (!nl_results)
14861 return -EMSGSIZE;
14862
14863 for (i = 0; i < nd->n_matches; i++) {
14864 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14865
14866 nl_match = nla_nest_start(msg, i);
14867 if (!nl_match)
14868 break;
14869
14870 /* The SSID attribute is optional in nl80211, but for
14871 * simplicity reasons it's always present in the
14872 * cfg80211 structure. If a driver can't pass the
14873 * SSID, that needs to be changed. A zero length SSID
14874 * is still a valid SSID (wildcard), so it cannot be
14875 * used for this purpose.
14876 */
14877 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14878 match->ssid.ssid)) {
14879 nla_nest_cancel(msg, nl_match);
14880 goto out;
14881 }
14882
14883 if (match->n_channels) {
14884 nl_freqs = nla_nest_start(
14885 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14886 if (!nl_freqs) {
14887 nla_nest_cancel(msg, nl_match);
14888 goto out;
14889 }
14890
14891 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014892 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014893 nla_nest_cancel(msg, nl_freqs);
14894 nla_nest_cancel(msg, nl_match);
14895 goto out;
14896 }
14897 }
14898
14899 nla_nest_end(msg, nl_freqs);
14900 }
14901
14902 nla_nest_end(msg, nl_match);
14903 }
14904
14905out:
14906 nla_nest_end(msg, nl_results);
14907 return 0;
14908}
14909
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014910void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14911 struct cfg80211_wowlan_wakeup *wakeup,
14912 gfp_t gfp)
14913{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014914 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014915 struct sk_buff *msg;
14916 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014917 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014918
14919 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14920
14921 if (wakeup)
14922 size += wakeup->packet_present_len;
14923
14924 msg = nlmsg_new(size, gfp);
14925 if (!msg)
14926 return;
14927
14928 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14929 if (!hdr)
14930 goto free_msg;
14931
14932 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014933 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14934 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014935 goto free_msg;
14936
14937 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14938 wdev->netdev->ifindex))
14939 goto free_msg;
14940
14941 if (wakeup) {
14942 struct nlattr *reasons;
14943
14944 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014945 if (!reasons)
14946 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014947
14948 if (wakeup->disconnect &&
14949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14950 goto free_msg;
14951 if (wakeup->magic_pkt &&
14952 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14953 goto free_msg;
14954 if (wakeup->gtk_rekey_failure &&
14955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14956 goto free_msg;
14957 if (wakeup->eap_identity_req &&
14958 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14959 goto free_msg;
14960 if (wakeup->four_way_handshake &&
14961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14962 goto free_msg;
14963 if (wakeup->rfkill_release &&
14964 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14965 goto free_msg;
14966
14967 if (wakeup->pattern_idx >= 0 &&
14968 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14969 wakeup->pattern_idx))
14970 goto free_msg;
14971
Johannes Bergae917c92013-10-25 11:05:22 +020014972 if (wakeup->tcp_match &&
14973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14974 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014975
Johannes Bergae917c92013-10-25 11:05:22 +020014976 if (wakeup->tcp_connlost &&
14977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14978 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014979
Johannes Bergae917c92013-10-25 11:05:22 +020014980 if (wakeup->tcp_nomoretokens &&
14981 nla_put_flag(msg,
14982 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14983 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014984
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014985 if (wakeup->packet) {
14986 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14987 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14988
14989 if (!wakeup->packet_80211) {
14990 pkt_attr =
14991 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14992 len_attr =
14993 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14994 }
14995
14996 if (wakeup->packet_len &&
14997 nla_put_u32(msg, len_attr, wakeup->packet_len))
14998 goto free_msg;
14999
15000 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15001 wakeup->packet))
15002 goto free_msg;
15003 }
15004
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015005 if (wakeup->net_detect &&
15006 cfg80211_net_detect_results(msg, wakeup))
15007 goto free_msg;
15008
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015009 nla_nest_end(msg, reasons);
15010 }
15011
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015012 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015013
Johannes Berg68eb5502013-11-19 15:19:38 +010015014 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015015 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015016 return;
15017
15018 free_msg:
15019 nlmsg_free(msg);
15020}
15021EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15022#endif
15023
Jouni Malinen3475b092012-11-16 22:49:57 +020015024void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15025 enum nl80211_tdls_operation oper,
15026 u16 reason_code, gfp_t gfp)
15027{
15028 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015029 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015030 struct sk_buff *msg;
15031 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015032
15033 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15034 reason_code);
15035
15036 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15037 if (!msg)
15038 return;
15039
15040 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15041 if (!hdr) {
15042 nlmsg_free(msg);
15043 return;
15044 }
15045
15046 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15047 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15048 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15049 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15050 (reason_code > 0 &&
15051 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15052 goto nla_put_failure;
15053
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015054 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015055
Johannes Berg68eb5502013-11-19 15:19:38 +010015056 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015057 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015058 return;
15059
15060 nla_put_failure:
15061 genlmsg_cancel(msg, hdr);
15062 nlmsg_free(msg);
15063}
15064EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15065
Jouni Malinen026331c2010-02-15 12:53:10 +020015066static int nl80211_netlink_notify(struct notifier_block * nb,
15067 unsigned long state,
15068 void *_notify)
15069{
15070 struct netlink_notify *notify = _notify;
15071 struct cfg80211_registered_device *rdev;
15072 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015073 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015074
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015075 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015076 return NOTIFY_DONE;
15077
15078 rcu_read_lock();
15079
Johannes Berg5e760232011-11-04 11:18:17 +010015080 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015081 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015082
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015083 list_for_each_entry_rcu(sched_scan_req,
15084 &rdev->sched_scan_req_list,
15085 list) {
15086 if (sched_scan_req->owner_nlportid == notify->portid) {
15087 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015088 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015089 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015090 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015091
Johannes Berg53873f12016-05-03 16:52:04 +030015092 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015093 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015094
Johannes Bergab810072017-04-26 07:43:41 +020015095 if (wdev->owner_nlportid == notify->portid) {
15096 wdev->nl_owner_dead = true;
15097 schedule_work(&rdev->destroy_work);
15098 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015099 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015100 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015101 }
15102
Ben Greear37c73b52012-10-26 14:49:25 -070015103 spin_lock_bh(&rdev->beacon_registrations_lock);
15104 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15105 list) {
15106 if (reg->nlportid == notify->portid) {
15107 list_del(&reg->list);
15108 kfree(reg);
15109 break;
15110 }
15111 }
15112 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015113 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015114
15115 rcu_read_unlock();
15116
Ilan peer05050752015-03-04 00:32:06 -050015117 /*
15118 * It is possible that the user space process that is controlling the
15119 * indoor setting disappeared, so notify the regulatory core.
15120 */
15121 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015122 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015123}
15124
15125static struct notifier_block nl80211_netlink_notifier = {
15126 .notifier_call = nl80211_netlink_notify,
15127};
15128
Jouni Malinen355199e2013-02-27 17:14:27 +020015129void cfg80211_ft_event(struct net_device *netdev,
15130 struct cfg80211_ft_event_params *ft_event)
15131{
15132 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015133 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015134 struct sk_buff *msg;
15135 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015136
15137 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15138
15139 if (!ft_event->target_ap)
15140 return;
15141
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015142 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015143 if (!msg)
15144 return;
15145
15146 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015147 if (!hdr)
15148 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015149
Johannes Bergae917c92013-10-25 11:05:22 +020015150 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15151 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15152 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15153 goto out;
15154
15155 if (ft_event->ies &&
15156 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15157 goto out;
15158 if (ft_event->ric_ies &&
15159 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15160 ft_event->ric_ies))
15161 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015162
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015163 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015164
Johannes Berg68eb5502013-11-19 15:19:38 +010015165 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015166 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015167 return;
15168 out:
15169 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015170}
15171EXPORT_SYMBOL(cfg80211_ft_event);
15172
Arend van Spriel5de17982013-04-18 15:49:00 +020015173void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15174{
15175 struct cfg80211_registered_device *rdev;
15176 struct sk_buff *msg;
15177 void *hdr;
15178 u32 nlportid;
15179
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015180 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015181 if (!rdev->crit_proto_nlportid)
15182 return;
15183
15184 nlportid = rdev->crit_proto_nlportid;
15185 rdev->crit_proto_nlportid = 0;
15186
15187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15188 if (!msg)
15189 return;
15190
15191 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15192 if (!hdr)
15193 goto nla_put_failure;
15194
15195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015196 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15197 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015198 goto nla_put_failure;
15199
15200 genlmsg_end(msg, hdr);
15201
15202 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15203 return;
15204
15205 nla_put_failure:
15206 if (hdr)
15207 genlmsg_cancel(msg, hdr);
15208 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015209}
15210EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15211
Johannes Berg348baf02014-01-24 14:06:29 +010015212void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15213{
15214 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015215 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015216 struct sk_buff *msg;
15217 void *hdr;
15218
15219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15220 if (!msg)
15221 return;
15222
15223 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15224 if (!hdr)
15225 goto out;
15226
15227 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15228 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015229 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15230 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015231 goto out;
15232
15233 genlmsg_end(msg, hdr);
15234
15235 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15236 NL80211_MCGRP_MLME, GFP_KERNEL);
15237 return;
15238 out:
15239 nlmsg_free(msg);
15240}
15241
Johannes Berg55682962007-09-20 13:09:35 -040015242/* initialisation/exit functions */
15243
Johannes Berg56989f62016-10-24 14:40:05 +020015244int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015245{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015246 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015247
Johannes Berg489111e2016-10-24 14:40:03 +020015248 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015249 if (err)
15250 return err;
15251
Jouni Malinen026331c2010-02-15 12:53:10 +020015252 err = netlink_register_notifier(&nl80211_netlink_notifier);
15253 if (err)
15254 goto err_out;
15255
Johannes Berg55682962007-09-20 13:09:35 -040015256 return 0;
15257 err_out:
15258 genl_unregister_family(&nl80211_fam);
15259 return err;
15260}
15261
15262void nl80211_exit(void)
15263{
Jouni Malinen026331c2010-02-15 12:53:10 +020015264 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015265 genl_unregister_family(&nl80211_fam);
15266}