blob: b1ac23ca20c86be0af71e9a1ba92cc99d8d5a967 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg66cd7942017-02-07 22:40:44 +02006 * Copyright 2015-2017 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Berg55682962007-09-20 13:09:35 -040035/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020036static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040037
Johannes Berg2a94fe42013-11-19 15:19:39 +010038/* multicast groups */
39enum nl80211_multicast_groups {
40 NL80211_MCGRP_CONFIG,
41 NL80211_MCGRP_SCAN,
42 NL80211_MCGRP_REGULATORY,
43 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010044 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030045 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010046 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
47};
48
49static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010050 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
51 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
52 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
53 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
54 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030055 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010056#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010057 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#endif
59};
60
Johannes Berg89a54e42012-06-15 14:33:17 +020061/* returns ERR_PTR values */
62static struct wireless_dev *
63__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040064{
Johannes Berg89a54e42012-06-15 14:33:17 +020065 struct cfg80211_registered_device *rdev;
66 struct wireless_dev *result = NULL;
67 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
68 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
69 u64 wdev_id;
70 int wiphy_idx = -1;
71 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040072
Johannes Berg5fe231e2013-05-08 21:45:15 +020073 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg89a54e42012-06-15 14:33:17 +020075 if (!have_ifidx && !have_wdev_id)
76 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (have_ifidx)
79 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
80 if (have_wdev_id) {
81 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
82 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040083 }
84
Johannes Berg89a54e42012-06-15 14:33:17 +020085 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
86 struct wireless_dev *wdev;
87
88 if (wiphy_net(&rdev->wiphy) != netns)
89 continue;
90
91 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
92 continue;
93
Johannes Berg53873f12016-05-03 16:52:04 +030094 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020095 if (have_ifidx && wdev->netdev &&
96 wdev->netdev->ifindex == ifidx) {
97 result = wdev;
98 break;
99 }
100 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
101 result = wdev;
102 break;
103 }
104 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200105
106 if (result)
107 break;
108 }
109
110 if (result)
111 return result;
112 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400113}
114
Johannes Berga9455402012-06-15 13:32:49 +0200115static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200116__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200117{
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 struct cfg80211_registered_device *rdev = NULL, *tmp;
119 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg5fe231e2013-05-08 21:45:15 +0200121 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg878d9ec2012-06-15 14:18:32 +0200123 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200124 !attrs[NL80211_ATTR_IFINDEX] &&
125 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 return ERR_PTR(-EINVAL);
127
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 if (attrs[NL80211_ATTR_WDEV]) {
133 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
134 struct wireless_dev *wdev;
135 bool found = false;
136
137 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
138 if (tmp) {
139 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300140 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200141 if (wdev->identifier != (u32)wdev_id)
142 continue;
143 found = true;
144 break;
145 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200146
147 if (!found)
148 tmp = NULL;
149
150 if (rdev && tmp != rdev)
151 return ERR_PTR(-EINVAL);
152 rdev = tmp;
153 }
154 }
155
Johannes Berg878d9ec2012-06-15 14:18:32 +0200156 if (attrs[NL80211_ATTR_IFINDEX]) {
157 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700158
Ying Xue7f2b8562014-01-15 10:23:45 +0800159 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200160 if (netdev) {
161 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800162 tmp = wiphy_to_rdev(
163 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200164 else
165 tmp = NULL;
166
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 /* not wireless device -- return error */
168 if (!tmp)
169 return ERR_PTR(-EINVAL);
170
171 /* mismatch -- return error */
172 if (rdev && tmp != rdev)
173 return ERR_PTR(-EINVAL);
174
175 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200176 }
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
178
Johannes Berg4f7eff12012-06-15 14:14:22 +0200179 if (!rdev)
180 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (netns != wiphy_net(&rdev->wiphy))
183 return ERR_PTR(-ENODEV);
184
185 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200186}
187
188/*
189 * This function returns a pointer to the driver
190 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200191 *
192 * The result of this can be a PTR_ERR and hence must
193 * be checked with IS_ERR() for errors.
194 */
195static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200197{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200198 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200199}
200
Johannes Berg55682962007-09-20 13:09:35 -0400201/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300202static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400203 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
204 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700205 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200206 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100207
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200208 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530209 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100210 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
211 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200214 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
215 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
217 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100218 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200219 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400220
221 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
222 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100224
Eliad Pellere007b852011-11-24 18:13:56 +0200225 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
226 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100227
Johannes Bergb9454e82009-07-08 13:29:08 +0200228 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100229 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
230 .len = WLAN_MAX_KEY_LEN },
231 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
232 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
233 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200234 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200235 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100236
237 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
238 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
239 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
240 .len = IEEE80211_MAX_DATA_LEN },
241 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100243 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
244 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
245 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
247 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100248 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100249 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200250 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100251 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800252 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700255 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
256 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
257
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300258 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
259 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200261 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100263 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300264
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800265 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700266 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700267
Johannes Berg6c739412011-11-03 09:27:01 +0100268 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200269
270 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
271 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100273 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200275
276 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_SSID_LEN },
278 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
279 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200280 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300281 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300282 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300283 [NL80211_ATTR_STA_FLAGS2] = {
284 .len = sizeof(struct nl80211_sta_flag_update),
285 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300286 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300287 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
288 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200289 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
290 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
291 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200292 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100293 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300294 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100295 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
296 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200297 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200298 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
299 .len = IEEE80211_MAX_DATA_LEN },
300 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200301 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200302 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300303 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200304 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300305 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
306 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200307 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900308 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
309 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100310 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100311 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100312 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200313 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700314 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300315 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200316 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200317 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300318 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300319 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
320 .len = IEEE80211_MAX_DATA_LEN },
321 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
322 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530323 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300324 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530325 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300326 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
327 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
330 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300331 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100332 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200333 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700335 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800336 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
337 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
338 .len = NL80211_HT_CAPABILITY_LEN
339 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100340 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530341 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530342 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200343 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700344 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300345 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000346 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700347 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100348 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
349 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasari8feb69c2017-07-07 01:43:41 +0300350 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200401 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200408 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
409 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
410 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
411 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200412 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300413 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
414 .len = FILS_ERP_MAX_USERNAME_LEN },
415 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
416 .len = FILS_ERP_MAX_REALM_LEN },
417 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
418 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
419 .len = FILS_ERP_MAX_RRK_LEN },
420 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
421 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100422 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400423};
424
Johannes Berge31b8212010-10-05 19:39:30 +0200425/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000426static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200427 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200428 [NL80211_KEY_IDX] = { .type = NLA_U8 },
429 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200430 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
432 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200433 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
435};
436
437/* policy for the key default flags */
438static const struct nla_policy
439nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
440 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
441 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200442};
443
Johannes Bergf83ace32016-10-17 08:04:07 +0200444#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200445/* policy for WoWLAN attributes */
446static const struct nla_policy
447nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
448 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
449 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
450 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200452 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
453 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
454 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100456 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300457 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100458};
459
460static const struct nla_policy
461nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
462 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
464 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
465 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
466 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
467 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
468 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
469 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
470 },
471 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
472 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
473 },
474 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
475 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
476 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200477};
Johannes Bergf83ace32016-10-17 08:04:07 +0200478#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200479
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700480/* policy for coalesce rule attributes */
481static const struct nla_policy
482nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
483 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
484 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
485 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
486};
487
Johannes Berge5497d72011-07-05 16:35:40 +0200488/* policy for GTK rekey offload attributes */
489static const struct nla_policy
490nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
491 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
492 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
493 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
494};
495
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300496static const struct nla_policy
497nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200498 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300499 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100500 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700501 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300502};
503
Avraham Stern3b06d272015-10-12 09:51:34 +0300504static const struct nla_policy
505nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
506 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
507 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
508};
509
Arend van Spriel38de03d2016-03-02 20:37:18 +0100510static const struct nla_policy
511nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
512 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
513 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
514 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
515 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
516 },
517};
518
Ayala Bekera442b762016-09-20 17:31:15 +0300519/* policy for NAN function attributes */
520static const struct nla_policy
521nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
522 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300523 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300524 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
525 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
526 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
527 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
528 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
529 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
530 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
531 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
532 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
533 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
534 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
535 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
536 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
537 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
538 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
539 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
540};
541
542/* policy for Service Response Filter attributes */
543static const struct nla_policy
544nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
545 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
546 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
547 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
548 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
549 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
550};
551
Peng Xuad670232017-10-03 23:21:51 +0300552/* policy for packet pattern attributes */
553static const struct nla_policy
554nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
555 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
556 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
557 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
558};
559
Johannes Berg97990a02013-04-19 01:02:55 +0200560static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
561 struct netlink_callback *cb,
562 struct cfg80211_registered_device **rdev,
563 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100564{
Johannes Berg67748892010-10-04 21:14:06 +0200565 int err;
566
Johannes Berg97990a02013-04-19 01:02:55 +0200567 if (!cb->args[0]) {
568 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200569 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200570 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200571 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100572 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200573
Johannes Bergc90c39d2016-10-24 14:40:01 +0200574 *wdev = __cfg80211_wdev_from_attrs(
575 sock_net(skb->sk),
576 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100577 if (IS_ERR(*wdev))
578 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800579 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200580 /* 0 is the first index - add 1 to parse only once */
581 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200582 cb->args[1] = (*wdev)->identifier;
583 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200584 /* subtract the 1 again here */
585 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200586 struct wireless_dev *tmp;
587
Johannes Bergea90e0d2017-03-15 14:26:04 +0100588 if (!wiphy)
589 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800590 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200591 *wdev = NULL;
592
Johannes Berg53873f12016-05-03 16:52:04 +0300593 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200594 if (tmp->identifier == cb->args[1]) {
595 *wdev = tmp;
596 break;
597 }
598 }
Johannes Berg97990a02013-04-19 01:02:55 +0200599
Johannes Bergea90e0d2017-03-15 14:26:04 +0100600 if (!*wdev)
601 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200602 }
603
Johannes Berg67748892010-10-04 21:14:06 +0200604 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200605}
606
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100607/* IE validation */
608static bool is_valid_ie_attr(const struct nlattr *attr)
609{
610 const u8 *pos;
611 int len;
612
613 if (!attr)
614 return true;
615
616 pos = nla_data(attr);
617 len = nla_len(attr);
618
619 while (len) {
620 u8 elemlen;
621
622 if (len < 2)
623 return false;
624 len -= 2;
625
626 elemlen = pos[1];
627 if (elemlen > len)
628 return false;
629
630 len -= elemlen;
631 pos += 2 + elemlen;
632 }
633
634 return true;
635}
636
Johannes Berg55682962007-09-20 13:09:35 -0400637/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000638static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400639 int flags, u8 cmd)
640{
641 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000642 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400643}
644
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100646 struct ieee80211_channel *chan,
647 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400648{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200649 /* Some channels must be completely excluded from the
650 * list to protect old user-space tools from breaking
651 */
652 if (!large && chan->flags &
653 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
654 return 0;
655
David S. Miller9360ffd2012-03-29 04:41:26 -0400656 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
657 chan->center_freq))
658 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400659
David S. Miller9360ffd2012-03-29 04:41:26 -0400660 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
662 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200663 if (chan->flags & IEEE80211_CHAN_NO_IR) {
664 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
665 goto nla_put_failure;
666 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
667 goto nla_put_failure;
668 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100669 if (chan->flags & IEEE80211_CHAN_RADAR) {
670 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
671 goto nla_put_failure;
672 if (large) {
673 u32 time;
674
675 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
676
677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
678 chan->dfs_state))
679 goto nla_put_failure;
680 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
681 time))
682 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100683 if (nla_put_u32(msg,
684 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
685 chan->dfs_cac_ms))
686 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100687 }
688 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400689
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100690 if (large) {
691 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
692 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
693 goto nla_put_failure;
694 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
695 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
696 goto nla_put_failure;
697 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
698 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
699 goto nla_put_failure;
700 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
701 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
702 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200703 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
704 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
705 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300706 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200708 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200709 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
710 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
711 goto nla_put_failure;
712 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
713 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
714 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100715 }
716
David S. Miller9360ffd2012-03-29 04:41:26 -0400717 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
718 DBM_TO_MBM(chan->max_power)))
719 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400720
721 return 0;
722
723 nla_put_failure:
724 return -ENOBUFS;
725}
726
Johannes Berg55682962007-09-20 13:09:35 -0400727/* netlink command implementations */
728
Johannes Bergb9454e82009-07-08 13:29:08 +0200729struct key_parse {
730 struct key_params p;
731 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200732 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200733 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100734 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200735};
736
737static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
738{
739 struct nlattr *tb[NL80211_KEY_MAX + 1];
740 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Bergfceb6432017-04-12 14:34:07 +0200741 nl80211_key_policy, NULL);
Johannes Bergb9454e82009-07-08 13:29:08 +0200742 if (err)
743 return err;
744
745 k->def = !!tb[NL80211_KEY_DEFAULT];
746 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
747
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100748 if (k->def) {
749 k->def_uni = true;
750 k->def_multi = true;
751 }
752 if (k->defmgmt)
753 k->def_multi = true;
754
Johannes Bergb9454e82009-07-08 13:29:08 +0200755 if (tb[NL80211_KEY_IDX])
756 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
757
758 if (tb[NL80211_KEY_DATA]) {
759 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
760 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
761 }
762
763 if (tb[NL80211_KEY_SEQ]) {
764 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
765 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
766 }
767
768 if (tb[NL80211_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
770
Johannes Berge31b8212010-10-05 19:39:30 +0200771 if (tb[NL80211_KEY_TYPE]) {
772 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
773 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
774 return -EINVAL;
775 }
776
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100777 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
778 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700779
Johannes Berg2da8f412012-01-20 13:52:37 +0100780 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
781 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Bergfceb6432017-04-12 14:34:07 +0200782 nl80211_key_default_policy, NULL);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (err)
784 return err;
785
786 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
787 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
788 }
789
Johannes Bergb9454e82009-07-08 13:29:08 +0200790 return 0;
791}
792
793static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
794{
795 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
796 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
797 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
798 }
799
800 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
801 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
802 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
803 }
804
805 if (info->attrs[NL80211_ATTR_KEY_IDX])
806 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
807
808 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
809 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
810
811 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
812 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
813
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100814 if (k->def) {
815 k->def_uni = true;
816 k->def_multi = true;
817 }
818 if (k->defmgmt)
819 k->def_multi = true;
820
Johannes Berge31b8212010-10-05 19:39:30 +0200821 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
822 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
823 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
824 return -EINVAL;
825 }
826
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100827 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
828 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200829 int err = nla_parse_nested(kdt,
830 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
831 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200832 nl80211_key_default_policy,
833 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100834 if (err)
835 return err;
836
837 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
838 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
839 }
840
Johannes Bergb9454e82009-07-08 13:29:08 +0200841 return 0;
842}
843
844static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
845{
846 int err;
847
848 memset(k, 0, sizeof(*k));
849 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200850 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200851
852 if (info->attrs[NL80211_ATTR_KEY])
853 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
854 else
855 err = nl80211_parse_key_old(info, k);
856
857 if (err)
858 return err;
859
860 if (k->def && k->defmgmt)
861 return -EINVAL;
862
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100863 if (k->defmgmt) {
864 if (k->def_uni || !k->def_multi)
865 return -EINVAL;
866 }
867
Johannes Bergb9454e82009-07-08 13:29:08 +0200868 if (k->idx != -1) {
869 if (k->defmgmt) {
870 if (k->idx < 4 || k->idx > 5)
871 return -EINVAL;
872 } else if (k->def) {
873 if (k->idx < 0 || k->idx > 3)
874 return -EINVAL;
875 } else {
876 if (k->idx < 0 || k->idx > 5)
877 return -EINVAL;
878 }
879 }
880
881 return 0;
882}
883
Johannes Bergfffd0932009-07-08 14:22:54 +0200884static struct cfg80211_cached_keys *
885nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530886 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200887{
888 struct key_parse parse;
889 struct nlattr *key;
890 struct cfg80211_cached_keys *result;
891 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200892 bool have_key = false;
893
894 nla_for_each_nested(key, keys, rem) {
895 have_key = true;
896 break;
897 }
898
899 if (!have_key)
900 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200901
902 result = kzalloc(sizeof(*result), GFP_KERNEL);
903 if (!result)
904 return ERR_PTR(-ENOMEM);
905
906 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200907
908 nla_for_each_nested(key, keys, rem) {
909 memset(&parse, 0, sizeof(parse));
910 parse.idx = -1;
911
912 err = nl80211_parse_key_new(key, &parse);
913 if (err)
914 goto error;
915 err = -EINVAL;
916 if (!parse.p.key)
917 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200918 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200919 goto error;
920 if (parse.def) {
921 if (def)
922 goto error;
923 def = 1;
924 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100925 if (!parse.def_uni || !parse.def_multi)
926 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200927 } else if (parse.defmgmt)
928 goto error;
929 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200930 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200931 if (err)
932 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200933 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
934 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
935 err = -EINVAL;
936 goto error;
937 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200938 result->params[parse.idx].cipher = parse.p.cipher;
939 result->params[parse.idx].key_len = parse.p.key_len;
940 result->params[parse.idx].key = result->data[parse.idx];
941 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530942
Johannes Berg386b1f22016-09-13 16:10:02 +0200943 /* must be WEP key if we got here */
944 if (no_ht)
945 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200946 }
947
Johannes Bergf1c1f172016-09-13 17:08:23 +0200948 if (result->def < 0) {
949 err = -EINVAL;
950 goto error;
951 }
952
Johannes Bergfffd0932009-07-08 14:22:54 +0200953 return result;
954 error:
955 kfree(result);
956 return ERR_PTR(err);
957}
958
959static int nl80211_key_allowed(struct wireless_dev *wdev)
960{
961 ASSERT_WDEV_LOCK(wdev);
962
Johannes Bergfffd0932009-07-08 14:22:54 +0200963 switch (wdev->iftype) {
964 case NL80211_IFTYPE_AP:
965 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200966 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700967 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200968 break;
969 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200970 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200971 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200972 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200973 return -ENOLINK;
974 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100975 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100976 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100977 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300978 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100979 case NL80211_IFTYPE_P2P_DEVICE:
980 case NL80211_IFTYPE_WDS:
981 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200982 return -EINVAL;
983 }
984
985 return 0;
986}
987
Jouni Malinen664834d2014-01-15 00:01:44 +0200988static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
989 struct nlattr *tb)
990{
991 struct ieee80211_channel *chan;
992
993 if (tb == NULL)
994 return NULL;
995 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
996 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
997 return NULL;
998 return chan;
999}
1000
Johannes Berg7527a782011-05-13 10:58:57 +02001001static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1002{
1003 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1004 int i;
1005
1006 if (!nl_modes)
1007 goto nla_put_failure;
1008
1009 i = 0;
1010 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001011 if ((ifmodes & 1) && nla_put_flag(msg, i))
1012 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001013 ifmodes >>= 1;
1014 i++;
1015 }
1016
1017 nla_nest_end(msg, nl_modes);
1018 return 0;
1019
1020nla_put_failure:
1021 return -ENOBUFS;
1022}
1023
1024static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001025 struct sk_buff *msg,
1026 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001027{
1028 struct nlattr *nl_combis;
1029 int i, j;
1030
1031 nl_combis = nla_nest_start(msg,
1032 NL80211_ATTR_INTERFACE_COMBINATIONS);
1033 if (!nl_combis)
1034 goto nla_put_failure;
1035
1036 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1037 const struct ieee80211_iface_combination *c;
1038 struct nlattr *nl_combi, *nl_limits;
1039
1040 c = &wiphy->iface_combinations[i];
1041
1042 nl_combi = nla_nest_start(msg, i + 1);
1043 if (!nl_combi)
1044 goto nla_put_failure;
1045
1046 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1047 if (!nl_limits)
1048 goto nla_put_failure;
1049
1050 for (j = 0; j < c->n_limits; j++) {
1051 struct nlattr *nl_limit;
1052
1053 nl_limit = nla_nest_start(msg, j + 1);
1054 if (!nl_limit)
1055 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001056 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1057 c->limits[j].max))
1058 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001059 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1060 c->limits[j].types))
1061 goto nla_put_failure;
1062 nla_nest_end(msg, nl_limit);
1063 }
1064
1065 nla_nest_end(msg, nl_limits);
1066
David S. Miller9360ffd2012-03-29 04:41:26 -04001067 if (c->beacon_int_infra_match &&
1068 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1069 goto nla_put_failure;
1070 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1071 c->num_different_channels) ||
1072 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1073 c->max_interfaces))
1074 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001075 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001076 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1077 c->radar_detect_widths) ||
1078 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1079 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001080 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301081 if (c->beacon_int_min_gcd &&
1082 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1083 c->beacon_int_min_gcd))
1084 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001085
1086 nla_nest_end(msg, nl_combi);
1087 }
1088
1089 nla_nest_end(msg, nl_combis);
1090
1091 return 0;
1092nla_put_failure:
1093 return -ENOBUFS;
1094}
1095
Johannes Berg3713b4e2013-02-14 16:19:38 +01001096#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001097static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1098 struct sk_buff *msg)
1099{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001100 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001101 struct nlattr *nl_tcp;
1102
1103 if (!tcp)
1104 return 0;
1105
1106 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1107 if (!nl_tcp)
1108 return -ENOBUFS;
1109
1110 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1111 tcp->data_payload_max))
1112 return -ENOBUFS;
1113
1114 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1115 tcp->data_payload_max))
1116 return -ENOBUFS;
1117
1118 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1119 return -ENOBUFS;
1120
1121 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1122 sizeof(*tcp->tok), tcp->tok))
1123 return -ENOBUFS;
1124
1125 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1126 tcp->data_interval_max))
1127 return -ENOBUFS;
1128
1129 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1130 tcp->wake_payload_max))
1131 return -ENOBUFS;
1132
1133 nla_nest_end(msg, nl_tcp);
1134 return 0;
1135}
1136
Johannes Berg3713b4e2013-02-14 16:19:38 +01001137static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001139 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001140{
1141 struct nlattr *nl_wowlan;
1142
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001143 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001144 return 0;
1145
1146 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1147 if (!nl_wowlan)
1148 return -ENOBUFS;
1149
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001152 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001153 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001156 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001157 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001158 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001160 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001162 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001163 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001164 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001165 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1166 return -ENOBUFS;
1167
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001168 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001169 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001170 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1171 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1172 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1173 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001174 };
1175
1176 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1177 sizeof(pat), &pat))
1178 return -ENOBUFS;
1179 }
1180
Luciano Coelho75453cc2015-01-09 14:06:37 +02001181 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1182 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1183 rdev->wiphy.wowlan->max_nd_match_sets))
1184 return -ENOBUFS;
1185
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001186 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001187 return -ENOBUFS;
1188
Johannes Berg3713b4e2013-02-14 16:19:38 +01001189 nla_nest_end(msg, nl_wowlan);
1190
1191 return 0;
1192}
1193#endif
1194
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001195static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001196 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001197{
1198 struct nl80211_coalesce_rule_support rule;
1199
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001200 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001201 return 0;
1202
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001203 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1204 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1205 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1206 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1207 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1208 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001209
1210 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1211 return -ENOBUFS;
1212
1213 return 0;
1214}
1215
Johannes Berg3713b4e2013-02-14 16:19:38 +01001216static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1217 struct ieee80211_supported_band *sband)
1218{
1219 struct nlattr *nl_rates, *nl_rate;
1220 struct ieee80211_rate *rate;
1221 int i;
1222
1223 /* add HT info */
1224 if (sband->ht_cap.ht_supported &&
1225 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1226 sizeof(sband->ht_cap.mcs),
1227 &sband->ht_cap.mcs) ||
1228 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1229 sband->ht_cap.cap) ||
1230 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1231 sband->ht_cap.ampdu_factor) ||
1232 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1233 sband->ht_cap.ampdu_density)))
1234 return -ENOBUFS;
1235
1236 /* add VHT info */
1237 if (sband->vht_cap.vht_supported &&
1238 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1239 sizeof(sband->vht_cap.vht_mcs),
1240 &sband->vht_cap.vht_mcs) ||
1241 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1242 sband->vht_cap.cap)))
1243 return -ENOBUFS;
1244
1245 /* add bitrates */
1246 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1247 if (!nl_rates)
1248 return -ENOBUFS;
1249
1250 for (i = 0; i < sband->n_bitrates; i++) {
1251 nl_rate = nla_nest_start(msg, i);
1252 if (!nl_rate)
1253 return -ENOBUFS;
1254
1255 rate = &sband->bitrates[i];
1256 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1257 rate->bitrate))
1258 return -ENOBUFS;
1259 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1260 nla_put_flag(msg,
1261 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1262 return -ENOBUFS;
1263
1264 nla_nest_end(msg, nl_rate);
1265 }
1266
1267 nla_nest_end(msg, nl_rates);
1268
1269 return 0;
1270}
1271
1272static int
1273nl80211_send_mgmt_stypes(struct sk_buff *msg,
1274 const struct ieee80211_txrx_stypes *mgmt_stypes)
1275{
1276 u16 stypes;
1277 struct nlattr *nl_ftypes, *nl_ifs;
1278 enum nl80211_iftype ift;
1279 int i;
1280
1281 if (!mgmt_stypes)
1282 return 0;
1283
1284 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1285 if (!nl_ifs)
1286 return -ENOBUFS;
1287
1288 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1289 nl_ftypes = nla_nest_start(msg, ift);
1290 if (!nl_ftypes)
1291 return -ENOBUFS;
1292 i = 0;
1293 stypes = mgmt_stypes[ift].tx;
1294 while (stypes) {
1295 if ((stypes & 1) &&
1296 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1297 (i << 4) | IEEE80211_FTYPE_MGMT))
1298 return -ENOBUFS;
1299 stypes >>= 1;
1300 i++;
1301 }
1302 nla_nest_end(msg, nl_ftypes);
1303 }
1304
1305 nla_nest_end(msg, nl_ifs);
1306
1307 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1308 if (!nl_ifs)
1309 return -ENOBUFS;
1310
1311 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1312 nl_ftypes = nla_nest_start(msg, ift);
1313 if (!nl_ftypes)
1314 return -ENOBUFS;
1315 i = 0;
1316 stypes = mgmt_stypes[ift].rx;
1317 while (stypes) {
1318 if ((stypes & 1) &&
1319 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1320 (i << 4) | IEEE80211_FTYPE_MGMT))
1321 return -ENOBUFS;
1322 stypes >>= 1;
1323 i++;
1324 }
1325 nla_nest_end(msg, nl_ftypes);
1326 }
1327 nla_nest_end(msg, nl_ifs);
1328
1329 return 0;
1330}
1331
Johannes Berg17948992016-10-26 11:42:04 +02001332#define CMD(op, n) \
1333 do { \
1334 if (rdev->ops->op) { \
1335 i++; \
1336 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1337 goto nla_put_failure; \
1338 } \
1339 } while (0)
1340
1341static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1342 struct sk_buff *msg)
1343{
1344 int i = 0;
1345
1346 /*
1347 * do *NOT* add anything into this function, new things need to be
1348 * advertised only to new versions of userspace that can deal with
1349 * the split (and they can't possibly care about new features...
1350 */
1351 CMD(add_virtual_intf, NEW_INTERFACE);
1352 CMD(change_virtual_intf, SET_INTERFACE);
1353 CMD(add_key, NEW_KEY);
1354 CMD(start_ap, START_AP);
1355 CMD(add_station, NEW_STATION);
1356 CMD(add_mpath, NEW_MPATH);
1357 CMD(update_mesh_config, SET_MESH_CONFIG);
1358 CMD(change_bss, SET_BSS);
1359 CMD(auth, AUTHENTICATE);
1360 CMD(assoc, ASSOCIATE);
1361 CMD(deauth, DEAUTHENTICATE);
1362 CMD(disassoc, DISASSOCIATE);
1363 CMD(join_ibss, JOIN_IBSS);
1364 CMD(join_mesh, JOIN_MESH);
1365 CMD(set_pmksa, SET_PMKSA);
1366 CMD(del_pmksa, DEL_PMKSA);
1367 CMD(flush_pmksa, FLUSH_PMKSA);
1368 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1369 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1370 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1371 CMD(mgmt_tx, FRAME);
1372 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1373 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1374 i++;
1375 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1376 goto nla_put_failure;
1377 }
1378 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1379 rdev->ops->join_mesh) {
1380 i++;
1381 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1382 goto nla_put_failure;
1383 }
1384 CMD(set_wds_peer, SET_WDS_PEER);
1385 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1386 CMD(tdls_mgmt, TDLS_MGMT);
1387 CMD(tdls_oper, TDLS_OPER);
1388 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001389 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001390 CMD(sched_scan_start, START_SCHED_SCAN);
1391 CMD(probe_client, PROBE_CLIENT);
1392 CMD(set_noack_map, SET_NOACK_MAP);
1393 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1394 i++;
1395 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1396 goto nla_put_failure;
1397 }
1398 CMD(start_p2p_device, START_P2P_DEVICE);
1399 CMD(set_mcast_rate, SET_MCAST_RATE);
1400#ifdef CONFIG_NL80211_TESTMODE
1401 CMD(testmode_cmd, TESTMODE);
1402#endif
1403
1404 if (rdev->ops->connect || rdev->ops->auth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1407 goto nla_put_failure;
1408 }
1409
1410 if (rdev->ops->disconnect || rdev->ops->deauth) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1413 goto nla_put_failure;
1414 }
1415
1416 return i;
1417 nla_put_failure:
1418 return -ENOBUFS;
1419}
1420
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421struct nl80211_dump_wiphy_state {
1422 s64 filter_wiphy;
1423 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301424 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 bool split;
1426};
1427
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001428static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001429 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001432{
1433 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001434 struct nlattr *nl_bands, *nl_band;
1435 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001436 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001437 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001438 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001439 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001440 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001441 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001442 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001443
Johannes Berg3bb20552014-05-26 13:52:25 +02001444 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001445 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 return -ENOBUFS;
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (WARN_ON(!state))
1449 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001450
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001451 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001453 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001454 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001456 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001457
Johannes Berg3bb20552014-05-26 13:52:25 +02001458 if (cmd != NL80211_CMD_NEW_WIPHY)
1459 goto finish;
1460
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 case 0:
1463 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001464 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001472 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001480 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001482 rdev->wiphy.max_match_sets) ||
1483 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1484 rdev->wiphy.max_sched_scan_plans) ||
1485 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1486 rdev->wiphy.max_sched_scan_plan_interval) ||
1487 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1488 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001489 goto nla_put_failure;
1490
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1493 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1496 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1499 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1502 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1505 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001508 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 state->split_start++;
1510 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 break;
1512 case 1:
1513 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1515 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001516 goto nla_put_failure;
1517
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001520 goto nla_put_failure;
1521
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1524 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001525
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001531
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001536
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001537 if ((rdev->wiphy.available_antennas_tx ||
1538 rdev->wiphy.available_antennas_rx) &&
1539 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 u32 tx_ant = 0, rx_ant = 0;
1541 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001542
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001543 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 if (!res) {
1545 if (nla_put_u32(msg,
1546 NL80211_ATTR_WIPHY_ANTENNA_TX,
1547 tx_ant) ||
1548 nla_put_u32(msg,
1549 NL80211_ATTR_WIPHY_ANTENNA_RX,
1550 rx_ant))
1551 goto nla_put_failure;
1552 }
Johannes Bergee688b002008-01-24 19:38:39 +01001553 }
1554
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
1556 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 break;
1558 case 2:
1559 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001560 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562 state->split_start++;
1563 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 3:
1566 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1567 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001568 goto nla_put_failure;
1569
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001571 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 struct ieee80211_supported_band *sband;
1573
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575
1576 if (!sband)
1577 continue;
1578
1579 nl_band = nla_nest_start(msg, band);
1580 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001581 goto nla_put_failure;
1582
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 case 0:
1585 if (nl80211_send_band_rateinfo(msg, sband))
1586 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001587 state->chan_start++;
1588 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 break;
1590 default:
1591 /* add frequencies */
1592 nl_freqs = nla_nest_start(
1593 msg, NL80211_BAND_ATTR_FREQS);
1594 if (!nl_freqs)
1595 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001596
Johannes Berg86e8cf92013-06-19 10:57:22 +02001597 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 i < sband->n_channels;
1599 i++) {
1600 nl_freq = nla_nest_start(msg, i);
1601 if (!nl_freq)
1602 goto nla_put_failure;
1603
1604 chan = &sband->channels[i];
1605
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 if (nl80211_msg_put_channel(
1607 msg, chan,
1608 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 goto nla_put_failure;
1610
1611 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 break;
1614 }
1615 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001616 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 nla_nest_end(msg, nl_freqs);
1620 }
1621
1622 nla_nest_end(msg, nl_band);
1623
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001625 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001626 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 band--;
1628 break;
1629 }
Johannes Bergee688b002008-01-24 19:38:39 +01001630 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001632
Johannes Berg57fbcce2016-04-12 15:56:15 +02001633 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001636 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001637
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->band_start == 0 && state->chan_start == 0)
1640 state->split_start++;
1641 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 break;
1643 case 4:
1644 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1645 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001646 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647
Johannes Berg17948992016-10-26 11:42:04 +02001648 i = nl80211_add_commands_unsplit(rdev, msg);
1649 if (i < 0)
1650 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001651 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001652 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1653 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001655 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001656 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001657 if (rdev->wiphy.features &
1658 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001659 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001660 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001661 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001662 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001663#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001664
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
1667 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 break;
1669 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 if (rdev->ops->remain_on_channel &&
1671 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 nla_put_u32(msg,
1673 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001675 goto nla_put_failure;
1676
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001677 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001678 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1679 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001680
Johannes Berg3713b4e2013-02-14 16:19:38 +01001681 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1682 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001683 state->split_start++;
1684 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 break;
1686 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001687#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001690 state->split_start++;
1691 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692 break;
1693#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695#endif
1696 case 7:
1697 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001698 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001699 goto nla_put_failure;
1700
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001701 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001702 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001704
Johannes Berg86e8cf92013-06-19 10:57:22 +02001705 state->split_start++;
1706 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 break;
1708 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001709 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001710 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001712 goto nla_put_failure;
1713
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001714 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001715 /*
1716 * We can only add the per-channel limit information if the
1717 * dump is split, otherwise it makes it too big. Therefore
1718 * only advertise it in that case.
1719 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001720 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001721 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1722 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 goto nla_put_failure;
1724
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001725 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001726 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1728 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 goto nla_put_failure;
1730
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001731 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1732 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001733 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001734 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 goto nla_put_failure;
1736
1737 /*
1738 * Any information below this point is only available to
1739 * applications that can deal with it being split. This
1740 * helps ensure that newly added capabilities don't break
1741 * older tools by overrunning their buffers.
1742 *
1743 * We still increment split_start so that in the split
1744 * case we'll continue with more data in the next round,
1745 * but break unconditionally so unsplit data stops here.
1746 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001748 break;
1749 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001750 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001751 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001752 rdev->wiphy.extended_capabilities_len,
1753 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001754 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 rdev->wiphy.extended_capabilities_len,
1756 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001757 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001758
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001759 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001760 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001761 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1762 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001763 goto nla_put_failure;
1764
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001765 state->split_start++;
1766 break;
1767 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001768 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001769 goto nla_put_failure;
1770
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001772 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1773 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1774 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001775
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001776 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001777 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001779 goto nla_put_failure;
1780
Johannes Bergad7e7182013-11-13 13:37:47 +01001781 state->split_start++;
1782 break;
1783 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001785 const struct nl80211_vendor_cmd_info *info;
1786 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001787
Johannes Berg567ffc32013-12-18 14:43:31 +01001788 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1789 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001790 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001791
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001792 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1793 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001794 if (nla_put(msg, i + 1, sizeof(*info), info))
1795 goto nla_put_failure;
1796 }
1797 nla_nest_end(msg, nested);
1798 }
1799
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001800 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001801 const struct nl80211_vendor_cmd_info *info;
1802 struct nlattr *nested;
1803
1804 nested = nla_nest_start(msg,
1805 NL80211_ATTR_VENDOR_EVENTS);
1806 if (!nested)
1807 goto nla_put_failure;
1808
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001809 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1810 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001811 if (nla_put(msg, i + 1, sizeof(*info), info))
1812 goto nla_put_failure;
1813 }
1814 nla_nest_end(msg, nested);
1815 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001816 state->split_start++;
1817 break;
1818 case 12:
1819 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1820 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1821 rdev->wiphy.max_num_csa_counters))
1822 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001823
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001824 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1825 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1826 goto nla_put_failure;
1827
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001828 if (rdev->wiphy.max_sched_scan_reqs &&
1829 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1830 rdev->wiphy.max_sched_scan_reqs))
1831 goto nla_put_failure;
1832
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001833 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1834 sizeof(rdev->wiphy.ext_features),
1835 rdev->wiphy.ext_features))
1836 goto nla_put_failure;
1837
Arend van Spriel38de03d2016-03-02 20:37:18 +01001838 if (rdev->wiphy.bss_select_support) {
1839 struct nlattr *nested;
1840 u32 bss_select_support = rdev->wiphy.bss_select_support;
1841
1842 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1843 if (!nested)
1844 goto nla_put_failure;
1845
1846 i = 0;
1847 while (bss_select_support) {
1848 if ((bss_select_support & 1) &&
1849 nla_put_flag(msg, i))
1850 goto nla_put_failure;
1851 i++;
1852 bss_select_support >>= 1;
1853 }
1854 nla_nest_end(msg, nested);
1855 }
1856
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301857 state->split_start++;
1858 break;
1859 case 13:
1860 if (rdev->wiphy.num_iftype_ext_capab &&
1861 rdev->wiphy.iftype_ext_capab) {
1862 struct nlattr *nested_ext_capab, *nested;
1863
1864 nested = nla_nest_start(msg,
1865 NL80211_ATTR_IFTYPE_EXT_CAPA);
1866 if (!nested)
1867 goto nla_put_failure;
1868
1869 for (i = state->capa_start;
1870 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1871 const struct wiphy_iftype_ext_capab *capab;
1872
1873 capab = &rdev->wiphy.iftype_ext_capab[i];
1874
1875 nested_ext_capab = nla_nest_start(msg, i);
1876 if (!nested_ext_capab ||
1877 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1878 capab->iftype) ||
1879 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1880 capab->extended_capabilities_len,
1881 capab->extended_capabilities) ||
1882 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1883 capab->extended_capabilities_len,
1884 capab->extended_capabilities_mask))
1885 goto nla_put_failure;
1886
1887 nla_nest_end(msg, nested_ext_capab);
1888 if (state->split)
1889 break;
1890 }
1891 nla_nest_end(msg, nested);
1892 if (i < rdev->wiphy.num_iftype_ext_capab) {
1893 state->capa_start = i + 1;
1894 break;
1895 }
1896 }
1897
Luca Coelho85859892017-02-08 15:00:34 +02001898 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1899 rdev->wiphy.nan_supported_bands))
1900 goto nla_put_failure;
1901
Johannes Berg3713b4e2013-02-14 16:19:38 +01001902 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001903 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001904 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001905 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001906 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001907 genlmsg_end(msg, hdr);
1908 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001909
1910 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001911 genlmsg_cancel(msg, hdr);
1912 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001913}
1914
Johannes Berg86e8cf92013-06-19 10:57:22 +02001915static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1916 struct netlink_callback *cb,
1917 struct nl80211_dump_wiphy_state *state)
1918{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001919 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02001920 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
1921 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 /* ignore parse errors for backward compatibility */
1923 if (ret)
1924 return 0;
1925
1926 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1927 if (tb[NL80211_ATTR_WIPHY])
1928 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1929 if (tb[NL80211_ATTR_WDEV])
1930 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1931 if (tb[NL80211_ATTR_IFINDEX]) {
1932 struct net_device *netdev;
1933 struct cfg80211_registered_device *rdev;
1934 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1935
Ying Xue7f2b8562014-01-15 10:23:45 +08001936 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001937 if (!netdev)
1938 return -ENODEV;
1939 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001940 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001941 netdev->ieee80211_ptr->wiphy);
1942 state->filter_wiphy = rdev->wiphy_idx;
1943 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 }
1945
1946 return 0;
1947}
1948
Johannes Berg55682962007-09-20 13:09:35 -04001949static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1950{
Johannes Berg645e77d2013-03-01 14:03:49 +01001951 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001952 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001953 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001954
Johannes Berg5fe231e2013-05-08 21:45:15 +02001955 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001956 if (!state) {
1957 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001958 if (!state) {
1959 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001960 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001961 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001962 state->filter_wiphy = -1;
1963 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1964 if (ret) {
1965 kfree(state);
1966 rtnl_unlock();
1967 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001968 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001969 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001970 }
1971
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001972 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1973 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001974 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001975 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001976 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001977 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001978 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001979 continue;
1980 /* attempt to fit multiple wiphy data chunks into the skb */
1981 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001982 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1983 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001984 NETLINK_CB(cb->skb).portid,
1985 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001986 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001987 if (ret < 0) {
1988 /*
1989 * If sending the wiphy data didn't fit (ENOBUFS
1990 * or EMSGSIZE returned), this SKB is still
1991 * empty (so it's not too big because another
1992 * wiphy dataset is already in the skb) and
1993 * we've not tried to adjust the dump allocation
1994 * yet ... then adjust the alloc size to be
1995 * bigger, and return 1 but with the empty skb.
1996 * This results in an empty message being RX'ed
1997 * in userspace, but that is ignored.
1998 *
1999 * We can then retry with the larger buffer.
2000 */
2001 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002002 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002003 cb->min_dump_alloc < 4096) {
2004 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002005 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002006 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002007 return 1;
2008 }
2009 idx--;
2010 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002011 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002012 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002013 break;
Johannes Berg55682962007-09-20 13:09:35 -04002014 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002015 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002016
Johannes Berg86e8cf92013-06-19 10:57:22 +02002017 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002018
2019 return skb->len;
2020}
2021
Johannes Berg86e8cf92013-06-19 10:57:22 +02002022static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2023{
2024 kfree((void *)cb->args[0]);
2025 return 0;
2026}
2027
Johannes Berg55682962007-09-20 13:09:35 -04002028static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2029{
2030 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002032 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002033
Johannes Berg645e77d2013-03-01 14:03:49 +01002034 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002035 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002036 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002037
Johannes Berg3bb20552014-05-26 13:52:25 +02002038 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2039 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002040 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002041 nlmsg_free(msg);
2042 return -ENOBUFS;
2043 }
Johannes Berg55682962007-09-20 13:09:35 -04002044
Johannes Berg134e6372009-07-10 09:51:34 +00002045 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002046}
2047
Jouni Malinen31888482008-10-30 16:59:24 +02002048static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2049 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2050 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2051 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2052 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2053 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2054};
2055
2056static int parse_txq_params(struct nlattr *tb[],
2057 struct ieee80211_txq_params *txq_params)
2058{
Johannes Berga3304b02012-03-28 11:04:24 +02002059 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002060 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2061 !tb[NL80211_TXQ_ATTR_AIFS])
2062 return -EINVAL;
2063
Johannes Berga3304b02012-03-28 11:04:24 +02002064 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002065 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2066 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2067 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2068 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2069
Johannes Berga3304b02012-03-28 11:04:24 +02002070 if (txq_params->ac >= NL80211_NUM_ACS)
2071 return -EINVAL;
2072
Jouni Malinen31888482008-10-30 16:59:24 +02002073 return 0;
2074}
2075
Johannes Bergf444de02010-05-05 15:25:02 +02002076static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2077{
2078 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002079 * You can only set the channel explicitly for WDS interfaces,
2080 * all others have their channel managed via their respective
2081 * "establish a connection" command (connect, join, ...)
2082 *
2083 * For AP/GO and mesh mode, the channel can be set with the
2084 * channel userspace API, but is only stored and passed to the
2085 * low-level driver when the AP starts or the mesh is joined.
2086 * This is for backward compatibility, userspace can also give
2087 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002088 *
2089 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002090 * whatever else is going on, so they have their own special
2091 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002092 */
2093 return !wdev ||
2094 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002095 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002096 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2097 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002098}
2099
Johannes Berg683b6d32012-11-08 21:25:48 +01002100static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2101 struct genl_info *info,
2102 struct cfg80211_chan_def *chandef)
2103{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302104 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002105
2106 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2107 return -EINVAL;
2108
2109 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2110
2111 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002112 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2113 chandef->center_freq1 = control_freq;
2114 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002115
2116 /* Primary channel not allowed */
2117 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2118 return -EINVAL;
2119
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002120 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2121 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002122
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002123 chantype = nla_get_u32(
2124 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2125
2126 switch (chantype) {
2127 case NL80211_CHAN_NO_HT:
2128 case NL80211_CHAN_HT20:
2129 case NL80211_CHAN_HT40PLUS:
2130 case NL80211_CHAN_HT40MINUS:
2131 cfg80211_chandef_create(chandef, chandef->chan,
2132 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002133 /* user input for center_freq is incorrect */
2134 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2135 chandef->center_freq1 != nla_get_u32(
2136 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2137 return -EINVAL;
2138 /* center_freq2 must be zero */
2139 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2140 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2141 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002142 break;
2143 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002144 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002145 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002146 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2147 chandef->width =
2148 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2149 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2150 chandef->center_freq1 =
2151 nla_get_u32(
2152 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2153 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2154 chandef->center_freq2 =
2155 nla_get_u32(
2156 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2157 }
2158
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002159 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002160 return -EINVAL;
2161
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002162 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2163 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002164 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002165
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002166 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2167 chandef->width == NL80211_CHAN_WIDTH_10) &&
2168 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2169 return -EINVAL;
2170
Johannes Berg683b6d32012-11-08 21:25:48 +01002171 return 0;
2172}
2173
Johannes Bergf444de02010-05-05 15:25:02 +02002174static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002175 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002176 struct genl_info *info)
2177{
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002179 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002180 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002181 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002182
Jouni Malinene16821b2014-04-28 11:22:08 +03002183 if (dev)
2184 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002185 if (!nl80211_can_set_dev_channel(wdev))
2186 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002187 if (wdev)
2188 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002189
Johannes Berg683b6d32012-11-08 21:25:48 +01002190 result = nl80211_parse_chandef(rdev, info, &chandef);
2191 if (result)
2192 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002193
Johannes Berge8c9bd52012-06-06 08:18:22 +02002194 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002195 case NL80211_IFTYPE_AP:
2196 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002197 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2198 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002199 result = -EINVAL;
2200 break;
2201 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002202 if (wdev->beacon_interval) {
2203 if (!dev || !rdev->ops->set_ap_chanwidth ||
2204 !(rdev->wiphy.features &
2205 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2206 result = -EBUSY;
2207 break;
2208 }
2209
2210 /* Only allow dynamic channel width changes */
2211 if (chandef.chan != wdev->preset_chandef.chan) {
2212 result = -EBUSY;
2213 break;
2214 }
2215 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2216 if (result)
2217 break;
2218 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002219 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002220 result = 0;
2221 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002222 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002223 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002224 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002225 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002226 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002227 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002228 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002229 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002230 }
Johannes Bergf444de02010-05-05 15:25:02 +02002231
2232 return result;
2233}
2234
2235static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2236{
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2238 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002239
Jouni Malinene16821b2014-04-28 11:22:08 +03002240 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002241}
2242
Bill Jordane8347eb2010-10-01 13:54:28 -04002243static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2244{
Johannes Berg43b19952010-10-07 13:10:30 +02002245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2246 struct net_device *dev = info->user_ptr[1];
2247 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002248 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002249
2250 if (!info->attrs[NL80211_ATTR_MAC])
2251 return -EINVAL;
2252
Johannes Berg43b19952010-10-07 13:10:30 +02002253 if (netif_running(dev))
2254 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002255
Johannes Berg43b19952010-10-07 13:10:30 +02002256 if (!rdev->ops->set_wds_peer)
2257 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002258
Johannes Berg43b19952010-10-07 13:10:30 +02002259 if (wdev->iftype != NL80211_IFTYPE_WDS)
2260 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002261
2262 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002263 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002264}
2265
Johannes Berg55682962007-09-20 13:09:35 -04002266static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2267{
2268 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002269 struct net_device *netdev = NULL;
2270 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002271 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002272 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002273 u32 changed;
2274 u8 retry_short = 0, retry_long = 0;
2275 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002277
Johannes Berg5fe231e2013-05-08 21:45:15 +02002278 ASSERT_RTNL();
2279
Johannes Bergf444de02010-05-05 15:25:02 +02002280 /*
2281 * Try to find the wiphy and netdev. Normally this
2282 * function shouldn't need the netdev, but this is
2283 * done for backward compatibility -- previously
2284 * setting the channel was done per wiphy, but now
2285 * it is per netdev. Previous userland like hostapd
2286 * also passed a netdev to set_wiphy, so that it is
2287 * possible to let that go to the right netdev!
2288 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002289
Johannes Bergf444de02010-05-05 15:25:02 +02002290 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2291 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2292
Ying Xue7f2b8562014-01-15 10:23:45 +08002293 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002294 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002295 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002296 else
Johannes Bergf444de02010-05-05 15:25:02 +02002297 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002298 }
2299
Johannes Bergf444de02010-05-05 15:25:02 +02002300 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002301 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2302 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002303 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002304 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002305 wdev = NULL;
2306 netdev = NULL;
2307 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002308 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002309 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002310
2311 /*
2312 * end workaround code, by now the rdev is available
2313 * and locked, and wdev may or may not be NULL.
2314 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002315
2316 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002317 result = cfg80211_dev_rename(
2318 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002319
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002322
Jouni Malinen31888482008-10-30 16:59:24 +02002323 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2324 struct ieee80211_txq_params txq_params;
2325 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2326
Ying Xue7f2b8562014-01-15 10:23:45 +08002327 if (!rdev->ops->set_txq_params)
2328 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002329
Ying Xue7f2b8562014-01-15 10:23:45 +08002330 if (!netdev)
2331 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002332
Johannes Berg133a3ff2011-11-03 14:50:13 +01002333 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2335 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002336
Ying Xue7f2b8562014-01-15 10:23:45 +08002337 if (!netif_running(netdev))
2338 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002339
Jouni Malinen31888482008-10-30 16:59:24 +02002340 nla_for_each_nested(nl_txq_params,
2341 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2342 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002343 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2344 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002345 txq_params_policy,
2346 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002347 if (result)
2348 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002349 result = parse_txq_params(tb, &txq_params);
2350 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002351 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002352
Hila Gonene35e4d22012-06-27 17:19:42 +03002353 result = rdev_set_txq_params(rdev, netdev,
2354 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002355 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002356 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002357 }
2358 }
2359
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002360 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002361 result = __nl80211_set_channel(
2362 rdev,
2363 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2364 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002365 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002366 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002367 }
2368
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002369 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002370 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002371 enum nl80211_tx_power_setting type;
2372 int idx, mbm = 0;
2373
Johannes Bergc8442112012-10-24 10:17:18 +02002374 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2375 txp_wdev = NULL;
2376
Ying Xue7f2b8562014-01-15 10:23:45 +08002377 if (!rdev->ops->set_tx_power)
2378 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002379
2380 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2381 type = nla_get_u32(info->attrs[idx]);
2382
2383 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002384 (type != NL80211_TX_POWER_AUTOMATIC))
2385 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002386
2387 if (type != NL80211_TX_POWER_AUTOMATIC) {
2388 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2389 mbm = nla_get_u32(info->attrs[idx]);
2390 }
2391
Johannes Bergc8442112012-10-24 10:17:18 +02002392 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002393 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002394 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002395 }
2396
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002397 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2398 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2399 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002400
Bruno Randolf7f531e02010-12-16 11:30:22 +09002401 if ((!rdev->wiphy.available_antennas_tx &&
2402 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002403 !rdev->ops->set_antenna)
2404 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002405
2406 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2407 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2408
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002409 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002410 * available antenna masks, except for the "all" mask */
2411 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002412 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2413 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002414
Bruno Randolf7f531e02010-12-16 11:30:22 +09002415 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2416 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002417
Hila Gonene35e4d22012-06-27 17:19:42 +03002418 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002419 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002420 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002421 }
2422
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002423 changed = 0;
2424
2425 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2426 retry_short = nla_get_u8(
2427 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002428 if (retry_short == 0)
2429 return -EINVAL;
2430
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002431 changed |= WIPHY_PARAM_RETRY_SHORT;
2432 }
2433
2434 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2435 retry_long = nla_get_u8(
2436 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002437 if (retry_long == 0)
2438 return -EINVAL;
2439
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002440 changed |= WIPHY_PARAM_RETRY_LONG;
2441 }
2442
2443 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2444 frag_threshold = nla_get_u32(
2445 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002446 if (frag_threshold < 256)
2447 return -EINVAL;
2448
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002449 if (frag_threshold != (u32) -1) {
2450 /*
2451 * Fragments (apart from the last one) are required to
2452 * have even length. Make the fragmentation code
2453 * simpler by stripping LSB should someone try to use
2454 * odd threshold value.
2455 */
2456 frag_threshold &= ~0x1;
2457 }
2458 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2459 }
2460
2461 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2462 rts_threshold = nla_get_u32(
2463 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2464 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2465 }
2466
Lukáš Turek81077e82009-12-21 22:50:47 +01002467 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002468 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2469 return -EINVAL;
2470
Lukáš Turek81077e82009-12-21 22:50:47 +01002471 coverage_class = nla_get_u8(
2472 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2473 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2474 }
2475
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002476 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2477 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2478 return -EOPNOTSUPP;
2479
2480 changed |= WIPHY_PARAM_DYN_ACK;
2481 }
2482
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002483 if (changed) {
2484 u8 old_retry_short, old_retry_long;
2485 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002486 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002487
Ying Xue7f2b8562014-01-15 10:23:45 +08002488 if (!rdev->ops->set_wiphy_params)
2489 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002490
2491 old_retry_short = rdev->wiphy.retry_short;
2492 old_retry_long = rdev->wiphy.retry_long;
2493 old_frag_threshold = rdev->wiphy.frag_threshold;
2494 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002495 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002496
2497 if (changed & WIPHY_PARAM_RETRY_SHORT)
2498 rdev->wiphy.retry_short = retry_short;
2499 if (changed & WIPHY_PARAM_RETRY_LONG)
2500 rdev->wiphy.retry_long = retry_long;
2501 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2502 rdev->wiphy.frag_threshold = frag_threshold;
2503 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2504 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002505 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2506 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002507
Hila Gonene35e4d22012-06-27 17:19:42 +03002508 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002509 if (result) {
2510 rdev->wiphy.retry_short = old_retry_short;
2511 rdev->wiphy.retry_long = old_retry_long;
2512 rdev->wiphy.frag_threshold = old_frag_threshold;
2513 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002514 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002515 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002516 }
2517 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002518 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002519}
2520
Johannes Berg71bbc992012-06-15 15:30:18 +02002521static inline u64 wdev_id(struct wireless_dev *wdev)
2522{
2523 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002524 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002525}
Johannes Berg55682962007-09-20 13:09:35 -04002526
Johannes Berg683b6d32012-11-08 21:25:48 +01002527static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002528 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002529{
Johannes Berg601555c2014-11-27 17:26:56 +01002530 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2531 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002532
Johannes Berg683b6d32012-11-08 21:25:48 +01002533 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2534 chandef->chan->center_freq))
2535 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002536 switch (chandef->width) {
2537 case NL80211_CHAN_WIDTH_20_NOHT:
2538 case NL80211_CHAN_WIDTH_20:
2539 case NL80211_CHAN_WIDTH_40:
2540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2541 cfg80211_get_chandef_type(chandef)))
2542 return -ENOBUFS;
2543 break;
2544 default:
2545 break;
2546 }
2547 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2548 return -ENOBUFS;
2549 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2550 return -ENOBUFS;
2551 if (chandef->center_freq2 &&
2552 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002553 return -ENOBUFS;
2554 return 0;
2555}
2556
Eric W. Biederman15e47302012-09-07 20:12:54 +00002557static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002558 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002559 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002560{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002561 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002562 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002563 void *hdr;
2564
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002565 if (removal)
2566 cmd = NL80211_CMD_DEL_INTERFACE;
2567
2568 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002569 if (!hdr)
2570 return -1;
2571
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002572 if (dev &&
2573 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002574 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002575 goto nla_put_failure;
2576
2577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2578 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002579 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2580 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002581 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002582 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2583 rdev->devlist_generation ^
2584 (cfg80211_rdev_list_generation << 2)))
2585 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002586
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002587 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002588 int ret;
2589 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002590
Johannes Berg683b6d32012-11-08 21:25:48 +01002591 ret = rdev_get_channel(rdev, wdev, &chandef);
2592 if (ret == 0) {
2593 if (nl80211_send_chandef(msg, &chandef))
2594 goto nla_put_failure;
2595 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002596 }
2597
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002598 if (rdev->ops->get_tx_power) {
2599 int dbm, ret;
2600
2601 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2602 if (ret == 0 &&
2603 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2604 DBM_TO_MBM(dbm)))
2605 goto nla_put_failure;
2606 }
2607
Johannes Berg44905262017-10-17 21:56:01 +02002608 wdev_lock(wdev);
2609 switch (wdev->iftype) {
2610 case NL80211_IFTYPE_AP:
2611 if (wdev->ssid_len &&
2612 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002613 goto nla_put_failure;
Johannes Berg44905262017-10-17 21:56:01 +02002614 break;
2615 case NL80211_IFTYPE_STATION:
2616 case NL80211_IFTYPE_P2P_CLIENT:
2617 case NL80211_IFTYPE_ADHOC: {
2618 const u8 *ssid_ie;
2619 if (!wdev->current_bss)
2620 break;
2621 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
2622 WLAN_EID_SSID);
2623 if (!ssid_ie)
2624 break;
2625 if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
2626 goto nla_put_failure;
2627 break;
2628 }
2629 default:
2630 /* nothing */
2631 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002632 }
Johannes Berg44905262017-10-17 21:56:01 +02002633 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002634
Johannes Berg053c0952015-01-16 22:09:00 +01002635 genlmsg_end(msg, hdr);
2636 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002637
2638 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002639 genlmsg_cancel(msg, hdr);
2640 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002641}
2642
2643static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2644{
2645 int wp_idx = 0;
2646 int if_idx = 0;
2647 int wp_start = cb->args[0];
2648 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002649 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002650 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002651 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002652 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002653
Johannes Berg5fe231e2013-05-08 21:45:15 +02002654 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002655 if (!cb->args[2]) {
2656 struct nl80211_dump_wiphy_state state = {
2657 .filter_wiphy = -1,
2658 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002659
2660 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2661 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002662 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002663
2664 filter_wiphy = state.filter_wiphy;
2665
2666 /*
2667 * if filtering, set cb->args[2] to +1 since 0 is the default
2668 * value needed to determine that parsing is necessary.
2669 */
2670 if (filter_wiphy >= 0)
2671 cb->args[2] = filter_wiphy + 1;
2672 else
2673 cb->args[2] = -1;
2674 } else if (cb->args[2] > 0) {
2675 filter_wiphy = cb->args[2] - 1;
2676 }
2677
Johannes Bergf5ea9122009-08-07 16:17:38 +02002678 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2679 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002680 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002681 if (wp_idx < wp_start) {
2682 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002683 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002684 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002685
2686 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2687 continue;
2688
Johannes Berg55682962007-09-20 13:09:35 -04002689 if_idx = 0;
2690
Johannes Berg53873f12016-05-03 16:52:04 +03002691 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002692 if (if_idx < if_start) {
2693 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002694 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002695 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002696 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002697 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002698 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002699 goto out;
2700 }
2701 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002702 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002703
2704 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002705 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002706 out:
Johannes Berg55682962007-09-20 13:09:35 -04002707 cb->args[0] = wp_idx;
2708 cb->args[1] = if_idx;
2709
Johannes Bergea90e0d2017-03-15 14:26:04 +01002710 ret = skb->len;
2711 out_unlock:
2712 rtnl_unlock();
2713
2714 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002715}
2716
2717static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2718{
2719 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002721 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002722
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002724 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002725 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002726
Eric W. Biederman15e47302012-09-07 20:12:54 +00002727 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002728 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002729 nlmsg_free(msg);
2730 return -ENOBUFS;
2731 }
Johannes Berg55682962007-09-20 13:09:35 -04002732
Johannes Berg134e6372009-07-10 09:51:34 +00002733 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002734}
2735
Michael Wu66f7ac52008-01-31 19:48:22 +01002736static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2737 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2738 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2739 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2740 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2741 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002742 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002743};
2744
2745static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2746{
2747 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2748 int flag;
2749
2750 *mntrflags = 0;
2751
2752 if (!nla)
2753 return -EINVAL;
2754
Johannes Bergfceb6432017-04-12 14:34:07 +02002755 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2756 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002757 return -EINVAL;
2758
2759 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2760 if (flags[flag])
2761 *mntrflags |= (1<<flag);
2762
Johannes Berg818a9862017-04-12 11:23:28 +02002763 *mntrflags |= MONITOR_FLAG_CHANGED;
2764
Michael Wu66f7ac52008-01-31 19:48:22 +01002765 return 0;
2766}
2767
Johannes Berg1db77592017-04-12 11:36:31 +02002768static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2769 enum nl80211_iftype type,
2770 struct genl_info *info,
2771 struct vif_params *params)
2772{
2773 bool change = false;
2774 int err;
2775
2776 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2777 if (type != NL80211_IFTYPE_MONITOR)
2778 return -EINVAL;
2779
2780 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2781 &params->flags);
2782 if (err)
2783 return err;
2784
2785 change = true;
2786 }
2787
2788 if (params->flags & MONITOR_FLAG_ACTIVE &&
2789 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2790 return -EOPNOTSUPP;
2791
2792 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2793 const u8 *mumimo_groups;
2794 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2795
2796 if (type != NL80211_IFTYPE_MONITOR)
2797 return -EINVAL;
2798
2799 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2800 return -EOPNOTSUPP;
2801
2802 mumimo_groups =
2803 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2804
2805 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002806 if ((mumimo_groups[0] & BIT(0)) ||
2807 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002808 return -EINVAL;
2809
2810 params->vht_mumimo_groups = mumimo_groups;
2811 change = true;
2812 }
2813
2814 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2815 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2816
2817 if (type != NL80211_IFTYPE_MONITOR)
2818 return -EINVAL;
2819
2820 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2821 return -EOPNOTSUPP;
2822
2823 params->vht_mumimo_follow_addr =
2824 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2825 change = true;
2826 }
2827
2828 return change ? 1 : 0;
2829}
2830
Johannes Berg9bc383d2009-11-19 11:55:19 +01002831static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002832 struct net_device *netdev, u8 use_4addr,
2833 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002834{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002835 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002836 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002837 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002838 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002839 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002840
2841 switch (iftype) {
2842 case NL80211_IFTYPE_AP_VLAN:
2843 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2844 return 0;
2845 break;
2846 case NL80211_IFTYPE_STATION:
2847 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2848 return 0;
2849 break;
2850 default:
2851 break;
2852 }
2853
2854 return -EOPNOTSUPP;
2855}
2856
Johannes Berg55682962007-09-20 13:09:35 -04002857static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2858{
Johannes Berg4c476992010-10-04 21:36:35 +02002859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002860 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002861 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002862 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002863 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002864 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002865
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002866 memset(&params, 0, sizeof(params));
2867
Johannes Berg04a773a2009-04-19 21:24:32 +02002868 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002869
Johannes Berg723b0382008-09-16 20:22:09 +02002870 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002871 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002872 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002873 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002874 if (ntype > NL80211_IFTYPE_MAX)
2875 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002876 }
2877
Johannes Berg92ffe052008-09-16 20:39:36 +02002878 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002879 struct wireless_dev *wdev = dev->ieee80211_ptr;
2880
Johannes Berg4c476992010-10-04 21:36:35 +02002881 if (ntype != NL80211_IFTYPE_MESH_POINT)
2882 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002883 if (netif_running(dev))
2884 return -EBUSY;
2885
2886 wdev_lock(wdev);
2887 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2888 IEEE80211_MAX_MESH_ID_LEN);
2889 wdev->mesh_id_up_len =
2890 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2891 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2892 wdev->mesh_id_up_len);
2893 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002894 }
2895
Felix Fietkau8b787642009-11-10 18:53:10 +01002896 if (info->attrs[NL80211_ATTR_4ADDR]) {
2897 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2898 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002899 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002900 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002901 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002902 } else {
2903 params.use_4addr = -1;
2904 }
2905
Johannes Berg1db77592017-04-12 11:36:31 +02002906 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2907 if (err < 0)
2908 return err;
2909 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002910 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002911
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002912 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002913 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002914 else
2915 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002916
Johannes Berg9bc383d2009-11-19 11:55:19 +01002917 if (!err && params.use_4addr != -1)
2918 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2919
Johannes Berg55682962007-09-20 13:09:35 -04002920 return err;
2921}
2922
2923static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2924{
Johannes Berg4c476992010-10-04 21:36:35 +02002925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002926 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002927 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002928 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002929 int err;
2930 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2931
Johannes Berg78f22b62014-03-24 17:57:27 +01002932 /* to avoid failing a new interface creation due to pending removal */
2933 cfg80211_destroy_ifaces(rdev);
2934
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002935 memset(&params, 0, sizeof(params));
2936
Johannes Berg55682962007-09-20 13:09:35 -04002937 if (!info->attrs[NL80211_ATTR_IFNAME])
2938 return -EINVAL;
2939
2940 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2941 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2942 if (type > NL80211_IFTYPE_MAX)
2943 return -EINVAL;
2944 }
2945
Johannes Berg79c97e92009-07-07 03:56:12 +02002946 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002947 !(rdev->wiphy.interface_modes & (1 << type)))
2948 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002949
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002950 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002951 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2952 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002953 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2954 ETH_ALEN);
2955 if (!is_valid_ether_addr(params.macaddr))
2956 return -EADDRNOTAVAIL;
2957 }
2958
Johannes Berg9bc383d2009-11-19 11:55:19 +01002959 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002960 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002961 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002962 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002963 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002964 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002965
Johannes Berg1db77592017-04-12 11:36:31 +02002966 err = nl80211_parse_mon_options(rdev, type, info, &params);
2967 if (err < 0)
2968 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002969
Johannes Berga18c7192015-02-24 10:56:42 +01002970 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2971 if (!msg)
2972 return -ENOMEM;
2973
Hila Gonene35e4d22012-06-27 17:19:42 +03002974 wdev = rdev_add_virtual_intf(rdev,
2975 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02002976 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002977 if (WARN_ON(!wdev)) {
2978 nlmsg_free(msg);
2979 return -EPROTO;
2980 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002981 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002982 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002983 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002984
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002985 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002986 wdev->owner_nlportid = info->snd_portid;
2987
Johannes Berg98104fde2012-06-16 00:19:54 +02002988 switch (type) {
2989 case NL80211_IFTYPE_MESH_POINT:
2990 if (!info->attrs[NL80211_ATTR_MESH_ID])
2991 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002992 wdev_lock(wdev);
2993 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2994 IEEE80211_MAX_MESH_ID_LEN);
2995 wdev->mesh_id_up_len =
2996 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2997 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2998 wdev->mesh_id_up_len);
2999 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003000 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003001 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003002 case NL80211_IFTYPE_P2P_DEVICE:
3003 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003004 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003005 * through the netdev notifier and must be added here
3006 */
3007 mutex_init(&wdev->mtx);
3008 INIT_LIST_HEAD(&wdev->event_list);
3009 spin_lock_init(&wdev->event_lock);
3010 INIT_LIST_HEAD(&wdev->mgmt_registrations);
3011 spin_lock_init(&wdev->mgmt_registrations_lock);
3012
Johannes Berg98104fde2012-06-16 00:19:54 +02003013 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03003014 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02003015 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02003016 break;
3017 default:
3018 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003019 }
3020
Eric W. Biederman15e47302012-09-07 20:12:54 +00003021 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003022 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003023 nlmsg_free(msg);
3024 return -ENOBUFS;
3025 }
3026
Denis Kenzior896ff062016-08-03 16:58:33 -05003027 /*
3028 * For wdevs which have no associated netdev object (e.g. of type
3029 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3030 * For all other types, the event will be generated from the
3031 * netdev notifier
3032 */
3033 if (!wdev->netdev)
3034 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003035
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003036 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003037}
3038
3039static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3040{
Johannes Berg4c476992010-10-04 21:36:35 +02003041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003042 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003043
Johannes Berg4c476992010-10-04 21:36:35 +02003044 if (!rdev->ops->del_virtual_intf)
3045 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003046
Johannes Berg84efbb82012-06-16 00:00:26 +02003047 /*
3048 * If we remove a wireless device without a netdev then clear
3049 * user_ptr[1] so that nl80211_post_doit won't dereference it
3050 * to check if it needs to do dev_put(). Otherwise it crashes
3051 * since the wdev has been freed, unlike with a netdev where
3052 * we need the dev_put() for the netdev to really be freed.
3053 */
3054 if (!wdev->netdev)
3055 info->user_ptr[1] = NULL;
3056
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003057 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003058}
3059
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003060static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3061{
3062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3063 struct net_device *dev = info->user_ptr[1];
3064 u16 noack_map;
3065
3066 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3067 return -EINVAL;
3068
3069 if (!rdev->ops->set_noack_map)
3070 return -EOPNOTSUPP;
3071
3072 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3073
Hila Gonene35e4d22012-06-27 17:19:42 +03003074 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003075}
3076
Johannes Berg41ade002007-12-19 02:03:29 +01003077struct get_key_cookie {
3078 struct sk_buff *msg;
3079 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003080 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003081};
3082
3083static void get_key_callback(void *c, struct key_params *params)
3084{
Johannes Bergb9454e82009-07-08 13:29:08 +02003085 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003086 struct get_key_cookie *cookie = c;
3087
David S. Miller9360ffd2012-03-29 04:41:26 -04003088 if ((params->key &&
3089 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3090 params->key_len, params->key)) ||
3091 (params->seq &&
3092 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3093 params->seq_len, params->seq)) ||
3094 (params->cipher &&
3095 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3096 params->cipher)))
3097 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003098
Johannes Bergb9454e82009-07-08 13:29:08 +02003099 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3100 if (!key)
3101 goto nla_put_failure;
3102
David S. Miller9360ffd2012-03-29 04:41:26 -04003103 if ((params->key &&
3104 nla_put(cookie->msg, NL80211_KEY_DATA,
3105 params->key_len, params->key)) ||
3106 (params->seq &&
3107 nla_put(cookie->msg, NL80211_KEY_SEQ,
3108 params->seq_len, params->seq)) ||
3109 (params->cipher &&
3110 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3111 params->cipher)))
3112 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003113
David S. Miller9360ffd2012-03-29 04:41:26 -04003114 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3115 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003116
3117 nla_nest_end(cookie->msg, key);
3118
Johannes Berg41ade002007-12-19 02:03:29 +01003119 return;
3120 nla_put_failure:
3121 cookie->error = 1;
3122}
3123
3124static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3125{
Johannes Berg4c476992010-10-04 21:36:35 +02003126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003127 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003128 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003129 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003130 const u8 *mac_addr = NULL;
3131 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003132 struct get_key_cookie cookie = {
3133 .error = 0,
3134 };
3135 void *hdr;
3136 struct sk_buff *msg;
3137
3138 if (info->attrs[NL80211_ATTR_KEY_IDX])
3139 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3140
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003141 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003142 return -EINVAL;
3143
3144 if (info->attrs[NL80211_ATTR_MAC])
3145 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3146
Johannes Berge31b8212010-10-05 19:39:30 +02003147 pairwise = !!mac_addr;
3148 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3149 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003150
Johannes Berge31b8212010-10-05 19:39:30 +02003151 if (kt >= NUM_NL80211_KEYTYPES)
3152 return -EINVAL;
3153 if (kt != NL80211_KEYTYPE_GROUP &&
3154 kt != NL80211_KEYTYPE_PAIRWISE)
3155 return -EINVAL;
3156 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3157 }
3158
Johannes Berg4c476992010-10-04 21:36:35 +02003159 if (!rdev->ops->get_key)
3160 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003161
Johannes Berg0fa7b392015-01-23 11:10:12 +01003162 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3163 return -ENOENT;
3164
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003165 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003166 if (!msg)
3167 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003168
Eric W. Biederman15e47302012-09-07 20:12:54 +00003169 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003170 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003171 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003172 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003173
3174 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003175 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003176
David S. Miller9360ffd2012-03-29 04:41:26 -04003177 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3178 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3179 goto nla_put_failure;
3180 if (mac_addr &&
3181 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3182 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003183
Hila Gonene35e4d22012-06-27 17:19:42 +03003184 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3185 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003186
3187 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003188 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003189
3190 if (cookie.error)
3191 goto nla_put_failure;
3192
3193 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003194 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003195
3196 nla_put_failure:
3197 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003198 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003199 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003200 return err;
3201}
3202
3203static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3204{
Johannes Berg4c476992010-10-04 21:36:35 +02003205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003206 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003207 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003208 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003209
Johannes Bergb9454e82009-07-08 13:29:08 +02003210 err = nl80211_parse_key(info, &key);
3211 if (err)
3212 return err;
3213
3214 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003215 return -EINVAL;
3216
Johannes Bergb9454e82009-07-08 13:29:08 +02003217 /* only support setting default key */
3218 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003219 return -EINVAL;
3220
Johannes Bergfffd0932009-07-08 14:22:54 +02003221 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003222
3223 if (key.def) {
3224 if (!rdev->ops->set_default_key) {
3225 err = -EOPNOTSUPP;
3226 goto out;
3227 }
3228
3229 err = nl80211_key_allowed(dev->ieee80211_ptr);
3230 if (err)
3231 goto out;
3232
Hila Gonene35e4d22012-06-27 17:19:42 +03003233 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003234 key.def_uni, key.def_multi);
3235
3236 if (err)
3237 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003238
Johannes Berg3d23e342009-09-29 23:27:28 +02003239#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003240 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003241#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003242 } else {
3243 if (key.def_uni || !key.def_multi) {
3244 err = -EINVAL;
3245 goto out;
3246 }
3247
3248 if (!rdev->ops->set_default_mgmt_key) {
3249 err = -EOPNOTSUPP;
3250 goto out;
3251 }
3252
3253 err = nl80211_key_allowed(dev->ieee80211_ptr);
3254 if (err)
3255 goto out;
3256
Hila Gonene35e4d22012-06-27 17:19:42 +03003257 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003258 if (err)
3259 goto out;
3260
3261#ifdef CONFIG_CFG80211_WEXT
3262 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3263#endif
3264 }
3265
3266 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003267 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003268
Johannes Berg41ade002007-12-19 02:03:29 +01003269 return err;
3270}
3271
3272static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3273{
Johannes Berg4c476992010-10-04 21:36:35 +02003274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003275 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003276 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003277 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003278 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003279
Johannes Bergb9454e82009-07-08 13:29:08 +02003280 err = nl80211_parse_key(info, &key);
3281 if (err)
3282 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003283
Johannes Bergb9454e82009-07-08 13:29:08 +02003284 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003285 return -EINVAL;
3286
Johannes Berg41ade002007-12-19 02:03:29 +01003287 if (info->attrs[NL80211_ATTR_MAC])
3288 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3289
Johannes Berge31b8212010-10-05 19:39:30 +02003290 if (key.type == -1) {
3291 if (mac_addr)
3292 key.type = NL80211_KEYTYPE_PAIRWISE;
3293 else
3294 key.type = NL80211_KEYTYPE_GROUP;
3295 }
3296
3297 /* for now */
3298 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3299 key.type != NL80211_KEYTYPE_GROUP)
3300 return -EINVAL;
3301
Johannes Berg4c476992010-10-04 21:36:35 +02003302 if (!rdev->ops->add_key)
3303 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003304
Johannes Berge31b8212010-10-05 19:39:30 +02003305 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3306 key.type == NL80211_KEYTYPE_PAIRWISE,
3307 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003308 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003309
3310 wdev_lock(dev->ieee80211_ptr);
3311 err = nl80211_key_allowed(dev->ieee80211_ptr);
3312 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003313 err = rdev_add_key(rdev, dev, key.idx,
3314 key.type == NL80211_KEYTYPE_PAIRWISE,
3315 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003316 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003317
Johannes Berg41ade002007-12-19 02:03:29 +01003318 return err;
3319}
3320
3321static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3322{
Johannes Berg4c476992010-10-04 21:36:35 +02003323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003324 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003325 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003326 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003327 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003328
Johannes Bergb9454e82009-07-08 13:29:08 +02003329 err = nl80211_parse_key(info, &key);
3330 if (err)
3331 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003332
3333 if (info->attrs[NL80211_ATTR_MAC])
3334 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3335
Johannes Berge31b8212010-10-05 19:39:30 +02003336 if (key.type == -1) {
3337 if (mac_addr)
3338 key.type = NL80211_KEYTYPE_PAIRWISE;
3339 else
3340 key.type = NL80211_KEYTYPE_GROUP;
3341 }
3342
3343 /* for now */
3344 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3345 key.type != NL80211_KEYTYPE_GROUP)
3346 return -EINVAL;
3347
Johannes Berg4c476992010-10-04 21:36:35 +02003348 if (!rdev->ops->del_key)
3349 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003350
Johannes Bergfffd0932009-07-08 14:22:54 +02003351 wdev_lock(dev->ieee80211_ptr);
3352 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003353
Johannes Berg0fa7b392015-01-23 11:10:12 +01003354 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003355 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3356 err = -ENOENT;
3357
Johannes Bergfffd0932009-07-08 14:22:54 +02003358 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003359 err = rdev_del_key(rdev, dev, key.idx,
3360 key.type == NL80211_KEYTYPE_PAIRWISE,
3361 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003362
Johannes Berg3d23e342009-09-29 23:27:28 +02003363#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003364 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003365 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003366 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003367 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003368 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3369 }
3370#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003371 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003372
Johannes Berg41ade002007-12-19 02:03:29 +01003373 return err;
3374}
3375
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303376/* This function returns an error or the number of nested attributes */
3377static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3378{
3379 struct nlattr *attr;
3380 int n_entries = 0, tmp;
3381
3382 nla_for_each_nested(attr, nl_attr, tmp) {
3383 if (nla_len(attr) != ETH_ALEN)
3384 return -EINVAL;
3385
3386 n_entries++;
3387 }
3388
3389 return n_entries;
3390}
3391
3392/*
3393 * This function parses ACL information and allocates memory for ACL data.
3394 * On successful return, the calling function is responsible to free the
3395 * ACL buffer returned by this function.
3396 */
3397static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3398 struct genl_info *info)
3399{
3400 enum nl80211_acl_policy acl_policy;
3401 struct nlattr *attr;
3402 struct cfg80211_acl_data *acl;
3403 int i = 0, n_entries, tmp;
3404
3405 if (!wiphy->max_acl_mac_addrs)
3406 return ERR_PTR(-EOPNOTSUPP);
3407
3408 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3409 return ERR_PTR(-EINVAL);
3410
3411 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3412 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3413 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3414 return ERR_PTR(-EINVAL);
3415
3416 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3417 return ERR_PTR(-EINVAL);
3418
3419 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3420 if (n_entries < 0)
3421 return ERR_PTR(n_entries);
3422
3423 if (n_entries > wiphy->max_acl_mac_addrs)
3424 return ERR_PTR(-ENOTSUPP);
3425
3426 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3427 GFP_KERNEL);
3428 if (!acl)
3429 return ERR_PTR(-ENOMEM);
3430
3431 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3432 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3433 i++;
3434 }
3435
3436 acl->n_acl_entries = n_entries;
3437 acl->acl_policy = acl_policy;
3438
3439 return acl;
3440}
3441
3442static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3443{
3444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3445 struct net_device *dev = info->user_ptr[1];
3446 struct cfg80211_acl_data *acl;
3447 int err;
3448
3449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3451 return -EOPNOTSUPP;
3452
3453 if (!dev->ieee80211_ptr->beacon_interval)
3454 return -EINVAL;
3455
3456 acl = parse_acl_data(&rdev->wiphy, info);
3457 if (IS_ERR(acl))
3458 return PTR_ERR(acl);
3459
3460 err = rdev_set_mac_acl(rdev, dev, acl);
3461
3462 kfree(acl);
3463
3464 return err;
3465}
3466
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303467static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3468 u8 *rates, u8 rates_len)
3469{
3470 u8 i;
3471 u32 mask = 0;
3472
3473 for (i = 0; i < rates_len; i++) {
3474 int rate = (rates[i] & 0x7f) * 5;
3475 int ridx;
3476
3477 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3478 struct ieee80211_rate *srate =
3479 &sband->bitrates[ridx];
3480 if (rate == srate->bitrate) {
3481 mask |= 1 << ridx;
3482 break;
3483 }
3484 }
3485 if (ridx == sband->n_bitrates)
3486 return 0; /* rate not found */
3487 }
3488
3489 return mask;
3490}
3491
3492static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3493 u8 *rates, u8 rates_len,
3494 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3495{
3496 u8 i;
3497
3498 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3499
3500 for (i = 0; i < rates_len; i++) {
3501 int ridx, rbit;
3502
3503 ridx = rates[i] / 8;
3504 rbit = BIT(rates[i] % 8);
3505
3506 /* check validity */
3507 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3508 return false;
3509
3510 /* check availability */
3511 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3512 mcs[ridx] |= rbit;
3513 else
3514 return false;
3515 }
3516
3517 return true;
3518}
3519
3520static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3521{
3522 u16 mcs_mask = 0;
3523
3524 switch (vht_mcs_map) {
3525 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3526 break;
3527 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3528 mcs_mask = 0x00FF;
3529 break;
3530 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3531 mcs_mask = 0x01FF;
3532 break;
3533 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3534 mcs_mask = 0x03FF;
3535 break;
3536 default:
3537 break;
3538 }
3539
3540 return mcs_mask;
3541}
3542
3543static void vht_build_mcs_mask(u16 vht_mcs_map,
3544 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3545{
3546 u8 nss;
3547
3548 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3549 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3550 vht_mcs_map >>= 2;
3551 }
3552}
3553
3554static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3555 struct nl80211_txrate_vht *txrate,
3556 u16 mcs[NL80211_VHT_NSS_MAX])
3557{
3558 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3559 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3560 u8 i;
3561
3562 if (!sband->vht_cap.vht_supported)
3563 return false;
3564
3565 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3566
3567 /* Build vht_mcs_mask from VHT capabilities */
3568 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3569
3570 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3571 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3572 mcs[i] = txrate->mcs[i];
3573 else
3574 return false;
3575 }
3576
3577 return true;
3578}
3579
3580static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3581 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3582 .len = NL80211_MAX_SUPP_RATES },
3583 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3584 .len = NL80211_MAX_SUPP_HT_RATES },
3585 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3586 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3587};
3588
3589static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3590 struct cfg80211_bitrate_mask *mask)
3591{
3592 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3594 int rem, i;
3595 struct nlattr *tx_rates;
3596 struct ieee80211_supported_band *sband;
3597 u16 vht_tx_mcs_map;
3598
3599 memset(mask, 0, sizeof(*mask));
3600 /* Default to all rates enabled */
3601 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3602 sband = rdev->wiphy.bands[i];
3603
3604 if (!sband)
3605 continue;
3606
3607 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3608 memcpy(mask->control[i].ht_mcs,
3609 sband->ht_cap.mcs.rx_mask,
3610 sizeof(mask->control[i].ht_mcs));
3611
3612 if (!sband->vht_cap.vht_supported)
3613 continue;
3614
3615 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3616 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3617 }
3618
3619 /* if no rates are given set it back to the defaults */
3620 if (!info->attrs[NL80211_ATTR_TX_RATES])
3621 goto out;
3622
3623 /* The nested attribute uses enum nl80211_band as the index. This maps
3624 * directly to the enum nl80211_band values used in cfg80211.
3625 */
3626 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3627 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3628 enum nl80211_band band = nla_type(tx_rates);
3629 int err;
3630
3631 if (band < 0 || band >= NUM_NL80211_BANDS)
3632 return -EINVAL;
3633 sband = rdev->wiphy.bands[band];
3634 if (sband == NULL)
3635 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003636 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003637 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303638 if (err)
3639 return err;
3640 if (tb[NL80211_TXRATE_LEGACY]) {
3641 mask->control[band].legacy = rateset_to_mask(
3642 sband,
3643 nla_data(tb[NL80211_TXRATE_LEGACY]),
3644 nla_len(tb[NL80211_TXRATE_LEGACY]));
3645 if ((mask->control[band].legacy == 0) &&
3646 nla_len(tb[NL80211_TXRATE_LEGACY]))
3647 return -EINVAL;
3648 }
3649 if (tb[NL80211_TXRATE_HT]) {
3650 if (!ht_rateset_to_mask(
3651 sband,
3652 nla_data(tb[NL80211_TXRATE_HT]),
3653 nla_len(tb[NL80211_TXRATE_HT]),
3654 mask->control[band].ht_mcs))
3655 return -EINVAL;
3656 }
3657 if (tb[NL80211_TXRATE_VHT]) {
3658 if (!vht_set_mcs_mask(
3659 sband,
3660 nla_data(tb[NL80211_TXRATE_VHT]),
3661 mask->control[band].vht_mcs))
3662 return -EINVAL;
3663 }
3664 if (tb[NL80211_TXRATE_GI]) {
3665 mask->control[band].gi =
3666 nla_get_u8(tb[NL80211_TXRATE_GI]);
3667 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3668 return -EINVAL;
3669 }
3670
3671 if (mask->control[band].legacy == 0) {
3672 /* don't allow empty legacy rates if HT or VHT
3673 * are not even supported.
3674 */
3675 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3676 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3677 return -EINVAL;
3678
3679 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3680 if (mask->control[band].ht_mcs[i])
3681 goto out;
3682
3683 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3684 if (mask->control[band].vht_mcs[i])
3685 goto out;
3686
3687 /* legacy and mcs rates may not be both empty */
3688 return -EINVAL;
3689 }
3690 }
3691
3692out:
3693 return 0;
3694}
3695
Johannes Berg8564e382016-09-19 09:44:44 +02003696static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3697 enum nl80211_band band,
3698 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303699{
Johannes Berg8564e382016-09-19 09:44:44 +02003700 u32 count_ht, count_vht, i;
3701 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303702
3703 /* Allow only one rate */
3704 if (hweight32(rate) > 1)
3705 return -EINVAL;
3706
3707 count_ht = 0;
3708 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003709 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303710 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003711 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303712 count_ht++;
3713 if (count_ht > 1)
3714 return -EINVAL;
3715 }
3716 if (count_ht && rate)
3717 return -EINVAL;
3718 }
3719
3720 count_vht = 0;
3721 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003722 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303723 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003724 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303725 count_vht++;
3726 if (count_vht > 1)
3727 return -EINVAL;
3728 }
3729 if (count_vht && rate)
3730 return -EINVAL;
3731 }
3732
3733 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3734 return -EINVAL;
3735
Johannes Berg8564e382016-09-19 09:44:44 +02003736 if (rate &&
3737 !wiphy_ext_feature_isset(&rdev->wiphy,
3738 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3739 return -EINVAL;
3740 if (count_ht &&
3741 !wiphy_ext_feature_isset(&rdev->wiphy,
3742 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3743 return -EINVAL;
3744 if (count_vht &&
3745 !wiphy_ext_feature_isset(&rdev->wiphy,
3746 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3747 return -EINVAL;
3748
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303749 return 0;
3750}
3751
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003752static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003753 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003754{
Johannes Berg88600202012-02-13 15:17:18 +01003755 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003756
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003757 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3758 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3759 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3760 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003761 return -EINVAL;
3762
Johannes Berg88600202012-02-13 15:17:18 +01003763 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003764
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003765 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3766 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3767 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003768 if (!bcn->head_len)
3769 return -EINVAL;
3770 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003771 }
3772
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003773 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3774 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3775 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003776 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003777 }
3778
Johannes Berg4c476992010-10-04 21:36:35 +02003779 if (!haveinfo)
3780 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003781
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003782 if (attrs[NL80211_ATTR_IE]) {
3783 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3784 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003785 }
3786
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003787 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003788 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003789 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003790 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003791 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003792 }
3793
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003794 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003795 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003796 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003797 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003798 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003799 }
3800
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003801 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3802 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3803 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003804 }
3805
Johannes Berg88600202012-02-13 15:17:18 +01003806 return 0;
3807}
3808
Johannes Berg66cd7942017-02-07 22:40:44 +02003809static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3810 const u8 *rates)
3811{
3812 int i;
3813
3814 if (!rates)
3815 return;
3816
3817 for (i = 0; i < rates[1]; i++) {
3818 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3819 params->ht_required = true;
3820 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3821 params->vht_required = true;
3822 }
3823}
3824
3825/*
3826 * Since the nl80211 API didn't include, from the beginning, attributes about
3827 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3828 * benefit of drivers that rebuild IEs in the firmware.
3829 */
3830static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3831{
3832 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07003833 size_t ies_len = bcn->tail_len;
3834 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02003835 const u8 *rates;
3836 const u8 *cap;
3837
3838 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3839 nl80211_check_ap_rate_selectors(params, rates);
3840
3841 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3842 nl80211_check_ap_rate_selectors(params, rates);
3843
3844 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3845 if (cap && cap[1] >= sizeof(*params->ht_cap))
3846 params->ht_cap = (void *)(cap + 2);
3847 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3848 if (cap && cap[1] >= sizeof(*params->vht_cap))
3849 params->vht_cap = (void *)(cap + 2);
3850}
3851
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003852static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3853 struct cfg80211_ap_settings *params)
3854{
3855 struct wireless_dev *wdev;
3856 bool ret = false;
3857
Johannes Berg53873f12016-05-03 16:52:04 +03003858 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003859 if (wdev->iftype != NL80211_IFTYPE_AP &&
3860 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3861 continue;
3862
Johannes Berg683b6d32012-11-08 21:25:48 +01003863 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003864 continue;
3865
Johannes Berg683b6d32012-11-08 21:25:48 +01003866 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003867 ret = true;
3868 break;
3869 }
3870
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003871 return ret;
3872}
3873
Jouni Malinene39e5b52012-09-30 19:29:39 +03003874static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3875 enum nl80211_auth_type auth_type,
3876 enum nl80211_commands cmd)
3877{
3878 if (auth_type > NL80211_AUTHTYPE_MAX)
3879 return false;
3880
3881 switch (cmd) {
3882 case NL80211_CMD_AUTHENTICATE:
3883 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3884 auth_type == NL80211_AUTHTYPE_SAE)
3885 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003886 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3887 NL80211_EXT_FEATURE_FILS_STA) &&
3888 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3889 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3890 auth_type == NL80211_AUTHTYPE_FILS_PK))
3891 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003892 return true;
3893 case NL80211_CMD_CONNECT:
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003894 /* SAE not supported yet */
3895 if (auth_type == NL80211_AUTHTYPE_SAE)
3896 return false;
3897 /* FILS with SK PFS or PK not supported yet */
3898 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3899 auth_type == NL80211_AUTHTYPE_FILS_PK)
3900 return false;
3901 if (!wiphy_ext_feature_isset(
3902 &rdev->wiphy,
3903 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3904 auth_type == NL80211_AUTHTYPE_FILS_SK)
3905 return false;
3906 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003907 case NL80211_CMD_START_AP:
3908 /* SAE not supported yet */
3909 if (auth_type == NL80211_AUTHTYPE_SAE)
3910 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003911 /* FILS not supported yet */
3912 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3913 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3914 auth_type == NL80211_AUTHTYPE_FILS_PK)
3915 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003916 return true;
3917 default:
3918 return false;
3919 }
3920}
3921
Johannes Berg88600202012-02-13 15:17:18 +01003922static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3923{
3924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3925 struct net_device *dev = info->user_ptr[1];
3926 struct wireless_dev *wdev = dev->ieee80211_ptr;
3927 struct cfg80211_ap_settings params;
3928 int err;
3929
3930 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3932 return -EOPNOTSUPP;
3933
3934 if (!rdev->ops->start_ap)
3935 return -EOPNOTSUPP;
3936
3937 if (wdev->beacon_interval)
3938 return -EALREADY;
3939
3940 memset(&params, 0, sizeof(params));
3941
3942 /* these are required for START_AP */
3943 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3944 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3945 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3946 return -EINVAL;
3947
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003948 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003949 if (err)
3950 return err;
3951
3952 params.beacon_interval =
3953 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3954 params.dtim_period =
3955 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3956
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303957 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3958 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003959 if (err)
3960 return err;
3961
3962 /*
3963 * In theory, some of these attributes should be required here
3964 * but since they were not used when the command was originally
3965 * added, keep them optional for old user space programs to let
3966 * them continue to work with drivers that do not need the
3967 * additional information -- drivers must check!
3968 */
3969 if (info->attrs[NL80211_ATTR_SSID]) {
3970 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3971 params.ssid_len =
3972 nla_len(info->attrs[NL80211_ATTR_SSID]);
3973 if (params.ssid_len == 0 ||
3974 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3975 return -EINVAL;
3976 }
3977
3978 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3979 params.hidden_ssid = nla_get_u32(
3980 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3981 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3982 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3983 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3984 return -EINVAL;
3985 }
3986
3987 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3988
3989 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3990 params.auth_type = nla_get_u32(
3991 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003992 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3993 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003994 return -EINVAL;
3995 } else
3996 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3997
3998 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3999 NL80211_MAX_NR_CIPHER_SUITES);
4000 if (err)
4001 return err;
4002
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304003 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4004 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4005 return -EOPNOTSUPP;
4006 params.inactivity_timeout = nla_get_u16(
4007 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4008 }
4009
Johannes Berg53cabad2012-11-14 15:17:28 +01004010 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4011 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4012 return -EINVAL;
4013 params.p2p_ctwindow =
4014 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4015 if (params.p2p_ctwindow > 127)
4016 return -EINVAL;
4017 if (params.p2p_ctwindow != 0 &&
4018 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4019 return -EINVAL;
4020 }
4021
4022 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4023 u8 tmp;
4024
4025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4026 return -EINVAL;
4027 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4028 if (tmp > 1)
4029 return -EINVAL;
4030 params.p2p_opp_ps = tmp;
4031 if (params.p2p_opp_ps != 0 &&
4032 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4033 return -EINVAL;
4034 }
4035
Johannes Bergaa430da2012-05-16 23:50:18 +02004036 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004037 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4038 if (err)
4039 return err;
4040 } else if (wdev->preset_chandef.chan) {
4041 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004042 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004043 return -EINVAL;
4044
Arik Nemtsov923b3522015-07-08 15:41:44 +03004045 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4046 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004047 return -EINVAL;
4048
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304049 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4050 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4051 if (err)
4052 return err;
4053
Johannes Berg8564e382016-09-19 09:44:44 +02004054 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4055 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304056 if (err)
4057 return err;
4058 }
4059
Eliad Peller18998c32014-09-10 14:07:34 +03004060 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4061 params.smps_mode =
4062 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4063 switch (params.smps_mode) {
4064 case NL80211_SMPS_OFF:
4065 break;
4066 case NL80211_SMPS_STATIC:
4067 if (!(rdev->wiphy.features &
4068 NL80211_FEATURE_STATIC_SMPS))
4069 return -EINVAL;
4070 break;
4071 case NL80211_SMPS_DYNAMIC:
4072 if (!(rdev->wiphy.features &
4073 NL80211_FEATURE_DYNAMIC_SMPS))
4074 return -EINVAL;
4075 break;
4076 default:
4077 return -EINVAL;
4078 }
4079 } else {
4080 params.smps_mode = NL80211_SMPS_OFF;
4081 }
4082
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304083 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4084 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4085 return -EOPNOTSUPP;
4086
Ola Olsson4baf6be2015-10-29 07:04:58 +01004087 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4088 params.acl = parse_acl_data(&rdev->wiphy, info);
4089 if (IS_ERR(params.acl))
4090 return PTR_ERR(params.acl);
4091 }
4092
Johannes Berg66cd7942017-02-07 22:40:44 +02004093 nl80211_calculate_ap_params(&params);
4094
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004095 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004096 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004097 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004098 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004099 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004100 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004101 wdev->ssid_len = params.ssid_len;
4102 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004103 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004104 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304105
4106 kfree(params.acl);
4107
Johannes Berg56d18932011-05-09 18:41:15 +02004108 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004109}
4110
Johannes Berg88600202012-02-13 15:17:18 +01004111static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4112{
4113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4114 struct net_device *dev = info->user_ptr[1];
4115 struct wireless_dev *wdev = dev->ieee80211_ptr;
4116 struct cfg80211_beacon_data params;
4117 int err;
4118
4119 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4120 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4121 return -EOPNOTSUPP;
4122
4123 if (!rdev->ops->change_beacon)
4124 return -EOPNOTSUPP;
4125
4126 if (!wdev->beacon_interval)
4127 return -EINVAL;
4128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004129 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004130 if (err)
4131 return err;
4132
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004133 wdev_lock(wdev);
4134 err = rdev_change_beacon(rdev, dev, &params);
4135 wdev_unlock(wdev);
4136
4137 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004138}
4139
4140static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004141{
Johannes Berg4c476992010-10-04 21:36:35 +02004142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4143 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004144
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004145 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004146}
4147
Johannes Berg5727ef12007-12-19 02:03:34 +01004148static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4149 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4150 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4151 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004152 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004153 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004154 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004155};
4156
Johannes Bergeccb8e82009-05-11 21:57:56 +03004157static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004158 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004159 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004160{
4161 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004162 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004163 int flag;
4164
Johannes Bergeccb8e82009-05-11 21:57:56 +03004165 /*
4166 * Try parsing the new attribute first so userspace
4167 * can specify both for older kernels.
4168 */
4169 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4170 if (nla) {
4171 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004172
Johannes Bergeccb8e82009-05-11 21:57:56 +03004173 sta_flags = nla_data(nla);
4174 params->sta_flags_mask = sta_flags->mask;
4175 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004176 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004177 if ((params->sta_flags_mask |
4178 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4179 return -EINVAL;
4180 return 0;
4181 }
4182
4183 /* if present, parse the old attribute */
4184
4185 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004186 if (!nla)
4187 return 0;
4188
Johannes Bergfceb6432017-04-12 14:34:07 +02004189 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004190 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004191 return -EINVAL;
4192
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004193 /*
4194 * Only allow certain flags for interface types so that
4195 * other attributes are silently ignored. Remember that
4196 * this is backward compatibility code with old userspace
4197 * and shouldn't be hit in other cases anyway.
4198 */
4199 switch (iftype) {
4200 case NL80211_IFTYPE_AP:
4201 case NL80211_IFTYPE_AP_VLAN:
4202 case NL80211_IFTYPE_P2P_GO:
4203 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4204 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4205 BIT(NL80211_STA_FLAG_WME) |
4206 BIT(NL80211_STA_FLAG_MFP);
4207 break;
4208 case NL80211_IFTYPE_P2P_CLIENT:
4209 case NL80211_IFTYPE_STATION:
4210 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4211 BIT(NL80211_STA_FLAG_TDLS_PEER);
4212 break;
4213 case NL80211_IFTYPE_MESH_POINT:
4214 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4215 BIT(NL80211_STA_FLAG_MFP) |
4216 BIT(NL80211_STA_FLAG_AUTHORIZED);
4217 default:
4218 return -EINVAL;
4219 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004220
Johannes Berg3383b5a2012-05-10 20:14:43 +02004221 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4222 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004223 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004224
Johannes Berg3383b5a2012-05-10 20:14:43 +02004225 /* no longer support new API additions in old API */
4226 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4227 return -EINVAL;
4228 }
4229 }
4230
Johannes Berg5727ef12007-12-19 02:03:34 +01004231 return 0;
4232}
4233
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004234static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4235 int attr)
4236{
4237 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004238 u32 bitrate;
4239 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004240 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004241
4242 rate = nla_nest_start(msg, attr);
4243 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004244 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004245
4246 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4247 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004248 /* report 16-bit bitrate only if we can */
4249 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004250 if (bitrate > 0 &&
4251 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4252 return false;
4253 if (bitrate_compat > 0 &&
4254 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4255 return false;
4256
Johannes Bergb51f3be2015-01-15 16:14:02 +01004257 switch (info->bw) {
4258 case RATE_INFO_BW_5:
4259 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4260 break;
4261 case RATE_INFO_BW_10:
4262 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4263 break;
4264 default:
4265 WARN_ON(1);
4266 /* fall through */
4267 case RATE_INFO_BW_20:
4268 rate_flg = 0;
4269 break;
4270 case RATE_INFO_BW_40:
4271 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4272 break;
4273 case RATE_INFO_BW_80:
4274 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4275 break;
4276 case RATE_INFO_BW_160:
4277 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4278 break;
4279 }
4280
4281 if (rate_flg && nla_put_flag(msg, rate_flg))
4282 return false;
4283
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004284 if (info->flags & RATE_INFO_FLAGS_MCS) {
4285 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4286 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004287 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4288 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4289 return false;
4290 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4291 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4292 return false;
4293 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4294 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004295 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4296 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4297 return false;
4298 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004299
4300 nla_nest_end(msg, rate);
4301 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004302}
4303
Felix Fietkau119363c2013-04-22 16:29:30 +02004304static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4305 int id)
4306{
4307 void *attr;
4308 int i = 0;
4309
4310 if (!mask)
4311 return true;
4312
4313 attr = nla_nest_start(msg, id);
4314 if (!attr)
4315 return false;
4316
4317 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4318 if (!(mask & BIT(i)))
4319 continue;
4320
4321 if (nla_put_u8(msg, i, signal[i]))
4322 return false;
4323 }
4324
4325 nla_nest_end(msg, attr);
4326
4327 return true;
4328}
4329
Johannes Bergcf5ead82014-11-14 17:14:00 +01004330static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4331 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004332 struct cfg80211_registered_device *rdev,
4333 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004334 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004335{
4336 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004337 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004338
Johannes Bergcf5ead82014-11-14 17:14:00 +01004339 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004340 if (!hdr)
4341 return -1;
4342
David S. Miller9360ffd2012-03-29 04:41:26 -04004343 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4344 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4345 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4346 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004347
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004348 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4349 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004350 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004351
4352#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004353 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304354 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004355 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4356 sinfo->memb)) \
4357 goto nla_put_failure; \
4358 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004359#define PUT_SINFO_U64(attr, memb) do { \
4360 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4361 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4362 sinfo->memb, NL80211_STA_INFO_PAD)) \
4363 goto nla_put_failure; \
4364 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004365
4366 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4367 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4368
4369 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4370 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004371 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004372 (u32)sinfo->rx_bytes))
4373 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004374
4375 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4376 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004377 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4378 (u32)sinfo->tx_bytes))
4379 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004380
Johannes Bergd686b922016-04-26 09:54:11 +02004381 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4382 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004383 PUT_SINFO(LLID, llid, u16);
4384 PUT_SINFO(PLID, plid, u16);
4385 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004386 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004387
John W. Linville66266b32012-03-15 13:25:41 -04004388 switch (rdev->wiphy.signal_type) {
4389 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004390 PUT_SINFO(SIGNAL, signal, u8);
4391 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004392 break;
4393 default:
4394 break;
4395 }
Johannes Berg319090b2014-11-17 14:08:11 +01004396 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004397 if (!nl80211_put_signal(msg, sinfo->chains,
4398 sinfo->chain_signal,
4399 NL80211_STA_INFO_CHAIN_SIGNAL))
4400 goto nla_put_failure;
4401 }
Johannes Berg319090b2014-11-17 14:08:11 +01004402 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004403 if (!nl80211_put_signal(msg, sinfo->chains,
4404 sinfo->chain_signal_avg,
4405 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4406 goto nla_put_failure;
4407 }
Johannes Berg319090b2014-11-17 14:08:11 +01004408 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004409 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4410 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004411 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004412 }
Johannes Berg319090b2014-11-17 14:08:11 +01004413 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004414 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4415 NL80211_STA_INFO_RX_BITRATE))
4416 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004417 }
Johannes Berg319090b2014-11-17 14:08:11 +01004418
4419 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4420 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4421 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4422 PUT_SINFO(TX_FAILED, tx_failed, u32);
4423 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4424 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4425 PUT_SINFO(LOCAL_PM, local_pm, u32);
4426 PUT_SINFO(PEER_PM, peer_pm, u32);
4427 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4428
4429 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004430 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4431 if (!bss_param)
4432 goto nla_put_failure;
4433
David S. Miller9360ffd2012-03-29 04:41:26 -04004434 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4435 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4436 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4437 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4438 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4439 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4440 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4441 sinfo->bss_param.dtim_period) ||
4442 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4443 sinfo->bss_param.beacon_interval))
4444 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004445
4446 nla_nest_end(msg, bss_param);
4447 }
Johannes Berg319090b2014-11-17 14:08:11 +01004448 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004449 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4450 sizeof(struct nl80211_sta_flag_update),
4451 &sinfo->sta_flags))
4452 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004453
Johannes Bergd686b922016-04-26 09:54:11 +02004454 PUT_SINFO_U64(T_OFFSET, t_offset);
4455 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4456 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004457 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004458
4459#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004460#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004461
4462 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4463 struct nlattr *tidsattr;
4464 int tid;
4465
4466 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4467 if (!tidsattr)
4468 goto nla_put_failure;
4469
4470 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4471 struct cfg80211_tid_stats *tidstats;
4472 struct nlattr *tidattr;
4473
4474 tidstats = &sinfo->pertid[tid];
4475
4476 if (!tidstats->filled)
4477 continue;
4478
4479 tidattr = nla_nest_start(msg, tid + 1);
4480 if (!tidattr)
4481 goto nla_put_failure;
4482
Johannes Bergd686b922016-04-26 09:54:11 +02004483#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004484 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004485 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4486 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004487 goto nla_put_failure; \
4488 } while (0)
4489
Johannes Bergd686b922016-04-26 09:54:11 +02004490 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4491 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4492 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4493 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004494
Johannes Bergd686b922016-04-26 09:54:11 +02004495#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004496 nla_nest_end(msg, tidattr);
4497 }
4498
4499 nla_nest_end(msg, tidsattr);
4500 }
4501
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004502 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004503
Johannes Berg319090b2014-11-17 14:08:11 +01004504 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004505 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4506 sinfo->assoc_req_ies))
4507 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004508
Johannes Berg053c0952015-01-16 22:09:00 +01004509 genlmsg_end(msg, hdr);
4510 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004511
4512 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004513 genlmsg_cancel(msg, hdr);
4514 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004515}
4516
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004518 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004519{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004520 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004521 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004522 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004523 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004524 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004525 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004526
Johannes Bergea90e0d2017-03-15 14:26:04 +01004527 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004528 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004529 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004530 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004531
Johannes Berg97990a02013-04-19 01:02:55 +02004532 if (!wdev->netdev) {
4533 err = -EINVAL;
4534 goto out_err;
4535 }
4536
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004537 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004539 goto out_err;
4540 }
4541
Johannes Bergbba95fe2008-07-29 13:22:51 +02004542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004543 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004544 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004546 if (err == -ENOENT)
4547 break;
4548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004550
Johannes Bergcf5ead82014-11-14 17:14:00 +01004551 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004554 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004555 &sinfo) < 0)
4556 goto out;
4557
4558 sta_idx++;
4559 }
4560
Johannes Bergbba95fe2008-07-29 13:22:51 +02004561 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004562 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004563 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004564 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004565 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004566
4567 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004568}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004569
Johannes Berg5727ef12007-12-19 02:03:34 +01004570static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4571{
Johannes Berg4c476992010-10-04 21:36:35 +02004572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4573 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004574 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004575 struct sk_buff *msg;
4576 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004577 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004578
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004579 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004580
4581 if (!info->attrs[NL80211_ATTR_MAC])
4582 return -EINVAL;
4583
4584 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4585
Johannes Berg4c476992010-10-04 21:36:35 +02004586 if (!rdev->ops->get_station)
4587 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004588
Hila Gonene35e4d22012-06-27 17:19:42 +03004589 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004590 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004591 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004592
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004593 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004594 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004595 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004596
Johannes Bergcf5ead82014-11-14 17:14:00 +01004597 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4598 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004600 nlmsg_free(msg);
4601 return -ENOBUFS;
4602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004603
Johannes Berg4c476992010-10-04 21:36:35 +02004604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004605}
4606
Johannes Berg77ee7c82013-02-15 00:48:33 +01004607int cfg80211_check_station_change(struct wiphy *wiphy,
4608 struct station_parameters *params,
4609 enum cfg80211_station_type statype)
4610{
Ayala Bekere4208422015-10-23 11:20:06 +03004611 if (params->listen_interval != -1 &&
4612 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004613 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004614
Ayala Beker17b94242016-03-17 15:41:38 +02004615 if (params->support_p2p_ps != -1 &&
4616 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4617 return -EINVAL;
4618
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004619 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004620 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4621 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004622 return -EINVAL;
4623
4624 /* When you run into this, adjust the code below for the new flag */
4625 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4626
4627 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004628 case CFG80211_STA_MESH_PEER_KERNEL:
4629 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004630 /*
4631 * No ignoring the TDLS flag here -- the userspace mesh
4632 * code doesn't have the bug of including TDLS in the
4633 * mask everywhere.
4634 */
4635 if (params->sta_flags_mask &
4636 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4637 BIT(NL80211_STA_FLAG_MFP) |
4638 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4639 return -EINVAL;
4640 break;
4641 case CFG80211_STA_TDLS_PEER_SETUP:
4642 case CFG80211_STA_TDLS_PEER_ACTIVE:
4643 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4644 return -EINVAL;
4645 /* ignore since it can't change */
4646 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4647 break;
4648 default:
4649 /* disallow mesh-specific things */
4650 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4651 return -EINVAL;
4652 if (params->local_pm)
4653 return -EINVAL;
4654 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4655 return -EINVAL;
4656 }
4657
4658 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4659 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4660 /* TDLS can't be set, ... */
4661 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4662 return -EINVAL;
4663 /*
4664 * ... but don't bother the driver with it. This works around
4665 * a hostapd/wpa_supplicant issue -- it always includes the
4666 * TLDS_PEER flag in the mask even for AP mode.
4667 */
4668 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4669 }
4670
Ayala Beker47edb112015-09-21 15:49:53 +03004671 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4672 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004673 /* reject other things that can't change */
4674 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4675 return -EINVAL;
4676 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4677 return -EINVAL;
4678 if (params->supported_rates)
4679 return -EINVAL;
4680 if (params->ext_capab || params->ht_capa || params->vht_capa)
4681 return -EINVAL;
4682 }
4683
Ayala Beker47edb112015-09-21 15:49:53 +03004684 if (statype != CFG80211_STA_AP_CLIENT &&
4685 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004686 if (params->vlan)
4687 return -EINVAL;
4688 }
4689
4690 switch (statype) {
4691 case CFG80211_STA_AP_MLME_CLIENT:
4692 /* Use this only for authorizing/unauthorizing a station */
4693 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4694 return -EOPNOTSUPP;
4695 break;
4696 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004697 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004698 /* accept only the listed bits */
4699 if (params->sta_flags_mask &
4700 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4701 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4702 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4703 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4704 BIT(NL80211_STA_FLAG_WME) |
4705 BIT(NL80211_STA_FLAG_MFP)))
4706 return -EINVAL;
4707
4708 /* but authenticated/associated only if driver handles it */
4709 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4710 params->sta_flags_mask &
4711 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4712 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4713 return -EINVAL;
4714 break;
4715 case CFG80211_STA_IBSS:
4716 case CFG80211_STA_AP_STA:
4717 /* reject any changes other than AUTHORIZED */
4718 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4719 return -EINVAL;
4720 break;
4721 case CFG80211_STA_TDLS_PEER_SETUP:
4722 /* reject any changes other than AUTHORIZED or WME */
4723 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4724 BIT(NL80211_STA_FLAG_WME)))
4725 return -EINVAL;
4726 /* force (at least) rates when authorizing */
4727 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4728 !params->supported_rates)
4729 return -EINVAL;
4730 break;
4731 case CFG80211_STA_TDLS_PEER_ACTIVE:
4732 /* reject any changes */
4733 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004734 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004735 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4736 return -EINVAL;
4737 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004738 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004739 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4740 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004741 return -EINVAL;
4742 break;
4743 }
4744
Beni Lev06f7c882016-07-19 19:28:56 +03004745 /*
4746 * Older kernel versions ignored this attribute entirely, so don't
4747 * reject attempts to update it but mark it as unused instead so the
4748 * driver won't look at the data.
4749 */
4750 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4751 statype != CFG80211_STA_TDLS_PEER_SETUP)
4752 params->opmode_notif_used = false;
4753
Johannes Berg77ee7c82013-02-15 00:48:33 +01004754 return 0;
4755}
4756EXPORT_SYMBOL(cfg80211_check_station_change);
4757
Johannes Berg5727ef12007-12-19 02:03:34 +01004758/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004759 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004760 */
Johannes Berg80b99892011-11-18 16:23:01 +01004761static struct net_device *get_vlan(struct genl_info *info,
4762 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004763{
Johannes Berg463d0182009-07-14 00:33:35 +02004764 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004765 struct net_device *v;
4766 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004767
Johannes Berg80b99892011-11-18 16:23:01 +01004768 if (!vlanattr)
4769 return NULL;
4770
4771 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4772 if (!v)
4773 return ERR_PTR(-ENODEV);
4774
4775 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4776 ret = -EINVAL;
4777 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004778 }
Johannes Berg80b99892011-11-18 16:23:01 +01004779
Johannes Berg77ee7c82013-02-15 00:48:33 +01004780 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4781 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4782 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4783 ret = -EINVAL;
4784 goto error;
4785 }
4786
Johannes Berg80b99892011-11-18 16:23:01 +01004787 if (!netif_running(v)) {
4788 ret = -ENETDOWN;
4789 goto error;
4790 }
4791
4792 return v;
4793 error:
4794 dev_put(v);
4795 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004796}
4797
Johannes Berg94e860f2014-01-20 23:58:15 +01004798static const struct nla_policy
4799nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004800 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4801 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4802};
4803
Johannes Bergff276692013-02-15 00:09:01 +01004804static int nl80211_parse_sta_wme(struct genl_info *info,
4805 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004806{
Jouni Malinendf881292013-02-14 21:10:54 +02004807 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4808 struct nlattr *nla;
4809 int err;
4810
Jouni Malinendf881292013-02-14 21:10:54 +02004811 /* parse WME attributes if present */
4812 if (!info->attrs[NL80211_ATTR_STA_WME])
4813 return 0;
4814
4815 nla = info->attrs[NL80211_ATTR_STA_WME];
4816 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004817 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004818 if (err)
4819 return err;
4820
4821 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4822 params->uapsd_queues = nla_get_u8(
4823 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4824 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4825 return -EINVAL;
4826
4827 if (tb[NL80211_STA_WME_MAX_SP])
4828 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4829
4830 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4831 return -EINVAL;
4832
4833 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4834
4835 return 0;
4836}
4837
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304838static int nl80211_parse_sta_channel_info(struct genl_info *info,
4839 struct station_parameters *params)
4840{
4841 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4842 params->supported_channels =
4843 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4844 params->supported_channels_len =
4845 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4846 /*
4847 * Need to include at least one (first channel, number of
4848 * channels) tuple for each subband, and must have proper
4849 * tuples for the rest of the data as well.
4850 */
4851 if (params->supported_channels_len < 2)
4852 return -EINVAL;
4853 if (params->supported_channels_len % 2)
4854 return -EINVAL;
4855 }
4856
4857 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4858 params->supported_oper_classes =
4859 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4860 params->supported_oper_classes_len =
4861 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4862 /*
4863 * The value of the Length field of the Supported Operating
4864 * Classes element is between 2 and 253.
4865 */
4866 if (params->supported_oper_classes_len < 2 ||
4867 params->supported_oper_classes_len > 253)
4868 return -EINVAL;
4869 }
4870 return 0;
4871}
4872
Johannes Bergff276692013-02-15 00:09:01 +01004873static int nl80211_set_station_tdls(struct genl_info *info,
4874 struct station_parameters *params)
4875{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304876 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004877 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004878 if (info->attrs[NL80211_ATTR_PEER_AID])
4879 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004880 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4881 params->ht_capa =
4882 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4883 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4884 params->vht_capa =
4885 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4886
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304887 err = nl80211_parse_sta_channel_info(info, params);
4888 if (err)
4889 return err;
4890
Johannes Bergff276692013-02-15 00:09:01 +01004891 return nl80211_parse_sta_wme(info, params);
4892}
4893
Johannes Berg5727ef12007-12-19 02:03:34 +01004894static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4895{
Johannes Berg4c476992010-10-04 21:36:35 +02004896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004897 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004898 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004899 u8 *mac_addr;
4900 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004901
4902 memset(&params, 0, sizeof(params));
4903
Johannes Berg77ee7c82013-02-15 00:48:33 +01004904 if (!rdev->ops->change_station)
4905 return -EOPNOTSUPP;
4906
Ayala Bekere4208422015-10-23 11:20:06 +03004907 /*
4908 * AID and listen_interval properties can be set only for unassociated
4909 * station. Include these parameters here and will check them in
4910 * cfg80211_check_station_change().
4911 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004912 if (info->attrs[NL80211_ATTR_STA_AID])
4913 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004914
4915 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4916 params.listen_interval =
4917 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4918 else
4919 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004920
Ayala Beker17b94242016-03-17 15:41:38 +02004921 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4922 u8 tmp;
4923
4924 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4925 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4926 return -EINVAL;
4927
4928 params.support_p2p_ps = tmp;
4929 } else {
4930 params.support_p2p_ps = -1;
4931 }
4932
Johannes Berg5727ef12007-12-19 02:03:34 +01004933 if (!info->attrs[NL80211_ATTR_MAC])
4934 return -EINVAL;
4935
4936 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4937
4938 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4939 params.supported_rates =
4940 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4941 params.supported_rates_len =
4942 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4943 }
4944
Jouni Malinen9d62a982013-02-14 21:10:13 +02004945 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4946 params.capability =
4947 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4948 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4949 }
4950
4951 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4952 params.ext_capab =
4953 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4954 params.ext_capab_len =
4955 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4956 }
4957
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004958 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004959 return -EINVAL;
4960
Johannes Bergf8bacc22013-02-14 23:27:01 +01004961 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004962 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004963 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4964 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4965 return -EINVAL;
4966 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004967
Johannes Bergf8bacc22013-02-14 23:27:01 +01004968 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004969 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004970 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4971 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4972 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004973 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4974 params.peer_aid = nla_get_u16(
4975 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4976 if (params.peer_aid > IEEE80211_MAX_AID)
4977 return -EINVAL;
4978 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004979 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4980 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004981
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004982 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4983 enum nl80211_mesh_power_mode pm = nla_get_u32(
4984 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4985
4986 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4987 pm > NL80211_MESH_POWER_MAX)
4988 return -EINVAL;
4989
4990 params.local_pm = pm;
4991 }
4992
Beni Lev06f7c882016-07-19 19:28:56 +03004993 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4994 params.opmode_notif_used = true;
4995 params.opmode_notif =
4996 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4997 }
4998
Johannes Berg77ee7c82013-02-15 00:48:33 +01004999 /* Include parameters for TDLS peer (will check later) */
5000 err = nl80211_set_station_tdls(info, &params);
5001 if (err)
5002 return err;
5003
5004 params.vlan = get_vlan(info, rdev);
5005 if (IS_ERR(params.vlan))
5006 return PTR_ERR(params.vlan);
5007
Johannes Berga97f4422009-06-18 17:23:43 +02005008 switch (dev->ieee80211_ptr->iftype) {
5009 case NL80211_IFTYPE_AP:
5010 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005011 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005012 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005013 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005014 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005015 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005016 break;
5017 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005018 err = -EOPNOTSUPP;
5019 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02005020 }
5021
Johannes Berg77ee7c82013-02-15 00:48:33 +01005022 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03005023 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005024
Johannes Berg77ee7c82013-02-15 00:48:33 +01005025 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01005026 if (params.vlan)
5027 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01005028
Johannes Berg5727ef12007-12-19 02:03:34 +01005029 return err;
5030}
5031
5032static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5033{
Johannes Berg4c476992010-10-04 21:36:35 +02005034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005035 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005036 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005037 struct station_parameters params;
5038 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005039 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5040 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005041
5042 memset(&params, 0, sizeof(params));
5043
Johannes Berg984c3112013-02-14 23:43:25 +01005044 if (!rdev->ops->add_station)
5045 return -EOPNOTSUPP;
5046
Johannes Berg5727ef12007-12-19 02:03:34 +01005047 if (!info->attrs[NL80211_ATTR_MAC])
5048 return -EINVAL;
5049
Johannes Berg5727ef12007-12-19 02:03:34 +01005050 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5051 return -EINVAL;
5052
5053 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5054 return -EINVAL;
5055
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005056 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5057 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005058 return -EINVAL;
5059
Johannes Berg5727ef12007-12-19 02:03:34 +01005060 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5061 params.supported_rates =
5062 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5063 params.supported_rates_len =
5064 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5065 params.listen_interval =
5066 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005067
Ayala Beker17b94242016-03-17 15:41:38 +02005068 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5069 u8 tmp;
5070
5071 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5072 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5073 return -EINVAL;
5074
5075 params.support_p2p_ps = tmp;
5076 } else {
5077 /*
5078 * if not specified, assume it's supported for P2P GO interface,
5079 * and is NOT supported for AP interface
5080 */
5081 params.support_p2p_ps =
5082 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5083 }
5084
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005085 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005086 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005087 else
5088 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005089 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5090 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005091
Jouni Malinen9d62a982013-02-14 21:10:13 +02005092 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5093 params.capability =
5094 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5095 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5096 }
5097
5098 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5099 params.ext_capab =
5100 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5101 params.ext_capab_len =
5102 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5103 }
5104
Jouni Malinen36aedc92008-08-25 11:58:58 +03005105 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5106 params.ht_capa =
5107 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005108
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005109 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5110 params.vht_capa =
5111 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5112
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005113 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5114 params.opmode_notif_used = true;
5115 params.opmode_notif =
5116 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5117 }
5118
Johannes Bergf8bacc22013-02-14 23:27:01 +01005119 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005120 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005121 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5122 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5123 return -EINVAL;
5124 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005125
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305126 err = nl80211_parse_sta_channel_info(info, &params);
5127 if (err)
5128 return err;
5129
Johannes Bergff276692013-02-15 00:09:01 +01005130 err = nl80211_parse_sta_wme(info, &params);
5131 if (err)
5132 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005133
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005134 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005135 return -EINVAL;
5136
Johannes Berg496fcc22015-03-12 08:53:27 +02005137 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5138 * as userspace might just pass through the capabilities from the IEs
5139 * directly, rather than enforcing this restriction and returning an
5140 * error in this case.
5141 */
5142 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5143 params.ht_capa = NULL;
5144 params.vht_capa = NULL;
5145 }
5146
Johannes Berg77ee7c82013-02-15 00:48:33 +01005147 /* When you run into this, adjust the code below for the new flag */
5148 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5149
Johannes Bergbdd90d52011-12-14 12:20:27 +01005150 switch (dev->ieee80211_ptr->iftype) {
5151 case NL80211_IFTYPE_AP:
5152 case NL80211_IFTYPE_AP_VLAN:
5153 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005154 /* ignore WME attributes if iface/sta is not capable */
5155 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5156 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5157 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005158
Johannes Bergbdd90d52011-12-14 12:20:27 +01005159 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005160 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5161 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005162 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005163 /* but don't bother the driver with it */
5164 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005165
Johannes Bergd582cff2012-10-26 17:53:44 +02005166 /* allow authenticated/associated only if driver handles it */
5167 if (!(rdev->wiphy.features &
5168 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005169 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005170 return -EINVAL;
5171
Johannes Bergbda95eb2015-11-26 16:26:13 +01005172 /* Older userspace, or userspace wanting to be compatible with
5173 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5174 * and assoc flags in the mask, but assumes the station will be
5175 * added as associated anyway since this was the required driver
5176 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5177 * introduced.
5178 * In order to not bother drivers with this quirk in the API
5179 * set the flags in both the mask and set for new stations in
5180 * this case.
5181 */
5182 if (!(params.sta_flags_mask & auth_assoc)) {
5183 params.sta_flags_mask |= auth_assoc;
5184 params.sta_flags_set |= auth_assoc;
5185 }
5186
Johannes Bergbdd90d52011-12-14 12:20:27 +01005187 /* must be last in here for error handling */
5188 params.vlan = get_vlan(info, rdev);
5189 if (IS_ERR(params.vlan))
5190 return PTR_ERR(params.vlan);
5191 break;
5192 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005193 /* ignore uAPSD data */
5194 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5195
Johannes Bergd582cff2012-10-26 17:53:44 +02005196 /* associated is disallowed */
5197 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5198 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005199 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005200 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5201 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005202 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005203 break;
5204 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005205 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005206 /* ignore uAPSD data */
5207 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5208
Johannes Berg77ee7c82013-02-15 00:48:33 +01005209 /* these are disallowed */
5210 if (params.sta_flags_mask &
5211 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5212 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005213 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005214 /* Only TDLS peers can be added */
5215 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5216 return -EINVAL;
5217 /* Can only add if TDLS ... */
5218 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5219 return -EOPNOTSUPP;
5220 /* ... with external setup is supported */
5221 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5222 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005223 /*
5224 * Older wpa_supplicant versions always mark the TDLS peer
5225 * as authorized, but it shouldn't yet be.
5226 */
5227 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005228 break;
5229 default:
5230 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005231 }
5232
Johannes Bergbdd90d52011-12-14 12:20:27 +01005233 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005234
Hila Gonene35e4d22012-06-27 17:19:42 +03005235 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005236
Johannes Berg5727ef12007-12-19 02:03:34 +01005237 if (params.vlan)
5238 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005239 return err;
5240}
5241
5242static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5243{
Johannes Berg4c476992010-10-04 21:36:35 +02005244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5245 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005246 struct station_del_parameters params;
5247
5248 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005249
5250 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005251 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005252
Johannes Berge80cf852009-05-11 14:43:13 +02005253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005254 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005255 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005256 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5257 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005258
Johannes Berg4c476992010-10-04 21:36:35 +02005259 if (!rdev->ops->del_station)
5260 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005261
Jouni Malinen98856862014-10-20 13:20:45 +03005262 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5263 params.subtype =
5264 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5265 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5266 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5267 return -EINVAL;
5268 } else {
5269 /* Default to Deauthentication frame */
5270 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5271 }
5272
5273 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5274 params.reason_code =
5275 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5276 if (params.reason_code == 0)
5277 return -EINVAL; /* 0 is reserved */
5278 } else {
5279 /* Default to reason code 2 */
5280 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5281 }
5282
Jouni Malinen89c771e2014-10-10 20:52:40 +03005283 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005284}
5285
Eric W. Biederman15e47302012-09-07 20:12:54 +00005286static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005287 int flags, struct net_device *dev,
5288 u8 *dst, u8 *next_hop,
5289 struct mpath_info *pinfo)
5290{
5291 void *hdr;
5292 struct nlattr *pinfoattr;
5293
Henning Rogge1ef4c852014-11-04 16:14:58 +01005294 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005295 if (!hdr)
5296 return -1;
5297
David S. Miller9360ffd2012-03-29 04:41:26 -04005298 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5299 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5300 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5301 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5302 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005303
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005304 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5305 if (!pinfoattr)
5306 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005307 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5308 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5309 pinfo->frame_qlen))
5310 goto nla_put_failure;
5311 if (((pinfo->filled & MPATH_INFO_SN) &&
5312 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5313 ((pinfo->filled & MPATH_INFO_METRIC) &&
5314 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5315 pinfo->metric)) ||
5316 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5317 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5318 pinfo->exptime)) ||
5319 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5320 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5321 pinfo->flags)) ||
5322 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5323 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5324 pinfo->discovery_timeout)) ||
5325 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5326 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5327 pinfo->discovery_retries)))
5328 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005329
5330 nla_nest_end(msg, pinfoattr);
5331
Johannes Berg053c0952015-01-16 22:09:00 +01005332 genlmsg_end(msg, hdr);
5333 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005334
5335 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005336 genlmsg_cancel(msg, hdr);
5337 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005338}
5339
5340static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005341 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005342{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005343 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005344 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005345 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005346 u8 dst[ETH_ALEN];
5347 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005348 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005349 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005350
Johannes Bergea90e0d2017-03-15 14:26:04 +01005351 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005352 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005353 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005354 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005355
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005356 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005357 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005358 goto out_err;
5359 }
5360
Johannes Berg97990a02013-04-19 01:02:55 +02005361 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005362 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005363 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005364 }
5365
Johannes Bergbba95fe2008-07-29 13:22:51 +02005366 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005367 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005368 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005369 if (err == -ENOENT)
5370 break;
5371 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005372 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005373
Eric W. Biederman15e47302012-09-07 20:12:54 +00005374 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005375 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005376 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005377 &pinfo) < 0)
5378 goto out;
5379
5380 path_idx++;
5381 }
5382
Johannes Bergbba95fe2008-07-29 13:22:51 +02005383 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005384 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005385 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005386 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005387 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005388 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005389}
5390
5391static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5392{
Johannes Berg4c476992010-10-04 21:36:35 +02005393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005394 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005395 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005396 struct mpath_info pinfo;
5397 struct sk_buff *msg;
5398 u8 *dst = NULL;
5399 u8 next_hop[ETH_ALEN];
5400
5401 memset(&pinfo, 0, sizeof(pinfo));
5402
5403 if (!info->attrs[NL80211_ATTR_MAC])
5404 return -EINVAL;
5405
5406 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5407
Johannes Berg4c476992010-10-04 21:36:35 +02005408 if (!rdev->ops->get_mpath)
5409 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005410
Johannes Berg4c476992010-10-04 21:36:35 +02005411 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5412 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005413
Hila Gonene35e4d22012-06-27 17:19:42 +03005414 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005415 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005416 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005417
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005418 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005419 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005420 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005421
Eric W. Biederman15e47302012-09-07 20:12:54 +00005422 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005423 dev, dst, next_hop, &pinfo) < 0) {
5424 nlmsg_free(msg);
5425 return -ENOBUFS;
5426 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005427
Johannes Berg4c476992010-10-04 21:36:35 +02005428 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005429}
5430
5431static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5432{
Johannes Berg4c476992010-10-04 21:36:35 +02005433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5434 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005435 u8 *dst = NULL;
5436 u8 *next_hop = NULL;
5437
5438 if (!info->attrs[NL80211_ATTR_MAC])
5439 return -EINVAL;
5440
5441 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5442 return -EINVAL;
5443
5444 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5445 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5446
Johannes Berg4c476992010-10-04 21:36:35 +02005447 if (!rdev->ops->change_mpath)
5448 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005449
Johannes Berg4c476992010-10-04 21:36:35 +02005450 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5451 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005452
Hila Gonene35e4d22012-06-27 17:19:42 +03005453 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005454}
Johannes Berg4c476992010-10-04 21:36:35 +02005455
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005456static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5457{
Johannes Berg4c476992010-10-04 21:36:35 +02005458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5459 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005460 u8 *dst = NULL;
5461 u8 *next_hop = NULL;
5462
5463 if (!info->attrs[NL80211_ATTR_MAC])
5464 return -EINVAL;
5465
5466 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5467 return -EINVAL;
5468
5469 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5470 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5471
Johannes Berg4c476992010-10-04 21:36:35 +02005472 if (!rdev->ops->add_mpath)
5473 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005474
Johannes Berg4c476992010-10-04 21:36:35 +02005475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5476 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005477
Hila Gonene35e4d22012-06-27 17:19:42 +03005478 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005479}
5480
5481static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5482{
Johannes Berg4c476992010-10-04 21:36:35 +02005483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5484 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005485 u8 *dst = NULL;
5486
5487 if (info->attrs[NL80211_ATTR_MAC])
5488 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5489
Johannes Berg4c476992010-10-04 21:36:35 +02005490 if (!rdev->ops->del_mpath)
5491 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005492
Hila Gonene35e4d22012-06-27 17:19:42 +03005493 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005494}
5495
Henning Rogge66be7d22014-09-12 08:58:49 +02005496static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5497{
5498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5499 int err;
5500 struct net_device *dev = info->user_ptr[1];
5501 struct mpath_info pinfo;
5502 struct sk_buff *msg;
5503 u8 *dst = NULL;
5504 u8 mpp[ETH_ALEN];
5505
5506 memset(&pinfo, 0, sizeof(pinfo));
5507
5508 if (!info->attrs[NL80211_ATTR_MAC])
5509 return -EINVAL;
5510
5511 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5512
5513 if (!rdev->ops->get_mpp)
5514 return -EOPNOTSUPP;
5515
5516 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5517 return -EOPNOTSUPP;
5518
5519 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5520 if (err)
5521 return err;
5522
5523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5524 if (!msg)
5525 return -ENOMEM;
5526
5527 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5528 dev, dst, mpp, &pinfo) < 0) {
5529 nlmsg_free(msg);
5530 return -ENOBUFS;
5531 }
5532
5533 return genlmsg_reply(msg, info);
5534}
5535
5536static int nl80211_dump_mpp(struct sk_buff *skb,
5537 struct netlink_callback *cb)
5538{
5539 struct mpath_info pinfo;
5540 struct cfg80211_registered_device *rdev;
5541 struct wireless_dev *wdev;
5542 u8 dst[ETH_ALEN];
5543 u8 mpp[ETH_ALEN];
5544 int path_idx = cb->args[2];
5545 int err;
5546
Johannes Bergea90e0d2017-03-15 14:26:04 +01005547 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005548 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5549 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005550 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005551
5552 if (!rdev->ops->dump_mpp) {
5553 err = -EOPNOTSUPP;
5554 goto out_err;
5555 }
5556
5557 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5558 err = -EOPNOTSUPP;
5559 goto out_err;
5560 }
5561
5562 while (1) {
5563 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5564 mpp, &pinfo);
5565 if (err == -ENOENT)
5566 break;
5567 if (err)
5568 goto out_err;
5569
5570 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5571 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5572 wdev->netdev, dst, mpp,
5573 &pinfo) < 0)
5574 goto out;
5575
5576 path_idx++;
5577 }
5578
5579 out:
5580 cb->args[2] = path_idx;
5581 err = skb->len;
5582 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005583 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005584 return err;
5585}
5586
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005587static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5588{
Johannes Berg4c476992010-10-04 21:36:35 +02005589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5590 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005591 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005592 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005593 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005594
5595 memset(&params, 0, sizeof(params));
5596 /* default to not changing parameters */
5597 params.use_cts_prot = -1;
5598 params.use_short_preamble = -1;
5599 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005600 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005601 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005602 params.p2p_ctwindow = -1;
5603 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005604
5605 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5606 params.use_cts_prot =
5607 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5608 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5609 params.use_short_preamble =
5610 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5611 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5612 params.use_short_slot_time =
5613 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005614 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5615 params.basic_rates =
5616 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5617 params.basic_rates_len =
5618 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5619 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005620 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5621 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005622 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5623 params.ht_opmode =
5624 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005625
Johannes Berg53cabad2012-11-14 15:17:28 +01005626 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5627 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5628 return -EINVAL;
5629 params.p2p_ctwindow =
5630 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5631 if (params.p2p_ctwindow < 0)
5632 return -EINVAL;
5633 if (params.p2p_ctwindow != 0 &&
5634 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5635 return -EINVAL;
5636 }
5637
5638 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5639 u8 tmp;
5640
5641 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5642 return -EINVAL;
5643 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5644 if (tmp > 1)
5645 return -EINVAL;
5646 params.p2p_opp_ps = tmp;
5647 if (params.p2p_opp_ps &&
5648 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5649 return -EINVAL;
5650 }
5651
Johannes Berg4c476992010-10-04 21:36:35 +02005652 if (!rdev->ops->change_bss)
5653 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005654
Johannes Berg074ac8d2010-09-16 14:58:22 +02005655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005656 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5657 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005658
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005659 wdev_lock(wdev);
5660 err = rdev_change_bss(rdev, dev, &params);
5661 wdev_unlock(wdev);
5662
5663 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005664}
5665
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005666static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5667{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005668 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005669 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005670 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005671 u32 owner_nlportid;
5672
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005673 /*
5674 * You should only get this when cfg80211 hasn't yet initialized
5675 * completely when built-in to the kernel right between the time
5676 * window between nl80211_init() and regulatory_init(), if that is
5677 * even possible.
5678 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005679 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005680 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005681
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005682 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5683 user_reg_hint_type =
5684 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5685 else
5686 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5687
5688 switch (user_reg_hint_type) {
5689 case NL80211_USER_REG_HINT_USER:
5690 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005691 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5692 return -EINVAL;
5693
5694 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5695 return regulatory_hint_user(data, user_reg_hint_type);
5696 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005697 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5698 owner_nlportid = info->snd_portid;
5699 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5700 } else {
5701 owner_nlportid = 0;
5702 is_indoor = true;
5703 }
5704
5705 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005706 default:
5707 return -EINVAL;
5708 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005709}
5710
Johannes Berg1ea4ff32017-09-13 16:07:22 +02005711static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
5712{
5713 return reg_reload_regdb();
5714}
5715
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005716static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005717 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005718{
Johannes Berg4c476992010-10-04 21:36:35 +02005719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005720 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005721 struct wireless_dev *wdev = dev->ieee80211_ptr;
5722 struct mesh_config cur_params;
5723 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005724 void *hdr;
5725 struct nlattr *pinfoattr;
5726 struct sk_buff *msg;
5727
Johannes Berg29cbe682010-12-03 09:20:44 +01005728 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5729 return -EOPNOTSUPP;
5730
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005731 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005732 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005733
Johannes Berg29cbe682010-12-03 09:20:44 +01005734 wdev_lock(wdev);
5735 /* If not connected, get default parameters */
5736 if (!wdev->mesh_id_len)
5737 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5738 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005739 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005740 wdev_unlock(wdev);
5741
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005742 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005743 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005744
5745 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005747 if (!msg)
5748 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005749 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005750 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005751 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005752 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005753 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005754 if (!pinfoattr)
5755 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005756 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5757 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5758 cur_params.dot11MeshRetryTimeout) ||
5759 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5760 cur_params.dot11MeshConfirmTimeout) ||
5761 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5762 cur_params.dot11MeshHoldingTimeout) ||
5763 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5764 cur_params.dot11MeshMaxPeerLinks) ||
5765 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5766 cur_params.dot11MeshMaxRetries) ||
5767 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5768 cur_params.dot11MeshTTL) ||
5769 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5770 cur_params.element_ttl) ||
5771 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5772 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005773 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5774 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005775 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5776 cur_params.dot11MeshHWMPmaxPREQretries) ||
5777 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5778 cur_params.path_refresh_time) ||
5779 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5780 cur_params.min_discovery_timeout) ||
5781 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5782 cur_params.dot11MeshHWMPactivePathTimeout) ||
5783 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5784 cur_params.dot11MeshHWMPpreqMinInterval) ||
5785 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5786 cur_params.dot11MeshHWMPperrMinInterval) ||
5787 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5788 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5789 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5790 cur_params.dot11MeshHWMPRootMode) ||
5791 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5792 cur_params.dot11MeshHWMPRannInterval) ||
5793 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5794 cur_params.dot11MeshGateAnnouncementProtocol) ||
5795 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5796 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005797 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005798 cur_params.rssi_threshold) ||
5799 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005800 cur_params.ht_opmode) ||
5801 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5802 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5803 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005804 cur_params.dot11MeshHWMProotInterval) ||
5805 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005806 cur_params.dot11MeshHWMPconfirmationInterval) ||
5807 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5808 cur_params.power_mode) ||
5809 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005810 cur_params.dot11MeshAwakeWindowDuration) ||
5811 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5812 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005813 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005814 nla_nest_end(msg, pinfoattr);
5815 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005816 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005817
Johannes Berg3b858752009-03-12 09:55:09 +01005818 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005819 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005820 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005821 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005822 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005823}
5824
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005825static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005826 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5827 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5828 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5829 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5830 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5831 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005832 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005833 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005834 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005835 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5836 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5837 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5838 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5839 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005840 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005841 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005842 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005843 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005844 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005845 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005846 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5847 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005848 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5849 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005850 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005851 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5852 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005853 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005854};
5855
Javier Cardonac80d5452010-12-16 17:37:49 -08005856static const struct nla_policy
5857 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005858 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005859 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5860 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005861 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005862 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005863 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005864 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005865 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005866 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005867};
5868
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005869static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5870{
5871 u8 val = nla_get_u8(nla);
5872 if (val < min || val > max)
5873 return -EINVAL;
5874 *out = val;
5875 return 0;
5876}
5877
5878static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5879{
5880 u8 val = nla_get_u8(nla);
5881 if (val < min || val > max)
5882 return -EINVAL;
5883 *out = val;
5884 return 0;
5885}
5886
5887static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5888{
5889 u16 val = nla_get_u16(nla);
5890 if (val < min || val > max)
5891 return -EINVAL;
5892 *out = val;
5893 return 0;
5894}
5895
5896static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5897{
5898 u32 val = nla_get_u32(nla);
5899 if (val < min || val > max)
5900 return -EINVAL;
5901 *out = val;
5902 return 0;
5903}
5904
5905static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5906{
5907 s32 val = nla_get_s32(nla);
5908 if (val < min || val > max)
5909 return -EINVAL;
5910 *out = val;
5911 return 0;
5912}
5913
Johannes Bergff9a71a2016-08-11 14:59:53 +02005914static int nl80211_check_power_mode(const struct nlattr *nla,
5915 enum nl80211_mesh_power_mode min,
5916 enum nl80211_mesh_power_mode max,
5917 enum nl80211_mesh_power_mode *out)
5918{
5919 u32 val = nla_get_u32(nla);
5920 if (val < min || val > max)
5921 return -EINVAL;
5922 *out = val;
5923 return 0;
5924}
5925
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005926static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005927 struct mesh_config *cfg,
5928 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005929{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005930 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005931 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005932 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005933
Marco Porschea54fba2013-01-07 16:04:48 +01005934#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5935do { \
5936 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005937 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005938 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005939 mask |= (1 << (attr - 1)); \
5940 } \
5941} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005942
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005943 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005944 return -EINVAL;
5945 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005946 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005947 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005948 return -EINVAL;
5949
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005950 /* This makes sure that there aren't more than 32 mesh config
5951 * parameters (otherwise our bitfield scheme would not work.) */
5952 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5953
5954 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005955 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005956 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005957 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005958 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005959 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005960 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005961 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005962 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005963 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005965 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005966 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005968 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005969 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005970 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005971 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005973 mask, NL80211_MESHCONF_ELEMENT_TTL,
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, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005976 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005977 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005978 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5979 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005980 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005981 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005983 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005984 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005986 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005987 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005989 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005990 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005991 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5992 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005993 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005994 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005996 1, 65535, mask,
5997 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005998 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005999 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01006000 1, 65535, mask,
6001 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006002 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006004 dot11MeshHWMPnetDiameterTraversalTime,
6005 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006006 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006007 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006008 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
6009 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006010 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
6012 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006013 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00006014 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006015 dot11MeshGateAnnouncementProtocol, 0, 1,
6016 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006017 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01006018 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006019 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006020 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08006021 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006022 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006023 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09006024 /*
6025 * Check HT operation mode based on
6026 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6027 */
6028 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6029 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6030
6031 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6032 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6033 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6034 return -EINVAL;
6035
6036 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6037 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6038 return -EINVAL;
6039
6040 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6041 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6042 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6043 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6044 return -EINVAL;
6045 break;
6046 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6047 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6048 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6049 return -EINVAL;
6050 break;
6051 }
6052 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006053 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006054 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006055 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006056 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006057 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006058 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006059 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006060 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006061 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006062 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006063 dot11MeshHWMPconfirmationInterval,
6064 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006065 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006066 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006067 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6068 NL80211_MESH_POWER_ACTIVE,
6069 NL80211_MESH_POWER_MAX,
6070 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006071 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006072 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6073 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006074 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006075 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006076 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006077 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006078 if (mask_out)
6079 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006080
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006081 return 0;
6082
6083#undef FILL_IN_MESH_PARAM_IF_SET
6084}
6085
Javier Cardonac80d5452010-12-16 17:37:49 -08006086static int nl80211_parse_mesh_setup(struct genl_info *info,
6087 struct mesh_setup *setup)
6088{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006090 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6091
6092 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6093 return -EINVAL;
6094 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6095 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006096 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006097 return -EINVAL;
6098
Javier Cardonad299a1f2012-03-31 11:31:33 -07006099 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6100 setup->sync_method =
6101 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6102 IEEE80211_SYNC_METHOD_VENDOR :
6103 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6104
Javier Cardonac80d5452010-12-16 17:37:49 -08006105 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6106 setup->path_sel_proto =
6107 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6108 IEEE80211_PATH_PROTOCOL_VENDOR :
6109 IEEE80211_PATH_PROTOCOL_HWMP;
6110
6111 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6112 setup->path_metric =
6113 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6114 IEEE80211_PATH_METRIC_VENDOR :
6115 IEEE80211_PATH_METRIC_AIRTIME;
6116
Javier Cardona581a8b02011-04-07 15:08:27 -07006117 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006118 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006119 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006120 if (!is_valid_ie_attr(ieattr))
6121 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006122 setup->ie = nla_data(ieattr);
6123 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006124 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006125 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6126 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6127 return -EINVAL;
6128 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006129 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6130 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006131 if (setup->is_secure)
6132 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006133
Colleen Twitty6e16d902013-05-08 11:45:59 -07006134 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6135 if (!setup->user_mpm)
6136 return -EINVAL;
6137 setup->auth_id =
6138 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6139 }
6140
Javier Cardonac80d5452010-12-16 17:37:49 -08006141 return 0;
6142}
6143
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006144static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006145 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006146{
6147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6148 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006149 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006150 struct mesh_config cfg;
6151 u32 mask;
6152 int err;
6153
Johannes Berg29cbe682010-12-03 09:20:44 +01006154 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6155 return -EOPNOTSUPP;
6156
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006157 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006158 return -EOPNOTSUPP;
6159
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006160 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006161 if (err)
6162 return err;
6163
Johannes Berg29cbe682010-12-03 09:20:44 +01006164 wdev_lock(wdev);
6165 if (!wdev->mesh_id_len)
6166 err = -ENOLINK;
6167
6168 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006169 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006170
6171 wdev_unlock(wdev);
6172
6173 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006174}
6175
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006176static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6177 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006178{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006179 struct nlattr *nl_reg_rules;
6180 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006181
Johannes Berg458f4f92012-12-06 15:47:38 +01006182 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6183 (regdom->dfs_region &&
6184 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006185 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006186
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006187 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6188 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006189 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006190
Johannes Berg458f4f92012-12-06 15:47:38 +01006191 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006192 struct nlattr *nl_reg_rule;
6193 const struct ieee80211_reg_rule *reg_rule;
6194 const struct ieee80211_freq_range *freq_range;
6195 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006196 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006197
Johannes Berg458f4f92012-12-06 15:47:38 +01006198 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006199 freq_range = &reg_rule->freq_range;
6200 power_rule = &reg_rule->power_rule;
6201
6202 nl_reg_rule = nla_nest_start(msg, i);
6203 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006204 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006205
Janusz Dziedzic97524822014-01-30 09:52:20 +01006206 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6207 if (!max_bandwidth_khz)
6208 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6209 reg_rule);
6210
David S. Miller9360ffd2012-03-29 04:41:26 -04006211 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6212 reg_rule->flags) ||
6213 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6214 freq_range->start_freq_khz) ||
6215 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6216 freq_range->end_freq_khz) ||
6217 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006218 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006219 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6220 power_rule->max_antenna_gain) ||
6221 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006222 power_rule->max_eirp) ||
6223 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6224 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006225 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006226
6227 nla_nest_end(msg, nl_reg_rule);
6228 }
6229
6230 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006231 return 0;
6232
6233nla_put_failure:
6234 return -EMSGSIZE;
6235}
6236
6237static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6238{
6239 const struct ieee80211_regdomain *regdom = NULL;
6240 struct cfg80211_registered_device *rdev;
6241 struct wiphy *wiphy = NULL;
6242 struct sk_buff *msg;
6243 void *hdr;
6244
6245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6246 if (!msg)
6247 return -ENOBUFS;
6248
6249 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6250 NL80211_CMD_GET_REG);
6251 if (!hdr)
6252 goto put_failure;
6253
6254 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006255 bool self_managed;
6256
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006257 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6258 if (IS_ERR(rdev)) {
6259 nlmsg_free(msg);
6260 return PTR_ERR(rdev);
6261 }
6262
6263 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006264 self_managed = wiphy->regulatory_flags &
6265 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006266 regdom = get_wiphy_regdom(wiphy);
6267
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006268 /* a self-managed-reg device must have a private regdom */
6269 if (WARN_ON(!regdom && self_managed)) {
6270 nlmsg_free(msg);
6271 return -EINVAL;
6272 }
6273
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006274 if (regdom &&
6275 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6276 goto nla_put_failure;
6277 }
6278
6279 if (!wiphy && reg_last_request_cell_base() &&
6280 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6281 NL80211_USER_REG_HINT_CELL_BASE))
6282 goto nla_put_failure;
6283
6284 rcu_read_lock();
6285
6286 if (!regdom)
6287 regdom = rcu_dereference(cfg80211_regdomain);
6288
6289 if (nl80211_put_regdom(regdom, msg))
6290 goto nla_put_failure_rcu;
6291
6292 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006293
6294 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006295 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006296
Johannes Berg458f4f92012-12-06 15:47:38 +01006297nla_put_failure_rcu:
6298 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006299nla_put_failure:
6300 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006301put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006302 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006303 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006304}
6305
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006306static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6307 u32 seq, int flags, struct wiphy *wiphy,
6308 const struct ieee80211_regdomain *regdom)
6309{
6310 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6311 NL80211_CMD_GET_REG);
6312
6313 if (!hdr)
6314 return -1;
6315
Michal Kubecek0a833c22017-11-15 13:09:32 +01006316 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006317
6318 if (nl80211_put_regdom(regdom, msg))
6319 goto nla_put_failure;
6320
6321 if (!wiphy && reg_last_request_cell_base() &&
6322 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6323 NL80211_USER_REG_HINT_CELL_BASE))
6324 goto nla_put_failure;
6325
6326 if (wiphy &&
6327 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6328 goto nla_put_failure;
6329
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006330 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6331 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6332 goto nla_put_failure;
6333
Johannes Berg053c0952015-01-16 22:09:00 +01006334 genlmsg_end(msg, hdr);
6335 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006336
6337nla_put_failure:
6338 genlmsg_cancel(msg, hdr);
6339 return -EMSGSIZE;
6340}
6341
6342static int nl80211_get_reg_dump(struct sk_buff *skb,
6343 struct netlink_callback *cb)
6344{
6345 const struct ieee80211_regdomain *regdom = NULL;
6346 struct cfg80211_registered_device *rdev;
6347 int err, reg_idx, start = cb->args[2];
6348
6349 rtnl_lock();
6350
6351 if (cfg80211_regdomain && start == 0) {
6352 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6353 NLM_F_MULTI, NULL,
6354 rtnl_dereference(cfg80211_regdomain));
6355 if (err < 0)
6356 goto out_err;
6357 }
6358
6359 /* the global regdom is idx 0 */
6360 reg_idx = 1;
6361 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6362 regdom = get_wiphy_regdom(&rdev->wiphy);
6363 if (!regdom)
6364 continue;
6365
6366 if (++reg_idx <= start)
6367 continue;
6368
6369 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6370 NLM_F_MULTI, &rdev->wiphy, regdom);
6371 if (err < 0) {
6372 reg_idx--;
6373 break;
6374 }
6375 }
6376
6377 cb->args[2] = reg_idx;
6378 err = skb->len;
6379out_err:
6380 rtnl_unlock();
6381 return err;
6382}
6383
Johannes Bergb6863032015-10-15 09:25:18 +02006384#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6385static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6386 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6387 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6388 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6389 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6390 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6391 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6392 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6393};
6394
6395static int parse_reg_rule(struct nlattr *tb[],
6396 struct ieee80211_reg_rule *reg_rule)
6397{
6398 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6399 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6400
6401 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6402 return -EINVAL;
6403 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6404 return -EINVAL;
6405 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6406 return -EINVAL;
6407 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6408 return -EINVAL;
6409 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6410 return -EINVAL;
6411
6412 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6413
6414 freq_range->start_freq_khz =
6415 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6416 freq_range->end_freq_khz =
6417 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6418 freq_range->max_bandwidth_khz =
6419 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6420
6421 power_rule->max_eirp =
6422 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6423
6424 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6425 power_rule->max_antenna_gain =
6426 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6427
6428 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6429 reg_rule->dfs_cac_ms =
6430 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6431
6432 return 0;
6433}
6434
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006435static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6436{
6437 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6438 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006439 char *alpha2;
6440 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006441 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006442 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006443 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006444
6445 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6446 return -EINVAL;
6447
6448 if (!info->attrs[NL80211_ATTR_REG_RULES])
6449 return -EINVAL;
6450
6451 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6452
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006453 if (info->attrs[NL80211_ATTR_DFS_REGION])
6454 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6455
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006456 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006457 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006458 num_rules++;
6459 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006460 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006461 }
6462
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006463 if (!reg_is_valid_request(alpha2))
6464 return -EINVAL;
6465
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006466 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006467 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006468
6469 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006470 if (!rd)
6471 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006472
6473 rd->n_reg_rules = num_rules;
6474 rd->alpha2[0] = alpha2[0];
6475 rd->alpha2[1] = alpha2[1];
6476
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006477 /*
6478 * Disable DFS master mode if the DFS region was
6479 * not supported or known on this kernel.
6480 */
6481 if (reg_supported_dfs_region(dfs_region))
6482 rd->dfs_region = dfs_region;
6483
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006484 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006485 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006486 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006487 nl_reg_rule, reg_rule_policy,
6488 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006489 if (r)
6490 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006491 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6492 if (r)
6493 goto bad_reg;
6494
6495 rule_idx++;
6496
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006497 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6498 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006499 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006500 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006501 }
6502
Johannes Berg06627992016-06-09 10:40:09 +02006503 /* set_regdom takes ownership of rd */
6504 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006505 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006506 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006507 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006508}
Johannes Bergb6863032015-10-15 09:25:18 +02006509#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006510
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006511static int validate_scan_freqs(struct nlattr *freqs)
6512{
6513 struct nlattr *attr1, *attr2;
6514 int n_channels = 0, tmp1, tmp2;
6515
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006516 nla_for_each_nested(attr1, freqs, tmp1)
6517 if (nla_len(attr1) != sizeof(u32))
6518 return 0;
6519
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006520 nla_for_each_nested(attr1, freqs, tmp1) {
6521 n_channels++;
6522 /*
6523 * Some hardware has a limited channel list for
6524 * scanning, and it is pretty much nonsensical
6525 * to scan for a channel twice, so disallow that
6526 * and don't require drivers to check that the
6527 * channel list they get isn't longer than what
6528 * they can scan, as long as they can scan all
6529 * the channels they registered at once.
6530 */
6531 nla_for_each_nested(attr2, freqs, tmp2)
6532 if (attr1 != attr2 &&
6533 nla_get_u32(attr1) == nla_get_u32(attr2))
6534 return 0;
6535 }
6536
6537 return n_channels;
6538}
6539
Johannes Berg57fbcce2016-04-12 15:56:15 +02006540static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006541{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006542 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006543}
6544
6545static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6546 struct cfg80211_bss_selection *bss_select)
6547{
6548 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6549 struct nlattr *nest;
6550 int err;
6551 bool found = false;
6552 int i;
6553
6554 /* only process one nested attribute */
6555 nest = nla_data(nla);
6556 if (!nla_ok(nest, nla_len(nest)))
6557 return -EINVAL;
6558
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006559 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006560 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006561 if (err)
6562 return err;
6563
6564 /* only one attribute may be given */
6565 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6566 if (attr[i]) {
6567 if (found)
6568 return -EINVAL;
6569 found = true;
6570 }
6571 }
6572
6573 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6574
6575 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6576 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6577
6578 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6579 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6580 bss_select->param.band_pref =
6581 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6582 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6583 return -EINVAL;
6584 }
6585
6586 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6587 struct nl80211_bss_select_rssi_adjust *adj_param;
6588
6589 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6590 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6591 bss_select->param.adjust.band = adj_param->band;
6592 bss_select->param.adjust.delta = adj_param->delta;
6593 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6594 return -EINVAL;
6595 }
6596
6597 /* user-space did not provide behaviour attribute */
6598 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6599 return -EINVAL;
6600
6601 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6602 return -EINVAL;
6603
6604 return 0;
6605}
6606
Johannes Bergad2b26a2014-06-12 21:39:05 +02006607static int nl80211_parse_random_mac(struct nlattr **attrs,
6608 u8 *mac_addr, u8 *mac_addr_mask)
6609{
6610 int i;
6611
6612 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006613 eth_zero_addr(mac_addr);
6614 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006615 mac_addr[0] = 0x2;
6616 mac_addr_mask[0] = 0x3;
6617
6618 return 0;
6619 }
6620
6621 /* need both or none */
6622 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6623 return -EINVAL;
6624
6625 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6626 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6627
6628 /* don't allow or configure an mcast address */
6629 if (!is_multicast_ether_addr(mac_addr_mask) ||
6630 is_multicast_ether_addr(mac_addr))
6631 return -EINVAL;
6632
6633 /*
6634 * allow users to pass a MAC address that has bits set outside
6635 * of the mask, but don't bother drivers with having to deal
6636 * with such bits
6637 */
6638 for (i = 0; i < ETH_ALEN; i++)
6639 mac_addr[i] &= mac_addr_mask[i];
6640
6641 return 0;
6642}
6643
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306644static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6645{
6646 ASSERT_WDEV_LOCK(wdev);
6647
6648 if (!cfg80211_beaconing_iface_active(wdev))
6649 return true;
6650
6651 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6652 return true;
6653
6654 return regulatory_pre_cac_allowed(wdev->wiphy);
6655}
6656
Roee Zamir2d23d072017-08-06 11:38:22 +03006657static int
6658nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6659 void *request, struct nlattr **attrs,
6660 bool is_sched_scan)
6661{
6662 u8 *mac_addr, *mac_addr_mask;
6663 u32 *flags;
6664 enum nl80211_feature_flags randomness_flag;
6665
6666 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6667 return 0;
6668
6669 if (is_sched_scan) {
6670 struct cfg80211_sched_scan_request *req = request;
6671
6672 randomness_flag = wdev ?
6673 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6674 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6675 flags = &req->flags;
6676 mac_addr = req->mac_addr;
6677 mac_addr_mask = req->mac_addr_mask;
6678 } else {
6679 struct cfg80211_scan_request *req = request;
6680
6681 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6682 flags = &req->flags;
6683 mac_addr = req->mac_addr;
6684 mac_addr_mask = req->mac_addr_mask;
6685 }
6686
6687 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
6688
6689 if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6690 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN))
6691 return -EOPNOTSUPP;
6692
6693 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6694 int err;
6695
6696 if (!(wiphy->features & randomness_flag) ||
6697 (wdev && wdev->current_bss))
6698 return -EOPNOTSUPP;
6699
6700 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
6701 if (err)
6702 return err;
6703 }
6704
6705 if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) &&
6706 !wiphy_ext_feature_isset(wiphy,
6707 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME))
6708 return -EOPNOTSUPP;
6709
6710 if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) &&
6711 !wiphy_ext_feature_isset(wiphy,
6712 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP))
6713 return -EOPNOTSUPP;
6714
6715 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
6716 !wiphy_ext_feature_isset(wiphy,
6717 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
6718 return -EOPNOTSUPP;
6719
6720 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) &&
6721 !wiphy_ext_feature_isset(wiphy,
6722 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE))
6723 return -EOPNOTSUPP;
6724
6725 return 0;
6726}
6727
Johannes Berg2a519312009-02-10 21:25:55 +01006728static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6729{
Johannes Berg4c476992010-10-04 21:36:35 +02006730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006731 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006732 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006733 struct nlattr *attr;
6734 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006735 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006736 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006737
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006738 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6739 return -EINVAL;
6740
Johannes Berg79c97e92009-07-07 03:56:12 +02006741 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006742
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006743 if (wdev->iftype == NL80211_IFTYPE_NAN)
6744 return -EOPNOTSUPP;
6745
Johannes Berg4c476992010-10-04 21:36:35 +02006746 if (!rdev->ops->scan)
6747 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006748
Johannes Bergf9d15d12014-01-22 11:14:19 +02006749 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006750 err = -EBUSY;
6751 goto unlock;
6752 }
Johannes Berg2a519312009-02-10 21:25:55 +01006753
6754 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006755 n_channels = validate_scan_freqs(
6756 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006757 if (!n_channels) {
6758 err = -EINVAL;
6759 goto unlock;
6760 }
Johannes Berg2a519312009-02-10 21:25:55 +01006761 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006762 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006763 }
6764
6765 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6766 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6767 n_ssids++;
6768
Johannes Bergf9f47522013-03-19 15:04:07 +01006769 if (n_ssids > wiphy->max_scan_ssids) {
6770 err = -EINVAL;
6771 goto unlock;
6772 }
Johannes Berg2a519312009-02-10 21:25:55 +01006773
Jouni Malinen70692ad2009-02-16 19:39:13 +02006774 if (info->attrs[NL80211_ATTR_IE])
6775 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6776 else
6777 ie_len = 0;
6778
Johannes Bergf9f47522013-03-19 15:04:07 +01006779 if (ie_len > wiphy->max_scan_ie_len) {
6780 err = -EINVAL;
6781 goto unlock;
6782 }
Johannes Berg18a83652009-03-31 12:12:05 +02006783
Johannes Berg2a519312009-02-10 21:25:55 +01006784 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006785 + sizeof(*request->ssids) * n_ssids
6786 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006787 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006788 if (!request) {
6789 err = -ENOMEM;
6790 goto unlock;
6791 }
Johannes Berg2a519312009-02-10 21:25:55 +01006792
Johannes Berg2a519312009-02-10 21:25:55 +01006793 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006794 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006795 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006796 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006797 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006798 request->ie = (void *)(request->ssids + n_ssids);
6799 else
6800 request->ie = (void *)(request->channels + n_channels);
6801 }
Johannes Berg2a519312009-02-10 21:25:55 +01006802
Johannes Berg584991d2009-11-02 13:32:03 +01006803 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006804 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6805 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006806 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006807 struct ieee80211_channel *chan;
6808
6809 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6810
6811 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006812 err = -EINVAL;
6813 goto out_free;
6814 }
Johannes Berg584991d2009-11-02 13:32:03 +01006815
6816 /* ignore disabled channels */
6817 if (chan->flags & IEEE80211_CHAN_DISABLED)
6818 continue;
6819
6820 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006821 i++;
6822 }
6823 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006824 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006825
Johannes Berg2a519312009-02-10 21:25:55 +01006826 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006827 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006828 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006829
Johannes Berg2a519312009-02-10 21:25:55 +01006830 if (!wiphy->bands[band])
6831 continue;
6832 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006833 struct ieee80211_channel *chan;
6834
6835 chan = &wiphy->bands[band]->channels[j];
6836
6837 if (chan->flags & IEEE80211_CHAN_DISABLED)
6838 continue;
6839
6840 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006841 i++;
6842 }
6843 }
6844 }
6845
Johannes Berg584991d2009-11-02 13:32:03 +01006846 if (!i) {
6847 err = -EINVAL;
6848 goto out_free;
6849 }
6850
6851 request->n_channels = i;
6852
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306853 wdev_lock(wdev);
6854 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6855 struct ieee80211_channel *chan;
6856
6857 if (request->n_channels != 1) {
6858 wdev_unlock(wdev);
6859 err = -EBUSY;
6860 goto out_free;
6861 }
6862
6863 chan = request->channels[0];
6864 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6865 wdev_unlock(wdev);
6866 err = -EBUSY;
6867 goto out_free;
6868 }
6869 }
6870 wdev_unlock(wdev);
6871
Johannes Berg2a519312009-02-10 21:25:55 +01006872 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006873 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006874 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006875 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006876 err = -EINVAL;
6877 goto out_free;
6878 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006879 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006880 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006881 i++;
6882 }
6883 }
6884
Jouni Malinen70692ad2009-02-16 19:39:13 +02006885 if (info->attrs[NL80211_ATTR_IE]) {
6886 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006887 memcpy((void *)request->ie,
6888 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006889 request->ie_len);
6890 }
6891
Johannes Berg57fbcce2016-04-12 15:56:15 +02006892 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006893 if (wiphy->bands[i])
6894 request->rates[i] =
6895 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006896
6897 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6898 nla_for_each_nested(attr,
6899 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6900 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006901 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006902
Johannes Berg57fbcce2016-04-12 15:56:15 +02006903 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006904 err = -EINVAL;
6905 goto out_free;
6906 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006907
6908 if (!wiphy->bands[band])
6909 continue;
6910
Johannes Berg34850ab2011-07-18 18:08:35 +02006911 err = ieee80211_get_ratemask(wiphy->bands[band],
6912 nla_data(attr),
6913 nla_len(attr),
6914 &request->rates[band]);
6915 if (err)
6916 goto out_free;
6917 }
6918 }
6919
Avraham Stern1d762502016-07-05 17:10:13 +03006920 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6921 if (!wiphy_ext_feature_isset(wiphy,
6922 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6923 err = -EOPNOTSUPP;
6924 goto out_free;
6925 }
6926
6927 request->duration =
6928 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6929 request->duration_mandatory =
6930 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6931 }
6932
Roee Zamir2d23d072017-08-06 11:38:22 +03006933 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
6934 false);
6935 if (err)
6936 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07006937
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306938 request->no_cck =
6939 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6940
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006941 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6942 * BSSID to scan for. This was problematic because that same attribute
6943 * was already used for another purpose (local random MAC address). The
6944 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6945 * compatibility with older userspace components, also use the
6946 * NL80211_ATTR_MAC value here if it can be determined to be used for
6947 * the specific BSSID use case instead of the random MAC address
6948 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6949 */
6950 if (info->attrs[NL80211_ATTR_BSSID])
6951 memcpy(request->bssid,
6952 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6953 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6954 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006955 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6956 ETH_ALEN);
6957 else
6958 eth_broadcast_addr(request->bssid);
6959
Johannes Bergfd014282012-06-18 19:17:03 +02006960 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006961 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006962 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006963
Johannes Berg79c97e92009-07-07 03:56:12 +02006964 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006965 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006966
Johannes Berg463d0182009-07-14 00:33:35 +02006967 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006968 nl80211_send_scan_start(rdev, wdev);
6969 if (wdev->netdev)
6970 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006971 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006972 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006973 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006974 kfree(request);
6975 }
Johannes Berg3b858752009-03-12 09:55:09 +01006976
Johannes Bergf9f47522013-03-19 15:04:07 +01006977 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006978 return err;
6979}
6980
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306981static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6982{
6983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6984 struct wireless_dev *wdev = info->user_ptr[1];
6985
6986 if (!rdev->ops->abort_scan)
6987 return -EOPNOTSUPP;
6988
6989 if (rdev->scan_msg)
6990 return 0;
6991
6992 if (!rdev->scan_req)
6993 return -ENOENT;
6994
6995 rdev_abort_scan(rdev, wdev);
6996 return 0;
6997}
6998
Avraham Stern3b06d272015-10-12 09:51:34 +03006999static int
7000nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7001 struct cfg80211_sched_scan_request *request,
7002 struct nlattr **attrs)
7003{
7004 int tmp, err, i = 0;
7005 struct nlattr *attr;
7006
7007 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7008 u32 interval;
7009
7010 /*
7011 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007012 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007013 * case one scan plan will be set with the specified scan
7014 * interval and infinite number of iterations.
7015 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007016 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7017 if (!interval)
7018 return -EINVAL;
7019
7020 request->scan_plans[0].interval =
7021 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7022 if (!request->scan_plans[0].interval)
7023 return -EINVAL;
7024
7025 if (request->scan_plans[0].interval >
7026 wiphy->max_sched_scan_plan_interval)
7027 request->scan_plans[0].interval =
7028 wiphy->max_sched_scan_plan_interval;
7029
7030 return 0;
7031 }
7032
7033 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7034 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7035
7036 if (WARN_ON(i >= n_plans))
7037 return -EINVAL;
7038
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007039 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007040 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007041 if (err)
7042 return err;
7043
7044 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7045 return -EINVAL;
7046
7047 request->scan_plans[i].interval =
7048 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7049 if (!request->scan_plans[i].interval ||
7050 request->scan_plans[i].interval >
7051 wiphy->max_sched_scan_plan_interval)
7052 return -EINVAL;
7053
7054 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7055 request->scan_plans[i].iterations =
7056 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7057 if (!request->scan_plans[i].iterations ||
7058 (request->scan_plans[i].iterations >
7059 wiphy->max_sched_scan_plan_iterations))
7060 return -EINVAL;
7061 } else if (i < n_plans - 1) {
7062 /*
7063 * All scan plans but the last one must specify
7064 * a finite number of iterations
7065 */
7066 return -EINVAL;
7067 }
7068
7069 i++;
7070 }
7071
7072 /*
7073 * The last scan plan must not specify the number of
7074 * iterations, it is supposed to run infinitely
7075 */
7076 if (request->scan_plans[n_plans - 1].iterations)
7077 return -EINVAL;
7078
7079 return 0;
7080}
7081
Luciano Coelho256da022014-11-10 16:13:46 +02007082static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007083nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007084 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007085{
7086 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007087 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007088 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007089 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007090 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007091 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007092 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007093
Luciano Coelho256da022014-11-10 16:13:46 +02007094 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7095 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007096
Luciano Coelho256da022014-11-10 16:13:46 +02007097 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007098 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007099 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007100 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007101 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007102 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007103 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007104 }
7105
Luciano Coelho256da022014-11-10 16:13:46 +02007106 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7107 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007108 tmp)
7109 n_ssids++;
7110
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007111 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007112 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007113
Johannes Bergea73cbc2014-01-24 10:53:53 +01007114 /*
7115 * First, count the number of 'real' matchsets. Due to an issue with
7116 * the old implementation, matchsets containing only the RSSI attribute
7117 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7118 * RSSI for all matchsets, rather than their own matchset for reporting
7119 * all APs with a strong RSSI. This is needed to be compatible with
7120 * older userspace that treated a matchset with only the RSSI as the
7121 * global RSSI for all other matchsets - if there are other matchsets.
7122 */
Luciano Coelho256da022014-11-10 16:13:46 +02007123 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007124 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007125 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007126 tmp) {
7127 struct nlattr *rssi;
7128
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007129 err = nla_parse_nested(tb,
7130 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007131 attr, nl80211_match_policy,
7132 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007133 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007134 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007135
7136 /* SSID and BSSID are mutually exclusive */
7137 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7138 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7139 return ERR_PTR(-EINVAL);
7140
Johannes Bergea73cbc2014-01-24 10:53:53 +01007141 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007142 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7143 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007144 n_match_sets++;
7145 continue;
7146 }
7147 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7148 if (rssi)
7149 default_match_rssi = nla_get_s32(rssi);
7150 }
7151 }
7152
7153 /* However, if there's no other matchset, add the RSSI one */
7154 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7155 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007156
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007157 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007158 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007159
Luciano Coelho256da022014-11-10 16:13:46 +02007160 if (attrs[NL80211_ATTR_IE])
7161 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007162 else
7163 ie_len = 0;
7164
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007165 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007166 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007167
Avraham Stern3b06d272015-10-12 09:51:34 +03007168 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7169 /*
7170 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7171 * each scan plan already specifies its own interval
7172 */
7173 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7174 return ERR_PTR(-EINVAL);
7175
7176 nla_for_each_nested(attr,
7177 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7178 n_plans++;
7179 } else {
7180 /*
7181 * The scan interval attribute is kept for backward
7182 * compatibility. If no scan plans are specified and sched scan
7183 * interval is specified, one scan plan will be set with this
7184 * scan interval and infinite number of iterations.
7185 */
7186 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7187 return ERR_PTR(-EINVAL);
7188
7189 n_plans = 1;
7190 }
7191
7192 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7193 return ERR_PTR(-EINVAL);
7194
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007195 if (!wiphy_ext_feature_isset(
7196 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7197 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7198 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7199 return ERR_PTR(-EINVAL);
7200
Luciano Coelho807f8a82011-05-11 17:09:35 +03007201 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007202 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007203 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007204 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007205 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007206 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007207 if (!request)
7208 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007209
7210 if (n_ssids)
7211 request->ssids = (void *)&request->channels[n_channels];
7212 request->n_ssids = n_ssids;
7213 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007214 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007215 request->ie = (void *)(request->ssids + n_ssids);
7216 else
7217 request->ie = (void *)(request->channels + n_channels);
7218 }
7219
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007220 if (n_match_sets) {
7221 if (request->ie)
7222 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007223 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007224 request->match_sets =
7225 (void *)(request->ssids + n_ssids);
7226 else
7227 request->match_sets =
7228 (void *)(request->channels + n_channels);
7229 }
7230 request->n_match_sets = n_match_sets;
7231
Avraham Stern3b06d272015-10-12 09:51:34 +03007232 if (n_match_sets)
7233 request->scan_plans = (void *)(request->match_sets +
7234 n_match_sets);
7235 else if (request->ie)
7236 request->scan_plans = (void *)(request->ie + ie_len);
7237 else if (n_ssids)
7238 request->scan_plans = (void *)(request->ssids + n_ssids);
7239 else
7240 request->scan_plans = (void *)(request->channels + n_channels);
7241
7242 request->n_scan_plans = n_plans;
7243
Luciano Coelho807f8a82011-05-11 17:09:35 +03007244 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007245 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007246 /* user specified, bail out if channel not found */
7247 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007248 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007249 tmp) {
7250 struct ieee80211_channel *chan;
7251
7252 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7253
7254 if (!chan) {
7255 err = -EINVAL;
7256 goto out_free;
7257 }
7258
7259 /* ignore disabled channels */
7260 if (chan->flags & IEEE80211_CHAN_DISABLED)
7261 continue;
7262
7263 request->channels[i] = chan;
7264 i++;
7265 }
7266 } else {
7267 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007268 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007269 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007270
Luciano Coelho807f8a82011-05-11 17:09:35 +03007271 if (!wiphy->bands[band])
7272 continue;
7273 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7274 struct ieee80211_channel *chan;
7275
7276 chan = &wiphy->bands[band]->channels[j];
7277
7278 if (chan->flags & IEEE80211_CHAN_DISABLED)
7279 continue;
7280
7281 request->channels[i] = chan;
7282 i++;
7283 }
7284 }
7285 }
7286
7287 if (!i) {
7288 err = -EINVAL;
7289 goto out_free;
7290 }
7291
7292 request->n_channels = i;
7293
7294 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007295 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007296 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007297 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007298 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007299 err = -EINVAL;
7300 goto out_free;
7301 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007302 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007303 memcpy(request->ssids[i].ssid, nla_data(attr),
7304 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007305 i++;
7306 }
7307 }
7308
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007309 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007310 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007311 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007312 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007313 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007314 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007315
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007316 err = nla_parse_nested(tb,
7317 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007318 attr, nl80211_match_policy,
7319 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007320 if (err)
7321 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007322 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007323 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7324 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007325 if (WARN_ON(i >= n_match_sets)) {
7326 /* this indicates a programming error,
7327 * the loop above should have verified
7328 * things properly
7329 */
7330 err = -EINVAL;
7331 goto out_free;
7332 }
7333
Arend Van Spriel3007e352017-04-21 13:05:01 +01007334 if (ssid) {
7335 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7336 err = -EINVAL;
7337 goto out_free;
7338 }
7339 memcpy(request->match_sets[i].ssid.ssid,
7340 nla_data(ssid), nla_len(ssid));
7341 request->match_sets[i].ssid.ssid_len =
7342 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007343 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007344 if (bssid) {
7345 if (nla_len(bssid) != ETH_ALEN) {
7346 err = -EINVAL;
7347 goto out_free;
7348 }
7349 memcpy(request->match_sets[i].bssid,
7350 nla_data(bssid), ETH_ALEN);
7351 }
7352
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007353 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007354 request->match_sets[i].rssi_thold =
7355 default_match_rssi;
7356 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7357 if (rssi)
7358 request->match_sets[i].rssi_thold =
7359 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007360 }
7361 i++;
7362 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007363
7364 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007365 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007366 request->match_sets[0].rssi_thold = default_match_rssi;
7367
7368 request->min_rssi_thold = INT_MAX;
7369 for (i = 0; i < n_match_sets; i++)
7370 request->min_rssi_thold =
7371 min(request->match_sets[i].rssi_thold,
7372 request->min_rssi_thold);
7373 } else {
7374 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007375 }
7376
Johannes Berg9900e482014-02-04 21:01:25 +01007377 if (ie_len) {
7378 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007379 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007380 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007381 request->ie_len);
7382 }
7383
Roee Zamir2d23d072017-08-06 11:38:22 +03007384 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7385 if (err)
7386 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007387
Luciano Coelho9c748932015-01-16 16:04:09 +02007388 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7389 request->delay =
7390 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7391
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007392 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7393 request->relative_rssi = nla_get_s8(
7394 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7395 request->relative_rssi_set = true;
7396 }
7397
7398 if (request->relative_rssi_set &&
7399 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7400 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7401
7402 rssi_adjust = nla_data(
7403 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7404 request->rssi_adjust.band = rssi_adjust->band;
7405 request->rssi_adjust.delta = rssi_adjust->delta;
7406 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7407 err = -EINVAL;
7408 goto out_free;
7409 }
7410 }
7411
Avraham Stern3b06d272015-10-12 09:51:34 +03007412 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7413 if (err)
7414 goto out_free;
7415
Sam Leffler15d60302012-10-11 21:03:34 -07007416 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007417
Luciano Coelho256da022014-11-10 16:13:46 +02007418 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007419
7420out_free:
7421 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007422 return ERR_PTR(err);
7423}
7424
7425static int nl80211_start_sched_scan(struct sk_buff *skb,
7426 struct genl_info *info)
7427{
7428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7429 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007430 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007431 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007432 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007433 int err;
7434
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007435 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007436 return -EOPNOTSUPP;
7437
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007438 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7439 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7440 if (err)
7441 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007442
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007443 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007444 info->attrs,
7445 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007446
7447 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007448 if (err)
7449 goto out_err;
7450
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007451 /* leave request id zero for legacy request
7452 * or if driver does not support multi-scheduled scan
7453 */
7454 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7455 while (!sched_scan_req->reqid)
7456 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7457 }
7458
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007459 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007460 if (err)
7461 goto out_free;
7462
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007463 sched_scan_req->dev = dev;
7464 sched_scan_req->wiphy = &rdev->wiphy;
7465
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007466 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7467 sched_scan_req->owner_nlportid = info->snd_portid;
7468
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007469 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007470
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007471 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007472 return 0;
7473
7474out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007475 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007476out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007477 return err;
7478}
7479
7480static int nl80211_stop_sched_scan(struct sk_buff *skb,
7481 struct genl_info *info)
7482{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007483 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007485 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007486
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007487 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007488 return -EOPNOTSUPP;
7489
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007490 if (info->attrs[NL80211_ATTR_COOKIE]) {
7491 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7492 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7493 }
7494
7495 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7496 struct cfg80211_sched_scan_request,
7497 list);
7498 if (!req || req->reqid ||
7499 (req->owner_nlportid &&
7500 req->owner_nlportid != info->snd_portid))
7501 return -ENOENT;
7502
7503 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007504}
7505
Simon Wunderlich04f39042013-02-08 18:16:19 +01007506static int nl80211_start_radar_detection(struct sk_buff *skb,
7507 struct genl_info *info)
7508{
7509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7510 struct net_device *dev = info->user_ptr[1];
7511 struct wireless_dev *wdev = dev->ieee80211_ptr;
7512 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007513 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007514 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007515 int err;
7516
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007517 dfs_region = reg_get_dfs_region(wdev->wiphy);
7518 if (dfs_region == NL80211_DFS_UNSET)
7519 return -EINVAL;
7520
Simon Wunderlich04f39042013-02-08 18:16:19 +01007521 err = nl80211_parse_chandef(rdev, info, &chandef);
7522 if (err)
7523 return err;
7524
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007525 if (netif_carrier_ok(dev))
7526 return -EBUSY;
7527
Simon Wunderlich04f39042013-02-08 18:16:19 +01007528 if (wdev->cac_started)
7529 return -EBUSY;
7530
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007531 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007532 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007533 if (err < 0)
7534 return err;
7535
7536 if (err == 0)
7537 return -EINVAL;
7538
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007539 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007540 return -EINVAL;
7541
7542 if (!rdev->ops->start_radar_detection)
7543 return -EOPNOTSUPP;
7544
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007545 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7546 if (WARN_ON(!cac_time_ms))
7547 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7548
Ilan Peera1056b12015-10-22 22:27:46 +03007549 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007550 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007551 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007552 wdev->cac_started = true;
7553 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007554 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007555 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007556 return err;
7557}
7558
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007559static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7560{
7561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7562 struct net_device *dev = info->user_ptr[1];
7563 struct wireless_dev *wdev = dev->ieee80211_ptr;
7564 struct cfg80211_csa_settings params;
7565 /* csa_attrs is defined static to avoid waste of stack size - this
7566 * function is called under RTNL lock, so this should not be a problem.
7567 */
7568 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007569 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007570 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007571 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007572 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007573 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007574
7575 if (!rdev->ops->channel_switch ||
7576 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7577 return -EOPNOTSUPP;
7578
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007579 switch (dev->ieee80211_ptr->iftype) {
7580 case NL80211_IFTYPE_AP:
7581 case NL80211_IFTYPE_P2P_GO:
7582 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007583 /* For all modes except AP the handle_dfs flag needs to be
7584 * supplied to tell the kernel that userspace will handle radar
7585 * events when they happen. Otherwise a switch to a channel
7586 * requiring DFS will be rejected.
7587 */
7588 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007589
7590 /* useless if AP is not running */
7591 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007592 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007593 break;
7594 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007595 if (!wdev->ssid_len)
7596 return -ENOTCONN;
7597 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007598 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007599 if (!wdev->mesh_id_len)
7600 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007601 break;
7602 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007603 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007604 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007605
7606 memset(&params, 0, sizeof(params));
7607
7608 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7609 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7610 return -EINVAL;
7611
7612 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007613 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007614 return -EINVAL;
7615
Luciano Coelho252e07c2014-10-08 09:48:34 +03007616 /* Even though the attribute is u32, the specification says
7617 * u8, so let's make sure we don't overflow.
7618 */
7619 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7620 if (cs_count > 255)
7621 return -EINVAL;
7622
7623 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007624
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007625 if (!need_new_beacon)
7626 goto skip_beacons;
7627
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007628 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7629 if (err)
7630 return err;
7631
7632 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7633 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007634 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007635 if (err)
7636 return err;
7637
7638 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7639 if (err)
7640 return err;
7641
7642 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7643 return -EINVAL;
7644
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007645 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7646 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007647 return -EINVAL;
7648
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007649 params.n_counter_offsets_beacon = len / sizeof(u16);
7650 if (rdev->wiphy.max_num_csa_counters &&
7651 (params.n_counter_offsets_beacon >
7652 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007653 return -EINVAL;
7654
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007655 params.counter_offsets_beacon =
7656 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7657
7658 /* sanity checks - counters should fit and be the same */
7659 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7660 u16 offset = params.counter_offsets_beacon[i];
7661
7662 if (offset >= params.beacon_csa.tail_len)
7663 return -EINVAL;
7664
7665 if (params.beacon_csa.tail[offset] != params.count)
7666 return -EINVAL;
7667 }
7668
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007669 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007670 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7671 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007672 return -EINVAL;
7673
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007674 params.n_counter_offsets_presp = len / sizeof(u16);
7675 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007676 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007677 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007678 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007679
7680 params.counter_offsets_presp =
7681 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7682
7683 /* sanity checks - counters should fit and be the same */
7684 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7685 u16 offset = params.counter_offsets_presp[i];
7686
7687 if (offset >= params.beacon_csa.probe_resp_len)
7688 return -EINVAL;
7689
7690 if (params.beacon_csa.probe_resp[offset] !=
7691 params.count)
7692 return -EINVAL;
7693 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007694 }
7695
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007696skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007697 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7698 if (err)
7699 return err;
7700
Arik Nemtsov923b3522015-07-08 15:41:44 +03007701 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7702 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007703 return -EINVAL;
7704
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007705 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7706 &params.chandef,
7707 wdev->iftype);
7708 if (err < 0)
7709 return err;
7710
Benjamin Berg8d9de162017-05-16 11:23:12 +02007711 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007712 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007713 if (need_handle_dfs_flag &&
7714 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7715 return -EINVAL;
7716 }
7717 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007718
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007719 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7720 params.block_tx = true;
7721
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007722 wdev_lock(wdev);
7723 err = rdev_channel_switch(rdev, dev, &params);
7724 wdev_unlock(wdev);
7725
7726 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007727}
7728
Johannes Berg9720bb32011-06-21 09:45:33 +02007729static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7730 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007731 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007732 struct wireless_dev *wdev,
7733 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007734{
Johannes Berg48ab9052009-07-10 18:42:31 +02007735 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007736 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007737 void *hdr;
7738 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007739
7740 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007741
Eric W. Biederman15e47302012-09-07 20:12:54 +00007742 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007743 NL80211_CMD_NEW_SCAN_RESULTS);
7744 if (!hdr)
7745 return -1;
7746
Michal Kubecek0a833c22017-11-15 13:09:32 +01007747 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02007748
Johannes Berg97990a02013-04-19 01:02:55 +02007749 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7750 goto nla_put_failure;
7751 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007752 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7753 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007754 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7755 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007756 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007757
7758 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7759 if (!bss)
7760 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007761 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007762 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007763 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007764
7765 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007766 /* indicate whether we have probe response data or not */
7767 if (rcu_access_pointer(res->proberesp_ies) &&
7768 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7769 goto fail_unlock_rcu;
7770
7771 /* this pointer prefers to be pointed to probe response data
7772 * but is always valid
7773 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007774 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007775 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007776 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7777 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007778 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007779 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7780 ies->len, ies->data))
7781 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007782 }
Johannes Berg0e227082014-08-12 20:34:30 +02007783
7784 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007785 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007786 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007787 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7788 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007789 goto fail_unlock_rcu;
7790 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7791 ies->len, ies->data))
7792 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007793 }
7794 rcu_read_unlock();
7795
David S. Miller9360ffd2012-03-29 04:41:26 -04007796 if (res->beacon_interval &&
7797 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7798 goto nla_put_failure;
7799 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7800 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007801 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007802 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7803 jiffies_to_msecs(jiffies - intbss->ts)))
7804 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007805
Avraham Stern1d762502016-07-05 17:10:13 +03007806 if (intbss->parent_tsf &&
7807 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7808 intbss->parent_tsf, NL80211_BSS_PAD) ||
7809 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7810 intbss->parent_bssid)))
7811 goto nla_put_failure;
7812
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007813 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007814 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7815 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007816 goto nla_put_failure;
7817
Johannes Berg77965c92009-02-18 18:45:06 +01007818 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007819 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007820 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7821 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007822 break;
7823 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007824 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7825 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007826 break;
7827 default:
7828 break;
7829 }
7830
Johannes Berg48ab9052009-07-10 18:42:31 +02007831 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007832 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007833 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007834 if (intbss == wdev->current_bss &&
7835 nla_put_u32(msg, NL80211_BSS_STATUS,
7836 NL80211_BSS_STATUS_ASSOCIATED))
7837 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007838 break;
7839 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007840 if (intbss == wdev->current_bss &&
7841 nla_put_u32(msg, NL80211_BSS_STATUS,
7842 NL80211_BSS_STATUS_IBSS_JOINED))
7843 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007844 break;
7845 default:
7846 break;
7847 }
7848
Johannes Berg2a519312009-02-10 21:25:55 +01007849 nla_nest_end(msg, bss);
7850
Johannes Berg053c0952015-01-16 22:09:00 +01007851 genlmsg_end(msg, hdr);
7852 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007853
Johannes Berg8cef2c92013-02-05 16:54:31 +01007854 fail_unlock_rcu:
7855 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007856 nla_put_failure:
7857 genlmsg_cancel(msg, hdr);
7858 return -EMSGSIZE;
7859}
7860
Johannes Berg97990a02013-04-19 01:02:55 +02007861static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007862{
Johannes Berg48ab9052009-07-10 18:42:31 +02007863 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007864 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007865 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007866 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007867 int err;
7868
Johannes Bergea90e0d2017-03-15 14:26:04 +01007869 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007870 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007871 if (err) {
7872 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007873 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007874 }
Johannes Berg2a519312009-02-10 21:25:55 +01007875
Johannes Berg48ab9052009-07-10 18:42:31 +02007876 wdev_lock(wdev);
7877 spin_lock_bh(&rdev->bss_lock);
7878 cfg80211_bss_expire(rdev);
7879
Johannes Berg9720bb32011-06-21 09:45:33 +02007880 cb->seq = rdev->bss_generation;
7881
Johannes Berg48ab9052009-07-10 18:42:31 +02007882 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007883 if (++idx <= start)
7884 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007885 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007886 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007887 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007888 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007889 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007890 }
7891 }
7892
Johannes Berg48ab9052009-07-10 18:42:31 +02007893 spin_unlock_bh(&rdev->bss_lock);
7894 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007895
Johannes Berg97990a02013-04-19 01:02:55 +02007896 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007897 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007898
Johannes Berg67748892010-10-04 21:14:06 +02007899 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007900}
7901
Eric W. Biederman15e47302012-09-07 20:12:54 +00007902static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007903 int flags, struct net_device *dev,
7904 bool allow_radio_stats,
7905 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007906{
7907 void *hdr;
7908 struct nlattr *infoattr;
7909
Johannes Berg11f78ac2014-11-14 16:43:50 +01007910 /* skip radio stats if userspace didn't request them */
7911 if (!survey->channel && !allow_radio_stats)
7912 return 0;
7913
Eric W. Biederman15e47302012-09-07 20:12:54 +00007914 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007915 NL80211_CMD_NEW_SURVEY_RESULTS);
7916 if (!hdr)
7917 return -ENOMEM;
7918
David S. Miller9360ffd2012-03-29 04:41:26 -04007919 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7920 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007921
7922 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7923 if (!infoattr)
7924 goto nla_put_failure;
7925
Johannes Berg11f78ac2014-11-14 16:43:50 +01007926 if (survey->channel &&
7927 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007928 survey->channel->center_freq))
7929 goto nla_put_failure;
7930
7931 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7932 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7933 goto nla_put_failure;
7934 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7935 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7936 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007937 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007938 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7939 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007940 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007941 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007942 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7943 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007944 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007945 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007946 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7947 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007948 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007949 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007950 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7951 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007952 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007953 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007954 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7955 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007956 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007957 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007958 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7959 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007960 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007961
7962 nla_nest_end(msg, infoattr);
7963
Johannes Berg053c0952015-01-16 22:09:00 +01007964 genlmsg_end(msg, hdr);
7965 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007966
7967 nla_put_failure:
7968 genlmsg_cancel(msg, hdr);
7969 return -EMSGSIZE;
7970}
7971
Johannes Berg11f78ac2014-11-14 16:43:50 +01007972static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007973{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007974 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007975 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007976 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007977 struct wireless_dev *wdev;
7978 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007979 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007980 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007981
Johannes Bergea90e0d2017-03-15 14:26:04 +01007982 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007983 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007984 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007985 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007986
Johannes Berg11f78ac2014-11-14 16:43:50 +01007987 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007988 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007989
Johannes Berg97990a02013-04-19 01:02:55 +02007990 if (!wdev->netdev) {
7991 res = -EINVAL;
7992 goto out_err;
7993 }
7994
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007995 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007996 res = -EOPNOTSUPP;
7997 goto out_err;
7998 }
7999
8000 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08008001 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01008002 if (res == -ENOENT)
8003 break;
8004 if (res)
8005 goto out_err;
8006
Johannes Berg11f78ac2014-11-14 16:43:50 +01008007 /* don't send disabled channels, but do send non-channel data */
8008 if (survey.channel &&
8009 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07008010 survey_idx++;
8011 continue;
8012 }
8013
Holger Schurig61fa7132009-11-11 12:25:40 +01008014 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008015 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01008016 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008017 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01008018 goto out;
8019 survey_idx++;
8020 }
8021
8022 out:
Johannes Berg97990a02013-04-19 01:02:55 +02008023 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01008024 res = skb->len;
8025 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01008026 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01008027 return res;
8028}
8029
Samuel Ortizb23aa672009-07-01 21:26:54 +02008030static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8031{
8032 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8033 NL80211_WPA_VERSION_2));
8034}
8035
Jouni Malinen636a5d32009-03-19 13:39:22 +02008036static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8037{
Johannes Berg4c476992010-10-04 21:36:35 +02008038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8039 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008040 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008041 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8042 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008043 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008044 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008045 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008046
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008047 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8048 return -EINVAL;
8049
8050 if (!info->attrs[NL80211_ATTR_MAC])
8051 return -EINVAL;
8052
Jouni Malinen17780922009-03-27 20:52:47 +02008053 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8054 return -EINVAL;
8055
Johannes Berg19957bb2009-07-02 17:20:43 +02008056 if (!info->attrs[NL80211_ATTR_SSID])
8057 return -EINVAL;
8058
8059 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8060 return -EINVAL;
8061
Johannes Bergfffd0932009-07-08 14:22:54 +02008062 err = nl80211_parse_key(info, &key);
8063 if (err)
8064 return err;
8065
8066 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008067 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8068 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008069 if (!key.p.key || !key.p.key_len)
8070 return -EINVAL;
8071 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8072 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8073 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8074 key.p.key_len != WLAN_KEY_LEN_WEP104))
8075 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008076 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008077 return -EINVAL;
8078 } else {
8079 key.p.key_len = 0;
8080 key.p.key = NULL;
8081 }
8082
Johannes Bergafea0b72010-08-10 09:46:42 +02008083 if (key.idx >= 0) {
8084 int i;
8085 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008086
Johannes Bergafea0b72010-08-10 09:46:42 +02008087 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8088 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8089 ok = true;
8090 break;
8091 }
8092 }
Johannes Berg4c476992010-10-04 21:36:35 +02008093 if (!ok)
8094 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008095 }
8096
Johannes Berg4c476992010-10-04 21:36:35 +02008097 if (!rdev->ops->auth)
8098 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008099
Johannes Berg074ac8d2010-09-16 14:58:22 +02008100 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8102 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008103
Johannes Berg19957bb2009-07-02 17:20:43 +02008104 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008105 chan = nl80211_get_valid_chan(&rdev->wiphy,
8106 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8107 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008108 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008109
Johannes Berg19957bb2009-07-02 17:20:43 +02008110 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8111 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8112
8113 if (info->attrs[NL80211_ATTR_IE]) {
8114 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8115 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8116 }
8117
8118 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008119 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008120 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008121
Jouni Malinen63181062016-10-27 00:42:02 +03008122 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8123 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8124 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8125 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008126 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008127 return -EINVAL;
8128
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008129 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008130 if (auth_type != NL80211_AUTHTYPE_SAE &&
8131 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8132 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8133 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008134 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008135 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8136 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008137 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008138 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008139 return -EINVAL;
8140 }
8141
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008142 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8143
Johannes Berg95de8172012-01-20 13:55:25 +01008144 /*
8145 * Since we no longer track auth state, ignore
8146 * requests to only change local state.
8147 */
8148 if (local_state_change)
8149 return 0;
8150
Johannes Berg91bf9b22013-05-15 17:44:01 +02008151 wdev_lock(dev->ieee80211_ptr);
8152 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8153 ssid, ssid_len, ie, ie_len,
8154 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008155 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008156 wdev_unlock(dev->ieee80211_ptr);
8157 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008158}
8159
Johannes Bergc0692b82010-08-27 14:26:53 +03008160static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8161 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008162 struct cfg80211_crypto_settings *settings,
8163 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008164{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008165 memset(settings, 0, sizeof(*settings));
8166
Samuel Ortizb23aa672009-07-01 21:26:54 +02008167 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8168
Johannes Bergc0692b82010-08-27 14:26:53 +03008169 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8170 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008171
Johannes Bergc0692b82010-08-27 14:26:53 +03008172 proto = nla_get_u16(
8173 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8174 settings->control_port_ethertype = cpu_to_be16(proto);
8175 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8176 proto != ETH_P_PAE)
8177 return -EINVAL;
8178 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8179 settings->control_port_no_encrypt = true;
8180 } else
8181 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8182
Samuel Ortizb23aa672009-07-01 21:26:54 +02008183 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8184 void *data;
8185 int len, i;
8186
8187 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8188 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8189 settings->n_ciphers_pairwise = len / sizeof(u32);
8190
8191 if (len % sizeof(u32))
8192 return -EINVAL;
8193
Johannes Berg3dc27d22009-07-02 21:36:37 +02008194 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008195 return -EINVAL;
8196
8197 memcpy(settings->ciphers_pairwise, data, len);
8198
8199 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008200 if (!cfg80211_supported_cipher_suite(
8201 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008202 settings->ciphers_pairwise[i]))
8203 return -EINVAL;
8204 }
8205
8206 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8207 settings->cipher_group =
8208 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008209 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8210 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008211 return -EINVAL;
8212 }
8213
8214 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8215 settings->wpa_versions =
8216 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8217 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8218 return -EINVAL;
8219 }
8220
8221 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8222 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008223 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008224
8225 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8226 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8227 settings->n_akm_suites = len / sizeof(u32);
8228
8229 if (len % sizeof(u32))
8230 return -EINVAL;
8231
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008232 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8233 return -EINVAL;
8234
Samuel Ortizb23aa672009-07-01 21:26:54 +02008235 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008236 }
8237
Eliad Peller91b5ab62017-06-09 13:08:42 +01008238 if (info->attrs[NL80211_ATTR_PMK]) {
8239 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8240 return -EINVAL;
8241 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8242 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8243 return -EINVAL;
8244 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8245 }
8246
Samuel Ortizb23aa672009-07-01 21:26:54 +02008247 return 0;
8248}
8249
Jouni Malinen636a5d32009-03-19 13:39:22 +02008250static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8251{
Johannes Berg4c476992010-10-04 21:36:35 +02008252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8253 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008254 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008255 struct cfg80211_assoc_request req = {};
8256 const u8 *bssid, *ssid;
8257 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008258
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008259 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8260 return -EINVAL;
8261
8262 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008263 !info->attrs[NL80211_ATTR_SSID] ||
8264 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008265 return -EINVAL;
8266
Johannes Berg4c476992010-10-04 21:36:35 +02008267 if (!rdev->ops->assoc)
8268 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008269
Johannes Berg074ac8d2010-09-16 14:58:22 +02008270 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008271 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8272 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008273
Johannes Berg19957bb2009-07-02 17:20:43 +02008274 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008275
Jouni Malinen664834d2014-01-15 00:01:44 +02008276 chan = nl80211_get_valid_chan(&rdev->wiphy,
8277 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8278 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008279 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008280
Johannes Berg19957bb2009-07-02 17:20:43 +02008281 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8282 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008283
8284 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008285 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8286 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008287 }
8288
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008289 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008290 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008291 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008292 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008293 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008294 else if (mfp != NL80211_MFP_NO)
8295 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008296 }
8297
Johannes Berg3e5d7642009-07-07 14:37:26 +02008298 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008299 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008300
Ben Greear7e7c8922011-11-18 11:31:59 -08008301 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008302 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008303
8304 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008305 memcpy(&req.ht_capa_mask,
8306 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8307 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008308
8309 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008310 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008311 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008312 memcpy(&req.ht_capa,
8313 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8314 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008315 }
8316
Johannes Bergee2aca32013-02-21 17:36:01 +01008317 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008318 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008319
8320 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008321 memcpy(&req.vht_capa_mask,
8322 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8323 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008324
8325 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008326 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008327 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008328 memcpy(&req.vht_capa,
8329 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8330 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008331 }
8332
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008333 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008334 if (!((rdev->wiphy.features &
8335 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8336 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8337 !wiphy_ext_feature_isset(&rdev->wiphy,
8338 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008339 return -EINVAL;
8340 req.flags |= ASSOC_REQ_USE_RRM;
8341 }
8342
Jouni Malinen348bd452016-10-27 00:42:03 +03008343 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8344 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8345 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8346 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8347 return -EINVAL;
8348 req.fils_nonces =
8349 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8350 }
8351
Johannes Bergf62fab72013-02-21 20:09:09 +01008352 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008353 if (!err) {
8354 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008355
Johannes Bergf62fab72013-02-21 20:09:09 +01008356 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8357 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008358
8359 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8360 dev->ieee80211_ptr->conn_owner_nlportid =
8361 info->snd_portid;
8362 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8363 bssid, ETH_ALEN);
8364 }
8365
Johannes Berg91bf9b22013-05-15 17:44:01 +02008366 wdev_unlock(dev->ieee80211_ptr);
8367 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008368
Jouni Malinen636a5d32009-03-19 13:39:22 +02008369 return err;
8370}
8371
8372static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8373{
Johannes Berg4c476992010-10-04 21:36:35 +02008374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8375 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008376 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008377 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008378 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008379 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008380
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008381 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8382 return -EINVAL;
8383
8384 if (!info->attrs[NL80211_ATTR_MAC])
8385 return -EINVAL;
8386
8387 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8388 return -EINVAL;
8389
Johannes Berg4c476992010-10-04 21:36:35 +02008390 if (!rdev->ops->deauth)
8391 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008392
Johannes Berg074ac8d2010-09-16 14:58:22 +02008393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008394 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8395 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008396
Johannes Berg19957bb2009-07-02 17:20:43 +02008397 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008398
Johannes Berg19957bb2009-07-02 17:20:43 +02008399 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8400 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008401 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008402 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008403 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008404
8405 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008406 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8407 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008408 }
8409
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008410 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8411
Johannes Berg91bf9b22013-05-15 17:44:01 +02008412 wdev_lock(dev->ieee80211_ptr);
8413 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8414 local_state_change);
8415 wdev_unlock(dev->ieee80211_ptr);
8416 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008417}
8418
8419static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8420{
Johannes Berg4c476992010-10-04 21:36:35 +02008421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8422 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008423 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008424 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008425 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008426 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008427
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008428 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8429 return -EINVAL;
8430
8431 if (!info->attrs[NL80211_ATTR_MAC])
8432 return -EINVAL;
8433
8434 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8435 return -EINVAL;
8436
Johannes Berg4c476992010-10-04 21:36:35 +02008437 if (!rdev->ops->disassoc)
8438 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008439
Johannes Berg074ac8d2010-09-16 14:58:22 +02008440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008441 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8442 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008443
Johannes Berg19957bb2009-07-02 17:20:43 +02008444 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008445
Johannes Berg19957bb2009-07-02 17:20:43 +02008446 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8447 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008448 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008449 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008450 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008451
8452 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008453 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8454 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008455 }
8456
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008457 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8458
Johannes Berg91bf9b22013-05-15 17:44:01 +02008459 wdev_lock(dev->ieee80211_ptr);
8460 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8461 local_state_change);
8462 wdev_unlock(dev->ieee80211_ptr);
8463 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008464}
8465
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008466static bool
8467nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008468 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008469 int rateval)
8470{
8471 struct wiphy *wiphy = &rdev->wiphy;
8472 bool found = false;
8473 int band, i;
8474
Johannes Berg57fbcce2016-04-12 15:56:15 +02008475 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008476 struct ieee80211_supported_band *sband;
8477
8478 sband = wiphy->bands[band];
8479 if (!sband)
8480 continue;
8481
8482 for (i = 0; i < sband->n_bitrates; i++) {
8483 if (sband->bitrates[i].bitrate == rateval) {
8484 mcast_rate[band] = i + 1;
8485 found = true;
8486 break;
8487 }
8488 }
8489 }
8490
8491 return found;
8492}
8493
Johannes Berg04a773a2009-04-19 21:24:32 +02008494static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8495{
Johannes Berg4c476992010-10-04 21:36:35 +02008496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8497 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008498 struct cfg80211_ibss_params ibss;
8499 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008500 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008501 int err;
8502
Johannes Berg8e30bc52009-04-22 17:45:38 +02008503 memset(&ibss, 0, sizeof(ibss));
8504
Johannes Berg04a773a2009-04-19 21:24:32 +02008505 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8506 return -EINVAL;
8507
Johannes Berg683b6d32012-11-08 21:25:48 +01008508 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008509 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8510 return -EINVAL;
8511
Johannes Berg8e30bc52009-04-22 17:45:38 +02008512 ibss.beacon_interval = 100;
8513
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308514 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008515 ibss.beacon_interval =
8516 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308517
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308518 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8519 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308520 if (err)
8521 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008522
Johannes Berg4c476992010-10-04 21:36:35 +02008523 if (!rdev->ops->join_ibss)
8524 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008525
Johannes Berg4c476992010-10-04 21:36:35 +02008526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8527 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008528
Johannes Berg79c97e92009-07-07 03:56:12 +02008529 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008530
Johannes Berg39193492011-09-16 13:45:25 +02008531 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008532 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008533
8534 if (!is_valid_ether_addr(ibss.bssid))
8535 return -EINVAL;
8536 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008537 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8538 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8539
8540 if (info->attrs[NL80211_ATTR_IE]) {
8541 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8542 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8543 }
8544
Johannes Berg683b6d32012-11-08 21:25:48 +01008545 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8546 if (err)
8547 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008548
Ilan Peer174e0cd2014-02-23 09:13:01 +02008549 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8550 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008551 return -EINVAL;
8552
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008553 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008554 case NL80211_CHAN_WIDTH_5:
8555 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008556 case NL80211_CHAN_WIDTH_20_NOHT:
8557 break;
8558 case NL80211_CHAN_WIDTH_20:
8559 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008560 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8561 return -EINVAL;
8562 break;
8563 case NL80211_CHAN_WIDTH_80:
8564 case NL80211_CHAN_WIDTH_80P80:
8565 case NL80211_CHAN_WIDTH_160:
8566 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8567 return -EINVAL;
8568 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8569 NL80211_EXT_FEATURE_VHT_IBSS))
8570 return -EINVAL;
8571 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008572 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008573 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008574 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008575
Johannes Berg04a773a2009-04-19 21:24:32 +02008576 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008577 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008578
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008579 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8580 u8 *rates =
8581 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8582 int n_rates =
8583 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8584 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008585 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008586
Johannes Berg34850ab2011-07-18 18:08:35 +02008587 err = ieee80211_get_ratemask(sband, rates, n_rates,
8588 &ibss.basic_rates);
8589 if (err)
8590 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008591 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008592
Simon Wunderlich803768f2013-06-28 10:39:58 +02008593 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8594 memcpy(&ibss.ht_capa_mask,
8595 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8596 sizeof(ibss.ht_capa_mask));
8597
8598 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8599 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8600 return -EINVAL;
8601 memcpy(&ibss.ht_capa,
8602 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8603 sizeof(ibss.ht_capa));
8604 }
8605
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008606 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8607 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8608 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8609 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008610
Johannes Berg4c476992010-10-04 21:36:35 +02008611 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308612 bool no_ht = false;
8613
Johannes Berg4c476992010-10-04 21:36:35 +02008614 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308615 info->attrs[NL80211_ATTR_KEYS],
8616 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008617 if (IS_ERR(connkeys))
8618 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308619
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008620 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8621 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008622 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308623 return -EINVAL;
8624 }
Johannes Berg4c476992010-10-04 21:36:35 +02008625 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008626
Antonio Quartulli267335d2012-01-31 20:25:47 +01008627 ibss.control_port =
8628 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8629
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008630 ibss.userspace_handles_dfs =
8631 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8632
Johannes Berg4c476992010-10-04 21:36:35 +02008633 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008634 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008635 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008636 return err;
8637}
8638
8639static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8640{
Johannes Berg4c476992010-10-04 21:36:35 +02008641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8642 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008643
Johannes Berg4c476992010-10-04 21:36:35 +02008644 if (!rdev->ops->leave_ibss)
8645 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008646
Johannes Berg4c476992010-10-04 21:36:35 +02008647 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8648 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008649
Johannes Berg4c476992010-10-04 21:36:35 +02008650 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008651}
8652
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008653static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8654{
8655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8656 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008657 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008658 u32 nla_rate;
8659 int err;
8660
8661 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008662 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8663 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008664 return -EOPNOTSUPP;
8665
8666 if (!rdev->ops->set_mcast_rate)
8667 return -EOPNOTSUPP;
8668
8669 memset(mcast_rate, 0, sizeof(mcast_rate));
8670
8671 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8672 return -EINVAL;
8673
8674 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8675 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8676 return -EINVAL;
8677
Ilan Peera1056b12015-10-22 22:27:46 +03008678 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008679
8680 return err;
8681}
8682
Johannes Bergad7e7182013-11-13 13:37:47 +01008683static struct sk_buff *
8684__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008685 struct wireless_dev *wdev, int approxlen,
8686 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008687 enum nl80211_attrs attr,
8688 const struct nl80211_vendor_cmd_info *info,
8689 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008690{
8691 struct sk_buff *skb;
8692 void *hdr;
8693 struct nlattr *data;
8694
8695 skb = nlmsg_new(approxlen + 100, gfp);
8696 if (!skb)
8697 return NULL;
8698
8699 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8700 if (!hdr) {
8701 kfree_skb(skb);
8702 return NULL;
8703 }
8704
8705 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8706 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008707
8708 if (info) {
8709 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8710 info->vendor_id))
8711 goto nla_put_failure;
8712 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8713 info->subcmd))
8714 goto nla_put_failure;
8715 }
8716
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008717 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008718 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8719 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008720 goto nla_put_failure;
8721 if (wdev->netdev &&
8722 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8723 wdev->netdev->ifindex))
8724 goto nla_put_failure;
8725 }
8726
Johannes Bergad7e7182013-11-13 13:37:47 +01008727 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008728 if (!data)
8729 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008730
8731 ((void **)skb->cb)[0] = rdev;
8732 ((void **)skb->cb)[1] = hdr;
8733 ((void **)skb->cb)[2] = data;
8734
8735 return skb;
8736
8737 nla_put_failure:
8738 kfree_skb(skb);
8739 return NULL;
8740}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008741
Johannes Berge03ad6e2014-01-01 17:22:30 +01008742struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008743 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008744 enum nl80211_commands cmd,
8745 enum nl80211_attrs attr,
8746 int vendor_event_idx,
8747 int approxlen, gfp_t gfp)
8748{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008749 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008750 const struct nl80211_vendor_cmd_info *info;
8751
8752 switch (cmd) {
8753 case NL80211_CMD_TESTMODE:
8754 if (WARN_ON(vendor_event_idx != -1))
8755 return NULL;
8756 info = NULL;
8757 break;
8758 case NL80211_CMD_VENDOR:
8759 if (WARN_ON(vendor_event_idx < 0 ||
8760 vendor_event_idx >= wiphy->n_vendor_events))
8761 return NULL;
8762 info = &wiphy->vendor_events[vendor_event_idx];
8763 break;
8764 default:
8765 WARN_ON(1);
8766 return NULL;
8767 }
8768
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008769 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008770 cmd, attr, info, gfp);
8771}
8772EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8773
8774void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8775{
8776 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8777 void *hdr = ((void **)skb->cb)[1];
8778 struct nlattr *data = ((void **)skb->cb)[2];
8779 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8780
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008781 /* clear CB data for netlink core to own from now on */
8782 memset(skb->cb, 0, sizeof(skb->cb));
8783
Johannes Berge03ad6e2014-01-01 17:22:30 +01008784 nla_nest_end(skb, data);
8785 genlmsg_end(skb, hdr);
8786
8787 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8788 mcgrp = NL80211_MCGRP_VENDOR;
8789
8790 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8791 mcgrp, gfp);
8792}
8793EXPORT_SYMBOL(__cfg80211_send_event_skb);
8794
Johannes Bergaff89a92009-07-01 21:26:51 +02008795#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008796static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8797{
Johannes Berg4c476992010-10-04 21:36:35 +02008798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008799 struct wireless_dev *wdev =
8800 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008801 int err;
8802
David Spinadelfc73f112013-07-31 18:04:15 +03008803 if (!rdev->ops->testmode_cmd)
8804 return -EOPNOTSUPP;
8805
8806 if (IS_ERR(wdev)) {
8807 err = PTR_ERR(wdev);
8808 if (err != -EINVAL)
8809 return err;
8810 wdev = NULL;
8811 } else if (wdev->wiphy != &rdev->wiphy) {
8812 return -EINVAL;
8813 }
8814
Johannes Bergaff89a92009-07-01 21:26:51 +02008815 if (!info->attrs[NL80211_ATTR_TESTDATA])
8816 return -EINVAL;
8817
Johannes Bergad7e7182013-11-13 13:37:47 +01008818 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008819 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008820 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8821 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008822 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008823
Johannes Bergaff89a92009-07-01 21:26:51 +02008824 return err;
8825}
8826
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008827static int nl80211_testmode_dump(struct sk_buff *skb,
8828 struct netlink_callback *cb)
8829{
Johannes Berg00918d32011-12-13 17:22:05 +01008830 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008831 int err;
8832 long phy_idx;
8833 void *data = NULL;
8834 int data_len = 0;
8835
Johannes Berg5fe231e2013-05-08 21:45:15 +02008836 rtnl_lock();
8837
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008838 if (cb->args[0]) {
8839 /*
8840 * 0 is a valid index, but not valid for args[0],
8841 * so we need to offset by 1.
8842 */
8843 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008844
8845 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8846 if (!rdev) {
8847 err = -ENOENT;
8848 goto out_err;
8849 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008850 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008851 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8852
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008853 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008854 attrbuf, nl80211_fam.maxattr,
8855 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008856 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008857 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008858
Johannes Bergc90c39d2016-10-24 14:40:01 +02008859 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008860 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008861 err = PTR_ERR(rdev);
8862 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008863 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008864 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008865
Johannes Bergc90c39d2016-10-24 14:40:01 +02008866 if (attrbuf[NL80211_ATTR_TESTDATA])
8867 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008868 }
8869
8870 if (cb->args[1]) {
8871 data = nla_data((void *)cb->args[1]);
8872 data_len = nla_len((void *)cb->args[1]);
8873 }
8874
Johannes Berg00918d32011-12-13 17:22:05 +01008875 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008876 err = -EOPNOTSUPP;
8877 goto out_err;
8878 }
8879
8880 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008881 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008882 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8883 NL80211_CMD_TESTMODE);
8884 struct nlattr *tmdata;
8885
Dan Carpentercb35fba2013-08-14 14:50:01 +03008886 if (!hdr)
8887 break;
8888
David S. Miller9360ffd2012-03-29 04:41:26 -04008889 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008890 genlmsg_cancel(skb, hdr);
8891 break;
8892 }
8893
8894 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8895 if (!tmdata) {
8896 genlmsg_cancel(skb, hdr);
8897 break;
8898 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008899 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008900 nla_nest_end(skb, tmdata);
8901
8902 if (err == -ENOBUFS || err == -ENOENT) {
8903 genlmsg_cancel(skb, hdr);
8904 break;
8905 } else if (err) {
8906 genlmsg_cancel(skb, hdr);
8907 goto out_err;
8908 }
8909
8910 genlmsg_end(skb, hdr);
8911 }
8912
8913 err = skb->len;
8914 /* see above */
8915 cb->args[0] = phy_idx + 1;
8916 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008917 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008918 return err;
8919}
Johannes Bergaff89a92009-07-01 21:26:51 +02008920#endif
8921
Samuel Ortizb23aa672009-07-01 21:26:54 +02008922static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8923{
Johannes Berg4c476992010-10-04 21:36:35 +02008924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8925 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008926 struct cfg80211_connect_params connect;
8927 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008928 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008929 int err;
8930
8931 memset(&connect, 0, sizeof(connect));
8932
8933 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8934 return -EINVAL;
8935
8936 if (!info->attrs[NL80211_ATTR_SSID] ||
8937 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8938 return -EINVAL;
8939
8940 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8941 connect.auth_type =
8942 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008943 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8944 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008945 return -EINVAL;
8946 } else
8947 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8948
8949 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8950
Avraham Stern3a00df52017-06-09 13:08:43 +01008951 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8952 !wiphy_ext_feature_isset(&rdev->wiphy,
8953 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8954 return -EINVAL;
8955 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8956
Johannes Bergc0692b82010-08-27 14:26:53 +03008957 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008958 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008959 if (err)
8960 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008961
Johannes Berg074ac8d2010-09-16 14:58:22 +02008962 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8964 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008965
Johannes Berg79c97e92009-07-07 03:56:12 +02008966 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008967
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308968 connect.bg_scan_period = -1;
8969 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8970 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8971 connect.bg_scan_period =
8972 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8973 }
8974
Samuel Ortizb23aa672009-07-01 21:26:54 +02008975 if (info->attrs[NL80211_ATTR_MAC])
8976 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008977 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8978 connect.bssid_hint =
8979 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008980 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8981 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8982
8983 if (info->attrs[NL80211_ATTR_IE]) {
8984 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8985 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8986 }
8987
Jouni Malinencee00a92013-01-15 17:15:57 +02008988 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8989 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008990 if (connect.mfp == NL80211_MFP_OPTIONAL &&
8991 !wiphy_ext_feature_isset(&rdev->wiphy,
8992 NL80211_EXT_FEATURE_MFP_OPTIONAL))
8993 return -EOPNOTSUPP;
8994
Jouni Malinencee00a92013-01-15 17:15:57 +02008995 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008996 connect.mfp != NL80211_MFP_NO &&
8997 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02008998 return -EINVAL;
8999 } else {
9000 connect.mfp = NL80211_MFP_NO;
9001 }
9002
Jouni Malinenba6fbac2016-03-29 13:53:27 +03009003 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9004 connect.prev_bssid =
9005 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9006
Samuel Ortizb23aa672009-07-01 21:26:54 +02009007 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009008 connect.channel = nl80211_get_valid_chan(
9009 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9010 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02009011 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02009012 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02009013 connect.channel_hint = nl80211_get_valid_chan(
9014 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9015 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02009016 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009017 }
9018
Johannes Bergfffd0932009-07-08 14:22:54 +02009019 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
9020 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05309021 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02009022 if (IS_ERR(connkeys))
9023 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009024 }
9025
Ben Greear7e7c8922011-11-18 11:31:59 -08009026 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9027 connect.flags |= ASSOC_REQ_DISABLE_HT;
9028
9029 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9030 memcpy(&connect.ht_capa_mask,
9031 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9032 sizeof(connect.ht_capa_mask));
9033
9034 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009035 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009036 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009037 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009038 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009039 memcpy(&connect.ht_capa,
9040 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9041 sizeof(connect.ht_capa));
9042 }
9043
Johannes Bergee2aca32013-02-21 17:36:01 +01009044 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9045 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9046
9047 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9048 memcpy(&connect.vht_capa_mask,
9049 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9050 sizeof(connect.vht_capa_mask));
9051
9052 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9053 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009054 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009055 return -EINVAL;
9056 }
9057 memcpy(&connect.vht_capa,
9058 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9059 sizeof(connect.vht_capa));
9060 }
9061
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009062 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009063 if (!((rdev->wiphy.features &
9064 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9065 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9066 !wiphy_ext_feature_isset(&rdev->wiphy,
9067 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009068 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009069 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009070 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009071 connect.flags |= ASSOC_REQ_USE_RRM;
9072 }
9073
Lior David34d50512016-01-28 10:58:25 +02009074 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009075 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009076 kzfree(connkeys);
9077 return -EOPNOTSUPP;
9078 }
9079
Arend van Spriel38de03d2016-03-02 20:37:18 +01009080 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9081 /* bss selection makes no sense if bssid is set */
9082 if (connect.bssid) {
9083 kzfree(connkeys);
9084 return -EINVAL;
9085 }
9086
9087 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9088 wiphy, &connect.bss_select);
9089 if (err) {
9090 kzfree(connkeys);
9091 return err;
9092 }
9093 }
9094
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009095 if (wiphy_ext_feature_isset(&rdev->wiphy,
9096 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9097 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9098 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9099 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9100 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9101 connect.fils_erp_username =
9102 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9103 connect.fils_erp_username_len =
9104 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9105 connect.fils_erp_realm =
9106 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9107 connect.fils_erp_realm_len =
9108 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9109 connect.fils_erp_next_seq_num =
9110 nla_get_u16(
9111 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9112 connect.fils_erp_rrk =
9113 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9114 connect.fils_erp_rrk_len =
9115 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9116 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9117 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9118 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9119 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9120 kzfree(connkeys);
9121 return -EINVAL;
9122 }
9123
Johannes Berg83739b02013-05-15 17:44:01 +02009124 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009125
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009126 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9127 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009128 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009129 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009130
9131 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9132 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9133 if (connect.bssid)
9134 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9135 connect.bssid, ETH_ALEN);
9136 else
9137 memset(dev->ieee80211_ptr->disconnect_bssid,
9138 0, ETH_ALEN);
9139 }
9140
9141 wdev_unlock(dev->ieee80211_ptr);
9142
Samuel Ortizb23aa672009-07-01 21:26:54 +02009143 return err;
9144}
9145
vamsi krishna088e8df2016-10-27 16:51:11 +03009146static int nl80211_update_connect_params(struct sk_buff *skb,
9147 struct genl_info *info)
9148{
9149 struct cfg80211_connect_params connect = {};
9150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9151 struct net_device *dev = info->user_ptr[1];
9152 struct wireless_dev *wdev = dev->ieee80211_ptr;
9153 u32 changed = 0;
9154 int ret;
9155
9156 if (!rdev->ops->update_connect_params)
9157 return -EOPNOTSUPP;
9158
9159 if (info->attrs[NL80211_ATTR_IE]) {
9160 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9161 return -EINVAL;
9162 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9163 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9164 changed |= UPDATE_ASSOC_IES;
9165 }
9166
9167 wdev_lock(dev->ieee80211_ptr);
9168 if (!wdev->current_bss)
9169 ret = -ENOLINK;
9170 else
9171 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9172 wdev_unlock(dev->ieee80211_ptr);
9173
9174 return ret;
9175}
9176
Samuel Ortizb23aa672009-07-01 21:26:54 +02009177static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9178{
Johannes Berg4c476992010-10-04 21:36:35 +02009179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9180 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009181 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009182 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009183
9184 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9185 reason = WLAN_REASON_DEAUTH_LEAVING;
9186 else
9187 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9188
9189 if (reason == 0)
9190 return -EINVAL;
9191
Johannes Berg074ac8d2010-09-16 14:58:22 +02009192 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009193 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9194 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009195
Johannes Berg83739b02013-05-15 17:44:01 +02009196 wdev_lock(dev->ieee80211_ptr);
9197 ret = cfg80211_disconnect(rdev, dev, reason, true);
9198 wdev_unlock(dev->ieee80211_ptr);
9199 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009200}
9201
Johannes Berg463d0182009-07-14 00:33:35 +02009202static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9203{
Johannes Berg4c476992010-10-04 21:36:35 +02009204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009205 struct net *net;
9206 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009207
Vadim Kochan4b681c82015-01-12 16:34:05 +02009208 if (info->attrs[NL80211_ATTR_PID]) {
9209 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9210
9211 net = get_net_ns_by_pid(pid);
9212 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9213 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9214
9215 net = get_net_ns_by_fd(fd);
9216 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009217 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009218 }
Johannes Berg463d0182009-07-14 00:33:35 +02009219
Johannes Berg4c476992010-10-04 21:36:35 +02009220 if (IS_ERR(net))
9221 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009222
9223 err = 0;
9224
9225 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009226 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9227 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009228
Johannes Berg463d0182009-07-14 00:33:35 +02009229 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009230 return err;
9231}
9232
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009233static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9234{
Johannes Berg4c476992010-10-04 21:36:35 +02009235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009236 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9237 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009238 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009239 struct cfg80211_pmksa pmksa;
9240
9241 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9242
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009243 if (!info->attrs[NL80211_ATTR_PMKID])
9244 return -EINVAL;
9245
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009246 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009247
9248 if (info->attrs[NL80211_ATTR_MAC]) {
9249 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9250 } else if (info->attrs[NL80211_ATTR_SSID] &&
9251 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9252 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9253 info->attrs[NL80211_ATTR_PMK])) {
9254 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9255 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9256 pmksa.cache_id =
9257 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9258 } else {
9259 return -EINVAL;
9260 }
9261 if (info->attrs[NL80211_ATTR_PMK]) {
9262 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9263 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9264 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009265
Johannes Berg074ac8d2010-09-16 14:58:22 +02009266 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009267 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9268 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009269
9270 switch (info->genlhdr->cmd) {
9271 case NL80211_CMD_SET_PMKSA:
9272 rdev_ops = rdev->ops->set_pmksa;
9273 break;
9274 case NL80211_CMD_DEL_PMKSA:
9275 rdev_ops = rdev->ops->del_pmksa;
9276 break;
9277 default:
9278 WARN_ON(1);
9279 break;
9280 }
9281
Johannes Berg4c476992010-10-04 21:36:35 +02009282 if (!rdev_ops)
9283 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009284
Johannes Berg4c476992010-10-04 21:36:35 +02009285 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009286}
9287
9288static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9289{
Johannes Berg4c476992010-10-04 21:36:35 +02009290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9291 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009292
Johannes Berg074ac8d2010-09-16 14:58:22 +02009293 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9295 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009296
Johannes Berg4c476992010-10-04 21:36:35 +02009297 if (!rdev->ops->flush_pmksa)
9298 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009299
Hila Gonene35e4d22012-06-27 17:19:42 +03009300 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009301}
9302
Arik Nemtsov109086c2011-09-28 14:12:50 +03009303static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9304{
9305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9306 struct net_device *dev = info->user_ptr[1];
9307 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309308 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009309 u16 status_code;
9310 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009311 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009312
9313 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9314 !rdev->ops->tdls_mgmt)
9315 return -EOPNOTSUPP;
9316
9317 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9318 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9319 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9320 !info->attrs[NL80211_ATTR_IE] ||
9321 !info->attrs[NL80211_ATTR_MAC])
9322 return -EINVAL;
9323
9324 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9325 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9326 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9327 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009328 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309329 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9330 peer_capability =
9331 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009332
Hila Gonene35e4d22012-06-27 17:19:42 +03009333 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309334 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009335 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009336 nla_data(info->attrs[NL80211_ATTR_IE]),
9337 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009338}
9339
9340static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9341{
9342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9343 struct net_device *dev = info->user_ptr[1];
9344 enum nl80211_tdls_operation operation;
9345 u8 *peer;
9346
9347 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9348 !rdev->ops->tdls_oper)
9349 return -EOPNOTSUPP;
9350
9351 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9352 !info->attrs[NL80211_ATTR_MAC])
9353 return -EINVAL;
9354
9355 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9356 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9357
Hila Gonene35e4d22012-06-27 17:19:42 +03009358 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009359}
9360
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009361static int nl80211_remain_on_channel(struct sk_buff *skb,
9362 struct genl_info *info)
9363{
Johannes Berg4c476992010-10-04 21:36:35 +02009364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009365 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009366 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309367 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009368 struct sk_buff *msg;
9369 void *hdr;
9370 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009371 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009372 int err;
9373
9374 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9375 !info->attrs[NL80211_ATTR_DURATION])
9376 return -EINVAL;
9377
9378 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9379
Johannes Berg7c4ef712011-11-18 15:33:48 +01009380 if (!rdev->ops->remain_on_channel ||
9381 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009382 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009383
Johannes Bergebf348f2012-06-01 12:50:54 +02009384 /*
9385 * We should be on that channel for at least a minimum amount of
9386 * time (10ms) but no longer than the driver supports.
9387 */
9388 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9389 duration > rdev->wiphy.max_remain_on_channel_duration)
9390 return -EINVAL;
9391
Johannes Berg683b6d32012-11-08 21:25:48 +01009392 err = nl80211_parse_chandef(rdev, info, &chandef);
9393 if (err)
9394 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009395
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309396 wdev_lock(wdev);
9397 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9398 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9399 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9400 &chandef);
9401 if (compat_chandef != &chandef) {
9402 wdev_unlock(wdev);
9403 return -EBUSY;
9404 }
9405 }
9406 wdev_unlock(wdev);
9407
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009409 if (!msg)
9410 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009411
Eric W. Biederman15e47302012-09-07 20:12:54 +00009412 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009413 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009414 if (!hdr) {
9415 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009416 goto free_msg;
9417 }
9418
Johannes Berg683b6d32012-11-08 21:25:48 +01009419 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9420 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009421
9422 if (err)
9423 goto free_msg;
9424
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009425 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9426 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009427 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009428
9429 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009430
9431 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009432
9433 nla_put_failure:
9434 err = -ENOBUFS;
9435 free_msg:
9436 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009437 return err;
9438}
9439
9440static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9441 struct genl_info *info)
9442{
Johannes Berg4c476992010-10-04 21:36:35 +02009443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009444 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009445 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009446
9447 if (!info->attrs[NL80211_ATTR_COOKIE])
9448 return -EINVAL;
9449
Johannes Berg4c476992010-10-04 21:36:35 +02009450 if (!rdev->ops->cancel_remain_on_channel)
9451 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009452
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009453 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9454
Hila Gonene35e4d22012-06-27 17:19:42 +03009455 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009456}
9457
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009458static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9459 struct genl_info *info)
9460{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009461 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009463 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309464 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009465
Johannes Berg4c476992010-10-04 21:36:35 +02009466 if (!rdev->ops->set_bitrate_mask)
9467 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009468
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309469 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9470 if (err)
9471 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009472
Hila Gonene35e4d22012-06-27 17:19:42 +03009473 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009474}
9475
Johannes Berg2e161f72010-08-12 15:38:38 +02009476static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009477{
Johannes Berg4c476992010-10-04 21:36:35 +02009478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009479 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009480 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009481
9482 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9483 return -EINVAL;
9484
Johannes Berg2e161f72010-08-12 15:38:38 +02009485 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9486 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009487
Johannes Berg71bbc992012-06-15 15:30:18 +02009488 switch (wdev->iftype) {
9489 case NL80211_IFTYPE_STATION:
9490 case NL80211_IFTYPE_ADHOC:
9491 case NL80211_IFTYPE_P2P_CLIENT:
9492 case NL80211_IFTYPE_AP:
9493 case NL80211_IFTYPE_AP_VLAN:
9494 case NL80211_IFTYPE_MESH_POINT:
9495 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009496 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009497 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009498 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009499 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009500 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009501 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009502
9503 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009504 if (!rdev->ops->mgmt_tx)
9505 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009506
Eric W. Biederman15e47302012-09-07 20:12:54 +00009507 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009508 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9509 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009510}
9511
Johannes Berg2e161f72010-08-12 15:38:38 +02009512static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009513{
Johannes Berg4c476992010-10-04 21:36:35 +02009514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009515 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009516 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009517 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009518 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009519 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009520 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009521 struct cfg80211_mgmt_tx_params params = {
9522 .dont_wait_for_ack =
9523 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9524 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009525
Johannes Berg683b6d32012-11-08 21:25:48 +01009526 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009527 return -EINVAL;
9528
Johannes Berg4c476992010-10-04 21:36:35 +02009529 if (!rdev->ops->mgmt_tx)
9530 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009531
Johannes Berg71bbc992012-06-15 15:30:18 +02009532 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009533 case NL80211_IFTYPE_P2P_DEVICE:
9534 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9535 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009536 case NL80211_IFTYPE_STATION:
9537 case NL80211_IFTYPE_ADHOC:
9538 case NL80211_IFTYPE_P2P_CLIENT:
9539 case NL80211_IFTYPE_AP:
9540 case NL80211_IFTYPE_AP_VLAN:
9541 case NL80211_IFTYPE_MESH_POINT:
9542 case NL80211_IFTYPE_P2P_GO:
9543 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009544 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009545 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009546 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009547 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009548
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009549 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009550 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009551 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009552 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009553
9554 /*
9555 * We should wait on the channel for at least a minimum amount
9556 * of time (10ms) but no longer than the driver supports.
9557 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009558 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9559 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009560 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009561 }
9562
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009563 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009564
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009565 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009566 return -EINVAL;
9567
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009568 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309569
Antonio Quartulliea141b752013-06-11 14:20:03 +02009570 /* get the channel if any has been specified, otherwise pass NULL to
9571 * the driver. The latter will use the current one
9572 */
9573 chandef.chan = NULL;
9574 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9575 err = nl80211_parse_chandef(rdev, info, &chandef);
9576 if (err)
9577 return err;
9578 }
9579
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009580 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009581 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009582
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309583 wdev_lock(wdev);
9584 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9585 wdev_unlock(wdev);
9586 return -EBUSY;
9587 }
9588 wdev_unlock(wdev);
9589
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009590 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9591 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9592
9593 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9594 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9595 int i;
9596
9597 if (len % sizeof(u16))
9598 return -EINVAL;
9599
9600 params.n_csa_offsets = len / sizeof(u16);
9601 params.csa_offsets =
9602 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9603
9604 /* check that all the offsets fit the frame */
9605 for (i = 0; i < params.n_csa_offsets; i++) {
9606 if (params.csa_offsets[i] >= params.len)
9607 return -EINVAL;
9608 }
9609 }
9610
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009611 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9613 if (!msg)
9614 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009615
Eric W. Biederman15e47302012-09-07 20:12:54 +00009616 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009617 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009618 if (!hdr) {
9619 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009620 goto free_msg;
9621 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009622 }
Johannes Berge247bd902011-11-04 11:18:21 +01009623
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009624 params.chan = chandef.chan;
9625 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009626 if (err)
9627 goto free_msg;
9628
Johannes Berge247bd902011-11-04 11:18:21 +01009629 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009630 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9631 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009632 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009633
Johannes Berge247bd902011-11-04 11:18:21 +01009634 genlmsg_end(msg, hdr);
9635 return genlmsg_reply(msg, info);
9636 }
9637
9638 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009639
9640 nla_put_failure:
9641 err = -ENOBUFS;
9642 free_msg:
9643 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009644 return err;
9645}
9646
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009647static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9648{
9649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009650 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009651 u64 cookie;
9652
9653 if (!info->attrs[NL80211_ATTR_COOKIE])
9654 return -EINVAL;
9655
9656 if (!rdev->ops->mgmt_tx_cancel_wait)
9657 return -EOPNOTSUPP;
9658
Johannes Berg71bbc992012-06-15 15:30:18 +02009659 switch (wdev->iftype) {
9660 case NL80211_IFTYPE_STATION:
9661 case NL80211_IFTYPE_ADHOC:
9662 case NL80211_IFTYPE_P2P_CLIENT:
9663 case NL80211_IFTYPE_AP:
9664 case NL80211_IFTYPE_AP_VLAN:
9665 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009666 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009667 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009668 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009669 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009670 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009671 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009672
9673 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9674
Hila Gonene35e4d22012-06-27 17:19:42 +03009675 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009676}
9677
Kalle Valoffb9eb32010-02-17 17:58:10 +02009678static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9679{
Johannes Berg4c476992010-10-04 21:36:35 +02009680 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009681 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009682 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009683 u8 ps_state;
9684 bool state;
9685 int err;
9686
Johannes Berg4c476992010-10-04 21:36:35 +02009687 if (!info->attrs[NL80211_ATTR_PS_STATE])
9688 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009689
9690 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9691
Johannes Berg4c476992010-10-04 21:36:35 +02009692 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9693 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009694
9695 wdev = dev->ieee80211_ptr;
9696
Johannes Berg4c476992010-10-04 21:36:35 +02009697 if (!rdev->ops->set_power_mgmt)
9698 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009699
9700 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9701
9702 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009703 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009704
Hila Gonene35e4d22012-06-27 17:19:42 +03009705 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009706 if (!err)
9707 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009708 return err;
9709}
9710
9711static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9712{
Johannes Berg4c476992010-10-04 21:36:35 +02009713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009714 enum nl80211_ps_state ps_state;
9715 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009716 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009717 struct sk_buff *msg;
9718 void *hdr;
9719 int err;
9720
Kalle Valoffb9eb32010-02-17 17:58:10 +02009721 wdev = dev->ieee80211_ptr;
9722
Johannes Berg4c476992010-10-04 21:36:35 +02009723 if (!rdev->ops->set_power_mgmt)
9724 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009725
9726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009727 if (!msg)
9728 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009729
Eric W. Biederman15e47302012-09-07 20:12:54 +00009730 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009731 NL80211_CMD_GET_POWER_SAVE);
9732 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009733 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009734 goto free_msg;
9735 }
9736
9737 if (wdev->ps)
9738 ps_state = NL80211_PS_ENABLED;
9739 else
9740 ps_state = NL80211_PS_DISABLED;
9741
David S. Miller9360ffd2012-03-29 04:41:26 -04009742 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9743 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009744
9745 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009746 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009747
Johannes Berg4c476992010-10-04 21:36:35 +02009748 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009749 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009750 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009751 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009752 return err;
9753}
9754
Johannes Berg94e860f2014-01-20 23:58:15 +01009755static const struct nla_policy
9756nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009757 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009758 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9759 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009760 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9761 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9762 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009763 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009764};
9765
Thomas Pedersen84f10702012-07-12 16:17:33 -07009766static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009767 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009768{
9769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009770 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009771 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009772
Johannes Bergd9d8b012012-11-26 12:51:52 +01009773 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009774 return -EINVAL;
9775
Thomas Pedersen84f10702012-07-12 16:17:33 -07009776 if (!rdev->ops->set_cqm_txe_config)
9777 return -EOPNOTSUPP;
9778
9779 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9780 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9781 return -EOPNOTSUPP;
9782
Hila Gonene35e4d22012-06-27 17:19:42 +03009783 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009784}
9785
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009786static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9787 struct net_device *dev)
9788{
9789 struct wireless_dev *wdev = dev->ieee80211_ptr;
9790 s32 last, low, high;
9791 u32 hyst;
9792 int i, n;
9793 int err;
9794
9795 /* RSSI reporting disabled? */
9796 if (!wdev->cqm_config)
9797 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9798
9799 /*
9800 * Obtain current RSSI value if possible, if not and no RSSI threshold
9801 * event has been received yet, we should receive an event after a
9802 * connection is established and enough beacons received to calculate
9803 * the average.
9804 */
9805 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9806 rdev->ops->get_station) {
9807 struct station_info sinfo;
9808 u8 *mac_addr;
9809
9810 mac_addr = wdev->current_bss->pub.bssid;
9811
9812 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9813 if (err)
9814 return err;
9815
9816 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9817 wdev->cqm_config->last_rssi_event_value =
9818 (s8) sinfo.rx_beacon_signal_avg;
9819 }
9820
9821 last = wdev->cqm_config->last_rssi_event_value;
9822 hyst = wdev->cqm_config->rssi_hyst;
9823 n = wdev->cqm_config->n_rssi_thresholds;
9824
9825 for (i = 0; i < n; i++)
9826 if (last < wdev->cqm_config->rssi_thresholds[i])
9827 break;
9828
9829 low = i > 0 ?
9830 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9831 high = i < n ?
9832 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9833
9834 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9835}
9836
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009837static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009838 const s32 *thresholds, int n_thresholds,
9839 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009840{
Johannes Berg4c476992010-10-04 21:36:35 +02009841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009842 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009843 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009844 int i, err;
9845 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009846
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009847 /* Check all values negative and sorted */
9848 for (i = 0; i < n_thresholds; i++) {
9849 if (thresholds[i] > 0 || thresholds[i] <= prev)
9850 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009851
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009852 prev = thresholds[i];
9853 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009854
Johannes Berg074ac8d2010-09-16 14:58:22 +02009855 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009856 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9857 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009858
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009859 wdev_lock(wdev);
9860 cfg80211_cqm_config_free(wdev);
9861 wdev_unlock(wdev);
9862
9863 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9864 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9865 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9866
9867 return rdev_set_cqm_rssi_config(rdev, dev,
9868 thresholds[0], hysteresis);
9869 }
9870
9871 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9872 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9873 return -EOPNOTSUPP;
9874
9875 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9876 n_thresholds = 0;
9877
9878 wdev_lock(wdev);
9879 if (n_thresholds) {
9880 struct cfg80211_cqm_config *cqm_config;
9881
9882 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9883 n_thresholds * sizeof(s32), GFP_KERNEL);
9884 if (!cqm_config) {
9885 err = -ENOMEM;
9886 goto unlock;
9887 }
9888
9889 cqm_config->rssi_hyst = hysteresis;
9890 cqm_config->n_rssi_thresholds = n_thresholds;
9891 memcpy(cqm_config->rssi_thresholds, thresholds,
9892 n_thresholds * sizeof(s32));
9893
9894 wdev->cqm_config = cqm_config;
9895 }
9896
9897 err = cfg80211_cqm_rssi_update(rdev, dev);
9898
9899unlock:
9900 wdev_unlock(wdev);
9901
9902 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009903}
9904
9905static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9906{
9907 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9908 struct nlattr *cqm;
9909 int err;
9910
9911 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009912 if (!cqm)
9913 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009914
9915 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009916 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009917 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009918 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009919
9920 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9921 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009922 const s32 *thresholds =
9923 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9924 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009925 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009926
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009927 if (len % 4)
9928 return -EINVAL;
9929
9930 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9931 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009932 }
9933
9934 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9935 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9936 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9937 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9938 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9939 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9940
9941 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9942 }
9943
9944 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009945}
9946
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009947static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9948{
9949 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9950 struct net_device *dev = info->user_ptr[1];
9951 struct ocb_setup setup = {};
9952 int err;
9953
9954 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9955 if (err)
9956 return err;
9957
9958 return cfg80211_join_ocb(rdev, dev, &setup);
9959}
9960
9961static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9962{
9963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9964 struct net_device *dev = info->user_ptr[1];
9965
9966 return cfg80211_leave_ocb(rdev, dev);
9967}
9968
Johannes Berg29cbe682010-12-03 09:20:44 +01009969static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9970{
9971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9972 struct net_device *dev = info->user_ptr[1];
9973 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009974 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009975 int err;
9976
9977 /* start with default */
9978 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009979 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009980
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009981 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009982 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009983 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009984 if (err)
9985 return err;
9986 }
9987
9988 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9989 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9990 return -EINVAL;
9991
Javier Cardonac80d5452010-12-16 17:37:49 -08009992 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9993 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9994
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009995 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9996 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9997 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9998 return -EINVAL;
9999
Marco Porsch9bdbf042013-01-07 16:04:51 +010010000 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
10001 setup.beacon_interval =
10002 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010003
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010004 err = cfg80211_validate_beacon_int(rdev,
10005 NL80211_IFTYPE_MESH_POINT,
10006 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010007 if (err)
10008 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010010009 }
10010
10011 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10012 setup.dtim_period =
10013 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10014 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10015 return -EINVAL;
10016 }
10017
Javier Cardonac80d5452010-12-16 17:37:49 -080010018 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10019 /* parse additional setup parameters if given */
10020 err = nl80211_parse_mesh_setup(info, &setup);
10021 if (err)
10022 return err;
10023 }
10024
Thomas Pedersend37bb182013-03-04 13:06:13 -080010025 if (setup.user_mpm)
10026 cfg.auto_open_plinks = false;
10027
Johannes Bergcc1d2802012-05-16 23:50:20 +020010028 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010010029 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10030 if (err)
10031 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010032 } else {
10033 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010010034 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010035 }
10036
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010037 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10038 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10039 int n_rates =
10040 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10041 struct ieee80211_supported_band *sband;
10042
10043 if (!setup.chandef.chan)
10044 return -EINVAL;
10045
10046 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10047
10048 err = ieee80211_get_ratemask(sband, rates, n_rates,
10049 &setup.basic_rates);
10050 if (err)
10051 return err;
10052 }
10053
Johannes Berg8564e382016-09-19 09:44:44 +020010054 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10055 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10056 if (err)
10057 return err;
10058
Johannes Berg265698d2017-09-18 22:46:36 +020010059 if (!setup.chandef.chan)
10060 return -EINVAL;
10061
Johannes Berg8564e382016-09-19 09:44:44 +020010062 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10063 &setup.beacon_rate);
10064 if (err)
10065 return err;
10066 }
10067
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010068 setup.userspace_handles_dfs =
10069 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10070
Javier Cardonac80d5452010-12-16 17:37:49 -080010071 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +010010072}
10073
10074static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10075{
10076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10077 struct net_device *dev = info->user_ptr[1];
10078
10079 return cfg80211_leave_mesh(rdev, dev);
10080}
10081
Johannes Bergdfb89c52012-06-27 09:23:48 +020010082#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010083static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10084 struct cfg80211_registered_device *rdev)
10085{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010086 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010087 struct nlattr *nl_pats, *nl_pat;
10088 int i, pat_len;
10089
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010090 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010091 return 0;
10092
10093 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10094 if (!nl_pats)
10095 return -ENOBUFS;
10096
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010097 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010098 nl_pat = nla_nest_start(msg, i + 1);
10099 if (!nl_pat)
10100 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010101 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010102 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010103 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010104 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10105 wowlan->patterns[i].pattern) ||
10106 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010107 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010108 return -ENOBUFS;
10109 nla_nest_end(msg, nl_pat);
10110 }
10111 nla_nest_end(msg, nl_pats);
10112
10113 return 0;
10114}
10115
Johannes Berg2a0e0472013-01-23 22:57:40 +010010116static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10117 struct cfg80211_wowlan_tcp *tcp)
10118{
10119 struct nlattr *nl_tcp;
10120
10121 if (!tcp)
10122 return 0;
10123
10124 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10125 if (!nl_tcp)
10126 return -ENOBUFS;
10127
Jiri Benc930345e2015-03-29 16:59:25 +020010128 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10129 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010130 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10131 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10132 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10133 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10134 tcp->payload_len, tcp->payload) ||
10135 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10136 tcp->data_interval) ||
10137 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10138 tcp->wake_len, tcp->wake_data) ||
10139 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10140 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10141 return -ENOBUFS;
10142
10143 if (tcp->payload_seq.len &&
10144 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10145 sizeof(tcp->payload_seq), &tcp->payload_seq))
10146 return -ENOBUFS;
10147
10148 if (tcp->payload_tok.len &&
10149 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10150 sizeof(tcp->payload_tok) + tcp->tokens_size,
10151 &tcp->payload_tok))
10152 return -ENOBUFS;
10153
Johannes Berge248ad32013-05-16 10:24:28 +020010154 nla_nest_end(msg, nl_tcp);
10155
Johannes Berg2a0e0472013-01-23 22:57:40 +010010156 return 0;
10157}
10158
Luciano Coelho75453cc2015-01-09 14:06:37 +020010159static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10160 struct cfg80211_sched_scan_request *req)
10161{
Avraham Stern3b06d272015-10-12 09:51:34 +030010162 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010163 int i;
10164
10165 if (!req)
10166 return 0;
10167
10168 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10169 if (!nd)
10170 return -ENOBUFS;
10171
Avraham Stern3b06d272015-10-12 09:51:34 +030010172 if (req->n_scan_plans == 1 &&
10173 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10174 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010175 return -ENOBUFS;
10176
Luciano Coelho21fea562015-03-17 16:36:01 +020010177 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10178 return -ENOBUFS;
10179
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010180 if (req->relative_rssi_set) {
10181 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10182
10183 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10184 req->relative_rssi))
10185 return -ENOBUFS;
10186
10187 rssi_adjust.band = req->rssi_adjust.band;
10188 rssi_adjust.delta = req->rssi_adjust.delta;
10189 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10190 sizeof(rssi_adjust), &rssi_adjust))
10191 return -ENOBUFS;
10192 }
10193
Luciano Coelho75453cc2015-01-09 14:06:37 +020010194 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10195 if (!freqs)
10196 return -ENOBUFS;
10197
Johannes Berg53b18982016-09-14 09:59:21 +020010198 for (i = 0; i < req->n_channels; i++) {
10199 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10200 return -ENOBUFS;
10201 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010202
10203 nla_nest_end(msg, freqs);
10204
10205 if (req->n_match_sets) {
10206 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010207 if (!matches)
10208 return -ENOBUFS;
10209
Luciano Coelho75453cc2015-01-09 14:06:37 +020010210 for (i = 0; i < req->n_match_sets; i++) {
10211 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010212 if (!match)
10213 return -ENOBUFS;
10214
Johannes Berg53b18982016-09-14 09:59:21 +020010215 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10216 req->match_sets[i].ssid.ssid_len,
10217 req->match_sets[i].ssid.ssid))
10218 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010219 nla_nest_end(msg, match);
10220 }
10221 nla_nest_end(msg, matches);
10222 }
10223
Avraham Stern3b06d272015-10-12 09:51:34 +030010224 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10225 if (!scan_plans)
10226 return -ENOBUFS;
10227
10228 for (i = 0; i < req->n_scan_plans; i++) {
10229 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010230 if (!scan_plan)
10231 return -ENOBUFS;
10232
Avraham Stern3b06d272015-10-12 09:51:34 +030010233 if (!scan_plan ||
10234 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10235 req->scan_plans[i].interval) ||
10236 (req->scan_plans[i].iterations &&
10237 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10238 req->scan_plans[i].iterations)))
10239 return -ENOBUFS;
10240 nla_nest_end(msg, scan_plan);
10241 }
10242 nla_nest_end(msg, scan_plans);
10243
Luciano Coelho75453cc2015-01-09 14:06:37 +020010244 nla_nest_end(msg, nd);
10245
10246 return 0;
10247}
10248
Johannes Bergff1b6e62011-05-04 15:37:28 +020010249static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10250{
10251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10252 struct sk_buff *msg;
10253 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010254 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010255
Johannes Berg964dc9e2013-06-03 17:25:34 +020010256 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010257 return -EOPNOTSUPP;
10258
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010259 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010260 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010261 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10262 rdev->wiphy.wowlan_config->tcp->payload_len +
10263 rdev->wiphy.wowlan_config->tcp->wake_len +
10264 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010265 }
10266
10267 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010268 if (!msg)
10269 return -ENOMEM;
10270
Eric W. Biederman15e47302012-09-07 20:12:54 +000010271 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010272 NL80211_CMD_GET_WOWLAN);
10273 if (!hdr)
10274 goto nla_put_failure;
10275
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010276 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010277 struct nlattr *nl_wowlan;
10278
10279 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10280 if (!nl_wowlan)
10281 goto nla_put_failure;
10282
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010283 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010284 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010285 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010286 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010287 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010288 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010289 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010290 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010291 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010292 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010293 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010294 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010295 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010296 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10297 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010298
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010299 if (nl80211_send_wowlan_patterns(msg, rdev))
10300 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010301
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010302 if (nl80211_send_wowlan_tcp(msg,
10303 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010304 goto nla_put_failure;
10305
Luciano Coelho75453cc2015-01-09 14:06:37 +020010306 if (nl80211_send_wowlan_nd(
10307 msg,
10308 rdev->wiphy.wowlan_config->nd_config))
10309 goto nla_put_failure;
10310
Johannes Bergff1b6e62011-05-04 15:37:28 +020010311 nla_nest_end(msg, nl_wowlan);
10312 }
10313
10314 genlmsg_end(msg, hdr);
10315 return genlmsg_reply(msg, info);
10316
10317nla_put_failure:
10318 nlmsg_free(msg);
10319 return -ENOBUFS;
10320}
10321
Johannes Berg2a0e0472013-01-23 22:57:40 +010010322static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10323 struct nlattr *attr,
10324 struct cfg80211_wowlan *trig)
10325{
10326 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10327 struct cfg80211_wowlan_tcp *cfg;
10328 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10329 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10330 u32 size;
10331 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10332 int err, port;
10333
Johannes Berg964dc9e2013-06-03 17:25:34 +020010334 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010335 return -EINVAL;
10336
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010337 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010338 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010339 if (err)
10340 return err;
10341
10342 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10343 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10344 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10345 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10346 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10347 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10348 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10349 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10350 return -EINVAL;
10351
10352 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010353 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010354 return -EINVAL;
10355
10356 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010357 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010358 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010359 return -EINVAL;
10360
10361 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010362 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010363 return -EINVAL;
10364
10365 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10366 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10367 return -EINVAL;
10368
10369 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10370 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10371
10372 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10373 tokens_size = tokln - sizeof(*tok);
10374
10375 if (!tok->len || tokens_size % tok->len)
10376 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010377 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010378 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010379 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010380 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010381 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010382 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010383 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010384 return -EINVAL;
10385 if (tok->offset + tok->len > data_size)
10386 return -EINVAL;
10387 }
10388
10389 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10390 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010391 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010392 return -EINVAL;
10393 if (seq->len == 0 || seq->len > 4)
10394 return -EINVAL;
10395 if (seq->len + seq->offset > data_size)
10396 return -EINVAL;
10397 }
10398
10399 size = sizeof(*cfg);
10400 size += data_size;
10401 size += wake_size + wake_mask_size;
10402 size += tokens_size;
10403
10404 cfg = kzalloc(size, GFP_KERNEL);
10405 if (!cfg)
10406 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010407 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10408 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010409 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10410 ETH_ALEN);
10411 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10412 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10413 else
10414 port = 0;
10415#ifdef CONFIG_INET
10416 /* allocate a socket and port for it and use it */
10417 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10418 IPPROTO_TCP, &cfg->sock, 1);
10419 if (err) {
10420 kfree(cfg);
10421 return err;
10422 }
10423 if (inet_csk_get_port(cfg->sock->sk, port)) {
10424 sock_release(cfg->sock);
10425 kfree(cfg);
10426 return -EADDRINUSE;
10427 }
10428 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10429#else
10430 if (!port) {
10431 kfree(cfg);
10432 return -EINVAL;
10433 }
10434 cfg->src_port = port;
10435#endif
10436
10437 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10438 cfg->payload_len = data_size;
10439 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10440 memcpy((void *)cfg->payload,
10441 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10442 data_size);
10443 if (seq)
10444 cfg->payload_seq = *seq;
10445 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10446 cfg->wake_len = wake_size;
10447 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10448 memcpy((void *)cfg->wake_data,
10449 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10450 wake_size);
10451 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10452 data_size + wake_size;
10453 memcpy((void *)cfg->wake_mask,
10454 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10455 wake_mask_size);
10456 if (tok) {
10457 cfg->tokens_size = tokens_size;
10458 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10459 }
10460
10461 trig->tcp = cfg;
10462
10463 return 0;
10464}
10465
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010466static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10467 const struct wiphy_wowlan_support *wowlan,
10468 struct nlattr *attr,
10469 struct cfg80211_wowlan *trig)
10470{
10471 struct nlattr **tb;
10472 int err;
10473
10474 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10475 if (!tb)
10476 return -ENOMEM;
10477
10478 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10479 err = -EOPNOTSUPP;
10480 goto out;
10481 }
10482
Johannes Bergfceb6432017-04-12 14:34:07 +020010483 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10484 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010485 if (err)
10486 goto out;
10487
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010488 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10489 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010490 err = PTR_ERR_OR_ZERO(trig->nd_config);
10491 if (err)
10492 trig->nd_config = NULL;
10493
10494out:
10495 kfree(tb);
10496 return err;
10497}
10498
Johannes Bergff1b6e62011-05-04 15:37:28 +020010499static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10500{
10501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10502 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010503 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010504 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010505 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010506 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010507 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010508 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010509
Johannes Berg964dc9e2013-06-03 17:25:34 +020010510 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010511 return -EOPNOTSUPP;
10512
Johannes Bergae33bd82012-07-12 16:25:02 +020010513 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10514 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010515 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010516 goto set_wakeup;
10517 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010518
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010519 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10520 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010521 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010522 if (err)
10523 return err;
10524
10525 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10526 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10527 return -EINVAL;
10528 new_triggers.any = true;
10529 }
10530
10531 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10532 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10533 return -EINVAL;
10534 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010535 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010536 }
10537
10538 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10539 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10540 return -EINVAL;
10541 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010542 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010543 }
10544
Johannes Berg77dbbb12011-07-13 10:48:55 +020010545 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10546 return -EINVAL;
10547
10548 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10549 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10550 return -EINVAL;
10551 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010552 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010553 }
10554
10555 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10556 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10557 return -EINVAL;
10558 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010559 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010560 }
10561
10562 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10563 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10564 return -EINVAL;
10565 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010566 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010567 }
10568
10569 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10570 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10571 return -EINVAL;
10572 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010573 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010574 }
10575
Johannes Bergff1b6e62011-05-04 15:37:28 +020010576 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10577 struct nlattr *pat;
10578 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010579 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010580 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010581
Johannes Berg98fc4382015-03-01 09:10:13 +020010582 regular = true;
10583
Johannes Bergff1b6e62011-05-04 15:37:28 +020010584 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10585 rem)
10586 n_patterns++;
10587 if (n_patterns > wowlan->n_patterns)
10588 return -EINVAL;
10589
10590 new_triggers.patterns = kcalloc(n_patterns,
10591 sizeof(new_triggers.patterns[0]),
10592 GFP_KERNEL);
10593 if (!new_triggers.patterns)
10594 return -ENOMEM;
10595
10596 new_triggers.n_patterns = n_patterns;
10597 i = 0;
10598
10599 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10600 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010601 u8 *mask_pat;
10602
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010603 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Peng Xuad670232017-10-03 23:21:51 +030010604 nl80211_packet_pattern_policy,
10605 info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010606 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010607 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10608 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010609 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010610 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010611 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010612 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010613 goto error;
10614 if (pat_len > wowlan->pattern_max_len ||
10615 pat_len < wowlan->pattern_min_len)
10616 goto error;
10617
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010618 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010619 pkt_offset = 0;
10620 else
10621 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010622 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010623 if (pkt_offset > wowlan->max_pkt_offset)
10624 goto error;
10625 new_triggers.patterns[i].pkt_offset = pkt_offset;
10626
Johannes Berg922bd802014-05-19 17:59:50 +020010627 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10628 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010629 err = -ENOMEM;
10630 goto error;
10631 }
Johannes Berg922bd802014-05-19 17:59:50 +020010632 new_triggers.patterns[i].mask = mask_pat;
10633 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010634 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010635 mask_pat += mask_len;
10636 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010637 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010638 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010639 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010640 pat_len);
10641 i++;
10642 }
10643 }
10644
Johannes Berg2a0e0472013-01-23 22:57:40 +010010645 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010646 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010647 err = nl80211_parse_wowlan_tcp(
10648 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10649 &new_triggers);
10650 if (err)
10651 goto error;
10652 }
10653
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010654 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010655 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010656 err = nl80211_parse_wowlan_nd(
10657 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10658 &new_triggers);
10659 if (err)
10660 goto error;
10661 }
10662
Johannes Berg98fc4382015-03-01 09:10:13 +020010663 /* The 'any' trigger means the device continues operating more or less
10664 * as in its normal operation mode and wakes up the host on most of the
10665 * normal interrupts (like packet RX, ...)
10666 * It therefore makes little sense to combine with the more constrained
10667 * wakeup trigger modes.
10668 */
10669 if (new_triggers.any && regular) {
10670 err = -EINVAL;
10671 goto error;
10672 }
10673
Johannes Bergae33bd82012-07-12 16:25:02 +020010674 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10675 if (!ntrig) {
10676 err = -ENOMEM;
10677 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010678 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010679 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010680 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010681
Johannes Bergae33bd82012-07-12 16:25:02 +020010682 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010683 if (rdev->ops->set_wakeup &&
10684 prev_enabled != !!rdev->wiphy.wowlan_config)
10685 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010686
Johannes Bergff1b6e62011-05-04 15:37:28 +020010687 return 0;
10688 error:
10689 for (i = 0; i < new_triggers.n_patterns; i++)
10690 kfree(new_triggers.patterns[i].mask);
10691 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010692 if (new_triggers.tcp && new_triggers.tcp->sock)
10693 sock_release(new_triggers.tcp->sock);
10694 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010695 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010696 return err;
10697}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010698#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010699
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010700static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10701 struct cfg80211_registered_device *rdev)
10702{
10703 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10704 int i, j, pat_len;
10705 struct cfg80211_coalesce_rules *rule;
10706
10707 if (!rdev->coalesce->n_rules)
10708 return 0;
10709
10710 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10711 if (!nl_rules)
10712 return -ENOBUFS;
10713
10714 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10715 nl_rule = nla_nest_start(msg, i + 1);
10716 if (!nl_rule)
10717 return -ENOBUFS;
10718
10719 rule = &rdev->coalesce->rules[i];
10720 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10721 rule->delay))
10722 return -ENOBUFS;
10723
10724 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10725 rule->condition))
10726 return -ENOBUFS;
10727
10728 nl_pats = nla_nest_start(msg,
10729 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10730 if (!nl_pats)
10731 return -ENOBUFS;
10732
10733 for (j = 0; j < rule->n_patterns; j++) {
10734 nl_pat = nla_nest_start(msg, j + 1);
10735 if (!nl_pat)
10736 return -ENOBUFS;
10737 pat_len = rule->patterns[j].pattern_len;
10738 if (nla_put(msg, NL80211_PKTPAT_MASK,
10739 DIV_ROUND_UP(pat_len, 8),
10740 rule->patterns[j].mask) ||
10741 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10742 rule->patterns[j].pattern) ||
10743 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10744 rule->patterns[j].pkt_offset))
10745 return -ENOBUFS;
10746 nla_nest_end(msg, nl_pat);
10747 }
10748 nla_nest_end(msg, nl_pats);
10749 nla_nest_end(msg, nl_rule);
10750 }
10751 nla_nest_end(msg, nl_rules);
10752
10753 return 0;
10754}
10755
10756static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10757{
10758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10759 struct sk_buff *msg;
10760 void *hdr;
10761
10762 if (!rdev->wiphy.coalesce)
10763 return -EOPNOTSUPP;
10764
10765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10766 if (!msg)
10767 return -ENOMEM;
10768
10769 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10770 NL80211_CMD_GET_COALESCE);
10771 if (!hdr)
10772 goto nla_put_failure;
10773
10774 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10775 goto nla_put_failure;
10776
10777 genlmsg_end(msg, hdr);
10778 return genlmsg_reply(msg, info);
10779
10780nla_put_failure:
10781 nlmsg_free(msg);
10782 return -ENOBUFS;
10783}
10784
10785void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10786{
10787 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10788 int i, j;
10789 struct cfg80211_coalesce_rules *rule;
10790
10791 if (!coalesce)
10792 return;
10793
10794 for (i = 0; i < coalesce->n_rules; i++) {
10795 rule = &coalesce->rules[i];
10796 for (j = 0; j < rule->n_patterns; j++)
10797 kfree(rule->patterns[j].mask);
10798 kfree(rule->patterns);
10799 }
10800 kfree(coalesce->rules);
10801 kfree(coalesce);
10802 rdev->coalesce = NULL;
10803}
10804
10805static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10806 struct nlattr *rule,
10807 struct cfg80211_coalesce_rules *new_rule)
10808{
10809 int err, i;
10810 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10811 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10812 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10813 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10814
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010815 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010816 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010817 if (err)
10818 return err;
10819
10820 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10821 new_rule->delay =
10822 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10823 if (new_rule->delay > coalesce->max_delay)
10824 return -EINVAL;
10825
10826 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10827 new_rule->condition =
10828 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10829 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10830 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10831 return -EINVAL;
10832
10833 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10834 return -EINVAL;
10835
10836 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10837 rem)
10838 n_patterns++;
10839 if (n_patterns > coalesce->n_patterns)
10840 return -EINVAL;
10841
10842 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10843 GFP_KERNEL);
10844 if (!new_rule->patterns)
10845 return -ENOMEM;
10846
10847 new_rule->n_patterns = n_patterns;
10848 i = 0;
10849
10850 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10851 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010852 u8 *mask_pat;
10853
Peng Xuad670232017-10-03 23:21:51 +030010854 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10855 nl80211_packet_pattern_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010856 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10857 !pat_tb[NL80211_PKTPAT_PATTERN])
10858 return -EINVAL;
10859 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10860 mask_len = DIV_ROUND_UP(pat_len, 8);
10861 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10862 return -EINVAL;
10863 if (pat_len > coalesce->pattern_max_len ||
10864 pat_len < coalesce->pattern_min_len)
10865 return -EINVAL;
10866
10867 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10868 pkt_offset = 0;
10869 else
10870 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10871 if (pkt_offset > coalesce->max_pkt_offset)
10872 return -EINVAL;
10873 new_rule->patterns[i].pkt_offset = pkt_offset;
10874
Johannes Berg922bd802014-05-19 17:59:50 +020010875 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10876 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010877 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010878
10879 new_rule->patterns[i].mask = mask_pat;
10880 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10881 mask_len);
10882
10883 mask_pat += mask_len;
10884 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010885 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010886 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10887 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010888 i++;
10889 }
10890
10891 return 0;
10892}
10893
10894static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10895{
10896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10897 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10898 struct cfg80211_coalesce new_coalesce = {};
10899 struct cfg80211_coalesce *n_coalesce;
10900 int err, rem_rule, n_rules = 0, i, j;
10901 struct nlattr *rule;
10902 struct cfg80211_coalesce_rules *tmp_rule;
10903
10904 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10905 return -EOPNOTSUPP;
10906
10907 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10908 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010909 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010910 return 0;
10911 }
10912
10913 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10914 rem_rule)
10915 n_rules++;
10916 if (n_rules > coalesce->n_rules)
10917 return -EINVAL;
10918
10919 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10920 GFP_KERNEL);
10921 if (!new_coalesce.rules)
10922 return -ENOMEM;
10923
10924 new_coalesce.n_rules = n_rules;
10925 i = 0;
10926
10927 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10928 rem_rule) {
10929 err = nl80211_parse_coalesce_rule(rdev, rule,
10930 &new_coalesce.rules[i]);
10931 if (err)
10932 goto error;
10933
10934 i++;
10935 }
10936
Ilan Peera1056b12015-10-22 22:27:46 +030010937 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010938 if (err)
10939 goto error;
10940
10941 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10942 if (!n_coalesce) {
10943 err = -ENOMEM;
10944 goto error;
10945 }
10946 cfg80211_rdev_free_coalesce(rdev);
10947 rdev->coalesce = n_coalesce;
10948
10949 return 0;
10950error:
10951 for (i = 0; i < new_coalesce.n_rules; i++) {
10952 tmp_rule = &new_coalesce.rules[i];
10953 for (j = 0; j < tmp_rule->n_patterns; j++)
10954 kfree(tmp_rule->patterns[j].mask);
10955 kfree(tmp_rule->patterns);
10956 }
10957 kfree(new_coalesce.rules);
10958
10959 return err;
10960}
10961
Johannes Berge5497d72011-07-05 16:35:40 +020010962static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10963{
10964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10965 struct net_device *dev = info->user_ptr[1];
10966 struct wireless_dev *wdev = dev->ieee80211_ptr;
10967 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10968 struct cfg80211_gtk_rekey_data rekey_data;
10969 int err;
10970
10971 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10972 return -EINVAL;
10973
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010974 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10975 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020010976 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020010977 if (err)
10978 return err;
10979
Vladis Dronove785fa02017-09-13 00:21:21 +020010980 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
10981 !tb[NL80211_REKEY_DATA_KCK])
10982 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020010983 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10984 return -ERANGE;
10985 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10986 return -ERANGE;
10987 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10988 return -ERANGE;
10989
Johannes Berg78f686c2014-09-10 22:28:06 +030010990 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10991 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10992 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010993
10994 wdev_lock(wdev);
10995 if (!wdev->current_bss) {
10996 err = -ENOTCONN;
10997 goto out;
10998 }
10999
11000 if (!rdev->ops->set_rekey_data) {
11001 err = -EOPNOTSUPP;
11002 goto out;
11003 }
11004
Hila Gonene35e4d22012-06-27 17:19:42 +030011005 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020011006 out:
11007 wdev_unlock(wdev);
11008 return err;
11009}
11010
Johannes Berg28946da2011-11-04 11:18:12 +010011011static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11012 struct genl_info *info)
11013{
11014 struct net_device *dev = info->user_ptr[1];
11015 struct wireless_dev *wdev = dev->ieee80211_ptr;
11016
11017 if (wdev->iftype != NL80211_IFTYPE_AP &&
11018 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11019 return -EINVAL;
11020
Eric W. Biederman15e47302012-09-07 20:12:54 +000011021 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011022 return -EBUSY;
11023
Eric W. Biederman15e47302012-09-07 20:12:54 +000011024 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010011025 return 0;
11026}
11027
Johannes Berg7f6cf312011-11-04 11:18:15 +010011028static int nl80211_probe_client(struct sk_buff *skb,
11029 struct genl_info *info)
11030{
11031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11032 struct net_device *dev = info->user_ptr[1];
11033 struct wireless_dev *wdev = dev->ieee80211_ptr;
11034 struct sk_buff *msg;
11035 void *hdr;
11036 const u8 *addr;
11037 u64 cookie;
11038 int err;
11039
11040 if (wdev->iftype != NL80211_IFTYPE_AP &&
11041 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11042 return -EOPNOTSUPP;
11043
11044 if (!info->attrs[NL80211_ATTR_MAC])
11045 return -EINVAL;
11046
11047 if (!rdev->ops->probe_client)
11048 return -EOPNOTSUPP;
11049
11050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11051 if (!msg)
11052 return -ENOMEM;
11053
Eric W. Biederman15e47302012-09-07 20:12:54 +000011054 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011055 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011056 if (!hdr) {
11057 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011058 goto free_msg;
11059 }
11060
11061 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11062
Hila Gonene35e4d22012-06-27 17:19:42 +030011063 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011064 if (err)
11065 goto free_msg;
11066
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011067 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11068 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011069 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011070
11071 genlmsg_end(msg, hdr);
11072
11073 return genlmsg_reply(msg, info);
11074
11075 nla_put_failure:
11076 err = -ENOBUFS;
11077 free_msg:
11078 nlmsg_free(msg);
11079 return err;
11080}
11081
Johannes Berg5e760232011-11-04 11:18:17 +010011082static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11083{
11084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011085 struct cfg80211_beacon_registration *reg, *nreg;
11086 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011087
11088 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11089 return -EOPNOTSUPP;
11090
Ben Greear37c73b52012-10-26 14:49:25 -070011091 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11092 if (!nreg)
11093 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011094
Ben Greear37c73b52012-10-26 14:49:25 -070011095 /* First, check if already registered. */
11096 spin_lock_bh(&rdev->beacon_registrations_lock);
11097 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11098 if (reg->nlportid == info->snd_portid) {
11099 rv = -EALREADY;
11100 goto out_err;
11101 }
11102 }
11103 /* Add it to the list */
11104 nreg->nlportid = info->snd_portid;
11105 list_add(&nreg->list, &rdev->beacon_registrations);
11106
11107 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011108
11109 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011110out_err:
11111 spin_unlock_bh(&rdev->beacon_registrations_lock);
11112 kfree(nreg);
11113 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011114}
11115
Johannes Berg98104fde2012-06-16 00:19:54 +020011116static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11117{
11118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11119 struct wireless_dev *wdev = info->user_ptr[1];
11120 int err;
11121
11122 if (!rdev->ops->start_p2p_device)
11123 return -EOPNOTSUPP;
11124
11125 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11126 return -EOPNOTSUPP;
11127
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011128 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011129 return 0;
11130
Luciano Coelhob6a55012014-02-27 11:07:21 +020011131 if (rfkill_blocked(rdev->rfkill))
11132 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011133
Johannes Bergeeb126e2012-10-23 15:16:50 +020011134 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011135 if (err)
11136 return err;
11137
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011138 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011139 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011140
11141 return 0;
11142}
11143
11144static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11145{
11146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11147 struct wireless_dev *wdev = info->user_ptr[1];
11148
11149 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11150 return -EOPNOTSUPP;
11151
11152 if (!rdev->ops->stop_p2p_device)
11153 return -EOPNOTSUPP;
11154
Johannes Bergf9f47522013-03-19 15:04:07 +010011155 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011156
11157 return 0;
11158}
11159
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011160static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11161{
11162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11163 struct wireless_dev *wdev = info->user_ptr[1];
11164 struct cfg80211_nan_conf conf = {};
11165 int err;
11166
11167 if (wdev->iftype != NL80211_IFTYPE_NAN)
11168 return -EOPNOTSUPP;
11169
Johannes Bergeeb04a92016-11-21 13:55:48 +010011170 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011171 return -EEXIST;
11172
11173 if (rfkill_blocked(rdev->rfkill))
11174 return -ERFKILL;
11175
11176 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11177 return -EINVAL;
11178
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011179 conf.master_pref =
11180 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11181 if (!conf.master_pref)
11182 return -EINVAL;
11183
Luca Coelho85859892017-02-08 15:00:34 +020011184 if (info->attrs[NL80211_ATTR_BANDS]) {
11185 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11186
11187 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11188 return -EOPNOTSUPP;
11189
11190 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11191 return -EINVAL;
11192
11193 conf.bands = bands;
11194 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011195
11196 err = rdev_start_nan(rdev, wdev, &conf);
11197 if (err)
11198 return err;
11199
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011200 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011201 rdev->opencount++;
11202
11203 return 0;
11204}
11205
11206static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11207{
11208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11209 struct wireless_dev *wdev = info->user_ptr[1];
11210
11211 if (wdev->iftype != NL80211_IFTYPE_NAN)
11212 return -EOPNOTSUPP;
11213
11214 cfg80211_stop_nan(rdev, wdev);
11215
11216 return 0;
11217}
11218
Ayala Bekera442b762016-09-20 17:31:15 +030011219static int validate_nan_filter(struct nlattr *filter_attr)
11220{
11221 struct nlattr *attr;
11222 int len = 0, n_entries = 0, rem;
11223
11224 nla_for_each_nested(attr, filter_attr, rem) {
11225 len += nla_len(attr);
11226 n_entries++;
11227 }
11228
11229 if (len >= U8_MAX)
11230 return -EINVAL;
11231
11232 return n_entries;
11233}
11234
11235static int handle_nan_filter(struct nlattr *attr_filter,
11236 struct cfg80211_nan_func *func,
11237 bool tx)
11238{
11239 struct nlattr *attr;
11240 int n_entries, rem, i;
11241 struct cfg80211_nan_func_filter *filter;
11242
11243 n_entries = validate_nan_filter(attr_filter);
11244 if (n_entries < 0)
11245 return n_entries;
11246
11247 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11248
11249 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11250 if (!filter)
11251 return -ENOMEM;
11252
11253 i = 0;
11254 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011255 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011256 filter[i].len = nla_len(attr);
11257 i++;
11258 }
11259 if (tx) {
11260 func->num_tx_filters = n_entries;
11261 func->tx_filters = filter;
11262 } else {
11263 func->num_rx_filters = n_entries;
11264 func->rx_filters = filter;
11265 }
11266
11267 return 0;
11268}
11269
11270static int nl80211_nan_add_func(struct sk_buff *skb,
11271 struct genl_info *info)
11272{
11273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11274 struct wireless_dev *wdev = info->user_ptr[1];
11275 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11276 struct cfg80211_nan_func *func;
11277 struct sk_buff *msg = NULL;
11278 void *hdr = NULL;
11279 int err = 0;
11280
11281 if (wdev->iftype != NL80211_IFTYPE_NAN)
11282 return -EOPNOTSUPP;
11283
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011284 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011285 return -ENOTCONN;
11286
11287 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11288 return -EINVAL;
11289
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011290 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11291 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011292 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011293 if (err)
11294 return err;
11295
11296 func = kzalloc(sizeof(*func), GFP_KERNEL);
11297 if (!func)
11298 return -ENOMEM;
11299
11300 func->cookie = wdev->wiphy->cookie_counter++;
11301
11302 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11303 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11304 err = -EINVAL;
11305 goto out;
11306 }
11307
11308
11309 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11310
11311 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11312 err = -EINVAL;
11313 goto out;
11314 }
11315
11316 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11317 sizeof(func->service_id));
11318
11319 func->close_range =
11320 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11321
11322 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11323 func->serv_spec_info_len =
11324 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11325 func->serv_spec_info =
11326 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11327 func->serv_spec_info_len,
11328 GFP_KERNEL);
11329 if (!func->serv_spec_info) {
11330 err = -ENOMEM;
11331 goto out;
11332 }
11333 }
11334
11335 if (tb[NL80211_NAN_FUNC_TTL])
11336 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11337
11338 switch (func->type) {
11339 case NL80211_NAN_FUNC_PUBLISH:
11340 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11341 err = -EINVAL;
11342 goto out;
11343 }
11344
11345 func->publish_type =
11346 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11347 func->publish_bcast =
11348 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11349
11350 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11351 func->publish_bcast) {
11352 err = -EINVAL;
11353 goto out;
11354 }
11355 break;
11356 case NL80211_NAN_FUNC_SUBSCRIBE:
11357 func->subscribe_active =
11358 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11359 break;
11360 case NL80211_NAN_FUNC_FOLLOW_UP:
11361 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11362 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11363 err = -EINVAL;
11364 goto out;
11365 }
11366
11367 func->followup_id =
11368 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11369 func->followup_reqid =
11370 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11371 memcpy(func->followup_dest.addr,
11372 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11373 sizeof(func->followup_dest.addr));
11374 if (func->ttl) {
11375 err = -EINVAL;
11376 goto out;
11377 }
11378 break;
11379 default:
11380 err = -EINVAL;
11381 goto out;
11382 }
11383
11384 if (tb[NL80211_NAN_FUNC_SRF]) {
11385 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11386
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011387 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11388 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011389 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011390 if (err)
11391 goto out;
11392
11393 func->srf_include =
11394 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11395
11396 if (srf_tb[NL80211_NAN_SRF_BF]) {
11397 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11398 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11399 err = -EINVAL;
11400 goto out;
11401 }
11402
11403 func->srf_bf_len =
11404 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11405 func->srf_bf =
11406 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11407 func->srf_bf_len, GFP_KERNEL);
11408 if (!func->srf_bf) {
11409 err = -ENOMEM;
11410 goto out;
11411 }
11412
11413 func->srf_bf_idx =
11414 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11415 } else {
11416 struct nlattr *attr, *mac_attr =
11417 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11418 int n_entries, rem, i = 0;
11419
11420 if (!mac_attr) {
11421 err = -EINVAL;
11422 goto out;
11423 }
11424
11425 n_entries = validate_acl_mac_addrs(mac_attr);
11426 if (n_entries <= 0) {
11427 err = -EINVAL;
11428 goto out;
11429 }
11430
11431 func->srf_num_macs = n_entries;
11432 func->srf_macs =
11433 kzalloc(sizeof(*func->srf_macs) * n_entries,
11434 GFP_KERNEL);
11435 if (!func->srf_macs) {
11436 err = -ENOMEM;
11437 goto out;
11438 }
11439
11440 nla_for_each_nested(attr, mac_attr, rem)
11441 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11442 sizeof(*func->srf_macs));
11443 }
11444 }
11445
11446 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11447 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11448 func, true);
11449 if (err)
11450 goto out;
11451 }
11452
11453 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11454 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11455 func, false);
11456 if (err)
11457 goto out;
11458 }
11459
11460 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11461 if (!msg) {
11462 err = -ENOMEM;
11463 goto out;
11464 }
11465
11466 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11467 NL80211_CMD_ADD_NAN_FUNCTION);
11468 /* This can't really happen - we just allocated 4KB */
11469 if (WARN_ON(!hdr)) {
11470 err = -ENOMEM;
11471 goto out;
11472 }
11473
11474 err = rdev_add_nan_func(rdev, wdev, func);
11475out:
11476 if (err < 0) {
11477 cfg80211_free_nan_func(func);
11478 nlmsg_free(msg);
11479 return err;
11480 }
11481
11482 /* propagate the instance id and cookie to userspace */
11483 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11484 NL80211_ATTR_PAD))
11485 goto nla_put_failure;
11486
11487 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11488 if (!func_attr)
11489 goto nla_put_failure;
11490
11491 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11492 func->instance_id))
11493 goto nla_put_failure;
11494
11495 nla_nest_end(msg, func_attr);
11496
11497 genlmsg_end(msg, hdr);
11498 return genlmsg_reply(msg, info);
11499
11500nla_put_failure:
11501 nlmsg_free(msg);
11502 return -ENOBUFS;
11503}
11504
11505static int nl80211_nan_del_func(struct sk_buff *skb,
11506 struct genl_info *info)
11507{
11508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11509 struct wireless_dev *wdev = info->user_ptr[1];
11510 u64 cookie;
11511
11512 if (wdev->iftype != NL80211_IFTYPE_NAN)
11513 return -EOPNOTSUPP;
11514
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011515 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011516 return -ENOTCONN;
11517
11518 if (!info->attrs[NL80211_ATTR_COOKIE])
11519 return -EINVAL;
11520
Ayala Bekera442b762016-09-20 17:31:15 +030011521 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11522
11523 rdev_del_nan_func(rdev, wdev, cookie);
11524
11525 return 0;
11526}
11527
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011528static int nl80211_nan_change_config(struct sk_buff *skb,
11529 struct genl_info *info)
11530{
11531 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11532 struct wireless_dev *wdev = info->user_ptr[1];
11533 struct cfg80211_nan_conf conf = {};
11534 u32 changed = 0;
11535
11536 if (wdev->iftype != NL80211_IFTYPE_NAN)
11537 return -EOPNOTSUPP;
11538
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011539 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011540 return -ENOTCONN;
11541
11542 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11543 conf.master_pref =
11544 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11545 if (conf.master_pref <= 1 || conf.master_pref == 255)
11546 return -EINVAL;
11547
11548 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11549 }
11550
Luca Coelho85859892017-02-08 15:00:34 +020011551 if (info->attrs[NL80211_ATTR_BANDS]) {
11552 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11553
11554 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11555 return -EOPNOTSUPP;
11556
11557 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11558 return -EINVAL;
11559
11560 conf.bands = bands;
11561 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011562 }
11563
11564 if (!changed)
11565 return -EINVAL;
11566
11567 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11568}
11569
Ayala Beker50bcd312016-09-20 17:31:17 +030011570void cfg80211_nan_match(struct wireless_dev *wdev,
11571 struct cfg80211_nan_match_params *match, gfp_t gfp)
11572{
11573 struct wiphy *wiphy = wdev->wiphy;
11574 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11575 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11576 struct sk_buff *msg;
11577 void *hdr;
11578
11579 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11580 return;
11581
11582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11583 if (!msg)
11584 return;
11585
11586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11587 if (!hdr) {
11588 nlmsg_free(msg);
11589 return;
11590 }
11591
11592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11593 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11594 wdev->netdev->ifindex)) ||
11595 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11596 NL80211_ATTR_PAD))
11597 goto nla_put_failure;
11598
11599 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11600 NL80211_ATTR_PAD) ||
11601 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11602 goto nla_put_failure;
11603
11604 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11605 if (!match_attr)
11606 goto nla_put_failure;
11607
11608 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11609 if (!local_func_attr)
11610 goto nla_put_failure;
11611
11612 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11613 goto nla_put_failure;
11614
11615 nla_nest_end(msg, local_func_attr);
11616
11617 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11618 if (!peer_func_attr)
11619 goto nla_put_failure;
11620
11621 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11622 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11623 goto nla_put_failure;
11624
11625 if (match->info && match->info_len &&
11626 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11627 match->info))
11628 goto nla_put_failure;
11629
11630 nla_nest_end(msg, peer_func_attr);
11631 nla_nest_end(msg, match_attr);
11632 genlmsg_end(msg, hdr);
11633
11634 if (!wdev->owner_nlportid)
11635 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11636 msg, 0, NL80211_MCGRP_NAN, gfp);
11637 else
11638 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11639 wdev->owner_nlportid);
11640
11641 return;
11642
11643nla_put_failure:
11644 nlmsg_free(msg);
11645}
11646EXPORT_SYMBOL(cfg80211_nan_match);
11647
Ayala Beker368e5a72016-09-20 17:31:18 +030011648void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11649 u8 inst_id,
11650 enum nl80211_nan_func_term_reason reason,
11651 u64 cookie, gfp_t gfp)
11652{
11653 struct wiphy *wiphy = wdev->wiphy;
11654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11655 struct sk_buff *msg;
11656 struct nlattr *func_attr;
11657 void *hdr;
11658
11659 if (WARN_ON(!inst_id))
11660 return;
11661
11662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11663 if (!msg)
11664 return;
11665
11666 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11667 if (!hdr) {
11668 nlmsg_free(msg);
11669 return;
11670 }
11671
11672 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11673 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11674 wdev->netdev->ifindex)) ||
11675 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11676 NL80211_ATTR_PAD))
11677 goto nla_put_failure;
11678
11679 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11680 NL80211_ATTR_PAD))
11681 goto nla_put_failure;
11682
11683 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11684 if (!func_attr)
11685 goto nla_put_failure;
11686
11687 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11688 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11689 goto nla_put_failure;
11690
11691 nla_nest_end(msg, func_attr);
11692 genlmsg_end(msg, hdr);
11693
11694 if (!wdev->owner_nlportid)
11695 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11696 msg, 0, NL80211_MCGRP_NAN, gfp);
11697 else
11698 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11699 wdev->owner_nlportid);
11700
11701 return;
11702
11703nla_put_failure:
11704 nlmsg_free(msg);
11705}
11706EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11707
Johannes Berg3713b4e2013-02-14 16:19:38 +010011708static int nl80211_get_protocol_features(struct sk_buff *skb,
11709 struct genl_info *info)
11710{
11711 void *hdr;
11712 struct sk_buff *msg;
11713
11714 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11715 if (!msg)
11716 return -ENOMEM;
11717
11718 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11719 NL80211_CMD_GET_PROTOCOL_FEATURES);
11720 if (!hdr)
11721 goto nla_put_failure;
11722
11723 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11724 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11725 goto nla_put_failure;
11726
11727 genlmsg_end(msg, hdr);
11728 return genlmsg_reply(msg, info);
11729
11730 nla_put_failure:
11731 kfree_skb(msg);
11732 return -ENOBUFS;
11733}
11734
Jouni Malinen355199e2013-02-27 17:14:27 +020011735static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11736{
11737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11738 struct cfg80211_update_ft_ies_params ft_params;
11739 struct net_device *dev = info->user_ptr[1];
11740
11741 if (!rdev->ops->update_ft_ies)
11742 return -EOPNOTSUPP;
11743
11744 if (!info->attrs[NL80211_ATTR_MDID] ||
11745 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11746 return -EINVAL;
11747
11748 memset(&ft_params, 0, sizeof(ft_params));
11749 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11750 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11751 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11752
11753 return rdev_update_ft_ies(rdev, dev, &ft_params);
11754}
11755
Arend van Spriel5de17982013-04-18 15:49:00 +020011756static int nl80211_crit_protocol_start(struct sk_buff *skb,
11757 struct genl_info *info)
11758{
11759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11760 struct wireless_dev *wdev = info->user_ptr[1];
11761 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11762 u16 duration;
11763 int ret;
11764
11765 if (!rdev->ops->crit_proto_start)
11766 return -EOPNOTSUPP;
11767
11768 if (WARN_ON(!rdev->ops->crit_proto_stop))
11769 return -EINVAL;
11770
11771 if (rdev->crit_proto_nlportid)
11772 return -EBUSY;
11773
11774 /* determine protocol if provided */
11775 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11776 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11777
11778 if (proto >= NUM_NL80211_CRIT_PROTO)
11779 return -EINVAL;
11780
11781 /* timeout must be provided */
11782 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11783 return -EINVAL;
11784
11785 duration =
11786 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11787
11788 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11789 return -ERANGE;
11790
11791 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11792 if (!ret)
11793 rdev->crit_proto_nlportid = info->snd_portid;
11794
11795 return ret;
11796}
11797
11798static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11799 struct genl_info *info)
11800{
11801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11802 struct wireless_dev *wdev = info->user_ptr[1];
11803
11804 if (!rdev->ops->crit_proto_stop)
11805 return -EOPNOTSUPP;
11806
11807 if (rdev->crit_proto_nlportid) {
11808 rdev->crit_proto_nlportid = 0;
11809 rdev_crit_proto_stop(rdev, wdev);
11810 }
11811 return 0;
11812}
11813
Johannes Bergad7e7182013-11-13 13:37:47 +010011814static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11815{
11816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11817 struct wireless_dev *wdev =
11818 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11819 int i, err;
11820 u32 vid, subcmd;
11821
11822 if (!rdev->wiphy.vendor_commands)
11823 return -EOPNOTSUPP;
11824
11825 if (IS_ERR(wdev)) {
11826 err = PTR_ERR(wdev);
11827 if (err != -EINVAL)
11828 return err;
11829 wdev = NULL;
11830 } else if (wdev->wiphy != &rdev->wiphy) {
11831 return -EINVAL;
11832 }
11833
11834 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11835 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11836 return -EINVAL;
11837
11838 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11839 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11840 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11841 const struct wiphy_vendor_command *vcmd;
11842 void *data = NULL;
11843 int len = 0;
11844
11845 vcmd = &rdev->wiphy.vendor_commands[i];
11846
11847 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11848 continue;
11849
11850 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11851 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11852 if (!wdev)
11853 return -EINVAL;
11854 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11855 !wdev->netdev)
11856 return -EINVAL;
11857
11858 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011859 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011860 return -ENETDOWN;
11861 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011862
11863 if (!vcmd->doit)
11864 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011865 } else {
11866 wdev = NULL;
11867 }
11868
11869 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11870 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11871 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11872 }
11873
11874 rdev->cur_cmd_info = info;
11875 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11876 data, len);
11877 rdev->cur_cmd_info = NULL;
11878 return err;
11879 }
11880
11881 return -EOPNOTSUPP;
11882}
11883
Johannes Berg7bdbe402015-08-15 22:39:49 +030011884static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11885 struct netlink_callback *cb,
11886 struct cfg80211_registered_device **rdev,
11887 struct wireless_dev **wdev)
11888{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011889 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011890 u32 vid, subcmd;
11891 unsigned int i;
11892 int vcmd_idx = -1;
11893 int err;
11894 void *data = NULL;
11895 unsigned int data_len = 0;
11896
Johannes Berg7bdbe402015-08-15 22:39:49 +030011897 if (cb->args[0]) {
11898 /* subtract the 1 again here */
11899 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11900 struct wireless_dev *tmp;
11901
Johannes Bergea90e0d2017-03-15 14:26:04 +010011902 if (!wiphy)
11903 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011904 *rdev = wiphy_to_rdev(wiphy);
11905 *wdev = NULL;
11906
11907 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011908 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011909 if (tmp->identifier == cb->args[1] - 1) {
11910 *wdev = tmp;
11911 break;
11912 }
11913 }
11914 }
11915
11916 /* keep rtnl locked in successful case */
11917 return 0;
11918 }
11919
Johannes Bergfceb6432017-04-12 14:34:07 +020011920 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11921 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011922 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011923 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011924
Johannes Bergc90c39d2016-10-24 14:40:01 +020011925 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011926 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11927 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011928
Johannes Bergc90c39d2016-10-24 14:40:01 +020011929 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011930 if (IS_ERR(*wdev))
11931 *wdev = NULL;
11932
Johannes Bergc90c39d2016-10-24 14:40:01 +020011933 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011934 if (IS_ERR(*rdev))
11935 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011936
Johannes Bergc90c39d2016-10-24 14:40:01 +020011937 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11938 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011939
11940 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11941 const struct wiphy_vendor_command *vcmd;
11942
11943 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11944
11945 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11946 continue;
11947
Johannes Bergea90e0d2017-03-15 14:26:04 +010011948 if (!vcmd->dumpit)
11949 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011950
11951 vcmd_idx = i;
11952 break;
11953 }
11954
Johannes Bergea90e0d2017-03-15 14:26:04 +010011955 if (vcmd_idx < 0)
11956 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011957
Johannes Bergc90c39d2016-10-24 14:40:01 +020011958 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11959 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11960 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011961 }
11962
11963 /* 0 is the first index - add 1 to parse only once */
11964 cb->args[0] = (*rdev)->wiphy_idx + 1;
11965 /* add 1 to know if it was NULL */
11966 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11967 cb->args[2] = vcmd_idx;
11968 cb->args[3] = (unsigned long)data;
11969 cb->args[4] = data_len;
11970
11971 /* keep rtnl locked in successful case */
11972 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011973}
11974
11975static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11976 struct netlink_callback *cb)
11977{
11978 struct cfg80211_registered_device *rdev;
11979 struct wireless_dev *wdev;
11980 unsigned int vcmd_idx;
11981 const struct wiphy_vendor_command *vcmd;
11982 void *data;
11983 int data_len;
11984 int err;
11985 struct nlattr *vendor_data;
11986
Johannes Bergea90e0d2017-03-15 14:26:04 +010011987 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011988 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11989 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011990 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011991
11992 vcmd_idx = cb->args[2];
11993 data = (void *)cb->args[3];
11994 data_len = cb->args[4];
11995 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11996
11997 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11998 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011999 if (!wdev) {
12000 err = -EINVAL;
12001 goto out;
12002 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012003 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010012004 !wdev->netdev) {
12005 err = -EINVAL;
12006 goto out;
12007 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012008
12009 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010012010 if (!wdev_running(wdev)) {
12011 err = -ENETDOWN;
12012 goto out;
12013 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030012014 }
12015 }
12016
12017 while (1) {
12018 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12019 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12020 NL80211_CMD_VENDOR);
12021 if (!hdr)
12022 break;
12023
12024 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012025 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12026 wdev_id(wdev),
12027 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030012028 genlmsg_cancel(skb, hdr);
12029 break;
12030 }
12031
12032 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12033 if (!vendor_data) {
12034 genlmsg_cancel(skb, hdr);
12035 break;
12036 }
12037
12038 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12039 (unsigned long *)&cb->args[5]);
12040 nla_nest_end(skb, vendor_data);
12041
12042 if (err == -ENOBUFS || err == -ENOENT) {
12043 genlmsg_cancel(skb, hdr);
12044 break;
12045 } else if (err) {
12046 genlmsg_cancel(skb, hdr);
12047 goto out;
12048 }
12049
12050 genlmsg_end(skb, hdr);
12051 }
12052
12053 err = skb->len;
12054 out:
12055 rtnl_unlock();
12056 return err;
12057}
12058
Johannes Bergad7e7182013-11-13 13:37:47 +010012059struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12060 enum nl80211_commands cmd,
12061 enum nl80211_attrs attr,
12062 int approxlen)
12063{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012064 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012065
12066 if (WARN_ON(!rdev->cur_cmd_info))
12067 return NULL;
12068
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012069 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012070 rdev->cur_cmd_info->snd_portid,
12071 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012072 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012073}
12074EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12075
12076int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12077{
12078 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12079 void *hdr = ((void **)skb->cb)[1];
12080 struct nlattr *data = ((void **)skb->cb)[2];
12081
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012082 /* clear CB data for netlink core to own from now on */
12083 memset(skb->cb, 0, sizeof(skb->cb));
12084
Johannes Bergad7e7182013-11-13 13:37:47 +010012085 if (WARN_ON(!rdev->cur_cmd_info)) {
12086 kfree_skb(skb);
12087 return -EINVAL;
12088 }
12089
12090 nla_nest_end(skb, data);
12091 genlmsg_end(skb, hdr);
12092 return genlmsg_reply(skb, rdev->cur_cmd_info);
12093}
12094EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12095
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012096static int nl80211_set_qos_map(struct sk_buff *skb,
12097 struct genl_info *info)
12098{
12099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12100 struct cfg80211_qos_map *qos_map = NULL;
12101 struct net_device *dev = info->user_ptr[1];
12102 u8 *pos, len, num_des, des_len, des;
12103 int ret;
12104
12105 if (!rdev->ops->set_qos_map)
12106 return -EOPNOTSUPP;
12107
12108 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12109 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12110 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12111
12112 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12113 len > IEEE80211_QOS_MAP_LEN_MAX)
12114 return -EINVAL;
12115
12116 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12117 if (!qos_map)
12118 return -ENOMEM;
12119
12120 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12121 if (num_des) {
12122 des_len = num_des *
12123 sizeof(struct cfg80211_dscp_exception);
12124 memcpy(qos_map->dscp_exception, pos, des_len);
12125 qos_map->num_des = num_des;
12126 for (des = 0; des < num_des; des++) {
12127 if (qos_map->dscp_exception[des].up > 7) {
12128 kfree(qos_map);
12129 return -EINVAL;
12130 }
12131 }
12132 pos += des_len;
12133 }
12134 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12135 }
12136
12137 wdev_lock(dev->ieee80211_ptr);
12138 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12139 if (!ret)
12140 ret = rdev_set_qos_map(rdev, dev, qos_map);
12141 wdev_unlock(dev->ieee80211_ptr);
12142
12143 kfree(qos_map);
12144 return ret;
12145}
12146
Johannes Berg960d01a2014-09-09 22:55:35 +030012147static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12148{
12149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12150 struct net_device *dev = info->user_ptr[1];
12151 struct wireless_dev *wdev = dev->ieee80211_ptr;
12152 const u8 *peer;
12153 u8 tsid, up;
12154 u16 admitted_time = 0;
12155 int err;
12156
Johannes Berg723e73a2014-10-22 09:25:06 +020012157 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012158 return -EOPNOTSUPP;
12159
12160 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12161 !info->attrs[NL80211_ATTR_USER_PRIO])
12162 return -EINVAL;
12163
12164 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12165 if (tsid >= IEEE80211_NUM_TIDS)
12166 return -EINVAL;
12167
12168 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12169 if (up >= IEEE80211_NUM_UPS)
12170 return -EINVAL;
12171
12172 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012173 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012174 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012175 * need more attributes for that (e.g. BA session requirement);
12176 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012177 */
12178 return -EINVAL;
12179 }
12180
12181 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12182
12183 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12184 admitted_time =
12185 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12186 if (!admitted_time)
12187 return -EINVAL;
12188 }
12189
12190 wdev_lock(wdev);
12191 switch (wdev->iftype) {
12192 case NL80211_IFTYPE_STATION:
12193 case NL80211_IFTYPE_P2P_CLIENT:
12194 if (wdev->current_bss)
12195 break;
12196 err = -ENOTCONN;
12197 goto out;
12198 default:
12199 err = -EOPNOTSUPP;
12200 goto out;
12201 }
12202
12203 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12204
12205 out:
12206 wdev_unlock(wdev);
12207 return err;
12208}
12209
12210static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12211{
12212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12213 struct net_device *dev = info->user_ptr[1];
12214 struct wireless_dev *wdev = dev->ieee80211_ptr;
12215 const u8 *peer;
12216 u8 tsid;
12217 int err;
12218
12219 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12220 return -EINVAL;
12221
12222 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12223 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12224
12225 wdev_lock(wdev);
12226 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12227 wdev_unlock(wdev);
12228
12229 return err;
12230}
12231
Arik Nemtsov1057d352014-11-19 12:54:26 +020012232static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12233 struct genl_info *info)
12234{
12235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12236 struct net_device *dev = info->user_ptr[1];
12237 struct wireless_dev *wdev = dev->ieee80211_ptr;
12238 struct cfg80211_chan_def chandef = {};
12239 const u8 *addr;
12240 u8 oper_class;
12241 int err;
12242
12243 if (!rdev->ops->tdls_channel_switch ||
12244 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12245 return -EOPNOTSUPP;
12246
12247 switch (dev->ieee80211_ptr->iftype) {
12248 case NL80211_IFTYPE_STATION:
12249 case NL80211_IFTYPE_P2P_CLIENT:
12250 break;
12251 default:
12252 return -EOPNOTSUPP;
12253 }
12254
12255 if (!info->attrs[NL80211_ATTR_MAC] ||
12256 !info->attrs[NL80211_ATTR_OPER_CLASS])
12257 return -EINVAL;
12258
12259 err = nl80211_parse_chandef(rdev, info, &chandef);
12260 if (err)
12261 return err;
12262
12263 /*
12264 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12265 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12266 * specification is not defined for them.
12267 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012268 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012269 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12270 chandef.width != NL80211_CHAN_WIDTH_20)
12271 return -EINVAL;
12272
12273 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012274 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12275 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012276 return -EINVAL;
12277
12278 /* don't allow switching to DFS channels */
12279 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12280 return -EINVAL;
12281
12282 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12283 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12284
12285 wdev_lock(wdev);
12286 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12287 wdev_unlock(wdev);
12288
12289 return err;
12290}
12291
12292static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12293 struct genl_info *info)
12294{
12295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12296 struct net_device *dev = info->user_ptr[1];
12297 struct wireless_dev *wdev = dev->ieee80211_ptr;
12298 const u8 *addr;
12299
12300 if (!rdev->ops->tdls_channel_switch ||
12301 !rdev->ops->tdls_cancel_channel_switch ||
12302 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12303 return -EOPNOTSUPP;
12304
12305 switch (dev->ieee80211_ptr->iftype) {
12306 case NL80211_IFTYPE_STATION:
12307 case NL80211_IFTYPE_P2P_CLIENT:
12308 break;
12309 default:
12310 return -EOPNOTSUPP;
12311 }
12312
12313 if (!info->attrs[NL80211_ATTR_MAC])
12314 return -EINVAL;
12315
12316 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12317
12318 wdev_lock(wdev);
12319 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12320 wdev_unlock(wdev);
12321
12322 return 0;
12323}
12324
Michael Braunce0ce132016-10-10 19:12:22 +020012325static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12326 struct genl_info *info)
12327{
12328 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12329 struct net_device *dev = info->user_ptr[1];
12330 struct wireless_dev *wdev = dev->ieee80211_ptr;
12331 const struct nlattr *nla;
12332 bool enabled;
12333
Michael Braunce0ce132016-10-10 19:12:22 +020012334 if (!rdev->ops->set_multicast_to_unicast)
12335 return -EOPNOTSUPP;
12336
12337 if (wdev->iftype != NL80211_IFTYPE_AP &&
12338 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12339 return -EOPNOTSUPP;
12340
12341 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12342 enabled = nla_get_flag(nla);
12343
12344 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12345}
12346
Avraham Stern3a00df52017-06-09 13:08:43 +010012347static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12348{
12349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12350 struct net_device *dev = info->user_ptr[1];
12351 struct wireless_dev *wdev = dev->ieee80211_ptr;
12352 struct cfg80211_pmk_conf pmk_conf = {};
12353 int ret;
12354
12355 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12356 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12357 return -EOPNOTSUPP;
12358
12359 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12360 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12361 return -EOPNOTSUPP;
12362
12363 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12364 return -EINVAL;
12365
12366 wdev_lock(wdev);
12367 if (!wdev->current_bss) {
12368 ret = -ENOTCONN;
12369 goto out;
12370 }
12371
12372 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12373 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12374 ret = -EINVAL;
12375 goto out;
12376 }
12377
12378 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12379 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12380 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12381 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12382 ret = -EINVAL;
12383 goto out;
12384 }
12385
12386 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12387 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12388
12389 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12390 ret = -EINVAL;
12391 goto out;
12392 }
12393
12394 pmk_conf.pmk_r0_name =
12395 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12396 }
12397
12398 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12399out:
12400 wdev_unlock(wdev);
12401 return ret;
12402}
12403
12404static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12405{
12406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12407 struct net_device *dev = info->user_ptr[1];
12408 struct wireless_dev *wdev = dev->ieee80211_ptr;
12409 const u8 *aa;
12410 int ret;
12411
12412 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12413 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12414 return -EOPNOTSUPP;
12415
12416 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12417 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12418 return -EOPNOTSUPP;
12419
12420 if (!info->attrs[NL80211_ATTR_MAC])
12421 return -EINVAL;
12422
12423 wdev_lock(wdev);
12424 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12425 ret = rdev_del_pmk(rdev, dev, aa);
12426 wdev_unlock(wdev);
12427
12428 return ret;
12429}
12430
Johannes Berg4c476992010-10-04 21:36:35 +020012431#define NL80211_FLAG_NEED_WIPHY 0x01
12432#define NL80211_FLAG_NEED_NETDEV 0x02
12433#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012434#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12435#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12436 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012437#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012438/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012439#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12440 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012441#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012442
Johannes Bergf84f7712013-11-14 17:14:45 +010012443static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012444 struct genl_info *info)
12445{
12446 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012447 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012448 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012449 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12450
12451 if (rtnl)
12452 rtnl_lock();
12453
12454 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012455 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012456 if (IS_ERR(rdev)) {
12457 if (rtnl)
12458 rtnl_unlock();
12459 return PTR_ERR(rdev);
12460 }
12461 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012462 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12463 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012464 ASSERT_RTNL();
12465
Johannes Berg89a54e42012-06-15 14:33:17 +020012466 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12467 info->attrs);
12468 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012469 if (rtnl)
12470 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012471 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012472 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012473
Johannes Berg89a54e42012-06-15 14:33:17 +020012474 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012475 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012476
Johannes Berg1bf614e2012-06-15 15:23:36 +020012477 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12478 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012479 if (rtnl)
12480 rtnl_unlock();
12481 return -EINVAL;
12482 }
12483
12484 info->user_ptr[1] = dev;
12485 } else {
12486 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012487 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012488
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012489 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12490 !wdev_running(wdev)) {
12491 if (rtnl)
12492 rtnl_unlock();
12493 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012494 }
12495
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012496 if (dev)
12497 dev_hold(dev);
12498
Johannes Berg4c476992010-10-04 21:36:35 +020012499 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012500 }
12501
12502 return 0;
12503}
12504
Johannes Bergf84f7712013-11-14 17:14:45 +010012505static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012506 struct genl_info *info)
12507{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012508 if (info->user_ptr[1]) {
12509 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12510 struct wireless_dev *wdev = info->user_ptr[1];
12511
12512 if (wdev->netdev)
12513 dev_put(wdev->netdev);
12514 } else {
12515 dev_put(info->user_ptr[1]);
12516 }
12517 }
Johannes Berg5393b912014-09-10 15:00:16 +030012518
Johannes Berg4c476992010-10-04 21:36:35 +020012519 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12520 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012521
12522 /* If needed, clear the netlink message payload from the SKB
12523 * as it might contain key data that shouldn't stick around on
12524 * the heap after the SKB is freed. The netlink message header
12525 * is still needed for further processing, so leave it intact.
12526 */
12527 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12528 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12529
12530 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12531 }
Johannes Berg4c476992010-10-04 21:36:35 +020012532}
12533
Johannes Berg4534de82013-11-14 17:14:46 +010012534static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012535 {
12536 .cmd = NL80211_CMD_GET_WIPHY,
12537 .doit = nl80211_get_wiphy,
12538 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012539 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012540 .policy = nl80211_policy,
12541 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012542 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12543 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012544 },
12545 {
12546 .cmd = NL80211_CMD_SET_WIPHY,
12547 .doit = nl80211_set_wiphy,
12548 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012549 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012550 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012551 },
12552 {
12553 .cmd = NL80211_CMD_GET_INTERFACE,
12554 .doit = nl80211_get_interface,
12555 .dumpit = nl80211_dump_interface,
12556 .policy = nl80211_policy,
12557 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012558 .internal_flags = NL80211_FLAG_NEED_WDEV |
12559 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012560 },
12561 {
12562 .cmd = NL80211_CMD_SET_INTERFACE,
12563 .doit = nl80211_set_interface,
12564 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012565 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012566 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12567 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012568 },
12569 {
12570 .cmd = NL80211_CMD_NEW_INTERFACE,
12571 .doit = nl80211_new_interface,
12572 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012573 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012574 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12575 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012576 },
12577 {
12578 .cmd = NL80211_CMD_DEL_INTERFACE,
12579 .doit = nl80211_del_interface,
12580 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012581 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012582 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012583 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012584 },
Johannes Berg41ade002007-12-19 02:03:29 +010012585 {
12586 .cmd = NL80211_CMD_GET_KEY,
12587 .doit = nl80211_get_key,
12588 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012589 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012591 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012592 },
12593 {
12594 .cmd = NL80211_CMD_SET_KEY,
12595 .doit = nl80211_set_key,
12596 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012597 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012599 NL80211_FLAG_NEED_RTNL |
12600 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012601 },
12602 {
12603 .cmd = NL80211_CMD_NEW_KEY,
12604 .doit = nl80211_new_key,
12605 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012606 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012607 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012608 NL80211_FLAG_NEED_RTNL |
12609 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012610 },
12611 {
12612 .cmd = NL80211_CMD_DEL_KEY,
12613 .doit = nl80211_del_key,
12614 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012615 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012616 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012617 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012618 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012619 {
12620 .cmd = NL80211_CMD_SET_BEACON,
12621 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012622 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012623 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012625 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012626 },
12627 {
Johannes Berg88600202012-02-13 15:17:18 +010012628 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012629 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012630 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012631 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012632 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012633 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012634 },
12635 {
Johannes Berg88600202012-02-13 15:17:18 +010012636 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012637 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012638 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012639 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012641 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012642 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012643 {
12644 .cmd = NL80211_CMD_GET_STATION,
12645 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012646 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012647 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012648 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12649 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012650 },
12651 {
12652 .cmd = NL80211_CMD_SET_STATION,
12653 .doit = nl80211_set_station,
12654 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012655 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012656 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012657 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012658 },
12659 {
12660 .cmd = NL80211_CMD_NEW_STATION,
12661 .doit = nl80211_new_station,
12662 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012663 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012665 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012666 },
12667 {
12668 .cmd = NL80211_CMD_DEL_STATION,
12669 .doit = nl80211_del_station,
12670 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012671 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012673 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012674 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012675 {
12676 .cmd = NL80211_CMD_GET_MPATH,
12677 .doit = nl80211_get_mpath,
12678 .dumpit = nl80211_dump_mpath,
12679 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012680 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012681 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012682 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012683 },
12684 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012685 .cmd = NL80211_CMD_GET_MPP,
12686 .doit = nl80211_get_mpp,
12687 .dumpit = nl80211_dump_mpp,
12688 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012689 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12691 NL80211_FLAG_NEED_RTNL,
12692 },
12693 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012694 .cmd = NL80211_CMD_SET_MPATH,
12695 .doit = nl80211_set_mpath,
12696 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012697 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012699 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012700 },
12701 {
12702 .cmd = NL80211_CMD_NEW_MPATH,
12703 .doit = nl80211_new_mpath,
12704 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012705 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012707 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012708 },
12709 {
12710 .cmd = NL80211_CMD_DEL_MPATH,
12711 .doit = nl80211_del_mpath,
12712 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012713 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012715 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012716 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012717 {
12718 .cmd = NL80211_CMD_SET_BSS,
12719 .doit = nl80211_set_bss,
12720 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012721 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012723 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012724 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012725 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012726 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012727 .doit = nl80211_get_reg_do,
12728 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012729 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012730 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012731 /* can be retrieved by unprivileged users */
12732 },
Johannes Bergb6863032015-10-15 09:25:18 +020012733#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012734 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012735 .cmd = NL80211_CMD_SET_REG,
12736 .doit = nl80211_set_reg,
12737 .policy = nl80211_policy,
12738 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012739 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012740 },
Johannes Bergb6863032015-10-15 09:25:18 +020012741#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012742 {
12743 .cmd = NL80211_CMD_REQ_SET_REG,
12744 .doit = nl80211_req_set_reg,
12745 .policy = nl80211_policy,
12746 .flags = GENL_ADMIN_PERM,
12747 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012748 {
Johannes Berg1ea4ff32017-09-13 16:07:22 +020012749 .cmd = NL80211_CMD_RELOAD_REGDB,
12750 .doit = nl80211_reload_regdb,
12751 .policy = nl80211_policy,
12752 .flags = GENL_ADMIN_PERM,
12753 },
12754 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012755 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12756 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012757 .policy = nl80211_policy,
12758 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012760 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012761 },
12762 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012763 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12764 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012765 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012766 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012768 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012769 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012770 {
Johannes Berg2a519312009-02-10 21:25:55 +010012771 .cmd = NL80211_CMD_TRIGGER_SCAN,
12772 .doit = nl80211_trigger_scan,
12773 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012774 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012775 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012776 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012777 },
12778 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012779 .cmd = NL80211_CMD_ABORT_SCAN,
12780 .doit = nl80211_abort_scan,
12781 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012782 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012783 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12784 NL80211_FLAG_NEED_RTNL,
12785 },
12786 {
Johannes Berg2a519312009-02-10 21:25:55 +010012787 .cmd = NL80211_CMD_GET_SCAN,
12788 .policy = nl80211_policy,
12789 .dumpit = nl80211_dump_scan,
12790 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012791 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012792 .cmd = NL80211_CMD_START_SCHED_SCAN,
12793 .doit = nl80211_start_sched_scan,
12794 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012795 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12797 NL80211_FLAG_NEED_RTNL,
12798 },
12799 {
12800 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12801 .doit = nl80211_stop_sched_scan,
12802 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012803 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12805 NL80211_FLAG_NEED_RTNL,
12806 },
12807 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012808 .cmd = NL80211_CMD_AUTHENTICATE,
12809 .doit = nl80211_authenticate,
12810 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012811 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012813 NL80211_FLAG_NEED_RTNL |
12814 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012815 },
12816 {
12817 .cmd = NL80211_CMD_ASSOCIATE,
12818 .doit = nl80211_associate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012823 },
12824 {
12825 .cmd = NL80211_CMD_DEAUTHENTICATE,
12826 .doit = nl80211_deauthenticate,
12827 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012828 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012830 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012831 },
12832 {
12833 .cmd = NL80211_CMD_DISASSOCIATE,
12834 .doit = nl80211_disassociate,
12835 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012836 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012838 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012839 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012840 {
12841 .cmd = NL80211_CMD_JOIN_IBSS,
12842 .doit = nl80211_join_ibss,
12843 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012844 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012846 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012847 },
12848 {
12849 .cmd = NL80211_CMD_LEAVE_IBSS,
12850 .doit = nl80211_leave_ibss,
12851 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012852 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012854 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012855 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012856#ifdef CONFIG_NL80211_TESTMODE
12857 {
12858 .cmd = NL80211_CMD_TESTMODE,
12859 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012860 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012861 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012862 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012863 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12864 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012865 },
12866#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012867 {
12868 .cmd = NL80211_CMD_CONNECT,
12869 .doit = nl80211_connect,
12870 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012871 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012872 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012873 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012874 },
12875 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012876 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12877 .doit = nl80211_update_connect_params,
12878 .policy = nl80211_policy,
12879 .flags = GENL_ADMIN_PERM,
12880 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12881 NL80211_FLAG_NEED_RTNL,
12882 },
12883 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012884 .cmd = NL80211_CMD_DISCONNECT,
12885 .doit = nl80211_disconnect,
12886 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012887 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012889 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012890 },
Johannes Berg463d0182009-07-14 00:33:35 +020012891 {
12892 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12893 .doit = nl80211_wiphy_netns,
12894 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012895 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012896 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12897 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012898 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012899 {
12900 .cmd = NL80211_CMD_GET_SURVEY,
12901 .policy = nl80211_policy,
12902 .dumpit = nl80211_dump_survey,
12903 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012904 {
12905 .cmd = NL80211_CMD_SET_PMKSA,
12906 .doit = nl80211_setdel_pmksa,
12907 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012908 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012909 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012910 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012911 },
12912 {
12913 .cmd = NL80211_CMD_DEL_PMKSA,
12914 .doit = nl80211_setdel_pmksa,
12915 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012916 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012917 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012918 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012919 },
12920 {
12921 .cmd = NL80211_CMD_FLUSH_PMKSA,
12922 .doit = nl80211_flush_pmksa,
12923 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012924 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012926 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012927 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012928 {
12929 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12930 .doit = nl80211_remain_on_channel,
12931 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012932 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012933 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012934 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012935 },
12936 {
12937 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12938 .doit = nl80211_cancel_remain_on_channel,
12939 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012940 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012941 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012942 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012943 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012944 {
12945 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12946 .doit = nl80211_set_tx_bitrate_mask,
12947 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012948 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012949 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12950 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012951 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012952 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012953 .cmd = NL80211_CMD_REGISTER_FRAME,
12954 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012955 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012956 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012957 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012958 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012959 },
12960 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012961 .cmd = NL80211_CMD_FRAME,
12962 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012963 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012964 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012965 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012966 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012967 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012968 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012969 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12970 .doit = nl80211_tx_mgmt_cancel_wait,
12971 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012972 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012973 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012974 NL80211_FLAG_NEED_RTNL,
12975 },
12976 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012977 .cmd = NL80211_CMD_SET_POWER_SAVE,
12978 .doit = nl80211_set_power_save,
12979 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012980 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012981 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12982 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012983 },
12984 {
12985 .cmd = NL80211_CMD_GET_POWER_SAVE,
12986 .doit = nl80211_get_power_save,
12987 .policy = nl80211_policy,
12988 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012989 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12990 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012991 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012992 {
12993 .cmd = NL80211_CMD_SET_CQM,
12994 .doit = nl80211_set_cqm,
12995 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012996 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012997 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12998 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012999 },
Johannes Bergf444de02010-05-05 15:25:02 +020013000 {
13001 .cmd = NL80211_CMD_SET_CHANNEL,
13002 .doit = nl80211_set_channel,
13003 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013004 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020013005 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13006 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020013007 },
Bill Jordane8347eb2010-10-01 13:54:28 -040013008 {
13009 .cmd = NL80211_CMD_SET_WDS_PEER,
13010 .doit = nl80211_set_wds_peer,
13011 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013012 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020013013 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13014 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040013015 },
Johannes Berg29cbe682010-12-03 09:20:44 +010013016 {
13017 .cmd = NL80211_CMD_JOIN_MESH,
13018 .doit = nl80211_join_mesh,
13019 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013020 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13022 NL80211_FLAG_NEED_RTNL,
13023 },
13024 {
13025 .cmd = NL80211_CMD_LEAVE_MESH,
13026 .doit = nl80211_leave_mesh,
13027 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013028 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010013029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13030 NL80211_FLAG_NEED_RTNL,
13031 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013032 {
13033 .cmd = NL80211_CMD_JOIN_OCB,
13034 .doit = nl80211_join_ocb,
13035 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013036 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13038 NL80211_FLAG_NEED_RTNL,
13039 },
13040 {
13041 .cmd = NL80211_CMD_LEAVE_OCB,
13042 .doit = nl80211_leave_ocb,
13043 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013044 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010013045 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13046 NL80211_FLAG_NEED_RTNL,
13047 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013048#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013049 {
13050 .cmd = NL80211_CMD_GET_WOWLAN,
13051 .doit = nl80211_get_wowlan,
13052 .policy = nl80211_policy,
13053 /* can be retrieved by unprivileged users */
13054 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13055 NL80211_FLAG_NEED_RTNL,
13056 },
13057 {
13058 .cmd = NL80211_CMD_SET_WOWLAN,
13059 .doit = nl80211_set_wowlan,
13060 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013061 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013062 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13063 NL80211_FLAG_NEED_RTNL,
13064 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013065#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013066 {
13067 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13068 .doit = nl80211_set_rekey_data,
13069 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013070 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013072 NL80211_FLAG_NEED_RTNL |
13073 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013074 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013075 {
13076 .cmd = NL80211_CMD_TDLS_MGMT,
13077 .doit = nl80211_tdls_mgmt,
13078 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013079 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13081 NL80211_FLAG_NEED_RTNL,
13082 },
13083 {
13084 .cmd = NL80211_CMD_TDLS_OPER,
13085 .doit = nl80211_tdls_oper,
13086 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013087 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13089 NL80211_FLAG_NEED_RTNL,
13090 },
Johannes Berg28946da2011-11-04 11:18:12 +010013091 {
13092 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13093 .doit = nl80211_register_unexpected_frame,
13094 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013095 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013096 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13097 NL80211_FLAG_NEED_RTNL,
13098 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013099 {
13100 .cmd = NL80211_CMD_PROBE_CLIENT,
13101 .doit = nl80211_probe_client,
13102 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013103 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013105 NL80211_FLAG_NEED_RTNL,
13106 },
Johannes Berg5e760232011-11-04 11:18:17 +010013107 {
13108 .cmd = NL80211_CMD_REGISTER_BEACONS,
13109 .doit = nl80211_register_beacons,
13110 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013111 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013112 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13113 NL80211_FLAG_NEED_RTNL,
13114 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013115 {
13116 .cmd = NL80211_CMD_SET_NOACK_MAP,
13117 .doit = nl80211_set_noack_map,
13118 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013119 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013120 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13121 NL80211_FLAG_NEED_RTNL,
13122 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013123 {
13124 .cmd = NL80211_CMD_START_P2P_DEVICE,
13125 .doit = nl80211_start_p2p_device,
13126 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013127 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013128 .internal_flags = NL80211_FLAG_NEED_WDEV |
13129 NL80211_FLAG_NEED_RTNL,
13130 },
13131 {
13132 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13133 .doit = nl80211_stop_p2p_device,
13134 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013135 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013136 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13137 NL80211_FLAG_NEED_RTNL,
13138 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013139 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013140 .cmd = NL80211_CMD_START_NAN,
13141 .doit = nl80211_start_nan,
13142 .policy = nl80211_policy,
13143 .flags = GENL_ADMIN_PERM,
13144 .internal_flags = NL80211_FLAG_NEED_WDEV |
13145 NL80211_FLAG_NEED_RTNL,
13146 },
13147 {
13148 .cmd = NL80211_CMD_STOP_NAN,
13149 .doit = nl80211_stop_nan,
13150 .policy = nl80211_policy,
13151 .flags = GENL_ADMIN_PERM,
13152 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13153 NL80211_FLAG_NEED_RTNL,
13154 },
13155 {
Ayala Bekera442b762016-09-20 17:31:15 +030013156 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13157 .doit = nl80211_nan_add_func,
13158 .policy = nl80211_policy,
13159 .flags = GENL_ADMIN_PERM,
13160 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13161 NL80211_FLAG_NEED_RTNL,
13162 },
13163 {
13164 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13165 .doit = nl80211_nan_del_func,
13166 .policy = nl80211_policy,
13167 .flags = GENL_ADMIN_PERM,
13168 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13169 NL80211_FLAG_NEED_RTNL,
13170 },
13171 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013172 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13173 .doit = nl80211_nan_change_config,
13174 .policy = nl80211_policy,
13175 .flags = GENL_ADMIN_PERM,
13176 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13177 NL80211_FLAG_NEED_RTNL,
13178 },
13179 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013180 .cmd = NL80211_CMD_SET_MCAST_RATE,
13181 .doit = nl80211_set_mcast_rate,
13182 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013183 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013184 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13185 NL80211_FLAG_NEED_RTNL,
13186 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013187 {
13188 .cmd = NL80211_CMD_SET_MAC_ACL,
13189 .doit = nl80211_set_mac_acl,
13190 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013191 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013192 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13193 NL80211_FLAG_NEED_RTNL,
13194 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013195 {
13196 .cmd = NL80211_CMD_RADAR_DETECT,
13197 .doit = nl80211_start_radar_detection,
13198 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013199 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13201 NL80211_FLAG_NEED_RTNL,
13202 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013203 {
13204 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13205 .doit = nl80211_get_protocol_features,
13206 .policy = nl80211_policy,
13207 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013208 {
13209 .cmd = NL80211_CMD_UPDATE_FT_IES,
13210 .doit = nl80211_update_ft_ies,
13211 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013212 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13214 NL80211_FLAG_NEED_RTNL,
13215 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013216 {
13217 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13218 .doit = nl80211_crit_protocol_start,
13219 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013220 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013221 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13222 NL80211_FLAG_NEED_RTNL,
13223 },
13224 {
13225 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13226 .doit = nl80211_crit_protocol_stop,
13227 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013228 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013229 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13230 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013231 },
13232 {
13233 .cmd = NL80211_CMD_GET_COALESCE,
13234 .doit = nl80211_get_coalesce,
13235 .policy = nl80211_policy,
13236 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13237 NL80211_FLAG_NEED_RTNL,
13238 },
13239 {
13240 .cmd = NL80211_CMD_SET_COALESCE,
13241 .doit = nl80211_set_coalesce,
13242 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013243 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013244 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13245 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013246 },
13247 {
13248 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13249 .doit = nl80211_channel_switch,
13250 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013251 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13253 NL80211_FLAG_NEED_RTNL,
13254 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013255 {
13256 .cmd = NL80211_CMD_VENDOR,
13257 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013258 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013259 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013260 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013261 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13262 NL80211_FLAG_NEED_RTNL,
13263 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013264 {
13265 .cmd = NL80211_CMD_SET_QOS_MAP,
13266 .doit = nl80211_set_qos_map,
13267 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013268 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013269 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13270 NL80211_FLAG_NEED_RTNL,
13271 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013272 {
13273 .cmd = NL80211_CMD_ADD_TX_TS,
13274 .doit = nl80211_add_tx_ts,
13275 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013276 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013277 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13278 NL80211_FLAG_NEED_RTNL,
13279 },
13280 {
13281 .cmd = NL80211_CMD_DEL_TX_TS,
13282 .doit = nl80211_del_tx_ts,
13283 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013284 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013285 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13286 NL80211_FLAG_NEED_RTNL,
13287 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013288 {
13289 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13290 .doit = nl80211_tdls_channel_switch,
13291 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013292 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013293 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13294 NL80211_FLAG_NEED_RTNL,
13295 },
13296 {
13297 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13298 .doit = nl80211_tdls_cancel_channel_switch,
13299 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013300 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13302 NL80211_FLAG_NEED_RTNL,
13303 },
Michael Braunce0ce132016-10-10 19:12:22 +020013304 {
13305 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13306 .doit = nl80211_set_multicast_to_unicast,
13307 .policy = nl80211_policy,
13308 .flags = GENL_UNS_ADMIN_PERM,
13309 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13310 NL80211_FLAG_NEED_RTNL,
13311 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013312 {
13313 .cmd = NL80211_CMD_SET_PMK,
13314 .doit = nl80211_set_pmk,
13315 .policy = nl80211_policy,
13316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13317 NL80211_FLAG_NEED_RTNL,
13318 },
13319 {
13320 .cmd = NL80211_CMD_DEL_PMK,
13321 .doit = nl80211_del_pmk,
13322 .policy = nl80211_policy,
13323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13324 NL80211_FLAG_NEED_RTNL,
13325 },
13326
Johannes Berg55682962007-09-20 13:09:35 -040013327};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013328
Johannes Berg56989f62016-10-24 14:40:05 +020013329static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013330 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13331 .hdrsize = 0, /* no private header */
13332 .version = 1, /* no particular meaning now */
13333 .maxattr = NL80211_ATTR_MAX,
13334 .netnsok = true,
13335 .pre_doit = nl80211_pre_doit,
13336 .post_doit = nl80211_post_doit,
13337 .module = THIS_MODULE,
13338 .ops = nl80211_ops,
13339 .n_ops = ARRAY_SIZE(nl80211_ops),
13340 .mcgrps = nl80211_mcgrps,
13341 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13342};
13343
Johannes Berg55682962007-09-20 13:09:35 -040013344/* notification functions */
13345
Johannes Berg3bb20552014-05-26 13:52:25 +020013346void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13347 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013348{
13349 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013350 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013351
Johannes Berg3bb20552014-05-26 13:52:25 +020013352 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13353 cmd != NL80211_CMD_DEL_WIPHY);
13354
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013356 if (!msg)
13357 return;
13358
Johannes Berg3bb20552014-05-26 13:52:25 +020013359 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013360 nlmsg_free(msg);
13361 return;
13362 }
13363
Johannes Berg68eb5502013-11-19 15:19:38 +010013364 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013365 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013366}
13367
Denis Kenzior896ff062016-08-03 16:58:33 -050013368void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13369 struct wireless_dev *wdev,
13370 enum nl80211_commands cmd)
13371{
13372 struct sk_buff *msg;
13373
13374 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13375 cmd != NL80211_CMD_DEL_INTERFACE);
13376
13377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13378 if (!msg)
13379 return;
13380
13381 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13382 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13383 nlmsg_free(msg);
13384 return;
13385 }
13386
13387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13388 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13389}
13390
Johannes Berg362a4152009-05-24 16:43:15 +020013391static int nl80211_add_scan_req(struct sk_buff *msg,
13392 struct cfg80211_registered_device *rdev)
13393{
13394 struct cfg80211_scan_request *req = rdev->scan_req;
13395 struct nlattr *nest;
13396 int i;
13397
13398 if (WARN_ON(!req))
13399 return 0;
13400
13401 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13402 if (!nest)
13403 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013404 for (i = 0; i < req->n_ssids; i++) {
13405 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13406 goto nla_put_failure;
13407 }
Johannes Berg362a4152009-05-24 16:43:15 +020013408 nla_nest_end(msg, nest);
13409
13410 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13411 if (!nest)
13412 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013413 for (i = 0; i < req->n_channels; i++) {
13414 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13415 goto nla_put_failure;
13416 }
Johannes Berg362a4152009-05-24 16:43:15 +020013417 nla_nest_end(msg, nest);
13418
David S. Miller9360ffd2012-03-29 04:41:26 -040013419 if (req->ie &&
13420 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13421 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013422
Johannes Bergae917c92013-10-25 11:05:22 +020013423 if (req->flags &&
13424 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13425 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013426
Avraham Stern1d762502016-07-05 17:10:13 +030013427 if (req->info.scan_start_tsf &&
13428 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13429 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13430 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13431 req->info.tsf_bssid)))
13432 goto nla_put_failure;
13433
Johannes Berg362a4152009-05-24 16:43:15 +020013434 return 0;
13435 nla_put_failure:
13436 return -ENOBUFS;
13437}
13438
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013439static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013440 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013441 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013442 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013443 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013444{
13445 void *hdr;
13446
Eric W. Biederman15e47302012-09-07 20:12:54 +000013447 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013448 if (!hdr)
13449 return -1;
13450
David S. Miller9360ffd2012-03-29 04:41:26 -040013451 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013452 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13453 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013454 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13455 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013456 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013457
Johannes Berg362a4152009-05-24 16:43:15 +020013458 /* ignore errors and send incomplete event anyway */
13459 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013460
Johannes Berg053c0952015-01-16 22:09:00 +010013461 genlmsg_end(msg, hdr);
13462 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013463
13464 nla_put_failure:
13465 genlmsg_cancel(msg, hdr);
13466 return -EMSGSIZE;
13467}
13468
Luciano Coelho807f8a82011-05-11 17:09:35 +030013469static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013470nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013471 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013472{
13473 void *hdr;
13474
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013475 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013476 if (!hdr)
13477 return -1;
13478
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13480 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13481 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13482 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13483 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013484 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013485
Johannes Berg053c0952015-01-16 22:09:00 +010013486 genlmsg_end(msg, hdr);
13487 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013488
13489 nla_put_failure:
13490 genlmsg_cancel(msg, hdr);
13491 return -EMSGSIZE;
13492}
13493
Johannes Berga538e2d2009-06-16 19:56:42 +020013494void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013495 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013496{
13497 struct sk_buff *msg;
13498
Thomas Graf58050fc2012-06-28 03:57:45 +000013499 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013500 if (!msg)
13501 return;
13502
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013503 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013504 NL80211_CMD_TRIGGER_SCAN) < 0) {
13505 nlmsg_free(msg);
13506 return;
13507 }
13508
Johannes Berg68eb5502013-11-19 15:19:38 +010013509 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013510 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013511}
13512
Johannes Bergf9d15d12014-01-22 11:14:19 +020013513struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13514 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013515{
13516 struct sk_buff *msg;
13517
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013519 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013520 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013521
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013522 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013523 aborted ? NL80211_CMD_SCAN_ABORTED :
13524 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013525 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013526 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013527 }
13528
Johannes Bergf9d15d12014-01-22 11:14:19 +020013529 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013530}
13531
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013532/* send message created by nl80211_build_scan_msg() */
13533void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13534 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013535{
Johannes Berg2a519312009-02-10 21:25:55 +010013536 if (!msg)
13537 return;
13538
Johannes Berg68eb5502013-11-19 15:19:38 +010013539 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013540 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013541}
13542
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013543void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013544{
13545 struct sk_buff *msg;
13546
Thomas Graf58050fc2012-06-28 03:57:45 +000013547 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013548 if (!msg)
13549 return;
13550
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013551 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013552 nlmsg_free(msg);
13553 return;
13554 }
13555
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013556 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013557 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013558}
13559
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013560static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13561 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013562{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013563 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013564 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13565 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013566
David S. Miller9360ffd2012-03-29 04:41:26 -040013567 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13568 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13569 NL80211_REGDOM_TYPE_WORLD))
13570 goto nla_put_failure;
13571 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13572 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13573 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13574 goto nla_put_failure;
13575 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13576 request->intersect) {
13577 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13578 NL80211_REGDOM_TYPE_INTERSECTION))
13579 goto nla_put_failure;
13580 } else {
13581 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13582 NL80211_REGDOM_TYPE_COUNTRY) ||
13583 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13584 request->alpha2))
13585 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013586 }
13587
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013588 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13589 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13590
13591 if (wiphy &&
13592 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13593 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013594
13595 if (wiphy &&
13596 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13597 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13598 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013599 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013600
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013601 return true;
13602
13603nla_put_failure:
13604 return false;
13605}
13606
13607/*
13608 * This can happen on global regulatory changes or device specific settings
13609 * based on custom regulatory domains.
13610 */
13611void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13612 struct regulatory_request *request)
13613{
13614 struct sk_buff *msg;
13615 void *hdr;
13616
13617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13618 if (!msg)
13619 return;
13620
13621 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13622 if (!hdr) {
13623 nlmsg_free(msg);
13624 return;
13625 }
13626
13627 if (nl80211_reg_change_event_fill(msg, request) == false)
13628 goto nla_put_failure;
13629
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013630 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013631
Johannes Bergbc43b282009-07-25 10:54:13 +020013632 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013633 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013634 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013635 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013636
13637 return;
13638
13639nla_put_failure:
13640 genlmsg_cancel(msg, hdr);
13641 nlmsg_free(msg);
13642}
13643
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013644static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13645 struct net_device *netdev,
13646 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013647 enum nl80211_commands cmd, gfp_t gfp,
13648 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013649{
13650 struct sk_buff *msg;
13651 void *hdr;
13652
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013653 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013654 if (!msg)
13655 return;
13656
13657 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13658 if (!hdr) {
13659 nlmsg_free(msg);
13660 return;
13661 }
13662
David S. Miller9360ffd2012-03-29 04:41:26 -040013663 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13664 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13665 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13666 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013667
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013668 if (uapsd_queues >= 0) {
13669 struct nlattr *nla_wmm =
13670 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13671 if (!nla_wmm)
13672 goto nla_put_failure;
13673
13674 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13675 uapsd_queues))
13676 goto nla_put_failure;
13677
13678 nla_nest_end(msg, nla_wmm);
13679 }
13680
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013681 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013682
Johannes Berg68eb5502013-11-19 15:19:38 +010013683 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013684 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013685 return;
13686
13687 nla_put_failure:
13688 genlmsg_cancel(msg, hdr);
13689 nlmsg_free(msg);
13690}
13691
13692void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013693 struct net_device *netdev, const u8 *buf,
13694 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013695{
13696 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013697 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013698}
13699
13700void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13701 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013702 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013703{
Johannes Berge6d6e342009-07-01 21:26:47 +020013704 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013705 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013706}
13707
Jouni Malinen53b46b82009-03-27 20:53:56 +020013708void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013709 struct net_device *netdev, const u8 *buf,
13710 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013711{
13712 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013713 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013714}
13715
Jouni Malinen53b46b82009-03-27 20:53:56 +020013716void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13717 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013718 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013719{
13720 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013721 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013722}
13723
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013724void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13725 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013726{
Johannes Berg947add32013-02-22 22:05:20 +010013727 struct wireless_dev *wdev = dev->ieee80211_ptr;
13728 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013729 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013730 const struct ieee80211_mgmt *mgmt = (void *)buf;
13731 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013732
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013733 if (WARN_ON(len < 2))
13734 return;
13735
13736 if (ieee80211_is_deauth(mgmt->frame_control))
13737 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13738 else
13739 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13740
13741 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013742 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013743}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013744EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013745
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013746static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13747 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013748 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013749{
13750 struct sk_buff *msg;
13751 void *hdr;
13752
Johannes Berge6d6e342009-07-01 21:26:47 +020013753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013754 if (!msg)
13755 return;
13756
13757 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13758 if (!hdr) {
13759 nlmsg_free(msg);
13760 return;
13761 }
13762
David S. Miller9360ffd2012-03-29 04:41:26 -040013763 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13764 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13765 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13766 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13767 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013768
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013769 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013770
Johannes Berg68eb5502013-11-19 15:19:38 +010013771 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013772 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013773 return;
13774
13775 nla_put_failure:
13776 genlmsg_cancel(msg, hdr);
13777 nlmsg_free(msg);
13778}
13779
13780void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013781 struct net_device *netdev, const u8 *addr,
13782 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013783{
13784 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013785 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013786}
13787
13788void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013789 struct net_device *netdev, const u8 *addr,
13790 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013791{
Johannes Berge6d6e342009-07-01 21:26:47 +020013792 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13793 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013794}
13795
Samuel Ortizb23aa672009-07-01 21:26:54 +020013796void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013797 struct net_device *netdev,
13798 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013799 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013800{
13801 struct sk_buff *msg;
13802 void *hdr;
13803
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013804 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13805 cr->fils_kek_len + cr->pmk_len +
13806 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013807 if (!msg)
13808 return;
13809
13810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13811 if (!hdr) {
13812 nlmsg_free(msg);
13813 return;
13814 }
13815
David S. Miller9360ffd2012-03-29 04:41:26 -040013816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013818 (cr->bssid &&
13819 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013820 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013821 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13822 cr->status) ||
13823 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013824 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013825 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13826 cr->timeout_reason))) ||
13827 (cr->req_ie &&
13828 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13829 (cr->resp_ie &&
13830 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013831 cr->resp_ie)) ||
13832 (cr->update_erp_next_seq_num &&
13833 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13834 cr->fils_erp_next_seq_num)) ||
13835 (cr->status == WLAN_STATUS_SUCCESS &&
13836 ((cr->fils_kek &&
13837 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13838 cr->fils_kek)) ||
13839 (cr->pmk &&
13840 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13841 (cr->pmkid &&
13842 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013843 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013844
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013845 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013846
Johannes Berg68eb5502013-11-19 15:19:38 +010013847 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013848 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013849 return;
13850
13851 nla_put_failure:
13852 genlmsg_cancel(msg, hdr);
13853 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013854}
13855
13856void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013857 struct net_device *netdev,
13858 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013859{
13860 struct sk_buff *msg;
13861 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013862 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013863
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013864 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013865 if (!msg)
13866 return;
13867
13868 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13869 if (!hdr) {
13870 nlmsg_free(msg);
13871 return;
13872 }
13873
David S. Miller9360ffd2012-03-29 04:41:26 -040013874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13875 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13876 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013877 (info->req_ie &&
13878 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13879 info->req_ie)) ||
13880 (info->resp_ie &&
13881 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern503c1fb2017-09-29 14:21:49 +020013882 info->resp_ie)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013883 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013884
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013885 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013886
Johannes Berg68eb5502013-11-19 15:19:38 +010013887 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013888 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013889 return;
13890
13891 nla_put_failure:
13892 genlmsg_cancel(msg, hdr);
13893 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013894}
13895
Avraham Stern503c1fb2017-09-29 14:21:49 +020013896void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
13897 struct net_device *netdev, const u8 *bssid)
13898{
13899 struct sk_buff *msg;
13900 void *hdr;
13901
13902 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13903 if (!msg)
13904 return;
13905
13906 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
13907 if (!hdr) {
13908 nlmsg_free(msg);
13909 return;
13910 }
13911
13912 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13913 goto nla_put_failure;
13914
13915 genlmsg_end(msg, hdr);
13916
13917 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13918 NL80211_MCGRP_MLME, GFP_KERNEL);
13919 return;
13920
13921 nla_put_failure:
13922 genlmsg_cancel(msg, hdr);
13923 nlmsg_free(msg);
13924}
13925
Samuel Ortizb23aa672009-07-01 21:26:54 +020013926void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13927 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013928 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013929{
13930 struct sk_buff *msg;
13931 void *hdr;
13932
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013933 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013934 if (!msg)
13935 return;
13936
13937 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13938 if (!hdr) {
13939 nlmsg_free(msg);
13940 return;
13941 }
13942
David S. Miller9360ffd2012-03-29 04:41:26 -040013943 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13944 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13945 (from_ap && reason &&
13946 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13947 (from_ap &&
13948 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13949 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13950 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013951
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013952 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013953
Johannes Berg68eb5502013-11-19 15:19:38 +010013954 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013955 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013956 return;
13957
13958 nla_put_failure:
13959 genlmsg_cancel(msg, hdr);
13960 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013961}
13962
Johannes Berg04a773a2009-04-19 21:24:32 +020013963void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13964 struct net_device *netdev, const u8 *bssid,
13965 gfp_t gfp)
13966{
13967 struct sk_buff *msg;
13968 void *hdr;
13969
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013970 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013971 if (!msg)
13972 return;
13973
13974 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13975 if (!hdr) {
13976 nlmsg_free(msg);
13977 return;
13978 }
13979
David S. Miller9360ffd2012-03-29 04:41:26 -040013980 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13981 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13982 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13983 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013984
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013985 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013986
Johannes Berg68eb5502013-11-19 15:19:38 +010013987 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013988 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013989 return;
13990
13991 nla_put_failure:
13992 genlmsg_cancel(msg, hdr);
13993 nlmsg_free(msg);
13994}
13995
Johannes Berg947add32013-02-22 22:05:20 +010013996void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13997 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013998{
Johannes Berg947add32013-02-22 22:05:20 +010013999 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014000 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014001 struct sk_buff *msg;
14002 void *hdr;
14003
Johannes Berg947add32013-02-22 22:05:20 +010014004 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
14005 return;
14006
14007 trace_cfg80211_notify_new_peer_candidate(dev, addr);
14008
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014009 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014010 if (!msg)
14011 return;
14012
14013 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
14014 if (!hdr) {
14015 nlmsg_free(msg);
14016 return;
14017 }
14018
David S. Miller9360ffd2012-03-29 04:41:26 -040014019 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014020 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14021 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014022 (ie_len && ie &&
14023 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14024 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070014025
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014026 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014027
Johannes Berg68eb5502013-11-19 15:19:38 +010014028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014029 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014030 return;
14031
14032 nla_put_failure:
14033 genlmsg_cancel(msg, hdr);
14034 nlmsg_free(msg);
14035}
Johannes Berg947add32013-02-22 22:05:20 +010014036EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070014037
Jouni Malinena3b8b052009-03-27 21:59:49 +020014038void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14039 struct net_device *netdev, const u8 *addr,
14040 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020014041 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020014042{
14043 struct sk_buff *msg;
14044 void *hdr;
14045
Johannes Berge6d6e342009-07-01 21:26:47 +020014046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014047 if (!msg)
14048 return;
14049
14050 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14051 if (!hdr) {
14052 nlmsg_free(msg);
14053 return;
14054 }
14055
David S. Miller9360ffd2012-03-29 04:41:26 -040014056 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14057 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14058 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14059 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14060 (key_id != -1 &&
14061 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14062 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14063 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014064
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014065 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014066
Johannes Berg68eb5502013-11-19 15:19:38 +010014067 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014068 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014069 return;
14070
14071 nla_put_failure:
14072 genlmsg_cancel(msg, hdr);
14073 nlmsg_free(msg);
14074}
14075
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014076void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14077 struct ieee80211_channel *channel_before,
14078 struct ieee80211_channel *channel_after)
14079{
14080 struct sk_buff *msg;
14081 void *hdr;
14082 struct nlattr *nl_freq;
14083
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014084 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014085 if (!msg)
14086 return;
14087
14088 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14089 if (!hdr) {
14090 nlmsg_free(msg);
14091 return;
14092 }
14093
14094 /*
14095 * Since we are applying the beacon hint to a wiphy we know its
14096 * wiphy_idx is valid
14097 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014098 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14099 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014100
14101 /* Before */
14102 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14103 if (!nl_freq)
14104 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014105 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014106 goto nla_put_failure;
14107 nla_nest_end(msg, nl_freq);
14108
14109 /* After */
14110 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14111 if (!nl_freq)
14112 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014113 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014114 goto nla_put_failure;
14115 nla_nest_end(msg, nl_freq);
14116
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014117 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014118
Johannes Berg463d0182009-07-14 00:33:35 +020014119 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014120 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014121 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014122 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014123
14124 return;
14125
14126nla_put_failure:
14127 genlmsg_cancel(msg, hdr);
14128 nlmsg_free(msg);
14129}
14130
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014131static void nl80211_send_remain_on_chan_event(
14132 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014133 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014134 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014135 unsigned int duration, gfp_t gfp)
14136{
14137 struct sk_buff *msg;
14138 void *hdr;
14139
14140 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14141 if (!msg)
14142 return;
14143
14144 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14145 if (!hdr) {
14146 nlmsg_free(msg);
14147 return;
14148 }
14149
David S. Miller9360ffd2012-03-29 04:41:26 -040014150 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014151 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14152 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014153 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14154 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014156 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14157 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014158 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14159 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014160 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014161
David S. Miller9360ffd2012-03-29 04:41:26 -040014162 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14163 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14164 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014165
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014166 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014167
Johannes Berg68eb5502013-11-19 15:19:38 +010014168 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014169 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014170 return;
14171
14172 nla_put_failure:
14173 genlmsg_cancel(msg, hdr);
14174 nlmsg_free(msg);
14175}
14176
Johannes Berg947add32013-02-22 22:05:20 +010014177void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14178 struct ieee80211_channel *chan,
14179 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014180{
Johannes Berg947add32013-02-22 22:05:20 +010014181 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014182 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014183
14184 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014185 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014186 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014187 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014188}
Johannes Berg947add32013-02-22 22:05:20 +010014189EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014190
Johannes Berg947add32013-02-22 22:05:20 +010014191void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14192 struct ieee80211_channel *chan,
14193 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014194{
Johannes Berg947add32013-02-22 22:05:20 +010014195 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014196 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014197
14198 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014199 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014200 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014201}
Johannes Berg947add32013-02-22 22:05:20 +010014202EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014203
Johannes Berg947add32013-02-22 22:05:20 +010014204void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14205 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014206{
Johannes Berg947add32013-02-22 22:05:20 +010014207 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014208 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014209 struct sk_buff *msg;
14210
Johannes Berg947add32013-02-22 22:05:20 +010014211 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14212
Thomas Graf58050fc2012-06-28 03:57:45 +000014213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014214 if (!msg)
14215 return;
14216
Johannes Bergcf5ead82014-11-14 17:14:00 +010014217 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014218 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014219 nlmsg_free(msg);
14220 return;
14221 }
14222
Johannes Berg68eb5502013-11-19 15:19:38 +010014223 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014224 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014225}
Johannes Berg947add32013-02-22 22:05:20 +010014226EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014227
Johannes Bergcf5ead82014-11-14 17:14:00 +010014228void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14229 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014230{
Johannes Berg947add32013-02-22 22:05:20 +010014231 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014233 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014234 struct station_info empty_sinfo = {};
14235
14236 if (!sinfo)
14237 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014238
Johannes Berg947add32013-02-22 22:05:20 +010014239 trace_cfg80211_del_sta(dev, mac_addr);
14240
Thomas Graf58050fc2012-06-28 03:57:45 +000014241 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014242 if (!msg)
14243 return;
14244
Johannes Bergcf5ead82014-11-14 17:14:00 +010014245 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014246 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014247 nlmsg_free(msg);
14248 return;
14249 }
14250
Johannes Berg68eb5502013-11-19 15:19:38 +010014251 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014252 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014253}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014254EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014255
Johannes Berg947add32013-02-22 22:05:20 +010014256void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14257 enum nl80211_connect_failed_reason reason,
14258 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014259{
Johannes Berg947add32013-02-22 22:05:20 +010014260 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014261 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014262 struct sk_buff *msg;
14263 void *hdr;
14264
14265 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14266 if (!msg)
14267 return;
14268
14269 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14270 if (!hdr) {
14271 nlmsg_free(msg);
14272 return;
14273 }
14274
14275 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14276 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14277 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14278 goto nla_put_failure;
14279
14280 genlmsg_end(msg, hdr);
14281
Johannes Berg68eb5502013-11-19 15:19:38 +010014282 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014283 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014284 return;
14285
14286 nla_put_failure:
14287 genlmsg_cancel(msg, hdr);
14288 nlmsg_free(msg);
14289}
Johannes Berg947add32013-02-22 22:05:20 +010014290EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014291
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014292static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14293 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014294{
14295 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014296 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014297 struct sk_buff *msg;
14298 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070014299 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014300
Eric W. Biederman15e47302012-09-07 20:12:54 +000014301 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014302 return false;
14303
14304 msg = nlmsg_new(100, gfp);
14305 if (!msg)
14306 return true;
14307
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014308 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014309 if (!hdr) {
14310 nlmsg_free(msg);
14311 return true;
14312 }
14313
David S. Miller9360ffd2012-03-29 04:41:26 -040014314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14316 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14317 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014318
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014319 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014320 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014321 return true;
14322
14323 nla_put_failure:
14324 genlmsg_cancel(msg, hdr);
14325 nlmsg_free(msg);
14326 return true;
14327}
14328
Johannes Berg947add32013-02-22 22:05:20 +010014329bool cfg80211_rx_spurious_frame(struct net_device *dev,
14330 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014331{
Johannes Berg947add32013-02-22 22:05:20 +010014332 struct wireless_dev *wdev = dev->ieee80211_ptr;
14333 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014334
Johannes Berg947add32013-02-22 22:05:20 +010014335 trace_cfg80211_rx_spurious_frame(dev, addr);
14336
14337 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14338 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14339 trace_cfg80211_return_bool(false);
14340 return false;
14341 }
14342 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14343 addr, gfp);
14344 trace_cfg80211_return_bool(ret);
14345 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014346}
Johannes Berg947add32013-02-22 22:05:20 +010014347EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14348
14349bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14350 const u8 *addr, gfp_t gfp)
14351{
14352 struct wireless_dev *wdev = dev->ieee80211_ptr;
14353 bool ret;
14354
14355 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14356
14357 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14358 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14359 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14360 trace_cfg80211_return_bool(false);
14361 return false;
14362 }
14363 ret = __nl80211_unexpected_frame(dev,
14364 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14365 addr, gfp);
14366 trace_cfg80211_return_bool(ret);
14367 return ret;
14368}
14369EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014370
Johannes Berg2e161f72010-08-12 15:38:38 +020014371int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014372 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014373 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014374 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014375{
Johannes Berg71bbc992012-06-15 15:30:18 +020014376 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014377 struct sk_buff *msg;
14378 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014379
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014380 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014381 if (!msg)
14382 return -ENOMEM;
14383
Johannes Berg2e161f72010-08-12 15:38:38 +020014384 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014385 if (!hdr) {
14386 nlmsg_free(msg);
14387 return -ENOMEM;
14388 }
14389
David S. Miller9360ffd2012-03-29 04:41:26 -040014390 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014391 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14392 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014393 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14394 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014395 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14396 (sig_dbm &&
14397 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014398 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14399 (flags &&
14400 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014401 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014402
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014403 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014404
Eric W. Biederman15e47302012-09-07 20:12:54 +000014405 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014406
14407 nla_put_failure:
14408 genlmsg_cancel(msg, hdr);
14409 nlmsg_free(msg);
14410 return -ENOBUFS;
14411}
14412
Johannes Berg947add32013-02-22 22:05:20 +010014413void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14414 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014415{
Johannes Berg947add32013-02-22 22:05:20 +010014416 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014417 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014418 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014419 struct sk_buff *msg;
14420 void *hdr;
14421
Johannes Berg947add32013-02-22 22:05:20 +010014422 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14423
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014424 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014425 if (!msg)
14426 return;
14427
Johannes Berg2e161f72010-08-12 15:38:38 +020014428 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014429 if (!hdr) {
14430 nlmsg_free(msg);
14431 return;
14432 }
14433
David S. Miller9360ffd2012-03-29 04:41:26 -040014434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014435 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14436 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014437 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14438 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014439 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014440 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14441 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014442 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14443 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014444
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014445 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014446
Johannes Berg68eb5502013-11-19 15:19:38 +010014447 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014448 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014449 return;
14450
14451 nla_put_failure:
14452 genlmsg_cancel(msg, hdr);
14453 nlmsg_free(msg);
14454}
Johannes Berg947add32013-02-22 22:05:20 +010014455EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014456
Johannes Berg5b97f492014-11-26 12:37:43 +010014457static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14458 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014459{
Johannes Berg947add32013-02-22 22:05:20 +010014460 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014461 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14462 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14463 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014464
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014465 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014466 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014467
Johannes Berg5b97f492014-11-26 12:37:43 +010014468 cb = (void **)msg->cb;
14469
14470 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14471 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014472 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014473 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014474 }
14475
David S. Miller9360ffd2012-03-29 04:41:26 -040014476 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014478 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014479
Johannes Berg5b97f492014-11-26 12:37:43 +010014480 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014481 goto nla_put_failure;
14482
Johannes Berg5b97f492014-11-26 12:37:43 +010014483 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14484 if (!cb[1])
14485 goto nla_put_failure;
14486
14487 cb[2] = rdev;
14488
14489 return msg;
14490 nla_put_failure:
14491 nlmsg_free(msg);
14492 return NULL;
14493}
14494
14495static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14496{
14497 void **cb = (void **)msg->cb;
14498 struct cfg80211_registered_device *rdev = cb[2];
14499
14500 nla_nest_end(msg, cb[1]);
14501 genlmsg_end(msg, cb[0]);
14502
14503 memset(msg->cb, 0, sizeof(msg->cb));
14504
14505 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14506 NL80211_MCGRP_MLME, gfp);
14507}
14508
14509void cfg80211_cqm_rssi_notify(struct net_device *dev,
14510 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014511 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014512{
14513 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014514 struct wireless_dev *wdev = dev->ieee80211_ptr;
14515 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014516
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014517 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014518
Johannes Berg98f03342014-11-26 12:42:02 +010014519 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14520 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14521 return;
14522
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014523 if (wdev->cqm_config) {
14524 wdev->cqm_config->last_rssi_event_value = rssi_level;
14525
14526 cfg80211_cqm_rssi_update(rdev, dev);
14527
14528 if (rssi_level == 0)
14529 rssi_level = wdev->cqm_config->last_rssi_event_value;
14530 }
14531
Johannes Berg5b97f492014-11-26 12:37:43 +010014532 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14533 if (!msg)
14534 return;
14535
David S. Miller9360ffd2012-03-29 04:41:26 -040014536 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14537 rssi_event))
14538 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014539
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014540 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14541 rssi_level))
14542 goto nla_put_failure;
14543
Johannes Berg5b97f492014-11-26 12:37:43 +010014544 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014545
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014546 return;
14547
14548 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014549 nlmsg_free(msg);
14550}
Johannes Berg947add32013-02-22 22:05:20 +010014551EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014552
Johannes Berg5b97f492014-11-26 12:37:43 +010014553void cfg80211_cqm_txe_notify(struct net_device *dev,
14554 const u8 *peer, u32 num_packets,
14555 u32 rate, u32 intvl, gfp_t gfp)
14556{
14557 struct sk_buff *msg;
14558
14559 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14560 if (!msg)
14561 return;
14562
14563 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14564 goto nla_put_failure;
14565
14566 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14567 goto nla_put_failure;
14568
14569 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14570 goto nla_put_failure;
14571
14572 cfg80211_send_cqm(msg, gfp);
14573 return;
14574
14575 nla_put_failure:
14576 nlmsg_free(msg);
14577}
14578EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14579
14580void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14581 const u8 *peer, u32 num_packets, gfp_t gfp)
14582{
14583 struct sk_buff *msg;
14584
14585 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14586
14587 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14588 if (!msg)
14589 return;
14590
14591 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14592 goto nla_put_failure;
14593
14594 cfg80211_send_cqm(msg, gfp);
14595 return;
14596
14597 nla_put_failure:
14598 nlmsg_free(msg);
14599}
14600EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14601
Johannes Berg98f03342014-11-26 12:42:02 +010014602void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14603{
14604 struct sk_buff *msg;
14605
14606 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14607 if (!msg)
14608 return;
14609
14610 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14611 goto nla_put_failure;
14612
14613 cfg80211_send_cqm(msg, gfp);
14614 return;
14615
14616 nla_put_failure:
14617 nlmsg_free(msg);
14618}
14619EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14620
Johannes Berg947add32013-02-22 22:05:20 +010014621static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14622 struct net_device *netdev, const u8 *bssid,
14623 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014624{
14625 struct sk_buff *msg;
14626 struct nlattr *rekey_attr;
14627 void *hdr;
14628
Thomas Graf58050fc2012-06-28 03:57:45 +000014629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014630 if (!msg)
14631 return;
14632
14633 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14634 if (!hdr) {
14635 nlmsg_free(msg);
14636 return;
14637 }
14638
David S. Miller9360ffd2012-03-29 04:41:26 -040014639 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14641 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14642 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014643
14644 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14645 if (!rekey_attr)
14646 goto nla_put_failure;
14647
David S. Miller9360ffd2012-03-29 04:41:26 -040014648 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14649 NL80211_REPLAY_CTR_LEN, replay_ctr))
14650 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014651
14652 nla_nest_end(msg, rekey_attr);
14653
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014654 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014655
Johannes Berg68eb5502013-11-19 15:19:38 +010014656 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014657 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014658 return;
14659
14660 nla_put_failure:
14661 genlmsg_cancel(msg, hdr);
14662 nlmsg_free(msg);
14663}
14664
Johannes Berg947add32013-02-22 22:05:20 +010014665void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14666 const u8 *replay_ctr, gfp_t gfp)
14667{
14668 struct wireless_dev *wdev = dev->ieee80211_ptr;
14669 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014670 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014671
14672 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14673 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14674}
14675EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14676
14677static void
14678nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14679 struct net_device *netdev, int index,
14680 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014681{
14682 struct sk_buff *msg;
14683 struct nlattr *attr;
14684 void *hdr;
14685
Thomas Graf58050fc2012-06-28 03:57:45 +000014686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014687 if (!msg)
14688 return;
14689
14690 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14691 if (!hdr) {
14692 nlmsg_free(msg);
14693 return;
14694 }
14695
David S. Miller9360ffd2012-03-29 04:41:26 -040014696 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14698 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014699
14700 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14701 if (!attr)
14702 goto nla_put_failure;
14703
David S. Miller9360ffd2012-03-29 04:41:26 -040014704 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14705 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14706 (preauth &&
14707 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14708 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014709
14710 nla_nest_end(msg, attr);
14711
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014712 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014713
Johannes Berg68eb5502013-11-19 15:19:38 +010014714 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014715 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014716 return;
14717
14718 nla_put_failure:
14719 genlmsg_cancel(msg, hdr);
14720 nlmsg_free(msg);
14721}
14722
Johannes Berg947add32013-02-22 22:05:20 +010014723void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14724 const u8 *bssid, bool preauth, gfp_t gfp)
14725{
14726 struct wireless_dev *wdev = dev->ieee80211_ptr;
14727 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014728 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014729
14730 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14731 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14732}
14733EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14734
14735static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14736 struct net_device *netdev,
14737 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014738 gfp_t gfp,
14739 enum nl80211_commands notif,
14740 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014741{
14742 struct sk_buff *msg;
14743 void *hdr;
14744
Thomas Graf58050fc2012-06-28 03:57:45 +000014745 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014746 if (!msg)
14747 return;
14748
Luciano Coelhof8d75522014-11-07 14:31:35 +020014749 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014750 if (!hdr) {
14751 nlmsg_free(msg);
14752 return;
14753 }
14754
Johannes Berg683b6d32012-11-08 21:25:48 +010014755 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14756 goto nla_put_failure;
14757
14758 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014759 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014760
Luciano Coelhof8d75522014-11-07 14:31:35 +020014761 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14762 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14763 goto nla_put_failure;
14764
Thomas Pedersen53145262012-04-06 13:35:47 -070014765 genlmsg_end(msg, hdr);
14766
Johannes Berg68eb5502013-11-19 15:19:38 +010014767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014768 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014769 return;
14770
14771 nla_put_failure:
14772 genlmsg_cancel(msg, hdr);
14773 nlmsg_free(msg);
14774}
14775
Johannes Berg947add32013-02-22 22:05:20 +010014776void cfg80211_ch_switch_notify(struct net_device *dev,
14777 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014778{
Johannes Berg947add32013-02-22 22:05:20 +010014779 struct wireless_dev *wdev = dev->ieee80211_ptr;
14780 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014781 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014782
Simon Wunderliche487eae2013-11-21 18:19:51 +010014783 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014784
Simon Wunderliche487eae2013-11-21 18:19:51 +010014785 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014786
Michal Kazior9e0e2962014-01-29 14:22:27 +010014787 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014788 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014789 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14790 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014791}
14792EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14793
Luciano Coelhof8d75522014-11-07 14:31:35 +020014794void cfg80211_ch_switch_started_notify(struct net_device *dev,
14795 struct cfg80211_chan_def *chandef,
14796 u8 count)
14797{
14798 struct wireless_dev *wdev = dev->ieee80211_ptr;
14799 struct wiphy *wiphy = wdev->wiphy;
14800 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14801
14802 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14803
14804 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14805 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14806}
14807EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14808
Thomas Pedersen84f10702012-07-12 16:17:33 -070014809void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014810nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014811 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014812 enum nl80211_radar_event event,
14813 struct net_device *netdev, gfp_t gfp)
14814{
14815 struct sk_buff *msg;
14816 void *hdr;
14817
14818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14819 if (!msg)
14820 return;
14821
14822 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14823 if (!hdr) {
14824 nlmsg_free(msg);
14825 return;
14826 }
14827
14828 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14829 goto nla_put_failure;
14830
14831 /* NOP and radar events don't need a netdev parameter */
14832 if (netdev) {
14833 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14834
14835 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014836 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14837 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014838 goto nla_put_failure;
14839 }
14840
14841 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14842 goto nla_put_failure;
14843
14844 if (nl80211_send_chandef(msg, chandef))
14845 goto nla_put_failure;
14846
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014847 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014848
Johannes Berg68eb5502013-11-19 15:19:38 +010014849 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014850 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014851 return;
14852
14853 nla_put_failure:
14854 genlmsg_cancel(msg, hdr);
14855 nlmsg_free(msg);
14856}
14857
Johannes Berg7f6cf312011-11-04 11:18:15 +010014858void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14859 u64 cookie, bool acked, gfp_t gfp)
14860{
14861 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014862 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014863 struct sk_buff *msg;
14864 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014865
Beni Lev4ee3e062012-08-27 12:49:39 +030014866 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14867
Thomas Graf58050fc2012-06-28 03:57:45 +000014868 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014869
Johannes Berg7f6cf312011-11-04 11:18:15 +010014870 if (!msg)
14871 return;
14872
14873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14874 if (!hdr) {
14875 nlmsg_free(msg);
14876 return;
14877 }
14878
David S. Miller9360ffd2012-03-29 04:41:26 -040014879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14880 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14881 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014882 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14883 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014884 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14885 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014886
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014887 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014888
Johannes Berg68eb5502013-11-19 15:19:38 +010014889 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014890 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014891 return;
14892
14893 nla_put_failure:
14894 genlmsg_cancel(msg, hdr);
14895 nlmsg_free(msg);
14896}
14897EXPORT_SYMBOL(cfg80211_probe_status);
14898
Johannes Berg5e760232011-11-04 11:18:17 +010014899void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14900 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014901 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014902{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014903 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014904 struct sk_buff *msg;
14905 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014906 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014907
Beni Lev4ee3e062012-08-27 12:49:39 +030014908 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14909
Ben Greear37c73b52012-10-26 14:49:25 -070014910 spin_lock_bh(&rdev->beacon_registrations_lock);
14911 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14912 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14913 if (!msg) {
14914 spin_unlock_bh(&rdev->beacon_registrations_lock);
14915 return;
14916 }
Johannes Berg5e760232011-11-04 11:18:17 +010014917
Ben Greear37c73b52012-10-26 14:49:25 -070014918 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14919 if (!hdr)
14920 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014921
Ben Greear37c73b52012-10-26 14:49:25 -070014922 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14923 (freq &&
14924 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14925 (sig_dbm &&
14926 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14927 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14928 goto nla_put_failure;
14929
14930 genlmsg_end(msg, hdr);
14931
14932 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014933 }
Ben Greear37c73b52012-10-26 14:49:25 -070014934 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014935 return;
14936
14937 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014938 spin_unlock_bh(&rdev->beacon_registrations_lock);
14939 if (hdr)
14940 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014941 nlmsg_free(msg);
14942}
14943EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14944
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014945#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014946static int cfg80211_net_detect_results(struct sk_buff *msg,
14947 struct cfg80211_wowlan_wakeup *wakeup)
14948{
14949 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14950 struct nlattr *nl_results, *nl_match, *nl_freqs;
14951 int i, j;
14952
14953 nl_results = nla_nest_start(
14954 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14955 if (!nl_results)
14956 return -EMSGSIZE;
14957
14958 for (i = 0; i < nd->n_matches; i++) {
14959 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14960
14961 nl_match = nla_nest_start(msg, i);
14962 if (!nl_match)
14963 break;
14964
14965 /* The SSID attribute is optional in nl80211, but for
14966 * simplicity reasons it's always present in the
14967 * cfg80211 structure. If a driver can't pass the
14968 * SSID, that needs to be changed. A zero length SSID
14969 * is still a valid SSID (wildcard), so it cannot be
14970 * used for this purpose.
14971 */
14972 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14973 match->ssid.ssid)) {
14974 nla_nest_cancel(msg, nl_match);
14975 goto out;
14976 }
14977
14978 if (match->n_channels) {
14979 nl_freqs = nla_nest_start(
14980 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14981 if (!nl_freqs) {
14982 nla_nest_cancel(msg, nl_match);
14983 goto out;
14984 }
14985
14986 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014987 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014988 nla_nest_cancel(msg, nl_freqs);
14989 nla_nest_cancel(msg, nl_match);
14990 goto out;
14991 }
14992 }
14993
14994 nla_nest_end(msg, nl_freqs);
14995 }
14996
14997 nla_nest_end(msg, nl_match);
14998 }
14999
15000out:
15001 nla_nest_end(msg, nl_results);
15002 return 0;
15003}
15004
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015005void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
15006 struct cfg80211_wowlan_wakeup *wakeup,
15007 gfp_t gfp)
15008{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015010 struct sk_buff *msg;
15011 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015012 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015013
15014 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15015
15016 if (wakeup)
15017 size += wakeup->packet_present_len;
15018
15019 msg = nlmsg_new(size, gfp);
15020 if (!msg)
15021 return;
15022
15023 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15024 if (!hdr)
15025 goto free_msg;
15026
15027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015028 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15029 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015030 goto free_msg;
15031
15032 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15033 wdev->netdev->ifindex))
15034 goto free_msg;
15035
15036 if (wakeup) {
15037 struct nlattr *reasons;
15038
15039 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020015040 if (!reasons)
15041 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015042
15043 if (wakeup->disconnect &&
15044 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15045 goto free_msg;
15046 if (wakeup->magic_pkt &&
15047 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15048 goto free_msg;
15049 if (wakeup->gtk_rekey_failure &&
15050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15051 goto free_msg;
15052 if (wakeup->eap_identity_req &&
15053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15054 goto free_msg;
15055 if (wakeup->four_way_handshake &&
15056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15057 goto free_msg;
15058 if (wakeup->rfkill_release &&
15059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15060 goto free_msg;
15061
15062 if (wakeup->pattern_idx >= 0 &&
15063 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15064 wakeup->pattern_idx))
15065 goto free_msg;
15066
Johannes Bergae917c92013-10-25 11:05:22 +020015067 if (wakeup->tcp_match &&
15068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15069 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015070
Johannes Bergae917c92013-10-25 11:05:22 +020015071 if (wakeup->tcp_connlost &&
15072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15073 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015074
Johannes Bergae917c92013-10-25 11:05:22 +020015075 if (wakeup->tcp_nomoretokens &&
15076 nla_put_flag(msg,
15077 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15078 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015079
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015080 if (wakeup->packet) {
15081 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15082 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15083
15084 if (!wakeup->packet_80211) {
15085 pkt_attr =
15086 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15087 len_attr =
15088 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15089 }
15090
15091 if (wakeup->packet_len &&
15092 nla_put_u32(msg, len_attr, wakeup->packet_len))
15093 goto free_msg;
15094
15095 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15096 wakeup->packet))
15097 goto free_msg;
15098 }
15099
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015100 if (wakeup->net_detect &&
15101 cfg80211_net_detect_results(msg, wakeup))
15102 goto free_msg;
15103
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015104 nla_nest_end(msg, reasons);
15105 }
15106
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015107 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015108
Johannes Berg68eb5502013-11-19 15:19:38 +010015109 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015110 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015111 return;
15112
15113 free_msg:
15114 nlmsg_free(msg);
15115}
15116EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15117#endif
15118
Jouni Malinen3475b092012-11-16 22:49:57 +020015119void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15120 enum nl80211_tdls_operation oper,
15121 u16 reason_code, gfp_t gfp)
15122{
15123 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015124 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015125 struct sk_buff *msg;
15126 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015127
15128 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15129 reason_code);
15130
15131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15132 if (!msg)
15133 return;
15134
15135 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15136 if (!hdr) {
15137 nlmsg_free(msg);
15138 return;
15139 }
15140
15141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15142 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15143 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15145 (reason_code > 0 &&
15146 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15147 goto nla_put_failure;
15148
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015149 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015150
Johannes Berg68eb5502013-11-19 15:19:38 +010015151 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015152 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015153 return;
15154
15155 nla_put_failure:
15156 genlmsg_cancel(msg, hdr);
15157 nlmsg_free(msg);
15158}
15159EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15160
Jouni Malinen026331c2010-02-15 12:53:10 +020015161static int nl80211_netlink_notify(struct notifier_block * nb,
15162 unsigned long state,
15163 void *_notify)
15164{
15165 struct netlink_notify *notify = _notify;
15166 struct cfg80211_registered_device *rdev;
15167 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015168 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015169
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015170 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015171 return NOTIFY_DONE;
15172
15173 rcu_read_lock();
15174
Johannes Berg5e760232011-11-04 11:18:17 +010015175 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015176 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015177
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015178 list_for_each_entry_rcu(sched_scan_req,
15179 &rdev->sched_scan_req_list,
15180 list) {
15181 if (sched_scan_req->owner_nlportid == notify->portid) {
15182 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015183 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015184 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015185 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015186
Johannes Berg53873f12016-05-03 16:52:04 +030015187 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015188 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015189
Johannes Bergab810072017-04-26 07:43:41 +020015190 if (wdev->owner_nlportid == notify->portid) {
15191 wdev->nl_owner_dead = true;
15192 schedule_work(&rdev->destroy_work);
15193 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015194 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015195 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015196 }
15197
Ben Greear37c73b52012-10-26 14:49:25 -070015198 spin_lock_bh(&rdev->beacon_registrations_lock);
15199 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15200 list) {
15201 if (reg->nlportid == notify->portid) {
15202 list_del(&reg->list);
15203 kfree(reg);
15204 break;
15205 }
15206 }
15207 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015208 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015209
15210 rcu_read_unlock();
15211
Ilan peer05050752015-03-04 00:32:06 -050015212 /*
15213 * It is possible that the user space process that is controlling the
15214 * indoor setting disappeared, so notify the regulatory core.
15215 */
15216 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015217 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015218}
15219
15220static struct notifier_block nl80211_netlink_notifier = {
15221 .notifier_call = nl80211_netlink_notify,
15222};
15223
Jouni Malinen355199e2013-02-27 17:14:27 +020015224void cfg80211_ft_event(struct net_device *netdev,
15225 struct cfg80211_ft_event_params *ft_event)
15226{
15227 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015228 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015229 struct sk_buff *msg;
15230 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015231
15232 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15233
15234 if (!ft_event->target_ap)
15235 return;
15236
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015237 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015238 if (!msg)
15239 return;
15240
15241 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015242 if (!hdr)
15243 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015244
Johannes Bergae917c92013-10-25 11:05:22 +020015245 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15246 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15247 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15248 goto out;
15249
15250 if (ft_event->ies &&
15251 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15252 goto out;
15253 if (ft_event->ric_ies &&
15254 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15255 ft_event->ric_ies))
15256 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015257
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015258 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015259
Johannes Berg68eb5502013-11-19 15:19:38 +010015260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015261 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015262 return;
15263 out:
15264 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015265}
15266EXPORT_SYMBOL(cfg80211_ft_event);
15267
Arend van Spriel5de17982013-04-18 15:49:00 +020015268void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15269{
15270 struct cfg80211_registered_device *rdev;
15271 struct sk_buff *msg;
15272 void *hdr;
15273 u32 nlportid;
15274
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015275 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015276 if (!rdev->crit_proto_nlportid)
15277 return;
15278
15279 nlportid = rdev->crit_proto_nlportid;
15280 rdev->crit_proto_nlportid = 0;
15281
15282 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15283 if (!msg)
15284 return;
15285
15286 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15287 if (!hdr)
15288 goto nla_put_failure;
15289
15290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015291 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15292 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015293 goto nla_put_failure;
15294
15295 genlmsg_end(msg, hdr);
15296
15297 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15298 return;
15299
15300 nla_put_failure:
15301 if (hdr)
15302 genlmsg_cancel(msg, hdr);
15303 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015304}
15305EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15306
Johannes Berg348baf02014-01-24 14:06:29 +010015307void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15308{
15309 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015310 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015311 struct sk_buff *msg;
15312 void *hdr;
15313
15314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15315 if (!msg)
15316 return;
15317
15318 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15319 if (!hdr)
15320 goto out;
15321
15322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15323 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015324 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15325 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015326 goto out;
15327
15328 genlmsg_end(msg, hdr);
15329
15330 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15331 NL80211_MCGRP_MLME, GFP_KERNEL);
15332 return;
15333 out:
15334 nlmsg_free(msg);
15335}
15336
Johannes Berg55682962007-09-20 13:09:35 -040015337/* initialisation/exit functions */
15338
Johannes Berg56989f62016-10-24 14:40:05 +020015339int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015340{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015341 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015342
Johannes Berg489111e2016-10-24 14:40:03 +020015343 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015344 if (err)
15345 return err;
15346
Jouni Malinen026331c2010-02-15 12:53:10 +020015347 err = netlink_register_notifier(&nl80211_netlink_notifier);
15348 if (err)
15349 goto err_out;
15350
Johannes Berg55682962007-09-20 13:09:35 -040015351 return 0;
15352 err_out:
15353 genl_unregister_family(&nl80211_fam);
15354 return err;
15355}
15356
15357void nl80211_exit(void)
15358{
Jouni Malinen026331c2010-02-15 12:53:10 +020015359 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015360 genl_unregister_family(&nl80211_fam);
15361}